From 5280863300e88c6e42c320115a53f0957e113589 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 19 Feb 2024 15:10:18 +0100 Subject: [PATCH 01/91] Set VBO hints in more places --- src/client/content_cao.cpp | 12 ++++++++++++ src/client/hud.cpp | 1 + src/client/minimap.cpp | 1 + src/irrlicht_changes/CGUITTFont.cpp | 1 + src/itemdef.cpp | 5 ++++- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 7e8dfaeb2..330eebd95 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -818,6 +818,18 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) <<"\" not supported"<getMesh()->setHardwareMappingHint(scene::EHM_STATIC); + if (m_animated_meshnode) + m_animated_meshnode->getMesh()->setHardwareMappingHint(scene::EHM_STATIC); + } + /* don't update while punch texture modifier is active */ if (m_reset_textures_timer < 0) updateTextures(m_current_texture_modifier); diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 181dcb0e4..9439a4492 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -135,6 +135,7 @@ Hud::Hud(Client *client, LocalPlayer *player, m_rotation_mesh_buffer.getMaterial().Lighting = false; m_rotation_mesh_buffer.getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + m_rotation_mesh_buffer.setHardwareMappingHint(scene::EHM_STATIC); } Hud::~Hud() diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index 1362dae68..852220d06 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -571,6 +571,7 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer() buf->Indices[4] = 3; buf->Indices[5] = 0; + buf->setHardwareMappingHint(scene::EHM_STATIC); return buf; } diff --git a/src/irrlicht_changes/CGUITTFont.cpp b/src/irrlicht_changes/CGUITTFont.cpp index 9274ee69f..40d2bb405 100644 --- a/src/irrlicht_changes/CGUITTFont.cpp +++ b/src/irrlicht_changes/CGUITTFont.cpp @@ -1046,6 +1046,7 @@ void CGUITTFont::createSharedPlane() buf->append(vertices, 4, indices, 6); shared_plane_.addMeshBuffer( buf ); + shared_plane_.setHardwareMappingHint(EHM_STATIC); shared_plane_ptr_ = &shared_plane_; buf->drop(); //the addMeshBuffer method will grab it, so we can drop this ptr. diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 5c63270c0..bd08f1e2b 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -462,11 +462,14 @@ public: // Create new ClientCached auto cc = std::make_unique(); - // Create an inventory texture cc->inventory_texture = NULL; if (!inventory_image.empty()) cc->inventory_texture = tsrc->getTexture(inventory_image); getItemMesh(client, item, &(cc->wield_mesh)); + // note: vertices are modified frequently (see hud.cpp) so only indices + // can be mapped + if (auto mesh = cc->wield_mesh.mesh) + mesh->setHardwareMappingHint(scene::EHM_STATIC, scene::EBT_INDEX); cc->palette = tsrc->getPalette(def.palette_image); From 09d542dfe0d7c29ff5f479e2fe2903ebda40400d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 19 Feb 2024 15:43:33 +0100 Subject: [PATCH 02/91] Drop enable_vbo setting Consistently applying this setting requires some code work, because Irrlicht does not provide a global toggle. At the same time I don't see any reason for someone to disable this. --- builtin/settingtypes.txt | 4 ---- src/client/mapblock_mesh.cpp | 18 +++++++----------- src/client/mapblock_mesh.h | 1 - src/defaultsettings.cpp | 1 - 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index cecf3d963..57420ec15 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1816,10 +1816,6 @@ video_driver (Video driver) enum ,opengl,opengl3,ogles1,ogles2 # Use this to limit the performance impact of transparency depth sorting transparency_sorting_distance (Transparency Sorting Distance) int 16 0 128 -# Enable vertex buffer objects. -# This should greatly improve graphics performance. -enable_vbo (VBO) bool true - # Radius of cloud area stated in number of 64 node cloud squares. # Values larger than 26 will start to produce sharp cutoffs at cloud area corners. cloud_radius (Cloud radius) int 12 1 62 diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 6e1817260..14434d8c5 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -645,7 +645,6 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs for (auto &m : m_mesh) m = new scene::SMesh(); m_enable_shaders = data->m_use_shaders; - m_enable_vbo = g_settings->getBool("enable_vbo"); auto mesh_grid = client->getMeshGrid(); v3s16 bp = data->m_blockpos; @@ -692,6 +691,8 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs m_bounding_radius = std::sqrt(collector.m_bounding_radius_sq); for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) { + scene::SMesh *mesh = (scene::SMesh *)m_mesh[layer]; + for(u32 i = 0; i < collector.prebuffers[layer].size(); i++) { PreMeshBuffer &p = collector.prebuffers[layer][i]; @@ -783,8 +784,6 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs p.layer.applyMaterialOptions(material); } - scene::SMesh *mesh = (scene::SMesh *)m_mesh[layer]; - scene::SMeshBuffer *buf = new scene::SMeshBuffer(); buf->Material = material; if (p.layer.isTransparent()) { @@ -808,10 +807,9 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs buf->drop(); } - if (m_mesh[layer]) { + if (mesh) { // Use VBO for mesh (this just would set this for ever buffer) - if (m_enable_vbo) - m_mesh[layer]->setHardwareMappingHint(scene::EHM_STATIC); + mesh->setHardwareMappingHint(scene::EHM_STATIC); } } @@ -896,15 +894,13 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, // Day-night transition if (!m_enable_shaders && (daynight_ratio != m_last_daynight_ratio)) { - // Force reload mesh to VBO - if (m_enable_vbo) - for (scene::IMesh *m : m_mesh) - m->setDirty(); video::SColorf day_color; get_sunlight_color(&day_color, daynight_ratio); for (auto &daynight_diff : m_daynight_diffs) { - scene::IMeshBuffer *buf = m_mesh[daynight_diff.first.first]-> + auto *mesh = m_mesh[daynight_diff.first.first]; + mesh->setDirty(scene::EBT_VERTEX); // force reload to VBO + scene::IMeshBuffer *buf = mesh-> getMeshBuffer(daynight_diff.first.second); video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices(); for (const auto &j : daynight_diff.second) diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 7eb141c70..09708799e 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -250,7 +250,6 @@ private: v3f m_bounding_sphere_center; bool m_enable_shaders; - bool m_enable_vbo; // Must animate() be called before rendering? bool m_has_animation; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 711f50f60..d4942a4f5 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -51,7 +51,6 @@ void set_default_settings() settings->setDefault("enable_mesh_cache", "false"); settings->setDefault("mesh_generation_interval", "0"); settings->setDefault("mesh_generation_threads", "0"); - settings->setDefault("enable_vbo", "true"); settings->setDefault("free_move", "false"); settings->setDefault("pitch_move", "false"); settings->setDefault("fast_move", "false"); From 5da18d34ba326ce214e2f427af4cd8bdec219560 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 20 Feb 2024 11:30:51 +0100 Subject: [PATCH 03/91] Properly warn that shader queue is unimplemented --- src/client/shader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/client/shader.cpp b/src/client/shader.cpp index 59852763e..04253f3b4 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -389,8 +389,10 @@ private: // The former container is behind this mutex std::mutex m_shaderinfo_cache_mutex; +#if 0 // Queued shader fetches (to be processed by the main thread) RequestQueue m_get_shader_queue; +#endif // Global constant setter factories std::vector> m_setter_factories; @@ -427,8 +429,10 @@ u32 ShaderSource::getShader(const std::string &name, return getShaderIdDirect(name, material_type, drawtype); } - /*errorstream<<"getShader(): Queued: name=\""< result_queue; @@ -451,6 +455,7 @@ u32 ShaderSource::getShader(const std::string &name, } infostream << "getShader(): Failed" << std::endl; +#endif return 0; } From e9ab5bc223dab08fb936b3cc9f08f95a7b801e04 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 20 Feb 2024 10:38:29 +0100 Subject: [PATCH 04/91] Factor shadow constants out of MainShaderConstantSetter --- src/client/game.cpp | 2 + src/client/shader.cpp | 87 +++---------------- src/client/shadows/dynamicshadowsrender.cpp | 15 +++- src/client/shadows/dynamicshadowsrender.h | 7 +- src/client/shadows/shadowsshadercallbacks.cpp | 47 ++++++++++ src/client/shadows/shadowsshadercallbacks.h | 41 +++++++++ 6 files changed, 118 insertions(+), 81 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 13ebffc7c..18a2ecc0e 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1495,6 +1495,8 @@ bool Game::createClient(const GameStartData &start_data) &m_flags.force_fog_off, &runData.fog_range, client); shader_src->addShaderConstantSetterFactory(scsf); + ShadowRenderer::preInit(shader_src); + // Update cached textures, meshes and materials client->afterContentReceived(); diff --git a/src/client/shader.cpp b/src/client/shader.cpp index 04253f3b4..219b4d807 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "client/renderingengine.h" -#include "EShaderTypes.h" +#include #include "gettext.h" #include "log.h" #include "gamedef.h" @@ -162,12 +162,10 @@ private: std::string readFile(const std::string &path) { - std::ifstream is(path.c_str(), std::ios::binary); - if(!is.is_open()) - return ""; - std::ostringstream tmp_os; - tmp_os << is.rdbuf(); - return tmp_os.str(); + std::string ret; + if (!fs::ReadFile(path, ret)) + ret.clear(); + return ret; } }; @@ -184,15 +182,15 @@ public: template ShaderCallback(const Factories &factories) { - for (auto &&factory : factories) - m_setters.emplace_back(factory->create()); + for (auto &&factory : factories) { + auto *setter = factory->create(); + if (setter) + m_setters.emplace_back(setter); + } } virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData) override { - video::IVideoDriver *driver = services->getVideoDriver(); - sanity_check(driver != NULL); - for (auto &&setter : m_setters) setter->onSetConstants(services); } @@ -214,27 +212,6 @@ class MainShaderConstantSetter : public IShaderConstantSetter CachedVertexShaderSetting m_world_view_proj{"mWorldViewProj"}; CachedVertexShaderSetting m_world{"mWorld"}; - // Shadow-related - CachedPixelShaderSetting m_shadow_view_proj{"m_ShadowViewProj"}; - CachedPixelShaderSetting m_light_direction{"v_LightDirection"}; - CachedPixelShaderSetting m_texture_res{"f_textureresolution"}; - CachedPixelShaderSetting m_shadow_strength{"f_shadow_strength"}; - CachedPixelShaderSetting m_time_of_day{"f_timeofday"}; - CachedPixelShaderSetting m_shadowfar{"f_shadowfar"}; - CachedPixelShaderSetting m_camera_pos{"CameraPos"}; - CachedPixelShaderSetting m_shadow_texture{"ShadowMapSampler"}; - CachedVertexShaderSetting - m_perspective_bias0_vertex{"xyPerspectiveBias0"}; - CachedPixelShaderSetting - m_perspective_bias0_pixel{"xyPerspectiveBias0"}; - CachedVertexShaderSetting - m_perspective_bias1_vertex{"xyPerspectiveBias1"}; - CachedPixelShaderSetting - m_perspective_bias1_pixel{"xyPerspectiveBias1"}; - CachedVertexShaderSetting - m_perspective_zbias_vertex{"zPerspectiveBias"}; - CachedPixelShaderSetting m_perspective_zbias_pixel{"zPerspectiveBias"}; - // Modelview matrix CachedVertexShaderSetting m_world_view{"mWorldView"}; // Texture matrix @@ -267,50 +244,6 @@ public: m_world_view.set(*reinterpret_cast(worldView.pointer()), services); m_texture.set(*reinterpret_cast(texture.pointer()), services); } - - // Set uniforms for Shadow shader - if (ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer()) { - const auto &light = shadow->getDirectionalLight(); - - core::matrix4 shadowViewProj = light.getProjectionMatrix(); - shadowViewProj *= light.getViewMatrix(); - m_shadow_view_proj.set(shadowViewProj.pointer(), services); - - f32 v_LightDirection[3]; - light.getDirection().getAs3Values(v_LightDirection); - m_light_direction.set(v_LightDirection, services); - - f32 TextureResolution = light.getMapResolution(); - m_texture_res.set(&TextureResolution, services); - - f32 ShadowStrength = shadow->getShadowStrength(); - m_shadow_strength.set(&ShadowStrength, services); - - f32 timeOfDay = shadow->getTimeOfDay(); - m_time_of_day.set(&timeOfDay, services); - - f32 shadowFar = shadow->getMaxShadowFar(); - m_shadowfar.set(&shadowFar, services); - - f32 cam_pos[4]; - shadowViewProj.transformVect(cam_pos, light.getPlayerPos()); - m_camera_pos.set(cam_pos, services); - - // I don't like using this hardcoded value. maybe something like - // MAX_TEXTURE - 1 or somthing like that?? - s32 TextureLayerID = 3; - m_shadow_texture.set(&TextureLayerID, services); - - f32 bias0 = shadow->getPerspectiveBiasXY(); - m_perspective_bias0_vertex.set(&bias0, services); - m_perspective_bias0_pixel.set(&bias0, services); - f32 bias1 = 1.0f - bias0 + 1e-5f; - m_perspective_bias1_vertex.set(&bias1, services); - m_perspective_bias1_pixel.set(&bias1, services); - f32 zbias = shadow->getPerspectiveBiasZ(); - m_perspective_zbias_vertex.set(&zbias, services); - m_perspective_zbias_pixel.set(&zbias, services); - } } }; diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index fc8592a21..ca61d8467 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -118,14 +118,20 @@ void ShadowRenderer::disable() }); } +void ShadowRenderer::preInit(IWritableShaderSource *shsrc) +{ + if (g_settings->getBool("enable_shaders") && + g_settings->getBool("enable_dynamic_shadows")) { + shsrc->addShaderConstantSetterFactory(new ShadowConstantSetterFactory()); + } +} + void ShadowRenderer::initialize() { auto *gpu = m_driver->getGPUProgrammingServices(); // we need glsl - if (m_shadows_supported && gpu && m_driver->queryFeature(video::EVDF_ARB_GLSL)) { - createShaders(); - } else { + if (!m_shadows_supported || !gpu || !m_driver->queryFeature(video::EVDF_ARB_GLSL)) { m_shadows_supported = false; warningstream << "Shadows: GLSL Shader not supported on this system." @@ -133,6 +139,9 @@ void ShadowRenderer::initialize() return; } + createShaders(); + + m_texture_format = m_shadow_map_texture_32bit ? video::ECOLOR_FORMAT::ECF_R32F : video::ECOLOR_FORMAT::ECF_R16F; diff --git a/src/client/shadows/dynamicshadowsrender.h b/src/client/shadows/dynamicshadowsrender.h index 7fe3461bc..fc139e28b 100644 --- a/src/client/shadows/dynamicshadowsrender.h +++ b/src/client/shadows/dynamicshadowsrender.h @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class ShadowDepthShaderCB; class shadowScreenQuad; class shadowScreenQuadCB; +class IWritableShaderSource; enum E_SHADOW_MODE : u8 { @@ -54,9 +55,13 @@ public: static const int TEXTURE_LAYER_SHADOW = 3; ShadowRenderer(IrrlichtDevice *device, Client *client); - ~ShadowRenderer(); + // Call before generating any shaders + // This is required because this class is initialized much later than all + // the shaders are dealt with. + static void preInit(IWritableShaderSource *shsrc); + void initialize(); /// Adds a directional light shadow map (Usually just one (the sun) except in diff --git a/src/client/shadows/shadowsshadercallbacks.cpp b/src/client/shadows/shadowsshadercallbacks.cpp index b571ea939..4cfe0f081 100644 --- a/src/client/shadows/shadowsshadercallbacks.cpp +++ b/src/client/shadows/shadowsshadercallbacks.cpp @@ -18,6 +18,53 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "client/shadows/shadowsshadercallbacks.h" +#include "client/renderingengine.h" + +void ShadowConstantSetter::onSetConstants(video::IMaterialRendererServices *services) +{ + auto *shadow = RenderingEngine::get_shadow_renderer(); + if (!shadow) + return; + + const auto &light = shadow->getDirectionalLight(); + + core::matrix4 shadowViewProj = light.getProjectionMatrix(); + shadowViewProj *= light.getViewMatrix(); + m_shadow_view_proj.set(shadowViewProj.pointer(), services); + + f32 v_LightDirection[3]; + light.getDirection().getAs3Values(v_LightDirection); + m_light_direction.set(v_LightDirection, services); + + f32 TextureResolution = light.getMapResolution(); + m_texture_res.set(&TextureResolution, services); + + f32 ShadowStrength = shadow->getShadowStrength(); + m_shadow_strength.set(&ShadowStrength, services); + + f32 timeOfDay = shadow->getTimeOfDay(); + m_time_of_day.set(&timeOfDay, services); + + f32 shadowFar = shadow->getMaxShadowFar(); + m_shadowfar.set(&shadowFar, services); + + f32 cam_pos[4]; + shadowViewProj.transformVect(cam_pos, light.getPlayerPos()); + m_camera_pos.set(cam_pos, services); + + s32 TextureLayerID = ShadowRenderer::TEXTURE_LAYER_SHADOW; + m_shadow_texture.set(&TextureLayerID, services); + + f32 bias0 = shadow->getPerspectiveBiasXY(); + m_perspective_bias0_vertex.set(&bias0, services); + m_perspective_bias0_pixel.set(&bias0, services); + f32 bias1 = 1.0f - bias0 + 1e-5f; + m_perspective_bias1_vertex.set(&bias1, services); + m_perspective_bias1_pixel.set(&bias1, services); + f32 zbias = shadow->getPerspectiveBiasZ(); + m_perspective_zbias_vertex.set(&zbias, services); + m_perspective_zbias_pixel.set(&zbias, services); +} void ShadowDepthShaderCB::OnSetConstants( video::IMaterialRendererServices *services, s32 userData) diff --git a/src/client/shadows/shadowsshadercallbacks.h b/src/client/shadows/shadowsshadercallbacks.h index 4d006fea6..af83f021e 100644 --- a/src/client/shadows/shadowsshadercallbacks.h +++ b/src/client/shadows/shadowsshadercallbacks.h @@ -23,6 +23,47 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "client/shader.h" +// Used by main game rendering + +class ShadowConstantSetter : public IShaderConstantSetter +{ + CachedPixelShaderSetting m_shadow_view_proj{"m_ShadowViewProj"}; + CachedPixelShaderSetting m_light_direction{"v_LightDirection"}; + CachedPixelShaderSetting m_texture_res{"f_textureresolution"}; + CachedPixelShaderSetting m_shadow_strength{"f_shadow_strength"}; + CachedPixelShaderSetting m_time_of_day{"f_timeofday"}; + CachedPixelShaderSetting m_shadowfar{"f_shadowfar"}; + CachedPixelShaderSetting m_camera_pos{"CameraPos"}; + CachedPixelShaderSetting m_shadow_texture{"ShadowMapSampler"}; + CachedVertexShaderSetting + m_perspective_bias0_vertex{"xyPerspectiveBias0"}; + CachedPixelShaderSetting + m_perspective_bias0_pixel{"xyPerspectiveBias0"}; + CachedVertexShaderSetting + m_perspective_bias1_vertex{"xyPerspectiveBias1"}; + CachedPixelShaderSetting + m_perspective_bias1_pixel{"xyPerspectiveBias1"}; + CachedVertexShaderSetting + m_perspective_zbias_vertex{"zPerspectiveBias"}; + CachedPixelShaderSetting m_perspective_zbias_pixel{"zPerspectiveBias"}; + +public: + ShadowConstantSetter() = default; + ~ShadowConstantSetter() = default; + + virtual void onSetConstants(video::IMaterialRendererServices *services) override; +}; + +class ShadowConstantSetterFactory : public IShaderConstantSetterFactory +{ +public: + virtual IShaderConstantSetter *create() { + return new ShadowConstantSetter(); + } +}; + +// Used by depth shader + class ShadowDepthShaderCB : public video::IShaderConstantSetCallBack { public: From 0c3a4cc7b98d35cadcbf743e7c25648d38dbfd28 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 20 Feb 2024 14:59:47 +0100 Subject: [PATCH 05/91] Improve ergonomics of CachedShaderSetting --- src/client/game.cpp | 57 ++++++------------- src/client/shader.cpp | 8 +-- src/client/shader.h | 51 +++++++++++++++++ src/client/shadows/shadowsshadercallbacks.cpp | 6 +- 4 files changed, 75 insertions(+), 47 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 18a2ecc0e..4a4c89fcf 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -398,7 +398,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter CachedPixelShaderSetting m_texture3{"texture3"}; CachedVertexShaderSetting m_texel_size0_vertex{"texelSize0"}; CachedPixelShaderSetting m_texel_size0_pixel{"texelSize0"}; - std::array m_texel_size0_values; + v2f m_texel_size0; CachedStructPixelShaderSetting m_exposure_params_pixel{ "exposureParams", std::array { @@ -477,10 +477,7 @@ public: void onSetConstants(video::IMaterialRendererServices *services) override { video::SColorf fogcolorf(m_sky->getFogColor()); - float fogcolorfa[4] = { - fogcolorf.r, fogcolorf.g, fogcolorf.b, fogcolorf.a, - }; - m_fog_color.set(fogcolorfa, services); + m_fog_color.set(fogcolorf, services); float fog_distance = 10000 * BS; if (m_fog_enabled && !*m_force_fog_off) @@ -494,11 +491,7 @@ public: u32 daynight_ratio = (float)m_client->getEnv().getDayNightRatio(); video::SColorf sunlight; get_sunlight_color(&sunlight, daynight_ratio); - float dnc[3] = { - sunlight.r, - sunlight.g, - sunlight.b }; - m_day_light.set(dnc, services); + m_day_light.set(sunlight, services); video::SColorf star_color = m_sky->getCurrentStarColor(); float clr[4] = {star_color.r, star_color.g, star_color.b, star_color.a}; @@ -513,24 +506,18 @@ public: m_animation_timer_delta_vertex.set(&animation_timer_delta_f, services); m_animation_timer_delta_pixel.set(&animation_timer_delta_f, services); - float eye_position_array[3]; v3f epos = m_client->getEnv().getLocalPlayer()->getEyePosition(); - epos.getAs3Values(eye_position_array); - m_eye_position_pixel.set(eye_position_array, services); - m_eye_position_vertex.set(eye_position_array, services); + m_eye_position_pixel.set(epos, services); + m_eye_position_vertex.set(epos, services); if (m_client->getMinimap()) { - float minimap_yaw_array[3]; v3f minimap_yaw = m_client->getMinimap()->getYawVec(); - minimap_yaw.getAs3Values(minimap_yaw_array); - m_minimap_yaw.set(minimap_yaw_array, services); + m_minimap_yaw.set(minimap_yaw, services); } - float camera_offset_array[3]; v3f offset = intToFloat(m_client->getCamera()->getOffset(), BS); - offset.getAs3Values(camera_offset_array); - m_camera_offset_pixel.set(camera_offset_array, services); - m_camera_offset_vertex.set(camera_offset_array, services); + m_camera_offset_pixel.set(offset, services); + m_camera_offset_vertex.set(offset, services); SamplerLayer_t tex_id; tex_id = 0; @@ -542,8 +529,8 @@ public: tex_id = 3; m_texture3.set(&tex_id, services); - m_texel_size0_vertex.set(m_texel_size0_values.data(), services); - m_texel_size0_pixel.set(m_texel_size0_values.data(), services); + m_texel_size0_vertex.set(m_texel_size0, services); + m_texel_size0_pixel.set(m_texel_size0, services); const AutoExposure &exposure_params = m_client->getEnv().getLocalPlayer()->getLighting().exposure; std::array exposure_buffer = { @@ -577,14 +564,12 @@ public: transform.transformVect(sun_position); sun_position.normalize(); - float sun_position_array[3] = { sun_position.X, sun_position.Y, sun_position.Z}; - m_sun_position_pixel.set(sun_position_array, services); + m_sun_position_pixel.set(sun_position, services); float sun_brightness = rangelim(107.143f * m_sky->getSunDirection().dotProduct(v3f(0.f, 1.f, 0.f)), 0.f, 1.f); m_sun_brightness_pixel.set(&sun_brightness, services); } else { - float sun_position_array[3] = { 0.f, 0.f, -1.f }; - m_sun_position_pixel.set(sun_position_array, services); + m_sun_position_pixel.set(v3f(0.f, 0.f, -1.f), services); float sun_brightness = 0.f; m_sun_brightness_pixel.set(&sun_brightness, services); @@ -596,15 +581,12 @@ public: transform.transformVect(moon_position); moon_position.normalize(); - float moon_position_array[3] = { moon_position.X, moon_position.Y, moon_position.Z}; - m_moon_position_pixel.set(moon_position_array, services); + m_moon_position_pixel.set(moon_position, services); float moon_brightness = rangelim(107.143f * m_sky->getMoonDirection().dotProduct(v3f(0.f, 1.f, 0.f)), 0.f, 1.f); m_moon_brightness_pixel.set(&moon_brightness, services); - } - else { - float moon_position_array[3] = { 0.f, 0.f, -1.f }; - m_moon_position_pixel.set(moon_position_array, services); + } else { + m_moon_position_pixel.set(v3f(0.f, 0.f, -1.f), services); float moon_brightness = 0.f; m_moon_brightness_pixel.set(&moon_brightness, services); @@ -619,12 +601,9 @@ public: video::ITexture *texture = material.getTexture(0); if (texture) { core::dimension2du size = texture->getSize(); - m_texel_size0_values[0] = 1.f / size.Width; - m_texel_size0_values[1] = 1.f / size.Height; - } - else { - m_texel_size0_values[0] = 0.f; - m_texel_size0_values[1] = 0.f; + m_texel_size0 = v2f(1.f / size.Width, 1.f / size.Height); + } else { + m_texel_size0 = v2f(); } } }; diff --git a/src/client/shader.cpp b/src/client/shader.cpp index 219b4d807..f9274d691 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -227,7 +227,7 @@ public: // Set world matrix core::matrix4 world = driver->getTransform(video::ETS_WORLD); - m_world.set(*reinterpret_cast(world.pointer()), services); + m_world.set(world, services); // Set clip matrix core::matrix4 worldView; @@ -237,12 +237,12 @@ public: core::matrix4 worldViewProj; worldViewProj = driver->getTransform(video::ETS_PROJECTION); worldViewProj *= worldView; - m_world_view_proj.set(*reinterpret_cast(worldViewProj.pointer()), services); + m_world_view_proj.set(worldViewProj, services); if (driver->getDriverType() == video::EDT_OGLES2 || driver->getDriverType() == video::EDT_OPENGL3) { core::matrix4 texture = driver->getTransform(video::ETS_TEXTURE_0); - m_world_view.set(*reinterpret_cast(worldView.pointer()), services); - m_texture.set(*reinterpret_cast(texture.pointer()), services); + m_world_view.set(worldView, services); + m_texture.set(texture, services); } } }; diff --git a/src/client/shader.h b/src/client/shader.h index fabb19922..da4715545 100644 --- a/src/client/shader.h +++ b/src/client/shader.h @@ -105,6 +105,57 @@ public: has_been_set = true; } } + + /* Type specializations */ + + /* + * T2 looks redundant here but it is necessary so the compiler won't + * resolve the templates at class instantiation and then fail because + * some of these methods don't have valid types (= are not usable). + * ref: + * + * Note: a `bool dummy` template parameter would have been easier but MSVC + * does not like that. Also make sure not to define different specializations + * with the same parameters, MSVC doesn't like that either. + * I extend my thanks to Microsoft® + */ +#define SPECIALIZE(_type, _count_expr) \ + template \ + std::enable_if_t && std::is_same_v && (_count_expr)> + + SPECIALIZE(float, count == 2) + set(const v2f value, video::IMaterialRendererServices *services) + { + float array[2] = { value.X, value.Y }; + set(array, services); + } + + SPECIALIZE(float, count == 3) + set(const v3f value, video::IMaterialRendererServices *services) + { + float array[3] = { value.X, value.Y, value.Z }; + set(array, services); + } + + SPECIALIZE(float, count == 3 || count == 4) + set(const video::SColorf value, video::IMaterialRendererServices *services) + { + if constexpr (count == 3) { + float array[3] = { value.r, value.g, value.b }; + set(array, services); + } else { + float array[4] = { value.r, value.g, value.b, value.a }; + set(array, services); + } + } + + SPECIALIZE(float, count == 16) + set(const core::matrix4 &value, video::IMaterialRendererServices *services) + { + set(value.pointer(), services); + } + +#undef SPECIALIZE }; template diff --git a/src/client/shadows/shadowsshadercallbacks.cpp b/src/client/shadows/shadowsshadercallbacks.cpp index 4cfe0f081..32d3e36be 100644 --- a/src/client/shadows/shadowsshadercallbacks.cpp +++ b/src/client/shadows/shadowsshadercallbacks.cpp @@ -32,9 +32,7 @@ void ShadowConstantSetter::onSetConstants(video::IMaterialRendererServices *serv shadowViewProj *= light.getViewMatrix(); m_shadow_view_proj.set(shadowViewProj.pointer(), services); - f32 v_LightDirection[3]; - light.getDirection().getAs3Values(v_LightDirection); - m_light_direction.set(v_LightDirection, services); + m_light_direction.set(light.getDirection(), services); f32 TextureResolution = light.getMapResolution(); m_texture_res.set(&TextureResolution, services); @@ -79,7 +77,7 @@ void ShadowDepthShaderCB::OnSetConstants( lightMVP *= driver->getTransform(video::ETS_WORLD); - m_light_mvp_setting.set(lightMVP.pointer(), services); + m_light_mvp_setting.set(lightMVP, services); m_map_resolution_setting.set(&MapRes, services); m_max_far_setting.set(&MaxFar, services); s32 TextureId = 0; From 13a0e5fb4a2cfcb6a7524b5825977c3e8d227948 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 20 Feb 2024 16:05:27 +0100 Subject: [PATCH 06/91] Share FpsControl code between game and menu --- src/client/game.cpp | 58 +----------------------------- src/client/renderingengine.cpp | 43 +++++++++++++++++++++- src/client/renderingengine.h | 18 +++++++--- src/gui/guiEngine.cpp | 66 +++++++--------------------------- src/gui/guiEngine.h | 8 +---- 5 files changed, 70 insertions(+), 123 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 4a4c89fcf..6714b1bcb 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -650,20 +650,6 @@ public: const static float object_hit_delay = 0.2; -struct FpsControl { - FpsControl() : last_time(0), busy_time(0), sleep_time(0) {} - - void reset(); - - void limit(IrrlichtDevice *device, f32 *dtime); - - u32 getBusyMs() const { return busy_time / 1000; } - - // all values in microseconds (us) - u64 last_time, busy_time, sleep_time; -}; - - /* The reason the following structs are not anonymous structs within the * class is that they are not used by the majority of member functions and * many functions that do require objects of thse types do not modify them @@ -1201,7 +1187,7 @@ void Game::run() // Calculate dtime = // m_rendering_engine->run() from this iteration // + Sleep time until the wanted FPS are reached - draw_times.limit(device, &dtime); + draw_times.limit(device, &dtime, g_menumgr.pausesGame()); const auto current_dynamic_info = ClientDynamicInfo::getCurrent(); if (!current_dynamic_info.equal(client_display_info)) { @@ -4330,48 +4316,6 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats) Misc ****************************************************************************/ -void FpsControl::reset() -{ - last_time = porting::getTimeUs(); -} - -/* - * On some computers framerate doesn't seem to be automatically limited - */ -void FpsControl::limit(IrrlichtDevice *device, f32 *dtime) -{ - const float fps_limit = (device->isWindowFocused() && !g_menumgr.pausesGame()) - ? g_settings->getFloat("fps_max") - : g_settings->getFloat("fps_max_unfocused"); - const u64 frametime_min = 1000000.0f / std::max(fps_limit, 1.0f); - - u64 time = porting::getTimeUs(); - - if (time > last_time) // Make sure time hasn't overflowed - busy_time = time - last_time; - else - busy_time = 0; - - if (busy_time < frametime_min) { - sleep_time = frametime_min - busy_time; - if (sleep_time > 0) - sleep_us(sleep_time); - } else { - sleep_time = 0; - } - - // Read the timer again to accurately determine how long we actually slept, - // rather than calculating it by adding sleep_time to time. - time = porting::getTimeUs(); - - if (time > last_time) // Make sure last_time hasn't overflowed - *dtime = (time - last_time) / 1000000.0f; - else - *dtime = 0; - - last_time = time; -} - void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool draw_sky) { m_rendering_engine->draw_load_screen(wstrgettext(msg), guienv, texture_src, diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index c1a51d289..22b55ec6b 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -44,6 +44,46 @@ RenderingEngine *RenderingEngine::s_singleton = nullptr; const video::SColor RenderingEngine::MENU_SKY_COLOR = video::SColor(255, 140, 186, 250); const float RenderingEngine::BASE_BLOOM_STRENGTH = 1.0f; +/* Helper stuff */ + +void FpsControl::reset() +{ + last_time = porting::getTimeUs(); +} + +void FpsControl::limit(IrrlichtDevice *device, f32 *dtime, bool assume_paused) +{ + const float fps_limit = (device->isWindowFocused() && !assume_paused) + ? g_settings->getFloat("fps_max") + : g_settings->getFloat("fps_max_unfocused"); + const u64 frametime_min = 1000000.0f / std::max(fps_limit, 1.0f); + + u64 time = porting::getTimeUs(); + + if (time > last_time) // Make sure time hasn't overflowed + busy_time = time - last_time; + else + busy_time = 0; + + if (busy_time < frametime_min) { + sleep_time = frametime_min - busy_time; + if (sleep_time > 0) + sleep_us(sleep_time); + } else { + sleep_time = 0; + } + + // Read the timer again to accurately determine how long we actually slept, + // rather than calculating it by adding sleep_time to time. + time = porting::getTimeUs(); + + if (time > last_time) // Make sure last_time hasn't overflowed + *dtime = (time - last_time) / 1000000.0f; + else + *dtime = 0; + + last_time = time; +} static gui::GUISkin *createSkin(gui::IGUIEnvironment *environment, gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver) @@ -66,7 +106,6 @@ static gui::GUISkin *createSkin(gui::IGUIEnvironment *environment, return skin; } - static std::optional chooseVideoDriver() { auto &&configured_name = g_settings->get("video_driver"); @@ -106,6 +145,8 @@ static irr::IrrlichtDevice *createDevice(SIrrlichtCreationParameters params, std throw std::runtime_error("Could not initialize the device with any supported video driver"); } +/* RenderingEngine class */ + RenderingEngine::RenderingEngine(IEventReceiver *receiver) { sanity_check(!s_singleton); diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index b8293f49a..629843ac9 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -46,6 +46,19 @@ class RenderingCore; // Instead of a mechanism to disable fog we just set it to be really far away #define FOG_RANGE_ALL (100000 * BS) +struct FpsControl { + FpsControl() : last_time(0), busy_time(0), sleep_time(0) {} + + void reset(); + + void limit(IrrlichtDevice *device, f32 *dtime, bool assume_paused = false); + + u32 getBusyMs() const { return busy_time / 1000; } + + // all values in microseconds (us) + u64 last_time, busy_time, sleep_time; +}; + class RenderingEngine { public: @@ -103,11 +116,6 @@ public: return s_singleton->m_device; } - u32 get_timer_time() - { - return m_device->getTimer()->getTime(); - } - gui::IGUIEnvironment *get_gui_env() { return m_device->getGUIEnvironment(); diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 3f21e69e6..a0e4055b8 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -315,10 +315,15 @@ void GUIEngine::run() ); const bool initial_window_maximized = g_settings->getBool("window_maximized"); - u64 t_last_frame = porting::getTimeUs(); + FpsControl fps_control; f32 dtime = 0.0f; - while (m_rendering_engine->run() && (!m_startgame) && (!m_kill)) { + fps_control.reset(); + + while (m_rendering_engine->run() && !m_startgame && !m_kill) { + + fps_control.limit(device, &dtime); + if (device->isWindowVisible()) { // check if we need to update the "upper left corner"-text if (text_height != g_fontengine->getTextHeight()) { @@ -328,13 +333,12 @@ void GUIEngine::run() driver->beginScene(true, true, RenderingEngine::MENU_SKY_COLOR); - if (m_clouds_enabled) - { - cloudPreProcess(); + if (m_clouds_enabled) { + drawClouds(dtime); drawOverlay(driver); - } - else + } else { drawBackground(driver); + } drawFooter(driver); @@ -349,22 +353,9 @@ void GUIEngine::run() driver->endScene(); } - u32 frametime_min = 1000 / (device->isWindowFocused() - ? g_settings->getFloat("fps_max") - : g_settings->getFloat("fps_max_unfocused")); - if (m_clouds_enabled) - cloudPostProcess(frametime_min, device); - else - sleep_ms(frametime_min); - - u64 t_now = porting::getTimeUs(); - dtime = static_cast(t_now - t_last_frame) * 1.0e-6f; - t_last_frame = t_now; - m_script->step(); sound_volume_control(m_sound_manager.get(), device->isWindowActive()); - m_sound_manager->step(dtime); #ifdef __ANDROID__ @@ -407,47 +398,16 @@ void GUIEngine::cloudInit() m_cloud.camera = m_smgr->addCameraSceneNode(0, v3f(0,0,0), v3f(0, 60, 100)); m_cloud.camera->setFarValue(10000); - - m_cloud.lasttime = m_rendering_engine->get_timer_time(); } /******************************************************************************/ -void GUIEngine::cloudPreProcess() +void GUIEngine::drawClouds(float dtime) { - u32 time = m_rendering_engine->get_timer_time(); - - if(time > m_cloud.lasttime) - m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0; - else - m_cloud.dtime = 0; - - m_cloud.lasttime = time; - - m_cloud.clouds->step(m_cloud.dtime*3); + m_cloud.clouds->step(dtime*3); m_cloud.clouds->render(); m_smgr->drawAll(); } -/******************************************************************************/ -void GUIEngine::cloudPostProcess(u32 frametime_min, IrrlichtDevice *device) -{ - // Time of frame without fps limit - u32 busytime_u32; - - // not using getRealTime is necessary for wine - u32 time = m_rendering_engine->get_timer_time(); - if(time > m_cloud.lasttime) - busytime_u32 = time - m_cloud.lasttime; - else - busytime_u32 = 0; - - // FPS limit - if (busytime_u32 < frametime_min) { - u32 sleeptime = frametime_min - busytime_u32; - device->sleep(sleeptime); - } -} - /******************************************************************************/ void GUIEngine::setFormspecPrepend(const std::string &fs) { diff --git a/src/gui/guiEngine.h b/src/gui/guiEngine.h index 7d33ce7c5..eb3e01f62 100644 --- a/src/gui/guiEngine.h +++ b/src/gui/guiEngine.h @@ -280,16 +280,10 @@ private: /** initialize cloud subsystem */ void cloudInit(); /** do preprocessing for cloud subsystem */ - void cloudPreProcess(); - /** do postprocessing for cloud subsystem */ - void cloudPostProcess(u32 frametime_min, IrrlichtDevice *device); + void drawClouds(float dtime); /** internam data required for drawing clouds */ struct clouddata { - /** delta time since last cloud processing */ - f32 dtime; - /** absolute time of last cloud processing */ - u32 lasttime; /** pointer to cloud class */ irr_ptr clouds; /** camera required for drawing clouds */ From dce166dc93078312d2a5a5de69ae305e3f91c7cf Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 20 Feb 2024 21:44:47 +0100 Subject: [PATCH 07/91] Support deleting shader materials --- src/client/shader.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/client/shader.cpp b/src/client/shader.cpp index f9274d691..ed4f618fe 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -264,6 +264,7 @@ class ShaderSource : public IWritableShaderSource { public: ShaderSource(); + ~ShaderSource() override; /* - If shader material specified by name is found from cache, @@ -351,6 +352,22 @@ ShaderSource::ShaderSource() addShaderConstantSetterFactory(new MainShaderConstantSetterFactory()); } +ShaderSource::~ShaderSource() +{ + MutexAutoLock lock(m_shaderinfo_cache_mutex); + +#if IRRLICHT_VERSION_MT_REVISION >= 15 + // Delete materials + video::IGPUProgrammingServices *gpu = RenderingEngine::get_video_driver()-> + getGPUProgrammingServices(); + for (ShaderInfo &i : m_shaderinfo_cache) { + if (!i.name.empty()) + gpu->deleteShaderMaterial(i.material); + } + m_shaderinfo_cache.clear(); +#endif +} + u32 ShaderSource::getShader(const std::string &name, MaterialType material_type, NodeDrawType drawtype) { @@ -472,15 +489,17 @@ void ShaderSource::rebuildShaders() { MutexAutoLock lock(m_shaderinfo_cache_mutex); - /*// Oh well... just clear everything, they'll load sometime. - m_shaderinfo_cache.clear(); - m_name_to_id.clear();*/ - - /* - FIXME: Old shader materials can't be deleted in Irrlicht, - or can they? - (This would be nice to do in the destructor too) - */ +#if IRRLICHT_VERSION_MT_REVISION >= 15 + // Delete materials + video::IGPUProgrammingServices *gpu = RenderingEngine::get_video_driver()-> + getGPUProgrammingServices(); + for (ShaderInfo &i : m_shaderinfo_cache) { + if (!i.name.empty()) { + gpu->deleteShaderMaterial(i.material); + i.material = video::EMT_SOLID; // invalidate + } + } +#endif // Recreate shaders for (ShaderInfo &i : m_shaderinfo_cache) { From d85c842ce9175d7299d2b5a9938d2275278a44ba Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 21 Feb 2024 21:15:50 +0100 Subject: [PATCH 08/91] Refactor fog shader to reuse Irrlicht values --- src/client/game.cpp | 67 +++++++++++----------------------- src/client/renderingengine.cpp | 43 +++++++++++++++++++++- src/client/renderingengine.h | 13 +++++++ 3 files changed, 76 insertions(+), 47 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 6714b1bcb..296b0ce8d 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -372,13 +372,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter { Sky *m_sky; Client *m_client; - bool *m_force_fog_off; - f32 *m_fog_range; - bool m_fog_enabled; - CachedPixelShaderSetting m_fog_color{"fogColor"}; - CachedPixelShaderSetting m_fog_distance{"fogDistance"}; - CachedPixelShaderSetting - m_fog_shading_parameter{"fogShadingParameter"}; CachedVertexShaderSetting m_animation_timer_vertex{"animationTimer"}; CachedPixelShaderSetting m_animation_timer_pixel{"animationTimer"}; CachedVertexShaderSetting @@ -425,11 +418,16 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter CachedPixelShaderSetting m_volumetric_light_strength_pixel{"volumetricLightStrength"}; + static constexpr std::array SETTING_CALLBACKS = { + "exposure_compensation", + "bloom_intensity", + "bloom_strength_factor", + "bloom_radius" + }; + public: void onSettingsChange(const std::string &name) { - if (name == "enable_fog") - m_fog_enabled = g_settings->getBool("enable_fog"); if (name == "exposure_compensation") m_user_exposure_compensation = g_settings->getFloat("exposure_compensation", -1.0f, 1.0f); if (name == "bloom_intensity") @@ -447,20 +445,13 @@ public: void setSky(Sky *sky) { m_sky = sky; } - GameGlobalShaderConstantSetter(Sky *sky, bool *force_fog_off, - f32 *fog_range, Client *client) : + GameGlobalShaderConstantSetter(Sky *sky, Client *client) : m_sky(sky), - m_client(client), - m_force_fog_off(force_fog_off), - m_fog_range(fog_range) + m_client(client) { - g_settings->registerChangedCallback("enable_fog", settingsCallback, this); - g_settings->registerChangedCallback("exposure_compensation", settingsCallback, this); - g_settings->registerChangedCallback("bloom_intensity", settingsCallback, this); - g_settings->registerChangedCallback("bloom_strength_factor", settingsCallback, this); - g_settings->registerChangedCallback("bloom_radius", settingsCallback, this); - g_settings->registerChangedCallback("saturation", settingsCallback, this); - m_fog_enabled = g_settings->getBool("enable_fog"); + for (auto &name : SETTING_CALLBACKS) + g_settings->registerChangedCallback(name, settingsCallback, this); + m_user_exposure_compensation = g_settings->getFloat("exposure_compensation", -1.0f, 1.0f); m_bloom_enabled = g_settings->getBool("enable_bloom"); m_bloom_intensity = g_settings->getFloat("bloom_intensity", 0.01f, 1.0f); @@ -471,23 +462,12 @@ public: ~GameGlobalShaderConstantSetter() { - g_settings->deregisterChangedCallback("enable_fog", settingsCallback, this); + for (auto &name : SETTING_CALLBACKS) + g_settings->deregisterChangedCallback(name, settingsCallback, this); } void onSetConstants(video::IMaterialRendererServices *services) override { - video::SColorf fogcolorf(m_sky->getFogColor()); - m_fog_color.set(fogcolorf, services); - - float fog_distance = 10000 * BS; - if (m_fog_enabled && !*m_force_fog_off) - fog_distance = *m_fog_range; - - float fog_shading_parameter = 1.0 / ( 1.0 - m_sky->getFogStart()); - - m_fog_distance.set(&fog_distance, services); - m_fog_shading_parameter.set(&fog_shading_parameter, services); - u32 daynight_ratio = (float)m_client->getEnv().getDayNightRatio(); video::SColorf sunlight; get_sunlight_color(&sunlight, daynight_ratio); @@ -611,17 +591,11 @@ public: class GameGlobalShaderConstantSetterFactory : public IShaderConstantSetterFactory { - Sky *m_sky; - bool *m_force_fog_off; - f32 *m_fog_range; + Sky *m_sky = nullptr; Client *m_client; std::vector created_nosky; public: - GameGlobalShaderConstantSetterFactory(bool *force_fog_off, - f32 *fog_range, Client *client) : - m_sky(NULL), - m_force_fog_off(force_fog_off), - m_fog_range(fog_range), + GameGlobalShaderConstantSetterFactory(Client *client) : m_client(client) {} @@ -635,8 +609,7 @@ public: virtual IShaderConstantSetter* create() { - auto *scs = new GameGlobalShaderConstantSetter( - m_sky, m_force_fog_off, m_fog_range, m_client); + auto *scs = new GameGlobalShaderConstantSetter(m_sky, m_client); if (!m_sky) created_nosky.push_back(scs); return scs; @@ -1456,10 +1429,12 @@ bool Game::createClient(const GameStartData &start_data) return false; } - auto *scsf = new GameGlobalShaderConstantSetterFactory( - &m_flags.force_fog_off, &runData.fog_range, client); + auto *scsf = new GameGlobalShaderConstantSetterFactory(client); shader_src->addShaderConstantSetterFactory(scsf); + shader_src->addShaderConstantSetterFactory( + new FogShaderConstantSetterFactory()); + ShadowRenderer::preInit(shader_src); // Update cached textures, meshes and materials diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 22b55ec6b..59c1a086f 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -44,7 +44,7 @@ RenderingEngine *RenderingEngine::s_singleton = nullptr; const video::SColor RenderingEngine::MENU_SKY_COLOR = video::SColor(255, 140, 186, 250); const float RenderingEngine::BASE_BLOOM_STRENGTH = 1.0f; -/* Helper stuff */ +/* Helper classes */ void FpsControl::reset() { @@ -85,6 +85,47 @@ void FpsControl::limit(IrrlichtDevice *device, f32 *dtime, bool assume_paused) last_time = time; } +class FogShaderConstantSetter : public IShaderConstantSetter +{ + CachedPixelShaderSetting m_fog_color{"fogColor"}; + CachedPixelShaderSetting m_fog_distance{"fogDistance"}; + CachedPixelShaderSetting m_fog_shading_parameter{"fogShadingParameter"}; + +public: + void onSetConstants(video::IMaterialRendererServices *services) override + { + auto *driver = RenderingEngine::get_video_driver(); + assert(driver); + + video::SColor fog_color(0); + video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR; + f32 fog_start = 0; + f32 fog_end = 0; + f32 fog_density = 0; + bool fog_pixelfog = false; + bool fog_rangefog = false; + driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density, + fog_pixelfog, fog_rangefog); + + video::SColorf fog_colorf(fog_color); + m_fog_color.set(fog_colorf, services); + + m_fog_distance.set(&fog_end, services); + + float parameter = 0; + if (fog_end > 0) + parameter = 1.0f / (1.0f - fog_start / fog_end); + m_fog_shading_parameter.set(¶meter, services); + } +}; + +IShaderConstantSetter *FogShaderConstantSetterFactory::create() +{ + return new FogShaderConstantSetter(); +} + +/* Other helpers */ + static gui::GUISkin *createSkin(gui::IGUIEnvironment *environment, gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver) { diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 629843ac9..e787af488 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "irrlichttypes_extrabloated.h" #include "debug.h" +#include "client/shader.h" #include "client/render/core.h" // include the shadow mapper classes too #include "client/shadows/dynamicshadowsrender.h" @@ -46,6 +47,8 @@ class RenderingCore; // Instead of a mechanism to disable fog we just set it to be really far away #define FOG_RANGE_ALL (100000 * BS) +/* Helpers */ + struct FpsControl { FpsControl() : last_time(0), busy_time(0), sleep_time(0) {} @@ -59,6 +62,16 @@ struct FpsControl { u64 last_time, busy_time, sleep_time; }; +// Populates fogColor, fogDistance, fogShadingParameter with values from Irrlicht +class FogShaderConstantSetterFactory : public IShaderConstantSetterFactory +{ +public: + FogShaderConstantSetterFactory() {}; + virtual IShaderConstantSetter *create(); +}; + +/* Rendering engine class */ + class RenderingEngine { public: From bb7f57b095cb6c95c5071d80ebc1c5173049c742 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 19 Feb 2024 19:04:20 +0100 Subject: [PATCH 09/91] VBO-related optimizations and improvements (#14395) --- .../shaders/cloud_shader/opengl_fragment.glsl | 17 ++ .../shaders/cloud_shader/opengl_vertex.glsl | 21 ++ .../shaders/stars_shader/opengl_fragment.glsl | 4 +- src/client/clientenvironment.cpp | 49 ---- src/client/clientlauncher.cpp | 106 ++++---- src/client/clientlauncher.h | 2 +- src/client/clouds.cpp | 242 +++++++++++------- src/client/clouds.h | 50 +++- src/client/content_cao.cpp | 1 - src/client/game.cpp | 24 +- src/client/hud.cpp | 27 +- src/client/minimap.cpp | 2 +- src/client/renderingengine.cpp | 24 +- src/client/renderingengine.h | 1 - src/client/shader.cpp | 26 +- src/client/sky.cpp | 10 +- src/client/sky.h | 2 - src/client/wieldmesh.cpp | 47 ++-- src/client/wieldmesh.h | 44 +++- src/gui/guiEngine.cpp | 53 ++-- src/gui/guiEngine.h | 5 +- src/itemdef.cpp | 4 - 22 files changed, 439 insertions(+), 322 deletions(-) create mode 100644 client/shaders/cloud_shader/opengl_fragment.glsl create mode 100644 client/shaders/cloud_shader/opengl_vertex.glsl diff --git a/client/shaders/cloud_shader/opengl_fragment.glsl b/client/shaders/cloud_shader/opengl_fragment.glsl new file mode 100644 index 000000000..fe416d121 --- /dev/null +++ b/client/shaders/cloud_shader/opengl_fragment.glsl @@ -0,0 +1,17 @@ +uniform vec4 fogColor; +uniform float fogDistance; +uniform float fogShadingParameter; +varying vec3 eyeVec; + +varying lowp vec4 varColor; + +void main(void) +{ + vec4 col = varColor; + + float clarity = clamp(fogShadingParameter + - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0); + col.rgb = mix(fogColor.rgb, col.rgb, clarity); + + gl_FragColor = col; +} diff --git a/client/shaders/cloud_shader/opengl_vertex.glsl b/client/shaders/cloud_shader/opengl_vertex.glsl new file mode 100644 index 000000000..4bc6eb65e --- /dev/null +++ b/client/shaders/cloud_shader/opengl_vertex.glsl @@ -0,0 +1,21 @@ +uniform vec4 emissiveColor; + +varying lowp vec4 varColor; + +varying vec3 eyeVec; + +void main(void) +{ + gl_Position = mWorldViewProj * inVertexPosition; + +#ifdef GL_ES + vec4 color = inVertexColor.bgra; +#else + vec4 color = inVertexColor; +#endif + + color *= emissiveColor; + varColor = color; + + eyeVec = -(mWorldView * inVertexPosition).xyz; +} diff --git a/client/shaders/stars_shader/opengl_fragment.glsl b/client/shaders/stars_shader/opengl_fragment.glsl index a9ed741bf..209b6dc89 100644 --- a/client/shaders/stars_shader/opengl_fragment.glsl +++ b/client/shaders/stars_shader/opengl_fragment.glsl @@ -1,6 +1,6 @@ -uniform vec4 starColor; +uniform vec4 emissiveColor; void main(void) { - gl_FragColor = starColor; + gl_FragColor = emissiveColor; } diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index af815c015..7e1676ffe 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -39,53 +39,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "client/renderingengine.h" -/* - CAOShaderConstantSetter -*/ - -//! Shader constant setter for passing material emissive color to the CAO object_shader -class CAOShaderConstantSetter : public IShaderConstantSetter -{ -public: - ~CAOShaderConstantSetter() override = default; - - void onSetConstants(video::IMaterialRendererServices *services) override - { - // Ambient color - video::SColorf emissive_color(m_emissive_color); - - float as_array[4] = { - emissive_color.r, - emissive_color.g, - emissive_color.b, - emissive_color.a, - }; - m_emissive_color_setting.set(as_array, services); - } - - void onSetMaterial(const video::SMaterial& material) override - { - m_emissive_color = material.EmissiveColor; - } - -private: - video::SColor m_emissive_color; - CachedPixelShaderSetting - m_emissive_color_setting{"emissiveColor"}; -}; - -class CAOShaderConstantSetterFactory : public IShaderConstantSetterFactory -{ -public: - CAOShaderConstantSetterFactory() - {} - - virtual IShaderConstantSetter* create() - { - return new CAOShaderConstantSetter(); - } -}; - /* ClientEnvironment */ @@ -97,8 +50,6 @@ ClientEnvironment::ClientEnvironment(ClientMap *map, m_texturesource(texturesource), m_client(client) { - auto *shdrsrc = m_client->getShaderSource(); - shdrsrc->addShaderConstantSetterFactory(new CAOShaderConstantSetterFactory()); } ClientEnvironment::~ClientEnvironment() diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index c23a1e3e9..b5ba4ccc8 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -107,7 +107,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) return false; } - if (m_rendering_engine->get_video_driver() == NULL) { + if (!m_rendering_engine->get_video_driver()) { errorstream << "Could not initialize video driver." << std::endl; return false; } @@ -125,51 +125,16 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); guienv = m_rendering_engine->get_gui_env(); - skin = guienv->getSkin(); - skin->setColor(gui::EGDC_WINDOW_SYMBOL, video::SColor(255, 255, 255, 255)); - skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255)); - skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0)); - skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30)); - skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0)); - skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50)); - skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255)); - - float density = rangelim(g_settings->getFloat("gui_scaling"), 0.5, 20) * - RenderingEngine::getDisplayDensity(); - skin->setSize(gui::EGDS_CHECK_BOX_WIDTH, (s32)(17.0f * density)); - skin->setSize(gui::EGDS_SCROLLBAR_SIZE, (s32)(14.0f * density)); - skin->setSize(gui::EGDS_WINDOW_BUTTON_WIDTH, (s32)(15.0f * density)); - if (density > 1.5f) { - std::string sprite_path = porting::path_share + "/textures/base/pack/"; - if (density > 3.5f) - sprite_path.append("checkbox_64.png"); - else if (density > 2.0f) - sprite_path.append("checkbox_32.png"); - else - sprite_path.append("checkbox_16.png"); - // Texture dimensions should be a power of 2 - gui::IGUISpriteBank *sprites = skin->getSpriteBank(); - video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); - video::ITexture *sprite_texture = driver->getTexture(sprite_path.c_str()); - if (sprite_texture) { - s32 sprite_id = sprites->addTextureAsSprite(sprite_texture); - if (sprite_id != -1) - skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, sprite_id); - } - } + init_guienv(guienv); g_fontengine = new FontEngine(guienv); - FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed."); - - // Irrlicht 1.8 input colours - skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128)); - skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49)); + FATAL_ERROR_IF(!g_fontengine, "Font engine creation failed."); // Create the menu clouds - if (!g_menucloudsmgr) - g_menucloudsmgr = m_rendering_engine->get_scene_manager()->createNewSceneManager(); - if (!g_menuclouds) - g_menuclouds = new Clouds(g_menucloudsmgr, -1, rand()); + // This is only global so it can be used by RenderingEngine::draw_load_screen(). + assert(!g_menucloudsmgr && !g_menuclouds); + g_menucloudsmgr = m_rendering_engine->get_scene_manager()->createNewSceneManager(); + g_menuclouds = new Clouds(g_menucloudsmgr, nullptr, -1, rand()); g_menuclouds->setHeight(100.0f); g_menuclouds->update(v3f(0, 0, 0), video::SColor(255, 240, 240, 255)); scene::ICameraSceneNode* camera; @@ -223,7 +188,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) guiroot = m_rendering_engine->get_gui_env()->addStaticText(L"", core::rect(0, 0, 10000, 10000)); - bool game_has_run = launch_game(error_message, reconnect_requested, + bool should_run_game = launch_game(error_message, reconnect_requested, start_data, cmd_args); // Reset the reconnect_requested flag @@ -232,13 +197,11 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // If skip_main_menu, we only want to startup once if (skip_main_menu && !first_loop) break; - first_loop = false; - if (!game_has_run) { + if (!should_run_game) { if (skip_main_menu) break; - continue; } @@ -246,9 +209,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) if (!m_rendering_engine->run() || *kill) break; - m_rendering_engine->get_video_driver()->setTextureCreationFlag( - video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map")); - if (g_settings->getBool("enable_touch")) { receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver); g_touchscreengui = receiver->m_touchscreengui; @@ -301,17 +261,18 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // If no main menu, show error and exit if (skip_main_menu) { - if (!error_message.empty()) { - verbosestream << "error_message = " - << error_message << std::endl; + if (!error_message.empty()) retval = false; - } break; } } // Menu-game loop + assert(g_menuclouds->getReferenceCount() == 1); g_menuclouds->drop(); + g_menuclouds = nullptr; + assert(g_menucloudsmgr->getReferenceCount() == 1); g_menucloudsmgr->drop(); + g_menucloudsmgr = nullptr; return retval; } @@ -373,6 +334,45 @@ void ClientLauncher::init_input() } } +void ClientLauncher::init_guienv(gui::IGUIEnvironment *guienv) +{ + gui::IGUISkin *skin = guienv->getSkin(); + + skin->setColor(gui::EGDC_WINDOW_SYMBOL, video::SColor(255, 255, 255, 255)); + skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255)); + skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0)); + skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30)); + skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0)); + skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50)); + skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255)); + skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128)); + skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49)); + + float density = rangelim(g_settings->getFloat("gui_scaling"), 0.5f, 20) * + RenderingEngine::getDisplayDensity(); + skin->setSize(gui::EGDS_CHECK_BOX_WIDTH, (s32)(17.0f * density)); + skin->setSize(gui::EGDS_SCROLLBAR_SIZE, (s32)(14.0f * density)); + skin->setSize(gui::EGDS_WINDOW_BUTTON_WIDTH, (s32)(15.0f * density)); + if (density > 1.5f) { + std::string sprite_path = porting::path_share + "/textures/base/pack/"; + if (density > 3.5f) + sprite_path.append("checkbox_64.png"); + else if (density > 2.0f) + sprite_path.append("checkbox_32.png"); + else + sprite_path.append("checkbox_16.png"); + // Texture dimensions should be a power of 2 + gui::IGUISpriteBank *sprites = skin->getSpriteBank(); + video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); + video::ITexture *sprite_texture = driver->getTexture(sprite_path.c_str()); + if (sprite_texture) { + s32 sprite_id = sprites->addTextureAsSprite(sprite_texture); + if (sprite_id != -1) + skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, sprite_id); + } + } +} + bool ClientLauncher::launch_game(std::string &error_message, bool reconnect_requested, GameStartData &start_data, const Settings &cmd_args) diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h index 395f83b9d..dc0794c88 100644 --- a/src/client/clientlauncher.h +++ b/src/client/clientlauncher.h @@ -38,6 +38,7 @@ private: void init_args(GameStartData &start_data, const Settings &cmd_args); bool init_engine(); void init_input(); + void init_guienv(gui::IGUIEnvironment *guienv); bool launch_game(std::string &error_message, bool reconnect_requested, GameStartData &start_data, const Settings &cmd_args); @@ -49,5 +50,4 @@ private: RenderingEngine *m_rendering_engine = nullptr; InputHandler *input = nullptr; MyEventReceiver *receiver = nullptr; - gui::IGUISkin *skin = nullptr; }; diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp index f07c2bcaf..3ab504371 100644 --- a/src/client/clouds.cpp +++ b/src/client/clouds.cpp @@ -18,10 +18,12 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "client/renderingengine.h" +#include "client/shader.h" #include "clouds.h" -#include "noise.h" #include "constants.h" #include "debug.h" +#include "irrlicht_changes/printing.h" +#include "noise.h" #include "profiler.h" #include "settings.h" #include @@ -40,35 +42,38 @@ static void cloud_3d_setting_changed(const std::string &settingname, void *data) ((Clouds *)data)->readSettings(); } -Clouds::Clouds(scene::ISceneManager* mgr, +Clouds::Clouds(scene::ISceneManager* mgr, IShaderSource *ssrc, s32 id, u32 seed ): scene::ISceneNode(mgr->getRootSceneNode(), mgr, id), m_seed(seed) { + m_enable_shaders = g_settings->getBool("enable_shaders"); + // menu clouds use shader-less clouds for simplicity (ssrc == NULL) + m_enable_shaders = m_enable_shaders && ssrc; + m_material.Lighting = false; m_material.BackfaceCulling = true; m_material.FogEnable = true; m_material.AntiAliasing = video::EAAM_SIMPLE; - m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; - m_material.forEachTexture([] (auto &tex) { - tex.MinFilter = video::ETMINF_NEAREST_MIPMAP_NEAREST; - tex.MagFilter = video::ETMAGF_NEAREST; - }); + if (m_enable_shaders) { + auto sid = ssrc->getShader("cloud_shader", TILE_MATERIAL_ALPHA); + m_material.MaterialType = ssrc->getShaderInfo(sid).material; + } else { + m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + } - m_params.height = 120; - m_params.density = 0.4f; - m_params.thickness = 16.0f; - m_params.color_bright = video::SColor(229, 240, 240, 255); - m_params.color_ambient = video::SColor(255, 0, 0, 0); - m_params.speed = v2f(0.0f, -2.0f); + m_params = SkyboxDefaults::getCloudDefaults(); readSettings(); g_settings->registerChangedCallback("enable_3d_clouds", &cloud_3d_setting_changed, this); updateBox(); + + m_meshbuffer.reset(new scene::SMeshBuffer()); + m_meshbuffer->setHardwareMappingHint(scene::EHM_DYNAMIC); } Clouds::~Clouds() @@ -82,38 +87,14 @@ void Clouds::OnRegisterSceneNode() if(IsVisible) { SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); - //SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); } ISceneNode::OnRegisterSceneNode(); } -void Clouds::render() +void Clouds::updateMesh() { - - if (m_params.density <= 0.0f) - return; // no need to do anything - - video::IVideoDriver* driver = SceneManager->getVideoDriver(); - - if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT) - //if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID) - return; - - ScopeProfiler sp(g_profiler, "Clouds::render()", SPT_AVG); - - int num_faces_to_draw = m_enable_3d ? 6 : 1; - - m_material.BackfaceCulling = m_enable_3d; - - driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); - driver->setMaterial(m_material); - - /* - Clouds move from Z+ towards Z- - */ - - const float cloud_full_radius = cloud_size * m_cloud_radius_i; + // Clouds move from Z+ towards Z- v2f camera_pos_2d(m_camera_pos.X, m_camera_pos.Z); // Position of cloud noise origin from the camera @@ -126,56 +107,61 @@ void Clouds::render() std::floor(center_of_drawing_in_noise_f.Y / cloud_size) ); + // Only update mesh if it has moved enough, this saves lots of GPU buffer uploads. + constexpr float max_d = 5 * BS; + + if (!m_mesh_valid) { + // mesh was never created or invalidated + } else if (m_mesh_origin.getDistanceFrom(m_origin) >= max_d) { + // clouds moved + } else if (center_of_drawing_in_noise_i != m_last_noise_center) { + // noise offset changed + // I think in practice this never happens due to the camera offset + // being smaller than the cloud size.(?) + } else { + return; + } + + ScopeProfiler sp(g_profiler, "Clouds::updateMesh()", SPT_AVG); + m_mesh_origin = m_origin; + m_last_noise_center = center_of_drawing_in_noise_i; + m_mesh_valid = true; + + const u32 num_faces_to_draw = m_enable_3d ? 6 : 1; + // The world position of the integer center point of drawing in the noise v2f world_center_of_drawing_in_noise_f = v2f( center_of_drawing_in_noise_i.X * cloud_size, center_of_drawing_in_noise_i.Y * cloud_size ) + m_origin; - /*video::SColor c_top(128,b*240,b*240,b*255); - video::SColor c_side_1(128,b*230,b*230,b*255); - video::SColor c_side_2(128,b*220,b*220,b*245); - video::SColor c_bottom(128,b*205,b*205,b*230);*/ + // Colors with primitive shading + video::SColorf c_top_f(m_color); video::SColorf c_side_1_f(m_color); video::SColorf c_side_2_f(m_color); video::SColorf c_bottom_f(m_color); - c_side_1_f.r *= 0.95; - c_side_1_f.g *= 0.95; - c_side_1_f.b *= 0.95; - c_side_2_f.r *= 0.90; - c_side_2_f.g *= 0.90; - c_side_2_f.b *= 0.90; - c_bottom_f.r *= 0.80; - c_bottom_f.g *= 0.80; - c_bottom_f.b *= 0.80; + if (m_enable_shaders) { + // shader mixes the base color, set via EmissiveColor + c_top_f = c_side_1_f = c_side_2_f = c_bottom_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); + } + c_side_1_f.r *= 0.95f; + c_side_1_f.g *= 0.95f; + c_side_1_f.b *= 0.95f; + c_side_2_f.r *= 0.90f; + c_side_2_f.g *= 0.90f; + c_side_2_f.b *= 0.90f; + c_bottom_f.r *= 0.80f; + c_bottom_f.g *= 0.80f; + c_bottom_f.b *= 0.80f; video::SColor c_top = c_top_f.toSColor(); video::SColor c_side_1 = c_side_1_f.toSColor(); video::SColor c_side_2 = c_side_2_f.toSColor(); video::SColor c_bottom = c_bottom_f.toSColor(); - // Get fog parameters for setting them back later - video::SColor fog_color(0,0,0,0); - video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR; - f32 fog_start = 0; - f32 fog_end = 0; - f32 fog_density = 0; - bool fog_pixelfog = false; - bool fog_rangefog = false; - driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density, - fog_pixelfog, fog_rangefog); - - // Set our own fog, unless it was already disabled - if (fog_start < FOG_RANGE_ALL) { - driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5, - cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog); - } - // Read noise std::vector grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2); - std::vector vertices; - vertices.reserve(16 * m_cloud_radius_i * m_cloud_radius_i); for(s16 zi = -m_cloud_radius_i; zi < m_cloud_radius_i; zi++) { u32 si = (zi + m_cloud_radius_i) * m_cloud_radius_i * 2 + m_cloud_radius_i; @@ -190,10 +176,23 @@ void Clouds::render() } } + + auto *mb = m_meshbuffer.get(); + { + const u32 vertex_count = num_faces_to_draw * 16 * m_cloud_radius_i * m_cloud_radius_i; + const u32 quad_count = vertex_count / 4; + const u32 index_count = quad_count * 6; + + // reserve memory + mb->Vertices.reallocate(vertex_count); + mb->Indices.reallocate(index_count); + } + #define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius)) #define INAREA(x, z, radius) \ ((x) >= -(radius) && (x) < (radius) && (z) >= -(radius) && (z) < (radius)) + mb->Vertices.set_used(0); for (s16 zi0= -m_cloud_radius_i; zi0 < m_cloud_radius_i; zi0++) for (s16 xi0= -m_cloud_radius_i; xi0 < m_cloud_radius_i; xi0++) { @@ -224,7 +223,7 @@ void Clouds::render() const f32 ry = m_enable_3d ? m_params.thickness * BS : 0.0f; const f32 rz = cloud_size / 2; - for(int i=0; iVertices.push_back(vertex); } } } - int quad_count = vertices.size() / 4; - std::vector indices; - indices.reserve(quad_count * 6); - for (int k = 0; k < quad_count; k++) { - indices.push_back(4 * k + 0); - indices.push_back(4 * k + 1); - indices.push_back(4 * k + 2); - indices.push_back(4 * k + 2); - indices.push_back(4 * k + 3); - indices.push_back(4 * k + 0); + mb->setDirty(scene::EBT_VERTEX); + + const u32 quad_count = mb->getVertexCount() / 4; + const u32 index_count = quad_count * 6; + // rewrite index array as needed + if (mb->getIndexCount() > index_count) { + mb->Indices.set_used(index_count); + mb->setDirty(scene::EBT_INDEX); + } else if (mb->getIndexCount() < index_count) { + const u32 start = mb->getIndexCount() / 6; + assert(start * 6 == mb->getIndexCount()); + for (u32 k = start; k < quad_count; k++) { + mb->Indices.push_back(4 * k + 0); + mb->Indices.push_back(4 * k + 1); + mb->Indices.push_back(4 * k + 2); + mb->Indices.push_back(4 * k + 2); + mb->Indices.push_back(4 * k + 3); + mb->Indices.push_back(4 * k + 0); + } + mb->setDirty(scene::EBT_INDEX); } - driver->drawVertexPrimitiveList(vertices.data(), vertices.size(), indices.data(), 2 * quad_count, - video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT); + + tracestream << "Cloud::updateMesh(): " << mb->getVertexCount() << " vertices" + << std::endl; +} + +void Clouds::render() +{ + if (m_params.density <= 0.0f) + return; // no need to do anything + + video::IVideoDriver* driver = SceneManager->getVideoDriver(); + + if (SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT) + return; + + updateMesh(); + + // Update position + { + v2f off_origin = m_origin - m_mesh_origin; + v3f rel(off_origin.X, 0, off_origin.Y); + rel -= intToFloat(m_camera_offset, BS); + setPosition(rel); + updateAbsolutePosition(); + } + + m_material.BackfaceCulling = m_enable_3d; + if (m_enable_shaders) + m_material.EmissiveColor = m_color.toSColor(); + + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); + driver->setMaterial(m_material); + + const float cloud_full_radius = cloud_size * m_cloud_radius_i; + + // Get fog parameters for setting them back later + video::SColor fog_color(0,0,0,0); + video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR; + f32 fog_start = 0; + f32 fog_end = 0; + f32 fog_density = 0; + bool fog_pixelfog = false; + bool fog_rangefog = false; + driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density, + fog_pixelfog, fog_rangefog); + + // Set our own fog, unless it was already disabled + if (fog_start < FOG_RANGE_ALL) { + driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5, + cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog); + } + + driver->drawMeshBuffer(m_meshbuffer.get()); // Restore fog settings driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density, @@ -346,13 +405,13 @@ void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse) { video::SColorf ambient(m_params.color_ambient); video::SColorf bright(m_params.color_bright); - m_camera_pos = camera_p; m_color.r = core::clamp(color_diffuse.r * bright.r, ambient.r, 1.0f); m_color.g = core::clamp(color_diffuse.g * bright.g, ambient.g, 1.0f); m_color.b = core::clamp(color_diffuse.b * bright.b, ambient.b, 1.0f); m_color.a = bright.a; // is the camera inside the cloud mesh? + m_camera_pos = camera_p; m_camera_inside_cloud = false; // default if (m_enable_3d) { float camera_height = camera_p.Y - BS * m_camera_offset.Y; @@ -369,9 +428,14 @@ void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse) void Clouds::readSettings() { - // Upper limit was chosen due to posible render bugs - m_cloud_radius_i = rangelim(g_settings->getU16("cloud_radius"), 1, 62); + // The code isn't designed to go over 64k vertices so the upper limits were + // chosen to avoid exactly that. + // refer to vertex_count in updateMesh() m_enable_3d = g_settings->getBool("enable_3d_clouds"); + const u16 maximum = m_enable_3d ? 62 : 25; + m_cloud_radius_i = rangelim(g_settings->getU16("cloud_radius"), 1, maximum); + + invalidateMesh(); } bool Clouds::gridFilled(int x, int y) const diff --git a/src/client/clouds.h b/src/client/clouds.h index 6db88d93c..23273a3c9 100644 --- a/src/client/clouds.h +++ b/src/client/clouds.h @@ -19,10 +19,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -#include "irrlichttypes_extrabloated.h" -#include #include "constants.h" +#include "irr_ptr.h" +#include "irrlichttypes_extrabloated.h" #include "skyparams.h" +#include + +class IShaderSource; // Menu clouds class Clouds; @@ -34,7 +37,7 @@ extern scene::ISceneManager *g_menucloudsmgr; class Clouds : public scene::ISceneNode { public: - Clouds(scene::ISceneManager* mgr, + Clouds(scene::ISceneManager* mgr, IShaderSource *ssrc, s32 id, u32 seed ); @@ -72,7 +75,7 @@ public: void update(const v3f &camera_p, const video::SColorf &color); - void updateCameraOffset(const v3s16 &camera_offset) + void updateCameraOffset(v3s16 camera_offset) { m_camera_offset = camera_offset; updateBox(); @@ -82,24 +85,29 @@ public: void setDensity(float density) { + if (m_params.density == density) + return; m_params.density = density; - // currently does not need bounding + invalidateMesh(); } - void setColorBright(const video::SColor &color_bright) + void setColorBright(video::SColor color_bright) { m_params.color_bright = color_bright; } - void setColorAmbient(const video::SColor &color_ambient) + void setColorAmbient(video::SColor color_ambient) { m_params.color_ambient = color_ambient; } void setHeight(float height) { - m_params.height = height; // add bounding when necessary + if (m_params.height == height) + return; + m_params.height = height; updateBox(); + invalidateMesh(); } void setSpeed(v2f speed) @@ -109,8 +117,11 @@ public: void setThickness(float thickness) { + if (m_params.thickness == thickness) + return; m_params.thickness = thickness; updateBox(); + invalidateMesh(); } bool isCameraInsideCloud() const { return m_camera_inside_cloud; } @@ -126,18 +137,33 @@ private: BS * 1000000.0f, height_bs + thickness_bs - BS * m_camera_offset.Y, BS * 1000000.0f); } + void updateMesh(); + void invalidateMesh() + { + m_mesh_valid = false; + } + bool gridFilled(int x, int y) const; video::SMaterial m_material; + irr_ptr m_meshbuffer; + // Value of m_origin at the time the mesh was last updated + v2f m_mesh_origin; + // Value of center_of_drawing_in_noise_i at the time the mesh was last updated + v2s16 m_last_noise_center; + // Was the mesh ever generated? + bool m_mesh_valid = false; + aabb3f m_box; + v2f m_origin; u16 m_cloud_radius_i; - bool m_enable_3d; u32 m_seed; v3f m_camera_pos; - v2f m_origin; + v3s16 m_camera_offset; - video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); - CloudParams m_params; bool m_camera_inside_cloud = false; + bool m_enable_shaders, m_enable_3d; + video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); + CloudParams m_params; }; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 330eebd95..6506521a3 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -812,7 +812,6 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) (m_prop.visual == "wielditem")); m_wield_meshnode->setScale(m_prop.visual_size / 2.0f); - m_wield_meshnode->setColor(video::SColor(0xFFFFFFFF)); } else { infostream<<"GenericCAO::addToScene(): \""< m_animation_timer_delta_pixel{"animationTimerDelta"}; CachedPixelShaderSetting m_day_light{"dayLight"}; - CachedPixelShaderSetting m_star_color{"starColor"}; CachedPixelShaderSetting m_eye_position_pixel{"eyePosition"}; CachedVertexShaderSetting m_eye_position_vertex{"eyePosition"}; CachedPixelShaderSetting m_minimap_yaw{"yawVec"}; @@ -473,10 +472,6 @@ public: get_sunlight_color(&sunlight, daynight_ratio); m_day_light.set(sunlight, services); - video::SColorf star_color = m_sky->getCurrentStarColor(); - float clr[4] = {star_color.r, star_color.g, star_color.b, star_color.a}; - m_star_color.set(clr, services); - u32 animation_timer = m_client->getEnv().getFrameTime() % 1000000; float animation_timer_f = (float)animation_timer / 100000.f; m_animation_timer_vertex.set(&animation_timer_f, services); @@ -529,7 +524,9 @@ public: m_bloom_radius_pixel.set(&m_bloom_radius, services); m_bloom_strength_pixel.set(&m_bloom_strength, services); } - float saturation = m_client->getEnv().getLocalPlayer()->getLighting().saturation; + + const auto &lighting = m_client->getEnv().getLocalPlayer()->getLighting(); + float saturation = lighting.saturation; m_saturation_pixel.set(&saturation, services); if (m_volumetric_light_enabled) { @@ -540,13 +537,13 @@ public: if (m_sky->getSunVisible()) { v3f sun_position = camera_node->getAbsolutePosition() + - 10000. * m_sky->getSunDirection(); + 10000.f * m_sky->getSunDirection(); transform.transformVect(sun_position); sun_position.normalize(); m_sun_position_pixel.set(sun_position, services); - float sun_brightness = rangelim(107.143f * m_sky->getSunDirection().dotProduct(v3f(0.f, 1.f, 0.f)), 0.f, 1.f); + float sun_brightness = core::clamp(107.143f * m_sky->getSunDirection().Y, 0.f, 1.f); m_sun_brightness_pixel.set(&sun_brightness, services); } else { m_sun_position_pixel.set(v3f(0.f, 0.f, -1.f), services); @@ -557,13 +554,13 @@ public: if (m_sky->getMoonVisible()) { v3f moon_position = camera_node->getAbsolutePosition() + - 10000. * m_sky->getMoonDirection(); + 10000.f * m_sky->getMoonDirection(); transform.transformVect(moon_position); moon_position.normalize(); m_moon_position_pixel.set(moon_position, services); - float moon_brightness = rangelim(107.143f * m_sky->getMoonDirection().dotProduct(v3f(0.f, 1.f, 0.f)), 0.f, 1.f); + float moon_brightness = core::clamp(107.143f * m_sky->getMoonDirection().Y, 0.f, 1.f); m_moon_brightness_pixel.set(&moon_brightness, services); } else { m_moon_position_pixel.set(v3f(0.f, 0.f, -1.f), services); @@ -571,7 +568,8 @@ public: float moon_brightness = 0.f; m_moon_brightness_pixel.set(&moon_brightness, services); } - float volumetric_light_strength = m_client->getEnv().getLocalPlayer()->getLighting().volumetric_light_strength; + + float volumetric_light_strength = lighting.volumetric_light_strength; m_volumetric_light_strength_pixel.set(&volumetric_light_strength, services); } } @@ -1099,6 +1097,8 @@ bool Game::startup(bool *kill, driver = device->getVideoDriver(); smgr = m_rendering_engine->get_scene_manager(); + driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map")); + smgr->getParameters()->setAttribute(scene::OBJ_LOADER_IGNORE_MATERIAL_FILES, true); // Reinit runData @@ -1454,7 +1454,7 @@ bool Game::createClient(const GameStartData &start_data) /* Clouds */ if (m_cache_enable_clouds) - clouds = new Clouds(smgr, -1, time(0)); + clouds = new Clouds(smgr, shader_src, -1, rand()); /* Skybox */ diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 9439a4492..e1641366e 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -97,7 +97,7 @@ Hud::Hud(Client *client, LocalPlayer *player, if (g_settings->getBool("enable_shaders")) { IShaderSource *shdrsrc = client->getShaderSource(); - u16 shader_id = shdrsrc->getShader( + auto shader_id = shdrsrc->getShader( m_mode == HIGHLIGHT_HALO ? "selection_shader" : "default_shader", TILE_MATERIAL_ALPHA); m_selection_material.MaterialType = shdrsrc->getShaderInfo(shader_id).material; } else { @@ -1100,24 +1100,23 @@ void drawItemStack( video::SColor basecolor = client->idef()->getItemstackColor(item, client); - u32 mc = mesh->getMeshBufferCount(); + const u32 mc = mesh->getMeshBufferCount(); + if (mc > imesh->buffer_colors.size()) + imesh->buffer_colors.resize(mc); for (u32 j = 0; j < mc; ++j) { scene::IMeshBuffer *buf = mesh->getMeshBuffer(j); - // we can modify vertices relatively fast, - // because these meshes are not buffered. - assert(buf->getHardwareMappingHint_Vertex() == scene::EHM_NEVER); video::SColor c = basecolor; - if (imesh->buffer_colors.size() > j) { - ItemPartColor *p = &imesh->buffer_colors[j]; - if (p->override_base) - c = p->color; - } + auto &p = imesh->buffer_colors[j]; + p.applyOverride(c); - if (imesh->needs_shading) - colorizeMeshBuffer(buf, &c); - else - setMeshBufferColor(buf, c); + if (p.needColorize(c)) { + buf->setDirty(scene::EBT_VERTEX); + if (imesh->needs_shading) + colorizeMeshBuffer(buf, &c); + else + setMeshBufferColor(buf, c); + } video::SMaterial &material = buf->getMaterial(); material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index 852220d06..afac89843 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -615,7 +615,7 @@ void Minimap::drawMinimap(core::rect rect) material.TextureLayers[1].Texture = data->heightmap_texture; if (m_enable_shaders && data->mode.type == MINIMAP_TYPE_SURFACE) { - u16 sid = m_shdrsrc->getShader("minimap_shader", TILE_MATERIAL_ALPHA); + auto sid = m_shdrsrc->getShader("minimap_shader", TILE_MATERIAL_ALPHA); material.MaterialType = m_shdrsrc->getShaderInfo(sid).material; } else { material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 59c1a086f..debfe8e21 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -94,7 +94,7 @@ class FogShaderConstantSetter : public IShaderConstantSetter public: void onSetConstants(video::IMaterialRendererServices *services) override { - auto *driver = RenderingEngine::get_video_driver(); + auto *driver = services->getVideoDriver(); assert(driver); video::SColor fog_color(0); @@ -314,15 +314,17 @@ void RenderingEngine::draw_load_screen(const std::wstring &text, gui::StaticText::add(guienv, text, textrect, false, false); guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); - if (sky && g_settings->getBool("menu_clouds")) { - g_menuclouds->step(dtime * 3); - g_menuclouds->render(); - get_video_driver()->beginScene(true, true, RenderingEngine::MENU_SKY_COLOR); - g_menucloudsmgr->drawAll(); - } else if (sky) - get_video_driver()->beginScene(true, true, RenderingEngine::MENU_SKY_COLOR); - else - get_video_driver()->beginScene(true, true, video::SColor(255, 0, 0, 0)); + auto *driver = get_video_driver(); + + if (sky) { + driver->beginScene(true, true, RenderingEngine::MENU_SKY_COLOR); + if (g_settings->getBool("menu_clouds")) { + g_menuclouds->step(dtime * 3); + g_menucloudsmgr->drawAll(); + } + } else { + driver->beginScene(true, true, video::SColor(255, 0, 0, 0)); + } // draw progress bar if ((percent >= 0) && (percent <= 100)) { @@ -367,7 +369,7 @@ void RenderingEngine::draw_load_screen(const std::wstring &text, } guienv->drawAll(); - get_video_driver()->endScene(); + driver->endScene(); guitext->remove(); } diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index e787af488..948485d82 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -90,7 +90,6 @@ public: bool setupTopLevelWindow(); bool setWindowIcon(); - static bool print_video_modes(); void cleanupMeshCache(); void removeMesh(const scene::IMesh* mesh); diff --git a/src/client/shader.cpp b/src/client/shader.cpp index ed4f618fe..c6de1ee35 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -217,13 +217,22 @@ class MainShaderConstantSetter : public IShaderConstantSetter // Texture matrix CachedVertexShaderSetting m_texture{"mTexture"}; + // commonly used way to pass material color to shader + video::SColor m_emissive_color; + CachedPixelShaderSetting m_emissive_color_setting{"emissiveColor"}; + public: ~MainShaderConstantSetter() = default; + virtual void onSetMaterial(const video::SMaterial& material) override + { + m_emissive_color = material.EmissiveColor; + } + virtual void onSetConstants(video::IMaterialRendererServices *services) override { video::IVideoDriver *driver = services->getVideoDriver(); - sanity_check(driver); + assert(driver); // Set world matrix core::matrix4 world = driver->getTransform(video::ETS_WORLD); @@ -244,6 +253,9 @@ public: m_world_view.set(worldView, services); m_texture.set(texture, services); } + + video::SColorf emissive_color(m_emissive_color); + m_emissive_color_setting.set(emissive_color, services); } }; @@ -545,11 +557,11 @@ ShaderInfo ShaderSource::generateShader(const std::string &name, return shaderinfo; video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - if (!driver->queryFeature(video::EVDF_ARB_GLSL)) { + video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices(); + if (!driver->queryFeature(video::EVDF_ARB_GLSL) || !gpu) { throw ShaderException(gettext("Shaders are enabled but GLSL is not " "supported by the driver.")); } - video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices(); // Create shaders header bool fully_programmable = driver->getDriverType() == video::EDT_OGLES2 || driver->getDriverType() == video::EDT_OPENGL3; @@ -610,14 +622,6 @@ ShaderInfo ShaderSource::generateShader(const std::string &name, #define textureFlags texture2 )"; - // Since this is the first time we're using the GL bindings be extra careful. - // This should be removed before 5.6.0 or similar. - if (!GL.GetString) { - errorstream << "OpenGL procedures were not loaded correctly, " - "please open a bug report with details about your platform/OS." << std::endl; - abort(); - } - bool use_discard = fully_programmable; // For renderers that should use discard instead of GL_ALPHA_TEST const char *renderer = reinterpret_cast(GL.GetString(GL.RENDERER)); diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 12eb7f0e8..d7e99fff7 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -77,6 +77,7 @@ Sky::Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShade // Create materials m_materials[0] = baseMaterial(); + // FIXME: shouldn't this check m_enable_shaders? m_materials[0].MaterialType = ssrc->getShaderInfo(ssrc->getShader("stars_shader", TILE_MATERIAL_ALPHA)).material; m_materials[0].Lighting = true; m_materials[0].ColorMaterial = video::ECM_NONE; @@ -683,11 +684,12 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day) float starbrightness = (0.25f - std::abs(tod)) * 20.0f; float alpha = clamp(starbrightness, day_opacity, 1.0f); - m_star_color = m_star_params.starcolor; - m_star_color.a *= alpha; - if (m_star_color.a <= 0.0f) // Stars are only drawn when not fully transparent + video::SColorf color(m_star_params.starcolor); + color.a *= alpha; + if (color.a <= 0.0f) // Stars are only drawn when not fully transparent return; - m_materials[0].DiffuseColor = m_materials[0].EmissiveColor = m_star_color.toSColor(); + m_materials[0].EmissiveColor = color.toSColor(); + auto sky_rotation = core::matrix4().setRotationAxisRadians(2.0f * M_PI * (wicked_time_of_day - 0.25f), v3f(0.0f, 0.0f, 1.0f)); auto world_matrix = driver->getTransform(video::ETS_WORLD); driver->setTransform(video::ETS_WORLD, world_matrix * sky_rotation); diff --git a/src/client/sky.h b/src/client/sky.h index c9064c038..2eadea561 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -114,7 +114,6 @@ public: void clearSkyboxTextures() { m_sky_params.textures.clear(); } void addTextureToSkybox(const std::string &texture, int material_id, ITextureSource *tsrc); - const video::SColorf &getCurrentStarColor() const { return m_star_color; } // Note: the Sky class doesn't use these values. It just stores them. void setFogDistance(s16 fog_distance) { m_sky_params.fog_distance = fog_distance; } @@ -210,7 +209,6 @@ private: u64 m_seed = 0; irr_ptr m_stars; - video::SColorf m_star_color; video::ITexture *m_sun_texture; video::ITexture *m_moon_texture; diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index c89f3bd4a..02039aa1c 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -508,21 +508,26 @@ void WieldMeshSceneNode::setColor(video::SColor c) u8 red = c.getRed(); u8 green = c.getGreen(); u8 blue = c.getBlue(); - u32 mc = mesh->getMeshBufferCount(); + + const u32 mc = mesh->getMeshBufferCount(); + if (mc > m_colors.size()) + m_colors.resize(mc); for (u32 j = 0; j < mc; j++) { video::SColor bc(m_base_color); - if ((m_colors.size() > j) && (m_colors[j].override_base)) - bc = m_colors[j].color; + m_colors[j].applyOverride(bc); video::SColor buffercolor(255, bc.getRed() * red / 255, bc.getGreen() * green / 255, bc.getBlue() * blue / 255); scene::IMeshBuffer *buf = mesh->getMeshBuffer(j); - if (m_enable_shaders) - setMeshBufferColor(buf, buffercolor); - else - colorizeMeshBuffer(buf, &buffercolor); + if (m_colors[j].needColorize(buffercolor)) { + buf->setDirty(scene::EBT_VERTEX); + if (m_enable_shaders) + setMeshBufferColor(buf, buffercolor); + else + colorizeMeshBuffer(buf, &buffercolor); + } } } @@ -536,8 +541,7 @@ void WieldMeshSceneNode::setNodeLightColor(video::SColor color) video::SMaterial &material = m_meshnode->getMaterial(i); material.EmissiveColor = color; } - } - else { + } else { setColor(color); } } @@ -557,6 +561,12 @@ void WieldMeshSceneNode::changeToMesh(scene::IMesh *mesh) dummymesh->drop(); // m_meshnode grabbed it } else { m_meshnode->setMesh(mesh); + // without shaders recolored often for lighting + // otherwise only once + if (m_enable_shaders) + mesh->setHardwareMappingHint(scene::EHM_STATIC); + else + mesh->setHardwareMappingHint(scene::EHM_DYNAMIC); } m_meshnode->forEachMaterial([this] (auto &mat) { @@ -651,8 +661,7 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result) } } - u32 mc = mesh->getMeshBufferCount(); - for (u32 i = 0; i < mc; ++i) { + for (u32 i = 0; i < mesh->getMeshBufferCount(); ++i) { scene::IMeshBuffer *buf = mesh->getMeshBuffer(i); video::SMaterial &material = buf->getMaterial(); material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; @@ -668,6 +677,12 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result) rotateMeshXZby(mesh, -45); rotateMeshYZby(mesh, -30); } + + // might need to be re-colorized, this is done only when needed + if (mesh) { + mesh->setHardwareMappingHint(scene::EHM_DYNAMIC, scene::EBT_VERTEX); + mesh->setHardwareMappingHint(scene::EHM_STATIC, scene::EBT_INDEX); + } result->mesh = mesh; } @@ -722,11 +737,10 @@ void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool use_shaders, bool set_material, const video::E_MATERIAL_TYPE *mattype, std::vector *colors, bool apply_scale) { - u32 mc = mesh->getMeshBufferCount(); + const u32 mc = mesh->getMeshBufferCount(); // Allocate colors for existing buffers colors->clear(); - for (u32 i = 0; i < mc; ++i) - colors->push_back(ItemPartColor()); + colors->resize(mc); for (u32 i = 0; i < mc; ++i) { const TileSpec *tile = &(f.tiles[i]); @@ -741,11 +755,11 @@ void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, mesh->addMeshBuffer(copy); copy->drop(); buf = copy; - colors->push_back( - ItemPartColor(layer->has_color, layer->color)); + colors->emplace_back(layer->has_color, layer->color); } else { (*colors)[i] = ItemPartColor(layer->has_color, layer->color); } + video::SMaterial &material = buf->getMaterial(); if (set_material) layer->applyMaterialOptions(material); @@ -768,6 +782,7 @@ void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, } material.setTexture(2, layer->flags_texture); } + if (apply_scale && tile->world_aligned) { u32 n = buf->getVertexCount(); for (u32 k = 0; k != n; ++k) diff --git a/src/client/wieldmesh.h b/src/client/wieldmesh.h index be0867e43..6358a6665 100644 --- a/src/client/wieldmesh.h +++ b/src/client/wieldmesh.h @@ -29,38 +29,54 @@ class ITextureSource; struct ContentFeatures; class ShadowRenderer; -/*! +/* * Holds color information of an item mesh's buffer. */ -struct ItemPartColor +class ItemPartColor { - /*! - * If this is false, the global base color of the item - * will be used instead of the specific color of the - * buffer. + /* + * Optional color that overrides the global base color. */ - bool override_base = false; - /*! - * The color of the buffer. + video::SColor override_color; + /* + * Stores the last color this mesh buffer was colorized as. */ - video::SColor color = 0; + video::SColor last_colorized; + + // saves some bytes compared to two std::optionals + bool override_color_set = false; + bool last_colorized_set = false; + +public: ItemPartColor() = default; ItemPartColor(bool override, video::SColor color) : - override_base(override), color(color) - { + override_color(color), override_color_set(override) + {} + + void applyOverride(video::SColor &dest) const { + if (override_color_set) + dest = override_color; + } + + bool needColorize(video::SColor target) { + if (last_colorized_set && target == last_colorized) + return false; + last_colorized_set = true; + last_colorized = target; + return true; } }; struct ItemMesh { scene::IMesh *mesh = nullptr; - /*! + /* * Stores the color of each mesh buffer. */ std::vector buffer_colors; - /*! + /* * If false, all faces of the item should have the same brightness. * Disables shading based on normal vectors. */ diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index a0e4055b8..923ca4bcd 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -19,25 +19,26 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiEngine.h" -#include -#include -#include "client/renderingengine.h" -#include "scripting_mainmenu.h" -#include "config.h" -#include "version.h" -#include "porting.h" -#include "filesys.h" -#include "settings.h" -#include "guiMainMenu.h" -#include "sound.h" -#include "httpfetch.h" -#include "log.h" #include "client/fontengine.h" #include "client/guiscalingfilter.h" -#include "irrlicht_changes/static_text.h" +#include "client/renderingengine.h" +#include "client/shader.h" #include "client/tile.h" +#include "config.h" #include "content/content.h" #include "content/mods.h" +#include "filesys.h" +#include "guiMainMenu.h" +#include "httpfetch.h" +#include "irrlicht_changes/static_text.h" +#include "log.h" +#include "porting.h" +#include "scripting_mainmenu.h" +#include "settings.h" +#include "sound.h" +#include "version.h" +#include +#include #if USE_SOUND #include "client/sound/sound_openal.h" @@ -139,6 +140,10 @@ GUIEngine::GUIEngine(JoystickController *joystick, // create texture source m_texture_source = std::make_unique(rendering_engine->get_video_driver()); + // create shader source + // (currently only used by clouds) + m_shader_source.reset(createShaderSource()); + // create soundmanager #if USE_SOUND if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) { @@ -285,10 +290,10 @@ bool GUIEngine::loadMainMenuScript() void GUIEngine::run() { IrrlichtDevice *device = m_rendering_engine->get_raw_device(); + video::IVideoDriver *driver = device->getVideoDriver(); + // Always create clouds because they may or may not be // needed based on the game selected - video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); - cloudInit(); unsigned int text_height = g_fontengine->getTextHeight(); @@ -375,23 +380,24 @@ GUIEngine::~GUIEngine() m_sound_manager.reset(); - m_irr_toplefttext->setText(L""); + m_irr_toplefttext->remove(); - //clean up texture pointers + m_cloud.clouds.reset(); + + // delete textures for (image_definition &texture : m_textures) { if (texture.texture) m_rendering_engine->get_video_driver()->removeTexture(texture.texture); } - - m_texture_source.reset(); - - m_cloud.clouds.reset(); } /******************************************************************************/ void GUIEngine::cloudInit() { - m_cloud.clouds = make_irr(m_smgr, -1, rand()); + m_shader_source->addShaderConstantSetterFactory( + new FogShaderConstantSetterFactory()); + + m_cloud.clouds = make_irr(m_smgr, m_shader_source.get(), -1, rand()); m_cloud.clouds->setHeight(100.0f); m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255,240,240,255)); @@ -404,7 +410,6 @@ void GUIEngine::cloudInit() void GUIEngine::drawClouds(float dtime) { m_cloud.clouds->step(dtime*3); - m_cloud.clouds->render(); m_smgr->drawAll(); } diff --git a/src/gui/guiEngine.h b/src/gui/guiEngine.h index eb3e01f62..688648be1 100644 --- a/src/gui/guiEngine.h +++ b/src/gui/guiEngine.h @@ -54,6 +54,7 @@ struct image_definition { class GUIEngine; class RenderingEngine; class MainMenuScripting; +class IWritableShaderSource; struct MainMenuData; /******************************************************************************/ @@ -203,7 +204,9 @@ private: MainMenuData *m_data = nullptr; /** texture source */ std::unique_ptr m_texture_source; - /** sound manager*/ + /** shader source */ + std::unique_ptr m_shader_source; + /** sound manager */ std::unique_ptr m_sound_manager; /** representation of form source to be used in mainmenu formspec */ diff --git a/src/itemdef.cpp b/src/itemdef.cpp index bd08f1e2b..363b94983 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -466,10 +466,6 @@ public: if (!inventory_image.empty()) cc->inventory_texture = tsrc->getTexture(inventory_image); getItemMesh(client, item, &(cc->wield_mesh)); - // note: vertices are modified frequently (see hud.cpp) so only indices - // can be mapped - if (auto mesh = cc->wield_mesh.mesh) - mesh->setHardwareMappingHint(scene::EHM_STATIC, scene::EBT_INDEX); cc->palette = tsrc->getPalette(def.palette_image); From 00a3e6bbd70b25c2a749026bff9797bc73915b8c Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Wed, 24 Jan 2024 21:09:08 +0100 Subject: [PATCH 10/91] Touchscreen: Allow camera movement while digging without touch_use_crosshair --- src/gui/touchscreengui.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index d6f22acd2..861eaa295 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -832,14 +832,12 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_move_pos = touch_pos; m_pointer_pos[event.TouchInput.ID] = touch_pos; - if (m_tap_state == TapState::None || m_draw_crosshair) { - // adapt to similar behavior as pc screen - const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f) * 3.0f; + // adapt to similar behavior as pc screen + const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f) * 3.0f; - // update camera_yaw and camera_pitch - m_camera_yaw_change -= dir_free.X * d; - m_camera_pitch_change += dir_free.Y * d; - } + // update camera_yaw and camera_pitch + m_camera_yaw_change -= dir_free.X * d; + m_camera_pitch_change += dir_free.Y * d; } } From fa0745f7dafea064af7df7771727220694ec153c Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Sat, 27 Jan 2024 19:16:23 +0100 Subject: [PATCH 11/91] Adjust touchscreen_sensitivity to display density --- src/gui/touchscreengui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 861eaa295..d2a0b16c0 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -832,8 +832,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_move_pos = touch_pos; m_pointer_pos[event.TouchInput.ID] = touch_pos; - // adapt to similar behavior as pc screen - const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f) * 3.0f; + const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f) + * 6.0f / RenderingEngine::getDisplayDensity(); // update camera_yaw and camera_pitch m_camera_yaw_change -= dir_free.X * d; From aac616fcc5ce5780de9f17e4ebe170fc6b62ae5f Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Mon, 29 Jan 2024 18:38:03 +0100 Subject: [PATCH 12/91] Avoid visible camera jumps because of touchscreen_threshold --- src/gui/touchscreengui.cpp | 25 +++++++++++++------------ src/gui/touchscreengui.h | 2 ++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index d2a0b16c0..07fe90585 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -718,6 +718,7 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) // By the way: Android reuses pointer IDs, so m_pointer_pos[evt_id] // will be overwritten soon anyway. + m_pointer_downpos.erase(evt_id); m_pointer_pos.erase(evt_id); } @@ -808,6 +809,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) } } + m_pointer_downpos[event.TouchInput.ID] = touch_pos; m_pointer_pos[event.TouchInput.ID] = touch_pos; } else if (event.TouchInput.Event == ETIE_LEFT_UP) { @@ -820,25 +822,24 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_pointer_pos[event.TouchInput.ID] == touch_pos) return; + const v2s32 dir_free_original = touch_pos - m_pointer_downpos[event.TouchInput.ID]; const v2s32 free_joystick_center = m_pointer_pos[event.TouchInput.ID]; const v2s32 dir_free = touch_pos - free_joystick_center; const double touch_threshold_sq = m_touchscreen_threshold * m_touchscreen_threshold; if (m_has_move_id && event.TouchInput.ID == m_move_id) { - if (dir_free.getLengthSQ() > touch_threshold_sq || m_move_has_really_moved) { + m_move_pos = touch_pos; + m_pointer_pos[event.TouchInput.ID] = touch_pos; + + // update camera_yaw and camera_pitch + const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f) + * 6.0f / RenderingEngine::getDisplayDensity(); + m_camera_yaw_change -= dir_free.X * d; + m_camera_pitch_change += dir_free.Y * d; + + if (dir_free_original.getLengthSQ() > touch_threshold_sq) m_move_has_really_moved = true; - - m_move_pos = touch_pos; - m_pointer_pos[event.TouchInput.ID] = touch_pos; - - const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f) - * 6.0f / RenderingEngine::getDisplayDensity(); - - // update camera_yaw and camera_pitch - m_camera_yaw_change -= dir_free.X * d; - m_camera_pitch_change += dir_free.Y * d; - } } if (m_has_joystick_id && event.TouchInput.ID == m_joystick_id) { diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 104c75eba..959f7ceb5 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -295,6 +295,8 @@ private: // apply joystick status void applyJoystickStatus(); + // map to store the IDs and original positions of currently pressed pointers + std::unordered_map m_pointer_downpos; // map to store the IDs and positions of currently pressed pointers std::unordered_map m_pointer_pos; From e40417f6875015119ed9a292f53ee0afc912209c Mon Sep 17 00:00:00 2001 From: grorp Date: Fri, 1 Mar 2024 17:12:13 +0100 Subject: [PATCH 13/91] Allow giving "pointabilities" to Lua raycasts (#14390) --- doc/lua_api.md | 23 ++++++++------- games/devtest/mods/unittests/init.lua | 1 + games/devtest/mods/unittests/raycast.lua | 36 ++++++++++++++++++++++++ src/script/lua_api/l_env.cpp | 6 +++- 4 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 games/devtest/mods/unittests/raycast.lua diff --git a/doc/lua_api.md b/doc/lua_api.md index 2eefacc08..6dbc58cb0 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -6202,13 +6202,16 @@ Environment access * Returns the position of the blocking node when `false` * `pos1`: First position * `pos2`: Second position -* `minetest.raycast(pos1, pos2, objects, liquids)`: returns `Raycast` +* `minetest.raycast(pos1, pos2, objects, liquids, pointabilities)`: returns `Raycast` * Creates a `Raycast` object. * `pos1`: start of the ray * `pos2`: end of the ray * `objects`: if false, only nodes will be returned. Default is `true`. * `liquids`: if false, liquid nodes (`liquidtype ~= "none"`) won't be returned. Default is `false`. + * `pointabilities`: Allows overriding the `pointable` property of + nodes and objects. Uses the same format as the `pointabilities` property + of item definitions. Default is `nil`. * `minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)` * returns table containing path that can be walked on * returns a table of 3D points representing a path from `pos1` to `pos2` or @@ -8932,16 +8935,16 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and -- even those for which `pointable = false` pointabilities = { - nodes = { - ["default:stone"] = "blocking", - ["group:leaves"] = false, - }, - objects = { - ["modname:entityname"] = true, - ["group:ghosty"] = true, -- (an armor group) - } + nodes = { + ["default:stone"] = "blocking", + ["group:leaves"] = false, + }, + objects = { + ["modname:entityname"] = true, + ["group:ghosty"] = true, -- (an armor group) + }, }, - -- Contains lists to override the `pointable` property of pointed nodes and objects. + -- Contains lists to override the `pointable` property of nodes and objects. -- The index can be a node/entity name or a group with the prefix `"group:"`. -- (For objects `armor_groups` are used and for players the entity name is irrelevant.) -- If multiple fields fit, the following priority order is applied: diff --git a/games/devtest/mods/unittests/init.lua b/games/devtest/mods/unittests/init.lua index edba2c3d2..f048b7aa6 100644 --- a/games/devtest/mods/unittests/init.lua +++ b/games/devtest/mods/unittests/init.lua @@ -182,6 +182,7 @@ dofile(modpath .. "/get_version.lua") dofile(modpath .. "/itemstack_equals.lua") dofile(modpath .. "/content_ids.lua") dofile(modpath .. "/metadata.lua") +dofile(modpath .. "/raycast.lua") -------------- diff --git a/games/devtest/mods/unittests/raycast.lua b/games/devtest/mods/unittests/raycast.lua new file mode 100644 index 000000000..08d6a1120 --- /dev/null +++ b/games/devtest/mods/unittests/raycast.lua @@ -0,0 +1,36 @@ +local function raycast_with_pointabilities(start_pos, end_pos, pointabilities) + local ray = core.raycast(start_pos, end_pos, nil, nil, pointabilities) + for hit in ray do + if hit.type == "node" then + return hit.under + end + end + return nil +end + +local function test_raycast_pointabilities(player, pos1) + local pos2 = pos1:offset(0, 0, 1) + local pos3 = pos1:offset(0, 0, 2) + + local oldnode1 = core.get_node(pos1) + local oldnode2 = core.get_node(pos2) + local oldnode3 = core.get_node(pos3) + core.swap_node(pos1, {name = "air"}) + core.swap_node(pos2, {name = "testnodes:not_pointable"}) + core.swap_node(pos3, {name = "testnodes:pointable"}) + + local p = nil + assert(raycast_with_pointabilities(pos1, pos3, p) == pos3) + + p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities + assert(raycast_with_pointabilities(pos1, pos3, p) == nil) + + p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities + assert(raycast_with_pointabilities(pos1, pos3, p) == pos2) + + core.swap_node(pos1, oldnode1) + core.swap_node(pos2, oldnode2) + core.swap_node(pos3, oldnode3) +end + +unittests.register("test_raycast_pointabilities", test_raycast_pointabilities, {map=true}) diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 39f36a31a..c6a427e48 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -177,6 +177,7 @@ int LuaRaycast::create_object(lua_State *L) bool objects = true; bool liquids = false; + std::optional pointabilities = std::nullopt; v3f pos1 = checkFloatPos(L, 1); v3f pos2 = checkFloatPos(L, 2); @@ -186,9 +187,12 @@ int LuaRaycast::create_object(lua_State *L) if (lua_isboolean(L, 4)) { liquids = readParam(L, 4); } + if (lua_istable(L, 5)) { + pointabilities = read_pointabilities(L, 5); + } LuaRaycast *o = new LuaRaycast(core::line3d(pos1, pos2), - objects, liquids, std::nullopt); + objects, liquids, pointabilities); *(void **) (lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, className); From e73e562a63c3ee450755f8dc6432af08fedea932 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 1 Mar 2024 18:21:47 +0100 Subject: [PATCH 14/91] Allow curl to use all content encodings --- src/httpfetch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index 355ace357..b5fece2e6 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -236,7 +236,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_, curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3); - curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip"); + curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); // = all supported ones std::string bind_address = g_settings->get("bind_address"); if (!bind_address.empty()) { From b10797b3d5a44bcdfef47ee5ac05ae9f1cbccc20 Mon Sep 17 00:00:00 2001 From: Desour Date: Sat, 2 Mar 2024 01:47:03 +0100 Subject: [PATCH 15/91] Add missing include in container.h BUILD_BENCHMAKRS builds were broken. --- src/util/container.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/container.h b/src/util/container.h index 9a52778d4..a6e302e2c 100644 --- a/src/util/container.h +++ b/src/util/container.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes.h" +#include "debug.h" // sanity_check #include "exceptions.h" #include "threading/mutex_auto_lock.h" #include "threading/semaphore.h" From cdce33dd05cfc9c13900e5a7cffcc41f8051237b Mon Sep 17 00:00:00 2001 From: Desour Date: Sat, 2 Mar 2024 01:50:16 +0100 Subject: [PATCH 16/91] Fix some narrowing warnings --- src/benchmark/benchmark_mapblock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/benchmark/benchmark_mapblock.cpp b/src/benchmark/benchmark_mapblock.cpp index 5522276f9..3ce202240 100644 --- a/src/benchmark/benchmark_mapblock.cpp +++ b/src/benchmark/benchmark_mapblock.cpp @@ -27,7 +27,7 @@ static void allocateSome(MBContainer &vec, u32 n) { vec.reserve(vec.size() + n); for (u32 i = 0; i < n; i++) { - auto *mb = new MapBlock({i & 0xff, 0, i >> 8}, nullptr); + auto *mb = new MapBlock(v3s16(i & 0xff, 0, (i >> 8) & S16_MAX), nullptr); vec.push_back(mb); } } From aaf77025b6b79db3991a5e0799fc5c1a65995317 Mon Sep 17 00:00:00 2001 From: cx384 Date: Tue, 27 Feb 2024 10:56:22 +0100 Subject: [PATCH 17/91] Split up tile.cpp/h --- src/client/CMakeLists.txt | 2 + src/client/camera.h | 2 +- src/client/client.cpp | 2 +- src/client/content_cao.cpp | 2 +- src/client/content_cso.cpp | 1 - src/client/game.cpp | 4 +- src/client/imagefilters.cpp | 37 + src/client/imagefilters.h | 8 + src/client/mapblock_mesh.cpp | 1 + src/client/mapblock_mesh.h | 2 + src/client/particles.h | 1 - src/client/shader.h | 1 - src/client/texturepaths.cpp | 154 ++ src/client/texturepaths.h | 44 + src/client/texturesource.cpp | 2493 +++++++++++++++++++++++++++++ src/client/texturesource.h | 93 ++ src/client/tile.cpp | 2669 +------------------------------- src/client/tile.h | 111 -- src/content/subgames.cpp | 2 +- src/gui/StyleSpec.h | 2 +- src/gui/guiAnimatedImage.cpp | 1 - src/gui/guiBackgroundImage.cpp | 1 + src/gui/guiBackgroundImage.h | 4 +- src/gui/guiButton.cpp | 1 - src/gui/guiChatConsole.cpp | 2 +- src/gui/guiEngine.cpp | 1 + src/gui/guiEngine.h | 1 - src/gui/guiFormSpecMenu.cpp | 1 - src/gui/guiHyperText.cpp | 1 - src/gui/guiTable.cpp | 2 +- src/gui/touchscreengui.h | 1 - src/itemdef.cpp | 1 - src/itemdef.h | 2 +- src/nodedef.cpp | 2 +- 34 files changed, 2851 insertions(+), 2801 deletions(-) create mode 100644 src/client/texturepaths.cpp create mode 100644 src/client/texturepaths.h create mode 100644 src/client/texturesource.cpp create mode 100644 src/client/texturesource.h diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 846a5b782..f2aa511b7 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -67,6 +67,8 @@ set(client_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/shader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sky.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/texturepaths.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/texturesource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wieldmesh.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadows.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadowsrender.cpp diff --git a/src/client/camera.h b/src/client/camera.h index 1d794d166..d6aa0bc54 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_extrabloated.h" #include "inventory.h" -#include "client/tile.h" +#include "util/numeric.h" #include "client/localplayer.h" #include #include diff --git a/src/client/client.cpp b/src/client/client.cpp index ba4c8ee98..914b9ce35 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/gameui.h" #include "client/renderingengine.h" #include "client/sound.h" -#include "client/tile.h" +#include "client/texturepaths.h" #include "client/mesh_generator_thread.h" #include "client/particles.h" #include "client/localplayer.h" diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 6506521a3..9fb110fdc 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/client.h" #include "client/renderingengine.h" #include "client/sound.h" -#include "client/tile.h" +#include "client/texturesource.h" #include "client/mapblock_mesh.h" #include "util/basic_macros.h" #include "util/numeric.h" diff --git a/src/client/content_cso.cpp b/src/client/content_cso.cpp index d61eb314a..d6c3fd3ef 100644 --- a/src/client/content_cso.cpp +++ b/src/client/content_cso.cpp @@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_cso.h" #include -#include "client/tile.h" #include "clientenvironment.h" #include "client.h" #include "map.h" diff --git a/src/client/game.cpp b/src/client/game.cpp index f4d74cbd2..9459b3204 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/clientevent.h" #include "client/gameui.h" #include "client/inputhandler.h" -#include "client/tile.h" // For TextureSource +#include "client/texturepaths.h" #include "client/keys.h" #include "client/joystick_controller.h" #include "client/mapblock_mesh.h" @@ -1383,7 +1383,7 @@ void Game::copyServerClientCache() { // It would be possible to let the client directly read the media files // from where the server knows they are. But aside from being more complicated - // it would also *not* fill the media cache and cause slower joining of + // it would also *not* fill the media cache and cause slower joining of // remote servers. // (Imagine that you launch a game once locally and then connect to a server.) diff --git a/src/client/imagefilters.cpp b/src/client/imagefilters.cpp index 55dedd09d..7c4dc094f 100644 --- a/src/client/imagefilters.cpp +++ b/src/client/imagefilters.cpp @@ -272,3 +272,40 @@ void imageScaleNNAA(video::IImage *src, const core::rect &srcrect, video::I dest->setPixel(dx, dy, pxl); } } + +/** + * Check and align image to npot2 if required by hardware + * @param image image to check for npot2 alignment + * @param driver driver to use for image operations + * @return image or copy of image aligned to npot2 + */ +video::IImage *Align2Npot2(video::IImage *image, + video::IVideoDriver *driver) +{ + if (image == NULL) + return image; + + if (driver->queryFeature(video::EVDF_TEXTURE_NPOT)) + return image; + + core::dimension2d dim = image->getDimension(); + unsigned int height = npot2(dim.Height); + unsigned int width = npot2(dim.Width); + + if (dim.Height == height && dim.Width == width) + return image; + + if (dim.Height > height) + height *= 2; + if (dim.Width > width) + width *= 2; + + video::IImage *targetimage = + driver->createImage(video::ECF_A8R8G8B8, + core::dimension2d(width, height)); + + if (targetimage != NULL) + image->copyToScaling(targetimage); + image->drop(); + return targetimage; +} diff --git a/src/client/imagefilters.h b/src/client/imagefilters.h index c9bdefbb6..e6cbf2d29 100644 --- a/src/client/imagefilters.h +++ b/src/client/imagefilters.h @@ -41,3 +41,11 @@ void imageCleanTransparent(video::IImage *src, u32 threshold); * and downscaling. */ void imageScaleNNAA(video::IImage *src, const core::rect &srcrect, video::IImage *dest); + +/* Check and align image to npot2 if required by hardware + * @param image image to check for npot2 alignment + * @param driver driver to use for image operations + * @return image or copy of image aligned to npot2 + */ +video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver); + diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 14434d8c5..1d74b70cb 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "client/texturesource.h" /* MeshMakeData diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 09708799e..7cd368762 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_extrabloated.h" +#include "util/numeric.h" #include "client/tile.h" #include "voxel.h" #include @@ -29,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class Client; class NodeDefManager; class IShaderSource; +class ITextureSource; /* Mesh making stuff diff --git a/src/client/particles.h b/src/client/particles.h index 8b7c30946..2c8ceafa4 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "irrlichttypes_extrabloated.h" -#include "client/tile.h" #include "localplayer.h" #include "../particles.h" diff --git a/src/client/shader.h b/src/client/shader.h index da4715545..72dac0833 100644 --- a/src/client/shader.h +++ b/src/client/shader.h @@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_bloated.h" #include #include -#include "tile.h" #include "nodedef.h" class IGameDef; diff --git a/src/client/texturepaths.cpp b/src/client/texturepaths.cpp new file mode 100644 index 000000000..b4bb93ee7 --- /dev/null +++ b/src/client/texturepaths.cpp @@ -0,0 +1,154 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "texturepaths.h" + +#include "util/container.h" +#include "settings.h" +#include "filesys.h" +#include "porting.h" + +/* + A cache from texture name to texture path +*/ +static MutexedMap g_texturename_to_path_cache; + +/* + Replaces the filename extension. + eg: + std::string image = "a/image.png" + replace_ext(image, "jpg") + -> image = "a/image.jpg" + Returns true on success. +*/ +static bool replace_ext(std::string &path, const char *ext) +{ + if (ext == NULL) + return false; + // Find place of last dot, fail if \ or / found. + s32 last_dot_i = -1; + for (s32 i=path.size()-1; i>=0; i--) + { + if (path[i] == '.') + { + last_dot_i = i; + break; + } + + if (path[i] == '\\' || path[i] == '/') + break; + } + // If not found, return an empty string + if (last_dot_i == -1) + return false; + // Else make the new path + path = path.substr(0, last_dot_i+1) + ext; + return true; +} + +/* + Find out the full path of an image by trying different filename + extensions. + If failed, return "". +*/ +std::string getImagePath(std::string path) +{ + // A NULL-ended list of possible image extensions + const char *extensions[] = { "png", "jpg", "bmp", "tga", NULL }; + // If there is no extension, assume PNG + if (removeStringEnd(path, extensions).empty()) + path = path + ".png"; + // Check paths until something is found to exist + const char **ext = extensions; + do{ + bool r = replace_ext(path, *ext); + if (!r) + return ""; + if (fs::PathExists(path)) + return path; + } + while((++ext) != NULL); + + return ""; +} + +/* + Gets the path to a texture by first checking if the texture exists + in texture_path and if not, using the data path. + Checks all supported extensions by replacing the original extension. + If not found, returns "". + Utilizes a thread-safe cache. +*/ +std::string getTexturePath(const std::string &filename, bool *is_base_pack) +{ + std::string fullpath; + + // This can set a wrong value on cached textures, but is irrelevant because + // is_base_pack is only passed when initializing the textures the first time + if (is_base_pack) + *is_base_pack = false; + /* + Check from cache + */ + bool incache = g_texturename_to_path_cache.get(filename, &fullpath); + if (incache) + return fullpath; + + /* + Check from texture_path + */ + for (const auto &path : getTextureDirs()) { + std::string testpath = path + DIR_DELIM; + testpath.append(filename); + // Check all filename extensions. Returns "" if not found. + fullpath = getImagePath(testpath); + if (!fullpath.empty()) + break; + } + + /* + Check from default data directory + */ + if (fullpath.empty()) + { + std::string base_path = porting::path_share + DIR_DELIM + "textures" + + DIR_DELIM + "base" + DIR_DELIM + "pack"; + std::string testpath = base_path + DIR_DELIM + filename; + // Check all filename extensions. Returns "" if not found. + fullpath = getImagePath(testpath); + if (is_base_pack && !fullpath.empty()) + *is_base_pack = true; + } + + // Add to cache (also an empty result is cached) + g_texturename_to_path_cache.set(filename, fullpath); + + // Finally return it + return fullpath; +} + +void clearTextureNameCache() +{ + g_texturename_to_path_cache.clear(); +} + +std::vector getTextureDirs() +{ + return fs::GetRecursiveDirs(g_settings->get("texture_path")); +} diff --git a/src/client/texturepaths.h b/src/client/texturepaths.h new file mode 100644 index 000000000..38ed0325d --- /dev/null +++ b/src/client/texturepaths.h @@ -0,0 +1,44 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include +#include + +// Texture paths get cached and this clears the Cache. +void clearTextureNameCache(); + +// Find out the full path of an image by trying different filename extensions. +// If failed, return "". +std::string getImagePath(std::string path); + +/* Gets the path to a texture by first checking if the texture exists + * in texture_path and if not, using the data path. + * + * Checks all supported extensions by replacing the original extension. + * + * If not found, returns "". + * + * Utilizes a thread-safe cache. +*/ +std::string getTexturePath(const std::string &filename, bool *is_base_pack = nullptr); + +// Returns all dictionaries found from the "texture_path" setting. +std::vector getTextureDirs(); diff --git a/src/client/texturesource.cpp b/src/client/texturesource.cpp new file mode 100644 index 000000000..529160b35 --- /dev/null +++ b/src/client/texturesource.cpp @@ -0,0 +1,2493 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "texturesource.h" + +#include +#include +#include "util/thread.h" +#include "settings.h" +#include "util/strfnd.h" +#include "imagefilters.h" +#include "guiscalingfilter.h" +#include "renderingengine.h" +#include "util/base64.h" +#include "irrlicht_changes/printing.h" +#include "util/numeric.h" +#include "texturepaths.h" + +/* + Stores internal information about a texture. +*/ + +struct TextureInfo +{ + std::string name; + video::ITexture *texture; + std::set sourceImages; + + TextureInfo( + const std::string &name_, + video::ITexture *texture_=NULL + ): + name(name_), + texture(texture_) + { + } + + TextureInfo( + const std::string &name_, + video::ITexture *texture_, + std::set &&sourceImages_ + ): + name(name_), + texture(texture_), + sourceImages(std::move(sourceImages_)) + { + } +}; + +/* + SourceImageCache: A cache used for storing source images. +*/ + +class SourceImageCache +{ +public: + ~SourceImageCache() { + for (auto &m_image : m_images) { + m_image.second->drop(); + } + m_images.clear(); + } + void insert(const std::string &name, video::IImage *img, bool prefer_local) + { + assert(img); // Pre-condition + // Remove old image + std::map::iterator n; + n = m_images.find(name); + if (n != m_images.end()){ + if (n->second) + n->second->drop(); + } + + video::IImage* toadd = img; + bool need_to_grab = true; + + // Try to use local texture instead if asked to + if (prefer_local) { + bool is_base_pack; + std::string path = getTexturePath(name, &is_base_pack); + // Ignore base pack + if (!path.empty() && !is_base_pack) { + video::IImage *img2 = RenderingEngine::get_video_driver()-> + createImageFromFile(path.c_str()); + if (img2){ + toadd = img2; + need_to_grab = false; + } + } + } + + if (need_to_grab) + toadd->grab(); + m_images[name] = toadd; + } + video::IImage* get(const std::string &name) + { + std::map::iterator n; + n = m_images.find(name); + if (n != m_images.end()) + return n->second; + return NULL; + } + // Primarily fetches from cache, secondarily tries to read from filesystem + video::IImage *getOrLoad(const std::string &name) + { + std::map::iterator n; + n = m_images.find(name); + if (n != m_images.end()){ + n->second->grab(); // Grab for caller + return n->second; + } + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + std::string path = getTexturePath(name); + if (path.empty()) { + infostream<<"SourceImageCache::getOrLoad(): No path found for \"" + <createImageFromFile(path.c_str()); + + if (img){ + m_images[name] = img; + img->grab(); // Grab for caller + } + return img; + } +private: + std::map m_images; +}; + +/* + TextureSource +*/ + +class TextureSource : public IWritableTextureSource +{ +public: + TextureSource(); + virtual ~TextureSource(); + + /* + Example case: + Now, assume a texture with the id 1 exists, and has the name + "stone.png^mineral1". + Then a random thread calls getTextureId for a texture called + "stone.png^mineral1^crack0". + ...Now, WTF should happen? Well: + - getTextureId strips off stuff recursively from the end until + the remaining part is found, or nothing is left when + something is stripped out + + But it is slow to search for textures by names and modify them + like that? + - ContentFeatures is made to contain ids for the basic plain + textures + - Crack textures can be slow by themselves, but the framework + must be fast. + + Example case #2: + - Assume a texture with the id 1 exists, and has the name + "stone.png^mineral_coal.png". + - Now getNodeTile() stumbles upon a node which uses + texture id 1, and determines that MATERIAL_FLAG_CRACK + must be applied to the tile + - MapBlockMesh::animate() finds the MATERIAL_FLAG_CRACK and + has received the current crack level 0 from the client. It + finds out the name of the texture with getTextureName(1), + appends "^crack0" to it and gets a new texture id with + getTextureId("stone.png^mineral_coal.png^crack0"). + + */ + + /* + Gets a texture id from cache or + - if main thread, generates the texture, adds to cache and returns id. + - if other thread, adds to request queue and waits for main thread. + + The id 0 points to a NULL texture. It is returned in case of error. + */ + u32 getTextureId(const std::string &name); + + // Finds out the name of a cached texture. + std::string getTextureName(u32 id); + + /* + If texture specified by the name pointed by the id doesn't + exist, create it, then return the cached texture. + + Can be called from any thread. If called from some other thread + and not found in cache, the call is queued to the main thread + for processing. + */ + video::ITexture* getTexture(u32 id); + + video::ITexture* getTexture(const std::string &name, u32 *id = NULL); + + /* + Get a texture specifically intended for mesh + application, i.e. not HUD, compositing, or other 2D + use. This texture may be a different size and may + have had additional filters applied. + */ + video::ITexture* getTextureForMesh(const std::string &name, u32 *id); + + virtual Palette* getPalette(const std::string &name); + + bool isKnownSourceImage(const std::string &name) + { + bool is_known = false; + bool cache_found = m_source_image_existence.get(name, &is_known); + if (cache_found) + return is_known; + // Not found in cache; find out if a local file exists + is_known = (!getTexturePath(name).empty()); + m_source_image_existence.set(name, is_known); + return is_known; + } + + // Processes queued texture requests from other threads. + // Shall be called from the main thread. + void processQueue(); + + // Insert an image into the cache without touching the filesystem. + // Shall be called from the main thread. + void insertSourceImage(const std::string &name, video::IImage *img); + + // Rebuild images and textures from the current set of source images + // Shall be called from the main thread. + void rebuildImagesAndTextures(); + + video::ITexture* getNormalTexture(const std::string &name); + video::SColor getTextureAverageColor(const std::string &name); + video::ITexture *getShaderFlagsTexture(bool normamap_present); + +private: + + // The id of the thread that is allowed to use irrlicht directly + std::thread::id m_main_thread; + + // Cache of source images + // This should be only accessed from the main thread + SourceImageCache m_sourcecache; + + // Rebuild images and textures from the current set of source images + // Shall be called from the main thread. + // You ARE expected to be holding m_textureinfo_cache_mutex + void rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti); + + // Generate a texture + u32 generateTexture(const std::string &name); + + // Generate image based on a string like "stone.png" or "[crack:1:0". + // if baseimg is NULL, it is created. Otherwise stuff is made on it. + // source_image_names is important to determine when to flush the image from a cache (dynamic media) + bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg, std::set &source_image_names); + + /*! Generates an image from a full string like + * "stone.png^mineral_coal.png^[crack:1:0". + * Shall be called from the main thread. + * The returned Image should be dropped. + * source_image_names is important to determine when to flush the image from a cache (dynamic media) + */ + video::IImage* generateImage(std::string_view name, std::set &source_image_names); + + // Thread-safe cache of what source images are known (true = known) + MutexedMap m_source_image_existence; + + // A texture id is index in this array. + // The first position contains a NULL texture. + std::vector m_textureinfo_cache; + // Maps a texture name to an index in the former. + std::map m_name_to_id; + // The two former containers are behind this mutex + std::mutex m_textureinfo_cache_mutex; + + // Queued texture fetches (to be processed by the main thread) + RequestQueue m_get_texture_queue; + + // Textures that have been overwritten with other ones + // but can't be deleted because the ITexture* might still be used + std::vector m_texture_trash; + + // Maps image file names to loaded palettes. + std::unordered_map m_palettes; + + // Cached settings needed for making textures from meshes + bool m_setting_mipmap; + bool m_setting_trilinear_filter; + bool m_setting_bilinear_filter; + bool m_setting_anisotropic_filter; +}; + +IWritableTextureSource *createTextureSource() +{ + return new TextureSource(); +} + +TextureSource::TextureSource() +{ + m_main_thread = std::this_thread::get_id(); + + // Add a NULL TextureInfo as the first index, named "" + m_textureinfo_cache.emplace_back(""); + m_name_to_id[""] = 0; + + // Cache some settings + // Note: Since this is only done once, the game must be restarted + // for these settings to take effect + m_setting_mipmap = g_settings->getBool("mip_map"); + m_setting_trilinear_filter = g_settings->getBool("trilinear_filter"); + m_setting_bilinear_filter = g_settings->getBool("bilinear_filter"); + m_setting_anisotropic_filter = g_settings->getBool("anisotropic_filter"); +} + +TextureSource::~TextureSource() +{ + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + + unsigned int textures_before = driver->getTextureCount(); + + for (const auto &iter : m_textureinfo_cache) { + //cleanup texture + if (iter.texture) + driver->removeTexture(iter.texture); + } + m_textureinfo_cache.clear(); + + for (auto t : m_texture_trash) { + //cleanup trashed texture + driver->removeTexture(t); + } + + infostream << "~TextureSource() before cleanup: "<< textures_before + << " after: " << driver->getTextureCount() << std::endl; +} + +u32 TextureSource::getTextureId(const std::string &name) +{ + { + /* + See if texture already exists + */ + MutexAutoLock lock(m_textureinfo_cache_mutex); + std::map::iterator n; + n = m_name_to_id.find(name); + if (n != m_name_to_id.end()) + { + return n->second; + } + } + + /* + Get texture + */ + if (std::this_thread::get_id() == m_main_thread) { + return generateTexture(name); + } + + + infostream<<"getTextureId(): Queued: name=\""< result_queue; + + // Throw a request in + m_get_texture_queue.add(name, std::this_thread::get_id(), 0, &result_queue); + + try { + while(true) { + // Wait for result for up to 1 seconds (empirical value) + GetResult + result = result_queue.pop_front(1000); + + if (result.key == name) { + return result.item; + } + } + } catch(ItemNotFoundException &e) { + errorstream << "Waiting for texture " << name << " timed out." << std::endl; + return 0; + } + + infostream << "getTextureId(): Failed" << std::endl; + + return 0; +} + +// Draw an image on top of another one, using the alpha channel of the +// source image +// overlay: only modify destination pixels that are fully opaque. +template +static void blit_with_alpha(video::IImage *src, video::IImage *dst, + v2s32 src_pos, v2s32 dst_pos, v2u32 size); + +// Apply a color to an image. Uses an int (0-255) to calculate the ratio. +// If the ratio is 255 or -1 and keep_alpha is true, then it multiples the +// color alpha with the destination alpha. +// Otherwise, any pixels that are not fully transparent get the color alpha. +static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color, int ratio, bool keep_alpha); + +// paint a texture using the given color +static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color); + +// Perform a Screen blend with the given color. The opposite effect of a +// Multiply blend. +static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color); + +// Adjust the hue, saturation, and lightness of destination. Like +// "Hue-Saturation" in GIMP. +// If colorize is true then the image will be converted to a grayscale +// image as though seen through a colored glass, like "Colorize" in GIMP. +static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 hue, s32 saturation, s32 lightness, bool colorize); + +// Apply an overlay blend to an images. +// Overlay blend combines Multiply and Screen blend modes.The parts of the top +// layer where the base layer is light become lighter, the parts where the base +// layer is dark become darker.Areas where the base layer are mid grey are +// unaffected.An overlay with the same picture looks like an S - curve. +static void apply_overlay(video::IImage *overlay, video::IImage *dst, + v2s32 overlay_pos, v2s32 dst_pos, v2u32 size, bool hardlight); + +// Adjust the brightness and contrast of the base image. Conceptually like +// "Brightness-Contrast" in GIMP but allowing brightness to be wound all the +// way up to white or down to black. +static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 brightness, s32 contrast); + +// Apply a mask to an image +static void apply_mask(video::IImage *mask, video::IImage *dst, + v2s32 mask_pos, v2s32 dst_pos, v2u32 size); + +// Draw or overlay a crack +static void draw_crack(video::IImage *crack, video::IImage *dst, + bool use_overlay, s32 frame_count, s32 progression, + video::IVideoDriver *driver, u8 tiles = 1); + +// Brighten image +void brighten(video::IImage *image); +// Parse a transform name +u32 parseImageTransform(std::string_view s); +// Apply transform to image dimension +core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim); +// Apply transform to image data +void imageTransform(u32 transform, video::IImage *src, video::IImage *dst); + +/* + This method generates all the textures +*/ +u32 TextureSource::generateTexture(const std::string &name) +{ + // Empty name means texture 0 + if (name.empty()) { + infostream<<"generateTexture(): name is empty"<second; + } + } + + /* + Calling only allowed from main thread + */ + if (std::this_thread::get_id() != m_main_thread) { + errorstream<<"TextureSource::generateTexture() " + "called not from main thread"< source_image_names; + video::IImage *img = generateImage(name, source_image_names); + + video::ITexture *tex = NULL; + + if (img != NULL) { + img = Align2Npot2(img, driver); + // Create texture from resulting image + tex = driver->addTexture(name.c_str(), img); + guiScalingCache(io::path(name.c_str()), driver, img); + img->drop(); + } + + /* + Add texture to caches (add NULL textures too) + */ + + MutexAutoLock lock(m_textureinfo_cache_mutex); + + u32 id = m_textureinfo_cache.size(); + TextureInfo ti(name, tex, std::move(source_image_names)); + m_textureinfo_cache.emplace_back(std::move(ti)); + m_name_to_id[name] = id; + + return id; +} + +std::string TextureSource::getTextureName(u32 id) +{ + MutexAutoLock lock(m_textureinfo_cache_mutex); + + if (id >= m_textureinfo_cache.size()) + { + errorstream<<"TextureSource::getTextureName(): id="<= m_textureinfo_cache.size()=" + <= m_textureinfo_cache.size()) + return NULL; + + return m_textureinfo_cache[id].texture; +} + +video::ITexture* TextureSource::getTexture(const std::string &name, u32 *id) +{ + u32 actual_id = getTextureId(name); + if (id){ + *id = actual_id; + } + return getTexture(actual_id); +} + +video::ITexture* TextureSource::getTextureForMesh(const std::string &name, u32 *id) +{ + // Avoid duplicating texture if it won't actually change + const bool filter_needed = + m_setting_mipmap || m_setting_trilinear_filter || + m_setting_bilinear_filter || m_setting_anisotropic_filter; + if (filter_needed && !name.empty()) + return getTexture(name + "^[applyfiltersformesh", id); + return getTexture(name, id); +} + +Palette* TextureSource::getPalette(const std::string &name) +{ + // Only the main thread may load images + sanity_check(std::this_thread::get_id() == m_main_thread); + + if (name.empty()) + return NULL; + + auto it = m_palettes.find(name); + if (it == m_palettes.end()) { + // Create palette + std::set source_image_names; // unused, sadly. + video::IImage *img = generateImage(name, source_image_names); + if (!img) { + warningstream << "TextureSource::getPalette(): palette \"" << name + << "\" could not be loaded." << std::endl; + return NULL; + } + Palette new_palette; + u32 w = img->getDimension().Width; + u32 h = img->getDimension().Height; + // Real area of the image + u32 area = h * w; + if (area == 0) + return NULL; + if (area > 256) { + warningstream << "TextureSource::getPalette(): the specified" + << " palette image \"" << name << "\" is larger than 256" + << " pixels, using the first 256." << std::endl; + area = 256; + } else if (256 % area != 0) + warningstream << "TextureSource::getPalette(): the " + << "specified palette image \"" << name << "\" does not " + << "contain power of two pixels." << std::endl; + // We stretch the palette so it will fit 256 values + // This many param2 values will have the same color + u32 step = 256 / area; + // For each pixel in the image + for (u32 i = 0; i < area; i++) { + video::SColor c = img->getPixel(i % w, i / w); + // Fill in palette with 'step' colors + for (u32 j = 0; j < step; j++) + new_palette.push_back(c); + } + img->drop(); + // Fill in remaining elements + while (new_palette.size() < 256) + new_palette.emplace_back(0xFFFFFFFF); + m_palettes[name] = new_palette; + it = m_palettes.find(name); + } + if (it != m_palettes.end()) + return &((*it).second); + return NULL; +} + +void TextureSource::processQueue() +{ + /* + Fetch textures + */ + // NOTE: process outstanding requests from all mesh generation threads + while (!m_get_texture_queue.empty()) + { + GetRequest + request = m_get_texture_queue.pop(); + + m_get_texture_queue.pushResult(request, generateTexture(request.key)); + } +} + +void TextureSource::insertSourceImage(const std::string &name, video::IImage *img) +{ + sanity_check(std::this_thread::get_id() == m_main_thread); + + m_sourcecache.insert(name, img, true); + m_source_image_existence.set(name, true); + + // now we need to check for any textures that need updating + MutexAutoLock lock(m_textureinfo_cache_mutex); + + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + sanity_check(driver); + + // Recreate affected textures + u32 affected = 0; + for (TextureInfo &ti : m_textureinfo_cache) { + if (ti.name.empty()) + continue; // Skip dummy entry + // If the source image was used, we need to rebuild this texture + if (ti.sourceImages.find(name) != ti.sourceImages.end()) { + rebuildTexture(driver, ti); + affected++; + } + } + if (affected > 0) + verbosestream << "TextureSource: inserting \"" << name << "\" caused rebuild of " << affected << " textures." << std::endl; +} + +void TextureSource::rebuildImagesAndTextures() +{ + MutexAutoLock lock(m_textureinfo_cache_mutex); + + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + sanity_check(driver); + + infostream << "TextureSource: recreating " << m_textureinfo_cache.size() + << " textures" << std::endl; + + // Recreate textures + for (TextureInfo &ti : m_textureinfo_cache) { + if (ti.name.empty()) + continue; // Skip dummy entry + rebuildTexture(driver, ti); + } +} + +void TextureSource::rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti) +{ + assert(!ti.name.empty()); + + // replaces the previous sourceImages + // shouldn't really need to be done, but can't hurt + std::set source_image_names; + video::IImage *img = generateImage(ti.name, source_image_names); + img = Align2Npot2(img, driver); + // Create texture from resulting image + video::ITexture *t = NULL; + if (img) { + t = driver->addTexture(ti.name.c_str(), img); + guiScalingCache(io::path(ti.name.c_str()), driver, img); + img->drop(); + } + video::ITexture *t_old = ti.texture; + // Replace texture + ti.texture = t; + ti.sourceImages = std::move(source_image_names); + + if (t_old) + m_texture_trash.push_back(t_old); +} + +inline static void applyShadeFactor(video::SColor &color, u32 factor) +{ + u32 f = core::clamp(factor, 0, 256); + color.setRed(color.getRed() * f / 256); + color.setGreen(color.getGreen() * f / 256); + color.setBlue(color.getBlue() * f / 256); +} + +static video::IImage *createInventoryCubeImage( + video::IImage *top, video::IImage *left, video::IImage *right) +{ + core::dimension2du size_top = top->getDimension(); + core::dimension2du size_left = left->getDimension(); + core::dimension2du size_right = right->getDimension(); + + u32 size = npot2(std::max({ + size_top.Width, size_top.Height, + size_left.Width, size_left.Height, + size_right.Width, size_right.Height, + })); + + // It must be divisible by 4, to let everything work correctly. + // But it is a power of 2, so being at least 4 is the same. + // And the resulting texture should't be too large as well. + size = core::clamp(size, 4, 64); + + // With such parameters, the cube fits exactly, touching each image line + // from `0` to `cube_size - 1`. (Note that division is exact here). + u32 cube_size = 9 * size; + u32 offset = size / 2; + + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + + auto lock_image = [size, driver] (video::IImage *&image) -> const u32 * { + image->grab(); + core::dimension2du dim = image->getDimension(); + video::ECOLOR_FORMAT format = image->getColorFormat(); + if (dim.Width != size || dim.Height != size || format != video::ECF_A8R8G8B8) { + video::IImage *scaled = driver->createImage(video::ECF_A8R8G8B8, {size, size}); + image->copyToScaling(scaled); + image->drop(); + image = scaled; + } + sanity_check(image->getPitch() == 4 * size); + return reinterpret_cast(image->getData()); + }; + auto free_image = [] (video::IImage *image) -> void { + image->drop(); + }; + + video::IImage *result = driver->createImage(video::ECF_A8R8G8B8, {cube_size, cube_size}); + sanity_check(result->getPitch() == 4 * cube_size); + result->fill(video::SColor(0x00000000u)); + u32 *target = reinterpret_cast(result->getData()); + + // Draws single cube face + // `shade_factor` is face brightness, in range [0.0, 1.0] + // (xu, xv, x1; yu, yv, y1) form coordinate transformation matrix + // `offsets` list pixels to be drawn for single source pixel + auto draw_image = [=] (video::IImage *image, float shade_factor, + s16 xu, s16 xv, s16 x1, + s16 yu, s16 yv, s16 y1, + std::initializer_list offsets) -> void { + u32 brightness = core::clamp(256 * shade_factor, 0, 256); + const u32 *source = lock_image(image); + for (u16 v = 0; v < size; v++) { + for (u16 u = 0; u < size; u++) { + video::SColor pixel(*source); + applyShadeFactor(pixel, brightness); + s16 x = xu * u + xv * v + x1; + s16 y = yu * u + yv * v + y1; + for (const auto &off : offsets) + target[(y + off.Y) * cube_size + (x + off.X) + offset] = pixel.color; + source++; + } + } + free_image(image); + }; + + draw_image(top, 1.000000f, + 4, -4, 4 * (size - 1), + 2, 2, 0, + { + {2, 0}, {3, 0}, {4, 0}, {5, 0}, + {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, + {2, 2}, {3, 2}, {4, 2}, {5, 2}, + }); + + draw_image(left, 0.836660f, + 4, 0, 0, + 2, 5, 2 * size, + { + {0, 0}, {1, 0}, + {0, 1}, {1, 1}, {2, 1}, {3, 1}, + {0, 2}, {1, 2}, {2, 2}, {3, 2}, + {0, 3}, {1, 3}, {2, 3}, {3, 3}, + {0, 4}, {1, 4}, {2, 4}, {3, 4}, + {2, 5}, {3, 5}, + }); + + draw_image(right, 0.670820f, + 4, 0, 4 * size, + -2, 5, 4 * size - 2, + { + {2, 0}, {3, 0}, + {0, 1}, {1, 1}, {2, 1}, {3, 1}, + {0, 2}, {1, 2}, {2, 2}, {3, 2}, + {0, 3}, {1, 3}, {2, 3}, {3, 3}, + {0, 4}, {1, 4}, {2, 4}, {3, 4}, + {0, 5}, {1, 5}, + }); + + return result; +} + +video::IImage* TextureSource::generateImage(std::string_view name, + std::set &source_image_names) +{ + // Get the base image + + const char separator = '^'; + const char escape = '\\'; + const char paren_open = '('; + const char paren_close = ')'; + + // Find last separator in the name + s32 last_separator_pos = -1; + u8 paren_bal = 0; + for (s32 i = name.size() - 1; i >= 0; i--) { + if (i > 0 && name[i-1] == escape) + continue; + switch (name[i]) { + case separator: + if (paren_bal == 0) { + last_separator_pos = i; + i = -1; // break out of loop + } + break; + case paren_open: + if (paren_bal == 0) { + errorstream << "generateImage(): unbalanced parentheses" + << "(extranous '(') while generating texture \"" + << name << "\"" << std::endl; + return NULL; + } + paren_bal--; + break; + case paren_close: + paren_bal++; + break; + default: + break; + } + } + if (paren_bal > 0) { + errorstream << "generateImage(): unbalanced parentheses" + << "(missing matching '(') while generating texture \"" + << name << "\"" << std::endl; + return NULL; + } + + + video::IImage *baseimg = NULL; + + /* + If separator was found, make the base image + using a recursive call. + */ + if (last_separator_pos != -1) { + baseimg = generateImage(name.substr(0, last_separator_pos), source_image_names); + } + + /* + Parse out the last part of the name of the image and act + according to it + */ + + auto last_part_of_name = name.substr(last_separator_pos + 1); + + /* + If this name is enclosed in parentheses, generate it + and blit it onto the base image + */ + if (last_part_of_name[0] == paren_open + && last_part_of_name.back() == paren_close) { + auto name2 = last_part_of_name.substr(1, + last_part_of_name.size() - 2); + video::IImage *tmp = generateImage(name2, source_image_names); + if (!tmp) { + errorstream << "generateImage(): " + "Failed to generate \"" << name2 << "\"" + << std::endl; + return NULL; + } + + if (baseimg) { + core::dimension2d dim = tmp->getDimension(); + blit_with_alpha(tmp, baseimg, v2s32(0, 0), v2s32(0, 0), dim); + tmp->drop(); + } else { + baseimg = tmp; + } + } else if (!generateImagePart(last_part_of_name, baseimg, source_image_names)) { + // Generate image according to part of name + errorstream << "generateImage(): " + "Failed to generate \"" << last_part_of_name << "\"" + << std::endl; + } + + // If no resulting image, print a warning + if (baseimg == NULL) { + errorstream << "generateImage(): baseimg is NULL (attempted to" + " create texture \"" << name << "\")" << std::endl; + } else if (baseimg->getDimension().Width == 0 || + baseimg->getDimension().Height == 0) { + errorstream << "generateImage(): zero-sized image was created?! " + "(attempted to create texture \"" << name << "\")" << std::endl; + baseimg->drop(); + baseimg = nullptr; + } + + return baseimg; +} + +static std::string unescape_string(const std::string &str, const char esc = '\\') +{ + std::string out; + size_t pos = 0, cpos; + out.reserve(str.size()); + while (1) { + cpos = str.find_first_of(esc, pos); + if (cpos == std::string::npos) { + out += str.substr(pos); + break; + } + out += str.substr(pos, cpos - pos) + str[cpos + 1]; + pos = cpos + 2; + } + return out; +} + +/* + Replaces the smaller of the two images with one upscaled to match the + dimensions of the other. + Ensure no other references to these images are being held, as one may + get dropped and switched with a new image. +*/ +void upscaleImagesToMatchLargest(video::IImage *& img1, + video::IImage *& img2) +{ + core::dimension2d dim1 = img1->getDimension(); + core::dimension2d dim2 = img2->getDimension(); + + if (dim1 == dim2) { + // image dimensions match, no scaling required + + } + else if (dim1.Width * dim1.Height < dim2.Width * dim2.Height) { + // Upscale img1 + video::IImage *scaled_image = RenderingEngine::get_video_driver()-> + createImage(video::ECF_A8R8G8B8, dim2); + img1->copyToScaling(scaled_image); + img1->drop(); + img1 = scaled_image; + + } else { + // Upscale img2 + video::IImage *scaled_image = RenderingEngine::get_video_driver()-> + createImage(video::ECF_A8R8G8B8, dim1); + img2->copyToScaling(scaled_image); + img2->drop(); + img2 = scaled_image; + } +} + +void blitBaseImage(video::IImage* &src, video::IImage* &dst) +{ + //infostream<<"Blitting "< dim_dst = dst->getDimension(); + // Position to copy the blitted to in the base image + core::position2d pos_to(0,0); + // Position to copy the blitted from in the blitted image + core::position2d pos_from(0,0); + + blit_with_alpha(src, dst, pos_from, pos_to, dim_dst); +} + +#define CHECK_BASEIMG() \ + do { \ + if (!baseimg) { \ + errorstream << "generateImagePart(): baseimg == NULL" \ + << " for part_of_name=\"" << part_of_name \ + << "\", cancelling." << std::endl; \ + return false; \ + } \ + } while(0) + +#define COMPLAIN_INVALID(description) \ + do { \ + errorstream << "generateImagePart(): invalid " << (description) \ + << " for part_of_name=\"" << part_of_name \ + << "\", cancelling." << std::endl; \ + return false; \ + } while(0) + +#define CHECK_DIM(w, h) \ + do { \ + if ((w) <= 0 || (h) <= 0 || (w) >= 0xffff || (h) >= 0xffff) { \ + COMPLAIN_INVALID("width or height"); \ + } \ + } while(0) + +bool TextureSource::generateImagePart(std::string_view part_of_name, + video::IImage *& baseimg, std::set &source_image_names) +{ + const char escape = '\\'; // same as in generateImage() + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + sanity_check(driver); + + if (baseimg && (baseimg->getDimension().Width == 0 || + baseimg->getDimension().Height == 0)) { + errorstream << "generateImagePart(): baseimg is zero-sized?!" + << std::endl; + baseimg->drop(); + baseimg = nullptr; + } + + // Stuff starting with [ are special commands + if (part_of_name.empty() || part_of_name[0] != '[') { + std::string part_s(part_of_name); + source_image_names.insert(part_s); + video::IImage *image = m_sourcecache.getOrLoad(part_s); + if (!image) { + // Do not create the dummy texture + if (part_of_name.empty()) + return true; + + // Do not create normalmap dummies + if (str_ends_with(part_of_name, "_normal.png")) { + warningstream << "generateImagePart(): Could not load normal map \"" + << part_of_name << "\"" << std::endl; + return true; + } + + errorstream << "generateImagePart(): Could not load image \"" + << part_of_name << "\" while building texture; " + "Creating a dummy image" << std::endl; + + core::dimension2d dim(1,1); + image = driver->createImage(video::ECF_A8R8G8B8, dim); + sanity_check(image != NULL); + image->setPixel(0,0, video::SColor(255,myrand()%256, + myrand()%256,myrand()%256)); + } + + // If base image is NULL, load as base. + if (baseimg == NULL) + { + /* + Copy it this way to get an alpha channel. + Otherwise images with alpha cannot be blitted on + images that don't have alpha in the original file. + */ + core::dimension2d dim = image->getDimension(); + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + image->copyTo(baseimg); + } + // Else blit on base. + else + { + blitBaseImage(image, baseimg); + } + + image->drop(); + } + else + { + // A special texture modification + + /* + [crack:N:P + [cracko:N:P + Adds a cracking texture + N = animation frame count, P = crack progression + */ + if (str_starts_with(part_of_name, "[crack")) + { + CHECK_BASEIMG(); + + // Crack image number and overlay option + // Format: crack[o][:]:: + bool use_overlay = (part_of_name[6] == 'o'); + Strfnd sf(part_of_name); + sf.next(":"); + s32 frame_count = stoi(sf.next(":")); + s32 progression = stoi(sf.next(":")); + s32 tiles = 1; + // Check whether there is the argument, that is, + // whether there are 3 arguments. If so, shift values + // as the first and not the last argument is optional. + auto s = sf.next(":"); + if (!s.empty()) { + tiles = frame_count; + frame_count = progression; + progression = stoi(s); + } + + if (progression >= 0) { + /* + Load crack image. + + It is an image with a number of cracking stages + horizontally tiled. + */ + video::IImage *img_crack = m_sourcecache.getOrLoad( + "crack_anylength.png"); + + if (img_crack) { + draw_crack(img_crack, baseimg, + use_overlay, frame_count, + progression, driver, tiles); + img_crack->drop(); + } + } + } + /* + [combine:WxH:X,Y=filename:X,Y=filename2 + Creates a bigger texture from any amount of smaller ones + */ + else if (str_starts_with(part_of_name, "[combine")) + { + Strfnd sf(part_of_name); + sf.next(":"); + u32 w0 = stoi(sf.next("x")); + u32 h0 = stoi(sf.next(":")); + if (!baseimg) { + CHECK_DIM(w0, h0); + baseimg = driver->createImage(video::ECF_A8R8G8B8, {w0, h0}); + baseimg->fill(video::SColor(0,0,0,0)); + } + + while (!sf.at_end()) { + v2s32 pos_base; + pos_base.X = stoi(sf.next(",")); + pos_base.Y = stoi(sf.next("=")); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + auto basedim = baseimg->getDimension(); + if (pos_base.X > (s32)basedim.Width || pos_base.Y > (s32)basedim.Height) { + warningstream << "generateImagePart(): Skipping \"" + << filename << "\" as it's out-of-bounds " << pos_base + << " for [combine" << std::endl; + continue; + } + infostream << "Adding \"" << filename<< "\" to combined " + << pos_base << std::endl; + + video::IImage *img = generateImage(filename, source_image_names); + if (!img) { + errorstream << "generateImagePart(): Failed to load image \"" + << filename << "\" for [combine" << std::endl; + continue; + } + const auto dim = img->getDimension(); + if (pos_base.X + dim.Width <= 0 || pos_base.Y + dim.Height <= 0) { + warningstream << "generateImagePart(): Skipping \"" + << filename << "\" as it's out-of-bounds " << pos_base + << " for [combine" << std::endl; + img->drop(); + continue; + } + + blit_with_alpha(img, baseimg, v2s32(0,0), pos_base, dim); + img->drop(); + } + } + /* + [fill:WxH:color + [fill:WxH:X,Y:color + Creates a texture of the given size and color, optionally with an , + position. An alpha value may be specified in the `Colorstring`. + */ + else if (str_starts_with(part_of_name, "[fill")) + { + u32 x = 0; + u32 y = 0; + + Strfnd sf(part_of_name); + sf.next(":"); + u32 width = stoi(sf.next("x")); + u32 height = stoi(sf.next(":")); + std::string color_or_x = sf.next(","); + + video::SColor color; + if (!parseColorString(color_or_x, color, true)) { + x = stoi(color_or_x); + y = stoi(sf.next(":")); + std::string color_str = sf.next(":"); + + if (!parseColorString(color_str, color, false)) + return false; + } + core::dimension2d dim(width, height); + + CHECK_DIM(dim.Width, dim.Height); + if (baseimg) { + auto basedim = baseimg->getDimension(); + if (x >= basedim.Width || y >= basedim.Height) + COMPLAIN_INVALID("X or Y offset"); + } + + video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim); + img->fill(color); + + if (baseimg == nullptr) { + baseimg = img; + } else { + blit_with_alpha(img, baseimg, v2s32(0, 0), v2s32(x, y), dim); + img->drop(); + } + } + /* + [brighten + */ + else if (str_starts_with(part_of_name, "[brighten")) + { + CHECK_BASEIMG(); + + brighten(baseimg); + } + /* + [noalpha + Make image completely opaque. + Used for the leaves texture when in old leaves mode, so + that the transparent parts don't look completely black + when simple alpha channel is used for rendering. + */ + else if (str_starts_with(part_of_name, "[noalpha")) + { + CHECK_BASEIMG(); + core::dimension2d dim = baseimg->getDimension(); + + // Set alpha to full + for (u32 y=0; ygetPixel(x,y); + c.setAlpha(255); + baseimg->setPixel(x,y,c); + } + } + /* + [makealpha:R,G,B + Convert one color to transparent. + */ + else if (str_starts_with(part_of_name, "[makealpha:")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name.substr(11)); + u32 r1 = stoi(sf.next(",")); + u32 g1 = stoi(sf.next(",")); + u32 b1 = stoi(sf.next("")); + + core::dimension2d dim = baseimg->getDimension(); + + for (u32 y=0; ygetPixel(x,y); + u32 r = c.getRed(); + u32 g = c.getGreen(); + u32 b = c.getBlue(); + if (!(r == r1 && g == g1 && b == b1)) + continue; + c.setAlpha(0); + baseimg->setPixel(x,y,c); + } + } + /* + [transformN + Rotates and/or flips the image. + + N can be a number (between 0 and 7) or a transform name. + Rotations are counter-clockwise. + 0 I identity + 1 R90 rotate by 90 degrees + 2 R180 rotate by 180 degrees + 3 R270 rotate by 270 degrees + 4 FX flip X + 5 FXR90 flip X then rotate by 90 degrees + 6 FY flip Y + 7 FYR90 flip Y then rotate by 90 degrees + + Note: Transform names can be concatenated to produce + their product (applies the first then the second). + The resulting transform will be equivalent to one of the + eight existing ones, though (see: dihedral group). + */ + else if (str_starts_with(part_of_name, "[transform")) + { + CHECK_BASEIMG(); + + u32 transform = parseImageTransform(part_of_name.substr(10)); + core::dimension2d dim = imageTransformDimension( + transform, baseimg->getDimension()); + video::IImage *image = driver->createImage( + baseimg->getColorFormat(), dim); + sanity_check(image != NULL); + imageTransform(transform, baseimg, image); + baseimg->drop(); + baseimg = image; + } + /* + [inventorycube{topimage{leftimage{rightimage + In every subimage, replace ^ with &. + Create an "inventory cube". + NOTE: This should be used only on its own. + Example (a grass block (not actually used in game): + "[inventorycube{grass.png{mud.png&grass_side.png{mud.png&grass_side.png" + */ + else if (str_starts_with(part_of_name, "[inventorycube")) + { + if (baseimg) { + errorstream<<"generateImagePart(): baseimg != NULL " + <<"for part_of_name=\""<drop(); + img_left->drop(); + img_right->drop(); + + return true; + } + /* + [lowpart:percent:filename + Adds the lower part of a texture + */ + else if (str_starts_with(part_of_name, "[lowpart:")) + { + Strfnd sf(part_of_name); + sf.next(":"); + u32 percent = stoi(sf.next(":"), 0, 100); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + video::IImage *img = generateImage(filename, source_image_names); + if (img) { + core::dimension2d dim = img->getDimension(); + if (!baseimg) + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + + core::position2d pos_base(0, 0); + core::position2d clippos(0, 0); + clippos.Y = dim.Height * (100-percent) / 100; + core::dimension2d clipdim = dim; + clipdim.Height = clipdim.Height * percent / 100 + 1; + core::rect cliprect(clippos, clipdim); + img->copyToWithAlpha(baseimg, pos_base, + core::rect(v2s32(0,0), dim), + video::SColor(255,255,255,255), + &cliprect); + img->drop(); + } + } + /* + [verticalframe:N:I + Crops a frame of a vertical animation. + N = frame count, I = frame index + */ + else if (str_starts_with(part_of_name, "[verticalframe:")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + u32 frame_count = stoi(sf.next(":")); + u32 frame_index = stoi(sf.next(":")); + + if (frame_count == 0){ + errorstream << "generateImagePart(): invalid frame_count " + << "for part_of_name=\"" << part_of_name + << "\", using frame_count = 1 instead." << std::endl; + frame_count = 1; + } + if (frame_index >= frame_count) + frame_index = frame_count - 1; + + v2u32 frame_size = baseimg->getDimension(); + frame_size.Y /= frame_count; + + video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, + frame_size); + + // Fill target image with transparency + img->fill(video::SColor(0,0,0,0)); + + core::dimension2d dim = frame_size; + core::position2d pos_dst(0, 0); + core::position2d pos_src(0, frame_index * frame_size.Y); + baseimg->copyToWithAlpha(img, pos_dst, + core::rect(pos_src, dim), + video::SColor(255,255,255,255), + NULL); + // Replace baseimg + baseimg->drop(); + baseimg = img; + } + /* + [mask:filename + Applies a mask to an image + */ + else if (str_starts_with(part_of_name, "[mask:")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + video::IImage *img = generateImage(filename, source_image_names); + if (img) { + apply_mask(img, baseimg, v2s32(0, 0), v2s32(0, 0), + img->getDimension()); + img->drop(); + } else { + errorstream << "generateImagePart(): Failed to load image \"" + << filename << "\" for [mask" << std::endl; + } + } + /* + [multiply:color + or + [screen:color + Multiply and Screen blend modes are basic blend modes for darkening and lightening + images, respectively. + A Multiply blend multiplies a given color to every pixel of an image. + A Screen blend has the opposite effect to a Multiply blend. + color = color as ColorString + */ + else if (str_starts_with(part_of_name, "[multiply:") || + str_starts_with(part_of_name, "[screen:")) { + Strfnd sf(part_of_name); + sf.next(":"); + std::string color_str = sf.next(":"); + + CHECK_BASEIMG(); + + video::SColor color; + + if (!parseColorString(color_str, color, false)) + return false; + if (str_starts_with(part_of_name, "[multiply:")) { + apply_multiplication(baseimg, v2u32(0, 0), + baseimg->getDimension(), color); + } else { + apply_screen(baseimg, v2u32(0, 0), baseimg->getDimension(), color); + } + } + /* + [colorize:color:ratio + Overlays image with given color + color = color as ColorString + ratio = optional string "alpha", or a weighting between 0 and 255 + */ + else if (str_starts_with(part_of_name, "[colorize:")) + { + Strfnd sf(part_of_name); + sf.next(":"); + std::string color_str = sf.next(":"); + std::string ratio_str = sf.next(":"); + + CHECK_BASEIMG(); + + video::SColor color; + int ratio = -1; + bool keep_alpha = false; + + if (!parseColorString(color_str, color, false)) + return false; + + if (is_number(ratio_str)) + ratio = mystoi(ratio_str, 0, 255); + else if (ratio_str == "alpha") + keep_alpha = true; + + apply_colorize(baseimg, v2u32(0, 0), baseimg->getDimension(), color, ratio, keep_alpha); + } + /* + [applyfiltersformesh + Internal modifier + */ + else if (str_starts_with(part_of_name, "[applyfiltersformesh")) + { + /* IMPORTANT: When changing this, getTextureForMesh() needs to be + * updated too. */ + + CHECK_BASEIMG(); + + // Apply the "clean transparent" filter, if needed + if (m_setting_mipmap || m_setting_bilinear_filter || + m_setting_trilinear_filter || m_setting_anisotropic_filter) + imageCleanTransparent(baseimg, 127); + + /* Upscale textures to user's requested minimum size. This is a trick to make + * filters look as good on low-res textures as on high-res ones, by making + * low-res textures BECOME high-res ones. This is helpful for worlds that + * mix high- and low-res textures, or for mods with least-common-denominator + * textures that don't have the resources to offer high-res alternatives. + */ + const bool filter = m_setting_trilinear_filter || m_setting_bilinear_filter; + const s32 scaleto = filter ? g_settings->getU16("texture_min_size") : 1; + if (scaleto > 1) { + const core::dimension2d dim = baseimg->getDimension(); + + /* Calculate scaling needed to make the shortest texture dimension + * equal to the target minimum. If e.g. this is a vertical frames + * animation, the short dimension will be the real size. + */ + u32 xscale = scaleto / dim.Width; + u32 yscale = scaleto / dim.Height; + const s32 scale = std::max(xscale, yscale); + + // Never downscale; only scale up by 2x or more. + if (scale > 1) { + u32 w = scale * dim.Width; + u32 h = scale * dim.Height; + const core::dimension2d newdim(w, h); + video::IImage *newimg = driver->createImage( + baseimg->getColorFormat(), newdim); + baseimg->copyToScaling(newimg); + baseimg->drop(); + baseimg = newimg; + } + } + } + /* + [resize:WxH + Resizes the base image to the given dimensions + */ + else if (str_starts_with(part_of_name, "[resize")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + u32 width = stoi(sf.next("x")); + u32 height = stoi(sf.next("")); + CHECK_DIM(width, height); + + video::IImage *image = driver-> + createImage(video::ECF_A8R8G8B8, {width, height}); + baseimg->copyToScaling(image); + baseimg->drop(); + baseimg = image; + } + /* + [opacity:R + Makes the base image transparent according to the given ratio. + R must be between 0 and 255. + 0 means totally transparent. + 255 means totally opaque. + */ + else if (str_starts_with(part_of_name, "[opacity:")) { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + + u32 ratio = mystoi(sf.next(""), 0, 255); + + core::dimension2d dim = baseimg->getDimension(); + + for (u32 y = 0; y < dim.Height; y++) + for (u32 x = 0; x < dim.Width; x++) + { + video::SColor c = baseimg->getPixel(x, y); + c.setAlpha(floor((c.getAlpha() * ratio) / 255 + 0.5)); + baseimg->setPixel(x, y, c); + } + } + /* + [invert:mode + Inverts the given channels of the base image. + Mode may contain the characters "r", "g", "b", "a". + Only the channels that are mentioned in the mode string + will be inverted. + */ + else if (str_starts_with(part_of_name, "[invert:")) { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + + std::string mode = sf.next(""); + u32 mask = 0; + if (mode.find('a') != std::string::npos) + mask |= 0xff000000UL; + if (mode.find('r') != std::string::npos) + mask |= 0x00ff0000UL; + if (mode.find('g') != std::string::npos) + mask |= 0x0000ff00UL; + if (mode.find('b') != std::string::npos) + mask |= 0x000000ffUL; + + core::dimension2d dim = baseimg->getDimension(); + + for (u32 y = 0; y < dim.Height; y++) + for (u32 x = 0; x < dim.Width; x++) + { + video::SColor c = baseimg->getPixel(x, y); + c.color ^= mask; + baseimg->setPixel(x, y, c); + } + } + /* + [sheet:WxH:X,Y + Retrieves a tile at position X,Y (in tiles) + from the base image it assumes to be a + tilesheet with dimensions W,H (in tiles). + */ + else if (str_starts_with(part_of_name, "[sheet:")) { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + u32 w0 = stoi(sf.next("x")); + u32 h0 = stoi(sf.next(":")); + u32 x0 = stoi(sf.next(",")); + u32 y0 = stoi(sf.next(":")); + + CHECK_DIM(w0, h0); + if (x0 >= w0 || y0 >= h0) + COMPLAIN_INVALID("tile position (X,Y)"); + + core::dimension2d img_dim = baseimg->getDimension(); + core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); + if (tile_dim.Width == 0) + tile_dim.Width = 1; + if (tile_dim.Height == 0) + tile_dim.Height = 1; + + video::IImage *img = driver->createImage( + video::ECF_A8R8G8B8, tile_dim); + img->fill(video::SColor(0,0,0,0)); + + v2u32 vdim(tile_dim); + core::rect rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); + baseimg->copyToWithAlpha(img, v2s32(0), rect, + video::SColor(255,255,255,255), NULL); + + // Replace baseimg + baseimg->drop(); + baseimg = img; + } + /* + [png:base64 + Decodes a PNG image in base64 form. + Use minetest.encode_png and minetest.encode_base64 + to produce a valid string. + */ + else if (str_starts_with(part_of_name, "[png:")) { + std::string png; + { + auto blob = part_of_name.substr(5); + if (!base64_is_valid(blob)) { + errorstream << "generateImagePart(): " + << "malformed base64 in [png" << std::endl; + return false; + } + png = base64_decode(blob); + } + + auto *device = RenderingEngine::get_raw_device(); + auto *fs = device->getFileSystem(); + auto *vd = device->getVideoDriver(); + auto *memfile = fs->createMemoryReadFile(png.data(), png.size(), "__temp_png"); + video::IImage* pngimg = vd->createImageFromFile(memfile); + memfile->drop(); + + if (!pngimg) { + errorstream << "generateImagePart(): Invalid PNG data" << std::endl; + return false; + } + + if (baseimg) { + blitBaseImage(pngimg, baseimg); + } else { + core::dimension2d dim = pngimg->getDimension(); + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + pngimg->copyTo(baseimg); + } + pngimg->drop(); + } + /* + [hsl:hue:saturation:lightness + or + [colorizehsl:hue:saturation:lightness + + Adjust the hue, saturation, and lightness of the base image. Like + "Hue-Saturation" in GIMP, but with 0 as the mid-point. + Hue should be from -180 to +180, though 0 to 360 is also supported. + Saturation and lightness are optional, with lightness from -100 to + +100, and sauration from -100 to +100-or-higher. + + If colorize is true then saturation is from 0 to 100, and the image + will be converted to a grayscale image as though seen through a + colored glass, like "Colorize" in GIMP. + */ + else if (str_starts_with(part_of_name, "[hsl:") || + str_starts_with(part_of_name, "[colorizehsl:")) { + + CHECK_BASEIMG(); + + bool colorize = str_starts_with(part_of_name, "[colorizehsl:"); + + // saturation range is 0 to 100 when colorize is true + s32 defaultSaturation = colorize ? 50 : 0; + + Strfnd sf(part_of_name); + sf.next(":"); + s32 hue = mystoi(sf.next(":"), -180, 360); + s32 saturation = sf.at_end() ? defaultSaturation : mystoi(sf.next(":"), -100, 1000); + s32 lightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -100, 100); + + + apply_hue_saturation(baseimg, v2u32(0, 0), baseimg->getDimension(), + hue, saturation, lightness, colorize); + } + /* + [overlay:filename + or + [hardlight:filename + + "A.png^[hardlight:B.png" is the same as "B.png^[overlay:A.Png" + + Applies an Overlay or Hard Light blend between two images, like the + layer modes of the same names in GIMP. + Overlay combines Multiply and Screen blend modes. The parts of the + top layer where the base layer is light become lighter, the parts + where the base layer is dark become darker. Areas where the base + layer are mid grey are unaffected. An overlay with the same picture + looks like an S-curve. + + Swapping the top layer and base layer is a Hard Light blend + */ + else if (str_starts_with(part_of_name, "[overlay:") || + str_starts_with(part_of_name, "[hardlight:")) { + + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + video::IImage *img = generateImage(filename, source_image_names); + if (img) { + upscaleImagesToMatchLargest(baseimg, img); + + bool hardlight = str_starts_with(part_of_name, "[hardlight:"); + apply_overlay(img, baseimg, v2s32(0, 0), v2s32(0, 0), + img->getDimension(), hardlight); + img->drop(); + } else { + errorstream << "generateImage(): Failed to load image \"" + << filename << "\" for [overlay or [hardlight" << std::endl; + } + } + /* + [contrast:C:B + + Adjust the brightness and contrast of the base image. Conceptually + like GIMP's "Brightness-Contrast" feature but allows brightness to + be wound all the way up to white or down to black. + C and B are both values from -127 to +127. + B is optional. + */ + else if (str_starts_with(part_of_name, "[contrast:")) { + + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + s32 contrast = mystoi(sf.next(":"), -127, 127); + s32 brightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -127, 127); + + apply_brightness_contrast(baseimg, v2u32(0, 0), + baseimg->getDimension(), brightness, contrast); + } + else + { + errorstream << "generateImagePart(): Invalid " + " modification: \"" << part_of_name << "\"" << std::endl; + } + } + + return true; +} + +#undef CHECK_BASEIMG + +#undef COMPLAIN_INVALID + +#undef CHECK_DIM + +/* + Calculate the color of a single pixel drawn on top of another pixel. + + This is a little more complicated than just video::SColor::getInterpolated + because getInterpolated does not handle alpha correctly. For example, a + pixel with alpha=64 drawn atop a pixel with alpha=128 should yield a + pixel with alpha=160, while getInterpolated would yield alpha=96. +*/ +static inline video::SColor blitPixel(const video::SColor src_c, const video::SColor dst_c, u32 ratio) +{ + if (dst_c.getAlpha() == 0) + return src_c; + video::SColor out_c = src_c.getInterpolated(dst_c, (float)ratio / 255.0f); + out_c.setAlpha(dst_c.getAlpha() + (255 - dst_c.getAlpha()) * + src_c.getAlpha() * ratio / (255 * 255)); + return out_c; +} + +/* + Draw an image on top of another one, using the alpha channel of the + source image + + This exists because IImage::copyToWithAlpha() doesn't seem to always + work. +*/ +template +static void blit_with_alpha(video::IImage *src, video::IImage *dst, + v2s32 src_pos, v2s32 dst_pos, v2u32 size) +{ + auto src_dim = src->getDimension(); + auto dst_dim = dst->getDimension(); + + // Limit y and x to the overlapping ranges + // s.t. the positions are all in bounds after offsetting. + for (u32 y0 = std::max(0, -dst_pos.Y); + y0 < std::min({size.Y, src_dim.Height, dst_dim.Height - (s64) dst_pos.Y}); + ++y0) + for (u32 x0 = std::max(0, -dst_pos.X); + x0 < std::min({size.X, src_dim.Width, dst_dim.Width - (s64) dst_pos.X}); + ++x0) + { + s32 src_x = src_pos.X + x0; + s32 src_y = src_pos.Y + y0; + s32 dst_x = dst_pos.X + x0; + s32 dst_y = dst_pos.Y + y0; + video::SColor src_c = src->getPixel(src_x, src_y); + video::SColor dst_c = dst->getPixel(dst_x, dst_y); + if (!overlay || (dst_c.getAlpha() == 255 && src_c.getAlpha() != 0)) { + dst_c = blitPixel(src_c, dst_c, src_c.getAlpha()); + dst->setPixel(dst_x, dst_y, dst_c); + } + } +} + +/* + Apply color to destination, using a weighted interpolation blend +*/ +static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color, int ratio, bool keep_alpha) +{ + u32 alpha = color.getAlpha(); + video::SColor dst_c; + if ((ratio == -1 && alpha == 255) || ratio == 255) { // full replacement of color + if (keep_alpha) { // replace the color with alpha = dest alpha * color alpha + dst_c = color; + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + u32 dst_alpha = dst->getPixel(x, y).getAlpha(); + if (dst_alpha > 0) { + dst_c.setAlpha(dst_alpha * alpha / 255); + dst->setPixel(x, y, dst_c); + } + } + } else { // replace the color including the alpha + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) + if (dst->getPixel(x, y).getAlpha() > 0) + dst->setPixel(x, y, color); + } + } else { // interpolate between the color and destination + float interp = (ratio == -1 ? color.getAlpha() / 255.0f : ratio / 255.0f); + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + if (dst_c.getAlpha() > 0) { + dst_c = color.getInterpolated(dst_c, interp); + dst->setPixel(x, y, dst_c); + } + } + } +} + +/* + Apply color to destination, using a Multiply blend mode +*/ +static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color) +{ + video::SColor dst_c; + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + dst_c.set( + dst_c.getAlpha(), + (dst_c.getRed() * color.getRed()) / 255, + (dst_c.getGreen() * color.getGreen()) / 255, + (dst_c.getBlue() * color.getBlue()) / 255 + ); + dst->setPixel(x, y, dst_c); + } +} + +/* + Apply color to destination, using a Screen blend mode +*/ +static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color) +{ + video::SColor dst_c; + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + dst_c.set( + dst_c.getAlpha(), + 255 - ((255 - dst_c.getRed()) * (255 - color.getRed())) / 255, + 255 - ((255 - dst_c.getGreen()) * (255 - color.getGreen())) / 255, + 255 - ((255 - dst_c.getBlue()) * (255 - color.getBlue())) / 255 + ); + dst->setPixel(x, y, dst_c); + } +} + +/* + Adjust the hue, saturation, and lightness of destination. Like + "Hue-Saturation" in GIMP, but with 0 as the mid-point. + Hue should be from -180 to +180, or from 0 to 360. + Saturation and Lightness are percentages. + Lightness is from -100 to +100. + Saturation goes down to -100 (fully desaturated) but can go above 100, + allowing for even muted colors to become saturated. + + If colorize is true then saturation is from 0 to 100, and destination will + be converted to a grayscale image as seen through a colored glass, like + "Colorize" in GIMP. +*/ +static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 hue, s32 saturation, s32 lightness, bool colorize) +{ + video::SColorf colorf; + video::SColorHSL hsl; + f32 norm_s = core::clamp(saturation, -100, 1000) / 100.0f; + f32 norm_l = core::clamp(lightness, -100, 100) / 100.0f; + + if (colorize) { + hsl.Saturation = core::clamp((f32)saturation, 0.0f, 100.0f); + } + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + + if (colorize) { + f32 lum = dst->getPixel(x, y).getLuminance() / 255.0f; + + if (norm_l < 0) { + lum *= norm_l + 1.0f; + } else { + lum = lum * (1.0f - norm_l) + norm_l; + } + hsl.Hue = 0; + hsl.Luminance = lum * 100; + + } else { + // convert the RGB to HSL + colorf = video::SColorf(dst->getPixel(x, y)); + hsl.fromRGB(colorf); + + if (norm_l < 0) { + hsl.Luminance *= norm_l + 1.0f; + } else{ + hsl.Luminance = hsl.Luminance + norm_l * (100.0f - hsl.Luminance); + } + + // Adjusting saturation in the same manner as lightness resulted in + // muted colours being affected too much and bright colours not + // affected enough, so I'm borrowing a leaf out of gimp's book and + // using a different scaling approach for saturation. + // https://github.com/GNOME/gimp/blob/6cc1e035f1822bf5198e7e99a53f7fa6e281396a/app/operations/gimpoperationhuesaturation.c#L139-L145= + // This difference is why values over 100% are not necessary for + // lightness but are very useful with saturation. An alternative UI + // approach would be to have an upper saturation limit of 100, but + // multiply positive values by ~3 to make it a more useful positive + // range scale. + hsl.Saturation *= norm_s + 1.0f; + hsl.Saturation = core::clamp(hsl.Saturation, 0.0f, 100.0f); + } + + // Apply the specified HSL adjustments + hsl.Hue = fmod(hsl.Hue + hue, 360); + if (hsl.Hue < 0) + hsl.Hue += 360; + + // Convert back to RGB + hsl.toRGB(colorf); + dst->setPixel(x, y, colorf.toSColor()); + } +} + + +/* + Apply an Overlay blend to destination + If hardlight is true then swap the dst & blend images (a hardlight blend) +*/ +static void apply_overlay(video::IImage *blend, video::IImage *dst, + v2s32 blend_pos, v2s32 dst_pos, v2u32 size, bool hardlight) +{ + video::IImage *blend_layer = hardlight ? dst : blend; + video::IImage *base_layer = hardlight ? blend : dst; + v2s32 blend_layer_pos = hardlight ? dst_pos : blend_pos; + v2s32 base_layer_pos = hardlight ? blend_pos : dst_pos; + + for (u32 y = 0; y < size.Y; y++) + for (u32 x = 0; x < size.X; x++) { + s32 base_x = x + base_layer_pos.X; + s32 base_y = y + base_layer_pos.Y; + + video::SColor blend_c = + blend_layer->getPixel(x + blend_layer_pos.X, y + blend_layer_pos.Y); + video::SColor base_c = base_layer->getPixel(base_x, base_y); + double blend_r = blend_c.getRed() / 255.0; + double blend_g = blend_c.getGreen() / 255.0; + double blend_b = blend_c.getBlue() / 255.0; + double base_r = base_c.getRed() / 255.0; + double base_g = base_c.getGreen() / 255.0; + double base_b = base_c.getBlue() / 255.0; + + base_c.set( + base_c.getAlpha(), + // Do a Multiply blend if less that 0.5, otherwise do a Screen blend + (u32)((base_r < 0.5 ? 2 * base_r * blend_r : 1 - 2 * (1 - base_r) * (1 - blend_r)) * 255), + (u32)((base_g < 0.5 ? 2 * base_g * blend_g : 1 - 2 * (1 - base_g) * (1 - blend_g)) * 255), + (u32)((base_b < 0.5 ? 2 * base_b * blend_b : 1 - 2 * (1 - base_b) * (1 - blend_b)) * 255) + ); + dst->setPixel(base_x, base_y, base_c); + } +} + +/* + Adjust the brightness and contrast of the base image. + + Conceptually like GIMP's "Brightness-Contrast" feature but allows brightness to be + wound all the way up to white or down to black. +*/ +static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 brightness, s32 contrast) +{ + video::SColor dst_c; + // Only allow normalized contrast to get as high as 127/128 to avoid infinite slope. + // (we could technically allow -128/128 here as that would just result in 0 slope) + double norm_c = core::clamp(contrast, -127, 127) / 128.0; + double norm_b = core::clamp(brightness, -127, 127) / 127.0; + + // Scale brightness so its range is -127.5 to 127.5, otherwise brightness + // adjustments will outputs values from 0.5 to 254.5 instead of 0 to 255. + double scaled_b = brightness * 127.5 / 127; + + // Calculate a contrast slope such that that no colors will get clamped due + // to the brightness setting. + // This allows the texture modifier to used as a brightness modifier without + // the user having to calculate a contrast to avoid clipping at that brightness. + double slope = 1 - fabs(norm_b); + + // Apply the user's contrast adjustment to the calculated slope, such that + // -127 will make it near-vertical and +127 will make it horizontal + double angle = atan(slope); + angle += norm_c <= 0 + ? norm_c * angle // allow contrast slope to be lowered to 0 + : norm_c * (M_PI_2 - angle); // allow contrast slope to be raised almost vert. + slope = tan(angle); + + double c = slope <= 1 + ? -slope * 127.5 + 127.5 + scaled_b // shift up/down when slope is horiz. + : -slope * (127.5 - scaled_b) + 127.5; // shift left/right when slope is vert. + + // add 0.5 to c so that when the final result is cast to int, it is effectively + // rounded rather than trunc'd. + c += 0.5; + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + + dst_c.set( + dst_c.getAlpha(), + core::clamp((int)(slope * dst_c.getRed() + c), 0, 255), + core::clamp((int)(slope * dst_c.getGreen() + c), 0, 255), + core::clamp((int)(slope * dst_c.getBlue() + c), 0, 255) + ); + dst->setPixel(x, y, dst_c); + } +} + +/* + Apply mask to destination +*/ +static void apply_mask(video::IImage *mask, video::IImage *dst, + v2s32 mask_pos, v2s32 dst_pos, v2u32 size) +{ + for (u32 y0 = 0; y0 < size.Y; y0++) { + for (u32 x0 = 0; x0 < size.X; x0++) { + s32 mask_x = x0 + mask_pos.X; + s32 mask_y = y0 + mask_pos.Y; + s32 dst_x = x0 + dst_pos.X; + s32 dst_y = y0 + dst_pos.Y; + video::SColor mask_c = mask->getPixel(mask_x, mask_y); + video::SColor dst_c = dst->getPixel(dst_x, dst_y); + dst_c.color &= mask_c.color; + dst->setPixel(dst_x, dst_y, dst_c); + } + } +} + +video::IImage *create_crack_image(video::IImage *crack, s32 frame_index, + core::dimension2d size, u8 tiles, video::IVideoDriver *driver) +{ + core::dimension2d strip_size = crack->getDimension(); + + if (tiles == 0 || strip_size.getArea() == 0) + return nullptr; + + core::dimension2d frame_size(strip_size.Width, strip_size.Width); + core::dimension2d tile_size(size / tiles); + s32 frame_count = strip_size.Height / strip_size.Width; + if (frame_index >= frame_count) + frame_index = frame_count - 1; + core::rect frame(v2s32(0, frame_index * frame_size.Height), frame_size); + video::IImage *result = nullptr; + + // extract crack frame + video::IImage *crack_tile = driver->createImage(video::ECF_A8R8G8B8, tile_size); + if (!crack_tile) + return nullptr; + if (tile_size == frame_size) { + crack->copyTo(crack_tile, v2s32(0, 0), frame); + } else { + video::IImage *crack_frame = driver->createImage(video::ECF_A8R8G8B8, frame_size); + if (!crack_frame) + goto exit__has_tile; + crack->copyTo(crack_frame, v2s32(0, 0), frame); + crack_frame->copyToScaling(crack_tile); + crack_frame->drop(); + } + if (tiles == 1) + return crack_tile; + + // tile it + result = driver->createImage(video::ECF_A8R8G8B8, size); + if (!result) + goto exit__has_tile; + result->fill({}); + for (u8 i = 0; i < tiles; i++) + for (u8 j = 0; j < tiles; j++) + crack_tile->copyTo(result, v2s32(i * tile_size.Width, j * tile_size.Height)); + +exit__has_tile: + crack_tile->drop(); + return result; +} + +static void draw_crack(video::IImage *crack, video::IImage *dst, + bool use_overlay, s32 frame_count, s32 progression, + video::IVideoDriver *driver, u8 tiles) +{ + // Dimension of destination image + core::dimension2d dim_dst = dst->getDimension(); + // Limit frame_count + if (frame_count > (s32) dim_dst.Height) + frame_count = dim_dst.Height; + if (frame_count < 1) + frame_count = 1; + // Dimension of the scaled crack stage, + // which is the same as the dimension of a single destination frame + core::dimension2d frame_size( + dim_dst.Width, + dim_dst.Height / frame_count + ); + video::IImage *crack_scaled = create_crack_image(crack, progression, + frame_size, tiles, driver); + if (!crack_scaled) + return; + + auto blit = use_overlay ? blit_with_alpha : blit_with_alpha; + for (s32 i = 0; i < frame_count; ++i) { + v2s32 dst_pos(0, frame_size.Height * i); + blit(crack_scaled, dst, v2s32(0,0), dst_pos, frame_size); + } + + crack_scaled->drop(); +} + +void brighten(video::IImage *image) +{ + if (image == NULL) + return; + + core::dimension2d dim = image->getDimension(); + + for (u32 y=0; ygetPixel(x,y); + c.setRed(0.5 * 255 + 0.5 * (float)c.getRed()); + c.setGreen(0.5 * 255 + 0.5 * (float)c.getGreen()); + c.setBlue(0.5 * 255 + 0.5 * (float)c.getBlue()); + image->setPixel(x,y,c); + } +} + +u32 parseImageTransform(std::string_view s) +{ + int total_transform = 0; + + std::string transform_names[8]; + transform_names[0] = "i"; + transform_names[1] = "r90"; + transform_names[2] = "r180"; + transform_names[3] = "r270"; + transform_names[4] = "fx"; + transform_names[6] = "fy"; + + std::size_t pos = 0; + while(pos < s.size()) + { + int transform = -1; + for (int i = 0; i <= 7; ++i) + { + const std::string &name_i = transform_names[i]; + + if (s[pos] == ('0' + i)) + { + transform = i; + pos++; + break; + } + + if (!(name_i.empty()) && lowercase(s.substr(pos, name_i.size())) == name_i) { + transform = i; + pos += name_i.size(); + break; + } + } + if (transform < 0) + break; + + // Multiply total_transform and transform in the group D4 + int new_total = 0; + if (transform < 4) + new_total = (transform + total_transform) % 4; + else + new_total = (transform - total_transform + 8) % 4; + if ((transform >= 4) ^ (total_transform >= 4)) + new_total += 4; + + total_transform = new_total; + } + return total_transform; +} + +core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim) +{ + if (transform % 2 == 0) + return dim; + + return core::dimension2d(dim.Height, dim.Width); +} + +void imageTransform(u32 transform, video::IImage *src, video::IImage *dst) +{ + if (src == NULL || dst == NULL) + return; + + core::dimension2d dstdim = dst->getDimension(); + + // Pre-conditions + assert(dstdim == imageTransformDimension(transform, src->getDimension())); + assert(transform <= 7); + + /* + Compute the transformation from source coordinates (sx,sy) + to destination coordinates (dx,dy). + */ + int sxn = 0; + int syn = 2; + if (transform == 0) // identity + sxn = 0, syn = 2; // sx = dx, sy = dy + else if (transform == 1) // rotate by 90 degrees ccw + sxn = 3, syn = 0; // sx = (H-1) - dy, sy = dx + else if (transform == 2) // rotate by 180 degrees + sxn = 1, syn = 3; // sx = (W-1) - dx, sy = (H-1) - dy + else if (transform == 3) // rotate by 270 degrees ccw + sxn = 2, syn = 1; // sx = dy, sy = (W-1) - dx + else if (transform == 4) // flip x + sxn = 1, syn = 2; // sx = (W-1) - dx, sy = dy + else if (transform == 5) // flip x then rotate by 90 degrees ccw + sxn = 2, syn = 0; // sx = dy, sy = dx + else if (transform == 6) // flip y + sxn = 0, syn = 3; // sx = dx, sy = (H-1) - dy + else if (transform == 7) // flip y then rotate by 90 degrees ccw + sxn = 3, syn = 1; // sx = (H-1) - dy, sy = (W-1) - dx + + for (u32 dy=0; dygetPixel(sx,sy); + dst->setPixel(dx,dy,c); + } +} + +video::ITexture* TextureSource::getNormalTexture(const std::string &name) +{ + if (isKnownSourceImage("override_normal.png")) + return getTexture("override_normal.png"); + std::string fname_base = name; + static const char *normal_ext = "_normal.png"; + static const u32 normal_ext_size = strlen(normal_ext); + size_t pos = fname_base.find('.'); + std::string fname_normal = fname_base.substr(0, pos) + normal_ext; + if (isKnownSourceImage(fname_normal)) { + // look for image extension and replace it + size_t i = 0; + while ((i = fname_base.find('.', i)) != std::string::npos) { + fname_base.replace(i, 4, normal_ext); + i += normal_ext_size; + } + return getTexture(fname_base); + } + return NULL; +} + +namespace { + // For more colourspace transformations, see for example + // https://github.com/tobspr/GLSL-Color-Spaces/blob/master/ColorSpaces.inc.glsl + + inline float linear_to_srgb_component(float v) + { + if (v > 0.0031308f) + return 1.055f * powf(v, 1.0f / 2.4f) - 0.055f; + return 12.92f * v; + } + inline float srgb_to_linear_component(float v) + { + if (v > 0.04045f) + return powf((v + 0.055f) / 1.055f, 2.4f); + return v / 12.92f; + } + + v3f srgb_to_linear(const video::SColor col_srgb) + { + v3f col(col_srgb.getRed(), col_srgb.getGreen(), col_srgb.getBlue()); + col /= 255.0f; + col.X = srgb_to_linear_component(col.X); + col.Y = srgb_to_linear_component(col.Y); + col.Z = srgb_to_linear_component(col.Z); + return col; + } + + video::SColor linear_to_srgb(const v3f col_linear) + { + v3f col; + col.X = linear_to_srgb_component(col_linear.X); + col.Y = linear_to_srgb_component(col_linear.Y); + col.Z = linear_to_srgb_component(col_linear.Z); + col *= 255.0f; + col.X = core::clamp(col.X, 0.0f, 255.0f); + col.Y = core::clamp(col.Y, 0.0f, 255.0f); + col.Z = core::clamp(col.Z, 0.0f, 255.0f); + return video::SColor(0xff, myround(col.X), myround(col.Y), + myround(col.Z)); + } +} + +video::SColor TextureSource::getTextureAverageColor(const std::string &name) +{ + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::SColor c(0, 0, 0, 0); + video::ITexture *texture = getTexture(name); + if (!texture) + return c; + video::IImage *image = driver->createImage(texture, + core::position2d(0, 0), + texture->getOriginalSize()); + if (!image) + return c; + + u32 total = 0; + v3f col_acc(0, 0, 0); + core::dimension2d dim = image->getDimension(); + u16 step = 1; + if (dim.Width > 16) + step = dim.Width / 16; + for (u16 x = 0; x < dim.Width; x += step) { + for (u16 y = 0; y < dim.Width; y += step) { + c = image->getPixel(x,y); + if (c.getAlpha() > 0) { + total++; + col_acc += srgb_to_linear(c); + } + } + } + image->drop(); + if (total > 0) { + col_acc /= total; + c = linear_to_srgb(col_acc); + } + c.setAlpha(255); + return c; +} + + +video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present) +{ + std::string tname = "__shaderFlagsTexture"; + tname += normalmap_present ? "1" : "0"; + + if (isKnownSourceImage(tname)) { + return getTexture(tname); + } + + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::IImage *flags_image = driver->createImage( + video::ECF_A8R8G8B8, core::dimension2d(1, 1)); + sanity_check(flags_image != NULL); + video::SColor c(255, normalmap_present ? 255 : 0, 0, 0); + flags_image->setPixel(0, 0, c); + insertSourceImage(tname, flags_image); + flags_image->drop(); + return getTexture(tname); + +} diff --git a/src/client/texturesource.h b/src/client/texturesource.h new file mode 100644 index 000000000..5fef20821 --- /dev/null +++ b/src/client/texturesource.h @@ -0,0 +1,93 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "irrlichttypes.h" +#include +#include +#include + +typedef std::vector Palette; + +/* + TextureSource creates and caches textures. +*/ + +class ISimpleTextureSource +{ +public: + ISimpleTextureSource() = default; + + virtual ~ISimpleTextureSource() = default; + + virtual video::ITexture* getTexture( + const std::string &name, u32 *id = nullptr) = 0; +}; + +class ITextureSource : public ISimpleTextureSource +{ +public: + ITextureSource() = default; + + virtual ~ITextureSource() = default; + + virtual u32 getTextureId(const std::string &name)=0; + virtual std::string getTextureName(u32 id)=0; + virtual video::ITexture* getTexture(u32 id)=0; + virtual video::ITexture* getTexture( + const std::string &name, u32 *id = nullptr)=0; + virtual video::ITexture* getTextureForMesh( + const std::string &name, u32 *id = nullptr) = 0; + /*! + * Returns a palette from the given texture name. + * The pointer is valid until the texture source is + * destructed. + * Should be called from the main thread. + */ + virtual Palette* getPalette(const std::string &name) = 0; + virtual bool isKnownSourceImage(const std::string &name)=0; + virtual video::ITexture* getNormalTexture(const std::string &name)=0; + virtual video::SColor getTextureAverageColor(const std::string &name)=0; + virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0; +}; + +class IWritableTextureSource : public ITextureSource +{ +public: + IWritableTextureSource() = default; + + virtual ~IWritableTextureSource() = default; + + virtual u32 getTextureId(const std::string &name)=0; + virtual std::string getTextureName(u32 id)=0; + virtual video::ITexture* getTexture(u32 id)=0; + virtual video::ITexture* getTexture( + const std::string &name, u32 *id = nullptr)=0; + virtual bool isKnownSourceImage(const std::string &name)=0; + + virtual void processQueue()=0; + virtual void insertSourceImage(const std::string &name, video::IImage *img)=0; + virtual void rebuildImagesAndTextures()=0; + virtual video::ITexture* getNormalTexture(const std::string &name)=0; + virtual video::SColor getTextureAverageColor(const std::string &name)=0; + virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0; +}; + +IWritableTextureSource *createTextureSource(); diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 624e927d8..0dc817b7b 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -1,2668 +1 @@ -/* -Minetest -Copyright (C) 2010-2013 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "tile.h" - -#include -#include -#include -#include -#include "util/string.h" -#include "util/container.h" -#include "util/thread.h" -#include "filesys.h" -#include "settings.h" -#include "mesh.h" -#include "gamedef.h" -#include "util/strfnd.h" -#include "imagefilters.h" -#include "guiscalingfilter.h" -#include "renderingengine.h" -#include "util/base64.h" -#include "irrlicht_changes/printing.h" - -/* - A cache from texture name to texture path -*/ -static MutexedMap g_texturename_to_path_cache; - -/* - Replaces the filename extension. - eg: - std::string image = "a/image.png" - replace_ext(image, "jpg") - -> image = "a/image.jpg" - Returns true on success. -*/ -static bool replace_ext(std::string &path, const char *ext) -{ - if (ext == NULL) - return false; - // Find place of last dot, fail if \ or / found. - s32 last_dot_i = -1; - for (s32 i=path.size()-1; i>=0; i--) - { - if (path[i] == '.') - { - last_dot_i = i; - break; - } - - if (path[i] == '\\' || path[i] == '/') - break; - } - // If not found, return an empty string - if (last_dot_i == -1) - return false; - // Else make the new path - path = path.substr(0, last_dot_i+1) + ext; - return true; -} - -/* - Find out the full path of an image by trying different filename - extensions. - - If failed, return "". -*/ -std::string getImagePath(std::string path) -{ - // A NULL-ended list of possible image extensions - const char *extensions[] = { "png", "jpg", "bmp", "tga", NULL }; - // If there is no extension, assume PNG - if (removeStringEnd(path, extensions).empty()) - path = path + ".png"; - // Check paths until something is found to exist - const char **ext = extensions; - do{ - bool r = replace_ext(path, *ext); - if (!r) - return ""; - if (fs::PathExists(path)) - return path; - } - while((++ext) != NULL); - - return ""; -} - -/* - Gets the path to a texture by first checking if the texture exists - in texture_path and if not, using the data path. - - Checks all supported extensions by replacing the original extension. - - If not found, returns "". - - Utilizes a thread-safe cache. -*/ -std::string getTexturePath(const std::string &filename, bool *is_base_pack) -{ - std::string fullpath; - - // This can set a wrong value on cached textures, but is irrelevant because - // is_base_pack is only passed when initializing the textures the first time - if (is_base_pack) - *is_base_pack = false; - /* - Check from cache - */ - bool incache = g_texturename_to_path_cache.get(filename, &fullpath); - if (incache) - return fullpath; - - /* - Check from texture_path - */ - for (const auto &path : getTextureDirs()) { - std::string testpath = path + DIR_DELIM; - testpath.append(filename); - // Check all filename extensions. Returns "" if not found. - fullpath = getImagePath(testpath); - if (!fullpath.empty()) - break; - } - - /* - Check from default data directory - */ - if (fullpath.empty()) - { - std::string base_path = porting::path_share + DIR_DELIM + "textures" - + DIR_DELIM + "base" + DIR_DELIM + "pack"; - std::string testpath = base_path + DIR_DELIM + filename; - // Check all filename extensions. Returns "" if not found. - fullpath = getImagePath(testpath); - if (is_base_pack && !fullpath.empty()) - *is_base_pack = true; - } - - // Add to cache (also an empty result is cached) - g_texturename_to_path_cache.set(filename, fullpath); - - // Finally return it - return fullpath; -} - -void clearTextureNameCache() -{ - g_texturename_to_path_cache.clear(); -} - -/* - Stores internal information about a texture. -*/ - -struct TextureInfo -{ - std::string name; - video::ITexture *texture; - std::set sourceImages; - - TextureInfo( - const std::string &name_, - video::ITexture *texture_=NULL - ): - name(name_), - texture(texture_) - { - } - - TextureInfo( - const std::string &name_, - video::ITexture *texture_, - std::set &&sourceImages_ - ): - name(name_), - texture(texture_), - sourceImages(std::move(sourceImages_)) - { - } -}; - -/* - SourceImageCache: A cache used for storing source images. -*/ - -class SourceImageCache -{ -public: - ~SourceImageCache() { - for (auto &m_image : m_images) { - m_image.second->drop(); - } - m_images.clear(); - } - void insert(const std::string &name, video::IImage *img, bool prefer_local) - { - assert(img); // Pre-condition - // Remove old image - std::map::iterator n; - n = m_images.find(name); - if (n != m_images.end()){ - if (n->second) - n->second->drop(); - } - - video::IImage* toadd = img; - bool need_to_grab = true; - - // Try to use local texture instead if asked to - if (prefer_local) { - bool is_base_pack; - std::string path = getTexturePath(name, &is_base_pack); - // Ignore base pack - if (!path.empty() && !is_base_pack) { - video::IImage *img2 = RenderingEngine::get_video_driver()-> - createImageFromFile(path.c_str()); - if (img2){ - toadd = img2; - need_to_grab = false; - } - } - } - - if (need_to_grab) - toadd->grab(); - m_images[name] = toadd; - } - video::IImage* get(const std::string &name) - { - std::map::iterator n; - n = m_images.find(name); - if (n != m_images.end()) - return n->second; - return NULL; - } - // Primarily fetches from cache, secondarily tries to read from filesystem - video::IImage *getOrLoad(const std::string &name) - { - std::map::iterator n; - n = m_images.find(name); - if (n != m_images.end()){ - n->second->grab(); // Grab for caller - return n->second; - } - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - std::string path = getTexturePath(name); - if (path.empty()) { - infostream<<"SourceImageCache::getOrLoad(): No path found for \"" - <createImageFromFile(path.c_str()); - - if (img){ - m_images[name] = img; - img->grab(); // Grab for caller - } - return img; - } -private: - std::map m_images; -}; - -/* - TextureSource -*/ - -class TextureSource : public IWritableTextureSource -{ -public: - TextureSource(); - virtual ~TextureSource(); - - /* - Example case: - Now, assume a texture with the id 1 exists, and has the name - "stone.png^mineral1". - Then a random thread calls getTextureId for a texture called - "stone.png^mineral1^crack0". - ...Now, WTF should happen? Well: - - getTextureId strips off stuff recursively from the end until - the remaining part is found, or nothing is left when - something is stripped out - - But it is slow to search for textures by names and modify them - like that? - - ContentFeatures is made to contain ids for the basic plain - textures - - Crack textures can be slow by themselves, but the framework - must be fast. - - Example case #2: - - Assume a texture with the id 1 exists, and has the name - "stone.png^mineral_coal.png". - - Now getNodeTile() stumbles upon a node which uses - texture id 1, and determines that MATERIAL_FLAG_CRACK - must be applied to the tile - - MapBlockMesh::animate() finds the MATERIAL_FLAG_CRACK and - has received the current crack level 0 from the client. It - finds out the name of the texture with getTextureName(1), - appends "^crack0" to it and gets a new texture id with - getTextureId("stone.png^mineral_coal.png^crack0"). - - */ - - /* - Gets a texture id from cache or - - if main thread, generates the texture, adds to cache and returns id. - - if other thread, adds to request queue and waits for main thread. - - The id 0 points to a NULL texture. It is returned in case of error. - */ - u32 getTextureId(const std::string &name); - - // Finds out the name of a cached texture. - std::string getTextureName(u32 id); - - /* - If texture specified by the name pointed by the id doesn't - exist, create it, then return the cached texture. - - Can be called from any thread. If called from some other thread - and not found in cache, the call is queued to the main thread - for processing. - */ - video::ITexture* getTexture(u32 id); - - video::ITexture* getTexture(const std::string &name, u32 *id = NULL); - - /* - Get a texture specifically intended for mesh - application, i.e. not HUD, compositing, or other 2D - use. This texture may be a different size and may - have had additional filters applied. - */ - video::ITexture* getTextureForMesh(const std::string &name, u32 *id); - - virtual Palette* getPalette(const std::string &name); - - bool isKnownSourceImage(const std::string &name) - { - bool is_known = false; - bool cache_found = m_source_image_existence.get(name, &is_known); - if (cache_found) - return is_known; - // Not found in cache; find out if a local file exists - is_known = (!getTexturePath(name).empty()); - m_source_image_existence.set(name, is_known); - return is_known; - } - - // Processes queued texture requests from other threads. - // Shall be called from the main thread. - void processQueue(); - - // Insert an image into the cache without touching the filesystem. - // Shall be called from the main thread. - void insertSourceImage(const std::string &name, video::IImage *img); - - // Rebuild images and textures from the current set of source images - // Shall be called from the main thread. - void rebuildImagesAndTextures(); - - video::ITexture* getNormalTexture(const std::string &name); - video::SColor getTextureAverageColor(const std::string &name); - video::ITexture *getShaderFlagsTexture(bool normamap_present); - -private: - - // The id of the thread that is allowed to use irrlicht directly - std::thread::id m_main_thread; - - // Cache of source images - // This should be only accessed from the main thread - SourceImageCache m_sourcecache; - - // Rebuild images and textures from the current set of source images - // Shall be called from the main thread. - // You ARE expected to be holding m_textureinfo_cache_mutex - void rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti); - - // Generate a texture - u32 generateTexture(const std::string &name); - - // Generate image based on a string like "stone.png" or "[crack:1:0". - // if baseimg is NULL, it is created. Otherwise stuff is made on it. - // source_image_names is important to determine when to flush the image from a cache (dynamic media) - bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg, std::set &source_image_names); - - /*! Generates an image from a full string like - * "stone.png^mineral_coal.png^[crack:1:0". - * Shall be called from the main thread. - * The returned Image should be dropped. - * source_image_names is important to determine when to flush the image from a cache (dynamic media) - */ - video::IImage* generateImage(std::string_view name, std::set &source_image_names); - - // Thread-safe cache of what source images are known (true = known) - MutexedMap m_source_image_existence; - - // A texture id is index in this array. - // The first position contains a NULL texture. - std::vector m_textureinfo_cache; - // Maps a texture name to an index in the former. - std::map m_name_to_id; - // The two former containers are behind this mutex - std::mutex m_textureinfo_cache_mutex; - - // Queued texture fetches (to be processed by the main thread) - RequestQueue m_get_texture_queue; - - // Textures that have been overwritten with other ones - // but can't be deleted because the ITexture* might still be used - std::vector m_texture_trash; - - // Maps image file names to loaded palettes. - std::unordered_map m_palettes; - - // Cached settings needed for making textures from meshes - bool m_setting_mipmap; - bool m_setting_trilinear_filter; - bool m_setting_bilinear_filter; - bool m_setting_anisotropic_filter; -}; - -IWritableTextureSource *createTextureSource() -{ - return new TextureSource(); -} - -TextureSource::TextureSource() -{ - m_main_thread = std::this_thread::get_id(); - - // Add a NULL TextureInfo as the first index, named "" - m_textureinfo_cache.emplace_back(""); - m_name_to_id[""] = 0; - - // Cache some settings - // Note: Since this is only done once, the game must be restarted - // for these settings to take effect - m_setting_mipmap = g_settings->getBool("mip_map"); - m_setting_trilinear_filter = g_settings->getBool("trilinear_filter"); - m_setting_bilinear_filter = g_settings->getBool("bilinear_filter"); - m_setting_anisotropic_filter = g_settings->getBool("anisotropic_filter"); -} - -TextureSource::~TextureSource() -{ - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - - unsigned int textures_before = driver->getTextureCount(); - - for (const auto &iter : m_textureinfo_cache) { - //cleanup texture - if (iter.texture) - driver->removeTexture(iter.texture); - } - m_textureinfo_cache.clear(); - - for (auto t : m_texture_trash) { - //cleanup trashed texture - driver->removeTexture(t); - } - - infostream << "~TextureSource() before cleanup: "<< textures_before - << " after: " << driver->getTextureCount() << std::endl; -} - -u32 TextureSource::getTextureId(const std::string &name) -{ - { - /* - See if texture already exists - */ - MutexAutoLock lock(m_textureinfo_cache_mutex); - std::map::iterator n; - n = m_name_to_id.find(name); - if (n != m_name_to_id.end()) - { - return n->second; - } - } - - /* - Get texture - */ - if (std::this_thread::get_id() == m_main_thread) { - return generateTexture(name); - } - - - infostream<<"getTextureId(): Queued: name=\""< result_queue; - - // Throw a request in - m_get_texture_queue.add(name, std::this_thread::get_id(), 0, &result_queue); - - try { - while(true) { - // Wait for result for up to 1 seconds (empirical value) - GetResult - result = result_queue.pop_front(1000); - - if (result.key == name) { - return result.item; - } - } - } catch(ItemNotFoundException &e) { - errorstream << "Waiting for texture " << name << " timed out." << std::endl; - return 0; - } - - infostream << "getTextureId(): Failed" << std::endl; - - return 0; -} - -// Draw an image on top of another one, using the alpha channel of the -// source image -// overlay: only modify destination pixels that are fully opaque. -template -static void blit_with_alpha(video::IImage *src, video::IImage *dst, - v2s32 src_pos, v2s32 dst_pos, v2u32 size); - -// Apply a color to an image. Uses an int (0-255) to calculate the ratio. -// If the ratio is 255 or -1 and keep_alpha is true, then it multiples the -// color alpha with the destination alpha. -// Otherwise, any pixels that are not fully transparent get the color alpha. -static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color, int ratio, bool keep_alpha); - -// paint a texture using the given color -static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color); - -// Perform a Screen blend with the given color. The opposite effect of a -// Multiply blend. -static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color); - -// Adjust the hue, saturation, and lightness of destination. Like -// "Hue-Saturation" in GIMP. -// If colorize is true then the image will be converted to a grayscale -// image as though seen through a colored glass, like "Colorize" in GIMP. -static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 hue, s32 saturation, s32 lightness, bool colorize); - -// Apply an overlay blend to an images. -// Overlay blend combines Multiply and Screen blend modes.The parts of the top -// layer where the base layer is light become lighter, the parts where the base -// layer is dark become darker.Areas where the base layer are mid grey are -// unaffected.An overlay with the same picture looks like an S - curve. -static void apply_overlay(video::IImage *overlay, video::IImage *dst, - v2s32 overlay_pos, v2s32 dst_pos, v2u32 size, bool hardlight); - -// Adjust the brightness and contrast of the base image. Conceptually like -// "Brightness-Contrast" in GIMP but allowing brightness to be wound all the -// way up to white or down to black. -static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 brightness, s32 contrast); - -// Apply a mask to an image -static void apply_mask(video::IImage *mask, video::IImage *dst, - v2s32 mask_pos, v2s32 dst_pos, v2u32 size); - -// Draw or overlay a crack -static void draw_crack(video::IImage *crack, video::IImage *dst, - bool use_overlay, s32 frame_count, s32 progression, - video::IVideoDriver *driver, u8 tiles = 1); - -// Brighten image -void brighten(video::IImage *image); -// Parse a transform name -u32 parseImageTransform(std::string_view s); -// Apply transform to image dimension -core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim); -// Apply transform to image data -void imageTransform(u32 transform, video::IImage *src, video::IImage *dst); - -/* - This method generates all the textures -*/ -u32 TextureSource::generateTexture(const std::string &name) -{ - // Empty name means texture 0 - if (name.empty()) { - infostream<<"generateTexture(): name is empty"<second; - } - } - - /* - Calling only allowed from main thread - */ - if (std::this_thread::get_id() != m_main_thread) { - errorstream<<"TextureSource::generateTexture() " - "called not from main thread"< source_image_names; - video::IImage *img = generateImage(name, source_image_names); - - video::ITexture *tex = NULL; - - if (img != NULL) { - img = Align2Npot2(img, driver); - // Create texture from resulting image - tex = driver->addTexture(name.c_str(), img); - guiScalingCache(io::path(name.c_str()), driver, img); - img->drop(); - } - - /* - Add texture to caches (add NULL textures too) - */ - - MutexAutoLock lock(m_textureinfo_cache_mutex); - - u32 id = m_textureinfo_cache.size(); - TextureInfo ti(name, tex, std::move(source_image_names)); - m_textureinfo_cache.emplace_back(std::move(ti)); - m_name_to_id[name] = id; - - return id; -} - -std::string TextureSource::getTextureName(u32 id) -{ - MutexAutoLock lock(m_textureinfo_cache_mutex); - - if (id >= m_textureinfo_cache.size()) - { - errorstream<<"TextureSource::getTextureName(): id="<= m_textureinfo_cache.size()=" - <= m_textureinfo_cache.size()) - return NULL; - - return m_textureinfo_cache[id].texture; -} - -video::ITexture* TextureSource::getTexture(const std::string &name, u32 *id) -{ - u32 actual_id = getTextureId(name); - if (id){ - *id = actual_id; - } - return getTexture(actual_id); -} - -video::ITexture* TextureSource::getTextureForMesh(const std::string &name, u32 *id) -{ - // Avoid duplicating texture if it won't actually change - const bool filter_needed = - m_setting_mipmap || m_setting_trilinear_filter || - m_setting_bilinear_filter || m_setting_anisotropic_filter; - if (filter_needed && !name.empty()) - return getTexture(name + "^[applyfiltersformesh", id); - return getTexture(name, id); -} - -Palette* TextureSource::getPalette(const std::string &name) -{ - // Only the main thread may load images - sanity_check(std::this_thread::get_id() == m_main_thread); - - if (name.empty()) - return NULL; - - auto it = m_palettes.find(name); - if (it == m_palettes.end()) { - // Create palette - std::set source_image_names; // unused, sadly. - video::IImage *img = generateImage(name, source_image_names); - if (!img) { - warningstream << "TextureSource::getPalette(): palette \"" << name - << "\" could not be loaded." << std::endl; - return NULL; - } - Palette new_palette; - u32 w = img->getDimension().Width; - u32 h = img->getDimension().Height; - // Real area of the image - u32 area = h * w; - if (area == 0) - return NULL; - if (area > 256) { - warningstream << "TextureSource::getPalette(): the specified" - << " palette image \"" << name << "\" is larger than 256" - << " pixels, using the first 256." << std::endl; - area = 256; - } else if (256 % area != 0) - warningstream << "TextureSource::getPalette(): the " - << "specified palette image \"" << name << "\" does not " - << "contain power of two pixels." << std::endl; - // We stretch the palette so it will fit 256 values - // This many param2 values will have the same color - u32 step = 256 / area; - // For each pixel in the image - for (u32 i = 0; i < area; i++) { - video::SColor c = img->getPixel(i % w, i / w); - // Fill in palette with 'step' colors - for (u32 j = 0; j < step; j++) - new_palette.push_back(c); - } - img->drop(); - // Fill in remaining elements - while (new_palette.size() < 256) - new_palette.emplace_back(0xFFFFFFFF); - m_palettes[name] = new_palette; - it = m_palettes.find(name); - } - if (it != m_palettes.end()) - return &((*it).second); - return NULL; -} - -void TextureSource::processQueue() -{ - /* - Fetch textures - */ - // NOTE: process outstanding requests from all mesh generation threads - while (!m_get_texture_queue.empty()) - { - GetRequest - request = m_get_texture_queue.pop(); - - m_get_texture_queue.pushResult(request, generateTexture(request.key)); - } -} - -void TextureSource::insertSourceImage(const std::string &name, video::IImage *img) -{ - sanity_check(std::this_thread::get_id() == m_main_thread); - - m_sourcecache.insert(name, img, true); - m_source_image_existence.set(name, true); - - // now we need to check for any textures that need updating - MutexAutoLock lock(m_textureinfo_cache_mutex); - - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - sanity_check(driver); - - // Recreate affected textures - u32 affected = 0; - for (TextureInfo &ti : m_textureinfo_cache) { - if (ti.name.empty()) - continue; // Skip dummy entry - // If the source image was used, we need to rebuild this texture - if (ti.sourceImages.find(name) != ti.sourceImages.end()) { - rebuildTexture(driver, ti); - affected++; - } - } - if (affected > 0) - verbosestream << "TextureSource: inserting \"" << name << "\" caused rebuild of " << affected << " textures." << std::endl; -} - -void TextureSource::rebuildImagesAndTextures() -{ - MutexAutoLock lock(m_textureinfo_cache_mutex); - - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - sanity_check(driver); - - infostream << "TextureSource: recreating " << m_textureinfo_cache.size() - << " textures" << std::endl; - - // Recreate textures - for (TextureInfo &ti : m_textureinfo_cache) { - if (ti.name.empty()) - continue; // Skip dummy entry - rebuildTexture(driver, ti); - } -} - -void TextureSource::rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti) -{ - assert(!ti.name.empty()); - - // replaces the previous sourceImages - // shouldn't really need to be done, but can't hurt - std::set source_image_names; - video::IImage *img = generateImage(ti.name, source_image_names); - img = Align2Npot2(img, driver); - // Create texture from resulting image - video::ITexture *t = NULL; - if (img) { - t = driver->addTexture(ti.name.c_str(), img); - guiScalingCache(io::path(ti.name.c_str()), driver, img); - img->drop(); - } - video::ITexture *t_old = ti.texture; - // Replace texture - ti.texture = t; - ti.sourceImages = std::move(source_image_names); - - if (t_old) - m_texture_trash.push_back(t_old); -} - -inline static void applyShadeFactor(video::SColor &color, u32 factor) -{ - u32 f = core::clamp(factor, 0, 256); - color.setRed(color.getRed() * f / 256); - color.setGreen(color.getGreen() * f / 256); - color.setBlue(color.getBlue() * f / 256); -} - -static video::IImage *createInventoryCubeImage( - video::IImage *top, video::IImage *left, video::IImage *right) -{ - core::dimension2du size_top = top->getDimension(); - core::dimension2du size_left = left->getDimension(); - core::dimension2du size_right = right->getDimension(); - - u32 size = npot2(std::max({ - size_top.Width, size_top.Height, - size_left.Width, size_left.Height, - size_right.Width, size_right.Height, - })); - - // It must be divisible by 4, to let everything work correctly. - // But it is a power of 2, so being at least 4 is the same. - // And the resulting texture should't be too large as well. - size = core::clamp(size, 4, 64); - - // With such parameters, the cube fits exactly, touching each image line - // from `0` to `cube_size - 1`. (Note that division is exact here). - u32 cube_size = 9 * size; - u32 offset = size / 2; - - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - - auto lock_image = [size, driver] (video::IImage *&image) -> const u32 * { - image->grab(); - core::dimension2du dim = image->getDimension(); - video::ECOLOR_FORMAT format = image->getColorFormat(); - if (dim.Width != size || dim.Height != size || format != video::ECF_A8R8G8B8) { - video::IImage *scaled = driver->createImage(video::ECF_A8R8G8B8, {size, size}); - image->copyToScaling(scaled); - image->drop(); - image = scaled; - } - sanity_check(image->getPitch() == 4 * size); - return reinterpret_cast(image->getData()); - }; - auto free_image = [] (video::IImage *image) -> void { - image->drop(); - }; - - video::IImage *result = driver->createImage(video::ECF_A8R8G8B8, {cube_size, cube_size}); - sanity_check(result->getPitch() == 4 * cube_size); - result->fill(video::SColor(0x00000000u)); - u32 *target = reinterpret_cast(result->getData()); - - // Draws single cube face - // `shade_factor` is face brightness, in range [0.0, 1.0] - // (xu, xv, x1; yu, yv, y1) form coordinate transformation matrix - // `offsets` list pixels to be drawn for single source pixel - auto draw_image = [=] (video::IImage *image, float shade_factor, - s16 xu, s16 xv, s16 x1, - s16 yu, s16 yv, s16 y1, - std::initializer_list offsets) -> void { - u32 brightness = core::clamp(256 * shade_factor, 0, 256); - const u32 *source = lock_image(image); - for (u16 v = 0; v < size; v++) { - for (u16 u = 0; u < size; u++) { - video::SColor pixel(*source); - applyShadeFactor(pixel, brightness); - s16 x = xu * u + xv * v + x1; - s16 y = yu * u + yv * v + y1; - for (const auto &off : offsets) - target[(y + off.Y) * cube_size + (x + off.X) + offset] = pixel.color; - source++; - } - } - free_image(image); - }; - - draw_image(top, 1.000000f, - 4, -4, 4 * (size - 1), - 2, 2, 0, - { - {2, 0}, {3, 0}, {4, 0}, {5, 0}, - {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, - {2, 2}, {3, 2}, {4, 2}, {5, 2}, - }); - - draw_image(left, 0.836660f, - 4, 0, 0, - 2, 5, 2 * size, - { - {0, 0}, {1, 0}, - {0, 1}, {1, 1}, {2, 1}, {3, 1}, - {0, 2}, {1, 2}, {2, 2}, {3, 2}, - {0, 3}, {1, 3}, {2, 3}, {3, 3}, - {0, 4}, {1, 4}, {2, 4}, {3, 4}, - {2, 5}, {3, 5}, - }); - - draw_image(right, 0.670820f, - 4, 0, 4 * size, - -2, 5, 4 * size - 2, - { - {2, 0}, {3, 0}, - {0, 1}, {1, 1}, {2, 1}, {3, 1}, - {0, 2}, {1, 2}, {2, 2}, {3, 2}, - {0, 3}, {1, 3}, {2, 3}, {3, 3}, - {0, 4}, {1, 4}, {2, 4}, {3, 4}, - {0, 5}, {1, 5}, - }); - - return result; -} - -video::IImage* TextureSource::generateImage(std::string_view name, - std::set &source_image_names) -{ - // Get the base image - - const char separator = '^'; - const char escape = '\\'; - const char paren_open = '('; - const char paren_close = ')'; - - // Find last separator in the name - s32 last_separator_pos = -1; - u8 paren_bal = 0; - for (s32 i = name.size() - 1; i >= 0; i--) { - if (i > 0 && name[i-1] == escape) - continue; - switch (name[i]) { - case separator: - if (paren_bal == 0) { - last_separator_pos = i; - i = -1; // break out of loop - } - break; - case paren_open: - if (paren_bal == 0) { - errorstream << "generateImage(): unbalanced parentheses" - << "(extranous '(') while generating texture \"" - << name << "\"" << std::endl; - return NULL; - } - paren_bal--; - break; - case paren_close: - paren_bal++; - break; - default: - break; - } - } - if (paren_bal > 0) { - errorstream << "generateImage(): unbalanced parentheses" - << "(missing matching '(') while generating texture \"" - << name << "\"" << std::endl; - return NULL; - } - - - video::IImage *baseimg = NULL; - - /* - If separator was found, make the base image - using a recursive call. - */ - if (last_separator_pos != -1) { - baseimg = generateImage(name.substr(0, last_separator_pos), source_image_names); - } - - /* - Parse out the last part of the name of the image and act - according to it - */ - - auto last_part_of_name = name.substr(last_separator_pos + 1); - - /* - If this name is enclosed in parentheses, generate it - and blit it onto the base image - */ - if (last_part_of_name[0] == paren_open - && last_part_of_name.back() == paren_close) { - auto name2 = last_part_of_name.substr(1, - last_part_of_name.size() - 2); - video::IImage *tmp = generateImage(name2, source_image_names); - if (!tmp) { - errorstream << "generateImage(): " - "Failed to generate \"" << name2 << "\"" - << std::endl; - return NULL; - } - - if (baseimg) { - core::dimension2d dim = tmp->getDimension(); - blit_with_alpha(tmp, baseimg, v2s32(0, 0), v2s32(0, 0), dim); - tmp->drop(); - } else { - baseimg = tmp; - } - } else if (!generateImagePart(last_part_of_name, baseimg, source_image_names)) { - // Generate image according to part of name - errorstream << "generateImage(): " - "Failed to generate \"" << last_part_of_name << "\"" - << std::endl; - } - - // If no resulting image, print a warning - if (baseimg == NULL) { - errorstream << "generateImage(): baseimg is NULL (attempted to" - " create texture \"" << name << "\")" << std::endl; - } else if (baseimg->getDimension().Width == 0 || - baseimg->getDimension().Height == 0) { - errorstream << "generateImage(): zero-sized image was created?! " - "(attempted to create texture \"" << name << "\")" << std::endl; - baseimg->drop(); - baseimg = nullptr; - } - - return baseimg; -} - -/** - * Check and align image to npot2 if required by hardware - * @param image image to check for npot2 alignment - * @param driver driver to use for image operations - * @return image or copy of image aligned to npot2 - */ -video::IImage *Align2Npot2(video::IImage *image, - video::IVideoDriver *driver) -{ - if (image == NULL) - return image; - - if (driver->queryFeature(video::EVDF_TEXTURE_NPOT)) - return image; - - core::dimension2d dim = image->getDimension(); - unsigned int height = npot2(dim.Height); - unsigned int width = npot2(dim.Width); - - if (dim.Height == height && dim.Width == width) - return image; - - if (dim.Height > height) - height *= 2; - if (dim.Width > width) - width *= 2; - - video::IImage *targetimage = - driver->createImage(video::ECF_A8R8G8B8, - core::dimension2d(width, height)); - - if (targetimage != NULL) - image->copyToScaling(targetimage); - image->drop(); - return targetimage; -} - -static std::string unescape_string(const std::string &str, const char esc = '\\') -{ - std::string out; - size_t pos = 0, cpos; - out.reserve(str.size()); - while (1) { - cpos = str.find_first_of(esc, pos); - if (cpos == std::string::npos) { - out += str.substr(pos); - break; - } - out += str.substr(pos, cpos - pos) + str[cpos + 1]; - pos = cpos + 2; - } - return out; -} - -/* - Replaces the smaller of the two images with one upscaled to match the - dimensions of the other. - Ensure no other references to these images are being held, as one may - get dropped and switched with a new image. -*/ -void upscaleImagesToMatchLargest(video::IImage *& img1, - video::IImage *& img2) -{ - core::dimension2d dim1 = img1->getDimension(); - core::dimension2d dim2 = img2->getDimension(); - - if (dim1 == dim2) { - // image dimensions match, no scaling required - - } - else if (dim1.Width * dim1.Height < dim2.Width * dim2.Height) { - // Upscale img1 - video::IImage *scaled_image = RenderingEngine::get_video_driver()-> - createImage(video::ECF_A8R8G8B8, dim2); - img1->copyToScaling(scaled_image); - img1->drop(); - img1 = scaled_image; - - } else { - // Upscale img2 - video::IImage *scaled_image = RenderingEngine::get_video_driver()-> - createImage(video::ECF_A8R8G8B8, dim1); - img2->copyToScaling(scaled_image); - img2->drop(); - img2 = scaled_image; - } -} - -void blitBaseImage(video::IImage* &src, video::IImage* &dst) -{ - //infostream<<"Blitting "< dim_dst = dst->getDimension(); - // Position to copy the blitted to in the base image - core::position2d pos_to(0,0); - // Position to copy the blitted from in the blitted image - core::position2d pos_from(0,0); - - blit_with_alpha(src, dst, pos_from, pos_to, dim_dst); -} - -#define CHECK_BASEIMG() \ - do { \ - if (!baseimg) { \ - errorstream << "generateImagePart(): baseimg == NULL" \ - << " for part_of_name=\"" << part_of_name \ - << "\", cancelling." << std::endl; \ - return false; \ - } \ - } while(0) - -#define COMPLAIN_INVALID(description) \ - do { \ - errorstream << "generateImagePart(): invalid " << (description) \ - << " for part_of_name=\"" << part_of_name \ - << "\", cancelling." << std::endl; \ - return false; \ - } while(0) - -#define CHECK_DIM(w, h) \ - do { \ - if ((w) <= 0 || (h) <= 0 || (w) >= 0xffff || (h) >= 0xffff) { \ - COMPLAIN_INVALID("width or height"); \ - } \ - } while(0) - -bool TextureSource::generateImagePart(std::string_view part_of_name, - video::IImage *& baseimg, std::set &source_image_names) -{ - const char escape = '\\'; // same as in generateImage() - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - sanity_check(driver); - - if (baseimg && (baseimg->getDimension().Width == 0 || - baseimg->getDimension().Height == 0)) { - errorstream << "generateImagePart(): baseimg is zero-sized?!" - << std::endl; - baseimg->drop(); - baseimg = nullptr; - } - - // Stuff starting with [ are special commands - if (part_of_name.empty() || part_of_name[0] != '[') { - std::string part_s(part_of_name); - source_image_names.insert(part_s); - video::IImage *image = m_sourcecache.getOrLoad(part_s); - if (!image) { - // Do not create the dummy texture - if (part_of_name.empty()) - return true; - - // Do not create normalmap dummies - if (str_ends_with(part_of_name, "_normal.png")) { - warningstream << "generateImagePart(): Could not load normal map \"" - << part_of_name << "\"" << std::endl; - return true; - } - - errorstream << "generateImagePart(): Could not load image \"" - << part_of_name << "\" while building texture; " - "Creating a dummy image" << std::endl; - - core::dimension2d dim(1,1); - image = driver->createImage(video::ECF_A8R8G8B8, dim); - sanity_check(image != NULL); - image->setPixel(0,0, video::SColor(255,myrand()%256, - myrand()%256,myrand()%256)); - } - - // If base image is NULL, load as base. - if (baseimg == NULL) - { - /* - Copy it this way to get an alpha channel. - Otherwise images with alpha cannot be blitted on - images that don't have alpha in the original file. - */ - core::dimension2d dim = image->getDimension(); - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - image->copyTo(baseimg); - } - // Else blit on base. - else - { - blitBaseImage(image, baseimg); - } - - image->drop(); - } - else - { - // A special texture modification - - /* - [crack:N:P - [cracko:N:P - Adds a cracking texture - N = animation frame count, P = crack progression - */ - if (str_starts_with(part_of_name, "[crack")) - { - CHECK_BASEIMG(); - - // Crack image number and overlay option - // Format: crack[o][:]:: - bool use_overlay = (part_of_name[6] == 'o'); - Strfnd sf(part_of_name); - sf.next(":"); - s32 frame_count = stoi(sf.next(":")); - s32 progression = stoi(sf.next(":")); - s32 tiles = 1; - // Check whether there is the argument, that is, - // whether there are 3 arguments. If so, shift values - // as the first and not the last argument is optional. - auto s = sf.next(":"); - if (!s.empty()) { - tiles = frame_count; - frame_count = progression; - progression = stoi(s); - } - - if (progression >= 0) { - /* - Load crack image. - - It is an image with a number of cracking stages - horizontally tiled. - */ - video::IImage *img_crack = m_sourcecache.getOrLoad( - "crack_anylength.png"); - - if (img_crack) { - draw_crack(img_crack, baseimg, - use_overlay, frame_count, - progression, driver, tiles); - img_crack->drop(); - } - } - } - /* - [combine:WxH:X,Y=filename:X,Y=filename2 - Creates a bigger texture from any amount of smaller ones - */ - else if (str_starts_with(part_of_name, "[combine")) - { - Strfnd sf(part_of_name); - sf.next(":"); - u32 w0 = stoi(sf.next("x")); - u32 h0 = stoi(sf.next(":")); - if (!baseimg) { - CHECK_DIM(w0, h0); - baseimg = driver->createImage(video::ECF_A8R8G8B8, {w0, h0}); - baseimg->fill(video::SColor(0,0,0,0)); - } - - while (!sf.at_end()) { - v2s32 pos_base; - pos_base.X = stoi(sf.next(",")); - pos_base.Y = stoi(sf.next("=")); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - auto basedim = baseimg->getDimension(); - if (pos_base.X > (s32)basedim.Width || pos_base.Y > (s32)basedim.Height) { - warningstream << "generateImagePart(): Skipping \"" - << filename << "\" as it's out-of-bounds " << pos_base - << " for [combine" << std::endl; - continue; - } - infostream << "Adding \"" << filename<< "\" to combined " - << pos_base << std::endl; - - video::IImage *img = generateImage(filename, source_image_names); - if (!img) { - errorstream << "generateImagePart(): Failed to load image \"" - << filename << "\" for [combine" << std::endl; - continue; - } - const auto dim = img->getDimension(); - if (pos_base.X + dim.Width <= 0 || pos_base.Y + dim.Height <= 0) { - warningstream << "generateImagePart(): Skipping \"" - << filename << "\" as it's out-of-bounds " << pos_base - << " for [combine" << std::endl; - img->drop(); - continue; - } - - blit_with_alpha(img, baseimg, v2s32(0,0), pos_base, dim); - img->drop(); - } - } - /* - [fill:WxH:color - [fill:WxH:X,Y:color - Creates a texture of the given size and color, optionally with an , - position. An alpha value may be specified in the `Colorstring`. - */ - else if (str_starts_with(part_of_name, "[fill")) - { - u32 x = 0; - u32 y = 0; - - Strfnd sf(part_of_name); - sf.next(":"); - u32 width = stoi(sf.next("x")); - u32 height = stoi(sf.next(":")); - std::string color_or_x = sf.next(","); - - video::SColor color; - if (!parseColorString(color_or_x, color, true)) { - x = stoi(color_or_x); - y = stoi(sf.next(":")); - std::string color_str = sf.next(":"); - - if (!parseColorString(color_str, color, false)) - return false; - } - core::dimension2d dim(width, height); - - CHECK_DIM(dim.Width, dim.Height); - if (baseimg) { - auto basedim = baseimg->getDimension(); - if (x >= basedim.Width || y >= basedim.Height) - COMPLAIN_INVALID("X or Y offset"); - } - - video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim); - img->fill(color); - - if (baseimg == nullptr) { - baseimg = img; - } else { - blit_with_alpha(img, baseimg, v2s32(0, 0), v2s32(x, y), dim); - img->drop(); - } - } - /* - [brighten - */ - else if (str_starts_with(part_of_name, "[brighten")) - { - CHECK_BASEIMG(); - - brighten(baseimg); - } - /* - [noalpha - Make image completely opaque. - Used for the leaves texture when in old leaves mode, so - that the transparent parts don't look completely black - when simple alpha channel is used for rendering. - */ - else if (str_starts_with(part_of_name, "[noalpha")) - { - CHECK_BASEIMG(); - core::dimension2d dim = baseimg->getDimension(); - - // Set alpha to full - for (u32 y=0; ygetPixel(x,y); - c.setAlpha(255); - baseimg->setPixel(x,y,c); - } - } - /* - [makealpha:R,G,B - Convert one color to transparent. - */ - else if (str_starts_with(part_of_name, "[makealpha:")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name.substr(11)); - u32 r1 = stoi(sf.next(",")); - u32 g1 = stoi(sf.next(",")); - u32 b1 = stoi(sf.next("")); - - core::dimension2d dim = baseimg->getDimension(); - - for (u32 y=0; ygetPixel(x,y); - u32 r = c.getRed(); - u32 g = c.getGreen(); - u32 b = c.getBlue(); - if (!(r == r1 && g == g1 && b == b1)) - continue; - c.setAlpha(0); - baseimg->setPixel(x,y,c); - } - } - /* - [transformN - Rotates and/or flips the image. - - N can be a number (between 0 and 7) or a transform name. - Rotations are counter-clockwise. - 0 I identity - 1 R90 rotate by 90 degrees - 2 R180 rotate by 180 degrees - 3 R270 rotate by 270 degrees - 4 FX flip X - 5 FXR90 flip X then rotate by 90 degrees - 6 FY flip Y - 7 FYR90 flip Y then rotate by 90 degrees - - Note: Transform names can be concatenated to produce - their product (applies the first then the second). - The resulting transform will be equivalent to one of the - eight existing ones, though (see: dihedral group). - */ - else if (str_starts_with(part_of_name, "[transform")) - { - CHECK_BASEIMG(); - - u32 transform = parseImageTransform(part_of_name.substr(10)); - core::dimension2d dim = imageTransformDimension( - transform, baseimg->getDimension()); - video::IImage *image = driver->createImage( - baseimg->getColorFormat(), dim); - sanity_check(image != NULL); - imageTransform(transform, baseimg, image); - baseimg->drop(); - baseimg = image; - } - /* - [inventorycube{topimage{leftimage{rightimage - In every subimage, replace ^ with &. - Create an "inventory cube". - NOTE: This should be used only on its own. - Example (a grass block (not actually used in game): - "[inventorycube{grass.png{mud.png&grass_side.png{mud.png&grass_side.png" - */ - else if (str_starts_with(part_of_name, "[inventorycube")) - { - if (baseimg) { - errorstream<<"generateImagePart(): baseimg != NULL " - <<"for part_of_name=\""<drop(); - img_left->drop(); - img_right->drop(); - - return true; - } - /* - [lowpart:percent:filename - Adds the lower part of a texture - */ - else if (str_starts_with(part_of_name, "[lowpart:")) - { - Strfnd sf(part_of_name); - sf.next(":"); - u32 percent = stoi(sf.next(":"), 0, 100); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - video::IImage *img = generateImage(filename, source_image_names); - if (img) { - core::dimension2d dim = img->getDimension(); - if (!baseimg) - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - - core::position2d pos_base(0, 0); - core::position2d clippos(0, 0); - clippos.Y = dim.Height * (100-percent) / 100; - core::dimension2d clipdim = dim; - clipdim.Height = clipdim.Height * percent / 100 + 1; - core::rect cliprect(clippos, clipdim); - img->copyToWithAlpha(baseimg, pos_base, - core::rect(v2s32(0,0), dim), - video::SColor(255,255,255,255), - &cliprect); - img->drop(); - } - } - /* - [verticalframe:N:I - Crops a frame of a vertical animation. - N = frame count, I = frame index - */ - else if (str_starts_with(part_of_name, "[verticalframe:")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - u32 frame_count = stoi(sf.next(":")); - u32 frame_index = stoi(sf.next(":")); - - if (frame_count == 0){ - errorstream << "generateImagePart(): invalid frame_count " - << "for part_of_name=\"" << part_of_name - << "\", using frame_count = 1 instead." << std::endl; - frame_count = 1; - } - if (frame_index >= frame_count) - frame_index = frame_count - 1; - - v2u32 frame_size = baseimg->getDimension(); - frame_size.Y /= frame_count; - - video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, - frame_size); - - // Fill target image with transparency - img->fill(video::SColor(0,0,0,0)); - - core::dimension2d dim = frame_size; - core::position2d pos_dst(0, 0); - core::position2d pos_src(0, frame_index * frame_size.Y); - baseimg->copyToWithAlpha(img, pos_dst, - core::rect(pos_src, dim), - video::SColor(255,255,255,255), - NULL); - // Replace baseimg - baseimg->drop(); - baseimg = img; - } - /* - [mask:filename - Applies a mask to an image - */ - else if (str_starts_with(part_of_name, "[mask:")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - video::IImage *img = generateImage(filename, source_image_names); - if (img) { - apply_mask(img, baseimg, v2s32(0, 0), v2s32(0, 0), - img->getDimension()); - img->drop(); - } else { - errorstream << "generateImagePart(): Failed to load image \"" - << filename << "\" for [mask" << std::endl; - } - } - /* - [multiply:color - or - [screen:color - Multiply and Screen blend modes are basic blend modes for darkening and lightening - images, respectively. - A Multiply blend multiplies a given color to every pixel of an image. - A Screen blend has the opposite effect to a Multiply blend. - color = color as ColorString - */ - else if (str_starts_with(part_of_name, "[multiply:") || - str_starts_with(part_of_name, "[screen:")) { - Strfnd sf(part_of_name); - sf.next(":"); - std::string color_str = sf.next(":"); - - CHECK_BASEIMG(); - - video::SColor color; - - if (!parseColorString(color_str, color, false)) - return false; - if (str_starts_with(part_of_name, "[multiply:")) { - apply_multiplication(baseimg, v2u32(0, 0), - baseimg->getDimension(), color); - } else { - apply_screen(baseimg, v2u32(0, 0), baseimg->getDimension(), color); - } - } - /* - [colorize:color:ratio - Overlays image with given color - color = color as ColorString - ratio = optional string "alpha", or a weighting between 0 and 255 - */ - else if (str_starts_with(part_of_name, "[colorize:")) - { - Strfnd sf(part_of_name); - sf.next(":"); - std::string color_str = sf.next(":"); - std::string ratio_str = sf.next(":"); - - CHECK_BASEIMG(); - - video::SColor color; - int ratio = -1; - bool keep_alpha = false; - - if (!parseColorString(color_str, color, false)) - return false; - - if (is_number(ratio_str)) - ratio = mystoi(ratio_str, 0, 255); - else if (ratio_str == "alpha") - keep_alpha = true; - - apply_colorize(baseimg, v2u32(0, 0), baseimg->getDimension(), color, ratio, keep_alpha); - } - /* - [applyfiltersformesh - Internal modifier - */ - else if (str_starts_with(part_of_name, "[applyfiltersformesh")) - { - /* IMPORTANT: When changing this, getTextureForMesh() needs to be - * updated too. */ - - CHECK_BASEIMG(); - - // Apply the "clean transparent" filter, if needed - if (m_setting_mipmap || m_setting_bilinear_filter || - m_setting_trilinear_filter || m_setting_anisotropic_filter) - imageCleanTransparent(baseimg, 127); - - /* Upscale textures to user's requested minimum size. This is a trick to make - * filters look as good on low-res textures as on high-res ones, by making - * low-res textures BECOME high-res ones. This is helpful for worlds that - * mix high- and low-res textures, or for mods with least-common-denominator - * textures that don't have the resources to offer high-res alternatives. - */ - const bool filter = m_setting_trilinear_filter || m_setting_bilinear_filter; - const s32 scaleto = filter ? g_settings->getU16("texture_min_size") : 1; - if (scaleto > 1) { - const core::dimension2d dim = baseimg->getDimension(); - - /* Calculate scaling needed to make the shortest texture dimension - * equal to the target minimum. If e.g. this is a vertical frames - * animation, the short dimension will be the real size. - */ - u32 xscale = scaleto / dim.Width; - u32 yscale = scaleto / dim.Height; - const s32 scale = std::max(xscale, yscale); - - // Never downscale; only scale up by 2x or more. - if (scale > 1) { - u32 w = scale * dim.Width; - u32 h = scale * dim.Height; - const core::dimension2d newdim(w, h); - video::IImage *newimg = driver->createImage( - baseimg->getColorFormat(), newdim); - baseimg->copyToScaling(newimg); - baseimg->drop(); - baseimg = newimg; - } - } - } - /* - [resize:WxH - Resizes the base image to the given dimensions - */ - else if (str_starts_with(part_of_name, "[resize")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - u32 width = stoi(sf.next("x")); - u32 height = stoi(sf.next("")); - CHECK_DIM(width, height); - - video::IImage *image = driver-> - createImage(video::ECF_A8R8G8B8, {width, height}); - baseimg->copyToScaling(image); - baseimg->drop(); - baseimg = image; - } - /* - [opacity:R - Makes the base image transparent according to the given ratio. - R must be between 0 and 255. - 0 means totally transparent. - 255 means totally opaque. - */ - else if (str_starts_with(part_of_name, "[opacity:")) { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - - u32 ratio = mystoi(sf.next(""), 0, 255); - - core::dimension2d dim = baseimg->getDimension(); - - for (u32 y = 0; y < dim.Height; y++) - for (u32 x = 0; x < dim.Width; x++) - { - video::SColor c = baseimg->getPixel(x, y); - c.setAlpha(floor((c.getAlpha() * ratio) / 255 + 0.5)); - baseimg->setPixel(x, y, c); - } - } - /* - [invert:mode - Inverts the given channels of the base image. - Mode may contain the characters "r", "g", "b", "a". - Only the channels that are mentioned in the mode string - will be inverted. - */ - else if (str_starts_with(part_of_name, "[invert:")) { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - - std::string mode = sf.next(""); - u32 mask = 0; - if (mode.find('a') != std::string::npos) - mask |= 0xff000000UL; - if (mode.find('r') != std::string::npos) - mask |= 0x00ff0000UL; - if (mode.find('g') != std::string::npos) - mask |= 0x0000ff00UL; - if (mode.find('b') != std::string::npos) - mask |= 0x000000ffUL; - - core::dimension2d dim = baseimg->getDimension(); - - for (u32 y = 0; y < dim.Height; y++) - for (u32 x = 0; x < dim.Width; x++) - { - video::SColor c = baseimg->getPixel(x, y); - c.color ^= mask; - baseimg->setPixel(x, y, c); - } - } - /* - [sheet:WxH:X,Y - Retrieves a tile at position X,Y (in tiles) - from the base image it assumes to be a - tilesheet with dimensions W,H (in tiles). - */ - else if (str_starts_with(part_of_name, "[sheet:")) { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - u32 w0 = stoi(sf.next("x")); - u32 h0 = stoi(sf.next(":")); - u32 x0 = stoi(sf.next(",")); - u32 y0 = stoi(sf.next(":")); - - CHECK_DIM(w0, h0); - if (x0 >= w0 || y0 >= h0) - COMPLAIN_INVALID("tile position (X,Y)"); - - core::dimension2d img_dim = baseimg->getDimension(); - core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); - if (tile_dim.Width == 0) - tile_dim.Width = 1; - if (tile_dim.Height == 0) - tile_dim.Height = 1; - - video::IImage *img = driver->createImage( - video::ECF_A8R8G8B8, tile_dim); - img->fill(video::SColor(0,0,0,0)); - - v2u32 vdim(tile_dim); - core::rect rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); - baseimg->copyToWithAlpha(img, v2s32(0), rect, - video::SColor(255,255,255,255), NULL); - - // Replace baseimg - baseimg->drop(); - baseimg = img; - } - /* - [png:base64 - Decodes a PNG image in base64 form. - Use minetest.encode_png and minetest.encode_base64 - to produce a valid string. - */ - else if (str_starts_with(part_of_name, "[png:")) { - std::string png; - { - auto blob = part_of_name.substr(5); - if (!base64_is_valid(blob)) { - errorstream << "generateImagePart(): " - << "malformed base64 in [png" << std::endl; - return false; - } - png = base64_decode(blob); - } - - auto *device = RenderingEngine::get_raw_device(); - auto *fs = device->getFileSystem(); - auto *vd = device->getVideoDriver(); - auto *memfile = fs->createMemoryReadFile(png.data(), png.size(), "__temp_png"); - video::IImage* pngimg = vd->createImageFromFile(memfile); - memfile->drop(); - - if (!pngimg) { - errorstream << "generateImagePart(): Invalid PNG data" << std::endl; - return false; - } - - if (baseimg) { - blitBaseImage(pngimg, baseimg); - } else { - core::dimension2d dim = pngimg->getDimension(); - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - pngimg->copyTo(baseimg); - } - pngimg->drop(); - } - /* - [hsl:hue:saturation:lightness - or - [colorizehsl:hue:saturation:lightness - - Adjust the hue, saturation, and lightness of the base image. Like - "Hue-Saturation" in GIMP, but with 0 as the mid-point. - Hue should be from -180 to +180, though 0 to 360 is also supported. - Saturation and lightness are optional, with lightness from -100 to - +100, and sauration from -100 to +100-or-higher. - - If colorize is true then saturation is from 0 to 100, and the image - will be converted to a grayscale image as though seen through a - colored glass, like "Colorize" in GIMP. - */ - else if (str_starts_with(part_of_name, "[hsl:") || - str_starts_with(part_of_name, "[colorizehsl:")) { - - CHECK_BASEIMG(); - - bool colorize = str_starts_with(part_of_name, "[colorizehsl:"); - - // saturation range is 0 to 100 when colorize is true - s32 defaultSaturation = colorize ? 50 : 0; - - Strfnd sf(part_of_name); - sf.next(":"); - s32 hue = mystoi(sf.next(":"), -180, 360); - s32 saturation = sf.at_end() ? defaultSaturation : mystoi(sf.next(":"), -100, 1000); - s32 lightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -100, 100); - - - apply_hue_saturation(baseimg, v2u32(0, 0), baseimg->getDimension(), - hue, saturation, lightness, colorize); - } - /* - [overlay:filename - or - [hardlight:filename - - "A.png^[hardlight:B.png" is the same as "B.png^[overlay:A.Png" - - Applies an Overlay or Hard Light blend between two images, like the - layer modes of the same names in GIMP. - Overlay combines Multiply and Screen blend modes. The parts of the - top layer where the base layer is light become lighter, the parts - where the base layer is dark become darker. Areas where the base - layer are mid grey are unaffected. An overlay with the same picture - looks like an S-curve. - - Swapping the top layer and base layer is a Hard Light blend - */ - else if (str_starts_with(part_of_name, "[overlay:") || - str_starts_with(part_of_name, "[hardlight:")) { - - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - video::IImage *img = generateImage(filename, source_image_names); - if (img) { - upscaleImagesToMatchLargest(baseimg, img); - - bool hardlight = str_starts_with(part_of_name, "[hardlight:"); - apply_overlay(img, baseimg, v2s32(0, 0), v2s32(0, 0), - img->getDimension(), hardlight); - img->drop(); - } else { - errorstream << "generateImage(): Failed to load image \"" - << filename << "\" for [overlay or [hardlight" << std::endl; - } - } - /* - [contrast:C:B - - Adjust the brightness and contrast of the base image. Conceptually - like GIMP's "Brightness-Contrast" feature but allows brightness to - be wound all the way up to white or down to black. - C and B are both values from -127 to +127. - B is optional. - */ - else if (str_starts_with(part_of_name, "[contrast:")) { - - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - s32 contrast = mystoi(sf.next(":"), -127, 127); - s32 brightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -127, 127); - - apply_brightness_contrast(baseimg, v2u32(0, 0), - baseimg->getDimension(), brightness, contrast); - } - else - { - errorstream << "generateImagePart(): Invalid " - " modification: \"" << part_of_name << "\"" << std::endl; - } - } - - return true; -} - -#undef CHECK_BASEIMG - -#undef COMPLAIN_INVALID - -#undef CHECK_DIM - -/* - Calculate the color of a single pixel drawn on top of another pixel. - - This is a little more complicated than just video::SColor::getInterpolated - because getInterpolated does not handle alpha correctly. For example, a - pixel with alpha=64 drawn atop a pixel with alpha=128 should yield a - pixel with alpha=160, while getInterpolated would yield alpha=96. -*/ -static inline video::SColor blitPixel(const video::SColor src_c, const video::SColor dst_c, u32 ratio) -{ - if (dst_c.getAlpha() == 0) - return src_c; - video::SColor out_c = src_c.getInterpolated(dst_c, (float)ratio / 255.0f); - out_c.setAlpha(dst_c.getAlpha() + (255 - dst_c.getAlpha()) * - src_c.getAlpha() * ratio / (255 * 255)); - return out_c; -} - -/* - Draw an image on top of another one, using the alpha channel of the - source image - - This exists because IImage::copyToWithAlpha() doesn't seem to always - work. -*/ -template -static void blit_with_alpha(video::IImage *src, video::IImage *dst, - v2s32 src_pos, v2s32 dst_pos, v2u32 size) -{ - auto src_dim = src->getDimension(); - auto dst_dim = dst->getDimension(); - - // Limit y and x to the overlapping ranges - // s.t. the positions are all in bounds after offsetting. - for (u32 y0 = std::max(0, -dst_pos.Y); - y0 < std::min({size.Y, src_dim.Height, dst_dim.Height - (s64) dst_pos.Y}); - ++y0) - for (u32 x0 = std::max(0, -dst_pos.X); - x0 < std::min({size.X, src_dim.Width, dst_dim.Width - (s64) dst_pos.X}); - ++x0) - { - s32 src_x = src_pos.X + x0; - s32 src_y = src_pos.Y + y0; - s32 dst_x = dst_pos.X + x0; - s32 dst_y = dst_pos.Y + y0; - video::SColor src_c = src->getPixel(src_x, src_y); - video::SColor dst_c = dst->getPixel(dst_x, dst_y); - if (!overlay || (dst_c.getAlpha() == 255 && src_c.getAlpha() != 0)) { - dst_c = blitPixel(src_c, dst_c, src_c.getAlpha()); - dst->setPixel(dst_x, dst_y, dst_c); - } - } -} - -/* - Apply color to destination, using a weighted interpolation blend -*/ -static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color, int ratio, bool keep_alpha) -{ - u32 alpha = color.getAlpha(); - video::SColor dst_c; - if ((ratio == -1 && alpha == 255) || ratio == 255) { // full replacement of color - if (keep_alpha) { // replace the color with alpha = dest alpha * color alpha - dst_c = color; - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - u32 dst_alpha = dst->getPixel(x, y).getAlpha(); - if (dst_alpha > 0) { - dst_c.setAlpha(dst_alpha * alpha / 255); - dst->setPixel(x, y, dst_c); - } - } - } else { // replace the color including the alpha - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) - if (dst->getPixel(x, y).getAlpha() > 0) - dst->setPixel(x, y, color); - } - } else { // interpolate between the color and destination - float interp = (ratio == -1 ? color.getAlpha() / 255.0f : ratio / 255.0f); - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - if (dst_c.getAlpha() > 0) { - dst_c = color.getInterpolated(dst_c, interp); - dst->setPixel(x, y, dst_c); - } - } - } -} - -/* - Apply color to destination, using a Multiply blend mode -*/ -static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color) -{ - video::SColor dst_c; - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - dst_c.set( - dst_c.getAlpha(), - (dst_c.getRed() * color.getRed()) / 255, - (dst_c.getGreen() * color.getGreen()) / 255, - (dst_c.getBlue() * color.getBlue()) / 255 - ); - dst->setPixel(x, y, dst_c); - } -} - -/* - Apply color to destination, using a Screen blend mode -*/ -static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color) -{ - video::SColor dst_c; - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - dst_c.set( - dst_c.getAlpha(), - 255 - ((255 - dst_c.getRed()) * (255 - color.getRed())) / 255, - 255 - ((255 - dst_c.getGreen()) * (255 - color.getGreen())) / 255, - 255 - ((255 - dst_c.getBlue()) * (255 - color.getBlue())) / 255 - ); - dst->setPixel(x, y, dst_c); - } -} - -/* - Adjust the hue, saturation, and lightness of destination. Like - "Hue-Saturation" in GIMP, but with 0 as the mid-point. - Hue should be from -180 to +180, or from 0 to 360. - Saturation and Lightness are percentages. - Lightness is from -100 to +100. - Saturation goes down to -100 (fully desaturated) but can go above 100, - allowing for even muted colors to become saturated. - - If colorize is true then saturation is from 0 to 100, and destination will - be converted to a grayscale image as seen through a colored glass, like - "Colorize" in GIMP. -*/ -static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 hue, s32 saturation, s32 lightness, bool colorize) -{ - video::SColorf colorf; - video::SColorHSL hsl; - f32 norm_s = core::clamp(saturation, -100, 1000) / 100.0f; - f32 norm_l = core::clamp(lightness, -100, 100) / 100.0f; - - if (colorize) { - hsl.Saturation = core::clamp((f32)saturation, 0.0f, 100.0f); - } - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - - if (colorize) { - f32 lum = dst->getPixel(x, y).getLuminance() / 255.0f; - - if (norm_l < 0) { - lum *= norm_l + 1.0f; - } else { - lum = lum * (1.0f - norm_l) + norm_l; - } - hsl.Hue = 0; - hsl.Luminance = lum * 100; - - } else { - // convert the RGB to HSL - colorf = video::SColorf(dst->getPixel(x, y)); - hsl.fromRGB(colorf); - - if (norm_l < 0) { - hsl.Luminance *= norm_l + 1.0f; - } else{ - hsl.Luminance = hsl.Luminance + norm_l * (100.0f - hsl.Luminance); - } - - // Adjusting saturation in the same manner as lightness resulted in - // muted colours being affected too much and bright colours not - // affected enough, so I'm borrowing a leaf out of gimp's book and - // using a different scaling approach for saturation. - // https://github.com/GNOME/gimp/blob/6cc1e035f1822bf5198e7e99a53f7fa6e281396a/app/operations/gimpoperationhuesaturation.c#L139-L145= - // This difference is why values over 100% are not necessary for - // lightness but are very useful with saturation. An alternative UI - // approach would be to have an upper saturation limit of 100, but - // multiply positive values by ~3 to make it a more useful positive - // range scale. - hsl.Saturation *= norm_s + 1.0f; - hsl.Saturation = core::clamp(hsl.Saturation, 0.0f, 100.0f); - } - - // Apply the specified HSL adjustments - hsl.Hue = fmod(hsl.Hue + hue, 360); - if (hsl.Hue < 0) - hsl.Hue += 360; - - // Convert back to RGB - hsl.toRGB(colorf); - dst->setPixel(x, y, colorf.toSColor()); - } -} - - -/* - Apply an Overlay blend to destination - If hardlight is true then swap the dst & blend images (a hardlight blend) -*/ -static void apply_overlay(video::IImage *blend, video::IImage *dst, - v2s32 blend_pos, v2s32 dst_pos, v2u32 size, bool hardlight) -{ - video::IImage *blend_layer = hardlight ? dst : blend; - video::IImage *base_layer = hardlight ? blend : dst; - v2s32 blend_layer_pos = hardlight ? dst_pos : blend_pos; - v2s32 base_layer_pos = hardlight ? blend_pos : dst_pos; - - for (u32 y = 0; y < size.Y; y++) - for (u32 x = 0; x < size.X; x++) { - s32 base_x = x + base_layer_pos.X; - s32 base_y = y + base_layer_pos.Y; - - video::SColor blend_c = - blend_layer->getPixel(x + blend_layer_pos.X, y + blend_layer_pos.Y); - video::SColor base_c = base_layer->getPixel(base_x, base_y); - double blend_r = blend_c.getRed() / 255.0; - double blend_g = blend_c.getGreen() / 255.0; - double blend_b = blend_c.getBlue() / 255.0; - double base_r = base_c.getRed() / 255.0; - double base_g = base_c.getGreen() / 255.0; - double base_b = base_c.getBlue() / 255.0; - - base_c.set( - base_c.getAlpha(), - // Do a Multiply blend if less that 0.5, otherwise do a Screen blend - (u32)((base_r < 0.5 ? 2 * base_r * blend_r : 1 - 2 * (1 - base_r) * (1 - blend_r)) * 255), - (u32)((base_g < 0.5 ? 2 * base_g * blend_g : 1 - 2 * (1 - base_g) * (1 - blend_g)) * 255), - (u32)((base_b < 0.5 ? 2 * base_b * blend_b : 1 - 2 * (1 - base_b) * (1 - blend_b)) * 255) - ); - dst->setPixel(base_x, base_y, base_c); - } -} - -/* - Adjust the brightness and contrast of the base image. - - Conceptually like GIMP's "Brightness-Contrast" feature but allows brightness to be - wound all the way up to white or down to black. -*/ -static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 brightness, s32 contrast) -{ - video::SColor dst_c; - // Only allow normalized contrast to get as high as 127/128 to avoid infinite slope. - // (we could technically allow -128/128 here as that would just result in 0 slope) - double norm_c = core::clamp(contrast, -127, 127) / 128.0; - double norm_b = core::clamp(brightness, -127, 127) / 127.0; - - // Scale brightness so its range is -127.5 to 127.5, otherwise brightness - // adjustments will outputs values from 0.5 to 254.5 instead of 0 to 255. - double scaled_b = brightness * 127.5 / 127; - - // Calculate a contrast slope such that that no colors will get clamped due - // to the brightness setting. - // This allows the texture modifier to used as a brightness modifier without - // the user having to calculate a contrast to avoid clipping at that brightness. - double slope = 1 - fabs(norm_b); - - // Apply the user's contrast adjustment to the calculated slope, such that - // -127 will make it near-vertical and +127 will make it horizontal - double angle = atan(slope); - angle += norm_c <= 0 - ? norm_c * angle // allow contrast slope to be lowered to 0 - : norm_c * (M_PI_2 - angle); // allow contrast slope to be raised almost vert. - slope = tan(angle); - - double c = slope <= 1 - ? -slope * 127.5 + 127.5 + scaled_b // shift up/down when slope is horiz. - : -slope * (127.5 - scaled_b) + 127.5; // shift left/right when slope is vert. - - // add 0.5 to c so that when the final result is cast to int, it is effectively - // rounded rather than trunc'd. - c += 0.5; - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - - dst_c.set( - dst_c.getAlpha(), - core::clamp((int)(slope * dst_c.getRed() + c), 0, 255), - core::clamp((int)(slope * dst_c.getGreen() + c), 0, 255), - core::clamp((int)(slope * dst_c.getBlue() + c), 0, 255) - ); - dst->setPixel(x, y, dst_c); - } -} - -/* - Apply mask to destination -*/ -static void apply_mask(video::IImage *mask, video::IImage *dst, - v2s32 mask_pos, v2s32 dst_pos, v2u32 size) -{ - for (u32 y0 = 0; y0 < size.Y; y0++) { - for (u32 x0 = 0; x0 < size.X; x0++) { - s32 mask_x = x0 + mask_pos.X; - s32 mask_y = y0 + mask_pos.Y; - s32 dst_x = x0 + dst_pos.X; - s32 dst_y = y0 + dst_pos.Y; - video::SColor mask_c = mask->getPixel(mask_x, mask_y); - video::SColor dst_c = dst->getPixel(dst_x, dst_y); - dst_c.color &= mask_c.color; - dst->setPixel(dst_x, dst_y, dst_c); - } - } -} - -video::IImage *create_crack_image(video::IImage *crack, s32 frame_index, - core::dimension2d size, u8 tiles, video::IVideoDriver *driver) -{ - core::dimension2d strip_size = crack->getDimension(); - - if (tiles == 0 || strip_size.getArea() == 0) - return nullptr; - - core::dimension2d frame_size(strip_size.Width, strip_size.Width); - core::dimension2d tile_size(size / tiles); - s32 frame_count = strip_size.Height / strip_size.Width; - if (frame_index >= frame_count) - frame_index = frame_count - 1; - core::rect frame(v2s32(0, frame_index * frame_size.Height), frame_size); - video::IImage *result = nullptr; - - // extract crack frame - video::IImage *crack_tile = driver->createImage(video::ECF_A8R8G8B8, tile_size); - if (!crack_tile) - return nullptr; - if (tile_size == frame_size) { - crack->copyTo(crack_tile, v2s32(0, 0), frame); - } else { - video::IImage *crack_frame = driver->createImage(video::ECF_A8R8G8B8, frame_size); - if (!crack_frame) - goto exit__has_tile; - crack->copyTo(crack_frame, v2s32(0, 0), frame); - crack_frame->copyToScaling(crack_tile); - crack_frame->drop(); - } - if (tiles == 1) - return crack_tile; - - // tile it - result = driver->createImage(video::ECF_A8R8G8B8, size); - if (!result) - goto exit__has_tile; - result->fill({}); - for (u8 i = 0; i < tiles; i++) - for (u8 j = 0; j < tiles; j++) - crack_tile->copyTo(result, v2s32(i * tile_size.Width, j * tile_size.Height)); - -exit__has_tile: - crack_tile->drop(); - return result; -} - -static void draw_crack(video::IImage *crack, video::IImage *dst, - bool use_overlay, s32 frame_count, s32 progression, - video::IVideoDriver *driver, u8 tiles) -{ - // Dimension of destination image - core::dimension2d dim_dst = dst->getDimension(); - // Limit frame_count - if (frame_count > (s32) dim_dst.Height) - frame_count = dim_dst.Height; - if (frame_count < 1) - frame_count = 1; - // Dimension of the scaled crack stage, - // which is the same as the dimension of a single destination frame - core::dimension2d frame_size( - dim_dst.Width, - dim_dst.Height / frame_count - ); - video::IImage *crack_scaled = create_crack_image(crack, progression, - frame_size, tiles, driver); - if (!crack_scaled) - return; - - auto blit = use_overlay ? blit_with_alpha : blit_with_alpha; - for (s32 i = 0; i < frame_count; ++i) { - v2s32 dst_pos(0, frame_size.Height * i); - blit(crack_scaled, dst, v2s32(0,0), dst_pos, frame_size); - } - - crack_scaled->drop(); -} - -void brighten(video::IImage *image) -{ - if (image == NULL) - return; - - core::dimension2d dim = image->getDimension(); - - for (u32 y=0; ygetPixel(x,y); - c.setRed(0.5 * 255 + 0.5 * (float)c.getRed()); - c.setGreen(0.5 * 255 + 0.5 * (float)c.getGreen()); - c.setBlue(0.5 * 255 + 0.5 * (float)c.getBlue()); - image->setPixel(x,y,c); - } -} - -u32 parseImageTransform(std::string_view s) -{ - int total_transform = 0; - - std::string transform_names[8]; - transform_names[0] = "i"; - transform_names[1] = "r90"; - transform_names[2] = "r180"; - transform_names[3] = "r270"; - transform_names[4] = "fx"; - transform_names[6] = "fy"; - - std::size_t pos = 0; - while(pos < s.size()) - { - int transform = -1; - for (int i = 0; i <= 7; ++i) - { - const std::string &name_i = transform_names[i]; - - if (s[pos] == ('0' + i)) - { - transform = i; - pos++; - break; - } - - if (!(name_i.empty()) && lowercase(s.substr(pos, name_i.size())) == name_i) { - transform = i; - pos += name_i.size(); - break; - } - } - if (transform < 0) - break; - - // Multiply total_transform and transform in the group D4 - int new_total = 0; - if (transform < 4) - new_total = (transform + total_transform) % 4; - else - new_total = (transform - total_transform + 8) % 4; - if ((transform >= 4) ^ (total_transform >= 4)) - new_total += 4; - - total_transform = new_total; - } - return total_transform; -} - -core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim) -{ - if (transform % 2 == 0) - return dim; - - return core::dimension2d(dim.Height, dim.Width); -} - -void imageTransform(u32 transform, video::IImage *src, video::IImage *dst) -{ - if (src == NULL || dst == NULL) - return; - - core::dimension2d dstdim = dst->getDimension(); - - // Pre-conditions - assert(dstdim == imageTransformDimension(transform, src->getDimension())); - assert(transform <= 7); - - /* - Compute the transformation from source coordinates (sx,sy) - to destination coordinates (dx,dy). - */ - int sxn = 0; - int syn = 2; - if (transform == 0) // identity - sxn = 0, syn = 2; // sx = dx, sy = dy - else if (transform == 1) // rotate by 90 degrees ccw - sxn = 3, syn = 0; // sx = (H-1) - dy, sy = dx - else if (transform == 2) // rotate by 180 degrees - sxn = 1, syn = 3; // sx = (W-1) - dx, sy = (H-1) - dy - else if (transform == 3) // rotate by 270 degrees ccw - sxn = 2, syn = 1; // sx = dy, sy = (W-1) - dx - else if (transform == 4) // flip x - sxn = 1, syn = 2; // sx = (W-1) - dx, sy = dy - else if (transform == 5) // flip x then rotate by 90 degrees ccw - sxn = 2, syn = 0; // sx = dy, sy = dx - else if (transform == 6) // flip y - sxn = 0, syn = 3; // sx = dx, sy = (H-1) - dy - else if (transform == 7) // flip y then rotate by 90 degrees ccw - sxn = 3, syn = 1; // sx = (H-1) - dy, sy = (W-1) - dx - - for (u32 dy=0; dygetPixel(sx,sy); - dst->setPixel(dx,dy,c); - } -} - -video::ITexture* TextureSource::getNormalTexture(const std::string &name) -{ - if (isKnownSourceImage("override_normal.png")) - return getTexture("override_normal.png"); - std::string fname_base = name; - static const char *normal_ext = "_normal.png"; - static const u32 normal_ext_size = strlen(normal_ext); - size_t pos = fname_base.find('.'); - std::string fname_normal = fname_base.substr(0, pos) + normal_ext; - if (isKnownSourceImage(fname_normal)) { - // look for image extension and replace it - size_t i = 0; - while ((i = fname_base.find('.', i)) != std::string::npos) { - fname_base.replace(i, 4, normal_ext); - i += normal_ext_size; - } - return getTexture(fname_base); - } - return NULL; -} - -namespace { - // For more colourspace transformations, see for example - // https://github.com/tobspr/GLSL-Color-Spaces/blob/master/ColorSpaces.inc.glsl - - inline float linear_to_srgb_component(float v) - { - if (v > 0.0031308f) - return 1.055f * powf(v, 1.0f / 2.4f) - 0.055f; - return 12.92f * v; - } - inline float srgb_to_linear_component(float v) - { - if (v > 0.04045f) - return powf((v + 0.055f) / 1.055f, 2.4f); - return v / 12.92f; - } - - v3f srgb_to_linear(const video::SColor col_srgb) - { - v3f col(col_srgb.getRed(), col_srgb.getGreen(), col_srgb.getBlue()); - col /= 255.0f; - col.X = srgb_to_linear_component(col.X); - col.Y = srgb_to_linear_component(col.Y); - col.Z = srgb_to_linear_component(col.Z); - return col; - } - - video::SColor linear_to_srgb(const v3f col_linear) - { - v3f col; - col.X = linear_to_srgb_component(col_linear.X); - col.Y = linear_to_srgb_component(col_linear.Y); - col.Z = linear_to_srgb_component(col_linear.Z); - col *= 255.0f; - col.X = core::clamp(col.X, 0.0f, 255.0f); - col.Y = core::clamp(col.Y, 0.0f, 255.0f); - col.Z = core::clamp(col.Z, 0.0f, 255.0f); - return video::SColor(0xff, myround(col.X), myround(col.Y), - myround(col.Z)); - } -} - -video::SColor TextureSource::getTextureAverageColor(const std::string &name) -{ - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - video::SColor c(0, 0, 0, 0); - video::ITexture *texture = getTexture(name); - if (!texture) - return c; - video::IImage *image = driver->createImage(texture, - core::position2d(0, 0), - texture->getOriginalSize()); - if (!image) - return c; - - u32 total = 0; - v3f col_acc(0, 0, 0); - core::dimension2d dim = image->getDimension(); - u16 step = 1; - if (dim.Width > 16) - step = dim.Width / 16; - for (u16 x = 0; x < dim.Width; x += step) { - for (u16 y = 0; y < dim.Width; y += step) { - c = image->getPixel(x,y); - if (c.getAlpha() > 0) { - total++; - col_acc += srgb_to_linear(c); - } - } - } - image->drop(); - if (total > 0) { - col_acc /= total; - c = linear_to_srgb(col_acc); - } - c.setAlpha(255); - return c; -} - - -video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present) -{ - std::string tname = "__shaderFlagsTexture"; - tname += normalmap_present ? "1" : "0"; - - if (isKnownSourceImage(tname)) { - return getTexture(tname); - } - - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - video::IImage *flags_image = driver->createImage( - video::ECF_A8R8G8B8, core::dimension2d(1, 1)); - sanity_check(flags_image != NULL); - video::SColor c(255, normalmap_present ? 255 : 0, 0, 0); - flags_image->setPixel(0, 0, c); - insertSourceImage(tname, flags_image); - flags_image->drop(); - return getTexture(tname); - -} - -std::vector getTextureDirs() -{ - return fs::GetRecursiveDirs(g_settings->get("texture_path")); -} +// Empty after splitting tile.h diff --git a/src/client/tile.h b/src/client/tile.h index 6deda1df5..3460edc2c 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -20,118 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes.h" -#include "irr_v3d.h" #include -#include #include #include -#include "util/numeric.h" -#include "config.h" - -class IGameDef; -struct TileSpec; -struct TileDef; - -namespace irr::video { class IVideoDriver; } - -typedef std::vector Palette; - -/* - tile.{h,cpp}: Texture handling stuff. -*/ - -/* - Find out the full path of an image by trying different filename - extensions. - - If failed, return "". - - TODO: Should probably be moved out from here, because things needing - this function do not need anything else from this header -*/ -std::string getImagePath(std::string path); - -/* - Gets the path to a texture by first checking if the texture exists - in texture_path and if not, using the data path. - - Checks all supported extensions by replacing the original extension. - - If not found, returns "". - - Utilizes a thread-safe cache. -*/ -std::string getTexturePath(const std::string &filename, bool *is_base_pack = nullptr); - -void clearTextureNameCache(); - -/* - TextureSource creates and caches textures. -*/ - -class ISimpleTextureSource -{ -public: - ISimpleTextureSource() = default; - - virtual ~ISimpleTextureSource() = default; - - virtual video::ITexture* getTexture( - const std::string &name, u32 *id = nullptr) = 0; -}; - -class ITextureSource : public ISimpleTextureSource -{ -public: - ITextureSource() = default; - - virtual ~ITextureSource() = default; - - virtual u32 getTextureId(const std::string &name)=0; - virtual std::string getTextureName(u32 id)=0; - virtual video::ITexture* getTexture(u32 id)=0; - virtual video::ITexture* getTexture( - const std::string &name, u32 *id = nullptr)=0; - virtual video::ITexture* getTextureForMesh( - const std::string &name, u32 *id = nullptr) = 0; - /*! - * Returns a palette from the given texture name. - * The pointer is valid until the texture source is - * destructed. - * Should be called from the main thread. - */ - virtual Palette* getPalette(const std::string &name) = 0; - virtual bool isKnownSourceImage(const std::string &name)=0; - virtual video::ITexture* getNormalTexture(const std::string &name)=0; - virtual video::SColor getTextureAverageColor(const std::string &name)=0; - virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0; -}; - -class IWritableTextureSource : public ITextureSource -{ -public: - IWritableTextureSource() = default; - - virtual ~IWritableTextureSource() = default; - - virtual u32 getTextureId(const std::string &name)=0; - virtual std::string getTextureName(u32 id)=0; - virtual video::ITexture* getTexture(u32 id)=0; - virtual video::ITexture* getTexture( - const std::string &name, u32 *id = nullptr)=0; - virtual bool isKnownSourceImage(const std::string &name)=0; - - virtual void processQueue()=0; - virtual void insertSourceImage(const std::string &name, video::IImage *img)=0; - virtual void rebuildImagesAndTextures()=0; - virtual video::ITexture* getNormalTexture(const std::string &name)=0; - virtual video::SColor getTextureAverageColor(const std::string &name)=0; - virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0; -}; - -IWritableTextureSource *createTextureSource(); - -video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver); enum MaterialType{ TILE_MATERIAL_BASIC, @@ -318,5 +209,3 @@ struct TileSpec //! The first is base texture, the second is overlay. TileLayer layers[MAX_TILE_LAYERS]; }; - -std::vector getTextureDirs(); diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp index 0ec927189..611b09308 100644 --- a/src/content/subgames.cpp +++ b/src/content/subgames.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #ifndef SERVER -#include "client/tile.h" // getImagePath +#include "client/texturepaths.h" #endif // The maximum number of identical world names allowed diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h index ab132f69e..ef7416bca 100644 --- a/src/gui/StyleSpec.h +++ b/src/gui/StyleSpec.h @@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "client/tile.h" // ITextureSource +#include "client/texturesource.h" #include "client/fontengine.h" #include "debug.h" #include "irrlichttypes_extrabloated.h" diff --git a/src/gui/guiAnimatedImage.cpp b/src/gui/guiAnimatedImage.cpp index 890763e71..5e14d2ef2 100644 --- a/src/gui/guiAnimatedImage.cpp +++ b/src/gui/guiAnimatedImage.cpp @@ -1,7 +1,6 @@ #include "guiAnimatedImage.h" #include "client/guiscalingfilter.h" -#include "client/tile.h" // ITextureSource #include "log.h" #include "porting.h" #include "util/string.h" diff --git a/src/gui/guiBackgroundImage.cpp b/src/gui/guiBackgroundImage.cpp index 987287fce..96197ca2c 100644 --- a/src/gui/guiBackgroundImage.cpp +++ b/src/gui/guiBackgroundImage.cpp @@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "guiBackgroundImage.h" #include "client/guiscalingfilter.h" #include "log.h" +#include "client/texturesource.h" GUIBackgroundImage::GUIBackgroundImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, const core::rect &rectangle, diff --git a/src/gui/guiBackgroundImage.h b/src/gui/guiBackgroundImage.h index 2e51a8190..71c5b5077 100644 --- a/src/gui/guiBackgroundImage.h +++ b/src/gui/guiBackgroundImage.h @@ -19,7 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "irrlichttypes_extrabloated.h" #include "util/string.h" -#include "client/tile.h" // ITextureSource + +class ISimpleTextureSource; + class GUIBackgroundImage : public gui::IGUIElement { diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index d19188699..30a9b45cc 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -6,7 +6,6 @@ #include "client/guiscalingfilter.h" -#include "client/tile.h" #include "IGUISkin.h" #include "IGUIEnvironment.h" #include "IVideoDriver.h" diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index f10b41940..243828df0 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/keycode.h" #include "settings.h" #include "porting.h" -#include "client/tile.h" +#include "client/texturesource.h" #include "client/fontengine.h" #include "log.h" #include "gettext.h" diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 923ca4bcd..e70f4529d 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "version.h" #include #include +#include "client/imagefilters.h" #if USE_SOUND #include "client/sound/sound_openal.h" diff --git a/src/gui/guiEngine.h b/src/gui/guiEngine.h index 688648be1..b2b396537 100644 --- a/src/gui/guiEngine.h +++ b/src/gui/guiEngine.h @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiFormSpecMenu.h" #include "client/clouds.h" #include "client/sound.h" -#include "client/tile.h" #include "util/enriched_string.h" #include "translation.h" diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index e4e123c16..0c616967c 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -39,7 +39,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "client/renderingengine.h" #include "log.h" -#include "client/tile.h" // ITextureSource #include "client/hud.h" // drawItemStack #include "filesys.h" #include "gettime.h" diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 8aba3083c..0929fc99f 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiHyperText.h" #include "guiScrollBar.h" #include "client/fontengine.h" -#include "client/tile.h" #include "IVideoDriver.h" #include "client/client.h" #include "client/renderingengine.h" diff --git a/src/gui/guiTable.cpp b/src/gui/guiTable.cpp index 7d2cf66f3..81c38ffd8 100644 --- a/src/gui/guiTable.cpp +++ b/src/gui/guiTable.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/renderingengine.h" #include "debug.h" #include "log.h" -#include "client/tile.h" +#include "client/texturesource.h" #include "gettime.h" #include "util/string.h" #include "util/numeric.h" diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 959f7ceb5..1e9aa128d 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -32,7 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "itemdef.h" -#include "client/tile.h" #include "client/game.h" using namespace irr; diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 363b94983..5031487ea 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/mapblock_mesh.h" #include "client/mesh.h" #include "client/wieldmesh.h" -#include "client/tile.h" #include "client/client.h" #endif #include "log.h" diff --git a/src/itemdef.h b/src/itemdef.h index f8cb1b613..884d31501 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -35,7 +35,7 @@ class Client; struct ToolCapabilities; struct PointedThing; #ifndef SERVER -#include "client/tile.h" +#include "client/texturesource.h" struct ItemMesh; struct ItemStack; #endif diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 6fc220145..1ce0a5c74 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -357,7 +357,7 @@ void ContentFeatures::reset() has_on_destruct = false; has_after_destruct = false; floats = false; - + /* Actual data From 879f7e9f0373cd331eca188f7dbc80ad73fac58f Mon Sep 17 00:00:00 2001 From: cx384 Date: Tue, 27 Feb 2024 19:03:46 +0100 Subject: [PATCH 18/91] Refactor tile.cpp/h parts except texturesource.cpp --- src/client/imagefilters.cpp | 10 ++- src/client/texturepaths.cpp | 118 ++++++++++++------------------------ src/client/texturepaths.h | 2 +- src/client/tile.cpp | 67 +++++++++++++++++++- src/client/tile.h | 45 +------------- 5 files changed, 112 insertions(+), 130 deletions(-) diff --git a/src/client/imagefilters.cpp b/src/client/imagefilters.cpp index 7c4dc094f..db6523ad3 100644 --- a/src/client/imagefilters.cpp +++ b/src/client/imagefilters.cpp @@ -273,16 +273,14 @@ void imageScaleNNAA(video::IImage *src, const core::rect &srcrect, video::I } } -/** - * Check and align image to npot2 if required by hardware +/* Check and align image to npot2 if required by hardware * @param image image to check for npot2 alignment * @param driver driver to use for image operations * @return image or copy of image aligned to npot2 */ -video::IImage *Align2Npot2(video::IImage *image, - video::IVideoDriver *driver) +video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver) { - if (image == NULL) + if (image == nullptr) return image; if (driver->queryFeature(video::EVDF_TEXTURE_NPOT)) @@ -304,7 +302,7 @@ video::IImage *Align2Npot2(video::IImage *image, driver->createImage(video::ECF_A8R8G8B8, core::dimension2d(width, height)); - if (targetimage != NULL) + if (targetimage != nullptr) image->copyToScaling(targetimage); image->drop(); return targetimage; diff --git a/src/client/texturepaths.cpp b/src/client/texturepaths.cpp index b4bb93ee7..ba28a243c 100644 --- a/src/client/texturepaths.cpp +++ b/src/client/texturepaths.cpp @@ -23,77 +23,51 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include "filesys.h" #include "porting.h" +#include -/* - A cache from texture name to texture path -*/ +// A cache from texture name to texture path static MutexedMap g_texturename_to_path_cache; -/* - Replaces the filename extension. - eg: - std::string image = "a/image.png" - replace_ext(image, "jpg") - -> image = "a/image.jpg" - Returns true on success. -*/ -static bool replace_ext(std::string &path, const char *ext) +void clearTextureNameCache() { - if (ext == NULL) - return false; - // Find place of last dot, fail if \ or / found. - s32 last_dot_i = -1; - for (s32 i=path.size()-1; i>=0; i--) - { - if (path[i] == '.') - { - last_dot_i = i; - break; - } - - if (path[i] == '\\' || path[i] == '/') - break; - } - // If not found, return an empty string - if (last_dot_i == -1) - return false; - // Else make the new path - path = path.substr(0, last_dot_i+1) + ext; - return true; + g_texturename_to_path_cache.clear(); } -/* - Find out the full path of an image by trying different filename - extensions. - If failed, return "". -*/ -std::string getImagePath(std::string path) +// Find out the full path of an image by trying different filename extensions. +// If failed, return "". +std::string getImagePath(std::string_view path) { // A NULL-ended list of possible image extensions - const char *extensions[] = { "png", "jpg", "bmp", "tga", NULL }; - // If there is no extension, assume PNG - if (removeStringEnd(path, extensions).empty()) - path = path + ".png"; - // Check paths until something is found to exist - const char **ext = extensions; - do{ - bool r = replace_ext(path, *ext); - if (!r) - return ""; - if (fs::PathExists(path)) - return path; + // (In newer C++ versions a fixed size array and ranges::subrange could be used + // or just modernise removeStringEnd.) + static const char *extensions[] = {".png", ".jpg", ".bmp", ".tga", nullptr}; + + // Remove present extension + std::string_view stripped_path = removeStringEnd(path, extensions); + // If there is no known extension, assume it has been omitted. + if (stripped_path.empty()) + stripped_path = path; + + for (const char *ext : extensions) { + if (!ext) + break; + std::string extended_path(stripped_path); + extended_path.append(ext); + if (fs::PathExists(extended_path)) + return extended_path; } - while((++ext) != NULL); return ""; } -/* - Gets the path to a texture by first checking if the texture exists - in texture_path and if not, using the data path. - Checks all supported extensions by replacing the original extension. - If not found, returns "". - Utilizes a thread-safe cache. +/* Gets the path to a texture by first checking if the texture exists + * in texture_path and if not, using the data path. + * + * Checks all supported extensions by replacing the original extension. + * + * If not found, returns "". + * + * Utilizes a thread-safe cache. */ std::string getTexturePath(const std::string &filename, bool *is_base_pack) { @@ -103,35 +77,26 @@ std::string getTexturePath(const std::string &filename, bool *is_base_pack) // is_base_pack is only passed when initializing the textures the first time if (is_base_pack) *is_base_pack = false; - /* - Check from cache - */ + + // Check from cache bool incache = g_texturename_to_path_cache.get(filename, &fullpath); if (incache) return fullpath; - /* - Check from texture_path - */ + // Check from texture_path setting for (const auto &path : getTextureDirs()) { - std::string testpath = path + DIR_DELIM; - testpath.append(filename); // Check all filename extensions. Returns "" if not found. - fullpath = getImagePath(testpath); + fullpath = getImagePath(path + DIR_DELIM + filename); if (!fullpath.empty()) break; } - /* - Check from default data directory - */ - if (fullpath.empty()) - { + // Check from default data directory i.e. .../minetest/textures/base/pack + if (fullpath.empty()) { std::string base_path = porting::path_share + DIR_DELIM + "textures" + DIR_DELIM + "base" + DIR_DELIM + "pack"; - std::string testpath = base_path + DIR_DELIM + filename; // Check all filename extensions. Returns "" if not found. - fullpath = getImagePath(testpath); + fullpath = getImagePath(base_path + DIR_DELIM + filename); if (is_base_pack && !fullpath.empty()) *is_base_pack = true; } @@ -143,11 +108,6 @@ std::string getTexturePath(const std::string &filename, bool *is_base_pack) return fullpath; } -void clearTextureNameCache() -{ - g_texturename_to_path_cache.clear(); -} - std::vector getTextureDirs() { return fs::GetRecursiveDirs(g_settings->get("texture_path")); diff --git a/src/client/texturepaths.h b/src/client/texturepaths.h index 38ed0325d..dc5119188 100644 --- a/src/client/texturepaths.h +++ b/src/client/texturepaths.h @@ -27,7 +27,7 @@ void clearTextureNameCache(); // Find out the full path of an image by trying different filename extensions. // If failed, return "". -std::string getImagePath(std::string path); +std::string getImagePath(std::string_view path); /* Gets the path to a texture by first checking if the texture exists * in texture_path and if not, using the data path. diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 0dc817b7b..1870547da 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -1 +1,66 @@ -// Empty after splitting tile.h +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "tile.h" + +// Sets everything else except the texture in the material +void TileLayer::applyMaterialOptions(video::SMaterial &material) const +{ + switch (material_type) { + case TILE_MATERIAL_OPAQUE: + case TILE_MATERIAL_LIQUID_OPAQUE: + case TILE_MATERIAL_WAVING_LIQUID_OPAQUE: + material.MaterialType = video::EMT_SOLID; + break; + case TILE_MATERIAL_BASIC: + case TILE_MATERIAL_WAVING_LEAVES: + case TILE_MATERIAL_WAVING_PLANTS: + case TILE_MATERIAL_WAVING_LIQUID_BASIC: + material.MaterialTypeParam = 0.5; + material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + break; + case TILE_MATERIAL_ALPHA: + case TILE_MATERIAL_LIQUID_TRANSPARENT: + case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT: + material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + break; + default: + break; + } + material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0; + if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) { + material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; + } + if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) { + material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; + } +} + +void TileLayer::applyMaterialOptionsWithShaders(video::SMaterial &material) const +{ + material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0; + if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) { + material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; + material.TextureLayers[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE; + } + if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) { + material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; + material.TextureLayers[1].TextureWrapV = video::ETC_CLAMP_TO_EDGE; + } +} diff --git a/src/client/tile.h b/src/client/tile.h index 3460edc2c..d761eefdd 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -96,50 +96,9 @@ struct TileLayer } // Sets everything else except the texture in the material - void applyMaterialOptions(video::SMaterial &material) const - { - switch (material_type) { - case TILE_MATERIAL_OPAQUE: - case TILE_MATERIAL_LIQUID_OPAQUE: - case TILE_MATERIAL_WAVING_LIQUID_OPAQUE: - material.MaterialType = video::EMT_SOLID; - break; - case TILE_MATERIAL_BASIC: - case TILE_MATERIAL_WAVING_LEAVES: - case TILE_MATERIAL_WAVING_PLANTS: - case TILE_MATERIAL_WAVING_LIQUID_BASIC: - material.MaterialTypeParam = 0.5; - material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; - break; - case TILE_MATERIAL_ALPHA: - case TILE_MATERIAL_LIQUID_TRANSPARENT: - case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT: - material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; - break; - default: - break; - } - material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0; - if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) { - material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; - } - if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) { - material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; - } - } + void applyMaterialOptions(video::SMaterial &material) const; - void applyMaterialOptionsWithShaders(video::SMaterial &material) const - { - material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0; - if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) { - material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; - material.TextureLayers[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE; - } - if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) { - material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; - material.TextureLayers[1].TextureWrapV = video::ETC_CLAMP_TO_EDGE; - } - } + void applyMaterialOptionsWithShaders(video::SMaterial &material) const; bool isTransparent() const { From d4d47123615327b36733024404e7259a2fc9d8f2 Mon Sep 17 00:00:00 2001 From: DS Date: Sun, 3 Mar 2024 15:53:23 +0100 Subject: [PATCH 19/91] Implement get_node with a get_node_raw (#14384) Add /bench_bulk_get_node Considerably improves the execution speed of core.get_node --- builtin/game/item.lua | 19 ++++++++ games/devtest/mods/benchmarks/init.lua | 65 ++++++++++++++++++++------ src/script/lua_api/l_env.cpp | 42 ++++++----------- src/script/lua_api/l_env.h | 13 ++---- 4 files changed, 90 insertions(+), 49 deletions(-) diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 498e5899f..8b79d2d71 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -736,3 +736,22 @@ core.noneitemdef_default = { -- This is used for the hand and unknown items on_drop = nil, on_use = nil, } + +-- +-- get_node implementation +-- + +local get_node_raw = core.get_node_raw +core.get_node_raw = nil + +function core.get_node(pos) + local content, param1, param2 = get_node_raw(pos.x, pos.y, pos.z) + return {name = core.get_name_from_content_id(content), param1 = param1, param2 = param2} +end + +function core.get_node_or_nil(pos) + local content, param1, param2, pos_ok = get_node_raw(pos.x, pos.y, pos.z) + return pos_ok and + {name = core.get_name_from_content_id(content), param1 = param1, param2 = param2} + or nil +end diff --git a/games/devtest/mods/benchmarks/init.lua b/games/devtest/mods/benchmarks/init.lua index 19ba044a4..1f5001c69 100644 --- a/games/devtest/mods/benchmarks/init.lua +++ b/games/devtest/mods/benchmarks/init.lua @@ -71,6 +71,22 @@ minetest.register_chatcommand("bench_content2name", { end, }) +local function get_positions_cube(ppos) + local pos_list = {} + + local i = 1 + for x=2,100 do + for y=2,100 do + for z=2,100 do + pos_list[i] = ppos:offset(x, y, z) + i = i + 1 + end + end + end + + return pos_list +end + minetest.register_chatcommand("bench_bulk_set_node", { params = "", description = "Benchmark: Bulk-set 99×99×99 stone nodes", @@ -79,25 +95,15 @@ minetest.register_chatcommand("bench_bulk_set_node", { if not player then return false, "No player." end - local pos_list = {} - local ppos = player:get_pos() - local i = 1 - for x=2,100 do - for y=2,100 do - for z=2,100 do - pos_list[i] = {x=ppos.x + x,y = ppos.y + y,z = ppos.z + z} - i = i + 1 - end - end - end + local pos_list = get_positions_cube(player:get_pos()) - minetest.chat_send_player(name, "Benchmarking minetest.bulk_set_node. Warming up ..."); + minetest.chat_send_player(name, "Benchmarking minetest.bulk_set_node. Warming up ...") -- warm up with stone to prevent having different callbacks -- due to different node topology minetest.bulk_set_node(pos_list, {name = "mapgen_stone"}) - minetest.chat_send_player(name, "Warming up finished, now benchmarking ..."); + minetest.chat_send_player(name, "Warming up finished, now benchmarking ...") local start_time = minetest.get_us_time() for i=1,#pos_list do @@ -114,4 +120,37 @@ minetest.register_chatcommand("bench_bulk_set_node", { end, }) +minetest.register_chatcommand("bench_bulk_get_node", { + params = "", + description = "Benchmark: Bulk-get 99×99×99 nodes", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local pos_list = get_positions_cube(player:get_pos()) + local function bench() + local start_time = minetest.get_us_time() + for i=1,#pos_list do + local n = minetest.get_node(pos_list[i]) + -- Make sure the name lookup is never optimized away. + -- Table allocation might still be omitted. But only accessing + -- the name of a node is a common pattern anyways. + if n.name == "benchmarks:nonexistent_node" then + error("should never happen") + end + end + return minetest.get_us_time() - start_time + end + minetest.chat_send_player(name, "Benchmarking minetest.get_node. Warming up ...") + bench() + + minetest.chat_send_player(name, "Warming up finished, now benchmarking ...") + local result_us = bench() + + local msg = string.format("Benchmark results: minetest.get_node loop 1: %.2f ms", + result_us / 1000) + return true, msg + end, +}) diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index c6a427e48..3b9be8314 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -328,39 +328,26 @@ int ModApiEnv::l_swap_node(lua_State *L) return 1; } -// get_node(pos) -// pos = {x=num, y=num, z=num} -int ModApiEnv::l_get_node(lua_State *L) +// get_node_raw(x, y, z) -> content, param1, param2, pos_ok +int ModApiEnv::l_get_node_raw(lua_State *L) { GET_ENV_PTR; // pos - v3s16 pos = read_v3s16(L, 1); - // Do it - MapNode n = env->getMap().getNode(pos); - // Return node - pushnode(L, n); - return 1; -} - -// get_node_or_nil(pos) -// pos = {x=num, y=num, z=num} -int ModApiEnv::l_get_node_or_nil(lua_State *L) -{ - GET_ENV_PTR; - - // pos - v3s16 pos = read_v3s16(L, 1); + // mirrors implementation of read_v3s16 (with the exact same rounding) + double x = lua_tonumber(L, 1); + double y = lua_tonumber(L, 2); + double z = lua_tonumber(L, 3); + v3s16 pos = doubleToInt(v3d(x, y, z), 1.0); // Do it bool pos_ok; MapNode n = env->getMap().getNode(pos, &pos_ok); - if (pos_ok) { - // Return node - pushnode(L, n); - } else { - lua_pushnil(L); - } - return 1; + // Return node and pos_ok + lua_pushinteger(L, n.getContent()); + lua_pushinteger(L, n.getParam1()); + lua_pushinteger(L, n.getParam2()); + lua_pushboolean(L, pos_ok); + return 4; } // get_node_light(pos, timeofday) @@ -1483,8 +1470,7 @@ void ModApiEnv::Initialize(lua_State *L, int top) API_FCT(swap_node); API_FCT(add_item); API_FCT(remove_node); - API_FCT(get_node); - API_FCT(get_node_or_nil); + API_FCT(get_node_raw); API_FCT(get_node_light); API_FCT(get_natural_light); API_FCT(place_node); diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 327cf9f75..ad4ac2d73 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -74,13 +74,10 @@ private: // pos = {x=num, y=num, z=num} static int l_swap_node(lua_State *L); - // get_node(pos) - // pos = {x=num, y=num, z=num} - static int l_get_node(lua_State *L); - - // get_node_or_nil(pos) - // pos = {x=num, y=num, z=num} - static int l_get_node_or_nil(lua_State *L); + // get_node_raw(x, y, z) -> content, param1, param2, pos_ok + // Used to implement get_node and get_node_or_nil in lua. + // This is still faster than doing it from C++ even with optimized pushnode. + static int l_get_node_raw(lua_State *L); // get_node_light(pos, timeofday) // pos = {x=num, y=num, z=num} @@ -245,7 +242,7 @@ public: /* * Duplicates of certain env APIs that operate not on the global - * map but on a VoxelManipulator. This is for emerge scripting. + * map but on a VoxelManipulator. This is for emerge scripting. */ class ModApiEnvVM : public ModApiEnvBase { private: From 9b971476372d7f144c6e58c0749e1f0f9ce47cad Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 1 Mar 2024 19:20:01 +0100 Subject: [PATCH 20/91] Fix assertion failure in clientlauncher.cpp --- src/client/clientlauncher.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index b5ba4ccc8..995381112 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -267,12 +267,12 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) } } // Menu-game loop - assert(g_menuclouds->getReferenceCount() == 1); - g_menuclouds->drop(); - g_menuclouds = nullptr; assert(g_menucloudsmgr->getReferenceCount() == 1); g_menucloudsmgr->drop(); g_menucloudsmgr = nullptr; + assert(g_menuclouds->getReferenceCount() == 1); + g_menuclouds->drop(); + g_menuclouds = nullptr; return retval; } From 91ea47fddf6c59f04fed4af66fa23127466e46fb Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 24 Feb 2024 00:53:22 +0100 Subject: [PATCH 21/91] Fix node callbacks unit test --- doc/lua_api.md | 1 + games/devtest/mods/unittests/init.lua | 11 ++++++----- games/devtest/mods/unittests/misc.lua | 23 +++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 6dbc58cb0..6f3fccb9f 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5966,6 +5966,7 @@ Environment access returns `{name="ignore", param1=0, param2=0}` for unloaded areas. * `minetest.get_node_or_nil(pos)` * Same as `get_node` but returns `nil` for unloaded areas. + * Note that areas may still contain "ignore" despite being loaded. * `minetest.get_node_light(pos[, timeofday])` * Gets the light value at the given position. Note that the light value "inside" the node at the given position is returned, so you usually want diff --git a/games/devtest/mods/unittests/init.lua b/games/devtest/mods/unittests/init.lua index f048b7aa6..b01a6271c 100644 --- a/games/devtest/mods/unittests/init.lua +++ b/games/devtest/mods/unittests/init.lua @@ -108,9 +108,9 @@ local function wait_for_player(callback) end) end -local function wait_for_map(player, callback) +local function wait_for_map(pos, callback) local function check() - if core.get_node_or_nil(player:get_pos()) ~= nil then + if core.get_node(pos).name ~= "ignore" then callback() else core.after(0, check) @@ -119,8 +119,8 @@ local function wait_for_map(player, callback) check() end +-- This runs in a coroutine so it uses await() function unittests.run_all() - -- This runs in a coroutine so it uses await(). local counters = { time = 0, total = 0, passed = 0 } -- Run standalone tests first @@ -143,10 +143,11 @@ function unittests.run_all() end -- Wait for the world to generate/load, run tests that require map access + local pos = player:get_pos():round():offset(0, 5, 0) + core.forceload_block(pos, true, -1) await(function(cb) - wait_for_map(player, cb) + wait_for_map(pos, cb) end) - local pos = vector.round(player:get_pos()) for idx = 1, #unittests.list do local def = unittests.list[idx] if not def.done then diff --git a/games/devtest/mods/unittests/misc.lua b/games/devtest/mods/unittests/misc.lua index 034b99b52..6ff5c7e84 100644 --- a/games/devtest/mods/unittests/misc.lua +++ b/games/devtest/mods/unittests/misc.lua @@ -99,17 +99,24 @@ local function test_clear_meta(_, pos) end unittests.register("test_clear_meta", test_clear_meta, {map=true}) -local on_punch_called -minetest.register_on_punchnode(function() +local on_punch_called, on_place_called +core.register_on_placenode(function() + on_place_called = true +end) +core.register_on_punchnode(function() on_punch_called = true end) -unittests.register("test_punch_node", function(_, pos) - minetest.place_node(pos, {name="basenodes:dirt"}) +local function test_node_callbacks(_, pos) + on_place_called = false on_punch_called = false - minetest.punch_node(pos) - minetest.remove_node(pos) - -- currently failing: assert(on_punch_called) -end, {map=true}) + + core.place_node(pos, {name="basenodes:dirt"}) + assert(on_place_called, "on_place not called") + core.punch_node(pos) + assert(on_punch_called, "on_punch not called") + core.remove_node(pos) +end +unittests.register("test_node_callbacks", test_node_callbacks, {map=true}) local function test_hashing() local input = "hello\000world" From e734b3f0d8055ff3ae710f3632726a711603bf84 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 24 Feb 2024 09:49:42 +0100 Subject: [PATCH 22/91] Fix core.get_node_or_nil in emerge env "ignore" does not mean unloaded, we have to properly check it. --- builtin/emerge/env.lua | 5 ----- src/script/lua_api/l_env.cpp | 14 ++++++++++++++ src/script/lua_api/l_env.h | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/builtin/emerge/env.lua b/builtin/emerge/env.lua index 43848082a..2b32a0339 100644 --- a/builtin/emerge/env.lua +++ b/builtin/emerge/env.lua @@ -31,11 +31,6 @@ function core.get_node(pos) return core.vmanip:get_node_at(pos) end -function core.get_node_or_nil(pos) - local node = core.vmanip:get_node_at(pos) - return node.name ~= "ignore" and node -end - function core.get_perlin(seed, octaves, persist, spread) local params if type(seed) == "table" then diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 3b9be8314..1fc640d23 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -1534,6 +1534,19 @@ void ModApiEnv::InitializeClient(lua_State *L, int top) if (!vm) \ return 0 +// get_node_or_nil(pos) +int ModApiEnvVM::l_get_node_or_nil(lua_State *L) +{ + GET_VM_PTR; + + v3s16 pos = read_v3s16(L, 1); + if (vm->exists(pos)) + pushnode(L, vm->getNodeRefUnsafe(pos)); + else + lua_pushnil(L); + return 1; +} + // get_node_max_level(pos) int ModApiEnvVM::l_get_node_max_level(lua_State *L) { @@ -1703,6 +1716,7 @@ MMVManip *ModApiEnvVM::getVManip(lua_State *L) void ModApiEnvVM::InitializeEmerge(lua_State *L, int top) { // other, more trivial functions are in builtin/emerge/env.lua + API_FCT(get_node_or_nil); API_FCT(get_node_max_level); API_FCT(get_node_level); API_FCT(set_node_level); diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index ad4ac2d73..f657424d0 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -247,6 +247,9 @@ public: class ModApiEnvVM : public ModApiEnvBase { private: + // get_node_or_nil(pos) + static int l_get_node_or_nil(lua_State *L); + // get_node_max_level(pos) static int l_get_node_max_level(lua_State *L); From 585ca90ae0620dc8fd4dd7afb4ca3af433efbec7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 29 Feb 2024 12:52:42 +0100 Subject: [PATCH 23/91] Reorder ObjectProperties struct --- src/object_properties.cpp | 2 +- src/object_properties.h | 59 +++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 6f66fbaee..df3d245f9 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -32,7 +32,7 @@ ObjectProperties::ObjectProperties() colors.emplace_back(255,255,255,255); } -std::string ObjectProperties::dump() +std::string ObjectProperties::dump() const { std::ostringstream os(std::ios::binary); os << "hp_max=" << hp_max; diff --git a/src/object_properties.h b/src/object_properties.h index 557f128be..9d548343c 100644 --- a/src/object_properties.h +++ b/src/object_properties.h @@ -29,49 +29,60 @@ with this program; if not, write to the Free Software Foundation, Inc., struct ObjectProperties { - u16 hp_max = 1; - u16 breath_max = 0; - bool physical = false; - bool collideWithObjects = true; + /* member variables ordered roughly by size */ + + std::vector textures; + std::vector colors; // Values are BS=1 aabb3f collisionbox = aabb3f(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f); + // Values are BS=1 aabb3f selectionbox = aabb3f(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f); - bool rotate_selectionbox = false; - PointabilityType pointable = PointabilityType::POINTABLE; std::string visual = "sprite"; - std::string mesh = ""; - v3f visual_size = v3f(1, 1, 1); - std::vector textures; + std::string mesh; std::string damage_texture_modifier = "^[brighten"; - std::vector colors; + std::string nametag; + std::string infotext; + // For dropped items, this contains the serialized item. + std::string wield_item; + v3f visual_size = v3f(1, 1, 1); + video::SColor nametag_color = video::SColor(255, 255, 255, 255); + std::optional nametag_bgcolor; v2s16 spritediv = v2s16(1, 1); v2s16 initial_sprite_basepos; - bool is_visible = true; - bool makes_footstep_sound = false; f32 stepheight = 0.0f; float automatic_rotate = 0.0f; - bool automatic_face_movement_dir = false; f32 automatic_face_movement_dir_offset = 0.0f; - bool backface_culling = true; - s8 glow = 0; - std::string nametag = ""; - video::SColor nametag_color = video::SColor(255, 255, 255, 255); - std::optional nametag_bgcolor = std::nullopt; f32 automatic_face_movement_max_rotation_per_sec = -1.0f; - std::string infotext; - //! For dropped items, this contains item information. - std::string wield_item; - bool static_save = true; float eye_height = 1.625f; float zoom_fov = 0.0f; + u16 hp_max = 1; + u16 breath_max = 0; + s8 glow = 0; + PointabilityType pointable = PointabilityType::POINTABLE; + // In a future protocol these could be a flag field. + bool physical = false; + bool collideWithObjects = true; + bool rotate_selectionbox = false; + bool is_visible = true; + bool makes_footstep_sound = false; + bool automatic_face_movement_dir = false; + bool backface_culling = true; + bool static_save = true; bool use_texture_alpha = false; bool shaded = true; bool show_on_minimap = false; ObjectProperties(); - std::string dump(); - // check limits of some important properties (strings) that'd cause exceptions later on + + std::string dump() const; + + /** + * Check limits of some important properties that'd cause exceptions later on. + * Errornous values are discarded after printing a warning. + * @return true if a problem was found + */ bool validate(); + void serialize(std::ostream &os) const; void deSerialize(std::istream &is); }; From c524c52baa5456cff87127b3c4c41b5758b91c7a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 29 Feb 2024 14:56:13 +0100 Subject: [PATCH 24/91] Fix some common SAO methods to not generate useless update packets --- src/inventory.cpp | 6 +- src/object_properties.h | 24 ++++++++ src/player.h | 36 ++++++++++- src/script/common/c_content.cpp | 17 +++--- src/script/common/c_content.h | 2 +- src/script/lua_api/l_object.cpp | 104 +++++++++++++++----------------- src/server.cpp | 17 +++++- src/server.h | 4 +- src/server/luaentity_sao.cpp | 22 ++++--- src/server/luaentity_sao.h | 4 +- src/server/unit_sao.cpp | 9 ++- 11 files changed, 160 insertions(+), 85 deletions(-) diff --git a/src/inventory.cpp b/src/inventory.cpp index a0f0ea9a2..2440c7f0c 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -601,8 +601,10 @@ ItemStack InventoryList::changeItem(u32 i, const ItemStack &newitem) return newitem; ItemStack olditem = m_items[i]; - m_items[i] = newitem; - setModified(); + if (olditem != newitem) { + m_items[i] = newitem; + setModified(); + } return olditem; } diff --git a/src/object_properties.h b/src/object_properties.h index 9d548343c..1f8384c77 100644 --- a/src/object_properties.h +++ b/src/object_properties.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include +#include #include #include "irrlichttypes_bloated.h" #include @@ -76,6 +77,29 @@ struct ObjectProperties std::string dump() const; +private: + auto tie() const { + // Make sure to add new members to this list! + return std::tie( + textures, colors, collisionbox, selectionbox, visual, mesh, damage_texture_modifier, + nametag, infotext, wield_item, visual_size, nametag_color, nametag_bgcolor, + spritediv, initial_sprite_basepos, stepheight, automatic_rotate, + automatic_face_movement_dir_offset, automatic_face_movement_max_rotation_per_sec, + eye_height, zoom_fov, hp_max, breath_max, glow, pointable, physical, + collideWithObjects, rotate_selectionbox, is_visible, makes_footstep_sound, + automatic_face_movement_dir, backface_culling, static_save, use_texture_alpha, + shaded, show_on_minimap + ); + } + +public: + bool operator==(const ObjectProperties &other) const { + return tie() == other.tie(); + }; + bool operator!=(const ObjectProperties &other) const { + return tie() != other.tie(); + }; + /** * Check limits of some important properties that'd cause exceptions later on. * Errornous values are discarded after printing a warning. diff --git a/src/player.h b/src/player.h index 25109c3f9..77d94cea9 100644 --- a/src/player.h +++ b/src/player.h @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include #define PLAYERNAME_SIZE 20 @@ -42,7 +43,17 @@ struct PlayerFovSpec // The time to be take to trasition to the new FOV value. // Transition is instantaneous if omitted. Omitted by default. - f32 transition_time; + f32 transition_time = 0; + + inline bool operator==(const PlayerFovSpec &other) const { + // transition_time is compared here since that could be relevant + // when aborting a running transition. + return fov == other.fov && is_multiplier == other.is_multiplier && + transition_time == other.transition_time; + } + inline bool operator!=(const PlayerFovSpec &other) const { + return !(*this == other); + } }; struct PlayerControl @@ -115,6 +126,24 @@ struct PlayerPhysicsOverride float liquid_sink = 1.f; float acceleration_default = 1.f; float acceleration_air = 1.f; + +private: + auto tie() const { + // Make sure to add new members to this list! + return std::tie( + speed, jump, gravity, sneak, sneak_glitch, new_move, speed_climb, speed_crouch, + liquid_fluidity, liquid_fluidity_smooth, liquid_sink, acceleration_default, + acceleration_air + ); + } + +public: + bool operator==(const PlayerPhysicsOverride &other) const { + return tie() == other.tie(); + }; + bool operator!=(const PlayerPhysicsOverride &other) const { + return tie() != other.tie(); + }; }; struct PlayerSettings @@ -215,9 +244,12 @@ public: void setWieldIndex(u16 index); u16 getWieldIndex() const { return m_wield_index; } - void setFov(const PlayerFovSpec &spec) + bool setFov(const PlayerFovSpec &spec) { + if (m_fov_override_spec == spec) + return false; m_fov_override_spec = spec; + return true; } const PlayerFovSpec &getFov() const diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 3bda40ebb..d9f179112 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -412,9 +412,12 @@ void read_object_properties(lua_State *L, int index, prop->automatic_face_movement_dir_offset = luaL_checknumber(L, -1); } else if (lua_isboolean(L, -1)) { prop->automatic_face_movement_dir = lua_toboolean(L, -1); - prop->automatic_face_movement_dir_offset = 0.0; + prop->automatic_face_movement_dir_offset = 0; } lua_pop(L, 1); + getfloatfield(L, -1, "automatic_face_movement_max_rotation_per_sec", + prop->automatic_face_movement_max_rotation_per_sec); + getboolfield(L, -1, "backface_culling", prop->backface_culling); getintfield(L, -1, "glow", prop->glow); @@ -438,12 +441,6 @@ void read_object_properties(lua_State *L, int index, } lua_pop(L, 1); - lua_getfield(L, -1, "automatic_face_movement_max_rotation_per_sec"); - if (lua_isnumber(L, -1)) { - prop->automatic_face_movement_max_rotation_per_sec = luaL_checknumber(L, -1); - } - lua_pop(L, 1); - getstringfield(L, -1, "infotext", prop->infotext); getboolfield(L, -1, "static_save", prop->static_save); @@ -464,7 +461,7 @@ void read_object_properties(lua_State *L, int index, } /******************************************************************************/ -void push_object_properties(lua_State *L, ObjectProperties *prop) +void push_object_properties(lua_State *L, const ObjectProperties *prop) { lua_newtable(L); lua_pushnumber(L, prop->hp_max); @@ -525,6 +522,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop) else lua_pushboolean(L, false); lua_setfield(L, -2, "automatic_face_movement_dir"); + lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec); + lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec"); lua_pushboolean(L, prop->backface_culling); lua_setfield(L, -2, "backface_culling"); lua_pushnumber(L, prop->glow); @@ -540,8 +539,6 @@ void push_object_properties(lua_State *L, ObjectProperties *prop) lua_pushboolean(L, false); lua_setfield(L, -2, "nametag_bgcolor"); } - lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec); - lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec"); lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size()); lua_setfield(L, -2, "infotext"); lua_pushboolean(L, prop->static_save); diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 07f77f8c7..c8481d98d 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -130,7 +130,7 @@ void read_object_properties (lua_State *L, int index, IItemDefManager *idef); void push_object_properties (lua_State *L, - ObjectProperties *prop); + const ObjectProperties *prop); void push_inventory_list (lua_State *L, const InventoryList &invlist); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index c291e605a..ad4b7af41 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -804,13 +804,16 @@ int ObjectRef::l_set_properties(lua_State *L) if (sao == nullptr) return 0; - ObjectProperties *prop = sao->accessObjectProperties(); + auto *prop = sao->accessObjectProperties(); if (prop == nullptr) return 0; + const auto old = *prop; read_object_properties(L, 2, sao, prop, getServer(L)->idef()); - prop->validate(); - sao->notifyObjectPropertiesModified(); + if (*prop != old) { + prop->validate(); + sao->notifyObjectPropertiesModified(); + } return 0; } @@ -1124,7 +1127,7 @@ int ObjectRef::l_get_entity_name(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkObject(L, 1); LuaEntitySAO *entitysao = getluaobject(ref); - log_deprecated(L,"Deprecated call to \"get_entity_name"); + log_deprecated(L, "Deprecated call to \"get_entity_name\""); if (entitysao == nullptr) return 0; @@ -1323,13 +1326,14 @@ int ObjectRef::l_set_fov(lua_State *L) if (player == nullptr) return 0; - float degrees = static_cast(luaL_checknumber(L, 2)); - bool is_multiplier = readParam(L, 3, false); - float transition_time = lua_isnumber(L, 4) ? - static_cast(luaL_checknumber(L, 4)) : 0.0f; + PlayerFovSpec s; + s.fov = readParam(L, 2); + s.is_multiplier = readParam(L, 3, false); + if (lua_isnumber(L, 4)) + s.transition_time = readParam(L, 4); - player->setFov({degrees, is_multiplier, transition_time}); - getServer(L)->SendPlayerFov(player->getPeerId()); + if (player->setFov(s)) + getServer(L)->SendPlayerFov(player->getPeerId()); return 0; } @@ -1342,7 +1346,7 @@ int ObjectRef::l_get_fov(lua_State *L) if (player == nullptr) return 0; - PlayerFovSpec fov_spec = player->getFov(); + const auto &fov_spec = player->getFov(); lua_pushnumber(L, fov_spec.fov); lua_pushboolean(L, fov_spec.is_multiplier); @@ -1446,10 +1450,12 @@ int ObjectRef::l_set_inventory_formspec(lua_State *L) if (player == nullptr) return 0; - std::string formspec = luaL_checkstring(L, 2); + auto formspec = readParam(L, 2); - player->inventory_formspec = formspec; - getServer(L)->reportInventoryFormspecModified(player->getName()); + if (formspec != player->inventory_formspec) { + player->inventory_formspec = formspec; + getServer(L)->reportInventoryFormspecModified(player->getName()); + } return 0; } @@ -1462,7 +1468,7 @@ int ObjectRef::l_get_inventory_formspec(lua_State *L) if (player == nullptr) return 0; - std::string formspec = player->inventory_formspec; + auto &formspec = player->inventory_formspec; lua_pushlstring(L, formspec.c_str(), formspec.size()); return 1; @@ -1477,10 +1483,12 @@ int ObjectRef::l_set_formspec_prepend(lua_State *L) if (player == nullptr) return 0; - std::string formspec = luaL_checkstring(L, 2); + auto formspec = readParam(L, 2); - player->formspec_prepend = formspec; - getServer(L)->reportFormspecPrependModified(player->getName()); + if (player->formspec_prepend != formspec) { + player->formspec_prepend = formspec; + getServer(L)->reportFormspecPrependModified(player->getName()); + } return 0; } @@ -1493,7 +1501,7 @@ int ObjectRef::l_get_formspec_prepend(lua_State *L) if (player == nullptr) return 0; - std::string formspec = player->formspec_prepend; + auto &formspec = player->formspec_prepend; lua_pushlstring(L, formspec.c_str(), formspec.size()); return 1; @@ -1506,7 +1514,7 @@ int ObjectRef::l_get_player_control(lua_State *L) ObjectRef *ref = checkObject(L, 1); RemotePlayer *player = getplayer(ref); - lua_newtable(L); + lua_createtable(L, 0, 12); if (player == nullptr) return 1; @@ -1580,41 +1588,26 @@ int ObjectRef::l_set_physics_override(lua_State *L) RemotePlayer *player = playersao->getPlayer(); auto &phys = player->physics_override; - if (lua_istable(L, 2)) { - bool modified = false; - modified |= getfloatfield(L, 2, "speed", phys.speed); - modified |= getfloatfield(L, 2, "jump", phys.jump); - modified |= getfloatfield(L, 2, "gravity", phys.gravity); - modified |= getboolfield(L, 2, "sneak", phys.sneak); - modified |= getboolfield(L, 2, "sneak_glitch", phys.sneak_glitch); - modified |= getboolfield(L, 2, "new_move", phys.new_move); - modified |= getfloatfield(L, 2, "speed_climb", phys.speed_climb); - modified |= getfloatfield(L, 2, "speed_crouch", phys.speed_crouch); - modified |= getfloatfield(L, 2, "liquid_fluidity", phys.liquid_fluidity); - modified |= getfloatfield(L, 2, "liquid_fluidity_smooth", phys.liquid_fluidity_smooth); - modified |= getfloatfield(L, 2, "liquid_sink", phys.liquid_sink); - modified |= getfloatfield(L, 2, "acceleration_default", phys.acceleration_default); - modified |= getfloatfield(L, 2, "acceleration_air", phys.acceleration_air); - if (modified) - playersao->m_physics_override_sent = false; - } else { - // old, non-table format - // TODO: Remove this code after version 5.4.0 - log_deprecated(L, "Deprecated use of set_physics_override(num, num, num)"); + const PlayerPhysicsOverride old = phys; - if (!lua_isnil(L, 2)) { - phys.speed = lua_tonumber(L, 2); - playersao->m_physics_override_sent = false; - } - if (!lua_isnil(L, 3)) { - phys.jump = lua_tonumber(L, 3); - playersao->m_physics_override_sent = false; - } - if (!lua_isnil(L, 4)) { - phys.gravity = lua_tonumber(L, 4); - playersao->m_physics_override_sent = false; - } - } + luaL_checktype(L, 2, LUA_TTABLE); + + getfloatfield(L, 2, "speed", phys.speed); + getfloatfield(L, 2, "jump", phys.jump); + getfloatfield(L, 2, "gravity", phys.gravity); + getboolfield(L, 2, "sneak", phys.sneak); + getboolfield(L, 2, "sneak_glitch", phys.sneak_glitch); + getboolfield(L, 2, "new_move", phys.new_move); + getfloatfield(L, 2, "speed_climb", phys.speed_climb); + getfloatfield(L, 2, "speed_crouch", phys.speed_crouch); + getfloatfield(L, 2, "liquid_fluidity", phys.liquid_fluidity); + getfloatfield(L, 2, "liquid_fluidity_smooth", phys.liquid_fluidity_smooth); + getfloatfield(L, 2, "liquid_sink", phys.liquid_sink); + getfloatfield(L, 2, "acceleration_default", phys.acceleration_default); + getfloatfield(L, 2, "acceleration_air", phys.acceleration_air); + + if (phys != old) + playersao->m_physics_override_sent = false; return 0; } @@ -1717,6 +1710,7 @@ int ObjectRef::l_hud_change(lua_State *L) void *value = nullptr; bool ok = read_hud_change(L, stat, elem, &value); + // FIXME: only send when actually changed if (ok) getServer(L)->hudChange(player, id, stat, value); @@ -1836,7 +1830,7 @@ int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L) if (player == nullptr) return 0; - lua_pushnumber(L, player->getHotbarItemcount()); + lua_pushinteger(L, player->getHotbarItemcount()); return 1; } diff --git a/src/server.cpp b/src/server.cpp index 9441f5050..5e828e00c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1789,7 +1789,7 @@ void Server::SendHUDSetFlags(session_t peer_id, u32 flags, u32 mask) Send(&pkt); } -void Server::SendHUDSetParam(session_t peer_id, u16 param, const std::string &value) +void Server::SendHUDSetParam(session_t peer_id, u16 param, std::string_view value) { NetworkPacket pkt(TOCLIENT_HUD_SET_PARAM, 0, peer_id); pkt << param << value; @@ -3433,6 +3433,9 @@ bool Server::hudSetHotbarItemcount(RemotePlayer *player, s32 hotbar_itemcount) if (hotbar_itemcount <= 0 || hotbar_itemcount > HUD_HOTBAR_ITEMCOUNT_MAX) return false; + if (player->getHotbarItemcount() == hotbar_itemcount) + return true; + player->setHotbarItemcount(hotbar_itemcount); std::ostringstream os(std::ios::binary); writeS32(os, hotbar_itemcount); @@ -3445,6 +3448,9 @@ void Server::hudSetHotbarImage(RemotePlayer *player, const std::string &name) if (!player) return; + if (player->getHotbarImage() == name) + return; + player->setHotbarImage(name); SendHUDSetParam(player->getPeerId(), HUD_PARAM_HOTBAR_IMAGE, name); } @@ -3454,6 +3460,9 @@ void Server::hudSetHotbarSelectedImage(RemotePlayer *player, const std::string & if (!player) return; + if (player->getHotbarSelectedImage() == name) + return; + player->setHotbarSelectedImage(name); SendHUDSetParam(player->getPeerId(), HUD_PARAM_HOTBAR_SELECTED_IMAGE, name); } @@ -3472,9 +3481,13 @@ void Server::setLocalPlayerAnimations(RemotePlayer *player, SendLocalPlayerAnimations(player->getPeerId(), animation_frames, frame_speed); } -void Server::setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third, const v3f &third_front) +void Server::setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third, v3f third_front) { sanity_check(player); + if (std::tie(player->eye_offset_first, player->eye_offset_third, + player->eye_offset_third_front) == std::tie(first, third, third_front)) + return; // no change + player->eye_offset_first = first; player->eye_offset_third = third; player->eye_offset_third_front = third_front; diff --git a/src/server.h b/src/server.h index d262ca3c2..1c0905935 100644 --- a/src/server.h +++ b/src/server.h @@ -343,7 +343,7 @@ public: void setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4], f32 frame_speed); - void setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third, const v3f &third_front); + void setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third, v3f third_front); void setSky(RemotePlayer *player, const SkyboxParams ¶ms); void setSun(RemotePlayer *player, const SunParams ¶ms); @@ -496,7 +496,7 @@ private: void SendHUDRemove(session_t peer_id, u32 id); void SendHUDChange(session_t peer_id, u32 id, HudElementStat stat, void *value); void SendHUDSetFlags(session_t peer_id, u32 flags, u32 mask); - void SendHUDSetParam(session_t peer_id, u16 param, const std::string &value); + void SendHUDSetParam(session_t peer_id, u16 param, std::string_view value); void SendSetSky(session_t peer_id, const SkyboxParams ¶ms); void SendSetSun(session_t peer_id, const SunParams ¶ms); void SendSetMoon(session_t peer_id, const MoonParams ¶ms); diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index ae5c97bfd..9917eb53a 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -134,12 +134,16 @@ void LuaEntitySAO::dispatchScriptDeactivate(bool removal) void LuaEntitySAO::step(float dtime, bool send_recommended) { - if(!m_properties_sent) - { + if (!m_properties_sent) { m_properties_sent = true; std::string str = getPropertyPacket(); // create message and add to list - m_messages_out.emplace(getId(), true, str); + m_messages_out.emplace(getId(), true, std::move(str)); + } + + if (!m_texture_modifier_sent) { + m_texture_modifier_sent = true; + m_messages_out.emplace(getId(), true, generateSetTextureModCommand()); } // If attached, check that our parent is still there. If it isn't, detach. @@ -444,24 +448,24 @@ v3f LuaEntitySAO::getAcceleration() void LuaEntitySAO::setTextureMod(const std::string &mod) { - m_current_texture_modifier = mod; - // create message and add to list - m_messages_out.emplace(getId(), true, generateSetTextureModCommand()); + if (m_texture_modifier == mod) + return; + m_texture_modifier = mod; + m_texture_modifier_sent = false; } std::string LuaEntitySAO::getTextureMod() const { - return m_current_texture_modifier; + return m_texture_modifier; } - std::string LuaEntitySAO::generateSetTextureModCommand() const { std::ostringstream os(std::ios::binary); // command writeU8(os, AO_CMD_SET_TEXTURE_MOD); // parameters - os << serializeString16(m_current_texture_modifier); + os << serializeString16(m_texture_modifier); return os.str(); } diff --git a/src/server/luaentity_sao.h b/src/server/luaentity_sao.h index 1dc72b150..2080df9c3 100644 --- a/src/server/luaentity_sao.h +++ b/src/server/luaentity_sao.h @@ -103,5 +103,7 @@ private: v3f m_last_sent_rotation; float m_last_sent_position_timer = 0.0f; float m_last_sent_move_precision = 0.0f; - std::string m_current_texture_modifier = ""; + + std::string m_texture_modifier; + bool m_texture_modifier_sent = false; }; diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp index fd44ae323..70594589b 100644 --- a/src/server/unit_sao.cpp +++ b/src/server/unit_sao.cpp @@ -41,6 +41,8 @@ ServerActiveObject *UnitSAO::getParent() const void UnitSAO::setArmorGroups(const ItemGroupList &armor_groups) { + if (m_armor_groups == armor_groups) + return; m_armor_groups = armor_groups; m_armor_groups_sent = false; } @@ -53,7 +55,10 @@ const ItemGroupList &UnitSAO::getArmorGroups() const void UnitSAO::setAnimation( v2f frame_range, float frame_speed, float frame_blend, bool frame_loop) { - // store these so they can be updated to clients + if (std::tie(m_animation_range, m_animation_speed, m_animation_blend, + m_animation_loop) == + std::tie(frame_range, frame_speed, frame_blend, frame_loop)) + return; // no change m_animation_range = frame_range; m_animation_speed = frame_speed; m_animation_blend = frame_blend; @@ -72,6 +77,8 @@ void UnitSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_bl void UnitSAO::setAnimationSpeed(float frame_speed) { + if (m_animation_speed == frame_speed) + return; m_animation_speed = frame_speed; m_animation_speed_sent = false; } From badd42789af375193a187e5c72552649b56f28a1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 29 Feb 2024 15:13:52 +0100 Subject: [PATCH 25/91] Move PlayerSettings class to client code --- src/client/localplayer.cpp | 50 ++++++++++++++++++++++++++++++++++++++ src/client/localplayer.h | 30 ++++++++++++++++++++--- src/player.cpp | 27 -------------------- src/player.h | 35 ++++++-------------------- 4 files changed, 83 insertions(+), 59 deletions(-) diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 1470d819a..e606e1edc 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -28,6 +28,49 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include "content_cao.h" +/* + PlayerSettings +*/ + +const static std::string PlayerSettings_names[] = { + "free_move", "pitch_move", "fast_move", "continuous_forward", "always_fly_fast", + "aux1_descends", "noclip", "autojump" +}; + +void PlayerSettings::readGlobalSettings() +{ + free_move = g_settings->getBool("free_move"); + pitch_move = g_settings->getBool("pitch_move"); + fast_move = g_settings->getBool("fast_move"); + continuous_forward = g_settings->getBool("continuous_forward"); + always_fly_fast = g_settings->getBool("always_fly_fast"); + aux1_descends = g_settings->getBool("aux1_descends"); + noclip = g_settings->getBool("noclip"); + autojump = g_settings->getBool("autojump"); +} + + +void PlayerSettings::registerSettingsCallback() +{ + for (auto &name : PlayerSettings_names) { + g_settings->registerChangedCallback(name, + &PlayerSettings::settingsChangedCallback, this); + } +} + +void PlayerSettings::deregisterSettingsCallback() +{ + for (auto &name : PlayerSettings_names) { + g_settings->deregisterChangedCallback(name, + &PlayerSettings::settingsChangedCallback, this); + } +} + +void PlayerSettings::settingsChangedCallback(const std::string &name, void *data) +{ + ((PlayerSettings *)data)->readGlobalSettings(); +} + /* LocalPlayer */ @@ -36,6 +79,13 @@ LocalPlayer::LocalPlayer(Client *client, const char *name): Player(name, client->idef()), m_client(client) { + m_player_settings.readGlobalSettings(); + m_player_settings.registerSettingsCallback(); +} + +LocalPlayer::~LocalPlayer() +{ + m_player_settings.deregisterSettingsCallback(); } static aabb3f getNodeBoundingBox(const std::vector &nodeboxes) diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 1133a3f56..fbccb1591 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "constants.h" #include "settings.h" #include "lighting.h" -#include class Client; class Environment; @@ -39,14 +38,33 @@ enum class LocalPlayerAnimation NO_ANIM, WALK_ANIM, DIG_ANIM, - WD_ANIM -}; // no local animation, walking, digging, both + WD_ANIM // walking + digging +}; + +struct PlayerSettings +{ + bool free_move = false; + bool pitch_move = false; + bool fast_move = false; + bool continuous_forward = false; + bool always_fly_fast = false; + bool aux1_descends = false; + bool noclip = false; + bool autojump = false; + + void readGlobalSettings(); + void registerSettingsCallback(); + void deregisterSettingsCallback(); + +private: + static void settingsChangedCallback(const std::string &name, void *data); +}; class LocalPlayer : public Player { public: LocalPlayer(Client *client, const char *name); - virtual ~LocalPlayer() = default; + virtual ~LocalPlayer(); // Initialize hp to 0, so that no hearts will be shown if server // doesn't support health points @@ -161,6 +179,8 @@ public: inline Lighting& getLighting() { return m_lighting; } + inline PlayerSettings &getPlayerSettings() { return m_player_settings; } + private: void accelerate(const v3f &target_speed, const f32 max_increase_H, const f32 max_increase_V, const bool use_pitch); @@ -211,5 +231,7 @@ private: GenericCAO *m_cao = nullptr; Client *m_client; + + PlayerSettings m_player_settings; Lighting m_lighting; }; diff --git a/src/player.cpp b/src/player.cpp index 14750b950..c876b6948 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -75,20 +75,10 @@ Player::Player(const char *name, IItemDefManager *idef): HUD_FLAG_CHAT_VISIBLE; hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT; - - m_player_settings.readGlobalSettings(); - // Register player setting callbacks - for (const std::string &name : m_player_settings.setting_names) - g_settings->registerChangedCallback(name, - &Player::settingsChangedCallback, &m_player_settings); } Player::~Player() { - // m_player_settings becomes invalid, remove callbacks - for (const std::string &name : m_player_settings.setting_names) - g_settings->deregisterChangedCallback(name, - &Player::settingsChangedCallback, &m_player_settings); clearHud(); } @@ -224,20 +214,3 @@ void PlayerControl::unpackKeysPressed(u32 keypress_bits) place = keypress_bits & (1 << 8); zoom = keypress_bits & (1 << 9); } - -void PlayerSettings::readGlobalSettings() -{ - free_move = g_settings->getBool("free_move"); - pitch_move = g_settings->getBool("pitch_move"); - fast_move = g_settings->getBool("fast_move"); - continuous_forward = g_settings->getBool("continuous_forward"); - always_fly_fast = g_settings->getBool("always_fly_fast"); - aux1_descends = g_settings->getBool("aux1_descends"); - noclip = g_settings->getBool("noclip"); - autojump = g_settings->getBool("autojump"); -} - -void Player::settingsChangedCallback(const std::string &name, void *data) -{ - ((PlayerSettings *)data)->readGlobalSettings(); -} diff --git a/src/player.h b/src/player.h index 77d94cea9..a79a13228 100644 --- a/src/player.h +++ b/src/player.h @@ -146,24 +146,6 @@ public: }; }; -struct PlayerSettings -{ - bool free_move = false; - bool pitch_move = false; - bool fast_move = false; - bool continuous_forward = false; - bool always_fly_fast = false; - bool aux1_descends = false; - bool noclip = false; - bool autojump = false; - - const std::string setting_names[8] = { - "free_move", "pitch_move", "fast_move", "continuous_forward", "always_fly_fast", - "aux1_descends", "noclip", "autojump" - }; - void readGlobalSettings(); -}; - class Map; struct CollisionInfo; struct HudElement; @@ -185,17 +167,14 @@ public: {} // in BS-space - v3f getSpeed() const - { - return m_speed; - } - - // in BS-space - void setSpeed(v3f speed) + inline void setSpeed(v3f speed) { m_speed = speed; } + // in BS-space + v3f getSpeed() const { return m_speed; } + const char *getName() const { return m_name; } u32 getFreeHudID() @@ -235,9 +214,8 @@ public: PlayerControl control; const PlayerControl& getPlayerControl() { return control; } + PlayerPhysicsOverride physics_override; - PlayerSettings &getPlayerSettings() { return m_player_settings; } - static void settingsChangedCallback(const std::string &name, void *data); // Returns non-empty `selected` ItemStack. `hand` is a fallback, if specified ItemStack &getWieldedItem(ItemStack *selected, ItemStack *hand) const; @@ -273,10 +251,11 @@ protected: PlayerFovSpec m_fov_override_spec = { 0.0f, false, 0.0f }; std::vector hud; + private: // Protect some critical areas // hud for example can be modified by EmergeThread // and ServerThread + // FIXME: ^ this sounds like nonsense. should be checked. std::mutex m_mutex; - PlayerSettings m_player_settings; }; From fc80f65a6d958b730af869399b131c84b0b6f72a Mon Sep 17 00:00:00 2001 From: y5nw <37980625+y5nw@users.noreply.github.com> Date: Wed, 6 Mar 2024 18:04:49 +0100 Subject: [PATCH 26/91] Try to preserve metatable when exchanging data with the async env (#14369) Co-authored-by: sfan5 Co-authored-by: Lars Mueller --- builtin/common/metatable.lua | 13 +++++ builtin/game/init.lua | 1 + builtin/init.lua | 1 + doc/lua_api.md | 15 +++++- games/devtest/mods/unittests/async_env.lua | 43 ++++++++++++++++- .../mods/unittests/inside_async_env.lua | 3 ++ src/script/common/c_packer.cpp | 48 ++++++++++++++++++- src/script/common/c_packer.h | 8 ++-- 8 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 builtin/common/metatable.lua diff --git a/builtin/common/metatable.lua b/builtin/common/metatable.lua new file mode 100644 index 000000000..b402dd63a --- /dev/null +++ b/builtin/common/metatable.lua @@ -0,0 +1,13 @@ +-- Registered metatables, used by the C++ packer +local known_metatables = {} +function core.register_async_metatable(name, mt) + assert(type(name) == "string", ("attempt to use %s value as metatable name"):format(type(name))) + assert(type(mt) == "table", ("attempt to register a %s value as metatable"):format(type(mt))) + assert(known_metatables[name] == nil or known_metatables[name] == mt, + ("attempt to override metatable %s"):format(name)) + known_metatables[name] = mt + known_metatables[mt] = name +end +core.known_metatables = known_metatables + +core.register_async_metatable("__builtin:vector", vector.metatable) diff --git a/builtin/game/init.lua b/builtin/game/init.lua index e6a8e800b..f6432a73d 100644 --- a/builtin/game/init.lua +++ b/builtin/game/init.lua @@ -18,6 +18,7 @@ if core.settings:get_bool("profiler.load") then end dofile(commonpath .. "after.lua") +dofile(commonpath .. "metatable.lua") dofile(commonpath .. "mod_storage.lua") dofile(gamepath .. "item_entity.lua") dofile(gamepath .. "deprecated.lua") diff --git a/builtin/init.lua b/builtin/init.lua index b62dbf07a..cf4e8704e 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -63,6 +63,7 @@ elseif INIT == "mainmenu" then elseif INIT == "async" then dofile(asyncpath .. "mainmenu.lua") elseif INIT == "async_game" then + dofile(commonpath .. "metatable.lua") dofile(asyncpath .. "game.lua") elseif INIT == "client" then dofile(scriptdir .. "client" .. DIR_DELIM .. "init.lua") diff --git a/doc/lua_api.md b/doc/lua_api.md index 6f3fccb9f..0b2c703f3 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -6012,7 +6012,7 @@ Environment access * `minetest.add_entity(pos, name, [staticdata])`: Spawn Lua-defined entity at position. * Returns `ObjectRef`, or `nil` if failed - * Entities with `static_save = true` can be added also + * Entities with `static_save = true` can be added also to unloaded and non-generated blocks. * `minetest.add_item(pos, item)`: Spawn item * Returns `ObjectRef`, or `nil` if failed @@ -6598,6 +6598,18 @@ This allows you easy interoperability for delegating work to jobs. * Register a path to a Lua file to be imported when an async environment is initialized. You can use this to preload code which you can then call later using `minetest.handle_async()`. +* `minetest.register_async_metatable(name, mt)`: + * Register a metatable that should be preserved when data is transferred + between the main thread and the async environment. + * `name` is a string that identifies the metatable. It is recommended to + follow the `modname:name` convention for this identifier. + * `mt` is the metatable to register. + * Note that it is allowed to register the same metatable under multiple + names, but it is not allowed to register multiple metatables under the + same name. + * You must register the metatable in both the main environment + and the async environment for this mechanism to work. + ### List of APIs available in an async environment @@ -6623,6 +6635,7 @@ Class instances that can be transferred between environments: Functions: * Standalone helpers such as logging, filesystem, encoding, hashing or compression APIs +* `minetest.register_async_metatable` (see above) Variables: * `minetest.settings` diff --git a/games/devtest/mods/unittests/async_env.lua b/games/devtest/mods/unittests/async_env.lua index b7edf941e..d7a714941 100644 --- a/games/devtest/mods/unittests/async_env.lua +++ b/games/devtest/mods/unittests/async_env.lua @@ -53,7 +53,7 @@ local test_object = { end, sunlight_propagates = true, is_ground_content = false, - light_source = 0, + pos = vector.new(-1, -2, -3), } local function test_object_passing() @@ -166,3 +166,44 @@ local function test_userdata_passing2(cb, _, pos) end, vm, pos) end unittests.register("test_userdata_passing2", test_userdata_passing2, {map=true, async=true}) + +local function test_async_metatable_override() + assert(pcall(core.register_async_metatable, "__builtin:vector", vector.metatable), + "Metatable name aliasing throws an error when it should be allowed") + + assert(not pcall(core.register_async_metatable, "__builtin:vector", {}), + "Illegal metatable overriding allowed") +end +unittests.register("test_async_metatable_override", test_async_metatable_override) + +local function test_async_metatable_registration(cb) + local custom_metatable = {} + core.register_async_metatable("unittests:custom_metatable", custom_metatable) + + core.handle_async(function(x) + -- unittests.custom_metatable is registered in inside_async_env.lua + return getmetatable(x) == unittests.custom_metatable, x + end, function(metatable_preserved_async, table_after_roundtrip) + if not metatable_preserved_async then + return cb("Custom metatable not preserved (main -> async)") + end + if getmetatable(table_after_roundtrip) ~= custom_metatable then + return cb("Custom metable not preserved (after roundtrip)") + end + cb() + end, setmetatable({}, custom_metatable)) +end +unittests.register("test_async_metatable_registration", test_async_metatable_registration, {async=true}) + +local function test_vector_preserve(cb) + local vec = vector.new(1, 2, 3) + core.handle_async(function(x) + return x[1] + end, function(ret) + if ret ~= vec then -- fails if metatable was not preserved + return cb("Vector value mismatch") + end + cb() + end, {vec}) +end +unittests.register("test_async_vector", test_vector_preserve, {async=true}) diff --git a/games/devtest/mods/unittests/inside_async_env.lua b/games/devtest/mods/unittests/inside_async_env.lua index 7228d383d..5f97ec15d 100644 --- a/games/devtest/mods/unittests/inside_async_env.lua +++ b/games/devtest/mods/unittests/inside_async_env.lua @@ -2,6 +2,9 @@ unittests = {} core.log("info", "Hello World") +unittests.custom_metatable = {} +core.register_async_metatable("unittests:custom_metatable", unittests.custom_metatable) + local function do_tests() assert(core == minetest) -- stuff that should not be here diff --git a/src/script/common/c_packer.cpp b/src/script/common/c_packer.cpp index c133e0ee2..579167952 100644 --- a/src/script/common/c_packer.cpp +++ b/src/script/common/c_packer.cpp @@ -99,6 +99,27 @@ static inline bool suitable_key(lua_State *L, int idx) } } +/** + * Push core.known_metatables to the stack if it exists. + * @param L Lua state + * @return true if core.known_metatables exists, false otherwise. +*/ +static inline bool get_known_lua_metatables(lua_State *L) +{ + lua_getglobal(L, "core"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, "known_metatables"); + if (lua_istable(L, -1)) { + lua_remove(L, -2); + return true; + } + lua_pop(L, 2); + return false; +} + namespace { // checks if you left any values on the stack, for debugging class StackChecker { @@ -450,6 +471,18 @@ static VectorRef pack_inner(lua_State *L, int idx, int vidx, Packed lua_pop(L, 1); } + // try to preserve metatable information + if (lua_getmetatable(L, idx) && get_known_lua_metatables(L)) { + lua_insert(L, -2); + lua_gettable(L, -2); + if (lua_isstring(L, -1)) { + auto r = emplace(pv, INSTR_SETMETATABLE); + r->sdata = std::string(lua_tostring(L, -1)); + r->set_into = vi_table; + } + lua_pop(L, 2); + } + // exactly the table should be left on stack assert(vidx == vi_table + 1); return rtable; @@ -514,6 +547,16 @@ void script_unpack(lua_State *L, PackedValue *pv) lua_pushinteger(L, i.sidata1); lua_rawget(L, top); break; + case INSTR_SETMETATABLE: + if (get_known_lua_metatables(L)) { + lua_getfield(L, -1, i.sdata.c_str()); + lua_remove(L, -2); + if (lua_istable(L, -1)) + lua_setmetatable(L, top + i.set_into); + else + lua_pop(L, 1); + } + continue; /* Lua types */ case LUA_TNIL: @@ -614,6 +657,9 @@ void script_dump_packed(const PackedValue *val) case INSTR_PUSHREF: printf("PUSHREF(%d)", i.sidata1); break; + case INSTR_SETMETATABLE: + printf("SETMETATABLE(%s)", i.sdata.c_str()); + break; case LUA_TNIL: printf("nil"); break; @@ -636,7 +682,7 @@ void script_dump_packed(const PackedValue *val) printf("userdata %s %p", i.sdata.c_str(), i.ptrdata); break; default: - printf("!!UNKNOWN!!"); + FATAL_ERROR("unknown type"); break; } if (i.set_into) { diff --git a/src/script/common/c_packer.h b/src/script/common/c_packer.h index 17f25fd17..2338da455 100644 --- a/src/script/common/c_packer.h +++ b/src/script/common/c_packer.h @@ -34,9 +34,10 @@ extern "C" { states and cannot be used for persistence or network transfer. */ -#define INSTR_SETTABLE (-10) -#define INSTR_POP (-11) -#define INSTR_PUSHREF (-12) +#define INSTR_SETTABLE (-10) +#define INSTR_POP (-11) +#define INSTR_PUSHREF (-12) +#define INSTR_SETMETATABLE (-13) /** * Represents a single instruction that pushes a new value or operates with existing ones. @@ -70,6 +71,7 @@ struct PackedInstr - function: buffer - w/ set_into: string key (no null bytes!) - userdata: name in registry + - INSTR_SETMETATABLE: name of the metatable */ std::string sdata; From bf52d1e6242607440bfa35d6e81e5909e0c46977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Wed, 6 Mar 2024 20:36:02 +0100 Subject: [PATCH 27/91] Fix attached sounds stopping if objects are removed serverside (#14436) Restores backwards compatibility for death sounds or other sounds that are not supposed to be "cut off" abruptly. --------- Co-authored-by: sfan5 Co-authored-by: grorp --- doc/lua_api.md | 16 ++++++++++++ src/client/client.cpp | 8 ------ src/client/client.h | 3 --- src/network/clientpackethandler.cpp | 1 - src/server.cpp | 40 +++++++++++++++++++++-------- src/server.h | 3 ++- src/serverenvironment.cpp | 19 +++++++------- src/serverenvironment.h | 10 +++++--- 8 files changed, 63 insertions(+), 37 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 0b2c703f3..f01e3cd35 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -1095,6 +1095,7 @@ Table used to specify how a sound is played: -- its end in `-start_time` seconds. -- It is unspecified what happens if `loop` is false and `start_time` is -- smaller than minus the sound's length. + -- Available since feature `sound_params_start_time`. loop = false, @@ -1108,6 +1109,21 @@ Table used to specify how a sound is played: -- Attach the sound to an object. -- Can't be used together with `pos`. + -- For backward compatibility, sounds continue playing at the last location + -- of the object if an object is removed (for example if an entity dies). + -- It is not recommended to rely on this. + -- For death sounds, prefer playing a positional sound instead. + + -- If you want to stop a sound when an entity dies or is deactivated, + -- store the handle and call `minetest.sound_stop` in `on_die` / `on_deactivate`. + + -- Ephemeral sounds are entirely unaffected by the object being removed + -- or leaving the active object range. + + -- Non-ephemeral sounds stop playing on clients if objects leave + -- the active object range; they should start playing again if objects + --- come back into range (but due to a known bug, they don't yet). + to_player = name, -- Only play for this player. -- Can't be used together with `exclude_player`. diff --git a/src/client/client.cpp b/src/client/client.cpp index 914b9ce35..d6781a965 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -2123,11 +2123,3 @@ const std::string &Client::getFormspecPrepend() const { return m_env.getLocalPlayer()->formspec_prepend; } - -void Client::removeActiveObjectSounds(u16 id) -{ - for (auto it : m_sounds_to_objects) { - if (it.second == id) - m_sound->stopSound(it.first); - } -} diff --git a/src/client/client.h b/src/client/client.h index ae003c011..9f898e78a 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -471,9 +471,6 @@ private: bool canSendChatMessage() const; - // remove sounds attached to object - void removeActiveObjectSounds(u16 id); - float m_packetcounter_timer = 0.0f; float m_connection_reinit_timer = 0.1f; float m_avg_rtt_timer = 0.0f; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index f62730d43..10ecdd34c 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -471,7 +471,6 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt) for (u16 i = 0; i < removed_count; i++) { *pkt >> id; m_env.removeActiveObject(id); - removeActiveObjectSounds(id); } // Read added objects diff --git a/src/server.cpp b/src/server.cpp index 5e828e00c..eebd3ba56 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2041,7 +2041,8 @@ void Server::SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersa if (my_radius <= 0) my_radius = radius; - std::queue removed_objects, added_objects; + std::queue> removed_objects; + std::queue added_objects; m_env->getRemovedActiveObjects(playersao, my_radius, player_radius, client->m_known_objects, removed_objects); m_env->getAddedActiveObjects(playersao, my_radius, player_radius, @@ -2057,13 +2058,21 @@ void Server::SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersa std::string data; // Handle removed objects + writeU16((u8*)buf, removed_objects.size()); data.append(buf, 2); while (!removed_objects.empty()) { // Get object - u16 id = removed_objects.front(); + const auto [gone, id] = removed_objects.front(); ServerActiveObject* obj = m_env->getActiveObject(id); + // Stop sounds if objects go out of range. + // This fixes https://github.com/minetest/minetest/issues/8094. + // We may not remove sounds if an entity was removed on the server. + // See https://github.com/minetest/minetest/issues/14422. + if (!gone) // just out of range for client, not gone on server? + stopAttachedSounds(client->peer_id, id); + // Add to data buffer for sending writeU16((u8*)buf, id); data.append(buf, 2); @@ -2278,19 +2287,30 @@ void Server::fadeSound(s32 handle, float step, float gain) m_playing_sounds.erase(it); } -void Server::stopAttachedSounds(u16 id) +void Server::stopAttachedSounds(session_t peer_id, u16 object_id) { - assert(id); + assert(peer_id != PEER_ID_INEXISTENT); + assert(object_id); - for (auto it = m_playing_sounds.begin(); it != m_playing_sounds.end(); ) { - const ServerPlayingSound &sound = it->second; + for (auto it = m_playing_sounds.begin(); it != m_playing_sounds.end();) { + ServerPlayingSound &sound = it->second; - if (sound.object == id) { - // Remove sound reference + if (sound.object != object_id) + continue; + + auto clients_it = sound.clients.find(peer_id); + if (clients_it == sound.clients.end()) + continue; + + NetworkPacket pkt(TOCLIENT_STOP_SOUND, 4); + pkt << it->first; + Send(peer_id, &pkt); + + sound.clients.erase(clients_it); + if (sound.clients.empty()) it = m_playing_sounds.erase(it); - } else - it++; + ++it; } } diff --git a/src/server.h b/src/server.h index 1c0905935..9f9f08ac7 100644 --- a/src/server.h +++ b/src/server.h @@ -239,7 +239,8 @@ public: s32 playSound(ServerPlayingSound ¶ms, bool ephemeral=false); void stopSound(s32 handle); void fadeSound(s32 handle, float step, float gain); - void stopAttachedSounds(u16 id); + // Stop all sounds attached to an object for a certain client + void stopAttachedSounds(session_t peer_id, u16 object_id); // Envlock std::set getPlayerEffectivePrivs(const std::string &name); diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index f3fe2c731..6d394309c 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include +#include #include "serverenvironment.h" #include "settings.h" #include "log.h" @@ -1253,7 +1254,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) return false; } - processActiveObjectRemove(obj, id); + processActiveObjectRemove(obj); // Delete active object return true; @@ -1742,7 +1743,7 @@ void ServerEnvironment::getAddedActiveObjects(PlayerSAO *playersao, s16 radius, void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius, s16 player_radius, std::set ¤t_objects, - std::queue &removed_objects) + std::queue> &removed_objects) { f32 radius_f = radius * BS; f32 player_radius_f = player_radius * BS; @@ -1763,12 +1764,12 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius if (object == NULL) { infostream << "ServerEnvironment::getRemovedActiveObjects():" << " object in current_objects is NULL" << std::endl; - removed_objects.push(id); + removed_objects.emplace(true, id); continue; } if (object->isGone()) { - removed_objects.push(id); + removed_objects.emplace(true, id); continue; } @@ -1780,7 +1781,7 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius continue; // Object is no longer visible - removed_objects.push(id); + removed_objects.emplace(false, id); } } @@ -1973,7 +1974,7 @@ void ServerEnvironment::removeRemovedObjects() } } - processActiveObjectRemove(obj, id); + processActiveObjectRemove(obj); // Delete return true; @@ -2210,7 +2211,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete) return false; } - processActiveObjectRemove(obj, id); + processActiveObjectRemove(obj); // Delete active object return true; @@ -2273,14 +2274,12 @@ bool ServerEnvironment::saveStaticToBlock( return true; } -void ServerEnvironment::processActiveObjectRemove(ServerActiveObject *obj, u16 id) +void ServerEnvironment::processActiveObjectRemove(ServerActiveObject *obj) { // Tell the object about removal obj->removingFromEnvironment(); // Deregister in scripting api m_script->removeObjectReference(obj); - // stop attached sounds - m_server->stopAttachedSounds(id); } PlayerDatabase *ServerEnvironment::openPlayerDatabase(const std::string &name, diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 01f232c8c..4a4872a8b 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -19,6 +19,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include +#include +#include + #include "activeobject.h" #include "environment.h" #include "map.h" @@ -26,8 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server/activeobjectmgr.h" #include "util/numeric.h" #include "util/metricsbackend.h" -#include -#include class IGameDef; struct GameParams; @@ -303,7 +305,7 @@ public: void getRemovedActiveObjects(PlayerSAO *playersao, s16 radius, s16 player_radius, std::set ¤t_objects, - std::queue &removed_objects); + std::queue> &removed_objects); /* Get the next message emitted by some active object. @@ -454,7 +456,7 @@ private: bool saveStaticToBlock(v3s16 blockpos, u16 store_id, ServerActiveObject *obj, const StaticObject &s_obj, u32 mod_reason); - void processActiveObjectRemove(ServerActiveObject *obj, u16 id); + void processActiveObjectRemove(ServerActiveObject *obj); /* Member variables From d88f0866b74e7a010e93233c067871c462edca78 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 4 Mar 2024 23:59:29 +0100 Subject: [PATCH 28/91] Reduce translations log spam --- src/translation.cpp | 23 +++++++---------------- src/translation.h | 4 ++-- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/translation.cpp b/src/translation.cpp index 336e3dd6b..5d5491e56 100644 --- a/src/translation.cpp +++ b/src/translation.cpp @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef SERVER // Client translations -Translations client_translations; +static Translations client_translations; Translations *g_client_translations = &client_translations; #endif @@ -36,19 +36,13 @@ void Translations::clear() } const std::wstring &Translations::getTranslation( - const std::wstring &textdomain, const std::wstring &s) + const std::wstring &textdomain, const std::wstring &s) const { std::wstring key = textdomain + L"|" + s; - try { - return m_translations.at(key); - } catch (const std::out_of_range &) { - verbosestream << "Translations: can't find translation for string \"" - << wide_to_utf8(s) << "\" in textdomain \"" - << wide_to_utf8(textdomain) << "\"" << std::endl; - // Silence that warning in the future - m_translations[key] = s; - return s; - } + auto it = m_translations.find(key); + if (it != m_translations.end()) + return it->second; + return s; } void Translations::loadTranslation(const std::string &data) @@ -155,10 +149,7 @@ void Translations::loadTranslation(const std::string &data) if (!oword2.empty()) { std::wstring translation_index = textdomain + L"|"; translation_index.append(oword1); - m_translations[translation_index] = oword2; - } else { - infostream << "Ignoring empty translation for \"" - << wide_to_utf8(oword1) << "\"" << std::endl; + m_translations.emplace(std::move(translation_index), std::move(oword2)); } } } diff --git a/src/translation.h b/src/translation.h index e3f5b21ea..d7ed15505 100644 --- a/src/translation.h +++ b/src/translation.h @@ -32,8 +32,8 @@ class Translations public: void loadTranslation(const std::string &data); void clear(); - const std::wstring &getTranslation( - const std::wstring &textdomain, const std::wstring &s); + const std::wstring &getTranslation(const std::wstring &textdomain, + const std::wstring &s) const; private: std::unordered_map m_translations; From 58bf4f04b1c76122415ff020dce5a3b53f13a3d8 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 18 Feb 2024 14:58:38 +0100 Subject: [PATCH 29/91] Skip Android deps download if they already exist It's close to impossible to test locally built changes otherwise. --- android/native/build.gradle | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/android/native/build.gradle b/android/native/build.gradle index 396ccff85..e78ddfc49 100644 --- a/android/native/build.gradle +++ b/android/native/build.gradle @@ -43,19 +43,25 @@ android { } // get precompiled deps -task downloadDeps(type: Download) { - def depsDir = new File(buildDir.parent, 'deps') - def depsZip = new File(buildDir, 'deps.zip') +def depsDir = new File(buildDir.parent, 'deps') +if (new File(depsDir, 'armeabi-v7a').exists()) { + task getDeps { + doLast { logger.lifecycle('Using existing deps from {}', depsDir) } + } +} else { + task downloadDeps(type: Download) { + def depsZip = new File(buildDir, 'deps.zip') - src 'https://github.com/minetest/minetest_android_deps/releases/download/latest/deps.zip' - dest depsZip - overwrite false + src 'https://github.com/minetest/minetest_android_deps/releases/download/latest/deps.zip' + dest depsZip + overwrite false - task getDeps(dependsOn: downloadDeps, type: Copy) { - depsDir.mkdir() - from zipTree(depsZip) - into depsDir - doFirst { logger.lifecycle('Extracting to {}', depsDir) } + task getDeps(dependsOn: downloadDeps, type: Copy) { + depsDir.mkdir() + from zipTree(depsZip) + into depsDir + doFirst { logger.lifecycle('Extracting to {}', depsDir) } + } } } From 4660310db6a3f6544bf49b7165639772cf71a6d5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 18 Feb 2024 15:04:15 +0100 Subject: [PATCH 30/91] Update Gradle --- android/gradle/wrapper/gradle-wrapper.jar | Bin 55616 -> 43462 bytes .../gradle/wrapper/gradle-wrapper.properties | 4 +- android/gradlew | 295 +++++++++++------- android/gradlew.bat | 100 ------ 4 files changed, 181 insertions(+), 218 deletions(-) delete mode 100644 android/gradlew.bat diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf016b3885f6930543d57b744ea8c220a1a..d64cd4917707c1f8861d8cb53dd15194d4248596 100644 GIT binary patch literal 43462 zcma&NWl&^owk(X(xVyW%ySuwf;qI=D6|RlDJ2cR^yEKh!@I- zp9QeisK*rlxC>+~7Dk4IxIRsKBHqdR9b3+fyL=ynHmIDe&|>O*VlvO+%z5;9Z$|DJ zb4dO}-R=MKr^6EKJiOrJdLnCJn>np?~vU-1sSFgPu;pthGwf}bG z(1db%xwr#x)r+`4AGu$j7~u2MpVs3VpLp|mx&;>`0p0vH6kF+D2CY0fVdQOZ@h;A` z{infNyvmFUiu*XG}RNMNwXrbec_*a3N=2zJ|Wh5z* z5rAX$JJR{#zP>KY**>xHTuw?|-Rg|o24V)74HcfVT;WtQHXlE+_4iPE8QE#DUm%x0 zEKr75ur~W%w#-My3Tj`hH6EuEW+8K-^5P62$7Sc5OK+22qj&Pd1;)1#4tKihi=~8C zHiQSst0cpri6%OeaR`PY>HH_;CPaRNty%WTm4{wDK8V6gCZlG@U3$~JQZ;HPvDJcT1V{ z?>H@13MJcCNe#5z+MecYNi@VT5|&UiN1D4ATT+%M+h4c$t;C#UAs3O_q=GxK0}8%8 z8J(_M9bayxN}69ex4dzM_P3oh@ZGREjVvn%%r7=xjkqxJP4kj}5tlf;QosR=%4L5y zWhgejO=vao5oX%mOHbhJ8V+SG&K5dABn6!WiKl{|oPkq(9z8l&Mm%(=qGcFzI=eLu zWc_oCLyf;hVlB@dnwY98?75B20=n$>u3b|NB28H0u-6Rpl((%KWEBOfElVWJx+5yg z#SGqwza7f}$z;n~g%4HDU{;V{gXIhft*q2=4zSezGK~nBgu9-Q*rZ#2f=Q}i2|qOp z!!y4p)4o=LVUNhlkp#JL{tfkhXNbB=Ox>M=n6soptJw-IDI|_$is2w}(XY>a=H52d z3zE$tjPUhWWS+5h=KVH&uqQS=$v3nRs&p$%11b%5qtF}S2#Pc`IiyBIF4%A!;AVoI zXU8-Rpv!DQNcF~(qQnyyMy=-AN~U>#&X1j5BLDP{?K!%h!;hfJI>$mdLSvktEr*89 zdJHvby^$xEX0^l9g$xW-d?J;L0#(`UT~zpL&*cEh$L|HPAu=P8`OQZV!-}l`noSp_ zQ-1$q$R-gDL)?6YaM!=8H=QGW$NT2SeZlb8PKJdc=F-cT@j7Xags+Pr*jPtlHFnf- zh?q<6;)27IdPc^Wdy-mX%2s84C1xZq9Xms+==F4);O`VUASmu3(RlgE#0+#giLh-& zcxm3_e}n4{%|X zJp{G_j+%`j_q5}k{eW&TlP}J2wtZ2^<^E(O)4OQX8FDp6RJq!F{(6eHWSD3=f~(h} zJXCf7=r<16X{pHkm%yzYI_=VDP&9bmI1*)YXZeB}F? z(%QsB5fo*FUZxK$oX~X^69;x~j7ms8xlzpt-T15e9}$4T-pC z6PFg@;B-j|Ywajpe4~bk#S6(fO^|mm1hKOPfA%8-_iGCfICE|=P_~e;Wz6my&)h_~ zkv&_xSAw7AZ%ThYF(4jADW4vg=oEdJGVOs>FqamoL3Np8>?!W#!R-0%2Bg4h?kz5I zKV-rKN2n(vUL%D<4oj@|`eJ>0i#TmYBtYmfla;c!ATW%;xGQ0*TW@PTlGG><@dxUI zg>+3SiGdZ%?5N=8uoLA|$4isK$aJ%i{hECP$bK{J#0W2gQ3YEa zZQ50Stn6hqdfxJ*9#NuSLwKFCUGk@c=(igyVL;;2^wi4o30YXSIb2g_ud$ zgpCr@H0qWtk2hK8Q|&wx)}4+hTYlf;$a4#oUM=V@Cw#!$(nOFFpZ;0lc!qd=c$S}Z zGGI-0jg~S~cgVT=4Vo)b)|4phjStD49*EqC)IPwyeKBLcN;Wu@Aeph;emROAwJ-0< z_#>wVm$)ygH|qyxZaet&(Vf%pVdnvKWJn9`%DAxj3ot;v>S$I}jJ$FLBF*~iZ!ZXE zkvui&p}fI0Y=IDX)mm0@tAd|fEHl~J&K}ZX(Mm3cm1UAuwJ42+AO5@HwYfDH7ipIc zmI;1J;J@+aCNG1M`Btf>YT>~c&3j~Qi@Py5JT6;zjx$cvOQW@3oQ>|}GH?TW-E z1R;q^QFjm5W~7f}c3Ww|awg1BAJ^slEV~Pk`Kd`PS$7;SqJZNj->it4DW2l15}xP6 zoCl$kyEF%yJni0(L!Z&14m!1urXh6Btj_5JYt1{#+H8w?5QI%% zo-$KYWNMJVH?Hh@1n7OSu~QhSswL8x0=$<8QG_zepi_`y_79=nK=_ZP_`Em2UI*tyQoB+r{1QYZCpb?2OrgUw#oRH$?^Tj!Req>XiE#~B|~ z+%HB;=ic+R@px4Ld8mwpY;W^A%8%l8$@B@1m5n`TlKI6bz2mp*^^^1mK$COW$HOfp zUGTz-cN9?BGEp}5A!mDFjaiWa2_J2Iq8qj0mXzk; z66JBKRP{p%wN7XobR0YjhAuW9T1Gw3FDvR5dWJ8ElNYF94eF3ebu+QwKjtvVu4L zI9ip#mQ@4uqVdkl-TUQMb^XBJVLW(-$s;Nq;@5gr4`UfLgF$adIhd?rHOa%D);whv z=;krPp~@I+-Z|r#s3yCH+c1US?dnm+C*)r{m+86sTJusLdNu^sqLrfWed^ndHXH`m zd3#cOe3>w-ga(Dus_^ppG9AC>Iq{y%%CK+Cro_sqLCs{VLuK=dev>OL1dis4(PQ5R zcz)>DjEkfV+MO;~>VUlYF00SgfUo~@(&9$Iy2|G0T9BSP?&T22>K46D zL*~j#yJ?)^*%J3!16f)@Y2Z^kS*BzwfAQ7K96rFRIh>#$*$_Io;z>ux@}G98!fWR@ zGTFxv4r~v)Gsd|pF91*-eaZ3Qw1MH$K^7JhWIdX%o$2kCbvGDXy)a?@8T&1dY4`;L z4Kn+f%SSFWE_rpEpL9bnlmYq`D!6F%di<&Hh=+!VI~j)2mfil03T#jJ_s?}VV0_hp z7T9bWxc>Jm2Z0WMU?`Z$xE74Gu~%s{mW!d4uvKCx@WD+gPUQ zV0vQS(Ig++z=EHN)BR44*EDSWIyT~R4$FcF*VEY*8@l=218Q05D2$|fXKFhRgBIEE zdDFB}1dKkoO^7}{5crKX!p?dZWNz$m>1icsXG2N+((x0OIST9Zo^DW_tytvlwXGpn zs8?pJXjEG;T@qrZi%#h93?FP$!&P4JA(&H61tqQi=opRzNpm zkrG}$^t9&XduK*Qa1?355wd8G2CI6QEh@Ua>AsD;7oRUNLPb76m4HG3K?)wF~IyS3`fXuNM>${?wmB zpVz;?6_(Fiadfd{vUCBM*_kt$+F3J+IojI;9L(gc9n3{sEZyzR9o!_mOwFC#tQ{Q~ zP3-`#uK#tP3Q7~Q;4H|wjZHO8h7e4IuBxl&vz2w~D8)w=Wtg31zpZhz%+kzSzL*dV zwp@{WU4i;hJ7c2f1O;7Mz6qRKeASoIv0_bV=i@NMG*l<#+;INk-^`5w@}Dj~;k=|}qM1vq_P z|GpBGe_IKq|LNy9SJhKOQ$c=5L{Dv|Q_lZl=-ky*BFBJLW9&y_C|!vyM~rQx=!vun z?rZJQB5t}Dctmui5i31C_;_}CEn}_W%>oSXtt>@kE1=JW*4*v4tPp;O6 zmAk{)m!)}34pTWg8{i>($%NQ(Tl;QC@J@FfBoc%Gr&m560^kgSfodAFrIjF}aIw)X zoXZ`@IsMkc8_=w%-7`D6Y4e*CG8k%Ud=GXhsTR50jUnm+R*0A(O3UKFg0`K;qp1bl z7``HN=?39ic_kR|^R^~w-*pa?Vj#7|e9F1iRx{GN2?wK!xR1GW!qa=~pjJb-#u1K8 zeR?Y2i-pt}yJq;SCiVHODIvQJX|ZJaT8nO+(?HXbLefulKKgM^B(UIO1r+S=7;kLJ zcH}1J=Px2jsh3Tec&v8Jcbng8;V-`#*UHt?hB(pmOipKwf3Lz8rG$heEB30Sg*2rx zV<|KN86$soN(I!BwO`1n^^uF2*x&vJ$2d$>+`(romzHP|)K_KkO6Hc>_dwMW-M(#S zK(~SiXT1@fvc#U+?|?PniDRm01)f^#55;nhM|wi?oG>yBsa?~?^xTU|fX-R(sTA+5 zaq}-8Tx7zrOy#3*JLIIVsBmHYLdD}!0NP!+ITW+Thn0)8SS!$@)HXwB3tY!fMxc#1 zMp3H?q3eD?u&Njx4;KQ5G>32+GRp1Ee5qMO0lZjaRRu&{W<&~DoJNGkcYF<5(Ab+J zgO>VhBl{okDPn78<%&e2mR{jwVCz5Og;*Z;;3%VvoGo_;HaGLWYF7q#jDX=Z#Ml`H z858YVV$%J|e<1n`%6Vsvq7GmnAV0wW4$5qQ3uR@1i>tW{xrl|ExywIc?fNgYlA?C5 zh$ezAFb5{rQu6i7BSS5*J-|9DQ{6^BVQ{b*lq`xS@RyrsJN?-t=MTMPY;WYeKBCNg z^2|pN!Q^WPJuuO4!|P@jzt&tY1Y8d%FNK5xK(!@`jO2aEA*4 zkO6b|UVBipci?){-Ke=+1;mGlND8)6+P;8sq}UXw2hn;fc7nM>g}GSMWu&v&fqh

iViYT=fZ(|3Ox^$aWPp4a8h24tD<|8-!aK0lHgL$N7Efw}J zVIB!7=T$U`ao1?upi5V4Et*-lTG0XvExbf!ya{cua==$WJyVG(CmA6Of*8E@DSE%L z`V^$qz&RU$7G5mg;8;=#`@rRG`-uS18$0WPN@!v2d{H2sOqP|!(cQ@ zUHo!d>>yFArLPf1q`uBvY32miqShLT1B@gDL4XoVTK&@owOoD)OIHXrYK-a1d$B{v zF^}8D3Y^g%^cnvScOSJR5QNH+BI%d|;J;wWM3~l>${fb8DNPg)wrf|GBP8p%LNGN# z3EaIiItgwtGgT&iYCFy9-LG}bMI|4LdmmJt@V@% zb6B)1kc=T)(|L@0;wr<>=?r04N;E&ef+7C^`wPWtyQe(*pD1pI_&XHy|0gIGHMekd zF_*M4yi6J&Z4LQj65)S zXwdM{SwUo%3SbPwFsHgqF@V|6afT|R6?&S;lw=8% z3}@9B=#JI3@B*#4s!O))~z zc>2_4Q_#&+5V`GFd?88^;c1i7;Vv_I*qt!_Yx*n=;rj!82rrR2rQ8u5(Ejlo{15P% zs~!{%XJ>FmJ})H^I9bn^Re&38H{xA!0l3^89k(oU;bZWXM@kn$#aoS&Y4l^-WEn-fH39Jb9lA%s*WsKJQl?n9B7_~P z-XM&WL7Z!PcoF6_D>V@$CvUIEy=+Z&0kt{szMk=f1|M+r*a43^$$B^MidrT0J;RI` z(?f!O<8UZkm$_Ny$Hth1J#^4ni+im8M9mr&k|3cIgwvjAgjH z8`N&h25xV#v*d$qBX5jkI|xOhQn!>IYZK7l5#^P4M&twe9&Ey@@GxYMxBZq2e7?`q z$~Szs0!g{2fGcp9PZEt|rdQ6bhAgpcLHPz?f-vB?$dc*!9OL?Q8mn7->bFD2Si60* z!O%y)fCdMSV|lkF9w%x~J*A&srMyYY3{=&$}H zGQ4VG_?$2X(0|vT0{=;W$~icCI{b6W{B!Q8xdGhF|D{25G_5_+%s(46lhvNLkik~R z>nr(&C#5wwOzJZQo9m|U<;&Wk!_#q|V>fsmj1g<6%hB{jGoNUPjgJslld>xmODzGjYc?7JSuA?A_QzjDw5AsRgi@Y|Z0{F{!1=!NES-#*f^s4l0Hu zz468))2IY5dmD9pa*(yT5{EyP^G>@ZWumealS-*WeRcZ}B%gxq{MiJ|RyX-^C1V=0 z@iKdrGi1jTe8Ya^x7yyH$kBNvM4R~`fbPq$BzHum-3Zo8C6=KW@||>zsA8-Y9uV5V z#oq-f5L5}V<&wF4@X@<3^C%ptp6+Ce)~hGl`kwj)bsAjmo_GU^r940Z-|`<)oGnh7 zFF0Tde3>ui?8Yj{sF-Z@)yQd~CGZ*w-6p2U<8}JO-sRsVI5dBji`01W8A&3$?}lxBaC&vn0E$c5tW* zX>5(zzZ=qn&!J~KdsPl;P@bmA-Pr8T*)eh_+Dv5=Ma|XSle6t(k8qcgNyar{*ReQ8 zTXwi=8vr>!3Ywr+BhggHDw8ke==NTQVMCK`$69fhzEFB*4+H9LIvdt-#IbhZvpS}} zO3lz;P?zr0*0$%-Rq_y^k(?I{Mk}h@w}cZpMUp|ucs55bcloL2)($u%mXQw({Wzc~ z;6nu5MkjP)0C(@%6Q_I_vsWrfhl7Zpoxw#WoE~r&GOSCz;_ro6i(^hM>I$8y>`!wW z*U^@?B!MMmb89I}2(hcE4zN2G^kwyWCZp5JG>$Ez7zP~D=J^LMjSM)27_0B_X^C(M z`fFT+%DcKlu?^)FCK>QzSnV%IsXVcUFhFdBP!6~se&xxrIxsvySAWu++IrH;FbcY$ z2DWTvSBRfLwdhr0nMx+URA$j3i7_*6BWv#DXfym?ZRDcX9C?cY9sD3q)uBDR3uWg= z(lUIzB)G$Hr!){>E{s4Dew+tb9kvToZp-1&c?y2wn@Z~(VBhqz`cB;{E4(P3N2*nJ z_>~g@;UF2iG{Kt(<1PyePTKahF8<)pozZ*xH~U-kfoAayCwJViIrnqwqO}7{0pHw$ zs2Kx?s#vQr7XZ264>5RNKSL8|Ty^=PsIx^}QqOOcfpGUU4tRkUc|kc7-!Ae6!+B{o~7nFpm3|G5^=0#Bnm6`V}oSQlrX(u%OWnC zoLPy&Q;1Jui&7ST0~#+}I^&?vcE*t47~Xq#YwvA^6^} z`WkC)$AkNub|t@S!$8CBlwbV~?yp&@9h{D|3z-vJXgzRC5^nYm+PyPcgRzAnEi6Q^gslXYRv4nycsy-SJu?lMps-? zV`U*#WnFsdPLL)Q$AmD|0`UaC4ND07+&UmOu!eHruzV|OUox<+Jl|Mr@6~C`T@P%s zW7sgXLF2SSe9Fl^O(I*{9wsFSYb2l%-;&Pi^dpv!{)C3d0AlNY6!4fgmSgj_wQ*7Am7&$z;Jg&wgR-Ih;lUvWS|KTSg!&s_E9_bXBkZvGiC6bFKDWZxsD$*NZ#_8bl zG1P-#@?OQzED7@jlMJTH@V!6k;W>auvft)}g zhoV{7$q=*;=l{O>Q4a@ ziMjf_u*o^PsO)#BjC%0^h>Xp@;5$p{JSYDt)zbb}s{Kbt!T*I@Pk@X0zds6wsefuU zW$XY%yyRGC94=6mf?x+bbA5CDQ2AgW1T-jVAJbm7K(gp+;v6E0WI#kuACgV$r}6L? zd|Tj?^%^*N&b>Dd{Wr$FS2qI#Ucs1yd4N+RBUQiSZGujH`#I)mG&VKoDh=KKFl4=G z&MagXl6*<)$6P}*Tiebpz5L=oMaPrN+caUXRJ`D?=K9!e0f{@D&cZLKN?iNP@X0aF zE(^pl+;*T5qt?1jRC=5PMgV!XNITRLS_=9{CJExaQj;lt!&pdzpK?8p>%Mb+D z?yO*uSung=-`QQ@yX@Hyd4@CI^r{2oiu`%^bNkz+Nkk!IunjwNC|WcqvX~k=><-I3 zDQdbdb|!v+Iz01$w@aMl!R)koD77Xp;eZwzSl-AT zr@Vu{=xvgfq9akRrrM)}=!=xcs+U1JO}{t(avgz`6RqiiX<|hGG1pmop8k6Q+G_mv zJv|RfDheUp2L3=^C=4aCBMBn0aRCU(DQwX-W(RkRwmLeuJYF<0urcaf(=7)JPg<3P zQs!~G)9CT18o!J4{zX{_e}4eS)U-E)0FAt}wEI(c0%HkxgggW;(1E=>J17_hsH^sP z%lT0LGgbUXHx-K*CI-MCrP66UP0PvGqM$MkeLyqHdbgP|_Cm!7te~b8p+e6sQ_3k| zVcwTh6d83ltdnR>D^)BYQpDKlLk3g0Hdcgz2}%qUs9~~Rie)A-BV1mS&naYai#xcZ z(d{8=-LVpTp}2*y)|gR~;qc7fp26}lPcLZ#=JpYcn3AT9(UIdOyg+d(P5T7D&*P}# zQCYplZO5|7+r19%9e`v^vfSS1sbX1c%=w1;oyruXB%Kl$ACgKQ6=qNWLsc=28xJjg zwvsI5-%SGU|3p>&zXVl^vVtQT3o-#$UT9LI@Npz~6=4!>mc431VRNN8od&Ul^+G_kHC`G=6WVWM z%9eWNyy(FTO|A+@x}Ou3CH)oi;t#7rAxdIXfNFwOj_@Y&TGz6P_sqiB`Q6Lxy|Q{`|fgmRG(k+!#b*M+Z9zFce)f-7;?Km5O=LHV9f9_87; zF7%R2B+$?@sH&&-$@tzaPYkw0;=i|;vWdI|Wl3q_Zu>l;XdIw2FjV=;Mq5t1Q0|f< zs08j54Bp`3RzqE=2enlkZxmX6OF+@|2<)A^RNQpBd6o@OXl+i)zO%D4iGiQNuXd+zIR{_lb96{lc~bxsBveIw6umhShTX+3@ZJ=YHh@ zWY3(d0azg;7oHn>H<>?4@*RQbi>SmM=JrHvIG(~BrvI)#W(EAeO6fS+}mxxcc+X~W6&YVl86W9WFSS}Vz-f9vS?XUDBk)3TcF z8V?$4Q)`uKFq>xT=)Y9mMFVTUk*NIA!0$?RP6Ig0TBmUFrq*Q-Agq~DzxjStQyJ({ zBeZ;o5qUUKg=4Hypm|}>>L=XKsZ!F$yNTDO)jt4H0gdQ5$f|d&bnVCMMXhNh)~mN z@_UV6D7MVlsWz+zM+inZZp&P4fj=tm6fX)SG5H>OsQf_I8c~uGCig$GzuwViK54bcgL;VN|FnyQl>Ed7(@>=8$a_UKIz|V6CeVSd2(P z0Uu>A8A+muM%HLFJQ9UZ5c)BSAv_zH#1f02x?h9C}@pN@6{>UiAp>({Fn(T9Q8B z^`zB;kJ5b`>%dLm+Ol}ty!3;8f1XDSVX0AUe5P#@I+FQ-`$(a;zNgz)4x5hz$Hfbg z!Q(z26wHLXko(1`;(BAOg_wShpX0ixfWq3ponndY+u%1gyX)_h=v1zR#V}#q{au6; z!3K=7fQwnRfg6FXtNQmP>`<;!N137paFS%y?;lb1@BEdbvQHYC{976l`cLqn;b8lp zIDY>~m{gDj(wfnK!lpW6pli)HyLEiUrNc%eXTil|F2s(AY+LW5hkKb>TQ3|Q4S9rr zpDs4uK_co6XPsn_z$LeS{K4jFF`2>U`tbgKdyDne`xmR<@6AA+_hPNKCOR-Zqv;xk zu5!HsBUb^!4uJ7v0RuH-7?l?}b=w5lzzXJ~gZcxRKOovSk@|#V+MuX%Y+=;14i*%{)_gSW9(#4%)AV#3__kac1|qUy!uyP{>?U#5wYNq}y$S9pCc zFc~4mgSC*G~j0u#qqp9 z${>3HV~@->GqEhr_Xwoxq?Hjn#=s2;i~g^&Hn|aDKpA>Oc%HlW(KA1?BXqpxB;Ydx)w;2z^MpjJ(Qi(X!$5RC z*P{~%JGDQqojV>2JbEeCE*OEu!$XJ>bWA9Oa_Hd;y)F%MhBRi*LPcdqR8X`NQ&1L# z5#9L*@qxrx8n}LfeB^J{%-?SU{FCwiWyHp682F+|pa+CQa3ZLzBqN1{)h4d6+vBbV zC#NEbQLC;}me3eeYnOG*nXOJZEU$xLZ1<1Y=7r0(-U0P6-AqwMAM`a(Ed#7vJkn6plb4eI4?2y3yOTGmmDQ!z9`wzbf z_OY#0@5=bnep;MV0X_;;SJJWEf^E6Bd^tVJ9znWx&Ks8t*B>AM@?;D4oWUGc z!H*`6d7Cxo6VuyS4Eye&L1ZRhrRmN6Lr`{NL(wDbif|y&z)JN>Fl5#Wi&mMIr5i;x zBx}3YfF>>8EC(fYnmpu~)CYHuHCyr5*`ECap%t@y=jD>!_%3iiE|LN$mK9>- zHdtpy8fGZtkZF?%TW~29JIAfi2jZT8>OA7=h;8T{{k?c2`nCEx9$r zS+*&vt~2o^^J+}RDG@+9&M^K*z4p{5#IEVbz`1%`m5c2};aGt=V?~vIM}ZdPECDI)47|CWBCfDWUbxBCnmYivQ*0Nu_xb*C>~C9(VjHM zxe<*D<#dQ8TlpMX2c@M<9$w!RP$hpG4cs%AI){jp*Sj|*`m)5(Bw*A0$*i-(CA5#%>a)$+jI2C9r6|(>J8InryENI z$NohnxDUB;wAYDwrb*!N3noBTKPpPN}~09SEL18tkG zxgz(RYU_;DPT{l?Q$+eaZaxnsWCA^ds^0PVRkIM%bOd|G2IEBBiz{&^JtNsODs;5z zICt_Zj8wo^KT$7Bg4H+y!Df#3mbl%%?|EXe!&(Vmac1DJ*y~3+kRKAD=Ovde4^^%~ zw<9av18HLyrf*_>Slp;^i`Uy~`mvBjZ|?Ad63yQa#YK`4+c6;pW4?XIY9G1(Xh9WO8{F-Aju+nS9Vmv=$Ac0ienZ+p9*O%NG zMZKy5?%Z6TAJTE?o5vEr0r>f>hb#2w2U3DL64*au_@P!J!TL`oH2r*{>ffu6|A7tv zL4juf$DZ1MW5ZPsG!5)`k8d8c$J$o;%EIL0va9&GzWvkS%ZsGb#S(?{!UFOZ9<$a| zY|a+5kmD5N&{vRqkgY>aHsBT&`rg|&kezoD)gP0fsNYHsO#TRc_$n6Lf1Z{?+DLziXlHrq4sf(!>O{?Tj;Eh@%)+nRE_2VxbN&&%%caU#JDU%vL3}Cb zsb4AazPI{>8H&d=jUaZDS$-0^AxE@utGs;-Ez_F(qC9T=UZX=>ok2k2 ziTn{K?y~a5reD2A)P${NoI^>JXn>`IeArow(41c-Wm~)wiryEP(OS{YXWi7;%dG9v zI?mwu1MxD{yp_rrk!j^cKM)dc4@p4Ezyo%lRN|XyD}}>v=Xoib0gOcdXrQ^*61HNj z=NP|pd>@yfvr-=m{8$3A8TQGMTE7g=z!%yt`8`Bk-0MMwW~h^++;qyUP!J~ykh1GO z(FZ59xuFR$(WE;F@UUyE@Sp>`aVNjyj=Ty>_Vo}xf`e7`F;j-IgL5`1~-#70$9_=uBMq!2&1l zomRgpD58@)YYfvLtPW}{C5B35R;ZVvB<<#)x%srmc_S=A7F@DW8>QOEGwD6suhwCg z>Pa+YyULhmw%BA*4yjDp|2{!T98~<6Yfd(wo1mQ!KWwq0eg+6)o1>W~f~kL<-S+P@$wx*zeI|1t7z#Sxr5 zt6w+;YblPQNplq4Z#T$GLX#j6yldXAqj>4gAnnWtBICUnA&-dtnlh=t0Ho_vEKwV` z)DlJi#!@nkYV#$!)@>udAU*hF?V`2$Hf=V&6PP_|r#Iv*J$9)pF@X3`k;5})9^o4y z&)~?EjX5yX12O(BsFy-l6}nYeuKkiq`u9145&3Ssg^y{5G3Pse z9w(YVa0)N-fLaBq1`P!_#>SS(8fh_5!f{UrgZ~uEdeMJIz7DzI5!NHHqQtm~#CPij z?=N|J>nPR6_sL7!f4hD_|KH`vf8(Wpnj-(gPWH+ZvID}%?~68SwhPTC3u1_cB`otq z)U?6qo!ZLi5b>*KnYHWW=3F!p%h1;h{L&(Q&{qY6)_qxNfbP6E3yYpW!EO+IW3?@J z);4>g4gnl^8klu7uA>eGF6rIGSynacogr)KUwE_R4E5Xzi*Qir@b-jy55-JPC8c~( zo!W8y9OGZ&`xmc8;=4-U9=h{vCqfCNzYirONmGbRQlR`WWlgnY+1wCXbMz&NT~9*| z6@FrzP!LX&{no2!Ln_3|I==_4`@}V?4a;YZKTdw;vT<+K+z=uWbW(&bXEaWJ^W8Td z-3&1bY^Z*oM<=M}LVt>_j+p=2Iu7pZmbXrhQ_k)ysE9yXKygFNw$5hwDn(M>H+e1&9BM5!|81vd%r%vEm zqxY3?F@fb6O#5UunwgAHR9jp_W2zZ}NGp2%mTW@(hz7$^+a`A?mb8|_G*GNMJ) zjqegXQio=i@AINre&%ofexAr95aop5C+0MZ0m-l=MeO8m3epm7U%vZB8+I+C*iNFM z#T3l`gknX;D$-`2XT^Cg*vrv=RH+P;_dfF++cP?B_msQI4j+lt&rX2)3GaJx%W*Nn zkML%D{z5tpHH=dksQ*gzc|}gzW;lwAbxoR07VNgS*-c3d&8J|;@3t^ zVUz*J*&r7DFRuFVDCJDK8V9NN5hvpgGjwx+5n)qa;YCKe8TKtdnh{I7NU9BCN!0dq zczrBk8pE{{@vJa9ywR@mq*J=v+PG;?fwqlJVhijG!3VmIKs>9T6r7MJpC)m!Tc#>g zMtVsU>wbwFJEfwZ{vB|ZlttNe83)$iz`~#8UJ^r)lJ@HA&G#}W&ZH*;k{=TavpjWE z7hdyLZPf*X%Gm}i`Y{OGeeu^~nB8=`{r#TUrM-`;1cBvEd#d!kPqIgYySYhN-*1;L z^byj%Yi}Gx)Wnkosi337BKs}+5H5dth1JA{Ir-JKN$7zC)*}hqeoD(WfaUDPT>0`- z(6sa0AoIqASwF`>hP}^|)a_j2s^PQn*qVC{Q}htR z5-)duBFXT_V56-+UohKXlq~^6uf!6sA#ttk1o~*QEy_Y-S$gAvq47J9Vtk$5oA$Ct zYhYJ@8{hsC^98${!#Ho?4y5MCa7iGnfz}b9jE~h%EAAv~Qxu)_rAV;^cygV~5r_~?l=B`zObj7S=H=~$W zPtI_m%g$`kL_fVUk9J@>EiBH zOO&jtn~&`hIFMS5S`g8w94R4H40mdNUH4W@@XQk1sr17b{@y|JB*G9z1|CrQjd+GX z6+KyURG3;!*BQrentw{B2R&@2&`2}n(z-2&X7#r!{yg@Soy}cRD~j zj9@UBW+N|4HW4AWapy4wfUI- zZ`gSL6DUlgj*f1hSOGXG0IVH8HxK?o2|3HZ;KW{K+yPAlxtb)NV_2AwJm|E)FRs&& z=c^e7bvUsztY|+f^k7NXs$o1EUq>cR7C0$UKi6IooHWlK_#?IWDkvywnzg&ThWo^? z2O_N{5X39#?eV9l)xI(>@!vSB{DLt*oY!K1R8}_?%+0^C{d9a%N4 zoxHVT1&Lm|uDX%$QrBun5e-F`HJ^T$ zmzv)p@4ZHd_w9!%Hf9UYNvGCw2TTTbrj9pl+T9%-_-}L(tES>Or-}Z4F*{##n3~L~TuxjirGuIY#H7{%$E${?p{Q01 zi6T`n;rbK1yIB9jmQNycD~yZq&mbIsFWHo|ZAChSFPQa<(%d8mGw*V3fh|yFoxOOiWJd(qvVb!Z$b88cg->N=qO*4k~6;R==|9ihg&riu#P~s4Oap9O7f%crSr^rljeIfXDEg>wi)&v*a%7zpz<9w z*r!3q9J|390x`Zk;g$&OeN&ctp)VKRpDSV@kU2Q>jtok($Y-*x8_$2piTxun81@vt z!Vj?COa0fg2RPXMSIo26T=~0d`{oGP*eV+$!0I<(4azk&Vj3SiG=Q!6mX0p$z7I}; z9BJUFgT-K9MQQ-0@Z=^7R<{bn2Fm48endsSs`V7_@%8?Bxkqv>BDoVcj?K#dV#uUP zL1ND~?D-|VGKe3Rw_7-Idpht>H6XRLh*U7epS6byiGvJpr%d}XwfusjH9g;Z98H`x zyde%%5mhGOiL4wljCaWCk-&uE4_OOccb9c!ZaWt4B(wYl!?vyzl%7n~QepN&eFUrw zFIOl9c({``6~QD+43*_tzP{f2x41h(?b43^y6=iwyB)2os5hBE!@YUS5?N_tXd=h( z)WE286Fbd>R4M^P{!G)f;h<3Q>Fipuy+d2q-)!RyTgt;wr$(?9ox3;q+{E*ZQHhOn;lM`cjnu9 zXa48ks-v(~b*;MAI<>YZH(^NV8vjb34beE<_cwKlJoR;k6lJNSP6v}uiyRD?|0w+X@o1ONrH8a$fCxXpf? z?$DL0)7|X}Oc%h^zrMKWc-NS9I0Utu@>*j}b@tJ=ixQSJ={4@854wzW@E>VSL+Y{i z#0b=WpbCZS>kUCO_iQz)LoE>P5LIG-hv9E+oG}DtlIDF>$tJ1aw9^LuhLEHt?BCj& z(O4I8v1s#HUi5A>nIS-JK{v!7dJx)^Yg%XjNmlkWAq2*cv#tHgz`Y(bETc6CuO1VkN^L-L3j_x<4NqYb5rzrLC-7uOv z!5e`GZt%B782C5-fGnn*GhDF$%(qP<74Z}3xx+{$4cYKy2ikxI7B2N+2r07DN;|-T->nU&!=Cm#rZt%O_5c&1Z%nlWq3TKAW0w zQqemZw_ue--2uKQsx+niCUou?HjD`xhEjjQd3%rrBi82crq*~#uA4+>vR<_S{~5ce z-2EIl?~s z1=GVL{NxP1N3%=AOaC}j_Fv=ur&THz zyO!d9kHq|c73kpq`$+t+8Bw7MgeR5~`d7ChYyGCBWSteTB>8WAU(NPYt2Dk`@#+}= zI4SvLlyk#pBgVigEe`?NG*vl7V6m+<}%FwPV=~PvvA)=#ths==DRTDEYh4V5}Cf$z@#;< zyWfLY_5sP$gc3LLl2x+Ii)#b2nhNXJ{R~vk`s5U7Nyu^3yFg&D%Txwj6QezMX`V(x z=C`{76*mNb!qHHs)#GgGZ_7|vkt9izl_&PBrsu@}L`X{95-2jf99K)0=*N)VxBX2q z((vkpP2RneSIiIUEnGb?VqbMb=Zia+rF~+iqslydE34cSLJ&BJW^3knX@M;t*b=EA zNvGzv41Ld_T+WT#XjDB840vovUU^FtN_)G}7v)1lPetgpEK9YS^OWFkPoE{ovj^=@ zO9N$S=G$1ecndT_=5ehth2Lmd1II-PuT~C9`XVePw$y8J#dpZ?Tss<6wtVglm(Ok7 z3?^oi@pPio6l&!z8JY(pJvG=*pI?GIOu}e^EB6QYk$#FJQ%^AIK$I4epJ+9t?KjqA+bkj&PQ*|vLttme+`9G=L% ziadyMw_7-M)hS(3E$QGNCu|o23|%O+VN7;Qggp?PB3K-iSeBa2b}V4_wY`G1Jsfz4 z9|SdB^;|I8E8gWqHKx!vj_@SMY^hLEIbSMCuE?WKq=c2mJK z8LoG-pnY!uhqFv&L?yEuxo{dpMTsmCn)95xanqBrNPTgXP((H$9N${Ow~Is-FBg%h z53;|Y5$MUN)9W2HBe2TD`ct^LHI<(xWrw}$qSoei?}s)&w$;&!14w6B6>Yr6Y8b)S z0r71`WmAvJJ`1h&poLftLUS6Ir zC$bG9!Im_4Zjse)#K=oJM9mHW1{%l8sz$1o?ltdKlLTxWWPB>Vk22czVt|1%^wnN@*!l)}?EgtvhC>vlHm^t+ogpgHI1_$1ox9e;>0!+b(tBrmXRB`PY1vp-R**8N7 zGP|QqI$m(Rdu#=(?!(N}G9QhQ%o!aXE=aN{&wtGP8|_qh+7a_j_sU5|J^)vxq;# zjvzLn%_QPHZZIWu1&mRAj;Sa_97p_lLq_{~j!M9N^1yp3U_SxRqK&JnR%6VI#^E12 z>CdOVI^_9aPK2eZ4h&^{pQs}xsijXgFYRIxJ~N7&BB9jUR1fm!(xl)mvy|3e6-B3j zJn#ajL;bFTYJ2+Q)tDjx=3IklO@Q+FFM}6UJr6km7hj7th9n_&JR7fnqC!hTZoM~T zBeaVFp%)0cbPhejX<8pf5HyRUj2>aXnXBqDJe73~J%P(2C?-RT{c3NjE`)om! zl$uewSgWkE66$Kb34+QZZvRn`fob~Cl9=cRk@Es}KQm=?E~CE%spXaMO6YmrMl%9Q zlA3Q$3|L1QJ4?->UjT&CBd!~ru{Ih^in&JXO=|<6J!&qp zRe*OZ*cj5bHYlz!!~iEKcuE|;U4vN1rk$xq6>bUWD*u(V@8sG^7>kVuo(QL@Ki;yL zWC!FT(q{E8#on>%1iAS0HMZDJg{Z{^!De(vSIq&;1$+b)oRMwA3nc3mdTSG#3uYO_ z>+x;7p4I;uHz?ZB>dA-BKl+t-3IB!jBRgdvAbW!aJ(Q{aT>+iz?91`C-xbe)IBoND z9_Xth{6?(y3rddwY$GD65IT#f3<(0o#`di{sh2gm{dw*#-Vnc3r=4==&PU^hCv$qd zjw;>i&?L*Wq#TxG$mFIUf>eK+170KG;~+o&1;Tom9}}mKo23KwdEM6UonXgc z!6N(@k8q@HPw{O8O!lAyi{rZv|DpgfU{py+j(X_cwpKqcalcqKIr0kM^%Br3SdeD> zHSKV94Yxw;pjzDHo!Q?8^0bb%L|wC;4U^9I#pd5O&eexX+Im{ z?jKnCcsE|H?{uGMqVie_C~w7GX)kYGWAg%-?8|N_1#W-|4F)3YTDC+QSq1s!DnOML3@d`mG%o2YbYd#jww|jD$gotpa)kntakp#K;+yo-_ZF9qrNZw<%#C zuPE@#3RocLgPyiBZ+R_-FJ_$xP!RzWm|aN)S+{$LY9vvN+IW~Kf3TsEIvP+B9Mtm! zpfNNxObWQpLoaO&cJh5>%slZnHl_Q~(-Tfh!DMz(dTWld@LG1VRF`9`DYKhyNv z2pU|UZ$#_yUx_B_|MxUq^glT}O5Xt(Vm4Mr02><%C)@v;vPb@pT$*yzJ4aPc_FZ3z z3}PLoMBIM>q_9U2rl^sGhk1VUJ89=*?7|v`{!Z{6bqFMq(mYiA?%KbsI~JwuqVA9$H5vDE+VocjX+G^%bieqx->s;XWlKcuv(s%y%D5Xbc9+ zc(_2nYS1&^yL*ey664&4`IoOeDIig}y-E~_GS?m;D!xv5-xwz+G`5l6V+}CpeJDi^ z%4ed$qowm88=iYG+(`ld5Uh&>Dgs4uPHSJ^TngXP_V6fPyl~>2bhi20QB%lSd#yYn zO05?KT1z@?^-bqO8Cg`;ft>ilejsw@2%RR7;`$Vs;FmO(Yr3Fp`pHGr@P2hC%QcA|X&N2Dn zYf`MqXdHi%cGR@%y7Rg7?d3?an){s$zA{!H;Ie5exE#c~@NhQUFG8V=SQh%UxUeiV zd7#UcYqD=lk-}sEwlpu&H^T_V0{#G?lZMxL7ih_&{(g)MWBnCZxtXg znr#}>U^6!jA%e}@Gj49LWG@*&t0V>Cxc3?oO7LSG%~)Y5}f7vqUUnQ;STjdDU}P9IF9d9<$;=QaXc zL1^X7>fa^jHBu_}9}J~#-oz3Oq^JmGR#?GO7b9a(=R@fw@}Q{{@`Wy1vIQ#Bw?>@X z-_RGG@wt|%u`XUc%W{J z>iSeiz8C3H7@St3mOr_mU+&bL#Uif;+Xw-aZdNYUpdf>Rvu0i0t6k*}vwU`XNO2he z%miH|1tQ8~ZK!zmL&wa3E;l?!!XzgV#%PMVU!0xrDsNNZUWKlbiOjzH-1Uoxm8E#r`#2Sz;-o&qcqB zC-O_R{QGuynW14@)7&@yw1U}uP(1cov)twxeLus0s|7ayrtT8c#`&2~Fiu2=R;1_4bCaD=*E@cYI>7YSnt)nQc zohw5CsK%m?8Ack)qNx`W0_v$5S}nO|(V|RZKBD+btO?JXe|~^Qqur%@eO~<8-L^9d z=GA3-V14ng9L29~XJ>a5k~xT2152zLhM*@zlp2P5Eu}bywkcqR;ISbas&#T#;HZSf z2m69qTV(V@EkY(1Dk3`}j)JMo%ZVJ*5eB zYOjIisi+igK0#yW*gBGj?@I{~mUOvRFQR^pJbEbzFxTubnrw(Muk%}jI+vXmJ;{Q6 zrSobKD>T%}jV4Ub?L1+MGOD~0Ir%-`iTnWZN^~YPrcP5y3VMAzQ+&en^VzKEb$K!Q z<7Dbg&DNXuow*eD5yMr+#08nF!;%4vGrJI++5HdCFcGLfMW!KS*Oi@=7hFwDG!h2< zPunUEAF+HncQkbfFj&pbzp|MU*~60Z(|Ik%Tn{BXMN!hZOosNIseT?R;A`W?=d?5X zK(FB=9mZusYahp|K-wyb={rOpdn=@;4YI2W0EcbMKyo~-#^?h`BA9~o285%oY zfifCh5Lk$SY@|2A@a!T2V+{^!psQkx4?x0HSV`(w9{l75QxMk!)U52Lbhn{8ol?S) zCKo*7R(z!uk<6*qO=wh!Pul{(qq6g6xW;X68GI_CXp`XwO zxuSgPRAtM8K7}5E#-GM!*ydOOG_{A{)hkCII<|2=ma*71ci_-}VPARm3crFQjLYV! z9zbz82$|l01mv`$WahE2$=fAGWkd^X2kY(J7iz}WGS z@%MyBEO=A?HB9=^?nX`@nh;7;laAjs+fbo!|K^mE!tOB>$2a_O0y-*uaIn8k^6Y zSbuv;5~##*4Y~+y7Z5O*3w4qgI5V^17u*ZeupVGH^nM&$qmAk|anf*>r zWc5CV;-JY-Z@Uq1Irpb^O`L_7AGiqd*YpGUShb==os$uN3yYvb`wm6d=?T*it&pDk zo`vhw)RZX|91^^Wa_ti2zBFyWy4cJu#g)_S6~jT}CC{DJ_kKpT`$oAL%b^!2M;JgT zM3ZNbUB?}kP(*YYvXDIH8^7LUxz5oE%kMhF!rnPqv!GiY0o}NR$OD=ITDo9r%4E>E0Y^R(rS^~XjWyVI6 zMOR5rPXhTp*G*M&X#NTL`Hu*R+u*QNoiOKg4CtNPrjgH>c?Hi4MUG#I917fx**+pJfOo!zFM&*da&G_x)L(`k&TPI*t3e^{crd zX<4I$5nBQ8Ax_lmNRa~E*zS-R0sxkz`|>7q_?*e%7bxqNm3_eRG#1ae3gtV9!fQpY z+!^a38o4ZGy9!J5sylDxZTx$JmG!wg7;>&5H1)>f4dXj;B+@6tMlL=)cLl={jLMxY zbbf1ax3S4>bwB9-$;SN2?+GULu;UA-35;VY*^9Blx)Jwyb$=U!D>HhB&=jSsd^6yw zL)?a|>GxU!W}ocTC(?-%z3!IUhw^uzc`Vz_g>-tv)(XA#JK^)ZnC|l1`@CdX1@|!| z_9gQ)7uOf?cR@KDp97*>6X|;t@Y`k_N@)aH7gY27)COv^P3ya9I{4z~vUjLR9~z1Z z5=G{mVtKH*&$*t0@}-i_v|3B$AHHYale7>E+jP`ClqG%L{u;*ff_h@)al?RuL7tOO z->;I}>%WI{;vbLP3VIQ^iA$4wl6@0sDj|~112Y4OFjMs`13!$JGkp%b&E8QzJw_L5 zOnw9joc0^;O%OpF$Qp)W1HI!$4BaXX84`%@#^dk^hFp^pQ@rx4g(8Xjy#!X%+X5Jd@fs3amGT`}mhq#L97R>OwT5-m|h#yT_-v@(k$q7P*9X~T*3)LTdzP!*B} z+SldbVWrrwQo9wX*%FyK+sRXTa@O?WM^FGWOE?S`R(0P{<6p#f?0NJvnBia?k^fX2 zNQs7K-?EijgHJY}&zsr;qJ<*PCZUd*x|dD=IQPUK_nn)@X4KWtqoJNHkT?ZWL_hF? zS8lp2(q>;RXR|F;1O}EE#}gCrY~#n^O`_I&?&z5~7N;zL0)3Tup`%)oHMK-^r$NT% zbFg|o?b9w(q@)6w5V%si<$!U<#}s#x@0aX-hP>zwS#9*75VXA4K*%gUc>+yzupTDBOKH8WR4V0pM(HrfbQ&eJ79>HdCvE=F z|J>s;;iDLB^3(9}?biKbxf1$lI!*Z%*0&8UUq}wMyPs_hclyQQi4;NUY+x2qy|0J; zhn8;5)4ED1oHwg+VZF|80<4MrL97tGGXc5Sw$wAI#|2*cvQ=jB5+{AjMiDHmhUC*a zlmiZ`LAuAn_}hftXh;`Kq0zblDk8?O-`tnilIh|;3lZp@F_osJUV9`*R29M?7H{Fy z`nfVEIDIWXmU&YW;NjU8)EJpXhxe5t+scf|VXM!^bBlwNh)~7|3?fWwo_~ZFk(22% zTMesYw+LNx3J-_|DM~`v93yXe=jPD{q;li;5PD?Dyk+b? zo21|XpT@)$BM$%F=P9J19Vi&1#{jM3!^Y&fr&_`toi`XB1!n>sbL%U9I5<7!@?t)~ z;&H%z>bAaQ4f$wIzkjH70;<8tpUoxzKrPhn#IQfS%9l5=Iu))^XC<58D!-O z{B+o5R^Z21H0T9JQ5gNJnqh#qH^na|z92=hONIM~@_iuOi|F>jBh-?aA20}Qx~EpDGElELNn~|7WRXRFnw+Wdo`|# zBpU=Cz3z%cUJ0mx_1($X<40XEIYz(`noWeO+x#yb_pwj6)R(__%@_Cf>txOQ74wSJ z0#F3(zWWaR-jMEY$7C*3HJrohc79>MCUu26mfYN)f4M~4gD`}EX4e}A!U}QV8!S47 z6y-U-%+h`1n`*pQuKE%Av0@)+wBZr9mH}@vH@i{v(m-6QK7Ncf17x_D=)32`FOjjo zg|^VPf5c6-!FxN{25dvVh#fog=NNpXz zfB$o+0jbRkHH{!TKhE709f+jI^$3#v1Nmf80w`@7-5$1Iv_`)W^px8P-({xwb;D0y z7LKDAHgX<84?l!I*Dvi2#D@oAE^J|g$3!)x1Ua;_;<@#l1fD}lqU2_tS^6Ht$1Wl} zBESo7o^)9-Tjuz$8YQSGhfs{BQV6zW7dA?0b(Dbt=UnQs&4zHfe_sj{RJ4uS-vQpC zX;Bbsuju4%!o8?&m4UZU@~ZZjeFF6ex2ss5_60_JS_|iNc+R0GIjH1@Z z=rLT9%B|WWgOrR7IiIwr2=T;Ne?30M!@{%Qf8o`!>=s<2CBpCK_TWc(DX51>e^xh8 z&@$^b6CgOd7KXQV&Y4%}_#uN*mbanXq(2=Nj`L7H7*k(6F8s6{FOw@(DzU`4-*77{ zF+dxpv}%mFpYK?>N_2*#Y?oB*qEKB}VoQ@bzm>ptmVS_EC(#}Lxxx730trt0G)#$b zE=wVvtqOct1%*9}U{q<)2?{+0TzZzP0jgf9*)arV)*e!f`|jgT{7_9iS@e)recI#z zbzolURQ+TOzE!ymqvBY7+5NnAbWxvMLsLTwEbFqW=CPyCsmJ}P1^V30|D5E|p3BC5 z)3|qgw@ra7aXb-wsa|l^in~1_fm{7bS9jhVRkYVO#U{qMp z)Wce+|DJ}4<2gp8r0_xfZpMo#{Hl2MfjLcZdRB9(B(A(f;+4s*FxV{1F|4d`*sRNd zp4#@sEY|?^FIJ;tmH{@keZ$P(sLh5IdOk@k^0uB^BWr@pk6mHy$qf&~rI>P*a;h0C{%oA*i!VjWn&D~O#MxN&f@1Po# zKN+ zrGrkSjcr?^R#nGl<#Q722^wbYcgW@{+6CBS<1@%dPA8HC!~a`jTz<`g_l5N1M@9wn9GOAZ>nqNgq!yOCbZ@1z`U_N`Z>}+1HIZxk*5RDc&rd5{3qjRh8QmT$VyS;jK z;AF+r6XnnCp=wQYoG|rT2@8&IvKq*IB_WvS%nt%e{MCFm`&W*#LXc|HrD?nVBo=(8*=Aq?u$sDA_sC_RPDUiQ+wnIJET8vx$&fxkW~kP9qXKt zozR)@xGC!P)CTkjeWvXW5&@2?)qt)jiYWWBU?AUtzAN}{JE1I)dfz~7$;}~BmQF`k zpn11qmObXwRB8&rnEG*#4Xax3XBkKlw(;tb?Np^i+H8m(Wyz9k{~ogba@laiEk;2! zV*QV^6g6(QG%vX5Um#^sT&_e`B1pBW5yVth~xUs#0}nv?~C#l?W+9Lsb_5)!71rirGvY zTIJ$OPOY516Y|_014sNv+Z8cc5t_V=i>lWV=vNu#!58y9Zl&GsMEW#pPYPYGHQ|;vFvd*9eM==$_=vc7xnyz0~ zY}r??$<`wAO?JQk@?RGvkWVJlq2dk9vB(yV^vm{=NVI8dhsX<)O(#nr9YD?I?(VmQ z^r7VfUBn<~p3()8yOBjm$#KWx!5hRW)5Jl7wY@ky9lNM^jaT##8QGVsYeaVywmpv>X|Xj7gWE1Ezai&wVLt3p)k4w~yrskT-!PR!kiyQlaxl(( zXhF%Q9x}1TMt3~u@|#wWm-Vq?ZerK={8@~&@9r5JW}r#45#rWii};t`{5#&3$W)|@ zbAf2yDNe0q}NEUvq_Quq3cTjcw z@H_;$hu&xllCI9CFDLuScEMg|x{S7GdV8<&Mq=ezDnRZAyX-8gv97YTm0bg=d)(>N z+B2FcqvI9>jGtnK%eO%y zoBPkJTk%y`8TLf4)IXPBn`U|9>O~WL2C~C$z~9|0m*YH<-vg2CD^SX#&)B4ngOSG$ zV^wmy_iQk>dfN@Pv(ckfy&#ak@MLC7&Q6Ro#!ezM*VEh`+b3Jt%m(^T&p&WJ2Oqvj zs-4nq0TW6cv~(YI$n0UkfwN}kg3_fp?(ijSV#tR9L0}l2qjc7W?i*q01=St0eZ=4h zyGQbEw`9OEH>NMuIe)hVwYHsGERWOD;JxEiO7cQv%pFCeR+IyhwQ|y@&^24k+|8fD zLiOWFNJ2&vu2&`Jv96_z-Cd5RLgmeY3*4rDOQo?Jm`;I_(+ejsPM03!ly!*Cu}Cco zrQSrEDHNyzT(D5s1rZq!8#?f6@v6dB7a-aWs(Qk>N?UGAo{gytlh$%_IhyL7h?DLXDGx zgxGEBQoCAWo-$LRvM=F5MTle`M})t3vVv;2j0HZY&G z22^iGhV@uaJh(XyyY%} zd4iH_UfdV#T=3n}(Lj^|n;O4|$;xhu*8T3hR1mc_A}fK}jfZ7LX~*n5+`8N2q#rI$ z@<_2VANlYF$vIH$ zl<)+*tIWW78IIINA7Rr7i{<;#^yzxoLNkXL)eSs=%|P>$YQIh+ea_3k z_s7r4%j7%&*NHSl?R4k%1>Z=M9o#zxY!n8sL5>BO-ZP;T3Gut>iLS@U%IBrX6BA3k z)&@q}V8a{X<5B}K5s(c(LQ=%v1ocr`t$EqqY0EqVjr65usa=0bkf|O#ky{j3)WBR(((L^wmyHRzoWuL2~WTC=`yZ zn%VX`L=|Ok0v7?s>IHg?yArBcync5rG#^+u)>a%qjES%dRZoIyA8gQ;StH z1Ao7{<&}6U=5}4v<)1T7t!J_CL%U}CKNs-0xWoTTeqj{5{?Be$L0_tk>M9o8 zo371}S#30rKZFM{`H_(L`EM9DGp+Mifk&IP|C2Zu_)Ghr4Qtpmkm1osCf@%Z$%t+7 zYH$Cr)Ro@3-QDeQJ8m+x6%;?YYT;k6Z0E-?kr>x33`H%*ueBD7Zx~3&HtWn0?2Wt} zTG}*|v?{$ajzt}xPzV%lL1t-URi8*Zn)YljXNGDb>;!905Td|mpa@mHjIH%VIiGx- zd@MqhpYFu4_?y5N4xiHn3vX&|e6r~Xt> zZG`aGq|yTNjv;9E+Txuoa@A(9V7g?1_T5FzRI;!=NP1Kqou1z5?%X~Wwb{trRfd>i z8&y^H)8YnKyA_Fyx>}RNmQIczT?w2J4SNvI{5J&}Wto|8FR(W;Qw#b1G<1%#tmYzQ zQ2mZA-PAdi%RQOhkHy9Ea#TPSw?WxwL@H@cbkZwIq0B!@ns}niALidmn&W?!Vd4Gj zO7FiuV4*6Mr^2xlFSvM;Cp_#r8UaqIzHJQg_z^rEJw&OMm_8NGAY2)rKvki|o1bH~ z$2IbfVeY2L(^*rMRU1lM5Y_sgrDS`Z??nR2lX;zyR=c%UyGb*%TC-Dil?SihkjrQy~TMv6;BMs7P8il`H7DmpVm@rJ;b)hW)BL)GjS154b*xq-NXq2cwE z^;VP7ua2pxvCmxrnqUYQMH%a%nHmwmI33nJM(>4LznvY*k&C0{8f*%?zggpDgkuz&JBx{9mfb@wegEl2v!=}Sq2Gaty0<)UrOT0{MZtZ~j5y&w zXlYa_jY)I_+VA-^#mEox#+G>UgvM!Ac8zI<%JRXM_73Q!#i3O|)lOP*qBeJG#BST0 zqohi)O!|$|2SeJQo(w6w7%*92S})XfnhrH_Z8qe!G5>CglP=nI7JAOW?(Z29;pXJ9 zR9`KzQ=WEhy*)WH>$;7Cdz|>*i>=##0bB)oU0OR>>N<21e4rMCHDemNi2LD>Nc$;& zQRFthpWniC1J6@Zh~iJCoLOxN`oCKD5Q4r%ynwgUKPlIEd#?QViIqovY|czyK8>6B zSP%{2-<;%;1`#0mG^B(8KbtXF;Nf>K#Di72UWE4gQ%(_26Koiad)q$xRL~?pN71ZZ zujaaCx~jXjygw;rI!WB=xrOJO6HJ!!w}7eiivtCg5K|F6$EXa)=xUC za^JXSX98W`7g-tm@uo|BKj39Dl;sg5ta;4qjo^pCh~{-HdLl6qI9Ix6f$+qiZ$}s= zNguKrU;u+T@ko(Vr1>)Q%h$?UKXCY>3se%&;h2osl2D zE4A9bd7_|^njDd)6cI*FupHpE3){4NQ*$k*cOWZ_?CZ>Z4_fl@n(mMnYK62Q1d@+I zr&O))G4hMihgBqRIAJkLdk(p(D~X{-oBUA+If@B}j& zsHbeJ3RzTq96lB7d($h$xTeZ^gP0c{t!Y0c)aQE;$FY2!mACg!GDEMKXFOPI^)nHZ z`aSPJpvV0|bbrzhWWkuPURlDeN%VT8tndV8?d)eN*i4I@u zVKl^6{?}A?P)Fsy?3oi#clf}L18t;TjNI2>eI&(ezDK7RyqFxcv%>?oxUlonv(px) z$vnPzRH`y5A(x!yOIfL0bmgeMQB$H5wenx~!ujQK*nUBW;@Em&6Xv2%s(~H5WcU2R z;%Nw<$tI)a`Ve!>x+qegJnQsN2N7HaKzrFqM>`6R*gvh%O*-%THt zrB$Nk;lE;z{s{r^PPm5qz(&lM{sO*g+W{sK+m3M_z=4=&CC>T`{X}1Vg2PEfSj2x_ zmT*(x;ov%3F?qoEeeM>dUn$a*?SIGyO8m806J1W1o+4HRhc2`9$s6hM#qAm zChQ87b~GEw{ADfs+5}FJ8+|bIlIv(jT$Ap#hSHoXdd9#w<#cA<1Rkq^*EEkknUd4& zoIWIY)sAswy6fSERVm&!SO~#iN$OgOX*{9@_BWFyJTvC%S++ilSfCrO(?u=Dc?CXZ zzCG&0yVR{Z`|ZF0eEApWEo#s9osV>F{uK{QA@BES#&;#KsScf>y zvs?vIbI>VrT<*!;XmQS=bhq%46-aambZ(8KU-wOO2=en~D}MCToB_u;Yz{)1ySrPZ z@=$}EvjTdzTWU7c0ZI6L8=yP+YRD_eMMos}b5vY^S*~VZysrkq<`cK3>>v%uy7jgq z0ilW9KjVDHLv0b<1K_`1IkbTOINs0=m-22c%M~l=^S}%hbli-3?BnNq?b`hx^HX2J zIe6ECljRL0uBWb`%{EA=%!i^4sMcj+U_TaTZRb+~GOk z^ZW!nky0n*Wb*r+Q|9H@ml@Z5gU&W`(z4-j!OzC1wOke`TRAYGZVl$PmQ16{3196( zO*?`--I}Qf(2HIwb2&1FB^!faPA2=sLg(@6P4mN)>Dc3i(B0;@O-y2;lM4akD>@^v z=u>*|!s&9zem70g7zfw9FXl1bpJW(C#5w#uy5!V?Q(U35A~$dR%LDVnq@}kQm13{} zd53q3N(s$Eu{R}k2esbftfjfOITCL;jWa$}(mmm}d(&7JZ6d3%IABCapFFYjdEjdK z&4Edqf$G^MNAtL=uCDRs&Fu@FXRgX{*0<(@c3|PNHa>L%zvxWS={L8%qw`STm+=Rd zA}FLspESSIpE_^41~#5yI2bJ=9`oc;GIL!JuW&7YetZ?0H}$$%8rW@*J37L-~Rsx!)8($nI4 zZhcZ2^=Y+p4YPl%j!nFJA|*M^gc(0o$i3nlphe+~-_m}jVkRN{spFs(o0ajW@f3K{ zDV!#BwL322CET$}Y}^0ixYj2w>&Xh12|R8&yEw|wLDvF!lZ#dOTHM9pK6@Nm-@9Lnng4ZHBgBSrr7KI8YCC9DX5Kg|`HsiwJHg2(7#nS;A{b3tVO?Z% za{m5b3rFV6EpX;=;n#wltDv1LE*|g5pQ+OY&*6qCJZc5oDS6Z6JD#6F)bWxZSF@q% z+1WV;m!lRB!n^PC>RgQCI#D1br_o^#iPk>;K2hB~0^<~)?p}LG%kigm@moD#q3PE+ zA^Qca)(xnqw6x>XFhV6ku9r$E>bWNrVH9fum0?4s?Rn2LG{Vm_+QJHse6xa%nzQ?k zKug4PW~#Gtb;#5+9!QBgyB@q=sk9=$S{4T>wjFICStOM?__fr+Kei1 z3j~xPqW;W@YkiUM;HngG!;>@AITg}vAE`M2Pj9Irl4w1fo4w<|Bu!%rh%a(Ai^Zhi zs92>v5;@Y(Zi#RI*ua*h`d_7;byQSa*v9E{2x$<-_=5Z<7{%)}4XExANcz@rK69T0x3%H<@frW>RA8^swA+^a(FxK| zFl3LD*ImHN=XDUkrRhp6RY5$rQ{bRgSO*(vEHYV)3Mo6Jy3puiLmU&g82p{qr0F?ohmbz)f2r{X2|T2 z$4fdQ=>0BeKbiVM!e-lIIs8wVTuC_m7}y4A_%ikI;Wm5$9j(^Y z(cD%U%k)X>_>9~t8;pGzL6L-fmQO@K; zo&vQzMlgY95;1BSkngY)e{`n0!NfVgf}2mB3t}D9@*N;FQ{HZ3Pb%BK6;5#-O|WI( zb6h@qTLU~AbVW#_6?c!?Dj65Now7*pU{h!1+eCV^KCuPAGs28~3k@ueL5+u|Z-7}t z9|lskE`4B7W8wMs@xJa{#bsCGDFoRSNSnmNYB&U7 zVGKWe%+kFB6kb)e;TyHfqtU6~fRg)f|>=5(N36)0+C z`hv65J<$B}WUc!wFAb^QtY31yNleq4dzmG`1wHTj=c*=hay9iD071Hc?oYoUk|M*_ zU1GihAMBsM@5rUJ(qS?9ZYJ6@{bNqJ`2Mr+5#hKf?doa?F|+^IR!8lq9)wS3tF_9n zW_?hm)G(M+MYb?V9YoX^_mu5h-LP^TL^!Q9Z7|@sO(rg_4+@=PdI)WL(B7`!K^ND- z-uIuVDCVEdH_C@c71YGYT^_Scf_dhB8Z2Xy6vGtBSlYud9vggOqv^L~F{BraSE_t} zIkP+Hp2&nH^-MNEs}^`oMLy11`PQW$T|K(`Bu*(f@)mv1-qY(_YG&J2M2<7k;;RK~ zL{Fqj9yCz8(S{}@c)S!65aF<=&eLI{hAMErCx&>i7OeDN>okvegO87OaG{Jmi<|}D zaT@b|0X{d@OIJ7zvT>r+eTzgLq~|Dpu)Z&db-P4z*`M$UL51lf>FLlq6rfG)%doyp z)3kk_YIM!03eQ8Vu_2fg{+osaEJPtJ-s36R+5_AEG12`NG)IQ#TF9c@$99%0iye+ zUzZ57=m2)$D(5Nx!n)=5Au&O0BBgwxIBaeI(mro$#&UGCr<;C{UjJVAbVi%|+WP(a zL$U@TYCxJ=1{Z~}rnW;7UVb7+ZnzgmrogDxhjLGo>c~MiJAWs&&;AGg@%U?Y^0JhL ze(x6Z74JG6FlOFK(T}SXQfhr}RIFl@QXKnIcXYF)5|V~e-}suHILKT-k|<*~Ij|VF zC;t@=uj=hot~*!C68G8hTA%8SzOfETOXQ|3FSaIEjvBJp(A)7SWUi5!Eu#yWgY+;n zlm<$+UDou*V+246_o#V4kMdto8hF%%Lki#zPh}KYXmMf?hrN0;>Mv%`@{0Qn`Ujp) z=lZe+13>^Q!9zT);H<(#bIeRWz%#*}sgUX9P|9($kexOyKIOc`dLux}c$7It4u|Rl z6SSkY*V~g_B-hMPo_ak>>z@AVQ(_N)VY2kB3IZ0G(iDUYw+2d7W^~(Jq}KY=JnWS( z#rzEa&0uNhJ>QE8iiyz;n2H|SV#Og+wEZv=f2%1ELX!SX-(d3tEj$5$1}70Mp<&eI zCkfbByL7af=qQE@5vDVxx1}FSGt_a1DoE3SDI+G)mBAna)KBG4p8Epxl9QZ4BfdAN zFnF|Y(umr;gRgG6NLQ$?ZWgllEeeq~z^ZS7L?<(~O&$5|y)Al^iMKy}&W+eMm1W z7EMU)u^ke(A1#XCV>CZ71}P}0x)4wtHO8#JRG3MA-6g=`ZM!FcICCZ{IEw8Dm2&LQ z1|r)BUG^0GzI6f946RrBlfB1Vs)~8toZf~7)+G;pv&XiUO(%5bm)pl=p>nV^o*;&T z;}@oZSibzto$arQgfkp|z4Z($P>dTXE{4O=vY0!)kDO* zGF8a4wq#VaFpLfK!iELy@?-SeRrdz%F*}hjKcA*y@mj~VD3!it9lhRhX}5YOaR9$} z3mS%$2Be7{l(+MVx3 z(4?h;P!jnRmX9J9sYN#7i=iyj_5q7n#X(!cdqI2lnr8T$IfOW<_v`eB!d9xY1P=2q&WtOXY=D9QYteP)De?S4}FK6#6Ma z=E*V+#s8>L;8aVroK^6iKo=MH{4yEZ_>N-N z`(|;aOATba1^asjxlILk<4}f~`39dBFlxj>Dw(hMYKPO3EEt1@S`1lxFNM+J@uB7T zZ8WKjz7HF1-5&2=l=fqF-*@>n5J}jIxdDwpT?oKM3s8Nr`x8JnN-kCE?~aM1H!hAE z%%w(3kHfGwMnMmNj(SU(w42OrC-euI>Dsjk&jz3ts}WHqmMpzQ3vZrsXrZ|}+MHA7 z068obeXZTsO*6RS@o3x80E4ok``rV^Y3hr&C1;|ZZ0|*EKO`$lECUYG2gVFtUTw)R z4Um<0ZzlON`zTdvVdL#KFoMFQX*a5wM0Czp%wTtfK4Sjs)P**RW&?lP$(<}q%r68Z zS53Y!d@&~ne9O)A^tNrXHhXBkj~$8j%pT1%%mypa9AW5E&s9)rjF4@O3ytH{0z6riz|@< zB~UPh*wRFg2^7EbQrHf0y?E~dHlkOxof_a?M{LqQ^C!i2dawHTPYUE=X@2(3<=OOxs8qn_(y>pU>u^}3y&df{JarR0@VJn0f+U%UiF=$Wyq zQvnVHESil@d|8&R<%}uidGh7@u^(%?$#|&J$pvFC-n8&A>utA=n3#)yMkz+qnG3wd zP7xCnF|$9Dif@N~L)Vde3hW8W!UY0BgT2v(wzp;tlLmyk2%N|0jfG$%<;A&IVrOI< z!L)o>j>;dFaqA3pL}b-Je(bB@VJ4%!JeX@3x!i{yIeIso^=n?fDX`3bU=eG7sTc%g%ye8$v8P@yKE^XD=NYxTb zbf!Mk=h|otpqjFaA-vs5YOF-*GwWPc7VbaOW&stlANnCN8iftFMMrUdYNJ_Bnn5Vt zxfz@Ah|+4&P;reZxp;MmEI7C|FOv8NKUm8njF7Wb6Gi7DeODLl&G~}G4be&*Hi0Qw z5}77vL0P+7-B%UL@3n1&JPxW^d@vVwp?u#gVcJqY9#@-3X{ok#UfW3<1fb%FT`|)V~ggq z(3AUoUS-;7)^hCjdT0Kf{i}h)mBg4qhtHHBti=~h^n^OTH5U*XMgDLIR@sre`AaB$ zg)IGBET_4??m@cx&c~bA80O7B8CHR7(LX7%HThkeC*@vi{-pL%e)yXp!B2InafbDF zjPXf1mko3h59{lT6EEbxKO1Z5GF71)WwowO6kY|6tjSVSWdQ}NsK2x{>i|MKZK8%Q zfu&_0D;CO-Jg0#YmyfctyJ!mRJp)e#@O0mYdp|8x;G1%OZQ3Q847YWTyy|%^cpA;m zze0(5p{tMu^lDkpe?HynyO?a1$_LJl2L&mpeKu%8YvgRNr=%2z${%WThHG=vrWY@4 zsA`OP#O&)TetZ>s%h!=+CE15lOOls&nvC~$Qz0Ph7tHiP;O$i|eDwpT{cp>+)0-|; zY$|bB+Gbel>5aRN3>c0x)4U=|X+z+{ zn*_p*EQoquRL+=+p;=lm`d71&1NqBz&_ph)MXu(Nv6&XE7(RsS)^MGj5Q?Fwude-(sq zjJ>aOq!7!EN>@(fK7EE#;i_BGvli`5U;r!YA{JRodLBc6-`n8K+Fjgwb%sX;j=qHQ z7&Tr!)!{HXoO<2BQrV9Sw?JRaLXV8HrsNevvnf>Y-6|{T!pYLl7jp$-nEE z#X!4G4L#K0qG_4Z;Cj6=;b|Be$hi4JvMH!-voxqx^@8cXp`B??eFBz2lLD8RRaRGh zn7kUfy!YV~p(R|p7iC1Rdgt$_24i0cd-S8HpG|`@my70g^y`gu%#Tf_L21-k?sRRZHK&at(*ED0P8iw{7?R$9~OF$Ko;Iu5)ur5<->x!m93Eb zFYpIx60s=Wxxw=`$aS-O&dCO_9?b1yKiPCQmSQb>T)963`*U+Ydj5kI(B(B?HNP8r z*bfSBpSu)w(Z3j7HQoRjUG(+d=IaE~tv}y14zHHs|0UcN52fT8V_<@2ep_ee{QgZG zmgp8iv4V{k;~8@I%M3<#B;2R>Ef(Gg_cQM7%}0s*^)SK6!Ym+~P^58*wnwV1BW@eG z4sZLqsUvBbFsr#8u7S1r4teQ;t)Y@jnn_m5jS$CsW1um!p&PqAcc8!zyiXHVta9QC zY~wCwCF0U%xiQPD_INKtTb;A|Zf29(mu9NI;E zc-e>*1%(LSXB`g}kd`#}O;veb<(sk~RWL|f3ljxCnEZDdNSTDV6#Td({6l&y4IjKF z^}lIUq*ZUqgTPumD)RrCN{M^jhY>E~1pn|KOZ5((%F)G|*ZQ|r4zIbrEiV%42hJV8 z3xS)=!X1+=olbdGJ=yZil?oXLct8FM{(6ikLL3E%=q#O6(H$p~gQu6T8N!plf!96| z&Q3=`L~>U0zZh;z(pGR2^S^{#PrPxTRHD1RQOON&f)Siaf`GLj#UOk&(|@0?zm;Sx ztsGt8=29-MZs5CSf1l1jNFtNt5rFNZxJPvkNu~2}7*9468TWm>nN9TP&^!;J{-h)_ z7WsHH9|F%I`Pb!>KAS3jQWKfGivTVkMJLO-HUGM_a4UQ_%RgL6WZvrW+Z4ujZn;y@ zz9$=oO!7qVTaQAA^BhX&ZxS*|5dj803M=k&2%QrXda`-Q#IoZL6E(g+tN!6CA!CP* zCpWtCujIea)ENl0liwVfj)Nc<9mV%+e@=d`haoZ*`B7+PNjEbXBkv=B+Pi^~L#EO$D$ZqTiD8f<5$eyb54-(=3 zh)6i8i|jp(@OnRrY5B8t|LFXFQVQ895n*P16cEKTrT*~yLH6Z4e*bZ5otpRDri&+A zfNbK1D5@O=sm`fN=WzWyse!za5n%^+6dHPGX#8DyIK>?9qyX}2XvBWVqbP%%D)7$= z=#$WulZlZR<{m#gU7lwqK4WS1Ne$#_P{b17qe$~UOXCl>5b|6WVh;5vVnR<%d+Lnp z$uEmML38}U4vaW8>shm6CzB(Wei3s#NAWE3)a2)z@i{4jTn;;aQS)O@l{rUM`J@K& l00vQ5JBs~;vo!vr%%-k{2_Fq1Mn4QF81S)AQ99zk{{c4yR+0b! literal 55616 zcmafaW0WS*vSoFbZJS-TZP!<}ZQEV8ZQHihW!tvx>6!c9%-lQoy;&DmfdT@8fB*sl68LLCKtKQ283+jS?^Q-bNq|NIAW8=eB==8_)^)r*{C^$z z{u;{v?IMYnO`JhmPq7|LA_@Iz75S9h~8`iX>QrjrmMeu{>hn4U;+$dor zz+`T8Q0f}p^Ao)LsYq74!W*)&dTnv}E8;7H*Zetclpo2zf_f>9>HT8;`O^F8;M%l@ z57Z8dk34kG-~Wg7n48qF2xwPp;SOUpd1}9Moir5$VSyf4gF)Mp-?`wO3;2x9gYj59oFwG>?Leva43@e(z{mjm0b*@OAYLC`O9q|s+FQLOE z!+*Y;%_0(6Sr<(cxE0c=lS&-FGBFGWd_R<5$vwHRJG=tB&Mi8@hq_U7@IMyVyKkOo6wgR(<% zQw1O!nnQl3T9QJ)Vh=(`cZM{nsEKChjbJhx@UQH+G>6p z;beBQ1L!3Zl>^&*?cSZjy$B3(1=Zyn~>@`!j%5v7IBRt6X`O)yDpVLS^9EqmHxBcisVG$TRwiip#ViN|4( zYn!Av841_Z@Ys=T7w#>RT&iXvNgDq3*d?$N(SznG^wR`x{%w<6^qj&|g})La;iD?`M=p>99p><39r9+e z`dNhQ&tol5)P#;x8{tT47i*blMHaDKqJs8!Pi*F{#)9%USFxTVMfMOy{mp2ZrLR40 z2a9?TJgFyqgx~|j0eA6SegKVk@|Pd|_6P$HvwTrLTK)Re`~%kg8o9`EAE1oAiY5Jgo=H}0*D?tSCn^=SIN~fvv453Ia(<1|s07aTVVtsRxY6+tT3589iQdi^ zC92D$ewm9O6FA*u*{Fe_=b`%q`pmFvAz@hfF@OC_${IPmD#QMpPNo0mE9U=Ch;k0L zZteokPG-h7PUeRCPPYG%H!WswC?cp7M|w42pbtwj!m_&4%hB6MdLQe&}@5-h~! zkOt;w0BbDc0H!RBw;1UeVckHpJ@^|j%FBZlC} zsm?nFOT$`F_i#1_gh4|n$rDe>0md6HvA=B%hlX*3Z%y@a&W>Rq`Fe(8smIgxTGb#8 zZ`->%h!?QCk>v*~{!qp=w?a*};Y**1uH`)OX`Gi+L%-d6{rV?@}MU#qfCU(!hLz;kWH=0A%W7E^pA zD;A%Jg5SsRe!O*0TyYkAHe&O9z*Ij-YA$%-rR?sc`xz_v{>x%xY39!8g#!Z0#03H( z{O=drKfb0cbx1F*5%q81xvTDy#rfUGw(fesh1!xiS2XT;7_wBi(Rh4i(!rR^9=C+- z+**b9;icxfq@<7}Y!PW-0rTW+A^$o*#ZKenSkxLB$Qi$%gJSL>x!jc86`GmGGhai9 zOHq~hxh}KqQHJeN$2U{M>qd*t8_e&lyCs69{bm1?KGTYoj=c0`rTg>pS6G&J4&)xp zLEGIHSTEjC0-s-@+e6o&w=h1sEWWvJUvezID1&exb$)ahF9`(6`?3KLyVL$|c)CjS zx(bsy87~n8TQNOKle(BM^>1I!2-CZ^{x6zdA}qeDBIdrfd-(n@Vjl^9zO1(%2pP9@ zKBc~ozr$+4ZfjmzEIzoth(k?pbI87=d5OfjVZ`Bn)J|urr8yJq`ol^>_VAl^P)>2r)s+*3z5d<3rP+-fniCkjmk=2hTYRa@t zCQcSxF&w%mHmA?!vaXnj7ZA$)te}ds+n8$2lH{NeD4mwk$>xZCBFhRy$8PE>q$wS`}8pI%45Y;Mg;HH+}Dp=PL)m77nKF68FggQ-l3iXlVZuM2BDrR8AQbK;bn1%jzahl0; zqz0(mNe;f~h8(fPzPKKf2qRsG8`+Ca)>|<&lw>KEqM&Lpnvig>69%YQpK6fx=8YFj zHKrfzy>(7h2OhUVasdwKY`praH?>qU0326-kiSyOU_Qh>ytIs^htlBA62xU6xg?*l z)&REdn*f9U3?u4$j-@ndD#D3l!viAUtw}i5*Vgd0Y6`^hHF5R=No7j8G-*$NWl%?t z`7Nilf_Yre@Oe}QT3z+jOUVgYtT_Ym3PS5(D>kDLLas8~F+5kW%~ZYppSrf1C$gL* zCVy}fWpZ3s%2rPL-E63^tA|8OdqKsZ4TH5fny47ENs1#^C`_NLg~H^uf3&bAj#fGV zDe&#Ot%_Vhj$}yBrC3J1Xqj>Y%&k{B?lhxKrtYy;^E9DkyNHk5#6`4cuP&V7S8ce9 zTUF5PQIRO7TT4P2a*4;M&hk;Q7&{(83hJe5BSm=9qt~;U)NTf=4uKUcnxC`;iPJeI zW#~w?HIOM+0j3ptB0{UU{^6_#B*Q2gs;1x^YFey(%DJHNWz@e_NEL?$fv?CDxG`jk zH|52WFdVsZR;n!Up;K;4E$|w4h>ZIN+@Z}EwFXI{w_`?5x+SJFY_e4J@|f8U08%dd z#Qsa9JLdO$jv)?4F@&z_^{Q($tG`?|9bzt8ZfH9P`epY`soPYqi1`oC3x&|@m{hc6 zs0R!t$g>sR@#SPfNV6Pf`a^E?q3QIaY30IO%yKjx#Njj@gro1YH2Q(0+7D7mM~c>C zk&_?9Ye>B%*MA+77$Pa!?G~5tm`=p{NaZsUsOgm6Yzclr_P^2)r(7r%n(0?4B#$e7 z!fP;+l)$)0kPbMk#WOjm07+e?{E)(v)2|Ijo{o1+Z8#8ET#=kcT*OwM#K68fSNo%< zvZFdHrOrr;>`zq!_welWh!X}=oN5+V01WJn7=;z5uo6l_$7wSNkXuh=8Y>`TjDbO< z!yF}c42&QWYXl}XaRr0uL?BNPXlGw=QpDUMo`v8pXzzG(=!G;t+mfCsg8 zJb9v&a)E!zg8|%9#U?SJqW!|oBHMsOu}U2Uwq8}RnWeUBJ>FtHKAhP~;&T4mn(9pB zu9jPnnnH0`8ywm-4OWV91y1GY$!qiQCOB04DzfDDFlNy}S{$Vg9o^AY!XHMueN<{y zYPo$cJZ6f7``tmlR5h8WUGm;G*i}ff!h`}L#ypFyV7iuca!J+C-4m@7*Pmj9>m+jh zlpWbud)8j9zvQ`8-oQF#u=4!uK4kMFh>qS_pZciyq3NC(dQ{577lr-!+HD*QO_zB9 z_Rv<#qB{AAEF8Gbr7xQly%nMA%oR`a-i7nJw95F3iH&IX5hhy3CCV5y>mK4)&5aC*12 zI`{(g%MHq<(ocY5+@OK-Qn-$%!Nl%AGCgHl>e8ogTgepIKOf3)WoaOkuRJQt%MN8W z=N-kW+FLw=1^}yN@*-_c>;0N{-B!aXy#O}`%_~Nk?{e|O=JmU8@+92Q-Y6h)>@omP=9i~ zi`krLQK^!=@2BH?-R83DyFkejZkhHJqV%^} zUa&K22zwz7b*@CQV6BQ9X*RB177VCVa{Z!Lf?*c~PwS~V3K{id1TB^WZh=aMqiws5)qWylK#^SG9!tqg3-)p_o(ABJsC!0;0v36;0tC= z!zMQ_@se(*`KkTxJ~$nIx$7ez&_2EI+{4=uI~dwKD$deb5?mwLJ~ema_0Z z6A8Q$1~=tY&l5_EBZ?nAvn$3hIExWo_ZH2R)tYPjxTH5mAw#3n-*sOMVjpUrdnj1DBm4G!J+Ke}a|oQN9f?!p-TcYej+(6FNh_A? zJ3C%AOjc<8%9SPJ)U(md`W5_pzYpLEMwK<_jgeg-VXSX1Nk1oX-{yHz z-;CW!^2ds%PH{L{#12WonyeK5A=`O@s0Uc%s!@22etgSZW!K<%0(FHC+5(BxsXW@e zAvMWiO~XSkmcz%-@s{|F76uFaBJ8L5H>nq6QM-8FsX08ug_=E)r#DC>d_!6Nr+rXe zzUt30Du_d0oSfX~u>qOVR*BmrPBwL@WhF^5+dHjWRB;kB$`m8|46efLBXLkiF|*W= zg|Hd(W}ZnlJLotYZCYKoL7YsQdLXZ!F`rLqLf8n$OZOyAzK`uKcbC-n0qoH!5-rh&k-`VADETKHxrhK<5C zhF0BB4azs%j~_q_HA#fYPO0r;YTlaa-eb)Le+!IeP>4S{b8&STp|Y0if*`-A&DQ$^ z-%=i73HvEMf_V6zSEF?G>G-Eqn+|k`0=q?(^|ZcqWsuLlMF2!E*8dDAx%)}y=lyMa z$Nn0_f8YN8g<4D>8IL3)GPf#dJYU@|NZqIX$;Lco?Qj=?W6J;D@pa`T=Yh z-ybpFyFr*3^gRt!9NnbSJWs2R-S?Y4+s~J8vfrPd_&_*)HBQ{&rW(2X>P-_CZU8Y9 z-32><7|wL*K+3{ZXE5}nn~t@NNT#Bc0F6kKI4pVwLrpU@C#T-&f{Vm}0h1N3#89@d zgcx3QyS;Pb?V*XAq;3(W&rjLBazm69XX;%^n6r}0!CR2zTU1!x#TypCr`yrII%wk8 z+g)fyQ!&xIX(*>?T}HYL^>wGC2E}euj{DD_RYKK@w=yF+44367X17)GP8DCmBK!xS zE{WRfQ(WB-v>DAr!{F2-cQKHIjIUnLk^D}7XcTI#HyjSiEX)BO^GBI9NjxojYfQza zWsX@GkLc7EqtP8(UM^cq5zP~{?j~*2T^Bb={@PV)DTkrP<9&hxDwN2@hEq~8(ZiF! z3FuQH_iHyQ_s-#EmAC5~K$j_$cw{+!T>dm#8`t%CYA+->rWp09jvXY`AJQ-l%C{SJ z1c~@<5*7$`1%b}n7ivSo(1(j8k+*Gek(m^rQ!+LPvb=xA@co<|(XDK+(tb46xJ4) zcw7w<0p3=Idb_FjQ@ttoyDmF?cT4JRGrX5xl&|ViA@Lg!vRR}p#$A?0=Qe+1)Mizl zn;!zhm`B&9t0GA67GF09t_ceE(bGdJ0mbXYrUoV2iuc3c69e;!%)xNOGG*?x*@5k( zh)snvm0s&gRq^{yyeE)>hk~w8)nTN`8HJRtY0~1f`f9ue%RV4~V(K*B;jFfJY4dBb z*BGFK`9M-tpWzayiD>p_`U(29f$R|V-qEB;+_4T939BPb=XRw~8n2cGiRi`o$2qm~ zN&5N7JU{L*QGM@lO8VI)fUA0D7bPrhV(GjJ$+@=dcE5vAVyCy6r&R#4D=GyoEVOnu z8``8q`PN-pEy>xiA_@+EN?EJpY<#}BhrsUJC0afQFx7-pBeLXR9Mr+#w@!wSNR7vxHy@r`!9MFecB4O zh9jye3iSzL0@t3)OZ=OxFjjyK#KSF|zz@K}-+HaY6gW+O{T6%Zky@gD$6SW)Jq;V0 zt&LAG*YFO^+=ULohZZW*=3>7YgND-!$2}2)Mt~c>JO3j6QiPC-*ayH2xBF)2m7+}# z`@m#q{J9r~Dr^eBgrF(l^#sOjlVNFgDs5NR*Xp;V*wr~HqBx7?qBUZ8w)%vIbhhe) zt4(#1S~c$Cq7b_A%wpuah1Qn(X9#obljoY)VUoK%OiQZ#Fa|@ZvGD0_oxR=vz{>U* znC(W7HaUDTc5F!T77GswL-jj7e0#83DH2+lS-T@_^SaWfROz9btt*5zDGck${}*njAwf}3hLqKGLTeV&5(8FC+IP>s;p{L@a~RyCu)MIa zs~vA?_JQ1^2Xc&^cjDq02tT_Z0gkElR0Aa$v@VHi+5*)1(@&}gEXxP5Xon?lxE@is z9sxd|h#w2&P5uHJxWgmtVZJv5w>cl2ALzri;r57qg){6`urTu(2}EI?D?##g=!Sbh z*L*>c9xN1a3CH$u7C~u_!g81`W|xp=54oZl9CM)&V9~ATCC-Q!yfKD@vp#2EKh0(S zgt~aJ^oq-TM0IBol!w1S2j7tJ8H7;SR7yn4-H}iz&U^*zW95HrHiT!H&E|rSlnCYr z7Y1|V7xebn=TFbkH;>WIH6H>8;0?HS#b6lCke9rSsH%3AM1#2U-^*NVhXEIDSFtE^ z=jOo1>j!c__Bub(R*dHyGa)@3h?!ls1&M)d2{?W5#1|M@6|ENYYa`X=2EA_oJUw=I zjQ)K6;C!@>^i7vdf`pBOjH>Ts$97}B=lkb07<&;&?f#cy3I0p5{1=?O*#8m$C_5TE zh}&8lOWWF7I@|pRC$G2;Sm#IJfhKW@^jk=jfM1MdJP(v2fIrYTc{;e5;5gsp`}X8-!{9{S1{h+)<@?+D13s^B zq9(1Pu(Dfl#&z|~qJGuGSWDT&u{sq|huEsbJhiqMUae}K*g+R(vG7P$p6g}w*eYWn zQ7luPl1@{vX?PMK%-IBt+N7TMn~GB z!Ldy^(2Mp{fw_0;<$dgHAv1gZgyJAx%}dA?jR=NPW1K`FkoY zNDgag#YWI6-a2#&_E9NMIE~gQ+*)i<>0c)dSRUMHpg!+AL;a;^u|M1jp#0b<+#14z z+#LuQ1jCyV_GNj#lHWG3e9P@H34~n0VgP#(SBX=v|RSuOiY>L87 z#KA{JDDj2EOBX^{`a;xQxHtY1?q5^B5?up1akjEPhi1-KUsK|J9XEBAbt%^F`t0I- zjRYYKI4OB7Zq3FqJFBZwbI=RuT~J|4tA8x)(v2yB^^+TYYJS>Et`_&yge##PuQ%0I z^|X!Vtof}`UuIxPjoH8kofw4u1pT5h`Ip}d8;l>WcG^qTe>@x63s#zoJiGmDM@_h= zo;8IZR`@AJRLnBNtatipUvL^(1P_a;q8P%&voqy#R!0(bNBTlV&*W9QU?kRV1B*~I zWvI?SNo2cB<7bgVY{F_CF$7z!02Qxfw-Ew#p!8PC#! z1sRfOl`d-Y@&=)l(Sl4CS=>fVvor5lYm61C!!iF3NMocKQHUYr0%QM}a4v2>rzPfM zUO}YRDb7-NEqW+p_;e0{Zi%0C$&B3CKx6|4BW`@`AwsxE?Vu}@Jm<3%T5O&05z+Yq zkK!QF(vlN}Rm}m_J+*W4`8i~R&`P0&5!;^@S#>7qkfb9wxFv@(wN@$k%2*sEwen$a zQnWymf+#Uyv)0lQVd?L1gpS}jMQZ(NHHCKRyu zjK|Zai0|N_)5iv)67(zDBCK4Ktm#ygP|0(m5tU`*AzR&{TSeSY8W=v5^=Ic`ahxM-LBWO+uoL~wxZmgcSJMUF9q%<%>jsvh9Dnp^_e>J_V=ySx4p?SF0Y zg4ZpZt@!h>WR76~P3_YchYOak7oOzR|`t+h!BbN}?zd zq+vMTt0!duALNWDwWVIA$O=%{lWJEj;5(QD()huhFL5=6x_=1h|5ESMW&S|*oxgF# z-0GRIb ziolwI13hJ-Rl(4Rj@*^=&Zz3vD$RX8bFWvBM{niz(%?z0gWNh_vUvpBDoa>-N=P4c zbw-XEJ@txIbc<`wC883;&yE4ayVh>+N($SJ01m}fumz!#!aOg*;y4Hl{V{b;&ux3& zBEmSq2jQ7#IbVm3TPBw?2vVN z0wzj|Y6EBS(V%Pb+@OPkMvEKHW~%DZk#u|A18pZMmCrjWh%7J4Ph>vG61 zRBgJ6w^8dNRg2*=K$Wvh$t>$Q^SMaIX*UpBG)0bqcvY%*by=$EfZAy{ZOA#^tB(D( zh}T(SZgdTj?bG9u+G{Avs5Yr1x=f3k7%K|eJp^>BHK#~dsG<&+=`mM@>kQ-cAJ2k) zT+Ht5liXdc^(aMi9su~{pJUhe)!^U&qn%mV6PS%lye+Iw5F@Xv8E zdR4#?iz+R4--iiHDQmQWfNre=iofAbF~1oGTa1Ce?hId~W^kPuN(5vhNx++ZLkn?l zUA7L~{0x|qA%%%P=8+-Ck{&2$UHn#OQncFS@uUVuE39c9o~#hl)v#!$X(X*4ban2c z{buYr9!`H2;6n73n^W3Vg(!gdBV7$e#v3qubWALaUEAf@`ava{UTx%2~VVQbEE(*Q8_ zv#me9i+0=QnY)$IT+@3vP1l9Wrne+MlZNGO6|zUVG+v&lm7Xw3P*+gS6e#6mVx~(w zyuaXogGTw4!!&P3oZ1|4oc_sGEa&m3Jsqy^lzUdJ^y8RlvUjDmbC^NZ0AmO-c*&m( zSI%4P9f|s!B#073b>Eet`T@J;3qY!NrABuUaED6M^=s-Q^2oZS`jVzuA z>g&g$!Tc>`u-Q9PmKu0SLu-X(tZeZ<%7F+$j3qOOftaoXO5=4!+P!%Cx0rNU+@E~{ zxCclYb~G(Ci%o{}4PC(Bu>TyX9slm5A^2Yi$$kCq-M#Jl)a2W9L-bq5%@Pw^ zh*iuuAz`x6N_rJ1LZ7J^MU9~}RYh+EVIVP+-62u+7IC%1p@;xmmQ`dGCx$QpnIUtK z0`++;Ddz7{_R^~KDh%_yo8WM$IQhcNOALCIGC$3_PtUs?Y44@Osw;OZ()Lk=(H&Vc zXjkHt+^1@M|J%Q&?4>;%T-i%#h|Tb1u;pO5rKst8(Cv2!3U{TRXdm&>fWTJG)n*q&wQPjRzg%pS1RO9}U0*C6fhUi&f#qoV`1{U<&mWKS<$oVFW>{&*$6)r6Rx)F4W zdUL8Mm_qNk6ycFVkI5F?V+cYFUch$92|8O^-Z1JC94GU+Nuk zA#n3Z1q4<6zRiv%W5`NGk*Ym{#0E~IA6*)H-=RmfWIY%mEC0? zSih7uchi`9-WkF2@z1ev6J_N~u;d$QfSNLMgPVpHZoh9oH-8D*;EhoCr~*kJ<|-VD z_jklPveOxWZq40E!SV@0XXy+~Vfn!7nZ1GXsn~U$>#u0d*f?RL9!NMlz^qxYmz|xt zz6A&MUAV#eD%^GcP#@5}QH5e7AV`}(N2#(3xpc!7dDmgu7C3TpgX5Z|$%Vu8=&SQI zdxUk*XS-#C^-cM*O>k}WD5K81e2ayyRA)R&5>KT1QL!T!%@}fw{>BsF+-pzu>;7{g z^CCSWfH;YtJGT@+An0Ded#zM9>UEFOdR_Xq zS~!5R*{p1Whq62ynHo|n$4p7&d|bal{iGsxAY?opi3R${)Zt*8YyOU!$TWMYXF?|i zPXYr}wJp#EH;keSG5WYJ*(~oiu#GDR>C4%-HpIWr7v`W`lzQN-lb?*vpoit z8FqJ)`LC4w8fO8Fu}AYV`awF2NLMS4$f+?=KisU4P6@#+_t)5WDz@f*qE|NG0*hwO z&gv^k^kC6Fg;5>Gr`Q46C{6>3F(p0QukG6NM07rxa&?)_C*eyU(jtli>9Zh#eUb(y zt9NbC-bp0>^m?i`?$aJUyBmF`N0zQ% zvF_;vLVI{tq%Ji%u*8s2p4iBirv*uD(?t~PEz$CfxVa=@R z^HQu6-+I9w>a35kX!P)TfnJDD!)j8!%38(vWNe9vK0{k*`FS$ABZ`rdwfQe@IGDki zssfXnsa6teKXCZUTd^qhhhUZ}>GG_>F0~LG7*<*x;8e39nb-0Bka(l)%+QZ_IVy3q zcmm2uKO0p)9|HGxk*e_$mX2?->&-MXe`=Fz3FRTFfM!$_y}G?{F9jmNgD+L%R`jM1 zIP-kb=3Hlsb35Q&qo(%Ja(LwQj>~!GI|Hgq65J9^A!ibChYB3kxLn@&=#pr}BwON0Q=e5;#sF8GGGuzx6O}z%u3l?jlKF&8Y#lUA)Cs6ZiW8DgOk|q z=YBPAMsO7AoAhWgnSKae2I7%7*Xk>#AyLX-InyBO?OD_^2^nI4#;G|tBvg3C0ldO0 z*`$g(q^es4VqXH2t~0-u^m5cfK8eECh3Rb2h1kW%%^8A!+ya3OHLw$8kHorx4(vJO zAlVu$nC>D{7i?7xDg3116Y2e+)Zb4FPAdZaX}qA!WW{$d?u+sK(iIKqOE-YM zH7y^hkny24==(1;qEacfFU{W{xSXhffC&DJV&oqw`u~WAl@=HIel>KC-mLs2ggFld zsSm-03=Jd^XNDA4i$vKqJ|e|TBc19bglw{)QL${Q(xlN?E;lPumO~;4w_McND6d+R zsc2p*&uRWd`wTDszTcWKiii1mNBrF7n&LQp$2Z<}zkv=8k2s6-^+#siy_K1`5R+n( z++5VOU^LDo(kt3ok?@$3drI`<%+SWcF*`CUWqAJxl3PAq!X|q{al;8%HfgxxM#2Vb zeBS756iU|BzB>bN2NP=AX&!{uZXS;|F`LLd9F^97UTMnNks_t7EPnjZF`2ocD2*u+ z?oKP{xXrD*AKGYGkZtlnvCuazg6g16ZAF{Nu%w+LCZ+v_*`0R$NK)tOh_c#cze;o$ z)kY(eZ5Viv<5zl1XfL(#GO|2FlXL#w3T?hpj3BZ&OAl^L!7@ zy;+iJWYQYP?$(`li_!|bfn!h~k#=v-#XXyjTLd+_txOqZZETqSEp>m+O0ji7MxZ*W zSdq+yqEmafrsLErZG8&;kH2kbCwluSa<@1yU3^Q#5HmW(hYVR0E6!4ZvH;Cr<$`qf zSvqRc`Pq_9b+xrtN3qLmds9;d7HdtlR!2NV$rZPCh6>(7f7M}>C^LeM_5^b$B~mn| z#)?`E=zeo9(9?{O_ko>51~h|c?8{F=2=_-o(-eRc z9p)o51krhCmff^U2oUi#$AG2p-*wSq8DZ(i!Jmu1wzD*)#%J&r)yZTq`3e|v4>EI- z=c|^$Qhv}lEyG@!{G~@}Wbx~vxTxwKoe9zn%5_Z^H$F1?JG_Kadc(G8#|@yaf2-4< zM1bdQF$b5R!W1f`j(S>Id;CHMzfpyjYEC_95VQ*$U3y5piVy=9Rdwg7g&)%#6;U%b2W}_VVdh}qPnM4FY9zFP(5eR zWuCEFox6e;COjs$1RV}IbpE0EV;}5IP}Oq|zcb*77PEDIZU{;@_;8*22{~JRvG~1t zc+ln^I+)Q*+Ha>(@=ra&L&a-kD;l$WEN;YL0q^GE8+})U_A_StHjX_gO{)N>tx4&F zRK?99!6JqktfeS-IsD@74yuq*aFJoV{5&K(W`6Oa2Qy0O5JG>O`zZ-p7vBGh!MxS;}}h6(96Wp`dci3DY?|B@1p8fVsDf$|0S zfE{WL5g3<9&{~yygYyR?jK!>;eZ2L#tpL2)H#89*b zycE?VViXbH7M}m33{#tI69PUPD=r)EVPTBku={Qh{ zKi*pht1jJ+yRhVE)1=Y()iS9j`FesMo$bjLSqPMF-i<42Hxl6%y7{#vw5YT(C}x0? z$rJU7fFmoiR&%b|Y*pG?7O&+Jb#Z%S8&%o~fc?S9c`Dwdnc4BJC7njo7?3bp#Yonz zPC>y`DVK~nzN^n}jB5RhE4N>LzhCZD#WQseohYXvqp5^%Ns!q^B z&8zQN(jgPS(2ty~g2t9!x9;Dao~lYVujG-QEq{vZp<1Nlp;oj#kFVsBnJssU^p-4% zKF_A?5sRmA>d*~^og-I95z$>T*K*33TGBPzs{OMoV2i+(P6K|95UwSj$Zn<@Rt(g%|iY z$SkSjYVJ)I<@S(kMQ6md{HxAa8S`^lXGV?ktLX!ngTVI~%WW+p#A#XTWaFWeBAl%U z&rVhve#Yse*h4BC4nrq7A1n>Rlf^ErbOceJC`o#fyCu@H;y)`E#a#)w)3eg^{Hw&E7);N5*6V+z%olvLj zp^aJ4`h*4L4ij)K+uYvdpil(Z{EO@u{BcMI&}5{ephilI%zCkBhBMCvOQT#zp|!18 zuNl=idd81|{FpGkt%ty=$fnZnWXxem!t4x{ zat@68CPmac(xYaOIeF}@O1j8O?2jbR!KkMSuix;L8x?m01}|bS2=&gsjg^t2O|+0{ zlzfu5r5_l4)py8uPb5~NHPG>!lYVynw;;T-gk1Pl6PQ39Mwgd2O+iHDB397H)2grN zHwbd>8i%GY>Pfy7;y5X7AN>qGLZVH>N_ZuJZ-`z9UA> zfyb$nbmPqxyF2F;UW}7`Cu>SS%0W6h^Wq5e{PWAjxlh=#Fq+6SiPa-L*551SZKX&w zc9TkPv4eao?kqomkZ#X%tA{`UIvf|_=Y7p~mHZKqO>i_;q4PrwVtUDTk?M7NCssa?Y4uxYrsXj!+k@`Cxl;&{NLs*6!R<6k9$Bq z%grLhxJ#G_j~ytJpiND8neLfvD0+xu>wa$-%5v;4;RYYM66PUab)c9ruUm%d{^s{# zTBBY??@^foRv9H}iEf{w_J%rV<%T1wv^`)Jm#snLTIifjgRkX``x2wV(D6(=VTLL4 zI-o}&5WuwBl~(XSLIn5~{cGWorl#z+=(vXuBXC#lp}SdW=_)~8Z(Vv!#3h2@pdA3d z{cIPYK@Ojc9(ph=H3T7;aY>(S3~iuIn05Puh^32WObj%hVN(Y{Ty?n?Cm#!kGNZFa zW6Ybz!tq|@erhtMo4xAus|H8V_c+XfE5mu|lYe|{$V3mKnb1~fqoFim;&_ZHN_=?t zysQwC4qO}rTi}k8_f=R&i27RdBB)@bTeV9Wcd}Rysvod}7I%ujwYbTI*cN7Kbp_hO z=eU521!#cx$0O@k9b$;pnCTRtLIzv){nVW6Ux1<0@te6`S5%Ew3{Z^9=lbL5$NFvd4eUtK?%zgmB;_I&p`)YtpN`2Im(?jPN<(7Ua_ZWJRF(CChv`(gHfWodK%+joy>8Vaa;H1w zIJ?!kA|x7V;4U1BNr(UrhfvjPii7YENLIm`LtnL9Sx z5E9TYaILoB2nSwDe|BVmrpLT43*dJ8;T@1l zJE)4LEzIE{IN}+Nvpo3=ZtV!U#D;rB@9OXYw^4QH+(52&pQEcZq&~u9bTg63ikW9! z=!_RjN2xO=F+bk>fSPhsjQA;)%M1My#34T`I7tUf>Q_L>DRa=>Eo(sapm>}}LUsN% zVw!C~a)xcca`G#g*Xqo>_uCJTz>LoWGSKOwp-tv`yvfqw{17t`9Z}U4o+q2JGP^&9 z(m}|d13XhYSnEm$_8vH-Lq$A^>oWUz1)bnv|AVn_0FwM$vYu&8+qUg$+qP}nwrykD zwmIF?wr$()X@33oz1@B9zi+?Th^nZnsES)rb@O*K^JL~ZH|pRRk$i0+ohh?Il)y&~ zQaq{}9YxPt5~_2|+r#{k#~SUhO6yFq)uBGtYMMg4h1qddg!`TGHocYROyNFJtYjNe z3oezNpq6%TP5V1g(?^5DMeKV|i6vdBq)aGJ)BRv;K(EL0_q7$h@s?BV$)w31*c(jd z{@hDGl3QdXxS=#?0y3KmPd4JL(q(>0ikTk6nt98ptq$6_M|qrPi)N>HY>wKFbnCKY z%0`~`9p)MDESQJ#A`_>@iL7qOCmCJ(p^>f+zqaMuDRk!z01Nd2A_W^D%~M73jTqC* zKu8u$$r({vP~TE8rPk?8RSjlRvG*BLF}ye~Su%s~rivmjg2F z24dhh6-1EQF(c>Z1E8DWY)Jw#9U#wR<@6J)3hjA&2qN$X%piJ4s={|>d-|Gzl~RNu z##iR(m;9TN3|zh+>HgTI&82iR>$YVoOq$a(2%l*2mNP(AsV=lR^>=tIP-R9Tw!BYnZROx`PN*JiNH>8bG}&@h0_v$yOTk#@1;Mh;-={ZU7e@JE(~@@y0AuETvsqQV@7hbKe2wiWk@QvV=Kz`%@$rN z_0Hadkl?7oEdp5eaaMqBm;#Xj^`fxNO^GQ9S3|Fb#%{lN;1b`~yxLGEcy8~!cz{!! z=7tS!I)Qq%w(t9sTSMWNhoV#f=l5+a{a=}--?S!rA0w}QF!_Eq>V4NbmYKV&^OndM z4WiLbqeC5+P@g_!_rs01AY6HwF7)$~%Ok^(NPD9I@fn5I?f$(rcOQjP+z?_|V0DiN zb}l0fy*el9E3Q7fVRKw$EIlb&T0fG~fDJZL7Qn8*a5{)vUblM)*)NTLf1ll$ zpQ^(0pkSTol`|t~`Y4wzl;%NRn>689mpQrW=SJ*rB;7}w zVHB?&sVa2%-q@ANA~v)FXb`?Nz8M1rHKiZB4xC9<{Q3T!XaS#fEk=sXI4IFMnlRqG+yaFw< zF{}7tcMjV04!-_FFD8(FtuOZx+|CjF@-xl6-{qSFF!r7L3yD()=*Ss6fT?lDhy(h$ zt#%F575$U(3-e2LsJd>ksuUZZ%=c}2dWvu8f!V%>z3gajZ!Dlk zm=0|(wKY`c?r$|pX6XVo6padb9{EH}px)jIsdHoqG^(XH(7}r^bRa8BC(%M+wtcB? z6G2%tui|Tx6C3*#RFgNZi9emm*v~txI}~xV4C`Ns)qEoczZ>j*r zqQCa5k90Gntl?EX!{iWh=1t$~jVoXjs&*jKu0Ay`^k)hC^v_y0xU~brMZ6PPcmt5$ z@_h`f#qnI$6BD(`#IR0PrITIV^~O{uo=)+Bi$oHA$G* zH0a^PRoeYD3jU_k%!rTFh)v#@cq`P3_y=6D(M~GBud;4 zCk$LuxPgJ5=8OEDlnU!R^4QDM4jGni}~C zy;t2E%Qy;A^bz_5HSb5pq{x{g59U!ReE?6ULOw58DJcJy;H?g*ofr(X7+8wF;*3{rx>j&27Syl6A~{|w{pHb zeFgu0E>OC81~6a9(2F13r7NZDGdQxR8T68&t`-BK zE>ZV0*0Ba9HkF_(AwfAds-r=|dA&p`G&B_zn5f9Zfrz9n#Rvso`x%u~SwE4SzYj!G zVQ0@jrLwbYP=awX$21Aq!I%M{x?|C`narFWhp4n;=>Sj!0_J!k7|A0;N4!+z%Oqlk z1>l=MHhw3bi1vT}1!}zR=6JOIYSm==qEN#7_fVsht?7SFCj=*2+Ro}B4}HR=D%%)F z?eHy=I#Qx(vvx)@Fc3?MT_@D))w@oOCRR5zRw7614#?(-nC?RH`r(bb{Zzn+VV0bm zJ93!(bfrDH;^p=IZkCH73f*GR8nDKoBo|!}($3^s*hV$c45Zu>6QCV(JhBW=3(Tpf z=4PT6@|s1Uz+U=zJXil3K(N6;ePhAJhCIo`%XDJYW@x#7Za);~`ANTvi$N4(Fy!K- z?CQ3KeEK64F0@ykv$-0oWCWhYI-5ZC1pDqui@B|+LVJmU`WJ=&C|{I_))TlREOc4* zSd%N=pJ_5$G5d^3XK+yj2UZasg2) zXMLtMp<5XWWfh-o@ywb*nCnGdK{&S{YI54Wh2|h}yZ})+NCM;~i9H@1GMCgYf`d5n zwOR(*EEkE4-V#R2+Rc>@cAEho+GAS2L!tzisLl${42Y=A7v}h;#@71_Gh2MV=hPr0_a% z0!={Fcv5^GwuEU^5rD|sP;+y<%5o9;#m>ssbtVR2g<420(I-@fSqfBVMv z?`>61-^q;M(b3r2z{=QxSjyH=-%99fpvb}8z}d;%_8$$J$qJg1Sp3KzlO_!nCn|g8 zzg8skdHNsfgkf8A7PWs;YBz_S$S%!hWQ@G>guCgS--P!!Ui9#%GQ#Jh?s!U-4)7ozR?i>JXHU$| zg0^vuti{!=N|kWorZNFX`dJgdphgic#(8sOBHQdBkY}Qzp3V%T{DFb{nGPgS;QwnH9B9;-Xhy{? z(QVwtzkn9I)vHEmjY!T3ifk1l5B?%%TgP#;CqG-?16lTz;S_mHOzu#MY0w}XuF{lk z*dt`2?&plYn(B>FFXo+fd&CS3q^hquSLVEn6TMAZ6e*WC{Q2e&U7l|)*W;^4l~|Q= zt+yFlLVqPz!I40}NHv zE2t1meCuGH%<`5iJ(~8ji#VD{?uhP%F(TnG#uRZW-V}1=N%ev&+Gd4v!0(f`2Ar-Y z)GO6eYj7S{T_vxV?5^%l6TF{ygS_9e2DXT>9caP~xq*~oE<5KkngGtsv)sdCC zaQH#kSL%c*gLj6tV)zE6SGq|0iX*DPV|I`byc9kn_tNQkPU%y<`rj zMC}lD<93=Oj+D6Y2GNMZb|m$^)RVdi`&0*}mxNy0BW#0iq!GGN2BGx5I0LS>I|4op z(6^xWULBr=QRpbxIJDK~?h;K#>LwQI4N<8V?%3>9I5l+e*yG zFOZTIM0c3(q?y9f7qDHKX|%zsUF%2zN9jDa7%AK*qrI5@z~IruFP+IJy7!s~TE%V3 z_PSSxXlr!FU|Za>G_JL>DD3KVZ7u&}6VWbwWmSg?5;MabycEB)JT(eK8wg`^wvw!Q zH5h24_E$2cuib&9>Ue&@%Cly}6YZN-oO_ei5#33VvqV%L*~ZehqMe;)m;$9)$HBsM zfJ96Hk8GJyWwQ0$iiGjwhxGgQX$sN8ij%XJzW`pxqgwW=79hgMOMnC|0Q@ed%Y~=_ z?OnjUB|5rS+R$Q-p)vvM(eFS+Qr{_w$?#Y;0Iknw3u(+wA=2?gPyl~NyYa3me{-Su zhH#8;01jEm%r#5g5oy-f&F>VA5TE_9=a0aO4!|gJpu470WIrfGo~v}HkF91m6qEG2 zK4j=7C?wWUMG$kYbIp^+@)<#ArZ$3k^EQxraLk0qav9TynuE7T79%MsBxl3|nRn?L zD&8kt6*RJB6*a7=5c57wp!pg)p6O?WHQarI{o9@3a32zQ3FH8cK@P!DZ?CPN_LtmC6U4F zlv8T2?sau&+(i@EL6+tvP^&=|aq3@QgL4 zOu6S3wSWeYtgCnKqg*H4ifIQlR4hd^n{F+3>h3;u_q~qw-Sh;4dYtp^VYymX12$`? z;V2_NiRt82RC=yC+aG?=t&a81!gso$hQUb)LM2D4Z{)S zI1S9f020mSm(Dn$&Rlj0UX}H@ zv={G+fFC>Sad0~8yB%62V(NB4Z|b%6%Co8j!>D(VyAvjFBP%gB+`b*&KnJ zU8s}&F+?iFKE(AT913mq;57|)q?ZrA&8YD3Hw*$yhkm;p5G6PNiO3VdFlnH-&U#JH zEX+y>hB(4$R<6k|pt0?$?8l@zeWk&1Y5tlbgs3540F>A@@rfvY;KdnVncEh@N6Mfi zY)8tFRY~Z?Qw!{@{sE~vQy)0&fKsJpj?yR`Yj+H5SDO1PBId3~d!yjh>FcI#Ug|^M z7-%>aeyQhL8Zmj1!O0D7A2pZE-$>+-6m<#`QX8(n)Fg>}l404xFmPR~at%$(h$hYD zoTzbxo`O{S{E}s8Mv6WviXMP}(YPZoL11xfd>bggPx;#&pFd;*#Yx%TtN1cp)MuHf z+Z*5CG_AFPwk624V9@&aL0;=@Ql=2h6aJoqWx|hPQQzdF{e7|fe(m){0==hk_!$ou zI|p_?kzdO9&d^GBS1u+$>JE-6Ov*o{mu@MF-?$r9V>i%;>>Fo~U`ac2hD*X}-gx*v z1&;@ey`rA0qNcD9-5;3_K&jg|qvn@m^+t?8(GTF0l#|({Zwp^5Ywik@bW9mN+5`MU zJ#_Ju|jtsq{tv)xA zY$5SnHgHj}c%qlQG72VS_(OSv;H~1GLUAegygT3T-J{<#h}))pk$FjfRQ+Kr%`2ZiI)@$96Nivh82#K@t>ze^H?R8wHii6Pxy z0o#T(lh=V>ZD6EXf0U}sG~nQ1dFI`bx;vivBkYSVkxXn?yx1aGxbUiNBawMGad;6? zm{zp?xqAoogt=I2H0g@826=7z^DmTTLB11byYvAO;ir|O0xmNN3Ec0w%yHO({-%q(go%?_X{LP?=E1uXoQgrEGOfL1?~ zI%uPHC23dn-RC@UPs;mxq6cFr{UrgG@e3ONEL^SoxFm%kE^LBhe_D6+Ia+u0J=)BC zf8FB!0J$dYg33jb2SxfmkB|8qeN&De!%r5|@H@GiqReK(YEpnXC;-v~*o<#JmYuze zW}p-K=9?0=*fZyYTE7A}?QR6}m_vMPK!r~y*6%My)d;x4R?-=~MMLC_02KejX9q6= z4sUB4AD0+H4ulSYz4;6mL8uaD07eXFvpy*i5X@dmx--+9`ur@rcJ5<L#s%nq3MRi4Dpr;#28}dl36M{MkVs4+Fm3Pjo5qSV)h}i(2^$Ty|<7N z>*LiBzFKH30D!$@n^3B@HYI_V1?yM(G$2Ml{oZ}?frfPU+{i|dHQOP^M0N2#NN_$+ zs*E=MXUOd=$Z2F4jSA^XIW=?KN=w6{_vJ4f(ZYhLxvFtPozPJv9k%7+z!Zj+_0|HC zMU0(8`8c`Sa=%e$|Mu2+CT22Ifbac@7Vn*he`|6Bl81j`44IRcTu8aw_Y%;I$Hnyd zdWz~I!tkWuGZx4Yjof(?jM;exFlUsrj5qO=@2F;56&^gM9D^ZUQ!6TMMUw19zslEu zwB^^D&nG96Y+Qwbvgk?Zmkn9%d{+V;DGKmBE(yBWX6H#wbaAm&O1U^ zS4YS7j2!1LDC6|>cfdQa`}_^satOz6vc$BfFIG07LoU^IhVMS_u+N=|QCJao0{F>p z-^UkM)ODJW9#9*o;?LPCRV1y~k9B`&U)jbTdvuxG&2%!n_Z&udT=0mb@e;tZ$_l3bj6d0K2;Ya!&)q`A${SmdG_*4WfjubB)Mn+vaLV+)L5$yD zYSTGxpVok&fJDG9iS8#oMN{vQneO|W{Y_xL2Hhb%YhQJgq7j~X7?bcA|B||C?R=Eo z!z;=sSeKiw4mM$Qm>|aIP3nw36Tbh6Eml?hL#&PlR5xf9^vQGN6J8op1dpLfwFg}p zlqYx$610Zf?=vCbB_^~~(e4IMic7C}X(L6~AjDp^;|=d$`=!gd%iwCi5E9<6Y~z0! zX8p$qprEadiMgq>gZ_V~n$d~YUqqqsL#BE6t9ufXIUrs@DCTfGg^-Yh5Ms(wD1xAf zTX8g52V!jr9TlWLl+whcUDv?Rc~JmYs3haeG*UnV;4bI=;__i?OSk)bF3=c9;qTdP zeW1exJwD+;Q3yAw9j_42Zj9nuvs%qGF=6I@($2Ue(a9QGRMZTd4ZAlxbT5W~7(alP1u<^YY!c3B7QV z@jm$vn34XnA6Gh1I)NBgTmgmR=O1PKp#dT*mYDPRZ=}~X3B8}H*e_;;BHlr$FO}Eq zJ9oWk0y#h;N1~ho724x~d)A4Z-{V%F6#e5?Z^(`GGC}sYp5%DKnnB+i-NWxwL-CuF+^JWNl`t@VbXZ{K3#aIX+h9-{T*+t(b0BM&MymW9AA*{p^&-9 zWpWQ?*z(Yw!y%AoeoYS|E!(3IlLksr@?Z9Hqlig?Q4|cGe;0rg#FC}tXTmTNfpE}; z$sfUYEG@hLHUb$(K{A{R%~%6MQN|Bu949`f#H6YC*E(p3lBBKcx z-~Bsd6^QsKzB0)$FteBf*b3i7CN4hccSa-&lfQz4qHm>eC|_X!_E#?=`M(bZ{$cvU zZpMbr|4omp`s9mrgz@>4=Fk3~8Y7q$G{T@?oE0<(I91_t+U}xYlT{c&6}zPAE8ikT z3DP!l#>}i!A(eGT+@;fWdK#(~CTkwjs?*i4SJVBuNB2$6!bCRmcm6AnpHHvnN8G<| zuh4YCYC%5}Zo;BO1>L0hQ8p>}tRVx~O89!${_NXhT!HUoGj0}bLvL2)qRNt|g*q~B z7U&U7E+8Ixy1U`QT^&W@ZSRN|`_Ko$-Mk^^c%`YzhF(KY9l5))1jSyz$&>mWJHZzHt0Jje%BQFxEV}C00{|qo5_Hz7c!FlJ|T(JD^0*yjkDm zL}4S%JU(mBV|3G2jVWU>DX413;d+h0C3{g3v|U8cUj`tZL37Sf@1d*jpwt4^B)`bK zZdlwnPB6jfc7rIKsldW81$C$a9BukX%=V}yPnaBz|i6(h>S)+Bn44@i8RtBZf0XetH&kAb?iAL zD%Ge{>Jo3sy2hgrD?15PM}X_)(6$LV`&t*D`IP)m}bzM)+x-xRJ zavhA)>hu2cD;LUTvN38FEtB94ee|~lIvk~3MBPzmTsN|7V}Kzi!h&za#NyY zX^0BnB+lfBuW!oR#8G&S#Er2bCVtA@5FI`Q+a-e?G)LhzW_chWN-ZQmjtR

eWu-UOPu^G}|k=o=;ffg>8|Z*qev7qS&oqA7%Z{4Ezb!t$f3& z^NuT8CSNp`VHScyikB1YO{BgaBVJR&>dNIEEBwYkfOkWN;(I8CJ|vIfD}STN z{097)R9iC@6($s$#dsb*4BXBx7 zb{6S2O}QUk>upEfij9C2tjqWy7%%V@Xfpe)vo6}PG+hmuY1Tc}peynUJLLmm)8pshG zb}HWl^|sOPtYk)CD-7{L+l(=F zOp}fX8)|n{JDa&9uI!*@jh^^9qP&SbZ(xxDhR)y|bjnn|K3MeR3gl6xcvh9uqzb#K zYkVjnK$;lUky~??mcqN-)d5~mk{wXhrf^<)!Jjqc zG~hX0P_@KvOKwV=X9H&KR3GnP3U)DfqafBt$e10}iuVRFBXx@uBQ)sn0J%%c<;R+! zQz;ETTVa+ma>+VF%U43w?_F6s0=x@N2(oisjA7LUOM<$|6iE|$WcO67W|KY8JUV_# zg7P9K3Yo-c*;EmbsqT!M4(WT`%9uk+s9Em-yB0bE{B%F4X<8fT!%4??vezaJ(wJhj zfOb%wKfkY3RU}7^FRq`UEbB-#A-%7)NJQwQd1As=!$u#~2vQ*CE~qp`u=_kL<`{OL zk>753UqJVx1-4~+d@(pnX-i zV4&=eRWbJ)9YEGMV53poXpv$vd@^yd05z$$@i5J7%>gYKBx?mR2qGv&BPn!tE-_aW zg*C!Z&!B zH>3J16dTJC(@M0*kIc}Jn}jf=f*agba|!HVm|^@+7A?V>Woo!$SJko*Jv1mu>;d}z z^vF{3u5Mvo_94`4kq2&R2`32oyoWc2lJco3`Ls0Ew4E7*AdiMbn^LCV%7%mU)hr4S3UVJjDLUoIKRQ)gm?^{1Z}OYzd$1?a~tEY ztjXmIM*2_qC|OC{7V%430T?RsY?ZLN$w!bkDOQ0}wiq69){Kdu3SqW?NMC))S}zq^ zu)w!>E1!;OrXO!RmT?m&PA;YKUjJy5-Seu=@o;m4*Vp$0OipBl4~Ub)1xBdWkZ47=UkJd$`Z}O8ZbpGN$i_WtY^00`S8=EHG#Ff{&MU1L(^wYjTchB zMTK%1LZ(eLLP($0UR2JVLaL|C2~IFbWirNjp|^=Fl48~Sp9zNOCZ@t&;;^avfN(NpNfq}~VYA{q%yjHo4D>JB>XEv(~Z!`1~SoY=9v zTq;hrjObE_h)cmHXLJ>LC_&XQ2BgGfV}e#v}ZF}iF97bG`Nog&O+SA`2zsn%bbB309}I$ zYi;vW$k@fC^muYBL?XB#CBuhC&^H)F4E&vw(5Q^PF{7~}(b&lF4^%DQzL0(BVk?lM zTHXTo4?Ps|dRICEiux#y77_RF8?5!1D-*h5UY&gRY`WO|V`xxB{f{DHzBwvt1W==r zdfAUyd({^*>Y7lObr;_fO zxDDw7X^dO`n!PLqHZ`by0h#BJ-@bAFPs{yJQ~Ylj^M5zWsxO_WFHG}8hH>OK{Q)9` zSRP94d{AM(q-2x0yhK@aNMv!qGA5@~2tB;X?l{Pf?DM5Y*QK`{mGA? zjx;gwnR~#Nep12dFk<^@-U{`&`P1Z}Z3T2~m8^J&7y}GaMElsTXg|GqfF3>E#HG=j zMt;6hfbfjHSQ&pN9(AT8q$FLKXo`N(WNHDY!K6;JrHZCO&ISBdX`g8sXvIf?|8 zX$-W^ut!FhBxY|+R49o44IgWHt}$1BuE|6|kvn1OR#zhyrw}4H*~cpmFk%K(CTGYc zNkJ8L$eS;UYDa=ZHWZy`rO`!w0oIcgZnK&xC|93#nHvfb^n1xgxf{$LB`H1ao+OGb zKG_}>N-RHSqL(RBdlc7J-Z$Gaay`wEGJ_u-lo88{`aQ*+T~+x(H5j?Q{uRA~>2R+} zB+{wM2m?$->unwg8-GaFrG%ZmoHEceOj{W21)Mi2lAfT)EQuNVo+Do%nHPuq7Ttt7 z%^6J5Yo64dH671tOUrA7I2hL@HKZq;S#Ejxt;*m-l*pPj?=i`=E~FAXAb#QH+a}-% z#3u^pFlg%p{hGiIp>05T$RiE*V7bPXtkz(G<+^E}Risi6F!R~Mbf(Qz*<@2&F#vDr zaL#!8!&ughWxjA(o9xtK{BzzYwm_z2t*c>2jI)c0-xo8ahnEqZ&K;8uF*!Hg0?Gd* z=eJK`FkAr>7$_i$;kq3Ks5NNJkNBnw|1f-&Ys56c9Y@tdM3VTTuXOCbWqye9va6+ZSeF0eh} zYb^ct&4lQTfNZ3M3(9?{;s><(zq%hza7zcxlZ+`F8J*>%4wq8s$cC6Z=F@ zhbvdv;n$%vEI$B~B)Q&LkTse!8Vt};7Szv2@YB!_Ztp@JA>rc(#R1`EZcIdE+JiI% zC2!hgYt+~@%xU?;ir+g92W`*j z3`@S;I6@2rO28zqj&SWO^CvA5MeNEhBF+8-U0O0Q1Co=I^WvPl%#}UFDMBVl z5iXV@d|`QTa$>iw;m$^}6JeuW zjr;{)S2TfK0Q%xgHvONSJb#NA|LOmg{U=k;R?&1tQbylMEY4<1*9mJh&(qo`G#9{X zYRs)#*PtEHnO;PV0G~6G`ca%tpKgb6<@)xc^SQY58lTo*S$*sv5w7bG+8YLKYU`8{ zNBVlvgaDu7icvyf;N&%42z2L4(rR<*Jd48X8Jnw zN>!R$%MZ@~Xu9jH?$2Se&I|ZcW>!26BJP?H7og0hT(S`nXh6{sR36O^7%v=31T+eL z)~BeC)15v>1m#(LN>OEwYFG?TE0_z)MrT%3SkMBBjvCd6!uD+03Jz#!s#Y~b1jf>S z&Rz5&8rbLj5!Y;(Hx|UY(2aw~W(8!3q3D}LRE%XX(@h5TnP@PhDoLVQx;6|r^+Bvs zaR55cR%Db9hZ<<|I%dDkone+8Sq7dqPOMnGoHk~-R*#a8w$c)`>4U`k+o?2|E>Sd4 zZ0ZVT{95pY$qKJ54K}3JB!(WcES>F+x56oJBRg))tMJ^#Qc(2rVcd5add=Us6vpBNkIg9b#ulk%!XBU zV^fH1uY(rGIAiFew|z#MM!qsVv%ZNb#why9%9In4Kj-hDYtMdirWLFzn~de!nnH(V zv0>I3;X#N)bo1$dFzqo(tzmvqNUKraAz~?)OSv42MeM!OYu;2VKn2-s7#fucX`|l~ zplxtG1Pgk#(;V=`P_PZ`MV{Bt4$a7;aLvG@KQo%E=;7ZO&Ws-r@XL+AhnPn>PAKc7 zQ_iQ4mXa-a4)QS>cJzt_j;AjuVCp8g^|dIV=DI0>v-f_|w5YWAX61lNBjZEZax3aV znher(j)f+a9_s8n#|u=kj0(unR1P-*L7`{F28xv054|#DMh}q=@rs@-fbyf(2+52L zN>hn3v!I~%jfOV=j(@xLOsl$Jv-+yR5{3pX)$rIdDarl7(C3)})P`QoHN|y<<2n;` zJ0UrF=Zv}d=F(Uj}~Yv9(@1pqUSRa5_bB*AvQ|Z-6YZ*N%p(U z<;Bpqr9iEBe^LFF!t{1UnRtaH-9=@p35fMQJ~1^&)(2D|^&z?m z855r&diVS6}jmt2)A7LZDiv;&Ys6@W5P{JHY!!n7W zvj3(2{1R9Y=TJ|{^2DK&be*ZaMiRHw>WVI^701fC) zAp1?8?oiU%Faj?Qhou6S^d11_7@tEK-XQ~%q!!7hha-Im^>NcRF7OH7s{IO7arZQ{ zE8n?2><7*!*lH}~usWPWZ}2&M+)VQo7C!AWJSQc>8g_r-P`N&uybK5)p$5_o;+58Q z-Ux2l<3i|hxqqur*qAfHq=)?GDchq}ShV#m6&w|mi~ar~`EO_S=fb~<}66U>5i7$H#m~wR;L~4yHL2R&;L*u7-SPdHxLS&Iy76q$2j#Pe)$WulRiCICG*t+ zeehM8`!{**KRL{Q{8WCEFLXu3+`-XF(b?c1Z~wg?c0lD!21y?NLq?O$STk3NzmrHM zsCgQS5I+nxDH0iyU;KKjzS24GJmG?{D`08|N-v+Egy92lBku)fnAM<}tELA_U`)xKYb=pq|hejMCT1-rg0Edt6(*E9l9WCKI1a=@c99swp2t6Tx zFHy`8Hb#iXS(8c>F~({`NV@F4w0lu5X;MH6I$&|h*qfx{~DJ*h5e|61t1QP}tZEIcjC%!Fa)omJTfpX%aI+OD*Y(l|xc0$1Zip;4rx; zV=qI!5tSuXG7h?jLR)pBEx!B15HCoVycD&Z2dlqN*MFQDb!|yi0j~JciNC!>){~ zQQgmZvc}0l$XB0VIWdg&ShDTbTkArryp3x)T8%ulR;Z?6APx{JZyUm=LC-ACkFm`6 z(x7zm5ULIU-xGi*V6x|eF~CN`PUM%`!4S;Uv_J>b#&OT9IT=jx5#nydC4=0htcDme zDUH*Hk-`Jsa>&Z<7zJ{K4AZE1BVW%zk&MZ^lHyj8mWmk|Pq8WwHROz0Kwj-AFqvR)H2gDN*6dzVk>R3@_CV zw3Z@6s^73xW)XY->AFwUlk^4Q=hXE;ckW=|RcZFchyOM0vqBW{2l*QR#v^SZNnT6j zZv|?ZO1-C_wLWVuYORQryj29JA; zS4BsxfVl@X!W{!2GkG9fL4}58Srv{$-GYngg>JuHz!7ZPQbfIQr4@6ZC4T$`;Vr@t zD#-uJ8A!kSM*gA&^6yWi|F}&59^*Rx{qn3z{(JYxrzg!X2b#uGd>&O0e=0k_2*N?3 zYXV{v={ONL{rW~z_FtFj7kSSJZ?s);LL@W&aND7blR8rlvkAb48RwJZlOHA~t~RfC zOD%ZcOzhYEV&s9%qns0&ste5U!^MFWYn`Od()5RwIz6%@Ek+Pn`s79unJY-$7n-Uf z&eUYvtd)f7h7zG_hDiFC!psCg#q&0c=GHKOik~$$>$Fw*k z;G)HS$IR)Cu72HH|JjeeauX;U6IgZ_IfxFCE_bGPAU25$!j8Etsl0Rk@R`$jXuHo8 z3Hhj-rTR$Gq(x)4Tu6;6rHQhoCvL4Q+h0Y+@Zdt=KTb0~wj7-(Z9G%J+aQu05@k6JHeCC|YRFWGdDCV}ja;-yl^9<`>f=AwOqML1a~* z9@cQYb?!+Fmkf}9VQrL8$uyq8k(r8)#;##xG9lJ-B)Fg@15&To(@xgk9SP*bkHlxiy8I*wJQylh(+9X~H-Is!g&C!q*eIYuhl&fS&|w)dAzXBdGJ&Mp$+8D| zZaD<+RtjI90QT{R0YLk6_dm=GfCg>7;$ zlyLsNYf@MfLH<}ott5)t2CXiQos zFLt^`%ygB2Vy^I$W3J_Rt4olRn~Gh}AW(`F@LsUN{d$sR%bU&3;rsD=2KCL+4c`zv zlI%D>9-)U&R3;>d1Vdd5b{DeR!HXDm44Vq*u?`wziLLsFUEp4El;*S0;I~D#TgG0s zBXYZS{o|Hy0A?LVNS)V4c_CFwyYj-E#)4SQq9yaf`Y2Yhk7yHSdos~|fImZG5_3~~o<@jTOH@Mc7`*xn-aO5F zyFT-|LBsm(NbWkL^oB-Nd31djBaYebhIGXhsJyn~`SQ6_4>{fqIjRp#Vb|~+Qi}Mdz!Zsw= zz?5L%F{c{;Cv3Q8ab>dsHp)z`DEKHf%e9sT(aE6$az?A}3P`Lm(~W$8Jr=;d8#?dm_cmv>2673NqAOenze z=&QW`?TQAu5~LzFLJvaJ zaBU3mQFtl5z?4XQDBWNPaH4y)McRpX#$(3o5Nx@hVoOYOL&-P+gqS1cQ~J;~1roGH zVzi46?FaI@w-MJ0Y7BuAg*3;D%?<_OGsB3)c|^s3A{UoAOLP8scn`!5?MFa|^cTvq z#%bYG3m3UO9(sH@LyK9-LSnlVcm#5^NRs9BXFtRN9kBY2mPO|@b7K#IH{B{=0W06) zl|s#cIYcreZ5p3j>@Ly@35wr-q8z5f9=R42IsII=->1stLo@Q%VooDvg@*K(H@*5g zUPS&cM~k4oqp`S+qp^*nxzm^0mg3h8ppEHQ@cXyQ=YKV-6)FB*$KCa{POe2^EHr{J zOxcVd)s3Mzs8m`iV?MSp=qV59blW9$+$P+2;PZDRUD~sr*CQUr&EDiCSfH@wuHez+ z`d5p(r;I7D@8>nbZ&DVhT6qe+accH;<}q$8Nzz|d1twqW?UV%FMP4Y@NQ`3(+5*i8 zP9*yIMP7frrneG3M9 zf>GsjA!O#Bifr5np-H~9lR(>#9vhE6W-r`EjjeQ_wdWp+rt{{L5t5t(Ho|4O24@}4 z_^=_CkbI`3;~sXTnnsv=^b3J}`;IYyvb1gM>#J9{$l#Zd*W!;meMn&yXO7x`Epx_Y zm-1wlu~@Ii_7D}>%tzlXW;zQT=uQXSG@t$<#6-W*^vy7Vr2TCpnix@7!_|aNXEnN<-m?Oq;DpN*x6f>w za1Wa5entFEDtA0SD%iZv#3{wl-S`0{{i3a9cmgNW`!TH{J*~{@|5f%CKy@uk*8~af zt_d34U4y&3y9IZ5cXxLQ?(XjH5?q3Z0KxK~y!-CUyWG6{<)5lkhbox0HnV&7^zNBn zjc|?X!Y=63(Vg>#&Wx%=LUr5{i@~OdzT#?P8xu#P*I_?Jl7xM4dq)4vi}3Wj_c=XI zSbc)@Q2Et4=(nBDU{aD(F&*%Ix!53_^0`+nOFk)}*34#b0Egffld|t_RV91}S0m)0 zap{cQDWzW$geKzYMcDZDAw480!1e1!1Onpv9fK9Ov~sfi!~OeXb(FW)wKx335nNY! za6*~K{k~=pw`~3z!Uq%?MMzSl#s%rZM{gzB7nB*A83XIGyNbi|H8X>a5i?}Rs+z^; z2iXrmK4|eDOu@{MdS+?@(!-Ar4P4?H_yjTEMqm7`rbV4P275(-#TW##v#Dt14Yn9UB-Sg3`WmL0+H~N;iC`Mg%pBl?1AAOfZ&e; z*G=dR>=h_Mz@i;lrGpIOQwezI=S=R8#);d*;G8I(39ZZGIpWU)y?qew(t!j23B9fD z?Uo?-Gx3}6r8u1fUy!u)7LthD2(}boE#uhO&mKBau8W8`XV7vO>zb^ZVWiH-DOjl2 zf~^o1CYVU8eBdmpAB=T%i(=y}!@3N%G-*{BT_|f=egqtucEtjRJJhSf)tiBhpPDpgzOpG12UgvOFnab&16Zn^2ZHjs)pbd&W1jpx%%EXmE^ zdn#R73^BHp3w%&v!0~azw(Fg*TT*~5#dJw%-UdxX&^^(~V&C4hBpc+bPcLRZizWlc zjR;$4X3Sw*Rp4-o+a4$cUmrz05RucTNoXRINYG*DPpzM&;d1GNHFiyl(_x#wspacQ zL)wVFXz2Rh0k5i>?Ao5zEVzT)R(4Pjmjv5pzPrav{T(bgr|CM4jH1wDp6z*_jnN{V ziN56m1T)PBp1%`OCFYcJJ+T09`=&=Y$Z#!0l0J2sIuGQtAr>dLfq5S;{XGJzNk@a^ zk^eHlC4Gch`t+ue3RviiOlhz81CD9z~d|n5;A>AGtkZMUQ#f>5M14f2d}2 z8<*LNZvYVob!p9lbmb!0jt)xn6O&JS)`}7v}j+csS3e;&Awj zoNyjnqLzC(QQ;!jvEYUTy73t_%16p)qMb?ihbU{y$i?=a7@JJoXS!#CE#y}PGMK~3 zeeqqmo7G-W_S97s2eed^erB2qeh4P25)RO1>MH7ai5cZJTEevogLNii=oKG)0(&f` z&hh8cO{of0;6KiNWZ6q$cO(1)9r{`}Q&%p*O0W7N--sw3Us;)EJgB)6iSOg(9p_mc zRw{M^qf|?rs2wGPtjVKTOMAfQ+ZNNkb$Ok0;Pe=dNc7__TPCzw^H$5J0l4D z%p(_0w(oLmn0)YDwrcFsc*8q)J@ORBRoZ54GkJpxSvnagp|8H5sxB|ZKirp%_mQt_ z81+*Y8{0Oy!r8Gmih48VuRPwoO$dDW@h53$C)duL4_(osryhwZSj%~KsZ?2n?b`Z* z#C8aMdZxYmCWSM{mFNw1ov*W}Dl=%GQpp90qgZ{(T}GOS8#>sbiEU;zYvA?=wbD5g+ahbd1#s`=| zV6&f#ofJC261~Ua6>0M$w?V1j##jh-lBJ2vQ%&z`7pO%frhLP-1l)wMs=3Q&?oth1 zefkPr@3Z(&OL@~|<0X-)?!AdK)ShtFJ;84G2(izo3cCuKc{>`+aDoziL z6gLTL(=RYeD7x^FYA%sPXswOKhVa4i(S4>h&mLvS##6-H?w8q!B<8Alk>nQEwUG)SFXK zETfcTwi=R3!ck|hSM`|-^N3NWLav&UTO{a9=&Tuz-Kq963;XaRFq#-1R18fi^Gb-; zVO>Q{Oe<^b0WA!hkBi9iJp3`kGwacXX2CVQ0xQn@Y2OhrM%e4)Ea7Y*Df$dY2BpbL zv$kX}*#`R1uNA(7lk_FAk~{~9Z*Si5xd(WKQdD&I?8Y^cK|9H&huMU1I(251D7(LL z+){kRc=ALmD;#SH#YJ+|7EJL6e~w!D7_IrK5Q=1DCulUcN(3j`+D_a|GP}?KYx}V+ zx_vLTYCLb0C?h;e<{K0`)-|-qfM16y{mnfX(GGs2H-;-lRMXyb@kiY^D;i1haxoEk zsQ7C_o2wv?;3KS_0w^G5#Qgf*>u)3bT<3kGQL-z#YiN9QH7<(oDdNlSdeHD zQJN-U*_wJM_cU}1YOH=m>DW~{%MAPxL;gLdU6S5xLb$gJt#4c2KYaEaL8ORWf=^(l z-2`8^J;&YG@vb9em%s~QpU)gG@24BQD69;*y&-#0NBkxumqg#YYomd2tyo0NGCr8N z5<5-E%utH?Ixt!(Y4x>zIz4R^9SABVMpLl(>oXnBNWs8w&xygh_e4*I$y_cVm?W-^ ze!9mPy^vTLRclXRGf$>g%Y{(#Bbm2xxr_Mrsvd7ci|X|`qGe5=54Zt2Tb)N zlykxE&re1ny+O7g#`6e_zyjVjRi5!DeTvSJ9^BJqQ*ovJ%?dkaQl!8r{F`@KuDEJB3#ho5 zmT$A&L=?}gF+!YACb=%Y@}8{SnhaGCHRmmuAh{LxAn0sg#R6P_^cJ-9)+-{YU@<^- zlYnH&^;mLVYE+tyjFj4gaAPCD4CnwP75BBXA`O*H(ULnYD!7K14C!kGL_&hak)udZ zkQN8)EAh&9I|TY~F{Z6mBv7sz3?<^o(#(NXGL898S3yZPTaT|CzZpZ~pK~*9Zcf2F zgwuG)jy^OTZD`|wf&bEdq4Vt$ir-+qM7BosXvu`>W1;iFN7yTvcpN_#at)Q4n+(Jh zYX1A-24l9H5jgY?wdEbW{(6U1=Kc?Utren80bP`K?J0+v@{-RDA7Y8yJYafdI<7-I z_XA!xeh#R4N7>rJ_?(VECa6iWhMJ$qdK0Ms27xG&$gLAy(|SO7_M|AH`fIY)1FGDp zlsLwIDshDU;*n`dF@8vV;B4~jRFpiHrJhQ6TcEm%OjWTi+KmE7+X{19 z>e!sg0--lE2(S0tK}zD&ov-{6bMUc%dNFIn{2^vjXWlt>+uxw#d)T6HNk6MjsfN~4 zDlq#Jjp_!wn}$wfs!f8NX3Rk#9)Q6-jD;D9D=1{$`3?o~caZjXU*U32^JkJ$ZzJ_% zQWNfcImxb!AV1DRBq`-qTV@g1#BT>TlvktYOBviCY!13Bv?_hGYDK}MINVi;pg)V- z($Bx1Tj`c?1I3pYg+i_cvFtcQ$SV9%%9QBPg&8R~Ig$eL+xKZY!C=;M1|r)$&9J2x z;l^a*Ph+isNl*%y1T4SviuK1Nco_spQ25v5-}7u?T9zHB5~{-+W*y3p{yjn{1obqf zYL`J^Uz8zZZN8c4Dxy~)k3Ws)E5eYi+V2C!+7Sm0uu{xq)S8o{9uszFTnE>lPhY=5 zdke-B8_*KwWOd%tQs_zf0x9+YixHp+Qi_V$aYVc$P-1mg?2|_{BUr$6WtLdIX2FaF zGmPRTrdIz)DNE)j*_>b9E}sp*(1-16}u za`dgT`KtA3;+e~9{KV48RT=CGPaVt;>-35}%nlFUMK0y7nOjoYds7&Ft~#>0$^ciZ zM}!J5Mz{&|&lyG^bnmh?YtR z*Z5EfDxkrI{QS#Iq752aiA~V)DRlC*2jlA|nCU!@CJwxO#<=j6ssn;muv zhBT9~35VtwsoSLf*(7vl&{u7d_K_CSBMbzr zzyjt&V5O#8VswCRK3AvVbS7U5(KvTPyUc0BhQ}wy0z3LjcdqH8`6F3!`)b3(mOSxL z>i4f8xor(#V+&#ph~ycJMcj#qeehjxt=~Na>dx#Tcq6Xi4?BnDeu5WBBxt603*BY& zZ#;o1kv?qpZjwK-E{8r4v1@g*lwb|8w@oR3BTDcbiGKs)a>Fpxfzh&b ziQANuJ_tNHdx;a*JeCo^RkGC$(TXS;jnxk=dx++D8|dmPP<0@ z$wh#ZYI%Rx$NKe-)BlJzB*bot0ras3I%`#HTMDthGtM_G6u-(tSroGp1Lz+W1Y`$@ zP`9NK^|IHbBrJ#AL3!X*g3{arc@)nuqa{=*2y+DvSwE=f*{>z1HX(>V zNE$>bbc}_yAu4OVn;8LG^naq5HZY zh{Hec==MD+kJhy6t=Nro&+V)RqORK&ssAxioc7-L#UQuPi#3V2pzfh6Ar400@iuV5 z@r>+{-yOZ%XQhsSfw%;|a4}XHaloW#uGluLKux0II9S1W4w=X9J=(k&8KU()m}b{H zFtoD$u5JlGfpX^&SXHlp$J~wk|DL^YVNh2w(oZ~1*W156YRmenU;g=mI zw({B(QVo2JpJ?pJqu9vijk$Cn+%PSw&b4c@uU6vw)DjGm2WJKt!X}uZ43XYlDIz%& z=~RlgZpU-tu_rD`5!t?289PTyQ zZgAEp=zMK>RW9^~gyc*x%vG;l+c-V?}Bm;^{RpgbEnt_B!FqvnvSy)T=R zGa!5GACDk{9801o@j>L8IbKp#!*Td5@vgFKI4w!5?R{>@^hd8ax{l=vQnd2RDHopo zwA+qb2cu4Rx9^Bu1WNYT`a(g}=&&vT`&Sqn-irxzX_j1=tIE#li`Hn=ht4KQXp zzZj`JO+wojs0dRA#(bXBOFn**o+7rPY{bM9m<+UBF{orv$#yF8)AiOWfuas5Fo`CJ zqa;jAZU^!bh8sjE7fsoPn%Tw11+vufr;NMm3*zC=;jB{R49e~BDeMR+H6MGzDlcA^ zKg>JEL~6_6iaR4i`tSfUhkgPaLXZ<@L7poRF?dw_DzodYG{Gp7#24<}=18PBT}aY` z{)rrt`g}930jr3^RBQNA$j!vzTh#Mo1VL`QCA&US?;<2`P+xy8b9D_Hz>FGHC2r$m zW>S9ywTSdQI5hh%7^e`#r#2906T?))i59O(V^Rpxw42rCAu-+I3y#Pg6cm#&AX%dy ze=hv0cUMxxxh1NQEIYXR{IBM&Bk8FK3NZI3z+M>r@A$ocd*e%x-?W;M0pv50p+MVt zugo<@_ij*6RZ;IPtT_sOf2Zv}-3R_1=sW37GgaF9Ti(>V z1L4ju8RzM%&(B}JpnHSVSs2LH#_&@`4Kg1)>*)^i`9-^JiPE@=4l$+?NbAP?44hX&XAZy&?}1;=8c(e0#-3bltVWg6h=k!(mCx=6DqOJ-I!-(g;*f~DDe={{JGtH7=UY|0F zNk(YyXsGi;g%hB8x)QLpp;;`~4rx>zr3?A|W$>xj>^D~%CyzRctVqtiIz7O3pc@r@JdGJiH@%XR_9vaYoV?J3K1cT%g1xOYqhXfSa`fg=bCLy% zWG74UTdouXiH$?H()lyx6QXt}AS)cOa~3IdBxddcQp;(H-O}btpXR-iwZ5E)di9Jf zfToEu%bOR11xf=Knw7JovRJJ#xZDgAvhBDF<8mDu+Q|!}Z?m_=Oy%Ur4p<71cD@0OGZW+{-1QT?U%_PJJ8T!0d2*a9I2;%|A z9LrfBU!r9qh4=3Mm3nR_~X-EyNc<;?m`?dKUNetCnS)}_-%QcWuOpw zAdZF`4c_24z&m{H9-LIL`=Hrx%{IjrNZ~U<7k6p{_wRkR84g>`eUBOQd3x5 zT^kISYq)gGw?IB8(lu1=$#Vl?iZdrx$H0%NxW)?MO$MhRHn8$F^&mzfMCu>|`{)FL z`ZgOt`z%W~^&kzMAuWy9=q~$ldBftH0}T#(K5e8;j~!x$JjyspJ1IISI?ON5OIPB$ z-5_|YUMb+QUsiv3R%Ys4tVYW+x$}dg;hw%EdoH%SXMp`)v?cxR4wic{X9pVBH>=`#`Kcj!}x4 zV!`6tj|*q?jZdG(CSevn(}4Ogij5 z-kp;sZs}7oNu0x+NHs~(aWaKGV@l~TBkmW&mPj==N!f|1e1SndS6(rPxsn7dz$q_{ zL0jSrihO)1t?gh8N zosMjR3n#YC()CVKv zos2TbnL&)lHEIiYdz|%6N^vAUvTs6?s|~kwI4uXjc9fim`KCqW3D838Xu{48p$2?I zOeEqQe1}JUZECrZSO_m=2<$^rB#B6?nrFXFpi8jw)NmoKV^*Utg6i8aEW|^QNJuW& z4cbXpHSp4|7~TW(%JP%q9W2~@&@5Y5%cXL#fMhV59AGj<3$Hhtfa>24DLk{7GZUtr z5ql**-e58|mbz%5Kk~|f!;g+Ze^b);F+5~^jdoq#m+s?Y*+=d5ruym%-Tnn8htCV; zDyyUrWydgDNM&bI{yp<_wd-q&?Ig+BN-^JjWo6Zu3%Eov^Ja>%eKqrk&7kUqeM8PL zs5D}lTe_Yx;e=K`TDya!-u%y$)r*Cr4bSfN*eZk$XT(Lv2Y}qj&_UaiTevxs_=HXjnOuBpmT> zBg|ty8?|1rD1~Ev^6=C$L9%+RkmBSQxlnj3j$XN?%QBstXdx+Vl!N$f2Ey`i3p@!f zzqhI3jC(TZUx|sP%yValu^nzEV96o%*CljO>I_YKa8wMfc3$_L()k4PB6kglP@IT#wBd*3RITYADL}g+hlzLYxFmCt=_XWS}=jg8`RgJefB57z(2n&&q>m ze&F(YMmoRZW7sQ;cZgd(!A9>7mQ2d#!-?$%G8IQ0`p1|*L&P$GnU0i0^(S;Rua4v8 z_7Qhmv#@+kjS-M|($c*ZOo?V2PgT;GKJyP1REABlZhPyf!kR(0UA7Bww~R<7_u6#t z{XNbiKT&tjne(&=UDZ+gNxf&@9EV|fblS^gxNhI-DH;|`1!YNlMcC{d7I{u_E~cJOalFEzDY|I?S3kHtbrN&}R3k zK(Ph_Ty}*L3Et6$cUW`0}**BY@44KtwEy(jW@pAt`>g> z&8>-TmJiDwc;H%Ae%k6$ndZlfKruu1GocgZrLN=sYI52}_I%d)~ z6z40!%W4I6ch$CE2m>Dl3iwWIbcm27QNY#J!}3hqc&~(F8K{^gIT6E&L!APVaQhj^ zjTJEO&?**pivl^xqfD(rpLu;`Tm1MV+Wtd4u>X6u5V{Yp%)xH$k410o{pGoKdtY0t@GgqFN zO=!hTcYoa^dEPKvPX4ukgUTmR#q840gRMMi%{3kvh9gt(wK;Fniqu9A%BMsq?U&B5DFXC8t8FBN1&UIwS#=S zF(6^Eyn8T}p)4)yRvs2rCXZ{L?N6{hgE_dkH_HA#L3a0$@UMoBw6RE9h|k_rx~%rB zUqeEPL|!Pbp|up2Q=8AcUxflck(fPNJYP1OM_4I(bc24a**Qnd-@;Bkb^2z8Xv?;3yZp*| zoy9KhLo=;8n0rPdQ}yAoS8eb zAtG5QYB|~z@Z(Fxdu`LmoO>f&(JzsO|v0V?1HYsfMvF!3| zka=}6U13(l@$9&=1!CLTCMS~L01CMs@Abl4^Q^YgVgizWaJa%{7t)2sVcZg0mh7>d z(tN=$5$r?s={yA@IX~2ot9`ZGjUgVlul$IU4N}{ zIFBzY3O0;g$BZ#X|VjuTPKyw*|IJ+&pQ` z(NpzU`o=D86kZ3E5#!3Ry$#0AW!6wZe)_xZ8EPidvJ0f+MQJZ6|ZJ$CEV6;Yt{OJnL`dewc1k>AGbkK9Gf5BbB-fg? zgC4#CPYX+9%LLHg@=c;_Vai_~#ksI~)5|9k(W()g6ylc(wP2uSeJ$QLATtq%e#zpT zp^6Y)bV+e_pqIE7#-hURQhfQvIZpMUzD8&-t$esrKJ}4`ZhT|woYi>rP~y~LRf`*2!6 z6prDzJ~1VOlYhYAuBHcu9m>k_F>;N3rpLg>pr;{EDkeQPHfPv~woj$?UTF=txmaZy z?RrVthxVcqUM;X*(=UNg4(L|0d250Xk)6GF&DKD@r6{aZo;(}dnO5@CP7pMmdsI)- zeYH*@#+|)L8x7)@GNBu0Npyyh6r z^~!3$x&w8N)T;|LVgnwx1jHmZn{b2V zO|8s#F0NZhvux?0W9NH5;qZ?P_JtPW86)4J>AS{0F1S0d}=L2`{F z_y;o;17%{j4I)znptnB z%No1W>o}H2%?~CFo~0j?pzWk?dV4ayb!s{#>Yj`ZJ!H)xn}*Z_gFHy~JDis)?9-P=z4iOQg{26~n?dTms7)+F}? zcXvnHHnnbNTzc!$t+V}=<2L<7l(84v1I3b;-)F*Q?cwLNlgg{zi#iS)*rQ5AFWe&~ zWHPPGy{8wEC9JSL?qNVY76=es`bA{vUr~L7f9G@mP}2MNF0Qhv6Sgs`r_k!qRbSXK zv16Qqq`rFM9!4zCrCeiVS~P2e{Pw^A8I?p?NSVR{XfwlQo*wj|Ctqz4X-j+dU7eGkC(2y`(P?FM?P4gKki3Msw#fM6paBq#VNc>T2@``L{DlnnA-_*i10Kre&@-H!Z7gzn9pRF61?^^ z8dJ5kEeVKb%Bly}6NLV}<0(*eZM$QTLcH#+@iWS^>$Of_@Mu1JwM!>&3evymgY6>C_)sK+n|A5G6(3RJz0k>(z2uLdzXeTw)e4*g!h} zn*UvIx-Ozx<3rCF#C`khSv`Y-b&R4gX>d5osr$6jlq^8vi!M$QGx05pJZoY#RGr*J zsJmOhfodAzYQxv-MoU?m_|h^aEwgEHt5h_HMkHwtE+OA03(7{hm1V?AlYAS7G$u5n zO+6?51qo@aQK5#l6pM`kD5OmI28g!J2Z{5kNlSuKl=Yj3QZ|bvVHU}FlM+{QV=<=) z+b|%Q!R)FE z@ycDMSKV2?*XfcAc5@IOrSI&3&aR$|oAD8WNA6O;p~q-J@ll{x`jP<*eEpIYOYnT zer_t=dYw6a0avjQtKN&#n&(KJ5Kr$RXPOp1@Fq#0Of zTXQkq4qQxKWR>x#d{Hyh?6Y)U07;Q$?BTl7mx2bSPY_juXub1 z%-$)NKXzE<%}q>RX25*oeMVjiz&r_z;BrQV-(u>!U>C*OisXNU*UftsrH6vAhTEm@ zoKA`?fZL1sdd!+G@*NNvZa>}37u^x8^T>VH0_6Bx{3@x5NAg&55{2jUE-w3zCJNJi z^IlU=+DJz-9K&4c@7iKj(zlj@%V}27?vYmxo*;!jZVXJMeDg;5T!4Y1rxNV-e$WAu zkk6^Xao8HC=w2hpLvM(!xwo|~$eG6jJj39zyQHf)E+NPJlfspUhzRv&_qr8+Z1`DA zz`EV=A)d=;2&J;eypNx~q&Ir_7e_^xXg(L9>k=X4pxZ3y#-ch$^TN}i>X&uwF%75c(9cjO6`E5 z16vbMYb!lEIM?jxn)^+Ld8*hmEXR4a8TSfqwBg1(@^8$p&#@?iyGd}uhWTVS`Mlpa zGc+kV)K7DJwd46aco@=?iASsx?sDjbHoDVU9=+^tk46|Fxxey1u)_}c1j z^(`5~PU%og1LdSBE5x4N&5&%Nh$sy0oANXwUcGa>@CCMqP`4W$ZPSaykK|giiuMIw zu#j)&VRKWP55I(5K1^cog|iXgaK1Z%wm%T;;M3X`-`TTWaI}NtIZj;CS)S%S(h}qq zRFQ#{m4Qk$7;1i*0PC^|X1@a1pcMq1aiRSCHq+mnfj^FS{oxWs0McCN-lK4>SDp#` z7=Duh)kXC;lr1g3dqogzBBDg6>et<<>m>KO^|bI5X{+eMd^-$2xfoP*&e$vdQc7J% zmFO~OHf7aqlIvg%P`Gu|3n;lKjtRd@;;x#$>_xU(HpZos7?ShZlQSU)bY?qyQM3cHh5twS6^bF8NBKDnJgXHa)? zBYv=GjsZuYC2QFS+jc#uCsaEPEzLSJCL=}SIk9!*2Eo(V*SAUqKw#?um$mUIbqQQb zF1Nn(y?7;gP#@ws$W76>TuGcG=U_f6q2uJq?j#mv7g;llvqu{Yk~Mo>id)jMD7;T> zSB$1!g)QpIf*f}IgmV;!B+3u(ifW%xrD=`RKt*PDC?M5KI)DO`VXw(7X-OMLd3iVU z0CihUN(eNrY;m?vwK{55MU`p1;JDF=6ITN$+!q8W#`iIsN8;W7H?`htf%RS9Lh+KQ z_p_4?qO4#*`t+8l-N|kAKDcOt zoHsqz_oO&n?@4^Mr*4YrkDX44BeS*0zaA1j@*c}{$;jUxRXx1rq7z^*NX6d`DcQ}L z6*cN7e%`2#_J4z8=^GM6>%*i>>X^_0u9qn%0JTUo)c0zIz|7a`%_UnB)-I1cc+ z0}jAK0}jBl|6-2VT759oxBnf%-;7vs>7Mr}0h3^$0`5FAy}2h{ps5%RJA|^~6uCqg zxBMK5bQVD{Aduh1lu4)`Up*&( zCJQ>nafDb#MuhSZ5>YmD@|TcrNv~Q%!tca;tyy8Iy2vu2CeA+AsV^q*Wohg%69XYq zP0ppEDEYJ9>Se&X(v=U#ibxg()m=83pLc*|otbG;`CYZ z*YgsakGO$E$E_$|3bns7`m9ARe%myU3$DE;RoQ<6hR8e;%`pxO1{GXb$cCZl9lVnJ$(c` z``G?|PhXaz`>)rb7jm2#v7=(W?@ zjUhrNndRFMQ}%^^(-nmD&J>}9w@)>l;mhRr@$}|4ueOd?U9ZfO-oi%^n4{#V`i}#f zqh<@f^%~(MnS?Z0xsQI|Fghrby<&{FA+e4a>c(yxFL!Pi#?DW!!YI{OmR{xEC7T7k zS_g*9VWI}d0IvIXx*d5<7$5Vs=2^=ews4qZGmAVyC^9e;wxJ%BmB(F5*&!yyABCtLVGL@`qW>X9K zpv=W~+EszGef=am3LG+#yIq5oLXMnZ_dxSLQ_&bwjC^0e8qN@v!p?7mg02H<9`uaJ zy0GKA&YQV2CxynI3T&J*m!rf4@J*eo235*!cB1zEMQZ%h5>GBF;8r37K0h?@|E*0A zIHUg0y7zm(rFKvJS48W7RJwl!i~<6X2Zw+Fbm9ekev0M;#MS=Y5P(kq^(#q11zsvq zDIppe@xOMnsOIK+5BTFB=cWLalK#{3eE>&7fd11>l2=MpNKjsZT2kmG!jCQh`~Fu0 z9P0ab`$3!r`1yz8>_7DYsO|h$kIsMh__s*^KXv?Z1O8|~sEz?Y{+GDzze^GPjk$E$ zXbA-1gd77#=tn)YKU=;JE?}De0)WrT%H9s3`fn|%YibEdyZov3|MJ>QWS>290eCZj z58i<*>dC9=kz?s$sP_9kK1p>nV3qvbleExyq56|o+oQsb{ZVmuu1n~JG z0sUvo_i4fSM>xRs8rvG$*+~GZof}&ISxn(2JU*K{L<3+b{bBw{68H&Uiup@;fWWl5 zgB?IWMab0LkXK(Hz#yq>scZbd2%=B?DO~^q9tarlzZysN+g}n0+v);JhbjUT8AYrt z3?;0r%p9zLJv1r$%q&HKF@;3~0wVwO!U5m;J`Mm|`Nc^80sZd+Wj}21*SPoF82hCF zoK?Vw;4ioafdAkZxT1er-LLVi-*0`@2Ur&*!b?0U>R;no+S%)xoBuBxRw$?weN-u~tKE}8xb@7Gs%(aC;e1-LIlSfXDK(faFW)mnHdrLc3`F z6ZBsT^u0uVS&il=>YVX^*5`k!P4g1)2LQmz{?&dgf`7JrA4ZeE0sikL`k!Eb6r=g0 z{aCy_0I>fxSAXQYz3lw5G|ivg^L@(x-uch!AphH+d;E4`175`R0#b^)Zp>EM1Ks=zx6_261>!7 z{7F#a{Tl@Tpw9S`>7_i|PbScS-(dPJv9_0-FBP_aa@Gg^2IoKNZM~#=sW$SH3MJ|{ zsQy8F43lX7hYx<{v^Q9`2QsMzeen3cGpiTgzVp- z`aj3&Wv0(he1qKI!2jpGpO-i0Wpcz%vdn`2o9x&3;^nsZPt3c \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,92 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - command -v java >/dev/null || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat deleted file mode 100644 index 9618d8d96..000000000 --- a/android/gradlew.bat +++ /dev/null @@ -1,100 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega From 8ff0e1da1578d4dea5b89227eca4ade39943c871 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 18 Feb 2024 15:23:37 +0100 Subject: [PATCH 31/91] Amend Android dev documentation --- android/app/build.gradle | 4 +++ doc/developing/README.md | 1 + doc/developing/android.md | 63 +++++++++++++++++++++++++++++++++++++++ doc/developing/misc.md | 46 ---------------------------- 4 files changed, 68 insertions(+), 46 deletions(-) create mode 100644 doc/developing/android.md diff --git a/android/app/build.gradle b/android/app/build.gradle index 6bacc3d55..c7471d2c7 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -108,6 +108,10 @@ task prepareAssets() { preBuild.dependsOn zipAssets prepareAssets.dependsOn ':native:getDeps' +clean { + delete new File("src/main/assets", "Minetest.zip") +} + // Map for the version code that gives each ABI a value. import com.android.build.OutputFile diff --git a/doc/developing/README.md b/doc/developing/README.md index b12e75ce4..d15ab8f69 100644 --- a/doc/developing/README.md +++ b/doc/developing/README.md @@ -15,6 +15,7 @@ Notable pages: ## In this folder - [Developing minetestserver with Docker](docker.md) +- [Android tips & tricks](android.md) - [Miscellaneous](misc.md) ## IRC diff --git a/doc/developing/android.md b/doc/developing/android.md new file mode 100644 index 000000000..e278c48d8 --- /dev/null +++ b/doc/developing/android.md @@ -0,0 +1,63 @@ +# Android tips & tricks + +## Sign the Android APK from CI + +The [Github Actions Workflow](https://github.com/minetest/minetest/actions?query=workflow%3Aandroid+event%3Apush) +automatically produces an APK for each architecture. +Before installing them onto a device they however need to be signed. + +This requires an installation of the Android SDK and `adb`. +```bash +.../android-sdk/build-tools/30.0.3/apksigner sign --ks ~/.android/debug.keystore \ + app-arm64-v8a-release-unsigned.apk +# Enter 'android' (without quotes) when asked for a password +``` + +Note that the `debug.keystore` will not exist if you have never compiled an +Android app on your system (probably). + +After that installing it will work: +```bash +adb install -r -d ./app-arm64-v8a-release-unsigned.apk +``` + +## How to get debug output from Minetest on Android + +In case debug.txt isn't enough (e.g. when debugging a crash), you can get debug +output using logcat: + +`adb logcat -s 'Minetest:*' '*:F'` + +Note that you can do this even *after* the app has crashed, +since Android keeps an internal buffer. + +A segmentation fault for example looks like this: + +``` +01-10 17:20:22.215 19308 20560 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 20560 (MinetestNativeT), pid 19308 (netest.minetest) +01-10 17:20:22.287 20576 20576 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** +01-10 17:20:22.287 20576 20576 F DEBUG : Build fingerprint: '...' +01-10 17:20:22.287 20576 20576 F DEBUG : Revision: '4' +01-10 17:20:22.287 20576 20576 F DEBUG : ABI: 'arm64' +01-10 17:20:22.288 20576 20576 F DEBUG : Timestamp: 2024-01-10 17:20:22+0100 +01-10 17:20:22.288 20576 20576 F DEBUG : pid: 19308, tid: 20560, name: MinetestNativeT >>> net.minetest.minetest <<< +01-10 17:20:22.288 20576 20576 F DEBUG : uid: 10385 +01-10 17:20:22.288 20576 20576 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- +[ ... more information follows ... ] +``` + +If you want get rid of previous output you can do that with `adb logcat -c`. + +## I edited builtin, shaders, ... but nothing changed. Help! + +You're probably hitting two problems: +* the build system only generates assets once +* the app only re-extracts assets when the version changes + +Force regenerating the assets: `./gradlew app:clean` + +Erase the app's memory of which version was installed: `adb shell run-as net.minetest.minetest rm shared_prefs/MinetestSettings.xml` + +If this doesn't work you can also uninstall it using `adb shell pm uninstall net.minetest.minetest`. You will obviously lose your data. + +Then build and install as normal and your changes should be applied. diff --git a/doc/developing/misc.md b/doc/developing/misc.md index a48ed2237..dfecd031d 100644 --- a/doc/developing/misc.md +++ b/doc/developing/misc.md @@ -1,51 +1,5 @@ # Miscellaneous -## Sign the Android APK from CI - -The [Github Actions Workflow](https://github.com/minetest/minetest/actions?query=workflow%3Aandroid+event%3Apush) -automatically produces an APK for each architecture. -Before installing them onto a device they however need to be signed. - -This requires an installation of the Android SDK and `adb`. -```bash -.../android-sdk/build-tools/30.0.3/apksigner sign --ks ~/.android/debug.keystore \ - app-arm64-v8a-release-unsigned.apk -# Enter 'android' (without quotes) when asked for a password -``` - -Note that the `debug.keystore` will not exist if you have never compiled an -Android app on your system (probably). - -After that installing it will work: -```bash -adb install -r -d ./app-arm64-v8a-release-unsigned.apk -``` - -## How to get debug output from Minetest on Android - -In case debug.txt isn't enough (e.g. when debugging a crash), you can get debug -output using logcat: - -`adb logcat -s 'Minetest:*' '*:F'` - -Note that you can do this even *after* the app has crashed, -since Android keeps an internal buffer. - -A segmentation fault for example looks like this: - -``` -01-10 17:20:22.215 19308 20560 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 20560 (MinetestNativeT), pid 19308 (netest.minetest) -01-10 17:20:22.287 20576 20576 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** -01-10 17:20:22.287 20576 20576 F DEBUG : Build fingerprint: '...' -01-10 17:20:22.287 20576 20576 F DEBUG : Revision: '4' -01-10 17:20:22.287 20576 20576 F DEBUG : ABI: 'arm64' -01-10 17:20:22.288 20576 20576 F DEBUG : Timestamp: 2024-01-10 17:20:22+0100 -01-10 17:20:22.288 20576 20576 F DEBUG : pid: 19308, tid: 20560, name: MinetestNativeT >>> net.minetest.minetest <<< -01-10 17:20:22.288 20576 20576 F DEBUG : uid: 10385 -01-10 17:20:22.288 20576 20576 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- -[ ... more information follows ... ] -``` - ## Profiling Minetest on Linux We will be using a tool called "perf", which you can get by installing `perf` or `linux-perf` or `linux-tools-common`. From f596c36f4f7a48d69b95110fdd98ace042367e20 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 23 Feb 2024 20:28:29 +0100 Subject: [PATCH 32/91] Update NDK --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 6aead7aba..1805ba856 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -10,7 +10,7 @@ project.ext.set("versionCode", 46) // Android Version Code // each APK must have a larger `versionCode` than the previous buildscript { - ext.ndk_version = '25.2.9519653' + ext.ndk_version = '26.2.11394342' repositories { google() mavenCentral() From 02a893d6130a887c51f290b2274adbfd899767df Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 10 Mar 2024 10:50:04 +0100 Subject: [PATCH 33/91] Client: fix failing assert on empty texture name --- src/client/texturesource.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/texturesource.cpp b/src/client/texturesource.cpp index 529160b35..6842b08a9 100644 --- a/src/client/texturesource.cpp +++ b/src/client/texturesource.cpp @@ -898,7 +898,9 @@ video::IImage* TextureSource::generateImage(std::string_view name, If this name is enclosed in parentheses, generate it and blit it onto the base image */ - if (last_part_of_name[0] == paren_open + if (last_part_of_name.empty()) { + // keep baseimg == nullptr + } else if (last_part_of_name[0] == paren_open && last_part_of_name.back() == paren_close) { auto name2 = last_part_of_name.substr(1, last_part_of_name.size() - 2); From 32f68f35cf5eabd4223ef4901486d43bb806867e Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 10 Mar 2024 13:24:35 +0100 Subject: [PATCH 34/91] Avoid packets getting sent to disconnected players (#14444) Many functions expect RemotePlayer to have a valid peer ID, this however is not the case immediately after disconnecting where the object is still alive and pending for removal. ServerEnvironment::getPlayer(const char *, bool) now only returns players that are connected unless forced to. --- src/network/serverpackethandler.cpp | 2 +- src/script/lua_api/l_env.cpp | 4 +--- src/server.cpp | 33 +++++++++++------------------ src/server/serverinventorymgr.cpp | 4 ++-- src/serverenvironment.cpp | 10 ++++++--- src/serverenvironment.h | 2 +- 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index c3888c110..f4b5a4859 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -179,7 +179,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt) return; } - RemotePlayer *player = m_env->getPlayer(playername); + RemotePlayer *player = m_env->getPlayer(playername, true); // If player is already connected, cancel if (player && player->getPeerId() != PEER_ID_INEXISTENT) { diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 1fc640d23..ccf2cd653 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -695,8 +695,6 @@ int ModApiEnv::l_get_connected_players(lua_State *L) lua_createtable(L, env->getPlayerCount(), 0); u32 i = 0; for (RemotePlayer *player : env->getPlayers()) { - if (player->getPeerId() == PEER_ID_INEXISTENT) - continue; PlayerSAO *sao = player->getPlayerSAO(); if (sao && !sao->isGone()) { getScriptApiBase(L)->objectrefGetOrCreate(L, sao); @@ -714,7 +712,7 @@ int ModApiEnv::l_get_player_by_name(lua_State *L) // Do it const char *name = luaL_checkstring(L, 1); RemotePlayer *player = env->getPlayer(name); - if (!player || player->getPeerId() == PEER_ID_INEXISTENT) + if (!player) return 0; PlayerSAO *sao = player->getPlayerSAO(); if (!sao || sao->isGone()) diff --git a/src/server.cpp b/src/server.cpp index eebd3ba56..19d92316c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1107,7 +1107,7 @@ PlayerSAO* Server::StageTwoClientInit(session_t peer_id) } } - RemotePlayer *player = m_env->getPlayer(playername.c_str()); + RemotePlayer *player = m_env->getPlayer(playername.c_str(), true); // If failed, cancel if (!playersao || !player) { @@ -1948,9 +1948,13 @@ void Server::SendMovePlayerRel(session_t peer_id, const v3f &added_pos) void Server::SendPlayerFov(session_t peer_id) { + RemotePlayer *player = m_env->getPlayer(peer_id); + if (!player) + return; + NetworkPacket pkt(TOCLIENT_FOV, 4 + 1 + 4, peer_id); - PlayerFovSpec fov_spec = m_env->getPlayer(peer_id)->getFov(); + PlayerFovSpec fov_spec = player->getFov(); pkt << fov_spec.fov << fov_spec.is_multiplier << fov_spec.transition_time; Send(&pkt); @@ -1978,8 +1982,7 @@ void Server::SendEyeOffset(session_t peer_id, v3f first, v3f third, v3f third_fr void Server::SendPlayerPrivileges(session_t peer_id) { RemotePlayer *player = m_env->getPlayer(peer_id); - assert(player); - if(player->getPeerId() == PEER_ID_INEXISTENT) + if (!player) return; std::set privs; @@ -1998,8 +2001,7 @@ void Server::SendPlayerPrivileges(session_t peer_id) void Server::SendPlayerInventoryFormspec(session_t peer_id) { RemotePlayer *player = m_env->getPlayer(peer_id); - assert(player); - if (player->getPeerId() == PEER_ID_INEXISTENT) + if (!player) return; NetworkPacket pkt(TOCLIENT_INVENTORY_FORMSPEC, 0, peer_id); @@ -2011,8 +2013,7 @@ void Server::SendPlayerInventoryFormspec(session_t peer_id) void Server::SendPlayerFormspecPrepend(session_t peer_id) { RemotePlayer *player = m_env->getPlayer(peer_id); - assert(player); - if (player->getPeerId() == PEER_ID_INEXISTENT) + if (!player) return; NetworkPacket pkt(TOCLIENT_FORMSPEC_PREPEND, 0, peer_id); @@ -2190,11 +2191,6 @@ s32 Server::playSound(ServerPlayingSound ¶ms, bool ephemeral) <<"\" not found"<getPeerId() == PEER_ID_INEXISTENT) { - infostream<<"Server::playSound: Player \""<getPeerId()); } else { std::vector clients = m_clients.getClientIDs(); @@ -2817,8 +2813,7 @@ void Server::SendMinimapModes(session_t peer_id, std::vector &modes, size_t wanted_mode) { RemotePlayer *player = m_env->getPlayer(peer_id); - assert(player); - if (player->getPeerId() == PEER_ID_INEXISTENT) + if (!player) return; NetworkPacket pkt(TOCLIENT_MINIMAP_MODES, 0, peer_id); @@ -3363,11 +3358,7 @@ void Server::notifyPlayer(const char *name, const std::wstring &msg) } RemotePlayer *player = m_env->getPlayer(name); - if (!player) { - return; - } - - if (player->getPeerId() == PEER_ID_INEXISTENT) + if (!player) return; SendChatMessage(player->getPeerId(), ChatMessage(msg)); @@ -4039,7 +4030,7 @@ PlayerSAO* Server::emergePlayer(const char *name, session_t peer_id, u16 proto_v RemotePlayer *player = m_env->getPlayer(name); // If player is already connected, cancel - if (player && player->getPeerId() != PEER_ID_INEXISTENT) { + if (player) { infostream<<"emergePlayer(): Player already connected"<getPlayer(name.c_str()); // if player is connected, send him the inventory - if (p && p->getPeerId() != PEER_ID_INEXISTENT) { + if (p) { m_env->getGameDef()->sendDetachedInventory( inv, name, p->getPeerId()); } @@ -152,7 +152,7 @@ bool ServerInventoryManager::removeDetachedInventory(const std::string &name) if (m_env) { RemotePlayer *player = m_env->getPlayer(owner.c_str()); - if (player && player->getPeerId() != PEER_ID_INEXISTENT) + if (player) m_env->getGameDef()->sendDetachedInventory( nullptr, name, player->getPeerId()); } diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 6d394309c..df5fb5e12 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -584,13 +584,17 @@ RemotePlayer *ServerEnvironment::getPlayer(const session_t peer_id) return NULL; } -RemotePlayer *ServerEnvironment::getPlayer(const char* name) +RemotePlayer *ServerEnvironment::getPlayer(const char* name, bool match_invalid_peer) { for (RemotePlayer *player : m_players) { - if (strcmp(player->getName(), name) == 0) + if (strcmp(player->getName(), name) != 0) + continue; + + if (match_invalid_peer || player->getPeerId() != PEER_ID_INEXISTENT) return player; + break; } - return NULL; + return nullptr; } void ServerEnvironment::addPlayer(RemotePlayer *player) diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 4a4872a8b..000f5f81f 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -388,7 +388,7 @@ public: bool static_exists, v3s16 static_block=v3s16(0,0,0)); RemotePlayer *getPlayer(const session_t peer_id); - RemotePlayer *getPlayer(const char* name); + RemotePlayer *getPlayer(const char* name, bool match_invalid_peer = false); const std::vector getPlayers() const { return m_players; } u32 getPlayerCount() const { return m_players.size(); } From f07e1026acecc5eba4cda0a223dc67deb1a88e36 Mon Sep 17 00:00:00 2001 From: grorp Date: Tue, 12 Mar 2024 20:09:43 +0100 Subject: [PATCH 35/91] Allow sync HTTP fetches to be interrupted to fix hanging (#14412) Co-authored-by: Jude Melton-Houghton --- src/gui/guiEngine.cpp | 6 ++++-- src/httpfetch.cpp | 32 ++++++++++++++++++++++++++++---- src/httpfetch.h | 9 ++++++--- src/script/lua_api/l_http.cpp | 4 ++-- src/threading/thread.cpp | 11 +++++++++++ src/threading/thread.h | 5 +++++ 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index e70f4529d..ea74f6afa 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -629,13 +629,15 @@ bool GUIEngine::downloadFile(const std::string &url, const std::string &target) fetch_request.caller = HTTPFETCH_SYNC; fetch_request.timeout = std::max(MIN_HTTPFETCH_TIMEOUT, (long)g_settings->getS32("curl_file_download_timeout")); - httpfetch_sync(fetch_request, fetch_result); + bool completed = httpfetch_sync_interruptible(fetch_request, fetch_result); - if (!fetch_result.succeeded) { + if (!completed || !fetch_result.succeeded) { target_file.close(); fs::DeleteSingleFileOrEmptyDirectory(target); return false; } + // TODO: directly stream the response data into the file instead of first + // storing the complete response in memory target_file << fetch_result.data; return true; diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index b5fece2e6..2212ba453 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "exceptions.h" #include "debug.h" #include "log.h" +#include "porting.h" #include "util/container.h" #include "util/thread.h" #include "version.h" @@ -753,7 +754,7 @@ static void httpfetch_request_clear(u64 caller) } } -void httpfetch_sync(const HTTPFetchRequest &fetch_request, +static void httpfetch_sync(const HTTPFetchRequest &fetch_request, HTTPFetchResult &fetch_result) { // Create ongoing fetch data and make a cURL handle @@ -766,6 +767,28 @@ void httpfetch_sync(const HTTPFetchRequest &fetch_request, fetch_result = *ongoing.complete(res); } +bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request, + HTTPFetchResult &fetch_result, long interval) +{ + if (Thread *thread = Thread::getCurrentThread()) { + HTTPFetchRequest req = fetch_request; + req.caller = httpfetch_caller_alloc_secure(); + httpfetch_async(req); + do { + if (thread->stopRequested()) { + httpfetch_caller_free(req.caller); + fetch_result = HTTPFetchResult(fetch_request); + return false; + } + sleep_ms(interval); + } while (!httpfetch_async_get(req.caller, fetch_result)); + httpfetch_caller_free(req.caller); + } else { + httpfetch_sync(fetch_request, fetch_result); + } + return true; +} + #else // USE_CURL /* @@ -795,13 +818,14 @@ static void httpfetch_request_clear(u64 caller) { } -void httpfetch_sync(const HTTPFetchRequest &fetch_request, - HTTPFetchResult &fetch_result) +bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request, + HTTPFetchResult &fetch_result, long interval) { - errorstream << "httpfetch_sync: unable to fetch " << fetch_request.url + errorstream << "httpfetch_sync_interruptible: unable to fetch " << fetch_request.url << " because USE_CURL=0" << std::endl; fetch_result = HTTPFetchResult(fetch_request); // sets succeeded = false etc. + return false; } #endif // USE_CURL diff --git a/src/httpfetch.h b/src/httpfetch.h index 930ce591c..88a4cd727 100644 --- a/src/httpfetch.h +++ b/src/httpfetch.h @@ -135,6 +135,9 @@ u64 httpfetch_caller_alloc_secure(); // to stop any ongoing fetches for the given caller. void httpfetch_caller_free(u64 caller); -// Performs a synchronous HTTP request. This blocks and therefore should -// only be used from background threads. -void httpfetch_sync(const HTTPFetchRequest &fetch_request, HTTPFetchResult &fetch_result); +// Performs a synchronous HTTP request that is interruptible if the current +// thread is a Thread object. interval is the completion check interval in ms. +// This blocks and therefore should only be used from background threads. +// Returned is whether the request completed without interruption. +bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request, + HTTPFetchResult &fetch_result, long interval = 100); diff --git a/src/script/lua_api/l_http.cpp b/src/script/lua_api/l_http.cpp index 5566a8523..57f632291 100644 --- a/src/script/lua_api/l_http.cpp +++ b/src/script/lua_api/l_http.cpp @@ -114,9 +114,9 @@ int ModApiHttp::l_http_fetch_sync(lua_State *L) infostream << "Mod performs HTTP request with URL " << req.url << std::endl; HTTPFetchResult res; - httpfetch_sync(req, res); + bool completed = httpfetch_sync_interruptible(req, res); - push_http_fetch_result(L, res, true); + push_http_fetch_result(L, res, completed); return 1; } diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index 6fef3683c..21143f231 100644 --- a/src/threading/thread.cpp +++ b/src/threading/thread.cpp @@ -62,6 +62,9 @@ DEALINGS IN THE SOFTWARE. // See https://msdn.microsoft.com/en-us/library/hh920601.aspx#thread__native_handle_method #define win32_native_handle() ((HANDLE) getThreadHandle()) +thread_local Thread *current_thread = nullptr; + + Thread::Thread(const std::string &name) : m_name(name), m_request_stop(false), @@ -177,6 +180,8 @@ void Thread::threadProc(Thread *thr) thr->m_kernel_thread_id = thread_self(); #endif + current_thread = thr; + thr->setName(thr->m_name); g_logger.registerThread(thr->m_name); @@ -197,6 +202,12 @@ void Thread::threadProc(Thread *thr) } +Thread *Thread::getCurrentThread() +{ + return current_thread; +} + + void Thread::setName(const std::string &name) { #if defined(__linux__) diff --git a/src/threading/thread.h b/src/threading/thread.h index 45fb171da..2d0641b43 100644 --- a/src/threading/thread.h +++ b/src/threading/thread.h @@ -119,6 +119,11 @@ public: */ bool setPriority(int prio); + /* + * Returns the thread object of the current thread if it exists. + */ + static Thread *getCurrentThread(); + /* * Sets the currently executing thread's name to where supported; useful * for debugging. From 60810c2d375a8c63e096669dd6c6cd791f2c5075 Mon Sep 17 00:00:00 2001 From: cx384 Date: Tue, 12 Mar 2024 20:10:28 +0100 Subject: [PATCH 36/91] Add L-system trees as decorations (#14355) --- builtin/game/features.lua | 1 + doc/lua_api.md | 16 +++++++++++- src/mapgen/mg_decoration.cpp | 22 ++++++++++++++++ src/mapgen/mg_decoration.h | 14 ++++++---- src/mapgen/treegen.cpp | 10 +++++++ src/mapgen/treegen.h | 4 ++- src/script/common/c_content.cpp | 46 +++++++++++++++++++++++++++++++++ src/script/common/c_content.h | 5 ++++ src/script/lua_api/l_env.cpp | 39 ---------------------------- src/script/lua_api/l_mapgen.cpp | 14 ++++++++++ 10 files changed, 125 insertions(+), 46 deletions(-) diff --git a/builtin/game/features.lua b/builtin/game/features.lua index 68005811f..0b5b40fb5 100644 --- a/builtin/game/features.lua +++ b/builtin/game/features.lua @@ -37,6 +37,7 @@ core.features = { blocking_pointability_type = true, dynamic_add_media_startup = true, dynamic_add_media_filepath = true, + lsystem_decoration_type = true, } function core.has_feature(arg) diff --git a/doc/lua_api.md b/doc/lua_api.md index f01e3cd35..13f4571ff 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -4533,6 +4533,12 @@ Can specify a probability of a node randomly appearing when placed. This decoration type is intended to be used for multi-node sized discrete structures, such as trees, cave spikes, rocks, and so on. +`lsystem` +----------- + +Generates a L-system tree at the position where the decoration is placed. +Uses the same L-system as `minetest.spawn_tree`, but is faster than using it manually. +The `treedef` field in the decoration definition is used for the tree definition. @@ -5376,6 +5382,8 @@ Utilities dynamic_add_media_startup = true, -- dynamic_add_media supports `filename` and `filedata` parameters (5.9.0) dynamic_add_media_filepath = true, + -- L-system decoration type (5.9.0) + lsystem_decoration_type = true, } ``` @@ -10134,7 +10142,7 @@ See [Decoration types]. Used by `minetest.register_decoration`. ```lua { deco_type = "simple", - -- Type. "simple" or "schematic" supported + -- Type. "simple", "schematic" or "lsystem" supported place_on = "default:dirt_with_grass", -- Node (or list of nodes) that the decoration can be placed on @@ -10287,6 +10295,12 @@ See [Decoration types]. Used by `minetest.register_decoration`. -- Effect is inverted for "all_ceilings" decorations. -- Ignored by 'y_min', 'y_max' and 'spawn_by' checks, which always refer -- to the 'place_on' node. + + ----- L-system-type parameters + + treedef = {}, + -- Same as for `minetest.spawn_tree`. + -- See section [L-system trees] for more details. } ``` diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index e9e249220..da364e4a1 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include #include +#include "mapgen/treegen.h" FlagDesc flagdesc_deco[] = { @@ -472,3 +473,24 @@ size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceilin return 1; } + +/////////////////////////////////////////////////////////////////////////////// +ObjDef *DecoLSystem::clone() const +{ + auto def = new DecoLSystem(); + Decoration::cloneTo(def); + + def->tree_def = tree_def; + return def; +} + + +size_t DecoLSystem::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) +{ + if (!canPlaceDecoration(vm, p)) + return 0; + + // Make sure that tree_def can't be modified, since it is shared. + const auto &ref = *tree_def; + return treegen::make_ltree(*vm, p, m_ndef, ref); +} diff --git a/src/mapgen/mg_decoration.h b/src/mapgen/mg_decoration.h index 89d8d355f..41d0dac64 100644 --- a/src/mapgen/mg_decoration.h +++ b/src/mapgen/mg_decoration.h @@ -31,6 +31,7 @@ class Mapgen; class MMVManip; class PcgRandom; class Schematic; +namespace treegen { struct TreeDef; } enum DecorationType { DECO_SIMPLE, @@ -112,12 +113,15 @@ public: }; -/* class DecoLSystem : public Decoration { public: - virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + ObjDef *clone() const; + + virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling); + + // In case it gets cloned it uses the same tree def. + std::shared_ptr tree_def; }; -*/ class DecorationManager : public ObjDefManager { @@ -139,8 +143,8 @@ public: return new DecoSimple; case DECO_SCHEMATIC: return new DecoSchematic; - //case DECO_LSYSTEM: - // return new DecoLSystem; + case DECO_LSYSTEM: + return new DecoLSystem; default: return NULL; } diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index 2c1266431..adff72950 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -32,6 +32,16 @@ with this program; if not, write to the Free Software Foundation, Inc., namespace treegen { +void TreeDef::resolveNodeNames() +{ + getIdFromNrBacklog(&trunknode.param0, "", CONTENT_IGNORE); + getIdFromNrBacklog(&leavesnode.param0, "", CONTENT_IGNORE); + if (leaves2_chance) + getIdFromNrBacklog(&leaves2node.param0, "", CONTENT_IGNORE); + if (fruit_chance) + getIdFromNrBacklog(&fruitnode.param0, "", CONTENT_IGNORE); +} + void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, const NodeDefManager *ndef, s32 seed) { diff --git a/src/mapgen/treegen.h b/src/mapgen/treegen.h index 59a418824..5ba1cc10c 100644 --- a/src/mapgen/treegen.h +++ b/src/mapgen/treegen.h @@ -35,7 +35,9 @@ namespace treegen { UNBALANCED_BRACKETS }; - struct TreeDef { + struct TreeDef : public NodeResolver { + virtual void resolveNodeNames(); + std::string initial_axiom; std::string rules_a; std::string rules_b; diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index d9f179112..02f69b3e1 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "debug.h" // For FATAL_ERROR #include #include +#include "mapgen/treegen.h" struct EnumString es_TileAnimationType[] = { @@ -2006,6 +2007,51 @@ void push_noiseparams(lua_State *L, NoiseParams *np) lua_setfield(L, -2, "spread"); } +bool read_tree_def(lua_State *L, int idx, const NodeDefManager *ndef, + treegen::TreeDef &tree_def) +{ + std::string trunk, leaves, fruit; + if (!lua_istable(L, idx)) + return false; + + getstringfield(L, idx, "axiom", tree_def.initial_axiom); + getstringfield(L, idx, "rules_a", tree_def.rules_a); + getstringfield(L, idx, "rules_b", tree_def.rules_b); + getstringfield(L, idx, "rules_c", tree_def.rules_c); + getstringfield(L, idx, "rules_d", tree_def.rules_d); + getstringfield(L, idx, "trunk", trunk); + tree_def.m_nodenames.push_back(trunk); + getstringfield(L, idx, "leaves", leaves); + tree_def.m_nodenames.push_back(leaves); + tree_def.leaves2_chance = 0; + getstringfield(L, idx, "leaves2", leaves); + if (!leaves.empty()) { + getintfield(L, idx, "leaves2_chance", tree_def.leaves2_chance); + if (tree_def.leaves2_chance) + tree_def.m_nodenames.push_back(leaves); + } + getintfield(L, idx, "angle", tree_def.angle); + getintfield(L, idx, "iterations", tree_def.iterations); + if (!getintfield(L, idx, "random_level", tree_def.iterations_random_level)) + tree_def.iterations_random_level = 0; + getstringfield(L, idx, "trunk_type", tree_def.trunk_type); + getboolfield(L, idx, "thin_branches", tree_def.thin_branches); + tree_def.fruit_chance = 0; + getstringfield(L, idx, "fruit", fruit); + if (!fruit.empty()) { + getintfield(L, idx, "fruit_chance", tree_def.fruit_chance); + if (tree_def.fruit_chance) + tree_def.m_nodenames.push_back(fruit); + } + tree_def.explicit_seed = getintfield(L, idx, "seed", tree_def.seed); + + // Resolves the node IDs for trunk, leaves, leaves2 and fruit at runtime, + // when tree_def.resolveNodeNames will be called. + ndef->pendNodeResolve(&tree_def); + + return true; +} + /******************************************************************************/ // Returns depth of json value tree static int push_json_value_getdepth(const Json::Value &value) diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index c8481d98d..178a86cf4 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -70,6 +70,7 @@ struct NoiseParams; class Schematic; class ServerActiveObject; struct collisionMoveResult; +namespace treegen { struct TreeDef; } extern struct EnumString es_TileAnimationType[]; @@ -189,6 +190,10 @@ bool read_noiseparams (lua_State *L, int index, NoiseParams *np); void push_noiseparams (lua_State *L, NoiseParams *np); +bool read_tree_def (lua_State *L, int idx, + const NodeDefManager *ndef, + treegen::TreeDef &tree_def); + void luaentity_get (lua_State *L,u16 id); bool push_json_value (lua_State *L, diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index ccf2cd653..37aba7500 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -1331,45 +1331,6 @@ int ModApiEnv::l_find_path(lua_State *L) return 0; } -static bool read_tree_def(lua_State *L, int idx, - const NodeDefManager *ndef, treegen::TreeDef &tree_def) -{ - std::string trunk, leaves, fruit; - if (!lua_istable(L, idx)) - return false; - - getstringfield(L, idx, "axiom", tree_def.initial_axiom); - getstringfield(L, idx, "rules_a", tree_def.rules_a); - getstringfield(L, idx, "rules_b", tree_def.rules_b); - getstringfield(L, idx, "rules_c", tree_def.rules_c); - getstringfield(L, idx, "rules_d", tree_def.rules_d); - getstringfield(L, idx, "trunk", trunk); - tree_def.trunknode = ndef->getId(trunk); - getstringfield(L, idx, "leaves", leaves); - tree_def.leavesnode = ndef->getId(leaves); - tree_def.leaves2_chance = 0; - getstringfield(L, idx, "leaves2", leaves); - if (!leaves.empty()) { - tree_def.leaves2node = ndef->getId(leaves); - getintfield(L, idx, "leaves2_chance", tree_def.leaves2_chance); - } - getintfield(L, idx, "angle", tree_def.angle); - getintfield(L, idx, "iterations", tree_def.iterations); - if (!getintfield(L, idx, "random_level", tree_def.iterations_random_level)) - tree_def.iterations_random_level = 0; - getstringfield(L, idx, "trunk_type", tree_def.trunk_type); - getboolfield(L, idx, "thin_branches", tree_def.thin_branches); - tree_def.fruit_chance = 0; - getstringfield(L, idx, "fruit", fruit); - if (!fruit.empty()) { - tree_def.fruitnode = ndef->getId(fruit); - getintfield(L, idx, "fruit_chance", tree_def.fruit_chance); - } - tree_def.explicit_seed = getintfield(L, idx, "seed", tree_def.seed); - - return true; -} - // spawn_tree(pos, treedef) int ModApiEnv::l_spawn_tree(lua_State *L) { diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index b8c6e7105..0dcf7b68a 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen/mg_schematic.h" #include "mapgen/mapgen_v5.h" #include "mapgen/mapgen_v7.h" +#include "mapgen/treegen.h" #include "filesys.h" #include "settings.h" #include "log.h" @@ -110,6 +111,7 @@ bool read_schematic_def(lua_State *L, int index, bool read_deco_simple(lua_State *L, DecoSimple *deco); bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic *deco); +bool read_deco_lsystem(lua_State *L, const NodeDefManager *ndef, DecoLSystem *deco); /////////////////////////////////////////////////////////////////////////////// @@ -1226,6 +1228,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L) success = read_deco_schematic(L, schemmgr, (DecoSchematic *)deco); break; case DECO_LSYSTEM: + success = read_deco_lsystem(L, ndef, (DecoLSystem *)deco); break; } @@ -1308,6 +1311,17 @@ bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic return schem != NULL; } +bool read_deco_lsystem(lua_State *L, const NodeDefManager *ndef, DecoLSystem *deco) +{ + deco->tree_def = std::make_shared(); + + lua_getfield(L, 1, "treedef"); + bool has_def = read_tree_def(L, -1, ndef, *(deco->tree_def)); + lua_pop(L, 1); + + return has_def; +} + // register_ore({lots of stuff}) int ModApiMapgen::l_register_ore(lua_State *L) From 658bc9fcc896b6987cc7401992c3cb703fbf048e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 13 Mar 2024 21:24:35 +0100 Subject: [PATCH 37/91] Fix infinite loop in Server::stopAttachedSounds --- src/server.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 19d92316c..8cf3d37ee 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2288,22 +2288,25 @@ void Server::stopAttachedSounds(session_t peer_id, u16 object_id) assert(peer_id != PEER_ID_INEXISTENT); assert(object_id); - for (auto it = m_playing_sounds.begin(); it != m_playing_sounds.end();) { - ServerPlayingSound &sound = it->second; - + auto cb = [&] (const s32 id, ServerPlayingSound &sound) -> bool { if (sound.object != object_id) - continue; + return false; auto clients_it = sound.clients.find(peer_id); if (clients_it == sound.clients.end()) - continue; + return false; NetworkPacket pkt(TOCLIENT_STOP_SOUND, 4); - pkt << it->first; + pkt << id; Send(peer_id, &pkt); sound.clients.erase(clients_it); - if (sound.clients.empty()) + // delete if client list empty + return sound.clients.empty(); + }; + + for (auto it = m_playing_sounds.begin(); it != m_playing_sounds.end(); ) { + if (cb(it->first, it->second)) it = m_playing_sounds.erase(it); else ++it; From d5d6e36ae0790c5e6b6e896ee04726ae5d6cda09 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 15 Mar 2024 11:24:08 +0100 Subject: [PATCH 38/91] Create CACHEDIR.TAG in path_cache (#14458) --- src/porting.cpp | 23 ++++++++++++++++++++++- src/porting.h | 6 ------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/porting.cpp b/src/porting.cpp index e2cc3dffd..db769d901 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -553,7 +553,8 @@ bool setSystemPaths() #endif -void migrateCachePath() +// Move cache folder from path_user to system cache location if possible. +[[maybe_unused]] static void migrateCachePath() { const std::string local_cache_path = path_user + DIR_DELIM + "cache"; @@ -573,6 +574,24 @@ void migrateCachePath() } } +// Create tag in cache folder according to spec +static void createCacheDirTag() +{ + const auto path = path_cache + DIR_DELIM + "CACHEDIR.TAG"; + + if (fs::PathExists(path)) + return; + fs::CreateAllDirs(path_cache); + std::ofstream ofs(path, std::ios::out | std::ios::binary); + if (!ofs.good()) + return; + ofs << "Signature: 8a477f597d28d172789f06886806bc55\n" + "# This file is a cache directory tag automatically created by " + PROJECT_NAME_C ".\n" + "# For information about cache directory tags, see: " + "https://bford.info/cachedir/\n"; +} + void initializePaths() { #if RUN_IN_PLACE @@ -652,6 +671,8 @@ void initializePaths() infostream << "Detected user path: " << path_user << std::endl; infostream << "Detected cache path: " << path_cache << std::endl; + createCacheDirTag(); + #if USE_GETTEXT bool found_localedir = false; # ifdef STATIC_LOCALEDIR diff --git a/src/porting.h b/src/porting.h index 004459bff..db9a99a97 100644 --- a/src/porting.h +++ b/src/porting.h @@ -129,12 +129,6 @@ bool getCurrentExecPath(char *buf, size_t len); */ std::string getDataPath(const char *subpath); -/* - Move cache folder from path_user to the - system cache location if possible. -*/ -void migrateCachePath(); - /* Initialize path_*. */ From 4245a7604b96b516b747e22f1410dee825922af1 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Tue, 26 Jul 2022 20:40:27 +0200 Subject: [PATCH 39/91] Inventory: Fix order of callbacks when swapping items --- doc/lua_api.md | 13 +++ games/devtest/mods/chest/chest.lua | 15 +++- src/inventory.cpp | 39 ++++---- src/inventory.h | 4 +- src/inventorymanager.cpp | 140 +++++++++++++++-------------- src/inventorymanager.h | 3 +- 6 files changed, 119 insertions(+), 95 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 13f4571ff..3a5f0460e 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -3640,6 +3640,19 @@ Player Inventory lists * Is not created automatically, use `InvRef:set_size` * Is only used to enhance the empty hand's tool capabilities +ItemStack transaction order +--------------------------- + +This list describes the situation for non-empty ItemStacks in both slots +that cannot be stacked at all, hence triggering an ItemStack swap operation. +Put/take callbacks on empty ItemStack are not executed. + +1. The "allow take" and "allow put" callbacks are each run once for the source + and destination inventory. +2. The allowed ItemStacks are exchanged. +3. The "on take" callbacks are run for the source and destination inventories +4. The "on put" callbacks are run for the source and destination inventories + Colors ====== diff --git a/games/devtest/mods/chest/chest.lua b/games/devtest/mods/chest/chest.lua index e347459ed..1f165fed4 100644 --- a/games/devtest/mods/chest/chest.lua +++ b/games/devtest/mods/chest/chest.lua @@ -29,12 +29,16 @@ minetest.register_node("chest:chest", { return inv:is_empty("main") end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) - print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow put' event for " .. stack:to_string()) - return stack:get_count() + print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow put' (10) event for " .. stack:to_string()) + return 10 end, allow_metadata_inventory_take = function(pos, listname, index, stack, player) - print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow take' event for " .. stack:to_string()) - return stack:get_count() + print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow take' (20) event for " .. stack:to_string()) + return 20 + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow move' (30) event") + return 30 end, on_metadata_inventory_put = function(pos, listname, index, stack, player) print_to_everything("Chest: ".. player:get_player_name() .. " put " .. stack:to_string()) @@ -42,4 +46,7 @@ minetest.register_node("chest:chest", { on_metadata_inventory_take = function(pos, listname, index, stack, player) print_to_everything("Chest: ".. player:get_player_name() .. " took " .. stack:to_string()) end, + on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + print_to_everything("Chest: ".. player:get_player_name() .. " moved " .. count) + end, }) diff --git a/src/inventory.cpp b/src/inventory.cpp index 2440c7f0c..65bbe0390 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -758,54 +758,53 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count) if (!leftover.empty()) { // Add the remaining part back to the source item - addItem(i, leftover); + ItemStack &source = getItem(i); + source.add(leftover.count); // do NOT use addItem to allow oversized stacks! } } -u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, +ItemStack InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count, bool swap_if_needed, bool *did_swap) { + ItemStack moved; if (this == dest && i == dest_i) - return count; + return moved; // Take item from source list - ItemStack item1; if (count == 0) - item1 = changeItem(i, ItemStack()); + moved = changeItem(i, ItemStack()); else - item1 = takeItem(i, count); - - if (item1.empty()) - return 0; + moved = takeItem(i, count); // Try to add the item to destination list - count = item1.count; - item1 = dest->addItem(dest_i, item1); + ItemStack leftover = dest->addItem(dest_i, moved); // If something is returned, the item was not fully added - if (!item1.empty()) { - bool nothing_added = (item1.count == count); + if (!leftover.empty()) { + // Keep track of how many we actually moved + moved.remove(leftover.count); // Add any leftover stack back to the source stack. - item1.add(getItem(i).count); // leftover + source count - changeItem(i, item1); // do NOT use addItem to allow oversized stacks! + leftover.add(getItem(i).count); // leftover + source count + changeItem(i, leftover); // do NOT use addItem to allow oversized stacks! + leftover.clear(); // Swap if no items could be moved - if (nothing_added && swap_if_needed) { + if (moved.empty() && swap_if_needed) { // Tell that we swapped if (did_swap != NULL) { *did_swap = true; } // Take item from source list - item1 = changeItem(i, ItemStack()); + moved = changeItem(i, ItemStack()); // Adding was not possible, swap the items. - ItemStack item2 = dest->changeItem(dest_i, item1); + ItemStack item2 = dest->changeItem(dest_i, moved); // Put item from destination list to the source list changeItem(i, item2); - item1.clear(); // no leftover } } - return (count - item1.count); + + return moved; } void InventoryList::checkResizeLock() diff --git a/src/inventory.h b/src/inventory.h index e92893a8e..9f7265b76 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -286,8 +286,8 @@ public: // Move an item to a different list (or a different stack in the same list) // count is the maximum number of items to move (0 for everything) - // returns number of moved items - u32 moveItem(u32 i, InventoryList *dest, u32 dest_i, + // returns the moved stack + ItemStack moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count = 0, bool swap_if_needed = true, bool *did_swap = NULL); // like moveItem, but without a fixed destination index diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index 75d3936a9..6c66fd351 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -162,7 +162,20 @@ void IMoveAction::swapDirections() std::swap(from_i, to_i); } -void IMoveAction::onPutAndOnTake(const ItemStack &src_item, ServerActiveObject *player) const +void IMoveAction::onTake(const ItemStack &src_item, ServerActiveObject *player) const +{ + ServerScripting *sa = PLAYER_TO_SA(player); + if (from_inv.type == InventoryLocation::DETACHED) + sa->detached_inventory_OnTake(*this, src_item, player); + else if (from_inv.type == InventoryLocation::NODEMETA) + sa->nodemeta_inventory_OnTake(*this, src_item, player); + else if (from_inv.type == InventoryLocation::PLAYER) + sa->player_inventory_OnTake(*this, src_item, player); + else + assert(false); +} + +void IMoveAction::onPut(const ItemStack &src_item, ServerActiveObject *player) const { ServerScripting *sa = PLAYER_TO_SA(player); if (to_inv.type == InventoryLocation::DETACHED) @@ -173,15 +186,6 @@ void IMoveAction::onPutAndOnTake(const ItemStack &src_item, ServerActiveObject * sa->player_inventory_OnPut(*this, src_item, player); else assert(false); - - if (from_inv.type == InventoryLocation::DETACHED) - sa->detached_inventory_OnTake(*this, src_item, player); - else if (from_inv.type == InventoryLocation::NODEMETA) - sa->nodemeta_inventory_OnTake(*this, src_item, player); - else if (from_inv.type == InventoryLocation::PLAYER) - sa->player_inventory_OnTake(*this, src_item, player); - else - assert(false); } void IMoveAction::onMove(int count, ServerActiveObject *player) const @@ -244,6 +248,8 @@ int IMoveAction::allowMove(int try_take_count, ServerActiveObject *player) const void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef) { + /// Necessary for executing Lua callbacks which may manipulate the inventory, + /// hence invalidate pointers needed by IMoveAction::apply auto get_borrow_checked_invlist = [mgr](const InventoryLocation &invloc, const std::string &listname) -> InventoryList::ResizeLocked { @@ -375,6 +381,8 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame bool allow_swap = !list_to->itemFits(to_i, src_item, &restitem) && restitem.count == src_item.count && !caused_by_move_somewhere; + // move_count : How many items that were moved at the end + // count : Total items "in the queue" of being moved. Do not touch. move_count = src_item.count - restitem.count; // Shift-click: Cannot fill this stack, proceed with next slot @@ -383,10 +391,11 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame } if (allow_swap) { - // Swap will affect the entire stack if it can performed. + // Swap will affect the entire stack (= count) if it can performed. src_item = list_from->getItem(from_i); - count = src_item.count; + move_count = src_item.count; } + src_item.count = move_count; // Temporary movement stack if (from_inv == to_inv) { // Move action within the same inventory @@ -409,16 +418,9 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame src_can_take_count = dst_can_put_count = 0; } else { // Take from one inventory, put into another - int src_item_count = src_item.count; - if (caused_by_move_somewhere) - // When moving somewhere: temporarily use the actual movable stack - // size to ensure correct callback execution. - src_item.count = move_count; dst_can_put_count = allowPut(src_item, player); src_can_take_count = allowTake(src_item, player); - if (caused_by_move_somewhere) - // Reset source item count - src_item.count = src_item_count; + bool swap_expected = allow_swap; allow_swap = allow_swap && (src_can_take_count == -1 || src_can_take_count >= src_item.count) @@ -440,25 +442,20 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame src_can_take_count = dst_can_put_count = 0; } - int old_count = count; + int old_move_count = move_count; - /* Modify count according to collected data */ - count = src_item.count; - if (src_can_take_count != -1 && count > src_can_take_count) - count = src_can_take_count; - if (dst_can_put_count != -1 && count > dst_can_put_count) - count = dst_can_put_count; + // Apply limits given by allow_* callbacks + if (src_can_take_count != -1) + move_count = (u32)std::min(src_can_take_count, move_count); + if (dst_can_put_count != -1) + move_count = (u32)std::min(dst_can_put_count, move_count); - /* Limit according to source item count */ - if (count > list_from->getItem(from_i).count) - count = list_from->getItem(from_i).count; + // allow_* callbacks should not modify the stack - but if they do - handle that. + if (move_count > list_from->getItem(from_i).count) + move_count = list_from->getItem(from_i).count; /* If no items will be moved, don't go further */ - if (count == 0) { - if (caused_by_move_somewhere) - // Set move count to zero, as no items have been moved - move_count = 0; - + if (move_count == 0) { // Undo client prediction. See 'clientApply' if (from_inv.type == InventoryLocation::PLAYER) list_from->setModified(); @@ -467,7 +464,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame list_to->setModified(); infostream<<"IMoveAction::apply(): move was completely disallowed:" - <<" count="<getItem(from_i); @@ -603,26 +599,34 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame } mgr->setInventoryModified(from_inv); } else { - int src_item_count = src_item.count; - if (caused_by_move_somewhere) - // When moving somewhere: temporarily use the actual movable stack - // size to ensure correct callback execution. - src_item.count = move_count; - onPutAndOnTake(src_item, player); - if (caused_by_move_somewhere) - // Reset source item count - src_item.count = src_item_count; + ItemStack swap_item; if (did_swap) { - // Item is now placed in source list + // Already swapped. The other stack is now placed in "from" list list_from = get_borrow_checked_invlist(from_inv, from_list); if (list_from) { - src_item = list_from->getItem(from_i); + swap_item = list_from->getItem(from_i); list_from.reset(); - swapDirections(); - onPutAndOnTake(src_item, player); - swapDirections(); } } + + // 1. Take the ItemStack (visually: freely detached) + onTake(src_item, player); + if (!swap_item.empty() && get_borrow_checked_invlist(to_inv, to_list)) { + swapDirections(); + onTake(swap_item, player); + swapDirections(); + } + + // 2. Put the ItemStack + if (get_borrow_checked_invlist(to_inv, to_list)) + onPut(src_item, player); + + if (!swap_item.empty() && get_borrow_checked_invlist(to_inv, to_list)) { + swapDirections(); + onPut(swap_item, player); + swapDirections(); + } + mgr->setInventoryModified(to_inv); mgr->setInventoryModified(from_inv); } diff --git a/src/inventorymanager.h b/src/inventorymanager.h index 704a493fd..8bc44f483 100644 --- a/src/inventorymanager.h +++ b/src/inventorymanager.h @@ -191,7 +191,8 @@ struct IMoveAction : public InventoryAction, public MoveAction void swapDirections(); - void onPutAndOnTake(const ItemStack &src_item, ServerActiveObject *player) const; + void onTake(const ItemStack &src_item, ServerActiveObject *player) const; + void onPut(const ItemStack &src_item, ServerActiveObject *player) const; void onMove(int count, ServerActiveObject *player) const; From 61a57336920e0f64361a4c48215b12969c3a1eff Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 29 Sep 2022 22:16:29 +0200 Subject: [PATCH 40/91] Unittest: Add inventory callback tests --- builtin/game/tests/test_moveaction.lua | 84 ++++++++++++++++++ src/script/cpp_api/s_base.h | 1 + src/server.h | 3 + src/server/serverinventorymgr.h | 7 +- src/unittest/mock_inventorymanager.h | 17 ++-- src/unittest/mock_server.h | 2 + src/unittest/test_moveaction.cpp | 114 ++++++++++++++++++------- 7 files changed, 187 insertions(+), 41 deletions(-) create mode 100644 builtin/game/tests/test_moveaction.lua diff --git a/builtin/game/tests/test_moveaction.lua b/builtin/game/tests/test_moveaction.lua new file mode 100644 index 000000000..476579348 --- /dev/null +++ b/builtin/game/tests/test_moveaction.lua @@ -0,0 +1,84 @@ +-- Table to keep track of callback executions +-- [i + 0] = count of expected patterns of index (i + 1) +-- [i + 1] = pattern to check +local PATTERN_NORMAL = { 4, "allow_%w", 2, "on_take", 1, "on_put", 1 } +local PATTERN_SWAP = { 8, "allow_%w", 4, "on_take", 2, "on_put", 2 } +local exec_listing = {} -- List of logged callbacks (e.g. "on_take", "allow_put") + +-- Checks whether the logged callbacks equal the expected pattern +core.__helper_check_callbacks = function(expect_swap) + local exec_pattern = expect_swap and PATTERN_SWAP or PATTERN_NORMAL + local ok = #exec_listing == exec_pattern[1] + if ok then + local list_index = 1 + for i = 2, #exec_pattern, 2 do + for n = 1, exec_pattern[i + 1] do + -- Match the list for "n" occurrences of the wanted callback name pattern + ok = exec_listing[list_index]:find(exec_pattern[i]) + list_index = list_index + 1 + if not ok then break end + end + if not ok then break end + end + end + + if not ok then + print("Execution order mismatch!") + print("Expected patterns: ", dump(exec_pattern)) + print("Got list: ", dump(exec_listing)) + end + exec_listing = {} + return ok +end + +-- Uncomment the other line for easier callback debugging +local log = function(...) end +--local log = print + +minetest.register_allow_player_inventory_action(function(_, action, inv, info) + log("\tallow " .. action, info.count or info.stack:to_string()) + + if action == "move" then + -- testMoveFillStack + return info.count + end + + if action == "take" or action == "put" then + assert(not info.stack:is_empty(), "Stack empty in: " .. action) + + -- testMoveUnallowed + -- testSwapFromUnallowed + -- testSwapToUnallowed + if info.stack:get_name() == "default:takeput_deny" then + return 0 + end + + -- testMovePartial + if info.stack:get_name() == "default:takeput_max_5" then + return 5 + end + + -- testCallbacks + if info.stack:get_name():find("default:takeput_cb_%d") then + -- Log callback as executed + table.insert(exec_listing, "allow_" .. action) + return -- Unlimited + end + end + + return -- Unlimited +end) + +minetest.register_on_player_inventory_action(function(_, action, inv, info) + log("\ton " .. action, info.count or info.stack:to_string()) + + if action == "take" or action == "put" then + assert(not info.stack:is_empty(), action) + + if info.stack:get_name():find("default:takeput_cb_%d") then + -- Log callback as executed + table.insert(exec_listing, "on_" .. action) + return + end + end +end) diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h index cacc79a83..ac74c2e68 100644 --- a/src/script/cpp_api/s_base.h +++ b/src/script/cpp_api/s_base.h @@ -146,6 +146,7 @@ protected: friend class ModApiBase; friend class ModApiEnv; friend class LuaVoxelManip; + friend class TestMoveAction; // needs getStack() /* Subtle edge case with coroutines: If for whatever reason you have a diff --git a/src/server.h b/src/server.h index 9f9f08ac7..bd1547238 100644 --- a/src/server.h +++ b/src/server.h @@ -434,7 +434,10 @@ public: private: friend class EmergeThread; friend class RemoteClient; + + // unittest classes friend class TestServerShutdownState; + friend class TestMoveAction; struct ShutdownState { friend class TestServerShutdownState; diff --git a/src/server/serverinventorymgr.h b/src/server/serverinventorymgr.h index b54f6edd6..9b654c507 100644 --- a/src/server/serverinventorymgr.h +++ b/src/server/serverinventorymgr.h @@ -40,8 +40,9 @@ public: m_env = env; } - Inventory *getInventory(const InventoryLocation &loc); - void setInventoryModified(const InventoryLocation &loc); + // virtual: Overwritten by MockInventoryManager for the unittests + virtual Inventory *getInventory(const InventoryLocation &loc); + virtual void setInventoryModified(const InventoryLocation &loc); // Creates or resets inventory Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef, @@ -52,7 +53,7 @@ public: void sendDetachedInventories(const std::string &peer_name, bool incremental, std::function apply_cb); -private: +protected: struct DetachedInventory { std::unique_ptr inventory; diff --git a/src/unittest/mock_inventorymanager.h b/src/unittest/mock_inventorymanager.h index dc75490de..bdf75296a 100644 --- a/src/unittest/mock_inventorymanager.h +++ b/src/unittest/mock_inventorymanager.h @@ -17,11 +17,15 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include -#include +#pragma once -class MockInventoryManager : public InventoryManager +#include "gamedef.h" +#include "inventory.h" +#include "server/serverinventorymgr.h" + +class ServerEnvironment; + +class MockInventoryManager : public ServerInventoryManager { public: MockInventoryManager(IGameDef *gamedef) : @@ -29,14 +33,17 @@ public: p2(gamedef->getItemDefManager()) {}; - virtual Inventory* getInventory(const InventoryLocation &loc){ + Inventory *getInventory(const InventoryLocation &loc) override + { if (loc.type == InventoryLocation::PLAYER && loc.name == "p1") return &p1; if (loc.type == InventoryLocation::PLAYER && loc.name == "p2") return &p2; return nullptr; } + void setInventoryModified(const InventoryLocation &loc) override {} Inventory p1; Inventory p2; + }; diff --git a/src/unittest/mock_server.h b/src/unittest/mock_server.h index 4c0e5fe16..062303a93 100644 --- a/src/unittest/mock_server.h +++ b/src/unittest/mock_server.h @@ -17,6 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#pragma once + #include class MockServer : public Server diff --git a/src/unittest/test_moveaction.cpp b/src/unittest/test_moveaction.cpp index 62a5237a3..af0a88df8 100644 --- a/src/unittest/test_moveaction.cpp +++ b/src/unittest/test_moveaction.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mock_serveractiveobject.h" #include "scripting_server.h" +#include "server/mods.h" class TestMoveAction : public TestBase @@ -39,43 +40,31 @@ public: void testMoveSomewhere(ServerActiveObject *obj, IGameDef *gamedef); void testMoveUnallowed(ServerActiveObject *obj, IGameDef *gamedef); void testMovePartial(ServerActiveObject *obj, IGameDef *gamedef); + void testSwap(ServerActiveObject *obj, IGameDef *gamedef); void testSwapFromUnallowed(ServerActiveObject *obj, IGameDef *gamedef); void testSwapToUnallowed(ServerActiveObject *obj, IGameDef *gamedef); + + void testCallbacks(ServerActiveObject *obj, Server *server); + void testCallbacksSwap(ServerActiveObject *obj, Server *server); }; static TestMoveAction g_test_instance; -const static char *helper_lua_src = R"( -core.register_allow_player_inventory_action(function(player, action, inventory, info) - if action == "move" then - return info.count - end - - if info.stack:get_name() == "default:water" then - return 0 - end - if info.stack:get_name() == "default:lava" then - return 5 - end - - return info.stack:get_count() -end) -)"; - void TestMoveAction::runTests(IGameDef *gamedef) { MockServer server(getTestTempDirectory()); - const auto helper_lua = getTestTempFile(); - std::ofstream ofs(helper_lua, std::ios::out | std::ios::binary); - ofs << helper_lua_src; - ofs.close(); - ServerScripting server_scripting(&server); try { - server_scripting.loadMod(Server::getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); - server_scripting.loadMod(helper_lua, BUILTIN_MOD_NAME); + // FIXME: When removing the line below, the unittest does NOT crash + // (but it should) when running all unittests in order or registration. + // Some Lua API functions used in builtin require the Mgr to be present. + server.m_modmgr = std::make_unique(server.m_path_world); + + std::string builtin = Server::getBuiltinLuaPath() + DIR_DELIM; + server_scripting.loadMod(builtin + "init.lua", BUILTIN_MOD_NAME); + server_scripting.loadMod(builtin + "game" DIR_DELIM "tests" DIR_DELIM "test_moveaction.lua", BUILTIN_MOD_NAME); } catch (ModError &e) { // Print backtrace in case of syntax errors rawstream << e.what() << std::endl; @@ -83,6 +72,8 @@ void TestMoveAction::runTests(IGameDef *gamedef) return; } + server.m_script = &server_scripting; + MetricsBackend mb; ServerEnvironment server_env(nullptr, &server_scripting, &server, "", &mb); MockServerActiveObject obj(&server_env); @@ -92,9 +83,15 @@ void TestMoveAction::runTests(IGameDef *gamedef) TEST(testMoveSomewhere, &obj, gamedef); TEST(testMoveUnallowed, &obj, gamedef); TEST(testMovePartial, &obj, gamedef); + TEST(testSwap, &obj, gamedef); TEST(testSwapFromUnallowed, &obj, gamedef); TEST(testSwapToUnallowed, &obj, gamedef); + + TEST(testCallbacks, &obj, &server); + TEST(testCallbacksSwap, &obj, &server); + + server.m_script = nullptr; // Do not free stack memory } static ItemStack parse_itemstack(const char *s) @@ -165,12 +162,12 @@ void TestMoveAction::testMoveUnallowed(ServerActiveObject *obj, IGameDef *gamede { MockInventoryManager inv(gamedef); - inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:water 50")); + inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:takeput_deny 50")); inv.p2.addList("main", 10); apply_action("Move 20 player:p1 main 0 player:p2 main 0", &inv, obj, gamedef); - UASSERT(inv.p1.getList("main")->getItem(0).getItemString() == "default:water 50"); + UASSERT(inv.p1.getList("main")->getItem(0).getItemString() == "default:takeput_deny 50"); UASSERT(inv.p2.getList("main")->getItem(0).empty()) } @@ -178,13 +175,14 @@ void TestMoveAction::testMovePartial(ServerActiveObject *obj, IGameDef *gamedef) { MockInventoryManager inv(gamedef); - inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:lava 50")); + inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:takeput_max_5 50")); inv.p2.addList("main", 10); + // Lua: limited to 5 per transaction apply_action("Move 20 player:p1 main 0 player:p2 main 0", &inv, obj, gamedef); - UASSERT(inv.p1.getList("main")->getItem(0).getItemString() == "default:lava 45"); - UASSERT(inv.p2.getList("main")->getItem(0).getItemString() == "default:lava 5"); + UASSERT(inv.p1.getList("main")->getItem(0).getItemString() == "default:takeput_max_5 45"); + UASSERT(inv.p2.getList("main")->getItem(0).getItemString() == "default:takeput_max_5 5"); } void TestMoveAction::testSwap(ServerActiveObject *obj, IGameDef *gamedef) @@ -204,12 +202,12 @@ void TestMoveAction::testSwapFromUnallowed(ServerActiveObject *obj, IGameDef *ga { MockInventoryManager inv(gamedef); - inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:water 50")); + inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:takeput_deny 50")); inv.p2.addList("main", 10)->addItem(0, parse_itemstack("default:brick 60")); apply_action("Move 50 player:p1 main 0 player:p2 main 0", &inv, obj, gamedef); - UASSERT(inv.p1.getList("main")->getItem(0).getItemString() == "default:water 50"); + UASSERT(inv.p1.getList("main")->getItem(0).getItemString() == "default:takeput_deny 50"); UASSERT(inv.p2.getList("main")->getItem(0).getItemString() == "default:brick 60"); } @@ -218,10 +216,60 @@ void TestMoveAction::testSwapToUnallowed(ServerActiveObject *obj, IGameDef *game MockInventoryManager inv(gamedef); inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:stone 50")); - inv.p2.addList("main", 10)->addItem(0, parse_itemstack("default:water 60")); + inv.p2.addList("main", 10)->addItem(0, parse_itemstack("default:takeput_deny 60")); apply_action("Move 50 player:p1 main 0 player:p2 main 0", &inv, obj, gamedef); UASSERT(inv.p1.getList("main")->getItem(0).getItemString() == "default:stone 50"); - UASSERT(inv.p2.getList("main")->getItem(0).getItemString() == "default:water 60"); + UASSERT(inv.p2.getList("main")->getItem(0).getItemString() == "default:takeput_deny 60"); +} + +static bool check_function(lua_State *L, bool expect_swap) +{ + bool ok = false; + int error_handler = PUSH_ERROR_HANDLER(L); + + lua_getglobal(L, "core"); + lua_getfield(L, -1, "__helper_check_callbacks"); + lua_pushboolean(L, expect_swap); + int result = lua_pcall(L, 1, 1, error_handler); + if (result == 0) + ok = lua_toboolean(L, -1); + else + errorstream << lua_tostring(L, -1) << std::endl; // Error msg + + lua_settop(L, 0); + return ok; +} + +void TestMoveAction::testCallbacks(ServerActiveObject *obj, Server *server) +{ + server->m_inventory_mgr = std::make_unique(server); + MockInventoryManager &inv = *(MockInventoryManager *)server->getInventoryMgr(); + + inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:takeput_cb_1 10")); + inv.p2.addList("main", 10); + + apply_action("Move 10 player:p1 main 0 player:p2 main 1", &inv, obj, server); + + // Expecting no swap. 4 callback executions in total. See Lua file for details. + UASSERT(check_function(server->getScriptIface()->getStack(), false)); + + server->m_inventory_mgr.reset(); +} + +void TestMoveAction::testCallbacksSwap(ServerActiveObject *obj, Server *server) +{ + server->m_inventory_mgr = std::make_unique(server); + MockInventoryManager &inv = *(MockInventoryManager *)server->getInventoryMgr(); + + inv.p1.addList("main", 10)->addItem(0, parse_itemstack("default:takeput_cb_2 50")); + inv.p2.addList("main", 10)->addItem(1, parse_itemstack("default:takeput_cb_1 10")); + + apply_action("Move 10 player:p1 main 0 player:p2 main 1", &inv, obj, server); + + // Expecting swap. 8 callback executions in total. See Lua file for details. + UASSERT(check_function(server->getScriptIface()->getStack(), true)); + + server->m_inventory_mgr.reset(); } From c8b615acc9817bba97626df5120c3dd2c5c1b453 Mon Sep 17 00:00:00 2001 From: grorp Date: Sun, 17 Mar 2024 14:59:50 +0100 Subject: [PATCH 41/91] Remove excessive touchscreengui.h includes (#14466) --- src/CMakeLists.txt | 1 + src/client/clientlauncher.cpp | 5 ++-- src/client/content_cso.cpp | 1 + src/client/game.cpp | 1 + src/client/inputhandler.cpp | 55 ++++++++++++++++++++++++++++++++--- src/client/inputhandler.h | 51 ++------------------------------ src/clientdynamicinfo.cpp | 55 +++++++++++++++++++++++++++++++++++ src/clientdynamicinfo.h | 32 ++------------------ 8 files changed, 115 insertions(+), 86 deletions(-) create mode 100644 src/clientdynamicinfo.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5eb6677a9..120ef277f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -368,6 +368,7 @@ set(common_SRCS ${server_SRCS} ${content_SRCS} chat.cpp + clientdynamicinfo.cpp collision.cpp content_mapnode.cpp content_nodemeta.cpp diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 995381112..93ed392b9 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gui/mainmenumanager.h" #include "clouds.h" +#include "gui/touchscreengui.h" #include "server.h" #include "filesys.h" #include "gui/guiMainMenu.h" @@ -210,8 +211,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) break; if (g_settings->getBool("enable_touch")) { - receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver); - g_touchscreengui = receiver->m_touchscreengui; + g_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver); } the_game( @@ -246,7 +246,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) if (g_touchscreengui) { delete g_touchscreengui; g_touchscreengui = NULL; - receiver->m_touchscreengui = NULL; } /* Save the settings when leaving the game. diff --git a/src/client/content_cso.cpp b/src/client/content_cso.cpp index d6c3fd3ef..c175df72e 100644 --- a/src/client/content_cso.cpp +++ b/src/client/content_cso.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_cso.h" #include +#include "client/texturesource.h" #include "clientenvironment.h" #include "client.h" #include "map.h" diff --git a/src/client/game.cpp b/src/client/game.cpp index 9459b3204..3a42f2b0c 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content/subgames.h" #include "client/event_manager.h" #include "fontengine.h" +#include "gui/touchscreengui.h" #include "itemdef.h" #include "log.h" #include "filesys.h" diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp index 82303c455..7b2e70b54 100644 --- a/src/client/inputhandler.cpp +++ b/src/client/inputhandler.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "inputhandler.h" #include "gui/mainmenumanager.h" +#include "gui/touchscreengui.h" #include "hud.h" void KeyCache::populate_nonchanging() @@ -102,8 +103,8 @@ bool MyEventReceiver::OnEvent(const SEvent &event) React to nothing here if a menu is active */ if (isMenuActive()) { - if (m_touchscreengui) { - m_touchscreengui->setVisible(false); + if (g_touchscreengui) { + g_touchscreengui->setVisible(false); } return g_menumgr.preprocessEvent(event); } @@ -128,9 +129,9 @@ bool MyEventReceiver::OnEvent(const SEvent &event) return true; } - } else if (m_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) { + } else if (g_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) { // In case of touchscreengui, we have to handle different events - m_touchscreengui->translateEvent(event); + g_touchscreengui->translateEvent(event); return true; } else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) { @@ -195,6 +196,52 @@ bool MyEventReceiver::OnEvent(const SEvent &event) return false; } +/* + * RealInputHandler + */ +float RealInputHandler::getMovementSpeed() +{ + bool f = m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]), + b = m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]), + l = m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]), + r = m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]); + if (f || b || l || r) + { + // if contradictory keys pressed, stay still + if (f && b && l && r) + return 0.0f; + else if (f && b && !l && !r) + return 0.0f; + else if (!f && !b && l && r) + return 0.0f; + return 1.0f; // If there is a keyboard event, assume maximum speed + } + if (g_touchscreengui && g_touchscreengui->getMovementSpeed()) + return g_touchscreengui->getMovementSpeed(); + return joystick.getMovementSpeed(); +} + +float RealInputHandler::getMovementDirection() +{ + float x = 0, z = 0; + + /* Check keyboard for input */ + if (m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD])) + z += 1; + if (m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD])) + z -= 1; + if (m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT])) + x += 1; + if (m_receiver->IsKeyDown(keycache.key[KeyType::LEFT])) + x -= 1; + + if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */ + return std::atan2(x, z); + else if (g_touchscreengui && g_touchscreengui->getMovementDirection()) + return g_touchscreengui->getMovementDirection(); + return joystick.getMovementDirection(); +} + /* * RandomInputHandler */ diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h index 68bd7bb03..f4fae2b0b 100644 --- a/src/client/inputhandler.h +++ b/src/client/inputhandler.h @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "keycode.h" #include "renderingengine.h" -#include "gui/touchscreengui.h" class InputHandler; @@ -198,15 +197,8 @@ public: keyWasReleased.clear(); } - MyEventReceiver() - { - m_touchscreengui = NULL; - } - JoystickController *joystick = nullptr; - TouchScreenGUI *m_touchscreengui; - private: s32 mouse_wheel = 0; @@ -308,48 +300,9 @@ public: return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k); } - virtual float getMovementSpeed() - { - bool f = m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]), - b = m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]), - l = m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]), - r = m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]); - if (f || b || l || r) - { - // if contradictory keys pressed, stay still - if (f && b && l && r) - return 0.0f; - else if (f && b && !l && !r) - return 0.0f; - else if (!f && !b && l && r) - return 0.0f; - return 1.0f; // If there is a keyboard event, assume maximum speed - } - if (m_receiver->m_touchscreengui && m_receiver->m_touchscreengui->getMovementSpeed()) - return m_receiver->m_touchscreengui->getMovementSpeed(); - return joystick.getMovementSpeed(); - } + virtual float getMovementSpeed(); - virtual float getMovementDirection() - { - float x = 0, z = 0; - - /* Check keyboard for input */ - if (m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD])) - z += 1; - if (m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD])) - z -= 1; - if (m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT])) - x += 1; - if (m_receiver->IsKeyDown(keycache.key[KeyType::LEFT])) - x -= 1; - - if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */ - return atan2(x, z); - else if (m_receiver->m_touchscreengui && m_receiver->m_touchscreengui->getMovementDirection()) - return m_receiver->m_touchscreengui->getMovementDirection(); - return joystick.getMovementDirection(); - } + virtual float getMovementDirection(); virtual bool cancelPressed() { diff --git a/src/clientdynamicinfo.cpp b/src/clientdynamicinfo.cpp new file mode 100644 index 000000000..a9b2a6ef3 --- /dev/null +++ b/src/clientdynamicinfo.cpp @@ -0,0 +1,55 @@ +/* +Minetest +Copyright (C) 2022-3 rubenwardy + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef SERVER + +#include "clientdynamicinfo.h" + +#include "settings.h" +#include "client/renderingengine.h" +#include "gui/touchscreengui.h" + +ClientDynamicInfo ClientDynamicInfo::getCurrent() +{ + v2u32 screen_size = RenderingEngine::getWindowSize(); + f32 density = RenderingEngine::getDisplayDensity(); + f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f); + f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f); + f32 real_gui_scaling = gui_scaling * density; + f32 real_hud_scaling = hud_scaling * density; + bool touch_controls = g_touchscreengui; + + return { + screen_size, real_gui_scaling, real_hud_scaling, + ClientDynamicInfo::calculateMaxFSSize(screen_size, gui_scaling), + touch_controls + }; +} + +v2f32 ClientDynamicInfo::calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling) +{ + f32 factor = (g_settings->getBool("enable_touch") ? 10 : 15) / gui_scaling; + f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y; + if (ratio < 1) + return { factor, factor / ratio }; + else + return { factor * ratio, factor }; +} + +#endif diff --git a/src/clientdynamicinfo.h b/src/clientdynamicinfo.h index bbea5d149..39faeeecc 100644 --- a/src/clientdynamicinfo.h +++ b/src/clientdynamicinfo.h @@ -20,11 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_bloated.h" -#ifndef SERVER -#include "settings.h" -#include "client/renderingengine.h" -#include "gui/touchscreengui.h" -#endif struct ClientDynamicInfo @@ -44,32 +39,9 @@ public: } #ifndef SERVER - static ClientDynamicInfo getCurrent() { - v2u32 screen_size = RenderingEngine::getWindowSize(); - f32 density = RenderingEngine::getDisplayDensity(); - f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f); - f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f); - f32 real_gui_scaling = gui_scaling * density; - f32 real_hud_scaling = hud_scaling * density; - bool touch_controls = g_touchscreengui; - - return { - screen_size, real_gui_scaling, real_hud_scaling, - ClientDynamicInfo::calculateMaxFSSize(screen_size, gui_scaling), - touch_controls - }; - } -#endif + static ClientDynamicInfo getCurrent(); private: -#ifndef SERVER - static v2f32 calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling) { - f32 factor = (g_settings->getBool("enable_touch") ? 10 : 15) / gui_scaling; - f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y; - if (ratio < 1) - return { factor, factor / ratio }; - else - return { factor * ratio, factor }; - } + static v2f32 calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling); #endif }; From 4f84b0135608676edc9969a653eaae07dce37e98 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Sun, 17 Mar 2024 14:40:50 +0100 Subject: [PATCH 42/91] Touchscreen: Fix virtual joystick sometimes going backwards This fixes a regression introduced by 34286d77c7ee65be480a372233c5ab7c4b81d9db / #14075. --- src/client/inputhandler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp index 7b2e70b54..5c91898bc 100644 --- a/src/client/inputhandler.cpp +++ b/src/client/inputhandler.cpp @@ -237,7 +237,9 @@ float RealInputHandler::getMovementDirection() if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */ return std::atan2(x, z); - else if (g_touchscreengui && g_touchscreengui->getMovementDirection()) + // `getMovementDirection() == 0` means forward, so we cannot use + // `getMovementDirection()` as a condition. + else if (g_touchscreengui && g_touchscreengui->getMovementSpeed()) return g_touchscreengui->getMovementDirection(); return joystick.getMovementDirection(); } From 4d24537590ea789934c5e5c62e611c6b10939b40 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 1 Mar 2024 19:01:28 +0100 Subject: [PATCH 43/91] Fix multiplayer test missing crashes at shutdown --- .github/workflows/linux.yml | 2 +- util/test_multiplayer.sh | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 3d831d92f..121e616ee 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -108,7 +108,7 @@ jobs: - name: Install deps run: | source ./util/ci/common.sh - install_linux_deps clang-14 gdb + install_linux_deps clang-14 lldb - name: Build run: | diff --git a/util/test_multiplayer.sh b/util/test_multiplayer.sh index 64f042977..624669ac1 100755 --- a/util/test_multiplayer.sh +++ b/util/test_multiplayer.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Runs a multiplayer server and connects a headless client, devtest unittests are executed. + dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" gameid=${gameid:-devtest} minetest=$dir/../bin/minetest @@ -21,6 +23,7 @@ waitfor () { [ -e "$minetest" ] || { echo "executable $minetest missing"; exit 1; } +rm -f "$testspath/log.txt" rm -rf "$worldpath" mkdir -p "$worldpath/worldmods" @@ -35,11 +38,13 @@ printf '%s\n' >"$testspath/server.conf" \ ln -s "$dir/helper_mod" "$worldpath/worldmods/" echo "Starting server" -"$minetest" --debugger --server --config "$conf_server" --world "$worldpath" --gameid $gameid 2>&1 | sed -u 's/^/(server) /' & +"$minetest" --debugger --server --config "$conf_server" --world "$worldpath" --gameid $gameid 2>&1 \ + | sed -u 's/^/(server) /' | tee -a "$testspath/log.txt" & waitfor "$worldpath/startup" echo "Starting client" -"$minetest" --debugger --config "$conf_client1" --go --address 127.0.0.1 2>&1 | sed -u 's/^/(client) /' & +"$minetest" --debugger --config "$conf_client1" --go --address 127.0.0.1 2>&1 \ + | sed -u 's/^/(client) /' | tee -a "$testspath/log.txt" & waitfor "$worldpath/done" echo "Waiting for client and server to exit" @@ -49,5 +54,10 @@ if [ -f "$worldpath/test_failure" ]; then echo "There were test failures." exit 1 fi +# gdb|lldb +if grep -Eq "(Thread .* received signal|thread .* stop reason =)" "$testspath/log.txt"; then + echo "Debugger reported error." + exit 1 +fi echo "Success" exit 0 From ef0009aea7e67638e9aea36fc406fc3f1190953f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 1 Mar 2024 20:02:58 +0100 Subject: [PATCH 44/91] Sort out server destruction order fixes #14421 --- src/map.cpp | 4 ++-- src/server.cpp | 50 ++++++++++++++++++++++----------------- src/serverenvironment.cpp | 14 +++++------ src/serverenvironment.h | 3 +++ 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 9d3cc8376..22731f120 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1328,8 +1328,8 @@ ServerMap::~ServerMap() } catch(std::exception &e) { - infostream<<"ServerMap: Failed to save map to "<stopThreads(); if (m_env) { MutexAutoLock envlock(m_env_mutex); - // Execute script shutdown hooks - infostream << "Executing shutdown hooks" << std::endl; + try { + // Empty out the environment, this can also invoke callbacks. + m_env->deactivateBlocksAndObjects(); + } catch (ModError &e) { + addShutdownError(e); + } + + infostream << "Server: Executing shutdown hooks" << std::endl; try { m_script->on_shutdown(); } catch (ModError &e) { @@ -369,12 +381,10 @@ Server::~Server() infostream << "Server: Saving environment metadata" << std::endl; m_env->saveMeta(); - } - // Stop threads - if (m_thread) { - stop(); - delete m_thread; + // Note that this also deletes and saves the map. + delete m_env; + m_env = nullptr; } // Write any changes before deletion. @@ -388,22 +398,18 @@ Server::~Server() } } - // Delete things in the reverse order of creation + // Delete the rest in the reverse order of creation + delete m_game_settings; delete m_emerge; - delete m_env; - delete m_rollback; - delete m_mod_storage_database; delete m_banmanager; + delete m_mod_storage_database; + delete m_startup_server_map; // if available + delete m_script; + delete m_rollback; delete m_itemdef; delete m_nodedef; delete m_craftdef; - // Deinitialize scripting - infostream << "Server: Deinitializing scripting" << std::endl; - delete m_script; - delete m_startup_server_map; // if available - delete m_game_settings; - while (!m_unsent_map_edit_queue.empty()) { delete m_unsent_map_edit_queue.front(); m_unsent_map_edit_queue.pop(); @@ -582,7 +588,7 @@ void Server::start() void Server::stop() { - infostream<<"Server: Stopping and waiting threads"<stop(); diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index df5fb5e12..47fff1ef4 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -534,18 +534,18 @@ void ServerEnvironment::init() } } -ServerEnvironment::~ServerEnvironment() +void ServerEnvironment::deactivateBlocksAndObjects() { // Clear active block list. // This makes the next one delete all active objects. m_active_blocks.clear(); - try { - // Convert all objects to static and delete the active objects - deactivateFarObjects(true); - } catch (ModError &e) { - m_server->addShutdownError(e); - } + deactivateFarObjects(true); +} + +ServerEnvironment::~ServerEnvironment() +{ + assert(m_active_blocks.size() == 0); // deactivateBlocksAndObjects does this // Drop/delete map if (m_map) diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 000f5f81f..f166802a0 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -363,6 +363,9 @@ public: // Clear objects, loading and going through every MapBlock void clearObjects(ClearObjectsMode mode); + // to be called before destructor + void deactivateBlocksAndObjects(); + // This makes stuff happen void step(f32 dtime); From 2386bfda7e6fe88fbdd12d9410f9674cbb7c5157 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 1 Mar 2024 20:46:07 +0100 Subject: [PATCH 45/91] Fix static_save=false not working & related cleanups --- src/mapblock.cpp | 2 +- src/server/luaentity_sao.cpp | 4 +++- src/serverenvironment.cpp | 30 ++++++++++++++++-------------- src/staticobject.cpp | 1 + 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 36210cad1..e2204f083 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -94,7 +94,7 @@ bool MapBlock::onObjectsActivation() const auto count = m_static_objects.getStoredSize(); verbosestream << "MapBlock::onObjectsActivation(): " - << "activating " << count << "objects in block " << getPos() + << "activating " << count << " objects in block " << getPos() << std::endl; if (count > g_settings->getU16("max_objects_per_block")) { diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index 9917eb53a..963fd63dc 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -71,7 +71,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d break; } // create object - infostream << "LuaEntitySAO::create(name=\"" << name << "\" state is"; + infostream << "LuaEntitySAO(name=\"" << name << "\" state is "; if (state.empty()) infostream << "empty"; else @@ -289,6 +289,8 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) void LuaEntitySAO::getStaticData(std::string *result) const { + assert(isStaticAllowed()); + std::ostringstream os(std::ios::binary); // version must be 1 to keep backwards-compatibility. See version2 writeU8(os, 1); diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 47fff1ef4..dc629f307 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1251,12 +1251,11 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) // Delete static object if block is loaded deleteStaticFromBlock(obj, id, MOD_REASON_CLEAR_ALL_OBJECTS, true); + obj->markForRemoval(); // If known by some client, don't delete immediately - if (obj->m_known_by_count > 0) { - obj->markForRemoval(); + if (obj->m_known_by_count > 0) return false; - } processActiveObjectRemove(obj); @@ -1894,6 +1893,12 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr ob return 0; } + // Register reference in scripting api (must be done before post-init) + m_script->addObjectReference(object); + // Post-initialize object + // Note that this can change the value of isStaticAllowed() in case of LuaEntitySAO + object->addedToEnvironment(dtime_s); + // Add static data to block if (object->isStaticAllowed()) { // Add static object to active static list of the block @@ -1916,15 +1921,14 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr ob << "could not emerge block " << p << " for storing id=" << object->getId() << " statically" << std::endl; // clean in case of error + object->markForRemoval(); + processActiveObjectRemove(object); m_ao_manager.removeObject(object->getId()); return 0; } } - // Register reference in scripting api (must be done before post-init) - m_script->addObjectReference(object); - // Post-initialize object - object->addedToEnvironment(dtime_s); + assert(object->m_static_exists == object->isStaticAllowed()); return object->getId(); } @@ -1937,13 +1941,6 @@ void ServerEnvironment::removeRemovedObjects() ScopeProfiler sp(g_profiler, "ServerEnvironment::removeRemovedObjects()", SPT_AVG); auto clear_cb = [this](ServerActiveObject *obj, u16 id) { - // This shouldn't happen but check it - if (!obj) { - errorstream << "ServerEnvironment::removeRemovedObjects(): " - << "NULL object found. id=" << id << std::endl; - return true; - } - /* We will handle objects marked for removal or deactivation */ @@ -2280,6 +2277,11 @@ bool ServerEnvironment::saveStaticToBlock( void ServerEnvironment::processActiveObjectRemove(ServerActiveObject *obj) { + // markForRemoval or markForDeactivation should have been called before + // Not because it's strictly necessary but because the Lua callback is + // bound to that. + assert(obj->isGone()); + // Tell the object about removal obj->removingFromEnvironment(); // Deregister in scripting api diff --git a/src/staticobject.cpp b/src/staticobject.cpp index d728f5d10..8fbfcef8b 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -25,6 +25,7 @@ StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_): type(s_obj->getType()), pos(pos_) { + assert(s_obj->isStaticAllowed()); s_obj->getStaticData(&data); } From 83395942069f3743830d88b9751f615a8926aacd Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 2 Mar 2024 09:54:53 +0100 Subject: [PATCH 46/91] Handle static_save changes at runtime and between restarts --- src/server/serveractiveobject.h | 4 +++ src/serverenvironment.cpp | 60 ++++++++++++++++++++++++--------- src/serverenvironment.h | 11 +----- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index 2911a5549..4d620b768 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -229,6 +229,10 @@ public: /* Whether the object's static data has been stored to a block + + Note that `!isStaticAllowed() && m_static_exists` is a valid state + (though it usually doesn't persist long) and you need to be careful + about handling it. */ bool m_static_exists = false; /* diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index dc629f307..64e8042ae 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1716,7 +1716,7 @@ u16 ServerEnvironment::addActiveObject(std::unique_ptr objec { assert(object); // Pre-condition m_added_objects++; - u16 id = addActiveObjectRaw(std::move(object), true, 0); + u16 id = addActiveObjectRaw(std::move(object), nullptr, 0); return id; } @@ -1886,7 +1886,7 @@ void ServerEnvironment::getSelectedActiveObjects( */ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr object_u, - bool set_changed, u32 dtime_s) + const StaticObject *from_static, u32 dtime_s) { auto object = object_u.get(); if (!m_ao_manager.registerObject(std::move(object_u))) { @@ -1899,9 +1899,29 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr ob // Note that this can change the value of isStaticAllowed() in case of LuaEntitySAO object->addedToEnvironment(dtime_s); + // Activate object + if (object->m_static_exists) + { + sanity_check(from_static); + /* + * Note: Don't check isStaticAllowed() here. If an object has static data + * when it shouldn't, we still need to activate it so the static data + * can be properly removed. + */ + auto blockpos = object->m_static_block; + MapBlock *block = m_map->emergeBlock(blockpos); + if (block) { + block->m_static_objects.setActive(object->getId(), *from_static); + } else { + warningstream << "ServerEnvironment::addActiveObjectRaw(): " + << "object was supposed to be in block " << blockpos + << ", but this block disappeared." << std::endl; + object->m_static_exists = false; + } + } // Add static data to block - if (object->isStaticAllowed()) { - // Add static object to active static list of the block + else if (object->isStaticAllowed()) + { v3f objectpos = object->getBasePosition(); StaticObject s_obj(object, objectpos); // Add to the block where the object is located in @@ -1912,9 +1932,8 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr ob object->m_static_exists = true; object->m_static_block = blockpos; - if(set_changed) - block->raiseModified(MOD_STATE_WRITE_NEEDED, - MOD_REASON_ADD_ACTIVE_OBJECT_RAW); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + MOD_REASON_ADD_ACTIVE_OBJECT_RAW); } else { v3s16 p = floatToInt(objectpos, BS); errorstream << "ServerEnvironment::addActiveObjectRaw(): " @@ -1928,8 +1947,6 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr ob } } - assert(object->m_static_exists == object->isStaticAllowed()); - return object->getId(); } @@ -2051,18 +2068,26 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) if (!obj) { errorstream << "ServerEnvironment::activateObjects(): " << "failed to create active object from static object " - << "in block " << (s_obj.pos / BS) + << "in block " << block->getPos() << " type=" << (int)s_obj.type << " data:" << std::endl; print_hexdump(verbosestream, s_obj.data); new_stored.push_back(s_obj); continue; } - verbosestream << "ServerEnvironment::activateObjects(): " - << "activated static object pos=" << (s_obj.pos / BS) - << " type=" << (int)s_obj.type << std::endl; + + obj->m_static_exists = true; + obj->m_static_block = block->getPos(); + // This will also add the object to the active static list - addActiveObjectRaw(std::move(obj), false, dtime_s); + bool ok = addActiveObjectRaw(std::move(obj), &s_obj, dtime_s) != 0; + if (ok) { + verbosestream << "ServerEnvironment::activateObjects(): " + << "activated static object pos=" << (s_obj.pos / BS) + << " type=" << (int)s_obj.type << std::endl; + } + + // callbacks could invalidate this block if (block->isOrphan()) return; } @@ -2095,7 +2120,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) If block wasn't generated (not in memory or on disk), */ -void ServerEnvironment::deactivateFarObjects(bool _force_delete) +void ServerEnvironment::deactivateFarObjects(const bool _force_delete) { auto cb_deactivate = [this, _force_delete](ServerActiveObject *obj, u16 id) { // force_delete might be overridden per object @@ -2117,7 +2142,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete) // If object's static data is stored in a deactivated block and object // is actually located in an active block, re-save to the block in // which the object is actually located in. - if (!force_delete && obj->m_static_exists && + if (!force_delete && obj->isStaticAllowed() && obj->m_static_exists && !m_active_blocks.contains(obj->m_static_block) && m_active_blocks.contains(blockpos_o)) { @@ -2194,6 +2219,9 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete) u16 store_id = pending_delete ? id : 0; if (!saveStaticToBlock(blockpos, store_id, obj, s_obj, reason)) force_delete = true; + } else { + // If the object has static data but shouldn't we need to get rid of it. + deleteStaticFromBlock(obj, id, MOD_REASON_STATIC_DATA_REMOVED, false); } // Regardless of what happens to the object at this point, deactivate it first. diff --git a/src/serverenvironment.h b/src/serverenvironment.h index f166802a0..ff2173938 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -280,15 +280,6 @@ public: */ u16 addActiveObject(std::unique_ptr object); - /* - Add an active object as a static object to the corresponding - MapBlock. - Caller allocates memory, ServerEnvironment frees memory. - Return value: true if succeeded, false if failed. - (note: not used, pending removal from engine) - */ - //bool addActiveObjectAsStatic(ServerActiveObject *object); - /* Find out what new objects have been added to inside a radius around a position @@ -428,7 +419,7 @@ private: Returns 0 if not added and thus deleted. */ u16 addActiveObjectRaw(std::unique_ptr object, - bool set_changed, u32 dtime_s); + const StaticObject *from_static, u32 dtime_s); /* Remove all objects that satisfy (isGone() && m_known_by_count==0) From e3b9828f240d8be31f15625e19d201fd3cf787e1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 3 Mar 2024 19:51:49 +0100 Subject: [PATCH 47/91] Add unit tests for SAO load / unload behaviour --- src/script/scripting_server.cpp | 7 + src/script/scripting_server.h | 1 + src/server.cpp | 3 +- src/serverenvironment.cpp | 3 +- src/unittest/CMakeLists.txt | 1 + src/unittest/mock_server.h | 5 +- src/unittest/test_moveaction.cpp | 4 +- src/unittest/test_sao.cpp | 315 +++++++++++++++++++++++++++++++ 8 files changed, 332 insertions(+), 7 deletions(-) create mode 100644 src/unittest/test_sao.cpp diff --git a/src/script/scripting_server.cpp b/src/script/scripting_server.cpp index b7114c7ab..324850011 100644 --- a/src/script/scripting_server.cpp +++ b/src/script/scripting_server.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "log.h" #include "settings.h" +#include "filesys.h" #include "cpp_api/s_internal.h" #include "lua_api/l_areastore.h" #include "lua_api/l_auth.h" @@ -89,6 +90,12 @@ ServerScripting::ServerScripting(Server* server): infostream << "SCRIPTAPI: Initialized game modules" << std::endl; } +void ServerScripting::loadBuiltin() +{ + loadMod(Server::getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); + checkSetByBuiltin(); +} + void ServerScripting::saveGlobals() { SCRIPTAPI_PRECHECKHEADER diff --git a/src/script/scripting_server.h b/src/script/scripting_server.h index d4eb1c4f2..20d99313a 100644 --- a/src/script/scripting_server.h +++ b/src/script/scripting_server.h @@ -49,6 +49,7 @@ class ServerScripting: public: ServerScripting(Server* server); + void loadBuiltin(); // use ScriptApiBase::loadMod() to load mods // Save globals that are copied into other Lua envs diff --git a/src/server.cpp b/src/server.cpp index 7344784cd..159076686 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -471,8 +471,7 @@ void Server::init() // Must be created before mod loading because we have some inventory creation m_inventory_mgr = std::make_unique(); - m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); - m_script->checkSetByBuiltin(); + m_script->loadBuiltin(); m_gamespec.checkAndLog(); m_modmgr->loadMods(m_script); diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 64e8042ae..56e7fe247 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1642,7 +1642,8 @@ void ServerEnvironment::step(float dtime) } // Send outdated detached inventories - m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true); + if (!m_players.empty()) + m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true); // Notify mods of modified mapblocks if (m_on_mapblocks_changed_receiver.receiving && diff --git a/src/unittest/CMakeLists.txt b/src/unittest/CMakeLists.txt index 3b8a48aaf..b249b0f75 100644 --- a/src/unittest/CMakeLists.txt +++ b/src/unittest/CMakeLists.txt @@ -26,6 +26,7 @@ set (UNITTEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/test_objdef.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_profiler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_random.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_sao.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_schematic.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_serialization.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_serveractiveobjectmgr.cpp diff --git a/src/unittest/mock_server.h b/src/unittest/mock_server.h index 062303a93..aa3a0ae52 100644 --- a/src/unittest/mock_server.h +++ b/src/unittest/mock_server.h @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -#include +#include "server.h" class MockServer : public Server { @@ -31,6 +31,9 @@ public: ) {} + void start() = delete; + void stop() = delete; + private: void SendChatMessage(session_t peer_id, const ChatMessage &message) {} }; diff --git a/src/unittest/test_moveaction.cpp b/src/unittest/test_moveaction.cpp index af0a88df8..4516fcc04 100644 --- a/src/unittest/test_moveaction.cpp +++ b/src/unittest/test_moveaction.cpp @@ -22,11 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mock_inventorymanager.h" #include "mock_server.h" #include "mock_serveractiveobject.h" - #include "scripting_server.h" #include "server/mods.h" - class TestMoveAction : public TestBase { public: @@ -63,7 +61,7 @@ void TestMoveAction::runTests(IGameDef *gamedef) server.m_modmgr = std::make_unique(server.m_path_world); std::string builtin = Server::getBuiltinLuaPath() + DIR_DELIM; - server_scripting.loadMod(builtin + "init.lua", BUILTIN_MOD_NAME); + server_scripting.loadBuiltin(); server_scripting.loadMod(builtin + "game" DIR_DELIM "tests" DIR_DELIM "test_moveaction.lua", BUILTIN_MOD_NAME); } catch (ModError &e) { // Print backtrace in case of syntax errors diff --git a/src/unittest/test_sao.cpp b/src/unittest/test_sao.cpp new file mode 100644 index 000000000..bedc3403b --- /dev/null +++ b/src/unittest/test_sao.cpp @@ -0,0 +1,315 @@ +/* +Minetest +Copyright (C) 2024 sfan5 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "test.h" + +#include "mock_server.h" +#include "scripting_server.h" +#include "server/luaentity_sao.h" +#include "emerge.h" + +/* + * Tests how SAOs behave in the server environment. + * See also test_serveractiveobjectmgr.cpp and test_activeobject.cpp for other tests. + */ + +class TestSAO : public TestBase +{ +public: + TestSAO() { TestManager::registerTestModule(this); } + const char *getName() { return "TestSAO"; } + + void runTests(IGameDef *gamedef); + + void testStaticSave(ServerEnvironment *env); + void testNotSaved(ServerEnvironment *env); + void testActivate(ServerEnvironment *env); + void testStaticToFalse(ServerEnvironment *env); + void testStaticToTrue(ServerEnvironment *env); + +private: + // enough for both removeRemovedObjects and deactivateFarObjects to be called + // use as param to ServerEnvironment::step() + float m_step_interval; +}; + +static TestSAO g_test_instance; + +const static char *helper_lua_src = R"( +core.register_entity(":test:static", {}) +core.register_entity(":test:non_static", { + initial_properties = { + static_save = false, + } +}) +)"; + +void TestSAO::runTests(IGameDef *gamedef) +{ + MockServer server(getTestTempDirectory()); + + const auto helper_lua = getTestTempFile(); + { + std::ofstream ofs(helper_lua, std::ios::out | std::ios::binary); + ofs << helper_lua_src; + std::ofstream ofs2(server.getWorldPath() + DIR_DELIM "world.mt", + std::ios::out | std::ios::binary); + ofs2 << "backend = dummy\n"; + } + + ServerScripting server_scripting(&server); + try { + server_scripting.loadBuiltin(); + server_scripting.loadMod(helper_lua, BUILTIN_MOD_NAME); + } catch (ModError &e) { + rawstream << e.what() << std::endl; + num_tests_failed = 1; + return; + } + + // unfortunately we have to create a lot since a DummyMap doesn't cut it. + // TODO: best to factor entity mgmt out of ServerEnvironment, also + // EmergeManager should become mockable + MetricsBackend mb; + EmergeManager emerge(&server, &mb); + auto *map = new ServerMap(server.getWorldPath(), gamedef, &emerge, &mb); + ServerEnvironment env(map, &server_scripting, &server, "", &mb); + env.loadMeta(); + + m_step_interval = std::max( + g_settings->getFloat("active_block_mgmt_interval"), 0.5f) + 0.1f; + + TEST(testStaticSave, &env); + TEST(testNotSaved, &env); + TEST(testActivate, &env); + TEST(testStaticToFalse, &env); + TEST(testStaticToTrue, &env); + + env.deactivateBlocksAndObjects(); +} + +static LuaEntitySAO *add_entity(ServerEnvironment *env, v3f pos, const char *name) +{ + auto obj_u = std::make_unique(env, pos, name, ""); + auto obj = obj_u.get(); + u16 id = env->addActiveObject(std::move(obj_u)); + if (!id || obj->isGone()) + return nullptr; + return obj; +} + +static u16 assert_active_in_block(MapBlock *block, u16 obj_id = 0) +{ + const auto &so = block->m_static_objects; + UASSERTEQ(size_t, so.getStoredSize(), 0); + UASSERTEQ(size_t, so.getActiveSize(), 1); + if (obj_id) { + UASSERT(so.getAllActives().count(obj_id) == 1); + } else { + obj_id = so.getAllActives().begin()->first; + UASSERT(obj_id != 0); + } + return obj_id; +} + +void TestSAO::testStaticSave(ServerEnvironment *env) +{ + Map &map = env->getMap(); + + const v3f testpos(0, -66 * BS, 0); + const v3s16 testblockpos = getNodeBlockPos(floatToInt(testpos, BS)); + + auto obj = add_entity(env, testpos, "test:static"); + UASSERT(obj); + const u16 obj_id = obj->getId(); + + // static data should have been created + UASSERT(obj->accessObjectProperties()->static_save); + UASSERT(obj->m_static_exists); + UASSERTEQ(auto, obj->m_static_block, testblockpos); + // check that it's really in there + auto *block = map.getBlockNoCreateNoEx(testblockpos); + UASSERT(block); + assert_active_in_block(block, obj_id); + + // Since we have no active blocks, stepping will deactivate it. + env->step(m_step_interval); + + obj = nullptr; // dangling reference + UASSERT(!env->getActiveObject(obj_id)); + UASSERTEQ(size_t, block->m_static_objects.getStoredSize(), 1); + UASSERTEQ(size_t, block->m_static_objects.getActiveSize(), 0); +} + +void TestSAO::testNotSaved(ServerEnvironment *env) +{ + Map &map = env->getMap(); + + const v3f testpos(0, 4 * BS, 0); + const v3s16 testblockpos = getNodeBlockPos(floatToInt(testpos, BS)); + + // make sure matching block exists (see below) + auto *block = map.emergeBlock(testblockpos, true); + UASSERT(block); + + auto obj = add_entity(env, testpos, "test:non_static"); + UASSERT(obj); + const u16 obj_id = obj->getId(); + + UASSERT(!obj->accessObjectProperties()->static_save); + UASSERT(!obj->m_static_exists); + UASSERTEQ(size_t, block->m_static_objects.size(), 0); + + // Non-static objects are only unloaded together with their block, so doing + // this will *not* delete it. + env->step(m_step_interval); + + UASSERT(env->getActiveObject(obj_id) == obj); + + // Here we force the block to be unloaded, this has the expected effect. + map.timerUpdate(10.0f, 5.0f, -1); + env->step(m_step_interval); + + block = nullptr; + obj = nullptr; + UASSERT(!env->getActiveObject(obj_id)); + block = map.emergeBlock(testblockpos, false); + if (block) + UASSERTEQ(size_t, block->m_static_objects.size(), 0); +} + +void TestSAO::testActivate(ServerEnvironment *env) +{ + Map &map = env->getMap(); + + const v3f testpos(0, 0, 100 * BS); + const v3s16 testblockpos = getNodeBlockPos(floatToInt(testpos, BS)); + + // this time insert the static object manually + StaticObject s_obj; + { + auto obj = std::make_unique(env, testpos, "test:static", ""); + s_obj = StaticObject(obj.get(), obj->getBasePosition()); + } + + auto *block = map.emergeBlock(testblockpos, true); + UASSERT(block); + block->m_static_objects.insert(0, s_obj); + + // Activating the block will convert it to active. + env->activateBlock(block); + + const u16 obj_id = assert_active_in_block(block); + auto *obj = env->getActiveObject(obj_id); + UASSERT(obj); + + // same conditions as testStaticSave + UASSERT(obj->m_static_exists); + UASSERTEQ(auto, obj->m_static_block, testblockpos); + + // let the object be deactivated, it causes a warning when we unload + // MapBlocks in further tests otherwise + // FIXME: figure out if this is a bug that needs to be fixed + env->step(m_step_interval); +} + +void TestSAO::testStaticToFalse(ServerEnvironment *env) +{ + Map &map = env->getMap(); + + const v3f testpos(0, 0, -22 * BS); + const v3s16 testblockpos = getNodeBlockPos(floatToInt(testpos, BS)); + + /* + * This test represents an edge case where static_save changed from true + * to false while the server was off. + */ + + StaticObject s_obj; + { + auto obj = std::make_unique(env, testpos, "test:non_static", ""); + // since the object is not added, it doesn't read info from Lua and retains + // the default value. This is what allows us to do this. + UASSERT(obj->isStaticAllowed()); + s_obj = StaticObject(obj.get(), obj->getBasePosition()); + } + + auto *block = map.emergeBlock(testblockpos, true); + UASSERT(block); + block->m_static_objects.insert(0, s_obj); + + env->activateBlock(block); + + const u16 obj_id = assert_active_in_block(block); + auto *obj = env->getActiveObject(obj_id); + UASSERT(obj); + + // environment must remember place of static data + UASSERT(obj->m_static_exists); + UASSERTEQ(auto, obj->m_static_block, testblockpos); + +#if 0 + /* + * FIXME: needs investigation + * When using this code path the test fails and there's also a warning. + * The problem is that the block is unloaded while the object is still in the + * active list, removeFarObjects() has no chance at doing something. + * This seems to be a general issue that in practice only applies with static_save=false. + */ + map.timerUpdate(10.0f, 5.0f, -1); + env->step(m_step_interval); +#else + obj->markForRemoval(); + env->step(m_step_interval); +#endif + + block = nullptr; + obj = nullptr; + UASSERT(!env->getActiveObject(obj_id)); + // static data must have been deleted + block = map.emergeBlock(testblockpos, false); + if (block) + UASSERTEQ(size_t, block->m_static_objects.size(), 0); +} + +void TestSAO::testStaticToTrue(ServerEnvironment *env) +{ + Map &map = env->getMap(); + + const v3f testpos(123 * BS, 5 * BS, 0); + const v3s16 testblockpos = getNodeBlockPos(floatToInt(testpos, BS)); + + auto obj = add_entity(env, testpos, "test:non_static"); + UASSERT(obj); + const u16 obj_id = obj->getId(); + + UASSERT(!obj->m_static_exists); + obj->accessObjectProperties()->static_save = true; + + env->step(m_step_interval); + + obj = nullptr; + UASSERT(!env->getActiveObject(obj_id)); + + // data must have been newly saved + auto *block = map.getBlockNoCreateNoEx(testblockpos); + UASSERT(block); + UASSERTEQ(size_t, block->m_static_objects.getStoredSize(), 1); + UASSERTEQ(size_t, block->m_static_objects.getActiveSize(), 0); +} From 234b01a8c29d5686e437a525351160b86079cf54 Mon Sep 17 00:00:00 2001 From: cx384 Date: Sun, 17 Mar 2024 15:55:38 +0100 Subject: [PATCH 48/91] Item meta pointing range (#14347) --- builtin/game/features.lua | 1 + doc/lua_api.md | 5 +++++ games/devtest/mods/testitems/init.lua | 15 +++++++++++++++ .../textures/testitems_telescope_stick.png | Bin 0 -> 170 bytes src/client/game.cpp | 4 ++-- src/network/serverpackethandler.cpp | 3 +-- src/tool.cpp | 16 +++++++++++----- src/tool.h | 4 +++- 8 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 games/devtest/mods/testitems/textures/testitems_telescope_stick.png diff --git a/builtin/game/features.lua b/builtin/game/features.lua index 0b5b40fb5..874d3e885 100644 --- a/builtin/game/features.lua +++ b/builtin/game/features.lua @@ -38,6 +38,7 @@ core.features = { dynamic_add_media_startup = true, dynamic_add_media_filepath = true, lsystem_decoration_type = true, + item_meta_range = true, } function core.has_feature(arg) diff --git a/doc/lua_api.md b/doc/lua_api.md index 3a5f0460e..be11a4c5d 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -2560,6 +2560,8 @@ Some of the values in the key-value store are handled specially: 0 = default, 1 = left / up, 2 = middle, 3 = right / down The default currently is the same as right/down. Example: 6 = 2 + 1*4 = middle,up +* `range`: Overrides the pointing range + Example: `meta:set_float("range", 4.2)` Example: @@ -5397,6 +5399,8 @@ Utilities dynamic_add_media_filepath = true, -- L-system decoration type (5.9.0) lsystem_decoration_type = true, + -- Overrideable pointing range using the itemstack meta key `"range"` (5.9.0) + item_meta_range = true, } ``` @@ -8980,6 +8984,7 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and range = 4.0, -- Range of node and object pointing that is possible with this item held + -- Can be overridden with itemstack meta. liquids_pointable = false, -- If true, item can point to all liquid nodes (`liquidtype ~= "none"`), diff --git a/games/devtest/mods/testitems/init.lua b/games/devtest/mods/testitems/init.lua index ec080a7c5..bde9cc6d9 100644 --- a/games/devtest/mods/testitems/init.lua +++ b/games/devtest/mods/testitems/init.lua @@ -90,3 +90,18 @@ minetest.register_craftitem("testitems:image_meta", { return itemstack end, }) + +minetest.register_craftitem("testitems:telescope_stick", { + description = S("Telescope Stick (Increases range on use.)"), + inventory_image = "testitems_telescope_stick.png", + on_use = function(itemstack, player) + local meta = itemstack:get_meta() + local range = meta:get_float("range") + 1.2 + if range > 10 then + range = 0 + end + meta:set_float("range", range) + minetest.chat_send_player(player:get_player_name(), "Telescope Stick range set to "..range) + return itemstack + end, +}) diff --git a/games/devtest/mods/testitems/textures/testitems_telescope_stick.png b/games/devtest/mods/testitems/textures/testitems_telescope_stick.png new file mode 100644 index 0000000000000000000000000000000000000000..88d004c4c3145b27865ec6e4d7be3ab9360dbdcb GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`g`O^sAr_~PPBP?TP~>5$E%(Yj z>a=0QY5(sxoH)X^?|j5GO)|}3=^w*v-6hkHOB9qZQP>)G#?rB4O-@?I+Qtb}jN}zH zpYGj$O?GPa`>5}0bxQA_3NoL*vURJ*YD<6a9Z+TO~L6&a;L!0h<)dni+t8r TC3$v$+`!=J>gTe~DWM4f73x6F literal 0 HcmV?d00001 diff --git a/src/client/game.cpp b/src/client/game.cpp index 3a42f2b0c..a140b730c 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1384,7 +1384,7 @@ void Game::copyServerClientCache() { // It would be possible to let the client directly read the media files // from where the server knows they are. But aside from being more complicated - // it would also *not* fill the media cache and cause slower joining of + // it would also *not* fill the media cache and cause slower joining of // remote servers. // (Imagine that you launch a game once locally and then connect to a server.) @@ -3233,7 +3233,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud) const ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item); const ItemDefinition &selected_def = selected_item.getDefinition(itemdef_manager); - f32 d = getToolRange(selected_def, hand_item.getDefinition(itemdef_manager)); + f32 d = getToolRange(selected_item, hand_item, itemdef_manager); core::line3d shootline; diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index f4b5a4859..6d93265eb 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -895,8 +895,7 @@ bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std: { ItemStack selected_item, hand_item; player->getWieldedItem(&selected_item, &hand_item); - f32 max_d = BS * getToolRange(selected_item.getDefinition(m_itemdef), - hand_item.getDefinition(m_itemdef)); + f32 max_d = BS * getToolRange(selected_item, hand_item, m_itemdef); // Cube diagonal * 1.5 for maximal supported node extents: // sqrt(3) * 1.5 ≅ 2.6 diff --git a/src/tool.cpp b/src/tool.cpp index 3f3c2f7bd..9b1dcc247 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/hex.h" #include "common/c_content.h" #include - + void ToolGroupCap::toJson(Json::Value &object) const { @@ -246,7 +246,7 @@ std::optional WearBarParams::deserializeJson(std::istream &is) blend = static_cast(blendInt); else return std::nullopt; - + const Json::Value &color_stops_object = root["color_stops"]; std::map colorStops; for (const std::string &key : color_stops_object.getMemberNames()) { @@ -491,10 +491,16 @@ PunchDamageResult getPunchDamage( return result; } -f32 getToolRange(const ItemDefinition &def_selected, const ItemDefinition &def_hand) +f32 getToolRange(const ItemStack &wielded_item, const ItemStack &hand_item, + const IItemDefManager *itemdef_manager) { - float max_d = def_selected.range; - float max_d_hand = def_hand.range; + const std::string &wielded_meta_range = wielded_item.metadata.getString("range"); + const std::string &hand_meta_range = hand_item.metadata.getString("range"); + + f32 max_d = wielded_meta_range.empty() ? wielded_item.getDefinition(itemdef_manager).range : + stof(wielded_meta_range); + f32 max_d_hand = hand_meta_range.empty() ? hand_item.getDefinition(itemdef_manager).range : + stof(hand_meta_range); if (max_d < 0 && max_d_hand >= 0) max_d = max_d_hand; diff --git a/src/tool.h b/src/tool.h index 3121e907d..55a8bf914 100644 --- a/src/tool.h +++ b/src/tool.h @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include struct ItemDefinition; +class IItemDefManager; struct ToolGroupCap { @@ -179,4 +180,5 @@ PunchDamageResult getPunchDamage( ); u32 calculateResultWear(const u32 uses, const u16 initial_wear); -f32 getToolRange(const ItemDefinition &def_selected, const ItemDefinition &def_hand); +f32 getToolRange(const ItemStack &wielded_item, const ItemStack &hand_item, + const IItemDefManager *itemdef_manager); From a862e4290c8ddffbcbb1c03291bd571109aef8b4 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 17 Mar 2024 17:32:35 +0100 Subject: [PATCH 49/91] Script API: Fix invalid rotation of L-system trees The MapNode struct fields param1 and param2 were previously not initialized. This commit now sets them to a sane default. --- src/mapgen/treegen.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mapgen/treegen.h b/src/mapgen/treegen.h index 5ba1cc10c..bae541030 100644 --- a/src/mapgen/treegen.h +++ b/src/mapgen/treegen.h @@ -36,6 +36,13 @@ namespace treegen { }; struct TreeDef : public NodeResolver { + TreeDef() : + // Initialize param1 and param2 + trunknode(CONTENT_IGNORE), + leavesnode(CONTENT_IGNORE), + leaves2node(CONTENT_IGNORE), + fruitnode(CONTENT_IGNORE) + {} virtual void resolveNodeNames(); std::string initial_axiom; From fa072c1d2cfba5f57ee528dde143947e5046f2d5 Mon Sep 17 00:00:00 2001 From: goodusername123 <61405538+goodusername123@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:54:57 -0500 Subject: [PATCH 50/91] Update Lua BitOp's stdint.h check for MSVC based on https://github.com/LuaJIT/LuaJIT/commit/3ece3a3e3a448ecc54e317fd5743d1f4c19db28b --- lib/bitop/bit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bitop/bit.cpp b/lib/bitop/bit.cpp index 39b53838f..9957ab5c2 100644 --- a/lib/bitop/bit.cpp +++ b/lib/bitop/bit.cpp @@ -37,8 +37,8 @@ extern "C" { #include "lauxlib.h" } -#ifdef _MSC_VER -/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */ +#if defined(_MSC_VER) && (_MSC_VER < 1700) +/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */ typedef __int32 int32_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; From cda112493a6f91a84f065463bb1783ac0e6b1e08 Mon Sep 17 00:00:00 2001 From: HybridDog <3192173+HybridDog@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:56:47 +0100 Subject: [PATCH 51/91] Faster blit_with_alpha() (#14448) * Add test nodes for alpha compositing and the fill texture modifier Texture test nodes can be helpful to test if `blit_with_alpha` works correctly. The alpha compositing test node covers different cases where pixel colors are mixed with each other. The test currently fails because `blitPixel` does not work correctly if a semi-transparent color is drawn on top of another semi-transparent color. The test nodes for the fill texture modifier show if the size and position arguments of the modifier work correctly. They do not cover special cases such as very large or negative position or size values. * Faster blit_with_alpha() The `blit_with_alpha` function has a noticeable effect on the time it takes to join a game. To reduce the join times, I replace the `blit_with_alpha` function with a new one: * It does not uses floating-point numbers. * It directly operates on the raw pixel data instead of using the comparatively slow `setPixel` and `getPixel` functions from Irrlicht. Only ECF_A8R8G8B8 base images are supported now. If the top image does not have the ECF_A8R8G8B8 color format, it is converted; I assume that this happens rarely. * There are case distinctions for fully opaque, fully transparent and semi-transparent pixels. This empirically increases the performance since the mixing between two semi-transparent happens rarely. * The new function no longer has the `src_pos` argument since it was always the zero vector. * The function is only documented once where it is declared. For backwards compatibility, `blit_with_alpha` still mixes colors without gamma correction. `blit_with_alpha` nonetheless behaves slightly different than before: If a semi-transparent pixel is drawn on top of another semi-transparent pixel, the color is mixed in a way which we can consider to be more correct now. --- games/devtest/mods/testnodes/textures.lua | 32 ++++ .../testnodes_alpha_compositing_bottom.png | Bin 0 -> 251 bytes .../testnodes_alpha_compositing_top.png | Bin 0 -> 160 bytes .../testnodes_fill_positioning_reference.png | Bin 0 -> 92 bytes src/client/texturesource.cpp | 166 ++++++++++++------ 5 files changed, 146 insertions(+), 52 deletions(-) create mode 100644 games/devtest/mods/testnodes/textures/testnodes_alpha_compositing_bottom.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_alpha_compositing_top.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_fill_positioning_reference.png diff --git a/games/devtest/mods/testnodes/textures.lua b/games/devtest/mods/testnodes/textures.lua index 8c7f198c3..0caaaed9d 100644 --- a/games/devtest/mods/testnodes/textures.lua +++ b/games/devtest/mods/testnodes/textures.lua @@ -33,6 +33,25 @@ minetest.register_node("testnodes:anim", { groups = { dig_immediate = 2 }, }) +minetest.register_node("testnodes:fill_positioning", { + description = S("Fill Modifier Test Node") .. "\n" .. + S("The node should have the same look as " .. + "testnodes:fill_positioning_reference."), + drawtype = "glasslike", + paramtype = "light", + tiles = {"[fill:16x16:#ffffff^[fill:6x6:1,1:#00ffdc" .. + "^[fill:6x6:1,9:#00ffdc^[fill:6x6:9,1:#00ffdc^[fill:6x6:9,9:#00ffdc"}, + groups = {dig_immediate = 3}, +}) + +minetest.register_node("testnodes:fill_positioning_reference", { + description = S("Fill Modifier Test Node Reference"), + drawtype = "glasslike", + paramtype = "light", + tiles = {"testnodes_fill_positioning_reference.png"}, + groups = {dig_immediate = 3}, +}) + -- Node texture transparency test local alphas = { 64, 128, 191 } @@ -69,6 +88,19 @@ for a=1,#alphas do }) end +minetest.register_node("testnodes:alpha_compositing", { + description = S("Alpha Compositing Test Node") .. "\n" .. + S("A regular grid should be visible where each cell contains two " .. + "texels with the same colour.") .. "\n" .. + S("Alpha compositing is gamma-incorrect for backwards compatibility."), + drawtype = "glasslike", + paramtype = "light", + tiles = {"testnodes_alpha_compositing_bottom.png^" .. + "testnodes_alpha_compositing_top.png"}, + use_texture_alpha = "blend", + groups = {dig_immediate = 3}, +}) + -- Generate PNG textures local function mandelbrot(w, h, iterations) diff --git a/games/devtest/mods/testnodes/textures/testnodes_alpha_compositing_bottom.png b/games/devtest/mods/testnodes/textures/testnodes_alpha_compositing_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..83447e42309a9c7433a74662b39fb40175bb74a9 GIT binary patch literal 251 zcmV<4M4S+DfY!}huY-W(A zVo^~ps1w18>+9?PKbxFW=HlYO29kGnbrgZi0|}6yFclySz%LI2KmoXuktJblT=Enf zKrkHunPjE|gaJc69RO*{(gBdBEFHkaaLH3_004eq!}dqKANT+O002ovPDHLkV1gM> BW)c7Z literal 0 HcmV?d00001 diff --git a/games/devtest/mods/testnodes/textures/testnodes_alpha_compositing_top.png b/games/devtest/mods/testnodes/textures/testnodes_alpha_compositing_top.png new file mode 100644 index 0000000000000000000000000000000000000000..64b5664d8df4f1599d23330c685f54e730bccf48 GIT binary patch literal 160 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`>7Fi*Ar-fhPfVKs^?%rsZ}o4Z zy|-mtzw;~KPXDvLfXSc#=ReGEzopr0KU98tN;K2 literal 0 HcmV?d00001 diff --git a/games/devtest/mods/testnodes/textures/testnodes_fill_positioning_reference.png b/games/devtest/mods/testnodes/textures/testnodes_fill_positioning_reference.png new file mode 100644 index 0000000000000000000000000000000000000000..2ecd969550500f8fefe0d0c394ccfbd4e92722d3 GIT binary patch literal 92 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;TYyi9>;M1%8UEk#Y~Ju0C?e?T o;uunKE198bmsJT1i^UN}>HXXnS&wE103{hbUHx3vIVCg!0KC{3c>n+a literal 0 HcmV?d00001 diff --git a/src/client/texturesource.cpp b/src/client/texturesource.cpp index 6842b08a9..e23b88dbe 100644 --- a/src/client/texturesource.cpp +++ b/src/client/texturesource.cpp @@ -404,12 +404,22 @@ u32 TextureSource::getTextureId(const std::string &name) return 0; } -// Draw an image on top of another one, using the alpha channel of the -// source image -// overlay: only modify destination pixels that are fully opaque. + +/** Draw an image on top of another one with gamma-incorrect alpha compositing + * + * This exists because IImage::copyToWithAlpha() doesn't seem to always work. + * + * \tparam overlay If enabled, only modify pixels in dst which are fully opaque. + * Defaults to false. + * \param src Top image. This image must have the ECF_A8R8G8B8 color format. + * \param dst Bottom image. + * The top image is drawn onto this base image in-place. + * \param dst_pos An offset vector to move src before drawing it onto dst + * \param size Size limit of the copied area +*/ template static void blit_with_alpha(video::IImage *src, video::IImage *dst, - v2s32 src_pos, v2s32 dst_pos, v2u32 size); + v2s32 dst_pos, v2u32 size); // Apply a color to an image. Uses an int (0-255) to calculate the ratio. // If the ratio is 255 or -1 and keep_alpha is true, then it multiples the @@ -914,7 +924,7 @@ video::IImage* TextureSource::generateImage(std::string_view name, if (baseimg) { core::dimension2d dim = tmp->getDimension(); - blit_with_alpha(tmp, baseimg, v2s32(0, 0), v2s32(0, 0), dim); + blit_with_alpha(tmp, baseimg, v2s32(0, 0), dim); tmp->drop(); } else { baseimg = tmp; @@ -1001,10 +1011,8 @@ void blitBaseImage(video::IImage* &src, video::IImage* &dst) core::dimension2d dim_dst = dst->getDimension(); // Position to copy the blitted to in the base image core::position2d pos_to(0,0); - // Position to copy the blitted from in the blitted image - core::position2d pos_from(0,0); - blit_with_alpha(src, dst, pos_from, pos_to, dim_dst); + blit_with_alpha(src, dst, pos_to, dim_dst); } #define CHECK_BASEIMG() \ @@ -1192,7 +1200,7 @@ bool TextureSource::generateImagePart(std::string_view part_of_name, continue; } - blit_with_alpha(img, baseimg, v2s32(0,0), pos_base, dim); + blit_with_alpha(img, baseimg, pos_base, dim); img->drop(); } } @@ -1237,7 +1245,7 @@ bool TextureSource::generateImagePart(std::string_view part_of_name, if (baseimg == nullptr) { baseimg = img; } else { - blit_with_alpha(img, baseimg, v2s32(0, 0), v2s32(x, y), dim); + blit_with_alpha(img, baseimg, v2s32(x, y), dim); img->drop(); } } @@ -1850,58 +1858,112 @@ bool TextureSource::generateImagePart(std::string_view part_of_name, #undef CHECK_DIM -/* - Calculate the color of a single pixel drawn on top of another pixel. - This is a little more complicated than just video::SColor::getInterpolated - because getInterpolated does not handle alpha correctly. For example, a - pixel with alpha=64 drawn atop a pixel with alpha=128 should yield a - pixel with alpha=160, while getInterpolated would yield alpha=96. +namespace { + +/** Calculate the color of a single pixel drawn on top of another pixel without + * gamma correction + * + * The color mixing is a little more complicated than just + * video::SColor::getInterpolated because getInterpolated does not handle alpha + * correctly. + * For example, a pixel with alpha=64 drawn atop a pixel with alpha=128 should + * yield a pixel with alpha=160, while getInterpolated would yield alpha=96. + * + * \tparam overlay If enabled, only modify dst_col if it is fully opaque + * \param src_col Color of the top pixel + * \param dst_col Color of the bottom pixel. This color is modified in-place to + * store the result. */ -static inline video::SColor blitPixel(const video::SColor src_c, const video::SColor dst_c, u32 ratio) +template +void blit_pixel(video::SColor src_col, video::SColor &dst_col) { - if (dst_c.getAlpha() == 0) - return src_c; - video::SColor out_c = src_c.getInterpolated(dst_c, (float)ratio / 255.0f); - out_c.setAlpha(dst_c.getAlpha() + (255 - dst_c.getAlpha()) * - src_c.getAlpha() * ratio / (255 * 255)); - return out_c; + u8 dst_a = (u8)dst_col.getAlpha(); + if constexpr (overlay) { + if (dst_a != 255) + // The bottom pixel has transparency -> do nothing + return; + } + u8 src_a = (u8)src_col.getAlpha(); + if (src_a == 0) { + // A fully transparent pixel is on top -> do nothing + return; + } + if (src_a == 255 || dst_a == 0) { + // The top pixel is fully opaque or the bottom pixel is + // fully transparent -> replace the color + dst_col = src_col; + return; + } + struct Color { u8 r, g, b; }; + Color src{(u8)src_col.getRed(), (u8)src_col.getGreen(), + (u8)src_col.getBlue()}; + Color dst{(u8)dst_col.getRed(), (u8)dst_col.getGreen(), + (u8)dst_col.getBlue()}; + if (dst_a == 255) { + // A semi-transparent pixel is on top and an opaque one in + // the bottom -> lerp r, g, and b + dst.r = (dst.r * (255 - src_a) + src.r * src_a) / 255; + dst.g = (dst.g * (255 - src_a) + src.g * src_a) / 255; + dst.b = (dst.b * (255 - src_a) + src.b * src_a) / 255; + dst_col.set(255, dst.r, dst.g, dst.b); + return; + } + // A semi-transparent pixel is on top of a + // semi-transparent pixel -> general alpha compositing + u16 a_new_255 = src_a * 255 + (255 - src_a) * dst_a; + dst.r = (dst.r * (255 - src_a) * dst_a + src.r * src_a * 255) / a_new_255; + dst.g = (dst.g * (255 - src_a) * dst_a + src.g * src_a * 255) / a_new_255; + dst.b = (dst.b * (255 - src_a) * dst_a + src.b * src_a * 255) / a_new_255; + dst_a = (a_new_255 + 127) / 255; + dst_col.set(dst_a, dst.r, dst.g, dst.b); } -/* - Draw an image on top of another one, using the alpha channel of the - source image +} // namespace - This exists because IImage::copyToWithAlpha() doesn't seem to always - work. -*/ template -static void blit_with_alpha(video::IImage *src, video::IImage *dst, - v2s32 src_pos, v2s32 dst_pos, v2u32 size) +void blit_with_alpha(video::IImage *src, video::IImage *dst, v2s32 dst_pos, + v2u32 size) { - auto src_dim = src->getDimension(); - auto dst_dim = dst->getDimension(); + if (dst->getColorFormat() != video::ECF_A8R8G8B8) + throw BaseException("blit_with_alpha() supports only ECF_A8R8G8B8 " + "destination images."); + core::dimension2d src_dim = src->getDimension(); + core::dimension2d dst_dim = dst->getDimension(); + bool drop_src = false; + if (src->getColorFormat() != video::ECF_A8R8G8B8) { + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::IImage *src_converted = driver->createImage(video::ECF_A8R8G8B8, + src_dim); + if (!src_converted) + throw BaseException("blit_with_alpha() failed to convert the " + "source image to ECF_A8R8G8B8."); + src->copyTo(src_converted); + src = src_converted; + drop_src = true; + } + video::SColor *pixels_src = + reinterpret_cast(src->getData()); + video::SColor *pixels_dst = + reinterpret_cast(dst->getData()); // Limit y and x to the overlapping ranges // s.t. the positions are all in bounds after offsetting. - for (u32 y0 = std::max(0, -dst_pos.Y); - y0 < std::min({size.Y, src_dim.Height, dst_dim.Height - (s64) dst_pos.Y}); - ++y0) - for (u32 x0 = std::max(0, -dst_pos.X); - x0 < std::min({size.X, src_dim.Width, dst_dim.Width - (s64) dst_pos.X}); - ++x0) - { - s32 src_x = src_pos.X + x0; - s32 src_y = src_pos.Y + y0; - s32 dst_x = dst_pos.X + x0; - s32 dst_y = dst_pos.Y + y0; - video::SColor src_c = src->getPixel(src_x, src_y); - video::SColor dst_c = dst->getPixel(dst_x, dst_y); - if (!overlay || (dst_c.getAlpha() == 255 && src_c.getAlpha() != 0)) { - dst_c = blitPixel(src_c, dst_c, src_c.getAlpha()); - dst->setPixel(dst_x, dst_y, dst_c); + u32 x_start = (u32)std::max(0, -dst_pos.X); + u32 y_start = (u32)std::max(0, -dst_pos.Y); + u32 x_end = (u32)std::min({size.X, src_dim.Width, + dst_dim.Width - (s64)dst_pos.X}); + u32 y_end = (u32)std::min({size.Y, src_dim.Height, + dst_dim.Height - (s64)dst_pos.Y}); + for (u32 y0 = y_start; y0 < y_end; ++y0) { + size_t i_src = y0 * src_dim.Width + x_start; + size_t i_dst = (dst_pos.Y + y0) * dst_dim.Width + dst_pos.X + x_start; + for (u32 x0 = x_start; x0 < x_end; ++x0) { + blit_pixel(pixels_src[i_src++], pixels_dst[i_dst++]); } } + if (drop_src) + src->drop(); } /* @@ -2035,7 +2097,7 @@ static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, } // Adjusting saturation in the same manner as lightness resulted in - // muted colours being affected too much and bright colours not + // muted colors being affected too much and bright colors not // affected enough, so I'm borrowing a leaf out of gimp's book and // using a different scaling approach for saturation. // https://github.com/GNOME/gimp/blob/6cc1e035f1822bf5198e7e99a53f7fa6e281396a/app/operations/gimpoperationhuesaturation.c#L139-L145= @@ -2245,7 +2307,7 @@ static void draw_crack(video::IImage *crack, video::IImage *dst, auto blit = use_overlay ? blit_with_alpha : blit_with_alpha; for (s32 i = 0; i < frame_count; ++i) { v2s32 dst_pos(0, frame_size.Height * i); - blit(crack_scaled, dst, v2s32(0,0), dst_pos, frame_size); + blit(crack_scaled, dst, dst_pos, frame_size); } crack_scaled->drop(); @@ -2394,7 +2456,7 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name) } namespace { - // For more colourspace transformations, see for example + // For more colorspace transformations, see for example // https://github.com/tobspr/GLSL-Color-Spaces/blob/master/ColorSpaces.inc.glsl inline float linear_to_srgb_component(float v) From 751ede516bf006edb9fca2610fc951bcc5eaf1d5 Mon Sep 17 00:00:00 2001 From: Desour Date: Wed, 20 Mar 2024 15:28:37 +0100 Subject: [PATCH 52/91] ProfilerGraph: Increase buffer size for min/max formatting Fixes values being cut off, e.g. "1.0000e+06" to "1.0000e+0". --- src/gui/profilergraph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/profilergraph.cpp b/src/gui/profilergraph.cpp index f71ef3799..e6fdf9ae8 100644 --- a/src/gui/profilergraph.cpp +++ b/src/gui/profilergraph.cpp @@ -95,7 +95,7 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver, } const s32 texth = 15; - char buf[10]; + char buf[20]; if (floorf(show_max) == show_max) porting::mt_snprintf(buf, sizeof(buf), "%.5g", show_max); else From 178943b4b7550b7f3e3736b6cc99c9155b82e924 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 6 Mar 2024 18:57:01 +0100 Subject: [PATCH 53/91] Improve ServerEnvironment::getRemovedActiveObjects() in many ways --- src/server.cpp | 78 ++++++++------------- src/server.h | 5 +- src/server/activeobjectmgr.cpp | 8 +-- src/server/activeobjectmgr.h | 6 +- src/serverenvironment.cpp | 20 +++--- src/serverenvironment.h | 8 +-- src/unittest/test_serveractiveobjectmgr.cpp | 4 +- 7 files changed, 56 insertions(+), 73 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 159076686..e85bbafd8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2047,91 +2047,72 @@ void Server::SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersa if (my_radius <= 0) my_radius = radius; - std::queue> removed_objects; - std::queue added_objects; + std::vector> removed_objects; + std::vector added_objects; m_env->getRemovedActiveObjects(playersao, my_radius, player_radius, client->m_known_objects, removed_objects); m_env->getAddedActiveObjects(playersao, my_radius, player_radius, client->m_known_objects, added_objects); - int removed_count = removed_objects.size(); - int added_count = added_objects.size(); - if (removed_objects.empty() && added_objects.empty()) return; - char buf[4]; - std::string data; + NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, + 2 * removed_objects.size() + 32 * added_objects.size(), client->peer_id); - // Handle removed objects + // Removed objects + pkt << static_cast(removed_objects.size()); - writeU16((u8*)buf, removed_objects.size()); - data.append(buf, 2); - while (!removed_objects.empty()) { - // Get object - const auto [gone, id] = removed_objects.front(); - ServerActiveObject* obj = m_env->getActiveObject(id); + std::vector sounds_to_stop; + + for (auto &it : removed_objects) { + const auto [gone, id] = it; + ServerActiveObject *obj = m_env->getActiveObject(id); // Stop sounds if objects go out of range. // This fixes https://github.com/minetest/minetest/issues/8094. // We may not remove sounds if an entity was removed on the server. // See https://github.com/minetest/minetest/issues/14422. if (!gone) // just out of range for client, not gone on server? - stopAttachedSounds(client->peer_id, id); + sounds_to_stop.push_back(id); - // Add to data buffer for sending - writeU16((u8*)buf, id); - data.append(buf, 2); + pkt << id; // Remove from known objects client->m_known_objects.erase(id); - if (obj && obj->m_known_by_count > 0) obj->m_known_by_count--; - - removed_objects.pop(); } - // Handle added objects - writeU16((u8*)buf, added_objects.size()); - data.append(buf, 2); - while (!added_objects.empty()) { - // Get object - u16 id = added_objects.front(); - ServerActiveObject *obj = m_env->getActiveObject(id); - added_objects.pop(); + if (!sounds_to_stop.empty()) + stopAttachedSounds(client->peer_id, sounds_to_stop); + // Added objects + pkt << static_cast(added_objects.size()); + + for (u16 id : added_objects) { + ServerActiveObject *obj = m_env->getActiveObject(id); if (!obj) { - warningstream << FUNCTION_NAME << ": NULL object id=" + warningstream << FUNCTION_NAME << ": found NULL object id=" << (int)id << std::endl; continue; } - // Get object type u8 type = obj->getSendType(); - // Add to data buffer for sending - writeU16((u8*)buf, id); - data.append(buf, 2); - writeU8((u8*)buf, type); - data.append(buf, 1); - - data.append(serializeString32( - obj->getClientInitializationData(client->net_proto_version))); + pkt << id << type; + pkt.putLongString(obj->getClientInitializationData(client->net_proto_version)); // Add to known objects client->m_known_objects.insert(id); - obj->m_known_by_count++; } - NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, data.size(), client->peer_id); - pkt.putRawString(data.c_str(), data.size()); Send(&pkt); - verbosestream << "Server::SendActiveObjectRemoveAdd: " - << removed_count << " removed, " << added_count << " added, " - << "packet size is " << pkt.getSize() << std::endl; + verbosestream << "Server::SendActiveObjectRemoveAdd(): " + << removed_objects.size() << " removed, " << added_objects.size() + << " added, packet size is " << pkt.getSize() << std::endl; } void Server::SendActiveObjectMessages(session_t peer_id, const std::string &datas, @@ -2288,13 +2269,14 @@ void Server::fadeSound(s32 handle, float step, float gain) m_playing_sounds.erase(it); } -void Server::stopAttachedSounds(session_t peer_id, u16 object_id) +void Server::stopAttachedSounds(session_t peer_id, + const std::vector &object_ids) { assert(peer_id != PEER_ID_INEXISTENT); - assert(object_id); + assert(!object_ids.empty()); auto cb = [&] (const s32 id, ServerPlayingSound &sound) -> bool { - if (sound.object != object_id) + if (!CONTAINS(object_ids, sound.object)) return false; auto clients_it = sound.clients.find(peer_id); diff --git a/src/server.h b/src/server.h index bd1547238..9facfb29d 100644 --- a/src/server.h +++ b/src/server.h @@ -239,8 +239,9 @@ public: s32 playSound(ServerPlayingSound ¶ms, bool ephemeral=false); void stopSound(s32 handle); void fadeSound(s32 handle, float step, float gain); - // Stop all sounds attached to an object for a certain client - void stopAttachedSounds(session_t peer_id, u16 object_id); + // Stop all sounds attached to given objects, for a certain client + void stopAttachedSounds(session_t peer_id, + const std::vector &object_ids); // Envlock std::set getPlayerEffectivePrivs(const std::string &name); diff --git a/src/server/activeobjectmgr.cpp b/src/server/activeobjectmgr.cpp index b4185d240..983fc0d95 100644 --- a/src/server/activeobjectmgr.cpp +++ b/src/server/activeobjectmgr.cpp @@ -153,9 +153,9 @@ void ActiveObjectMgr::getObjectsInArea(const aabb3f &box, } } -void ActiveObjectMgr::getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 radius, - f32 player_radius, std::set ¤t_objects, - std::queue &added_objects) +void ActiveObjectMgr::getAddedActiveObjectsAroundPos(v3f player_pos, f32 radius, + f32 player_radius, const std::set ¤t_objects, + std::vector &added_objects) { /* Go through the object list, @@ -188,7 +188,7 @@ void ActiveObjectMgr::getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 if (n != current_objects.end()) continue; // Add to added_objects - added_objects.push(id); + added_objects.push_back(id); } } diff --git a/src/server/activeobjectmgr.h b/src/server/activeobjectmgr.h index 5d333c232..dab795e8c 100644 --- a/src/server/activeobjectmgr.h +++ b/src/server/activeobjectmgr.h @@ -45,8 +45,8 @@ public: std::vector &result, std::function include_obj_cb); - void getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 radius, - f32 player_radius, std::set ¤t_objects, - std::queue &added_objects); + void getAddedActiveObjectsAroundPos(v3f player_pos, f32 radius, + f32 player_radius, const std::set ¤t_objects, + std::vector &added_objects); }; } // namespace server diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 56e7fe247..6f45f51c6 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1727,8 +1727,8 @@ u16 ServerEnvironment::addActiveObject(std::unique_ptr objec */ void ServerEnvironment::getAddedActiveObjects(PlayerSAO *playersao, s16 radius, s16 player_radius, - std::set ¤t_objects, - std::queue &added_objects) + const std::set ¤t_objects, + std::vector &added_objects) { f32 radius_f = radius * BS; f32 player_radius_f = player_radius * BS; @@ -1746,8 +1746,8 @@ void ServerEnvironment::getAddedActiveObjects(PlayerSAO *playersao, s16 radius, */ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius, s16 player_radius, - std::set ¤t_objects, - std::queue> &removed_objects) + const std::set ¤t_objects, + std::vector> &removed_objects) { f32 radius_f = radius * BS; f32 player_radius_f = player_radius * BS; @@ -1765,15 +1765,15 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius for (u16 id : current_objects) { ServerActiveObject *object = getActiveObject(id); - if (object == NULL) { - infostream << "ServerEnvironment::getRemovedActiveObjects():" - << " object in current_objects is NULL" << std::endl; - removed_objects.emplace(true, id); + if (!object) { + warningstream << FUNCTION_NAME << ": found NULL object id=" + << (int)id << std::endl; + removed_objects.emplace_back(true, id); continue; } if (object->isGone()) { - removed_objects.emplace(true, id); + removed_objects.emplace_back(true, id); continue; } @@ -1785,7 +1785,7 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius continue; // Object is no longer visible - removed_objects.emplace(false, id); + removed_objects.emplace_back(false, id); } } diff --git a/src/serverenvironment.h b/src/serverenvironment.h index ff2173938..21accff7e 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -286,8 +286,8 @@ public: */ void getAddedActiveObjects(PlayerSAO *playersao, s16 radius, s16 player_radius, - std::set ¤t_objects, - std::queue &added_objects); + const std::set ¤t_objects, + std::vector &added_objects); /* Find out what new objects have been removed from @@ -295,8 +295,8 @@ public: */ void getRemovedActiveObjects(PlayerSAO *playersao, s16 radius, s16 player_radius, - std::set ¤t_objects, - std::queue> &removed_objects); + const std::set ¤t_objects, + std::vector> &removed_objects); /* Get the next message emitted by some active object. diff --git a/src/unittest/test_serveractiveobjectmgr.cpp b/src/unittest/test_serveractiveobjectmgr.cpp index 3e57eb99a..7f0ca84cb 100644 --- a/src/unittest/test_serveractiveobjectmgr.cpp +++ b/src/unittest/test_serveractiveobjectmgr.cpp @@ -173,12 +173,12 @@ void TestServerActiveObjectMgr::testGetAddedActiveObjectsAroundPos() saomgr.registerObject(std::make_unique(nullptr, p)); } - std::queue result; + std::vector result; std::set cur_objects; saomgr.getAddedActiveObjectsAroundPos(v3f(), 100, 50, cur_objects, result); UASSERTCMP(int, ==, result.size(), 1); - result = std::queue(); + result.clear(); cur_objects.clear(); saomgr.getAddedActiveObjectsAroundPos(v3f(), 740, 50, cur_objects, result); UASSERTCMP(int, ==, result.size(), 2); From 0d817ff4ff4f0bd18d3c81fd9dbd708e297b21cc Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 6 Mar 2024 19:16:42 +0100 Subject: [PATCH 54/91] Try to fix httpfetch method bug see #14394 --- src/httpfetch.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index 2212ba453..87c1c51eb 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -229,9 +229,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_, oss(std::ios::binary) { curl = pool->alloc(); - if (curl == NULL) { + if (!curl) return; - } // Set static cURL options curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); @@ -417,10 +416,12 @@ HTTPFetchOngoing::~HTTPFetchOngoing() // Set safe options for the reusable cURL handle curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, httpfetch_discardfunction); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL); + curl_easy_setopt(curl, CURLOPT_USERAGENT, nullptr); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr); + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, nullptr); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, nullptr); if (http_header) { - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, nullptr); curl_slist_free_all(http_header); } if (multipart_mime) { From dfba79f8ff974963d86777399123a995a2cafcf2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 6 Mar 2024 21:04:57 +0100 Subject: [PATCH 55/91] Split servermap.cpp/h off from map.cpp/h --- src/CMakeLists.txt | 1 + src/emerge.cpp | 2 +- src/emerge.h | 2 +- src/map.cpp | 1197 -------------------------- src/map.h | 175 +--- src/mapgen/treegen.cpp | 2 +- src/network/clientpackethandler.cpp | 2 +- src/server.cpp | 2 +- src/serverenvironment.cpp | 1 - src/serverenvironment.h | 2 +- src/servermap.cpp | 1230 +++++++++++++++++++++++++++ src/servermap.h | 195 +++++ 12 files changed, 1433 insertions(+), 1378 deletions(-) create mode 100644 src/servermap.cpp create mode 100644 src/servermap.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 120ef277f..00f6b724e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -417,6 +417,7 @@ set(common_SRCS serialization.cpp server.cpp serverenvironment.cpp + servermap.cpp settings.cpp staticobject.cpp terminal_chat_console.cpp diff --git a/src/emerge.cpp b/src/emerge.cpp index bef1e34ac..5b778db69 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlicht_changes/printing.h" #include "filesys.h" #include "log.h" -#include "map.h" +#include "servermap.h" #include "mapblock.h" #include "mapgen/mg_biome.h" #include "mapgen/mg_ore.h" diff --git a/src/emerge.h b/src/emerge.h index ace9f6e46..6e4223c2d 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -39,7 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class EmergeThread; class NodeDefManager; class Settings; - +class MapSettingsManager; class BiomeManager; class OreManager; class DecorationManager; diff --git a/src/map.cpp b/src/map.cpp index 22731f120..cea2ed31c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -20,13 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "mapsector.h" #include "mapblock.h" -#include "filesys.h" #include "voxel.h" #include "voxelalgorithms.h" #include "porting.h" -#include "serialization.h" #include "nodemetadata.h" -#include "settings.h" #include "log.h" #include "profiler.h" #include "nodedef.h" @@ -34,29 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/directiontables.h" #include "rollback_interface.h" #include "environment.h" -#include "reflowscan.h" -#include "emerge.h" -#include "mapgen/mapgen_v6.h" -#include "mapgen/mg_biome.h" -#include "config.h" -#include "server.h" -#include "database/database.h" -#include "database/database-dummy.h" -#include "database/database-sqlite3.h" -#include "script/scripting_server.h" #include "irrlicht_changes/printing.h" -#include -#include -#if USE_LEVELDB -#include "database/database-leveldb.h" -#endif -#if USE_REDIS -#include "database/database-redis.h" -#endif -#if USE_POSTGRESQL -#include "database/database-postgresql.h" -#endif - /* Map @@ -478,446 +453,6 @@ void Map::PrintInfo(std::ostream &out) out<<"Map: "; } -#define WATER_DROP_BOOST 4 - -const static v3s16 liquid_6dirs[6] = { - // order: upper before same level before lower - v3s16( 0, 1, 0), - v3s16( 0, 0, 1), - v3s16( 1, 0, 0), - v3s16( 0, 0,-1), - v3s16(-1, 0, 0), - v3s16( 0,-1, 0) -}; - -enum NeighborType : u8 { - NEIGHBOR_UPPER, - NEIGHBOR_SAME_LEVEL, - NEIGHBOR_LOWER -}; - -struct NodeNeighbor { - MapNode n; - NeighborType t; - v3s16 p; - - NodeNeighbor() - : n(CONTENT_AIR), t(NEIGHBOR_SAME_LEVEL) - { } - - NodeNeighbor(const MapNode &node, NeighborType n_type, const v3s16 &pos) - : n(node), - t(n_type), - p(pos) - { } -}; - -static s8 get_max_liquid_level(NodeNeighbor nb, s8 current_max_node_level) -{ - s8 max_node_level = current_max_node_level; - u8 nb_liquid_level = (nb.n.param2 & LIQUID_LEVEL_MASK); - switch (nb.t) { - case NEIGHBOR_UPPER: - if (nb_liquid_level + WATER_DROP_BOOST > current_max_node_level) { - max_node_level = LIQUID_LEVEL_MAX; - if (nb_liquid_level + WATER_DROP_BOOST < LIQUID_LEVEL_MAX) - max_node_level = nb_liquid_level + WATER_DROP_BOOST; - } else if (nb_liquid_level > current_max_node_level) { - max_node_level = nb_liquid_level; - } - break; - case NEIGHBOR_LOWER: - break; - case NEIGHBOR_SAME_LEVEL: - if ((nb.n.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK && - nb_liquid_level > 0 && nb_liquid_level - 1 > max_node_level) - max_node_level = nb_liquid_level - 1; - break; - } - return max_node_level; -} - -void ServerMap::transforming_liquid_add(v3s16 p) { - m_transforming_liquid.push_back(p); -} - -void ServerMap::transformLiquids(std::map &modified_blocks, - ServerEnvironment *env) -{ - u32 loopcount = 0; - u32 initial_size = m_transforming_liquid.size(); - - /*if(initial_size != 0) - infostream<<"transformLiquids(): initial_size="< must_reflow; - - std::vector > changed_nodes; - - std::vector check_for_falling; - - u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); - u32 loop_max = liquid_loop_max; - - while (m_transforming_liquid.size() != 0) - { - // This should be done here so that it is done when continue is used - if (loopcount >= initial_size || loopcount >= loop_max) - break; - loopcount++; - - /* - Get a queued transforming liquid node - */ - v3s16 p0 = m_transforming_liquid.front(); - m_transforming_liquid.pop_front(); - - MapNode n0 = getNode(p0); - - /* - Collect information about current node - */ - s8 liquid_level = -1; - // The liquid node which will be placed there if - // the liquid flows into this node. - content_t liquid_kind = CONTENT_IGNORE; - // The node which will be placed there if liquid - // can't flow into this node. - content_t floodable_node = CONTENT_AIR; - const ContentFeatures &cf = m_nodedef->get(n0); - LiquidType liquid_type = cf.liquid_type; - switch (liquid_type) { - case LIQUID_SOURCE: - liquid_level = LIQUID_LEVEL_SOURCE; - liquid_kind = cf.liquid_alternative_flowing_id; - break; - case LIQUID_FLOWING: - liquid_level = (n0.param2 & LIQUID_LEVEL_MASK); - liquid_kind = n0.getContent(); - break; - case LIQUID_NONE: - // if this node is 'floodable', it *could* be transformed - // into a liquid, otherwise, continue with the next node. - if (!cf.floodable) - continue; - floodable_node = n0.getContent(); - liquid_kind = CONTENT_AIR; - break; - case LiquidType_END: - break; - } - - /* - Collect information about the environment - */ - NodeNeighbor sources[6]; // surrounding sources - int num_sources = 0; - NodeNeighbor flows[6]; // surrounding flowing liquid nodes - int num_flows = 0; - NodeNeighbor airs[6]; // surrounding air - int num_airs = 0; - NodeNeighbor neutrals[6]; // nodes that are solid or another kind of liquid - int num_neutrals = 0; - bool flowing_down = false; - bool ignored_sources = false; - bool floating_node_above = false; - for (u16 i = 0; i < 6; i++) { - NeighborType nt = NEIGHBOR_SAME_LEVEL; - switch (i) { - case 0: - nt = NEIGHBOR_UPPER; - break; - case 5: - nt = NEIGHBOR_LOWER; - break; - default: - break; - } - v3s16 npos = p0 + liquid_6dirs[i]; - NodeNeighbor nb(getNode(npos), nt, npos); - const ContentFeatures &cfnb = m_nodedef->get(nb.n); - if (nt == NEIGHBOR_UPPER && cfnb.floats) - floating_node_above = true; - switch (cfnb.liquid_type) { - case LIQUID_NONE: - if (cfnb.floodable) { - airs[num_airs++] = nb; - // if the current node is a water source the neighbor - // should be enqueded for transformation regardless of whether the - // current node changes or not. - if (nb.t != NEIGHBOR_UPPER && liquid_type != LIQUID_NONE) - m_transforming_liquid.push_back(npos); - // if the current node happens to be a flowing node, it will start to flow down here. - if (nb.t == NEIGHBOR_LOWER) - flowing_down = true; - } else { - neutrals[num_neutrals++] = nb; - if (nb.n.getContent() == CONTENT_IGNORE) { - // If node below is ignore prevent water from - // spreading outwards and otherwise prevent from - // flowing away as ignore node might be the source - if (nb.t == NEIGHBOR_LOWER) - flowing_down = true; - else - ignored_sources = true; - } - } - break; - case LIQUID_SOURCE: - // if this node is not (yet) of a liquid type, choose the first liquid type we encounter - if (liquid_kind == CONTENT_AIR) - liquid_kind = cfnb.liquid_alternative_flowing_id; - if (cfnb.liquid_alternative_flowing_id != liquid_kind) { - neutrals[num_neutrals++] = nb; - } else { - // Do not count bottom source, it will screw things up - if(nt != NEIGHBOR_LOWER) - sources[num_sources++] = nb; - } - break; - case LIQUID_FLOWING: - if (nb.t != NEIGHBOR_SAME_LEVEL || - (nb.n.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK) { - // if this node is not (yet) of a liquid type, choose the first liquid type we encounter - // but exclude falling liquids on the same level, they cannot flow here anyway - - // used to determine if the neighbor can even flow into this node - s8 max_level_from_neighbor = get_max_liquid_level(nb, -1); - u8 range = m_nodedef->get(cfnb.liquid_alternative_flowing_id).liquid_range; - - if (liquid_kind == CONTENT_AIR && - max_level_from_neighbor >= (LIQUID_LEVEL_MAX + 1 - range)) - liquid_kind = cfnb.liquid_alternative_flowing_id; - } - if (cfnb.liquid_alternative_flowing_id != liquid_kind) { - neutrals[num_neutrals++] = nb; - } else { - flows[num_flows++] = nb; - if (nb.t == NEIGHBOR_LOWER) - flowing_down = true; - } - break; - case LiquidType_END: - break; - } - } - - /* - decide on the type (and possibly level) of the current node - */ - content_t new_node_content; - s8 new_node_level = -1; - s8 max_node_level = -1; - - u8 range = m_nodedef->get(liquid_kind).liquid_range; - if (range > LIQUID_LEVEL_MAX + 1) - range = LIQUID_LEVEL_MAX + 1; - - if ((num_sources >= 2 && m_nodedef->get(liquid_kind).liquid_renewable) || liquid_type == LIQUID_SOURCE) { - // liquid_kind will be set to either the flowing alternative of the node (if it's a liquid) - // or the flowing alternative of the first of the surrounding sources (if it's air), so - // it's perfectly safe to use liquid_kind here to determine the new node content. - new_node_content = m_nodedef->get(liquid_kind).liquid_alternative_source_id; - } else if (num_sources >= 1 && sources[0].t != NEIGHBOR_LOWER) { - // liquid_kind is set properly, see above - max_node_level = new_node_level = LIQUID_LEVEL_MAX; - if (new_node_level >= (LIQUID_LEVEL_MAX + 1 - range)) - new_node_content = liquid_kind; - else - new_node_content = floodable_node; - } else if (ignored_sources && liquid_level >= 0) { - // Maybe there are neighboring sources that aren't loaded yet - // so prevent flowing away. - new_node_level = liquid_level; - new_node_content = liquid_kind; - } else { - // no surrounding sources, so get the maximum level that can flow into this node - for (u16 i = 0; i < num_flows; i++) { - max_node_level = get_max_liquid_level(flows[i], max_node_level); - } - - u8 viscosity = m_nodedef->get(liquid_kind).liquid_viscosity; - if (viscosity > 1 && max_node_level != liquid_level) { - // amount to gain, limited by viscosity - // must be at least 1 in absolute value - s8 level_inc = max_node_level - liquid_level; - if (level_inc < -viscosity || level_inc > viscosity) - new_node_level = liquid_level + level_inc/viscosity; - else if (level_inc < 0) - new_node_level = liquid_level - 1; - else if (level_inc > 0) - new_node_level = liquid_level + 1; - if (new_node_level != max_node_level) - must_reflow.push_back(p0); - } else { - new_node_level = max_node_level; - } - - if (max_node_level >= (LIQUID_LEVEL_MAX + 1 - range)) - new_node_content = liquid_kind; - else - new_node_content = floodable_node; - - } - - /* - check if anything has changed. if not, just continue with the next node. - */ - if (new_node_content == n0.getContent() && - (m_nodedef->get(n0.getContent()).liquid_type != LIQUID_FLOWING || - ((n0.param2 & LIQUID_LEVEL_MASK) == (u8)new_node_level && - ((n0.param2 & LIQUID_FLOW_DOWN_MASK) == LIQUID_FLOW_DOWN_MASK) - == flowing_down))) - continue; - - /* - check if there is a floating node above that needs to be updated. - */ - if (floating_node_above && new_node_content == CONTENT_AIR) - check_for_falling.push_back(p0); - - /* - update the current node - */ - MapNode n00 = n0; - //bool flow_down_enabled = (flowing_down && ((n0.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK)); - if (m_nodedef->get(new_node_content).liquid_type == LIQUID_FLOWING) { - // set level to last 3 bits, flowing down bit to 4th bit - n0.param2 = (flowing_down ? LIQUID_FLOW_DOWN_MASK : 0x00) | (new_node_level & LIQUID_LEVEL_MASK); - } else { - // set the liquid level and flow bits to 0 - n0.param2 &= ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK); - } - - // change the node. - n0.setContent(new_node_content); - - // on_flood() the node - if (floodable_node != CONTENT_AIR) { - if (env->getScriptIface()->node_on_flood(p0, n00, n0)) - continue; - } - - // Ignore light (because calling voxalgo::update_lighting_nodes) - ContentLightingFlags f0 = m_nodedef->getLightingFlags(n0); - n0.setLight(LIGHTBANK_DAY, 0, f0); - n0.setLight(LIGHTBANK_NIGHT, 0, f0); - - // Find out whether there is a suspect for this action - std::string suspect; - if (m_gamedef->rollback()) - suspect = m_gamedef->rollback()->getSuspect(p0, 83, 1); - - if (m_gamedef->rollback() && !suspect.empty()) { - // Blame suspect - RollbackScopeActor rollback_scope(m_gamedef->rollback(), suspect, true); - // Get old node for rollback - RollbackNode rollback_oldnode(this, p0, m_gamedef); - // Set node - setNode(p0, n0); - // Report - RollbackNode rollback_newnode(this, p0, m_gamedef); - RollbackAction action; - action.setSetNode(p0, rollback_oldnode, rollback_newnode); - m_gamedef->rollback()->reportAction(action); - } else { - // Set node - setNode(p0, n0); - } - - v3s16 blockpos = getNodeBlockPos(p0); - MapBlock *block = getBlockNoCreateNoEx(blockpos); - if (block != NULL) { - modified_blocks[blockpos] = block; - changed_nodes.emplace_back(p0, n00); - } - - /* - enqueue neighbors for update if necessary - */ - switch (m_nodedef->get(n0.getContent()).liquid_type) { - case LIQUID_SOURCE: - case LIQUID_FLOWING: - // make sure source flows into all neighboring nodes - for (u16 i = 0; i < num_flows; i++) - if (flows[i].t != NEIGHBOR_UPPER) - m_transforming_liquid.push_back(flows[i].p); - for (u16 i = 0; i < num_airs; i++) - if (airs[i].t != NEIGHBOR_UPPER) - m_transforming_liquid.push_back(airs[i].p); - break; - case LIQUID_NONE: - // this flow has turned to air; neighboring flows might need to do the same - for (u16 i = 0; i < num_flows; i++) - m_transforming_liquid.push_back(flows[i].p); - break; - case LiquidType_END: - break; - } - } - //infostream<<"Map::transformLiquids(): loopcount="<getScriptIface()->check_for_falling(p); - } - - env->getScriptIface()->on_liquid_transformed(changed_nodes); - - /* ---------------------------------------------------------------------- - * Manage the queue so that it does not grow indefinitely - */ - u16 time_until_purge = g_settings->getU16("liquid_queue_purge_time"); - - if (time_until_purge == 0) - return; // Feature disabled - - time_until_purge *= 1000; // seconds -> milliseconds - - u64 curr_time = porting::getTimeMs(); - u32 prev_unprocessed = m_unprocessed_count; - m_unprocessed_count = m_transforming_liquid.size(); - - // if unprocessed block count is decreasing or stable - if (m_unprocessed_count <= prev_unprocessed) { - m_queue_size_timer_started = false; - } else { - if (!m_queue_size_timer_started) - m_inc_trending_up_start_time = curr_time; - m_queue_size_timer_started = true; - } - - // Account for curr_time overflowing - if (m_queue_size_timer_started && m_inc_trending_up_start_time > curr_time) - m_queue_size_timer_started = false; - - /* If the queue has been growing for more than liquid_queue_purge_time seconds - * and the number of unprocessed blocks is still > liquid_loop_max then we - * cannot keep up; dump the oldest blocks from the queue so that the queue - * has liquid_loop_max items in it - */ - if (m_queue_size_timer_started - && curr_time - m_inc_trending_up_start_time > time_until_purge - && m_unprocessed_count > liquid_loop_max) { - - size_t dump_qty = m_unprocessed_count - liquid_loop_max; - - infostream << "transformLiquids(): DUMPING " << dump_qty - << " blocks from the queue" << std::endl; - - while (dump_qty--) - m_transforming_liquid.pop_front(); - - m_queue_size_timer_started = false; // optimistically assume we can keep up now - m_unprocessed_count = m_transforming_liquid.size(); - } -} - std::vector Map::findNodesWithMetadata(v3s16 p1, v3s16 p2) { std::vector positions_with_meta; @@ -1225,738 +760,6 @@ bool Map::isBlockOccluded(v3s16 pos_relative, v3s16 cam_pos_nodes, bool simple_c return true; } -/* - ServerMap -*/ -ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef, - EmergeManager *emerge, MetricsBackend *mb): - Map(gamedef), - settings_mgr(savedir + DIR_DELIM + "map_meta.txt"), - m_emerge(emerge) -{ - verbosestream<map_settings_mgr = &settings_mgr; - - /* - Try to load map; if not found, create a new one. - */ - - // Determine which database backend to use - std::string conf_path = savedir + DIR_DELIM + "world.mt"; - Settings conf; - bool succeeded = conf.readConfigFile(conf_path.c_str()); - if (!succeeded || !conf.exists("backend")) { - // fall back to sqlite3 - conf.set("backend", "sqlite3"); - } - std::string backend = conf.get("backend"); - dbase = createDatabase(backend, savedir, conf); - if (conf.exists("readonly_backend")) { - std::string readonly_dir = savedir + DIR_DELIM + "readonly"; - dbase_ro = createDatabase(conf.get("readonly_backend"), readonly_dir, conf); - } - if (!conf.updateConfigFile(conf_path.c_str())) - errorstream << "ServerMap::ServerMap(): Failed to update world.mt!" << std::endl; - - m_savedir = savedir; - m_map_saving_enabled = false; - - m_save_time_counter = mb->addCounter( - "minetest_map_save_time", "Time spent saving blocks (in microseconds)"); - m_save_count_counter = mb->addCounter( - "minetest_map_saved_blocks", "Number of blocks saved"); - m_loaded_blocks_gauge = mb->addGauge( - "minetest_map_loaded_blocks", "Number of loaded blocks"); - - m_map_compression_level = rangelim(g_settings->getS16("map_compression_level_disk"), -1, 9); - - try { - // If directory exists, check contents and load if possible - if (fs::PathExists(m_savedir)) { - // If directory is empty, it is safe to save into it. - if (fs::GetDirListing(m_savedir).empty()) { - infostream<<"ServerMap: Empty save directory is valid." - <seed; -} - -bool ServerMap::blockpos_over_mapgen_limit(v3s16 p) -{ - const s16 mapgen_limit_bp = rangelim( - getMapgenParams()->mapgen_limit, 0, MAX_MAP_GENERATION_LIMIT) / - MAP_BLOCKSIZE; - return p.X < -mapgen_limit_bp || - p.X > mapgen_limit_bp || - p.Y < -mapgen_limit_bp || - p.Y > mapgen_limit_bp || - p.Z < -mapgen_limit_bp || - p.Z > mapgen_limit_bp; -} - -bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) -{ - s16 csize = getMapgenParams()->chunksize; - v3s16 bpmin = EmergeManager::getContainingChunk(blockpos, csize); - v3s16 bpmax = bpmin + v3s16(1, 1, 1) * (csize - 1); - - if (!m_chunks_in_progress.insert(bpmin).second) - return false; - - bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; - EMERGE_DBG_OUT("initBlockMake(): " << bpmin << " - " << bpmax); - - v3s16 extra_borders(1, 1, 1); - v3s16 full_bpmin = bpmin - extra_borders; - v3s16 full_bpmax = bpmax + extra_borders; - - // Do nothing if not inside mapgen limits (+-1 because of neighbors) - if (blockpos_over_mapgen_limit(full_bpmin) || - blockpos_over_mapgen_limit(full_bpmax)) - return false; - - data->seed = getSeed(); - data->blockpos_min = bpmin; - data->blockpos_max = bpmax; - data->nodedef = m_nodedef; - - /* - Create the whole area of this and the neighboring blocks - */ - for (s16 x = full_bpmin.X; x <= full_bpmax.X; x++) - for (s16 z = full_bpmin.Z; z <= full_bpmax.Z; z++) { - v2s16 sectorpos(x, z); - // Sector metadata is loaded from disk if not already loaded. - MapSector *sector = createSector(sectorpos); - FATAL_ERROR_IF(sector == NULL, "createSector() failed"); - - for (s16 y = full_bpmin.Y; y <= full_bpmax.Y; y++) { - v3s16 p(x, y, z); - - MapBlock *block = emergeBlock(p, false); - if (block == NULL) { - block = createBlock(p); - - // Block gets sunlight if this is true. - // Refer to the map generator heuristics. - bool ug = m_emerge->isBlockUnderground(p); - block->setIsUnderground(ug); - } - } - } - - /* - Now we have a big empty area. - - Make a ManualMapVoxelManipulator that contains this and the - neighboring blocks - */ - - data->vmanip = new MMVManip(this); - data->vmanip->initialEmerge(full_bpmin, full_bpmax); - - // Data is ready now. - return true; -} - -void ServerMap::finishBlockMake(BlockMakeData *data, - std::map *changed_blocks) -{ - v3s16 bpmin = data->blockpos_min; - v3s16 bpmax = data->blockpos_max; - - bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; - EMERGE_DBG_OUT("finishBlockMake(): " << bpmin << " - " << bpmax); - - /* - Blit generated stuff to map - NOTE: blitBackAll adds nearly everything to changed_blocks - */ - data->vmanip->blitBackAll(changed_blocks); - - EMERGE_DBG_OUT("finishBlockMake: changed_blocks.size()=" - << changed_blocks->size()); - - /* - Copy transforming liquid information - */ - while (data->transforming_liquid.size()) { - m_transforming_liquid.push_back(data->transforming_liquid.front()); - data->transforming_liquid.pop_front(); - } - - for (auto &changed_block : *changed_blocks) { - MapBlock *block = changed_block.second; - if (!block) - continue; - /* - Update is air cache of the MapBlocks - */ - block->expireIsAirCache(); - /* - Set block as modified - */ - block->raiseModified(MOD_STATE_WRITE_NEEDED, - MOD_REASON_EXPIRE_IS_AIR); - } - - /* - Set central blocks as generated - */ - for (s16 x = bpmin.X; x <= bpmax.X; x++) - for (s16 z = bpmin.Z; z <= bpmax.Z; z++) - for (s16 y = bpmin.Y; y <= bpmax.Y; y++) { - MapBlock *block = getBlockNoCreateNoEx(v3s16(x, y, z)); - if (!block) - continue; - - block->setGenerated(true); - } - - /* - Save changed parts of map - NOTE: Will be saved later. - */ - //save(MOD_STATE_WRITE_AT_UNLOAD); - m_chunks_in_progress.erase(bpmin); -} - -MapSector *ServerMap::createSector(v2s16 p2d) -{ - /* - Check if it exists already in memory - */ - MapSector *sector = getSectorNoGenerate(p2d); - if (sector) - return sector; - - /* - Do not create over max mapgen limit - */ - if (blockpos_over_max_limit(v3s16(p2d.X, 0, p2d.Y))) - throw InvalidPositionException("createSector(): pos over max mapgen limit"); - - /* - Generate blank sector - */ - sector = new MapSector(this, p2d, m_gamedef); - - /* - Insert to container - */ - m_sectors[p2d] = sector; - - return sector; -} - -MapBlock * ServerMap::createBlock(v3s16 p) -{ - v2s16 p2d(p.X, p.Z); - s16 block_y = p.Y; - - /* - This will create or load a sector if not found in memory. - */ - MapSector *sector; - try { - sector = createSector(p2d); - } catch (InvalidPositionException &e) { - infostream<<"createBlock: createSector() failed"<getBlockNoCreateNoEx(block_y); - if (block) - return block; - - // Create blank - try { - block = sector->createBlankBlock(block_y); - } catch (InvalidPositionException &e) { - infostream << "createBlock: createBlankBlock() failed" << std::endl; - throw e; - } - - return block; -} - -MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank) -{ - { - MapBlock *block = getBlockNoCreateNoEx(p); - if (block) - return block; - } - - { - MapBlock *block = loadBlock(p); - if(block) - return block; - } - - if (create_blank) { - try { - MapSector *sector = createSector(v2s16(p.X, p.Z)); - return sector->createBlankBlock(p.Y); - } catch (InvalidPositionException &e) {} - } - - return NULL; -} - -MapBlock *ServerMap::getBlockOrEmerge(v3s16 p3d, bool generate) -{ - MapBlock *block = getBlockNoCreateNoEx(p3d); - if (block == NULL) - m_emerge->enqueueBlockEmerge(PEER_ID_INEXISTENT, p3d, generate); - - return block; -} - -bool ServerMap::isBlockInQueue(v3s16 pos) -{ - return m_emerge && m_emerge->isBlockInQueue(pos); -} - -void ServerMap::addNodeAndUpdate(v3s16 p, MapNode n, - std::map &modified_blocks, - bool remove_metadata) -{ - Map::addNodeAndUpdate(p, n, modified_blocks, remove_metadata); - - /* - Add neighboring liquid nodes and this node to transform queue. - (it's vital for the node itself to get updated last, if it was removed.) - */ - - for (const v3s16 &dir : g_7dirs) { - v3s16 p2 = p + dir; - - bool is_valid_position; - MapNode n2 = getNode(p2, &is_valid_position); - if(is_valid_position && - (m_nodedef->get(n2).isLiquid() || - n2.getContent() == CONTENT_AIR)) - m_transforming_liquid.push_back(p2); - } -} - -// N.B. This requires no synchronization, since data will not be modified unless -// the VoxelManipulator being updated belongs to the same thread. -void ServerMap::updateVManip(v3s16 pos) -{ - Mapgen *mg = m_emerge->getCurrentMapgen(); - if (!mg) - return; - - MMVManip *vm = mg->vm; - if (!vm) - return; - - if (!vm->m_area.contains(pos)) - return; - - s32 idx = vm->m_area.index(pos); - vm->m_data[idx] = getNode(pos); - vm->m_flags[idx] &= ~VOXELFLAG_NO_DATA; - - vm->m_is_dirty = true; -} - -void ServerMap::reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) -{ - m_loaded_blocks_gauge->set(all_blocks); - m_save_time_counter->increment(save_time_us); - m_save_count_counter->increment(saved_blocks); -} - -void ServerMap::save(ModifiedState save_level) -{ - if (!m_map_saving_enabled) { - warningstream<<"Not saving map, saving disabled."<getBlocks(blocks); - - for (MapBlock *block : blocks) { - block_count_all++; - - if(block->getModified() >= (u32)save_level) { - // Lazy beginSave() - if(!save_started) { - beginSave(); - save_started = true; - } - - modprofiler.add(block->getModifiedReasonString(), 1); - - saveBlock(block); - block_count++; - } - } - } - - if(save_started) - endSave(); - - /* - Only print if something happened or saved whole map - */ - if(save_level == MOD_STATE_CLEAN - || block_count != 0) { - infostream << "ServerMap: Written: " - << block_count << " blocks" - << ", " << block_count_all << " blocks in memory." - << std::endl; - PrintInfo(infostream); // ServerMap/ClientMap: - infostream<<"Blocks modified by: "< &dst) -{ - dbase->listAllLoadableBlocks(dst); - if (dbase_ro) - dbase_ro->listAllLoadableBlocks(dst); -} - -void ServerMap::listAllLoadedBlocks(std::vector &dst) -{ - for (auto §or_it : m_sectors) { - MapSector *sector = sector_it.second; - - MapBlockVect blocks; - sector->getBlocks(blocks); - - for (MapBlock *block : blocks) { - v3s16 p = block->getPos(); - dst.push_back(p); - } - } -} - -MapDatabase *ServerMap::createDatabase( - const std::string &name, - const std::string &savedir, - Settings &conf) -{ - if (name == "sqlite3") - return new MapDatabaseSQLite3(savedir); - if (name == "dummy") - return new Database_Dummy(); - #if USE_LEVELDB - if (name == "leveldb") - return new Database_LevelDB(savedir); - #endif - #if USE_REDIS - if (name == "redis") - return new Database_Redis(conf); - #endif - #if USE_POSTGRESQL - if (name == "postgresql") { - std::string connect_string; - conf.getNoEx("pgsql_connection", connect_string); - return new MapDatabasePostgreSQL(connect_string); - } - #endif - - throw BaseException(std::string("Database backend ") + name + " not supported."); -} - -void ServerMap::beginSave() -{ - dbase->beginSave(); -} - -void ServerMap::endSave() -{ - dbase->endSave(); -} - -bool ServerMap::saveBlock(MapBlock *block) -{ - return saveBlock(block, dbase, m_map_compression_level); -} - -bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db, int compression_level) -{ - v3s16 p3d = block->getPos(); - - // Format used for writing - u8 version = SER_FMT_VER_HIGHEST_WRITE; - - /* - [0] u8 serialization version - [1] data - */ - std::ostringstream o(std::ios_base::binary); - o.write((char*) &version, 1); - block->serialize(o, version, true, compression_level); - - // FIXME: zero copy possible in c++20 or with custom rdbuf - bool ret = db->saveBlock(p3d, o.str()); - if (ret) { - // We just wrote it to the disk so clear modified flag - block->resetModified(); - } - return ret; -} - -void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load) -{ - try { - std::istringstream is(*blob, std::ios_base::binary); - - u8 version = SER_FMT_VER_INVALID; - is.read((char*)&version, 1); - - if(is.fail()) - throw SerializationError("ServerMap::loadBlock(): Failed" - " to read MapBlock version"); - - MapBlock *block = nullptr; - std::unique_ptr block_created_new; - block = sector->getBlockNoCreateNoEx(p3d.Y); - if (!block) { - block_created_new = sector->createBlankBlockNoInsert(p3d.Y); - block = block_created_new.get(); - } - - { - ScopeProfiler sp(g_profiler, "ServerMap: deSer block", SPT_AVG); - // Read basic data - block->deSerialize(is, version, true); - } - - // If it's a new block, insert it to the map - if (block_created_new) { - sector->insertBlock(std::move(block_created_new)); - ReflowScan scanner(this, m_emerge->ndef); - scanner.scan(block, &m_transforming_liquid); - } - - /* - Save blocks loaded in old format in new format - */ - - //if(version < SER_FMT_VER_HIGHEST_READ || save_after_load) - // Only save if asked to; no need to update version - if(save_after_load) - saveBlock(block); - - // We just loaded it from, so it's up-to-date. - block->resetModified(); - } - catch(SerializationError &e) - { - errorstream<<"Invalid block data in database" - <<" ("<getBool("ignore_world_load_errors")){ - errorstream<<"Ignoring block load error. Duck and cover! " - <<"(ignore_world_load_errors)"<loadBlock(blockpos, &ret); - if (!ret.empty()) { - loadBlock(&ret, blockpos, createSector(p2d), false); - } else if (dbase_ro) { - dbase_ro->loadBlock(blockpos, &ret); - if (!ret.empty()) { - loadBlock(&ret, blockpos, createSector(p2d), false); - } - } else { - return NULL; - } - - MapBlock *block = getBlockNoCreateNoEx(blockpos); - if (created_new && (block != NULL)) { - std::map modified_blocks; - // Fix lighting if necessary - voxalgo::update_block_border_lighting(this, block, modified_blocks); - if (!modified_blocks.empty()) { - //Modified lighting, send event - MapEditEvent event; - event.type = MEET_OTHER; - event.setModifiedBlocks(modified_blocks); - dispatchEvent(event); - } - } - return block; -} - -bool ServerMap::deleteBlock(v3s16 blockpos) -{ - if (!dbase->deleteBlock(blockpos)) - return false; - - MapBlock *block = getBlockNoCreateNoEx(blockpos); - if (block) { - v2s16 p2d(blockpos.X, blockpos.Z); - MapSector *sector = getSectorNoGenerate(p2d); - if (!sector) - return false; - // It may not be safe to delete the block from memory at the moment - // (pointers to it could still be in use) - m_detached_blocks.push_back(sector->detachBlock(block)); - } - - return true; -} - -void ServerMap::deleteDetachedBlocks() -{ - for (const auto &block : m_detached_blocks) { - assert(block->isOrphan()); - (void)block; // silence unused-variable warning in release builds - } - - m_detached_blocks.clear(); -} - -void ServerMap::step() -{ - // Delete from memory blocks removed by deleteBlocks() only when pointers - // to them are (probably) no longer in use - deleteDetachedBlocks(); -} - -void ServerMap::PrintInfo(std::ostream &out) -{ - out<<"ServerMap: "; -} - -bool ServerMap::repairBlockLight(v3s16 blockpos, - std::map *modified_blocks) -{ - MapBlock *block = emergeBlock(blockpos, false); - if (!block || !block->isGenerated()) - return false; - voxalgo::repair_block_light(this, block, modified_blocks); - return true; -} - MMVManip::MMVManip(Map *map): VoxelManipulator(), m_map(map) diff --git a/src/map.h b/src/map.h index 482ff2859..44362bb5d 100644 --- a/src/map.h +++ b/src/map.h @@ -20,10 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include -#include #include #include -#include #include "irrlichttypes_bloated.h" #include "mapblock.h" @@ -31,32 +29,20 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "constants.h" #include "voxel.h" #include "modifiedstate.h" -#include "util/container.h" -#include "util/metricsbackend.h" #include "util/numeric.h" #include "nodetimer.h" -#include "map_settings_manager.h" #include "debug.h" -class Settings; -class MapDatabase; -class ClientMap; class MapSector; -class ServerMapSector; -class MapBlock; class NodeMetadata; class IGameDef; class IRollbackManager; -class EmergeManager; -class MetricsBackend; -class ServerEnvironment; -struct BlockMakeData; /* MapEditEvent */ -enum MapEditEventType{ +enum MapEditEventType { // Node added (changed from air or something else to something) MEET_ADDNODE, // Node removed (changed to air) @@ -335,165 +321,6 @@ protected: u32 needed_count); }; -/* - ServerMap - - This is the only map class that is able to generate map. -*/ - -class ServerMap : public Map -{ -public: - /* - savedir: directory to which map data should be saved - */ - ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge, MetricsBackend *mb); - ~ServerMap(); - - /* - Get a sector from somewhere. - - Check memory - - Check disk (doesn't load blocks) - - Create blank one - */ - MapSector *createSector(v2s16 p); - - /* - Blocks are generated by using these and makeBlock(). - */ - bool blockpos_over_mapgen_limit(v3s16 p); - bool initBlockMake(v3s16 blockpos, BlockMakeData *data); - void finishBlockMake(BlockMakeData *data, - std::map *changed_blocks); - - /* - Get a block from somewhere. - - Memory - - Create blank - */ - MapBlock *createBlock(v3s16 p); - - /* - Forcefully get a block from somewhere. - - Memory - - Load from disk - - Create blank filled with CONTENT_IGNORE - - */ - MapBlock *emergeBlock(v3s16 p, bool create_blank=true) override; - - /* - Try to get a block. - If it does not exist in memory, add it to the emerge queue. - - Memory - - Emerge Queue (deferred disk or generate) - */ - MapBlock *getBlockOrEmerge(v3s16 p3d, bool generate); - - bool isBlockInQueue(v3s16 pos); - - void addNodeAndUpdate(v3s16 p, MapNode n, - std::map &modified_blocks, - bool remove_metadata) override; - - /* - Database functions - */ - static MapDatabase *createDatabase(const std::string &name, const std::string &savedir, Settings &conf); - - // Call these before and after saving of blocks - void beginSave() override; - void endSave() override; - - void save(ModifiedState save_level) override; - void listAllLoadableBlocks(std::vector &dst); - void listAllLoadedBlocks(std::vector &dst); - - MapgenParams *getMapgenParams(); - - bool saveBlock(MapBlock *block) override; - static bool saveBlock(MapBlock *block, MapDatabase *db, int compression_level = -1); - MapBlock* loadBlock(v3s16 p); - // Database version - void loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load=false); - - // Blocks are removed from the map but not deleted from memory until - // deleteDetachedBlocks() is called, since pointers to them may still exist - // when deleteBlock() is called. - bool deleteBlock(v3s16 blockpos) override; - - void deleteDetachedBlocks(); - - void step(); - - void updateVManip(v3s16 pos); - - // For debug printing - void PrintInfo(std::ostream &out) override; - - bool isSavingEnabled(){ return m_map_saving_enabled; } - - u64 getSeed(); - - /*! - * Fixes lighting in one map block. - * May modify other blocks as well, as light can spread - * out of the specified block. - * Returns false if the block is not generated (so nothing - * changed), true otherwise. - */ - bool repairBlockLight(v3s16 blockpos, - std::map *modified_blocks); - - void transformLiquids(std::map & modified_blocks, - ServerEnvironment *env); - - void transforming_liquid_add(v3s16 p); - - MapSettingsManager settings_mgr; - -protected: - - void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override; - -private: - friend class ModApiMapgen; // for m_transforming_liquid - - // Emerge manager - EmergeManager *m_emerge; - - std::string m_savedir; - bool m_map_saving_enabled; - - int m_map_compression_level; - - std::set m_chunks_in_progress; - - // used by deleteBlock() and deleteDetachedBlocks() - std::vector> m_detached_blocks; - - // Queued transforming water nodes - UniqueQueue m_transforming_liquid; - f32 m_transforming_liquid_loop_count_multiplier = 1.0f; - u32 m_unprocessed_count = 0; - u64 m_inc_trending_up_start_time = 0; // milliseconds - bool m_queue_size_timer_started = false; - - /* - Metadata is re-written on disk only if this is true. - This is reset to false when written on disk. - */ - bool m_map_metadata_changed = true; - MapDatabase *dbase = nullptr; - MapDatabase *dbase_ro = nullptr; - - // Map metrics - MetricGaugePtr m_loaded_blocks_gauge; - MetricCounterPtr m_save_time_counter; - MetricCounterPtr m_save_count_counter; -}; - - #define VMANIP_BLOCK_DATA_INEXIST 1 #define VMANIP_BLOCK_CONTAINS_CIGNORE 2 diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index adff72950..ab12233c1 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "util/pointer.h" #include "util/numeric.h" -#include "map.h" +#include "servermap.h" #include "mapblock.h" #include "nodedef.h" #include "treegen.h" diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 10ecdd34c..90f2bed5b 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "chatmessage.h" #include "client/clientmedia.h" #include "log.h" -#include "map.h" +#include "servermap.h" #include "mapsector.h" #include "client/minimap.h" #include "modchannels.h" diff --git a/src/server.cpp b/src/server.cpp index e85bbafd8..9e07c8c85 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "network/serveropcodes.h" #include "server/ban.h" #include "environment.h" -#include "map.h" +#include "servermap.h" #include "threading/mutex_auto_lock.h" #include "constants.h" #include "voxel.h" diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 6f45f51c6..6b8e645a7 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "nodemetadata.h" #include "gamedef.h" -#include "map.h" #include "porting.h" #include "profiler.h" #include "raycast.h" diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 21accff7e..93244760d 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "activeobject.h" #include "environment.h" -#include "map.h" +#include "servermap.h" #include "settings.h" #include "server/activeobjectmgr.h" #include "util/numeric.h" diff --git a/src/servermap.cpp b/src/servermap.cpp new file mode 100644 index 000000000..0a2e54b4d --- /dev/null +++ b/src/servermap.cpp @@ -0,0 +1,1230 @@ +/* +Minetest +Copyright (C) 2010-2024 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "map.h" +#include "mapsector.h" +#include "filesys.h" +#include "voxel.h" +#include "voxelalgorithms.h" +#include "porting.h" +#include "serialization.h" +#include "settings.h" +#include "log.h" +#include "profiler.h" +#include "gamedef.h" +#include "util/directiontables.h" +#include "rollback_interface.h" +#include "reflowscan.h" +#include "emerge.h" +#include "mapgen/mapgen_v6.h" +#include "mapgen/mg_biome.h" +#include "config.h" +#include "server.h" +#include "database/database.h" +#include "database/database-dummy.h" +#include "database/database-sqlite3.h" +#include "script/scripting_server.h" +#include "irrlicht_changes/printing.h" +#if USE_LEVELDB +#include "database/database-leveldb.h" +#endif +#if USE_REDIS +#include "database/database-redis.h" +#endif +#if USE_POSTGRESQL +#include "database/database-postgresql.h" +#endif + +/* + ServerMap +*/ + +ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef, + EmergeManager *emerge, MetricsBackend *mb): + Map(gamedef), + settings_mgr(savedir + DIR_DELIM + "map_meta.txt"), + m_emerge(emerge) +{ + verbosestream<map_settings_mgr = &settings_mgr; + + /* + Try to load map; if not found, create a new one. + */ + + // Determine which database backend to use + std::string conf_path = savedir + DIR_DELIM + "world.mt"; + Settings conf; + bool succeeded = conf.readConfigFile(conf_path.c_str()); + if (!succeeded || !conf.exists("backend")) { + // fall back to sqlite3 + conf.set("backend", "sqlite3"); + } + std::string backend = conf.get("backend"); + dbase = createDatabase(backend, savedir, conf); + if (conf.exists("readonly_backend")) { + std::string readonly_dir = savedir + DIR_DELIM + "readonly"; + dbase_ro = createDatabase(conf.get("readonly_backend"), readonly_dir, conf); + } + if (!conf.updateConfigFile(conf_path.c_str())) + errorstream << "ServerMap::ServerMap(): Failed to update world.mt!" << std::endl; + + m_savedir = savedir; + m_map_saving_enabled = false; + + m_save_time_counter = mb->addCounter( + "minetest_map_save_time", "Time spent saving blocks (in microseconds)"); + m_save_count_counter = mb->addCounter( + "minetest_map_saved_blocks", "Number of blocks saved"); + m_loaded_blocks_gauge = mb->addGauge( + "minetest_map_loaded_blocks", "Number of loaded blocks"); + + m_map_compression_level = rangelim(g_settings->getS16("map_compression_level_disk"), -1, 9); + + try { + // If directory exists, check contents and load if possible + if (fs::PathExists(m_savedir)) { + // If directory is empty, it is safe to save into it. + if (fs::GetDirListing(m_savedir).empty()) { + infostream<<"ServerMap: Empty save directory is valid." + <seed; +} + +bool ServerMap::blockpos_over_mapgen_limit(v3s16 p) +{ + const s16 mapgen_limit_bp = rangelim( + getMapgenParams()->mapgen_limit, 0, MAX_MAP_GENERATION_LIMIT) / + MAP_BLOCKSIZE; + return p.X < -mapgen_limit_bp || + p.X > mapgen_limit_bp || + p.Y < -mapgen_limit_bp || + p.Y > mapgen_limit_bp || + p.Z < -mapgen_limit_bp || + p.Z > mapgen_limit_bp; +} + +bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) +{ + s16 csize = getMapgenParams()->chunksize; + v3s16 bpmin = EmergeManager::getContainingChunk(blockpos, csize); + v3s16 bpmax = bpmin + v3s16(1, 1, 1) * (csize - 1); + + if (!m_chunks_in_progress.insert(bpmin).second) + return false; + + bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; + EMERGE_DBG_OUT("initBlockMake(): " << bpmin << " - " << bpmax); + + v3s16 extra_borders(1, 1, 1); + v3s16 full_bpmin = bpmin - extra_borders; + v3s16 full_bpmax = bpmax + extra_borders; + + // Do nothing if not inside mapgen limits (+-1 because of neighbors) + if (blockpos_over_mapgen_limit(full_bpmin) || + blockpos_over_mapgen_limit(full_bpmax)) + return false; + + data->seed = getSeed(); + data->blockpos_min = bpmin; + data->blockpos_max = bpmax; + data->nodedef = m_nodedef; + + /* + Create the whole area of this and the neighboring blocks + */ + for (s16 x = full_bpmin.X; x <= full_bpmax.X; x++) + for (s16 z = full_bpmin.Z; z <= full_bpmax.Z; z++) { + v2s16 sectorpos(x, z); + // Sector metadata is loaded from disk if not already loaded. + MapSector *sector = createSector(sectorpos); + FATAL_ERROR_IF(sector == NULL, "createSector() failed"); + + for (s16 y = full_bpmin.Y; y <= full_bpmax.Y; y++) { + v3s16 p(x, y, z); + + MapBlock *block = emergeBlock(p, false); + if (block == NULL) { + block = createBlock(p); + + // Block gets sunlight if this is true. + // Refer to the map generator heuristics. + bool ug = m_emerge->isBlockUnderground(p); + block->setIsUnderground(ug); + } + } + } + + /* + Now we have a big empty area. + + Make a ManualMapVoxelManipulator that contains this and the + neighboring blocks + */ + + data->vmanip = new MMVManip(this); + data->vmanip->initialEmerge(full_bpmin, full_bpmax); + + // Data is ready now. + return true; +} + +void ServerMap::finishBlockMake(BlockMakeData *data, + std::map *changed_blocks) +{ + v3s16 bpmin = data->blockpos_min; + v3s16 bpmax = data->blockpos_max; + + bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; + EMERGE_DBG_OUT("finishBlockMake(): " << bpmin << " - " << bpmax); + + /* + Blit generated stuff to map + NOTE: blitBackAll adds nearly everything to changed_blocks + */ + data->vmanip->blitBackAll(changed_blocks); + + EMERGE_DBG_OUT("finishBlockMake: changed_blocks.size()=" + << changed_blocks->size()); + + /* + Copy transforming liquid information + */ + while (data->transforming_liquid.size()) { + m_transforming_liquid.push_back(data->transforming_liquid.front()); + data->transforming_liquid.pop_front(); + } + + for (auto &changed_block : *changed_blocks) { + MapBlock *block = changed_block.second; + if (!block) + continue; + /* + Update is air cache of the MapBlocks + */ + block->expireIsAirCache(); + /* + Set block as modified + */ + block->raiseModified(MOD_STATE_WRITE_NEEDED, + MOD_REASON_EXPIRE_IS_AIR); + } + + /* + Set central blocks as generated + */ + for (s16 x = bpmin.X; x <= bpmax.X; x++) + for (s16 z = bpmin.Z; z <= bpmax.Z; z++) + for (s16 y = bpmin.Y; y <= bpmax.Y; y++) { + MapBlock *block = getBlockNoCreateNoEx(v3s16(x, y, z)); + if (!block) + continue; + + block->setGenerated(true); + } + + /* + Save changed parts of map + NOTE: Will be saved later. + */ + //save(MOD_STATE_WRITE_AT_UNLOAD); + m_chunks_in_progress.erase(bpmin); +} + +MapSector *ServerMap::createSector(v2s16 p2d) +{ + /* + Check if it exists already in memory + */ + MapSector *sector = getSectorNoGenerate(p2d); + if (sector) + return sector; + + /* + Do not create over max mapgen limit + */ + if (blockpos_over_max_limit(v3s16(p2d.X, 0, p2d.Y))) + throw InvalidPositionException("createSector(): pos over max mapgen limit"); + + /* + Generate blank sector + */ + sector = new MapSector(this, p2d, m_gamedef); + + /* + Insert to container + */ + m_sectors[p2d] = sector; + + return sector; +} + +MapBlock * ServerMap::createBlock(v3s16 p) +{ + v2s16 p2d(p.X, p.Z); + s16 block_y = p.Y; + + /* + This will create or load a sector if not found in memory. + */ + MapSector *sector; + try { + sector = createSector(p2d); + } catch (InvalidPositionException &e) { + infostream<<"createBlock: createSector() failed"<getBlockNoCreateNoEx(block_y); + if (block) + return block; + + // Create blank + try { + block = sector->createBlankBlock(block_y); + } catch (InvalidPositionException &e) { + infostream << "createBlock: createBlankBlock() failed" << std::endl; + throw e; + } + + return block; +} + +MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank) +{ + { + MapBlock *block = getBlockNoCreateNoEx(p); + if (block) + return block; + } + + { + MapBlock *block = loadBlock(p); + if(block) + return block; + } + + if (create_blank) { + try { + MapSector *sector = createSector(v2s16(p.X, p.Z)); + return sector->createBlankBlock(p.Y); + } catch (InvalidPositionException &e) {} + } + + return NULL; +} + +MapBlock *ServerMap::getBlockOrEmerge(v3s16 p3d, bool generate) +{ + MapBlock *block = getBlockNoCreateNoEx(p3d); + if (block == NULL) + m_emerge->enqueueBlockEmerge(PEER_ID_INEXISTENT, p3d, generate); + + return block; +} + +bool ServerMap::isBlockInQueue(v3s16 pos) +{ + return m_emerge && m_emerge->isBlockInQueue(pos); +} + +void ServerMap::addNodeAndUpdate(v3s16 p, MapNode n, + std::map &modified_blocks, + bool remove_metadata) +{ + Map::addNodeAndUpdate(p, n, modified_blocks, remove_metadata); + + /* + Add neighboring liquid nodes and this node to transform queue. + (it's vital for the node itself to get updated last, if it was removed.) + */ + + for (const v3s16 &dir : g_7dirs) { + v3s16 p2 = p + dir; + + bool is_valid_position; + MapNode n2 = getNode(p2, &is_valid_position); + if(is_valid_position && + (m_nodedef->get(n2).isLiquid() || + n2.getContent() == CONTENT_AIR)) + m_transforming_liquid.push_back(p2); + } +} + +// N.B. This requires no synchronization, since data will not be modified unless +// the VoxelManipulator being updated belongs to the same thread. +void ServerMap::updateVManip(v3s16 pos) +{ + Mapgen *mg = m_emerge->getCurrentMapgen(); + if (!mg) + return; + + MMVManip *vm = mg->vm; + if (!vm) + return; + + if (!vm->m_area.contains(pos)) + return; + + s32 idx = vm->m_area.index(pos); + vm->m_data[idx] = getNode(pos); + vm->m_flags[idx] &= ~VOXELFLAG_NO_DATA; + + vm->m_is_dirty = true; +} + +void ServerMap::reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) +{ + m_loaded_blocks_gauge->set(all_blocks); + m_save_time_counter->increment(save_time_us); + m_save_count_counter->increment(saved_blocks); +} + +void ServerMap::save(ModifiedState save_level) +{ + if (!m_map_saving_enabled) { + warningstream<<"Not saving map, saving disabled."<getBlocks(blocks); + + for (MapBlock *block : blocks) { + block_count_all++; + + if(block->getModified() >= (u32)save_level) { + // Lazy beginSave() + if(!save_started) { + beginSave(); + save_started = true; + } + + modprofiler.add(block->getModifiedReasonString(), 1); + + saveBlock(block); + block_count++; + } + } + } + + if(save_started) + endSave(); + + /* + Only print if something happened or saved whole map + */ + if(save_level == MOD_STATE_CLEAN + || block_count != 0) { + infostream << "ServerMap: Written: " + << block_count << " blocks" + << ", " << block_count_all << " blocks in memory." + << std::endl; + PrintInfo(infostream); // ServerMap/ClientMap: + infostream<<"Blocks modified by: "< &dst) +{ + dbase->listAllLoadableBlocks(dst); + if (dbase_ro) + dbase_ro->listAllLoadableBlocks(dst); +} + +void ServerMap::listAllLoadedBlocks(std::vector &dst) +{ + for (auto §or_it : m_sectors) { + MapSector *sector = sector_it.second; + + MapBlockVect blocks; + sector->getBlocks(blocks); + + for (MapBlock *block : blocks) { + v3s16 p = block->getPos(); + dst.push_back(p); + } + } +} + +MapDatabase *ServerMap::createDatabase( + const std::string &name, + const std::string &savedir, + Settings &conf) +{ + if (name == "sqlite3") + return new MapDatabaseSQLite3(savedir); + if (name == "dummy") + return new Database_Dummy(); + #if USE_LEVELDB + if (name == "leveldb") + return new Database_LevelDB(savedir); + #endif + #if USE_REDIS + if (name == "redis") + return new Database_Redis(conf); + #endif + #if USE_POSTGRESQL + if (name == "postgresql") { + std::string connect_string; + conf.getNoEx("pgsql_connection", connect_string); + return new MapDatabasePostgreSQL(connect_string); + } + #endif + + throw BaseException(std::string("Database backend ") + name + " not supported."); +} + +void ServerMap::beginSave() +{ + dbase->beginSave(); +} + +void ServerMap::endSave() +{ + dbase->endSave(); +} + +bool ServerMap::saveBlock(MapBlock *block) +{ + return saveBlock(block, dbase, m_map_compression_level); +} + +bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db, int compression_level) +{ + v3s16 p3d = block->getPos(); + + // Format used for writing + u8 version = SER_FMT_VER_HIGHEST_WRITE; + + /* + [0] u8 serialization version + [1] data + */ + std::ostringstream o(std::ios_base::binary); + o.write((char*) &version, 1); + block->serialize(o, version, true, compression_level); + + // FIXME: zero copy possible in c++20 or with custom rdbuf + bool ret = db->saveBlock(p3d, o.str()); + if (ret) { + // We just wrote it to the disk so clear modified flag + block->resetModified(); + } + return ret; +} + +void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load) +{ + try { + std::istringstream is(*blob, std::ios_base::binary); + + u8 version = SER_FMT_VER_INVALID; + is.read((char*)&version, 1); + + if(is.fail()) + throw SerializationError("ServerMap::loadBlock(): Failed" + " to read MapBlock version"); + + MapBlock *block = nullptr; + std::unique_ptr block_created_new; + block = sector->getBlockNoCreateNoEx(p3d.Y); + if (!block) { + block_created_new = sector->createBlankBlockNoInsert(p3d.Y); + block = block_created_new.get(); + } + + { + ScopeProfiler sp(g_profiler, "ServerMap: deSer block", SPT_AVG); + // Read basic data + block->deSerialize(is, version, true); + } + + // If it's a new block, insert it to the map + if (block_created_new) { + sector->insertBlock(std::move(block_created_new)); + ReflowScan scanner(this, m_emerge->ndef); + scanner.scan(block, &m_transforming_liquid); + } + + /* + Save blocks loaded in old format in new format + */ + + //if(version < SER_FMT_VER_HIGHEST_READ || save_after_load) + // Only save if asked to; no need to update version + if(save_after_load) + saveBlock(block); + + // We just loaded it from, so it's up-to-date. + block->resetModified(); + } + catch(SerializationError &e) + { + errorstream<<"Invalid block data in database" + <<" ("<getBool("ignore_world_load_errors")){ + errorstream<<"Ignoring block load error. Duck and cover! " + <<"(ignore_world_load_errors)"<loadBlock(blockpos, &ret); + if (!ret.empty()) { + loadBlock(&ret, blockpos, createSector(p2d), false); + } else if (dbase_ro) { + dbase_ro->loadBlock(blockpos, &ret); + if (!ret.empty()) { + loadBlock(&ret, blockpos, createSector(p2d), false); + } + } else { + return NULL; + } + + MapBlock *block = getBlockNoCreateNoEx(blockpos); + if (created_new && (block != NULL)) { + std::map modified_blocks; + // Fix lighting if necessary + voxalgo::update_block_border_lighting(this, block, modified_blocks); + if (!modified_blocks.empty()) { + //Modified lighting, send event + MapEditEvent event; + event.type = MEET_OTHER; + event.setModifiedBlocks(modified_blocks); + dispatchEvent(event); + } + } + return block; +} + +bool ServerMap::deleteBlock(v3s16 blockpos) +{ + if (!dbase->deleteBlock(blockpos)) + return false; + + MapBlock *block = getBlockNoCreateNoEx(blockpos); + if (block) { + v2s16 p2d(blockpos.X, blockpos.Z); + MapSector *sector = getSectorNoGenerate(p2d); + if (!sector) + return false; + // It may not be safe to delete the block from memory at the moment + // (pointers to it could still be in use) + m_detached_blocks.push_back(sector->detachBlock(block)); + } + + return true; +} + +void ServerMap::deleteDetachedBlocks() +{ + for (const auto &block : m_detached_blocks) { + assert(block->isOrphan()); + (void)block; // silence unused-variable warning in release builds + } + + m_detached_blocks.clear(); +} + +void ServerMap::step() +{ + // Delete from memory blocks removed by deleteBlocks() only when pointers + // to them are (probably) no longer in use + deleteDetachedBlocks(); +} + +void ServerMap::PrintInfo(std::ostream &out) +{ + out<<"ServerMap: "; +} + +bool ServerMap::repairBlockLight(v3s16 blockpos, + std::map *modified_blocks) +{ + MapBlock *block = emergeBlock(blockpos, false); + if (!block || !block->isGenerated()) + return false; + voxalgo::repair_block_light(this, block, modified_blocks); + return true; +} + +/* + Liquids +*/ + +#define WATER_DROP_BOOST 4 + +const static v3s16 liquid_6dirs[6] = { + // order: upper before same level before lower + v3s16( 0, 1, 0), + v3s16( 0, 0, 1), + v3s16( 1, 0, 0), + v3s16( 0, 0,-1), + v3s16(-1, 0, 0), + v3s16( 0,-1, 0) +}; + +enum NeighborType : u8 { + NEIGHBOR_UPPER, + NEIGHBOR_SAME_LEVEL, + NEIGHBOR_LOWER +}; + +struct NodeNeighbor { + MapNode n; + NeighborType t; + v3s16 p; + + NodeNeighbor() + : n(CONTENT_AIR), t(NEIGHBOR_SAME_LEVEL) + { } + + NodeNeighbor(const MapNode &node, NeighborType n_type, const v3s16 &pos) + : n(node), + t(n_type), + p(pos) + { } +}; + +static s8 get_max_liquid_level(NodeNeighbor nb, s8 current_max_node_level) +{ + s8 max_node_level = current_max_node_level; + u8 nb_liquid_level = (nb.n.param2 & LIQUID_LEVEL_MASK); + switch (nb.t) { + case NEIGHBOR_UPPER: + if (nb_liquid_level + WATER_DROP_BOOST > current_max_node_level) { + max_node_level = LIQUID_LEVEL_MAX; + if (nb_liquid_level + WATER_DROP_BOOST < LIQUID_LEVEL_MAX) + max_node_level = nb_liquid_level + WATER_DROP_BOOST; + } else if (nb_liquid_level > current_max_node_level) { + max_node_level = nb_liquid_level; + } + break; + case NEIGHBOR_LOWER: + break; + case NEIGHBOR_SAME_LEVEL: + if ((nb.n.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK && + nb_liquid_level > 0 && nb_liquid_level - 1 > max_node_level) + max_node_level = nb_liquid_level - 1; + break; + } + return max_node_level; +} + +void ServerMap::transforming_liquid_add(v3s16 p) +{ + m_transforming_liquid.push_back(p); +} + +void ServerMap::transformLiquids(std::map &modified_blocks, + ServerEnvironment *env) +{ + u32 loopcount = 0; + u32 initial_size = m_transforming_liquid.size(); + + /*if(initial_size != 0) + infostream<<"transformLiquids(): initial_size="< must_reflow; + + std::vector > changed_nodes; + + std::vector check_for_falling; + + u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); + u32 loop_max = liquid_loop_max; + + while (m_transforming_liquid.size() != 0) + { + // This should be done here so that it is done when continue is used + if (loopcount >= initial_size || loopcount >= loop_max) + break; + loopcount++; + + /* + Get a queued transforming liquid node + */ + v3s16 p0 = m_transforming_liquid.front(); + m_transforming_liquid.pop_front(); + + MapNode n0 = getNode(p0); + + /* + Collect information about current node + */ + s8 liquid_level = -1; + // The liquid node which will be placed there if + // the liquid flows into this node. + content_t liquid_kind = CONTENT_IGNORE; + // The node which will be placed there if liquid + // can't flow into this node. + content_t floodable_node = CONTENT_AIR; + const ContentFeatures &cf = m_nodedef->get(n0); + LiquidType liquid_type = cf.liquid_type; + switch (liquid_type) { + case LIQUID_SOURCE: + liquid_level = LIQUID_LEVEL_SOURCE; + liquid_kind = cf.liquid_alternative_flowing_id; + break; + case LIQUID_FLOWING: + liquid_level = (n0.param2 & LIQUID_LEVEL_MASK); + liquid_kind = n0.getContent(); + break; + case LIQUID_NONE: + // if this node is 'floodable', it *could* be transformed + // into a liquid, otherwise, continue with the next node. + if (!cf.floodable) + continue; + floodable_node = n0.getContent(); + liquid_kind = CONTENT_AIR; + break; + case LiquidType_END: + break; + } + + /* + Collect information about the environment + */ + NodeNeighbor sources[6]; // surrounding sources + int num_sources = 0; + NodeNeighbor flows[6]; // surrounding flowing liquid nodes + int num_flows = 0; + NodeNeighbor airs[6]; // surrounding air + int num_airs = 0; + NodeNeighbor neutrals[6]; // nodes that are solid or another kind of liquid + int num_neutrals = 0; + bool flowing_down = false; + bool ignored_sources = false; + bool floating_node_above = false; + for (u16 i = 0; i < 6; i++) { + NeighborType nt = NEIGHBOR_SAME_LEVEL; + switch (i) { + case 0: + nt = NEIGHBOR_UPPER; + break; + case 5: + nt = NEIGHBOR_LOWER; + break; + default: + break; + } + v3s16 npos = p0 + liquid_6dirs[i]; + NodeNeighbor nb(getNode(npos), nt, npos); + const ContentFeatures &cfnb = m_nodedef->get(nb.n); + if (nt == NEIGHBOR_UPPER && cfnb.floats) + floating_node_above = true; + switch (cfnb.liquid_type) { + case LIQUID_NONE: + if (cfnb.floodable) { + airs[num_airs++] = nb; + // if the current node is a water source the neighbor + // should be enqueded for transformation regardless of whether the + // current node changes or not. + if (nb.t != NEIGHBOR_UPPER && liquid_type != LIQUID_NONE) + m_transforming_liquid.push_back(npos); + // if the current node happens to be a flowing node, it will start to flow down here. + if (nb.t == NEIGHBOR_LOWER) + flowing_down = true; + } else { + neutrals[num_neutrals++] = nb; + if (nb.n.getContent() == CONTENT_IGNORE) { + // If node below is ignore prevent water from + // spreading outwards and otherwise prevent from + // flowing away as ignore node might be the source + if (nb.t == NEIGHBOR_LOWER) + flowing_down = true; + else + ignored_sources = true; + } + } + break; + case LIQUID_SOURCE: + // if this node is not (yet) of a liquid type, choose the first liquid type we encounter + if (liquid_kind == CONTENT_AIR) + liquid_kind = cfnb.liquid_alternative_flowing_id; + if (cfnb.liquid_alternative_flowing_id != liquid_kind) { + neutrals[num_neutrals++] = nb; + } else { + // Do not count bottom source, it will screw things up + if(nt != NEIGHBOR_LOWER) + sources[num_sources++] = nb; + } + break; + case LIQUID_FLOWING: + if (nb.t != NEIGHBOR_SAME_LEVEL || + (nb.n.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK) { + // if this node is not (yet) of a liquid type, choose the first liquid type we encounter + // but exclude falling liquids on the same level, they cannot flow here anyway + + // used to determine if the neighbor can even flow into this node + s8 max_level_from_neighbor = get_max_liquid_level(nb, -1); + u8 range = m_nodedef->get(cfnb.liquid_alternative_flowing_id).liquid_range; + + if (liquid_kind == CONTENT_AIR && + max_level_from_neighbor >= (LIQUID_LEVEL_MAX + 1 - range)) + liquid_kind = cfnb.liquid_alternative_flowing_id; + } + if (cfnb.liquid_alternative_flowing_id != liquid_kind) { + neutrals[num_neutrals++] = nb; + } else { + flows[num_flows++] = nb; + if (nb.t == NEIGHBOR_LOWER) + flowing_down = true; + } + break; + case LiquidType_END: + break; + } + } + + /* + decide on the type (and possibly level) of the current node + */ + content_t new_node_content; + s8 new_node_level = -1; + s8 max_node_level = -1; + + u8 range = m_nodedef->get(liquid_kind).liquid_range; + if (range > LIQUID_LEVEL_MAX + 1) + range = LIQUID_LEVEL_MAX + 1; + + if ((num_sources >= 2 && m_nodedef->get(liquid_kind).liquid_renewable) || liquid_type == LIQUID_SOURCE) { + // liquid_kind will be set to either the flowing alternative of the node (if it's a liquid) + // or the flowing alternative of the first of the surrounding sources (if it's air), so + // it's perfectly safe to use liquid_kind here to determine the new node content. + new_node_content = m_nodedef->get(liquid_kind).liquid_alternative_source_id; + } else if (num_sources >= 1 && sources[0].t != NEIGHBOR_LOWER) { + // liquid_kind is set properly, see above + max_node_level = new_node_level = LIQUID_LEVEL_MAX; + if (new_node_level >= (LIQUID_LEVEL_MAX + 1 - range)) + new_node_content = liquid_kind; + else + new_node_content = floodable_node; + } else if (ignored_sources && liquid_level >= 0) { + // Maybe there are neighboring sources that aren't loaded yet + // so prevent flowing away. + new_node_level = liquid_level; + new_node_content = liquid_kind; + } else { + // no surrounding sources, so get the maximum level that can flow into this node + for (u16 i = 0; i < num_flows; i++) { + max_node_level = get_max_liquid_level(flows[i], max_node_level); + } + + u8 viscosity = m_nodedef->get(liquid_kind).liquid_viscosity; + if (viscosity > 1 && max_node_level != liquid_level) { + // amount to gain, limited by viscosity + // must be at least 1 in absolute value + s8 level_inc = max_node_level - liquid_level; + if (level_inc < -viscosity || level_inc > viscosity) + new_node_level = liquid_level + level_inc/viscosity; + else if (level_inc < 0) + new_node_level = liquid_level - 1; + else if (level_inc > 0) + new_node_level = liquid_level + 1; + if (new_node_level != max_node_level) + must_reflow.push_back(p0); + } else { + new_node_level = max_node_level; + } + + if (max_node_level >= (LIQUID_LEVEL_MAX + 1 - range)) + new_node_content = liquid_kind; + else + new_node_content = floodable_node; + + } + + /* + check if anything has changed. if not, just continue with the next node. + */ + if (new_node_content == n0.getContent() && + (m_nodedef->get(n0.getContent()).liquid_type != LIQUID_FLOWING || + ((n0.param2 & LIQUID_LEVEL_MASK) == (u8)new_node_level && + ((n0.param2 & LIQUID_FLOW_DOWN_MASK) == LIQUID_FLOW_DOWN_MASK) + == flowing_down))) + continue; + + /* + check if there is a floating node above that needs to be updated. + */ + if (floating_node_above && new_node_content == CONTENT_AIR) + check_for_falling.push_back(p0); + + /* + update the current node + */ + MapNode n00 = n0; + //bool flow_down_enabled = (flowing_down && ((n0.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK)); + if (m_nodedef->get(new_node_content).liquid_type == LIQUID_FLOWING) { + // set level to last 3 bits, flowing down bit to 4th bit + n0.param2 = (flowing_down ? LIQUID_FLOW_DOWN_MASK : 0x00) | (new_node_level & LIQUID_LEVEL_MASK); + } else { + // set the liquid level and flow bits to 0 + n0.param2 &= ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK); + } + + // change the node. + n0.setContent(new_node_content); + + // on_flood() the node + if (floodable_node != CONTENT_AIR) { + if (env->getScriptIface()->node_on_flood(p0, n00, n0)) + continue; + } + + // Ignore light (because calling voxalgo::update_lighting_nodes) + ContentLightingFlags f0 = m_nodedef->getLightingFlags(n0); + n0.setLight(LIGHTBANK_DAY, 0, f0); + n0.setLight(LIGHTBANK_NIGHT, 0, f0); + + // Find out whether there is a suspect for this action + std::string suspect; + if (m_gamedef->rollback()) + suspect = m_gamedef->rollback()->getSuspect(p0, 83, 1); + + if (m_gamedef->rollback() && !suspect.empty()) { + // Blame suspect + RollbackScopeActor rollback_scope(m_gamedef->rollback(), suspect, true); + // Get old node for rollback + RollbackNode rollback_oldnode(this, p0, m_gamedef); + // Set node + setNode(p0, n0); + // Report + RollbackNode rollback_newnode(this, p0, m_gamedef); + RollbackAction action; + action.setSetNode(p0, rollback_oldnode, rollback_newnode); + m_gamedef->rollback()->reportAction(action); + } else { + // Set node + setNode(p0, n0); + } + + v3s16 blockpos = getNodeBlockPos(p0); + MapBlock *block = getBlockNoCreateNoEx(blockpos); + if (block != NULL) { + modified_blocks[blockpos] = block; + changed_nodes.emplace_back(p0, n00); + } + + /* + enqueue neighbors for update if necessary + */ + switch (m_nodedef->get(n0.getContent()).liquid_type) { + case LIQUID_SOURCE: + case LIQUID_FLOWING: + // make sure source flows into all neighboring nodes + for (u16 i = 0; i < num_flows; i++) + if (flows[i].t != NEIGHBOR_UPPER) + m_transforming_liquid.push_back(flows[i].p); + for (u16 i = 0; i < num_airs; i++) + if (airs[i].t != NEIGHBOR_UPPER) + m_transforming_liquid.push_back(airs[i].p); + break; + case LIQUID_NONE: + // this flow has turned to air; neighboring flows might need to do the same + for (u16 i = 0; i < num_flows; i++) + m_transforming_liquid.push_back(flows[i].p); + break; + case LiquidType_END: + break; + } + } + //infostream<<"Map::transformLiquids(): loopcount="<getScriptIface()->check_for_falling(p); + } + + env->getScriptIface()->on_liquid_transformed(changed_nodes); + + /* ---------------------------------------------------------------------- + * Manage the queue so that it does not grow indefinitely + */ + u16 time_until_purge = g_settings->getU16("liquid_queue_purge_time"); + + if (time_until_purge == 0) + return; // Feature disabled + + time_until_purge *= 1000; // seconds -> milliseconds + + u64 curr_time = porting::getTimeMs(); + u32 prev_unprocessed = m_unprocessed_count; + m_unprocessed_count = m_transforming_liquid.size(); + + // if unprocessed block count is decreasing or stable + if (m_unprocessed_count <= prev_unprocessed) { + m_queue_size_timer_started = false; + } else { + if (!m_queue_size_timer_started) + m_inc_trending_up_start_time = curr_time; + m_queue_size_timer_started = true; + } + + // Account for curr_time overflowing + if (m_queue_size_timer_started && m_inc_trending_up_start_time > curr_time) + m_queue_size_timer_started = false; + + /* If the queue has been growing for more than liquid_queue_purge_time seconds + * and the number of unprocessed blocks is still > liquid_loop_max then we + * cannot keep up; dump the oldest blocks from the queue so that the queue + * has liquid_loop_max items in it + */ + if (m_queue_size_timer_started + && curr_time - m_inc_trending_up_start_time > time_until_purge + && m_unprocessed_count > liquid_loop_max) { + + size_t dump_qty = m_unprocessed_count - liquid_loop_max; + + infostream << "transformLiquids(): DUMPING " << dump_qty + << " blocks from the queue" << std::endl; + + while (dump_qty--) + m_transforming_liquid.pop_front(); + + m_queue_size_timer_started = false; // optimistically assume we can keep up now + m_unprocessed_count = m_transforming_liquid.size(); + } +} diff --git a/src/servermap.h b/src/servermap.h new file mode 100644 index 000000000..7a8a84b9b --- /dev/null +++ b/src/servermap.h @@ -0,0 +1,195 @@ +/* +Minetest +Copyright (C) 2010-2024 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include +#include + +#include "map.h" +#include "util/container.h" +#include "util/metricsbackend.h" +#include "map_settings_manager.h" + +class Settings; +class MapDatabase; +class IRollbackManager; +class EmergeManager; +class ServerEnvironment; +struct BlockMakeData; + +class MetricsBackend; + +/* + ServerMap + + This is the only map class that is able to generate map. +*/ + +class ServerMap : public Map +{ +public: + /* + savedir: directory to which map data should be saved + */ + ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge, MetricsBackend *mb); + ~ServerMap(); + + /* + Get a sector from somewhere. + - Check memory + - Check disk (doesn't load blocks) + - Create blank one + */ + MapSector *createSector(v2s16 p); + + /* + Blocks are generated by using these and makeBlock(). + */ + bool blockpos_over_mapgen_limit(v3s16 p); + bool initBlockMake(v3s16 blockpos, BlockMakeData *data); + void finishBlockMake(BlockMakeData *data, + std::map *changed_blocks); + + /* + Get a block from somewhere. + - Memory + - Create blank + */ + MapBlock *createBlock(v3s16 p); + + /* + Forcefully get a block from somewhere. + - Memory + - Load from disk + - Create blank filled with CONTENT_IGNORE + + */ + MapBlock *emergeBlock(v3s16 p, bool create_blank=true) override; + + /* + Try to get a block. + If it does not exist in memory, add it to the emerge queue. + - Memory + - Emerge Queue (deferred disk or generate) + */ + MapBlock *getBlockOrEmerge(v3s16 p3d, bool generate); + + bool isBlockInQueue(v3s16 pos); + + void addNodeAndUpdate(v3s16 p, MapNode n, + std::map &modified_blocks, + bool remove_metadata) override; + + /* + Database functions + */ + static MapDatabase *createDatabase(const std::string &name, const std::string &savedir, Settings &conf); + + // Call these before and after saving of blocks + void beginSave() override; + void endSave() override; + + void save(ModifiedState save_level) override; + void listAllLoadableBlocks(std::vector &dst); + void listAllLoadedBlocks(std::vector &dst); + + MapgenParams *getMapgenParams(); + + bool saveBlock(MapBlock *block) override; + static bool saveBlock(MapBlock *block, MapDatabase *db, int compression_level = -1); + MapBlock* loadBlock(v3s16 p); + // Database version + void loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load=false); + + // Blocks are removed from the map but not deleted from memory until + // deleteDetachedBlocks() is called, since pointers to them may still exist + // when deleteBlock() is called. + bool deleteBlock(v3s16 blockpos) override; + + void deleteDetachedBlocks(); + + void step(); + + void updateVManip(v3s16 pos); + + // For debug printing + void PrintInfo(std::ostream &out) override; + + bool isSavingEnabled(){ return m_map_saving_enabled; } + + u64 getSeed(); + + /*! + * Fixes lighting in one map block. + * May modify other blocks as well, as light can spread + * out of the specified block. + * Returns false if the block is not generated (so nothing + * changed), true otherwise. + */ + bool repairBlockLight(v3s16 blockpos, + std::map *modified_blocks); + + void transformLiquids(std::map & modified_blocks, + ServerEnvironment *env); + + void transforming_liquid_add(v3s16 p); + + MapSettingsManager settings_mgr; + +protected: + + void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override; + +private: + friend class ModApiMapgen; // for m_transforming_liquid + + // Emerge manager + EmergeManager *m_emerge; + + std::string m_savedir; + bool m_map_saving_enabled; + + int m_map_compression_level; + + std::set m_chunks_in_progress; + + // used by deleteBlock() and deleteDetachedBlocks() + std::vector> m_detached_blocks; + + // Queued transforming water nodes + UniqueQueue m_transforming_liquid; + f32 m_transforming_liquid_loop_count_multiplier = 1.0f; + u32 m_unprocessed_count = 0; + u64 m_inc_trending_up_start_time = 0; // milliseconds + bool m_queue_size_timer_started = false; + + /* + Metadata is re-written on disk only if this is true. + This is reset to false when written on disk. + */ + bool m_map_metadata_changed = true; + MapDatabase *dbase = nullptr; + MapDatabase *dbase_ro = nullptr; + + // Map metrics + MetricGaugePtr m_loaded_blocks_gauge; + MetricCounterPtr m_save_time_counter; + MetricCounterPtr m_save_count_counter; +}; From 24f2c38093dd1c1e3cfff4181b12a0268dbe3abd Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 7 Mar 2024 15:10:52 +0100 Subject: [PATCH 56/91] Split internal parts from connection.h --- src/network/connection.cpp | 2 +- src/network/connection.h | 575 +++--------------------------- src/network/connection_internal.h | 499 ++++++++++++++++++++++++++ src/network/connectionthreads.h | 6 +- src/unittest/test_connection.cpp | 2 +- 5 files changed, 562 insertions(+), 522 deletions(-) create mode 100644 src/network/connection_internal.h diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 8c9f1cbac..0110f8c22 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include "connection.h" +#include "connection_internal.h" #include "serialization.h" #include "log.h" #include "porting.h" diff --git a/src/network/connection.h b/src/network/connection.h index 4c7c7a609..13a2cabb0 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -32,95 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#define MAX_UDP_PEERS 65535 - -/* -=== NOTES === - -A packet is sent through a channel to a peer with a basic header: - Header (7 bytes): - [0] u32 protocol_id - [4] session_t sender_peer_id - [6] u8 channel -sender_peer_id: - Unique to each peer. - value 0 (PEER_ID_INEXISTENT) is reserved for making new connections - value 1 (PEER_ID_SERVER) is reserved for server - these constants are defined in constants.h -channel: - Channel numbers have no intrinsic meaning. Currently only 0, 1, 2 exist. -*/ -#define BASE_HEADER_SIZE 7 -#define CHANNEL_COUNT 3 - -/* -Packet types: - -CONTROL: This is a packet used by the protocol. -- When this is processed, nothing is handed to the user. - Header (2 byte): - [0] u8 type - [1] u8 controltype -controltype and data description: - CONTROLTYPE_ACK - [2] u16 seqnum - CONTROLTYPE_SET_PEER_ID - [2] session_t peer_id_new - CONTROLTYPE_PING - - There is no actual reply, but this can be sent in a reliable - packet to get a reply - CONTROLTYPE_DISCO -*/ -enum ControlType : u8 { - CONTROLTYPE_ACK = 0, - CONTROLTYPE_SET_PEER_ID = 1, - CONTROLTYPE_PING = 2, - CONTROLTYPE_DISCO = 3, -}; - -/* -ORIGINAL: This is a plain packet with no control and no error -checking at all. -- When this is processed, it is directly handed to the user. - Header (1 byte): - [0] u8 type -*/ -//#define TYPE_ORIGINAL 1 -#define ORIGINAL_HEADER_SIZE 1 - -/* -SPLIT: These are sequences of packets forming one bigger piece of -data. -- When processed and all the packet_nums 0...packet_count-1 are - present (this should be buffered), the resulting data shall be - directly handed to the user. -- If the data fails to come up in a reasonable time, the buffer shall - be silently discarded. -- These can be sent as-is or atop of a RELIABLE packet stream. - Header (7 bytes): - [0] u8 type - [1] u16 seqnum - [3] u16 chunk_count - [5] u16 chunk_num -*/ -//#define TYPE_SPLIT 2 - -/* -RELIABLE: Delivery of all RELIABLE packets shall be forced by ACKs, -and they shall be delivered in the same order as sent. This is done -with a buffer in the receiving and transmitting end. -- When this is processed, the contents of each packet is recursively - processed as packets. - Header (3 bytes): - [0] u8 type - [1] u16 seqnum - -*/ -//#define TYPE_RELIABLE 3 -#define RELIABLE_HEADER_SIZE 3 -#define SEQNUM_INITIAL 65500 -#define SEQNUM_MAX 65535 - class NetworkPacket; namespace con @@ -129,336 +40,19 @@ namespace con class ConnectionReceiveThread; class ConnectionSendThread; -typedef enum MTProtocols { +enum MTProtocols { MTP_PRIMARY, MTP_UDP, MTP_MINETEST_RELIABLE_UDP -} MTProtocols; - -enum PacketType : u8 { - PACKET_TYPE_CONTROL = 0, - PACKET_TYPE_ORIGINAL = 1, - PACKET_TYPE_SPLIT = 2, - PACKET_TYPE_RELIABLE = 3, - PACKET_TYPE_MAX }; -inline bool seqnum_higher(u16 totest, u16 base) -{ - if (totest > base) - { - if ((totest - base) > (SEQNUM_MAX/2)) - return false; - - return true; - } - - if ((base - totest) > (SEQNUM_MAX/2)) - return true; - - return false; -} - -inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size) -{ - u16 window_start = next; - u16 window_end = ( next + window_size ) % (SEQNUM_MAX+1); - - if (window_start < window_end) { - return ((seqnum >= window_start) && (seqnum < window_end)); - } - - - return ((seqnum < window_end) || (seqnum >= window_start)); -} - -static inline float CALC_DTIME(u64 lasttime, u64 curtime) -{ - float value = ( curtime - lasttime) / 1000.0; - return MYMAX(MYMIN(value,0.1),0.0); -} - -/* - Struct for all kinds of packets. Includes following data: - BASE_HEADER - u8[] packet data (usually copied from SharedBuffer) -*/ -struct BufferedPacket { - BufferedPacket(u32 a_size) - { - m_data.resize(a_size); - data = &m_data[0]; - } - - DISABLE_CLASS_COPY(BufferedPacket) - - u16 getSeqnum() const; - - inline size_t size() const { return m_data.size(); } - - u8 *data; // Direct memory access - float time = 0.0f; // Seconds from buffering the packet or re-sending - float totaltime = 0.0f; // Seconds from buffering the packet - u64 absolute_send_time = -1; - Address address; // Sender or destination - unsigned int resend_count = 0; - -private: - std::vector m_data; // Data of the packet, including headers -}; - -typedef std::shared_ptr BufferedPacketPtr; - - -// This adds the base headers to the data and makes a packet out of it -BufferedPacketPtr makePacket(Address &address, const SharedBuffer &data, - u32 protocol_id, session_t sender_peer_id, u8 channel); - -// Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet -// Increments split_seqnum if a split packet is made -void makeAutoSplitPacket(const SharedBuffer &data, u32 chunksize_max, - u16 &split_seqnum, std::list> *list); - -// Add the TYPE_RELIABLE header to the data -SharedBuffer makeReliablePacket(const SharedBuffer &data, u16 seqnum); - -struct IncomingSplitPacket -{ - IncomingSplitPacket(u32 cc, bool r): - chunk_count(cc), reliable(r) {} - - IncomingSplitPacket() = delete; - - float time = 0.0f; // Seconds from adding - u32 chunk_count; - bool reliable; // If true, isn't deleted on timeout - - bool allReceived() const - { - return (chunks.size() == chunk_count); - } - bool insert(u32 chunk_num, SharedBuffer &chunkdata); - SharedBuffer reassemble(); - -private: - // Key is chunk number, value is data without headers - std::map> chunks; -}; - -/* - A buffer which stores reliable packets and sorts them internally - for fast access to the smallest one. -*/ - -class ReliablePacketBuffer -{ -public: - ReliablePacketBuffer() = default; - - bool getFirstSeqnum(u16& result); - - BufferedPacketPtr popFirst(); - BufferedPacketPtr popSeqnum(u16 seqnum); - void insert(BufferedPacketPtr &p_ptr, u16 next_expected); - - void incrementTimeouts(float dtime); - u32 getTimedOuts(float timeout); - // timeout relative to last resend - std::vector> getResend(float timeout, u32 max_packets); - - void print(); - bool empty(); - u32 size(); - - -private: - typedef std::list::iterator FindResult; - - FindResult findPacketNoLock(u16 seqnum); - - std::list m_list; - - u16 m_oldest_non_answered_ack; - - std::mutex m_list_mutex; -}; - -/* - A buffer for reconstructing split packets -*/ - -class IncomingSplitBuffer -{ -public: - ~IncomingSplitBuffer(); - /* - Returns a reference counted buffer of length != 0 when a full split - packet is constructed. If not, returns one of length 0. - */ - SharedBuffer insert(BufferedPacketPtr &p_ptr, bool reliable); - - void removeUnreliableTimedOuts(float dtime, float timeout); - -private: - // Key is seqnum - std::map m_buf; - - std::mutex m_map_mutex; -}; - -enum ConnectionCommandType{ - CONNCMD_NONE, - CONNCMD_SERVE, - CONNCMD_CONNECT, - CONNCMD_DISCONNECT, - CONNCMD_DISCONNECT_PEER, - CONNCMD_SEND, - CONNCMD_SEND_TO_ALL, - CONCMD_ACK, - CONCMD_CREATE_PEER, - CONNCMD_RESEND_ONE -}; - -struct ConnectionCommand; -typedef std::shared_ptr ConnectionCommandPtr; - -// This is very similar to ConnectionEvent -struct ConnectionCommand -{ - const ConnectionCommandType type; - Address address; - session_t peer_id = PEER_ID_INEXISTENT; - u8 channelnum = 0; - Buffer data; - bool reliable = false; - bool raw = false; - - DISABLE_CLASS_COPY(ConnectionCommand); - - static ConnectionCommandPtr serve(Address address); - static ConnectionCommandPtr connect(Address address); - static ConnectionCommandPtr disconnect(); - static ConnectionCommandPtr disconnect_peer(session_t peer_id); - static ConnectionCommandPtr resend_one(session_t peer_id); - static ConnectionCommandPtr send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable); - static ConnectionCommandPtr ack(session_t peer_id, u8 channelnum, const Buffer &data); - static ConnectionCommandPtr createPeer(session_t peer_id, const Buffer &data); - -private: - ConnectionCommand(ConnectionCommandType type_) : - type(type_) {} - - static ConnectionCommandPtr create(ConnectionCommandType type); -}; - -/* maximum window size to use, 0xFFFF is theoretical maximum. don't think about - * touching it, the less you're away from it the more likely data corruption - * will occur - */ -#define MAX_RELIABLE_WINDOW_SIZE 0x8000 -/* starting value for window size */ -#define START_RELIABLE_WINDOW_SIZE 0x400 -/* minimum value for window size */ -#define MIN_RELIABLE_WINDOW_SIZE 0x40 - -class Channel -{ - -public: - u16 readNextIncomingSeqNum(); - u16 incNextIncomingSeqNum(); - - u16 getOutgoingSequenceNumber(bool& successful); - u16 readOutgoingSequenceNumber(); - bool putBackSequenceNumber(u16); - - u16 readNextSplitSeqNum(); - void setNextSplitSeqNum(u16 seqnum); - - // This is for buffering the incoming packets that are coming in - // the wrong order - ReliablePacketBuffer incoming_reliables; - // This is for buffering the sent packets so that the sender can - // re-send them if no ACK is received - ReliablePacketBuffer outgoing_reliables_sent; - - //queued reliable packets - std::queue queued_reliables; - - //queue commands prior splitting to packets - std::deque queued_commands; - - IncomingSplitBuffer incoming_splits; - - Channel() = default; - ~Channel() = default; - - void UpdatePacketLossCounter(unsigned int count); - void UpdatePacketTooLateCounter(); - void UpdateBytesSent(unsigned int bytes,unsigned int packages=1); - void UpdateBytesLost(unsigned int bytes); - void UpdateBytesReceived(unsigned int bytes); - - void UpdateTimers(float dtime); - - float getCurrentDownloadRateKB() - { MutexAutoLock lock(m_internal_mutex); return cur_kbps; }; - float getMaxDownloadRateKB() - { MutexAutoLock lock(m_internal_mutex); return max_kbps; }; - - float getCurrentLossRateKB() - { MutexAutoLock lock(m_internal_mutex); return cur_kbps_lost; }; - float getMaxLossRateKB() - { MutexAutoLock lock(m_internal_mutex); return max_kbps_lost; }; - - float getCurrentIncomingRateKB() - { MutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; }; - float getMaxIncomingRateKB() - { MutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; }; - - float getAvgDownloadRateKB() - { MutexAutoLock lock(m_internal_mutex); return avg_kbps; }; - float getAvgLossRateKB() - { MutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; }; - float getAvgIncomingRateKB() - { MutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; }; - - u16 getWindowSize() const { return m_window_size; }; - - void setWindowSize(long size) - { - m_window_size = (u16)rangelim(size, MIN_RELIABLE_WINDOW_SIZE, MAX_RELIABLE_WINDOW_SIZE); - } - -private: - std::mutex m_internal_mutex; - u16 m_window_size = MIN_RELIABLE_WINDOW_SIZE; - - u16 next_incoming_seqnum = SEQNUM_INITIAL; - - u16 next_outgoing_seqnum = SEQNUM_INITIAL; - u16 next_outgoing_split_seqnum = SEQNUM_INITIAL; - - unsigned int current_packet_loss = 0; - unsigned int current_packet_too_late = 0; - unsigned int current_packet_successful = 0; - float packet_loss_counter = 0.0f; - - unsigned int current_bytes_transfered = 0; - unsigned int current_bytes_received = 0; - unsigned int current_bytes_lost = 0; - float max_kbps = 0.0f; - float cur_kbps = 0.0f; - float avg_kbps = 0.0f; - float max_incoming_kbps = 0.0f; - float cur_incoming_kbps = 0.0f; - float avg_incoming_kbps = 0.0f; - float max_kbps_lost = 0.0f; - float cur_kbps_lost = 0.0f; - float avg_kbps_lost = 0.0f; - float bpm_counter = 0.0f; - - unsigned int rate_samples = 0; +enum rate_stat_type { + CUR_DL_RATE, + AVG_DL_RATE, + CUR_INC_RATE, + AVG_INC_RATE, + CUR_LOSS_RATE, + AVG_LOSS_RATE, }; class Peer; @@ -480,16 +74,54 @@ private: Peer *m_peer = nullptr; }; -class Connection; +/* + Connection +*/ -typedef enum { - CUR_DL_RATE, - AVG_DL_RATE, - CUR_INC_RATE, - AVG_INC_RATE, - CUR_LOSS_RATE, - AVG_LOSS_RATE, -} rate_stat_type; +enum ConnectionEventType { + CONNEVENT_NONE, + CONNEVENT_DATA_RECEIVED, + CONNEVENT_PEER_ADDED, + CONNEVENT_PEER_REMOVED, + CONNEVENT_BIND_FAILED, +}; + +struct ConnectionEvent; +typedef std::shared_ptr ConnectionEventPtr; + +// This is very similar to ConnectionCommand +struct ConnectionEvent +{ + const ConnectionEventType type; + session_t peer_id = 0; + Buffer data; + bool timeout = false; + Address address; + + // We don't want to copy "data" + DISABLE_CLASS_COPY(ConnectionEvent); + + static ConnectionEventPtr create(ConnectionEventType type); + static ConnectionEventPtr dataReceived(session_t peer_id, const Buffer &data); + static ConnectionEventPtr peerAdded(session_t peer_id, Address address); + static ConnectionEventPtr peerRemoved(session_t peer_id, bool is_timeout, Address address); + static ConnectionEventPtr bindFailed(); + + const char *describe() const; + +private: + ConnectionEvent(ConnectionEventType type_) : + type(type_) {} +}; + +struct ConnectionCommand; +typedef std::shared_ptr ConnectionCommandPtr; + +struct BufferedPacket; +typedef std::shared_ptr BufferedPacketPtr; + +class Connection; +class PeerHandler; class Peer { public: @@ -615,102 +247,7 @@ class Peer { u64 m_last_timeout_check; }; -class UDPPeer final : public Peer -{ -public: - - friend class PeerHelper; - friend class ConnectionReceiveThread; - friend class ConnectionSendThread; - friend class Connection; - - UDPPeer(u16 a_id, Address a_address, Connection* connection); - virtual ~UDPPeer() = default; - - void PutReliableSendCommand(ConnectionCommandPtr &c, - unsigned int max_packet_size) override; - - bool getAddress(MTProtocols type, Address& toset) override; - - u16 getNextSplitSequenceNumber(u8 channel) override; - void setNextSplitSequenceNumber(u8 channel, u16 seqnum) override; - - SharedBuffer addSplitPacket(u8 channel, BufferedPacketPtr &toadd, - bool reliable) override; - - bool isTimedOut(float timeout, std::string &reason) override; - -protected: - /* - Calculates avg_rtt and resend_timeout. - rtt=-1 only recalculates resend_timeout - */ - void reportRTT(float rtt) override; - - void RunCommandQueues( - unsigned int max_packet_size, - unsigned int maxtransfer); - - float getResendTimeout() - { MutexAutoLock lock(m_exclusive_access_mutex); return resend_timeout; } - - void setResendTimeout(float timeout) - { MutexAutoLock lock(m_exclusive_access_mutex); resend_timeout = timeout; } - - bool Ping(float dtime, SharedBuffer& data) override; - - Channel channels[CHANNEL_COUNT]; - bool m_pending_disconnect = false; -private: - // This is changed dynamically - float resend_timeout = 0.5; - - bool processReliableSendCommand( - ConnectionCommandPtr &c_ptr, - unsigned int max_packet_size); -}; - -/* - Connection -*/ - -enum ConnectionEventType { - CONNEVENT_NONE, - CONNEVENT_DATA_RECEIVED, - CONNEVENT_PEER_ADDED, - CONNEVENT_PEER_REMOVED, - CONNEVENT_BIND_FAILED, -}; - -struct ConnectionEvent; -typedef std::shared_ptr ConnectionEventPtr; - -// This is very similar to ConnectionCommand -struct ConnectionEvent -{ - const ConnectionEventType type; - session_t peer_id = 0; - Buffer data; - bool timeout = false; - Address address; - - // We don't want to copy "data" - DISABLE_CLASS_COPY(ConnectionEvent); - - static ConnectionEventPtr create(ConnectionEventType type); - static ConnectionEventPtr dataReceived(session_t peer_id, const Buffer &data); - static ConnectionEventPtr peerAdded(session_t peer_id, Address address); - static ConnectionEventPtr peerRemoved(session_t peer_id, bool is_timeout, Address address); - static ConnectionEventPtr bindFailed(); - - const char *describe() const; - -private: - ConnectionEvent(ConnectionEventType type_) : - type(type_) {} -}; - -class PeerHandler; +class UDPPeer; class Connection { diff --git a/src/network/connection_internal.h b/src/network/connection_internal.h new file mode 100644 index 000000000..1bb95d2cf --- /dev/null +++ b/src/network/connection_internal.h @@ -0,0 +1,499 @@ +/* +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +/********************************************/ +/* may only be included from in src/network */ +/********************************************/ + +#include "connection.h" + +#define MAX_UDP_PEERS 65535 + +/* +=== NOTES === + +A packet is sent through a channel to a peer with a basic header: + Header (7 bytes): + [0] u32 protocol_id + [4] session_t sender_peer_id + [6] u8 channel +sender_peer_id: + Unique to each peer. + value 0 (PEER_ID_INEXISTENT) is reserved for making new connections + value 1 (PEER_ID_SERVER) is reserved for server + these constants are defined in constants.h +channel: + Channel numbers have no intrinsic meaning. Currently only 0, 1, 2 exist. +*/ +#define BASE_HEADER_SIZE 7 +#define CHANNEL_COUNT 3 + +/* +Packet types: + +CONTROL: This is a packet used by the protocol. +- When this is processed, nothing is handed to the user. + Header (2 byte): + [0] u8 type + [1] u8 controltype +controltype and data description: + CONTROLTYPE_ACK + [2] u16 seqnum + CONTROLTYPE_SET_PEER_ID + [2] session_t peer_id_new + CONTROLTYPE_PING + - There is no actual reply, but this can be sent in a reliable + packet to get a reply + CONTROLTYPE_DISCO +*/ +enum ControlType : u8 { + CONTROLTYPE_ACK = 0, + CONTROLTYPE_SET_PEER_ID = 1, + CONTROLTYPE_PING = 2, + CONTROLTYPE_DISCO = 3, +}; + +/* +ORIGINAL: This is a plain packet with no control and no error +checking at all. +- When this is processed, it is directly handed to the user. + Header (1 byte): + [0] u8 type +*/ +//#define TYPE_ORIGINAL 1 +#define ORIGINAL_HEADER_SIZE 1 + +/* +SPLIT: These are sequences of packets forming one bigger piece of +data. +- When processed and all the packet_nums 0...packet_count-1 are + present (this should be buffered), the resulting data shall be + directly handed to the user. +- If the data fails to come up in a reasonable time, the buffer shall + be silently discarded. +- These can be sent as-is or atop of a RELIABLE packet stream. + Header (7 bytes): + [0] u8 type + [1] u16 seqnum + [3] u16 chunk_count + [5] u16 chunk_num +*/ +//#define TYPE_SPLIT 2 + +/* +RELIABLE: Delivery of all RELIABLE packets shall be forced by ACKs, +and they shall be delivered in the same order as sent. This is done +with a buffer in the receiving and transmitting end. +- When this is processed, the contents of each packet is recursively + processed as packets. + Header (3 bytes): + [0] u8 type + [1] u16 seqnum + +*/ +//#define TYPE_RELIABLE 3 +#define RELIABLE_HEADER_SIZE 3 +#define SEQNUM_INITIAL 65500 +#define SEQNUM_MAX 65535 + +namespace con +{ + + +enum PacketType : u8 { + PACKET_TYPE_CONTROL = 0, + PACKET_TYPE_ORIGINAL = 1, + PACKET_TYPE_SPLIT = 2, + PACKET_TYPE_RELIABLE = 3, + PACKET_TYPE_MAX +}; + +inline bool seqnum_higher(u16 totest, u16 base) +{ + if (totest > base) + { + if ((totest - base) > (SEQNUM_MAX/2)) + return false; + + return true; + } + + if ((base - totest) > (SEQNUM_MAX/2)) + return true; + + return false; +} + +inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size) +{ + u16 window_start = next; + u16 window_end = ( next + window_size ) % (SEQNUM_MAX+1); + + if (window_start < window_end) { + return ((seqnum >= window_start) && (seqnum < window_end)); + } + + + return ((seqnum < window_end) || (seqnum >= window_start)); +} + +inline float CALC_DTIME(u64 lasttime, u64 curtime) +{ + float value = (curtime - lasttime) / 1000.0f; + return MYMAX(MYMIN(value, 0.1f), 0.0f); +} + + +/* + Struct for all kinds of packets. Includes following data: + BASE_HEADER + u8[] packet data (usually copied from SharedBuffer) +*/ +struct BufferedPacket { + BufferedPacket(u32 a_size) + { + m_data.resize(a_size); + data = &m_data[0]; + } + + DISABLE_CLASS_COPY(BufferedPacket) + + u16 getSeqnum() const; + + inline size_t size() const { return m_data.size(); } + + u8 *data; // Direct memory access + float time = 0.0f; // Seconds from buffering the packet or re-sending + float totaltime = 0.0f; // Seconds from buffering the packet + u64 absolute_send_time = -1; + Address address; // Sender or destination + unsigned int resend_count = 0; + +private: + std::vector m_data; // Data of the packet, including headers +}; + + +// This adds the base headers to the data and makes a packet out of it +BufferedPacketPtr makePacket(Address &address, const SharedBuffer &data, + u32 protocol_id, session_t sender_peer_id, u8 channel); + +// Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet +// Increments split_seqnum if a split packet is made +void makeAutoSplitPacket(const SharedBuffer &data, u32 chunksize_max, + u16 &split_seqnum, std::list> *list); + +// Add the TYPE_RELIABLE header to the data +SharedBuffer makeReliablePacket(const SharedBuffer &data, u16 seqnum); + +struct IncomingSplitPacket +{ + IncomingSplitPacket(u32 cc, bool r): + chunk_count(cc), reliable(r) {} + + IncomingSplitPacket() = delete; + + float time = 0.0f; // Seconds from adding + u32 chunk_count; + bool reliable; // If true, isn't deleted on timeout + + bool allReceived() const + { + return (chunks.size() == chunk_count); + } + bool insert(u32 chunk_num, SharedBuffer &chunkdata); + SharedBuffer reassemble(); + +private: + // Key is chunk number, value is data without headers + std::map> chunks; +}; + +/* + A buffer which stores reliable packets and sorts them internally + for fast access to the smallest one. +*/ + +class ReliablePacketBuffer +{ +public: + ReliablePacketBuffer() = default; + + bool getFirstSeqnum(u16& result); + + BufferedPacketPtr popFirst(); + BufferedPacketPtr popSeqnum(u16 seqnum); + void insert(BufferedPacketPtr &p_ptr, u16 next_expected); + + void incrementTimeouts(float dtime); + u32 getTimedOuts(float timeout); + // timeout relative to last resend + std::vector> getResend(float timeout, u32 max_packets); + + void print(); + bool empty(); + u32 size(); + + +private: + typedef std::list::iterator FindResult; + + FindResult findPacketNoLock(u16 seqnum); + + std::list m_list; + + u16 m_oldest_non_answered_ack; + + std::mutex m_list_mutex; +}; + +/* + A buffer for reconstructing split packets +*/ + +class IncomingSplitBuffer +{ +public: + ~IncomingSplitBuffer(); + /* + Returns a reference counted buffer of length != 0 when a full split + packet is constructed. If not, returns one of length 0. + */ + SharedBuffer insert(BufferedPacketPtr &p_ptr, bool reliable); + + void removeUnreliableTimedOuts(float dtime, float timeout); + +private: + // Key is seqnum + std::map m_buf; + + std::mutex m_map_mutex; +}; + +enum ConnectionCommandType{ + CONNCMD_NONE, + CONNCMD_SERVE, + CONNCMD_CONNECT, + CONNCMD_DISCONNECT, + CONNCMD_DISCONNECT_PEER, + CONNCMD_SEND, + CONNCMD_SEND_TO_ALL, + CONCMD_ACK, + CONCMD_CREATE_PEER, + CONNCMD_RESEND_ONE +}; + +// This is very similar to ConnectionEvent +struct ConnectionCommand +{ + const ConnectionCommandType type; + Address address; + session_t peer_id = PEER_ID_INEXISTENT; + u8 channelnum = 0; + Buffer data; + bool reliable = false; + bool raw = false; + + DISABLE_CLASS_COPY(ConnectionCommand); + + static ConnectionCommandPtr serve(Address address); + static ConnectionCommandPtr connect(Address address); + static ConnectionCommandPtr disconnect(); + static ConnectionCommandPtr disconnect_peer(session_t peer_id); + static ConnectionCommandPtr resend_one(session_t peer_id); + static ConnectionCommandPtr send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable); + static ConnectionCommandPtr ack(session_t peer_id, u8 channelnum, const Buffer &data); + static ConnectionCommandPtr createPeer(session_t peer_id, const Buffer &data); + +private: + ConnectionCommand(ConnectionCommandType type_) : + type(type_) {} + + static ConnectionCommandPtr create(ConnectionCommandType type); +}; + +/* maximum window size to use, 0xFFFF is theoretical maximum. don't think about + * touching it, the less you're away from it the more likely data corruption + * will occur + */ +#define MAX_RELIABLE_WINDOW_SIZE 0x8000 +/* starting value for window size */ +#define START_RELIABLE_WINDOW_SIZE 0x400 +/* minimum value for window size */ +#define MIN_RELIABLE_WINDOW_SIZE 0x40 + +class Channel +{ + +public: + u16 readNextIncomingSeqNum(); + u16 incNextIncomingSeqNum(); + + u16 getOutgoingSequenceNumber(bool& successful); + u16 readOutgoingSequenceNumber(); + bool putBackSequenceNumber(u16); + + u16 readNextSplitSeqNum(); + void setNextSplitSeqNum(u16 seqnum); + + // This is for buffering the incoming packets that are coming in + // the wrong order + ReliablePacketBuffer incoming_reliables; + // This is for buffering the sent packets so that the sender can + // re-send them if no ACK is received + ReliablePacketBuffer outgoing_reliables_sent; + + //queued reliable packets + std::queue queued_reliables; + + //queue commands prior splitting to packets + std::deque queued_commands; + + IncomingSplitBuffer incoming_splits; + + Channel() = default; + ~Channel() = default; + + void UpdatePacketLossCounter(unsigned int count); + void UpdatePacketTooLateCounter(); + void UpdateBytesSent(unsigned int bytes,unsigned int packages=1); + void UpdateBytesLost(unsigned int bytes); + void UpdateBytesReceived(unsigned int bytes); + + void UpdateTimers(float dtime); + + float getCurrentDownloadRateKB() + { MutexAutoLock lock(m_internal_mutex); return cur_kbps; }; + float getMaxDownloadRateKB() + { MutexAutoLock lock(m_internal_mutex); return max_kbps; }; + + float getCurrentLossRateKB() + { MutexAutoLock lock(m_internal_mutex); return cur_kbps_lost; }; + float getMaxLossRateKB() + { MutexAutoLock lock(m_internal_mutex); return max_kbps_lost; }; + + float getCurrentIncomingRateKB() + { MutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; }; + float getMaxIncomingRateKB() + { MutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; }; + + float getAvgDownloadRateKB() + { MutexAutoLock lock(m_internal_mutex); return avg_kbps; }; + float getAvgLossRateKB() + { MutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; }; + float getAvgIncomingRateKB() + { MutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; }; + + u16 getWindowSize() const { return m_window_size; }; + + void setWindowSize(long size) + { + m_window_size = (u16)rangelim(size, MIN_RELIABLE_WINDOW_SIZE, MAX_RELIABLE_WINDOW_SIZE); + } + +private: + std::mutex m_internal_mutex; + u16 m_window_size = MIN_RELIABLE_WINDOW_SIZE; + + u16 next_incoming_seqnum = SEQNUM_INITIAL; + + u16 next_outgoing_seqnum = SEQNUM_INITIAL; + u16 next_outgoing_split_seqnum = SEQNUM_INITIAL; + + unsigned int current_packet_loss = 0; + unsigned int current_packet_too_late = 0; + unsigned int current_packet_successful = 0; + float packet_loss_counter = 0.0f; + + unsigned int current_bytes_transfered = 0; + unsigned int current_bytes_received = 0; + unsigned int current_bytes_lost = 0; + float max_kbps = 0.0f; + float cur_kbps = 0.0f; + float avg_kbps = 0.0f; + float max_incoming_kbps = 0.0f; + float cur_incoming_kbps = 0.0f; + float avg_incoming_kbps = 0.0f; + float max_kbps_lost = 0.0f; + float cur_kbps_lost = 0.0f; + float avg_kbps_lost = 0.0f; + float bpm_counter = 0.0f; + + unsigned int rate_samples = 0; +}; + + +class UDPPeer final : public Peer +{ +public: + + friend class PeerHelper; + friend class ConnectionReceiveThread; + friend class ConnectionSendThread; + friend class Connection; + + UDPPeer(u16 id, Address address, Connection *connection); + virtual ~UDPPeer() = default; + + void PutReliableSendCommand(ConnectionCommandPtr &c, + unsigned int max_packet_size) override; + + bool getAddress(MTProtocols type, Address& toset) override; + + u16 getNextSplitSequenceNumber(u8 channel) override; + void setNextSplitSequenceNumber(u8 channel, u16 seqnum) override; + + SharedBuffer addSplitPacket(u8 channel, BufferedPacketPtr &toadd, + bool reliable) override; + + bool isTimedOut(float timeout, std::string &reason) override; + +protected: + /* + Calculates avg_rtt and resend_timeout. + rtt=-1 only recalculates resend_timeout + */ + void reportRTT(float rtt) override; + + void RunCommandQueues( + unsigned int max_packet_size, + unsigned int maxtransfer); + + float getResendTimeout() + { MutexAutoLock lock(m_exclusive_access_mutex); return resend_timeout; } + + void setResendTimeout(float timeout) + { MutexAutoLock lock(m_exclusive_access_mutex); resend_timeout = timeout; } + + bool Ping(float dtime, SharedBuffer& data) override; + + Channel channels[CHANNEL_COUNT]; + bool m_pending_disconnect = false; +private: + // This is changed dynamically + float resend_timeout = 0.5; + + bool processReliableSendCommand( + ConnectionCommandPtr &c_ptr, + unsigned int max_packet_size); +}; + +} diff --git a/src/network/connectionthreads.h b/src/network/connectionthreads.h index 7e0d44373..ce96e4342 100644 --- a/src/network/connectionthreads.h +++ b/src/network/connectionthreads.h @@ -20,9 +20,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +/********************************************/ +/* may only be included from in src/network */ +/********************************************/ + #include #include "threading/thread.h" -#include "connection.h" +#include "connection_internal.h" namespace con { diff --git a/src/unittest/test_connection.cpp b/src/unittest/test_connection.cpp index ea280f56b..4adbc9039 100644 --- a/src/unittest/test_connection.cpp +++ b/src/unittest/test_connection.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "porting.h" #include "settings.h" #include "util/serialize.h" -#include "network/connection.h" +#include "network/connection_internal.h" #include "network/networkpacket.h" #include "network/socket.h" From bc4ab8b99e8a9530f2a53152ff03608e278b4351 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 12 Mar 2024 14:13:24 +0100 Subject: [PATCH 57/91] General code refactoring/improvements in server, treegen and connection --- src/client/clientmap.h | 10 +-- src/collision.cpp | 2 +- src/collision.h | 2 +- src/database/database-files.cpp | 1 + src/database/database-files.h | 1 - src/emerge.cpp | 2 +- src/httpfetch.cpp | 18 ++---- src/map.cpp | 4 +- src/map.h | 14 +--- src/mapgen/mg_decoration.cpp | 2 +- src/mapgen/treegen.cpp | 102 ++++++++++++++++-------------- src/mapgen/treegen.h | 30 +++------ src/network/connection.cpp | 81 +++++------------------- src/network/connection.h | 82 ++++++++++++------------ src/network/connection_internal.h | 13 ++-- src/network/connectionthreads.cpp | 85 ++++++++----------------- src/raycast.cpp | 11 ++-- src/raycast.h | 6 +- src/script/lua_api/l_env.cpp | 4 +- src/server.cpp | 69 +++++++++----------- src/server.h | 30 ++++----- src/server/mods.cpp | 6 +- src/server/mods.h | 14 ++-- src/serverenvironment.cpp | 61 ++++++++---------- src/serverenvironment.h | 16 ++--- src/tool.cpp | 6 +- src/tool.h | 23 +++---- src/unittest/mock_server.h | 14 +++- src/unittest/test_moveaction.cpp | 22 ++----- src/unittest/test_sao.cpp | 12 ++-- src/util/numeric.cpp | 4 +- src/util/numeric.h | 18 ++++-- src/util/string.cpp | 2 +- src/util/string.h | 2 +- 34 files changed, 330 insertions(+), 439 deletions(-) diff --git a/src/client/clientmap.h b/src/client/clientmap.h index eb9bf7d39..05c33d67c 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -57,18 +57,11 @@ public: s32 id ); - virtual ~ClientMap(); - bool maySaveBlocks() override { return false; } - void drop() override - { - ISceneNode::drop(); // calls destructor - } - void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color); /* @@ -122,6 +115,9 @@ public: void onSettingChanged(const std::string &name); protected: + // use drop() instead + virtual ~ClientMap(); + void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override; private: bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes); diff --git a/src/collision.cpp b/src/collision.cpp index 0814791ed..8e778b402 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -89,7 +89,7 @@ static inline v3f truncate(const v3f& vec, const f32 factor) // The time after which the collision occurs is stored in dtime. CollisionAxis axisAlignedCollision( const aabb3f &staticbox, const aabb3f &movingbox, - const v3f &speed, f32 *dtime) + const v3f speed, f32 *dtime) { //TimeTaker tt("axisAlignedCollision"); diff --git a/src/collision.h b/src/collision.h index 87a502828..b44af55df 100644 --- a/src/collision.h +++ b/src/collision.h @@ -78,7 +78,7 @@ collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef, // dtime receives time until first collision, invalid if -1 is returned CollisionAxis axisAlignedCollision( const aabb3f &staticbox, const aabb3f &movingbox, - const v3f &speed, f32 *dtime); + v3f speed, f32 *dtime); // Helper function: // Checks if moving the movingbox up by the given distance would hit a ceiling. diff --git a/src/database/database-files.cpp b/src/database/database-files.cpp index d670b3ef0..518c776ea 100644 --- a/src/database/database-files.cpp +++ b/src/database/database-files.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "server/player_sao.h" #include "util/string.h" +#include #include // !!! WARNING !!! diff --git a/src/database/database-files.h b/src/database/database-files.h index 04a74aa83..c1bd034f4 100644 --- a/src/database/database-files.h +++ b/src/database/database-files.h @@ -94,7 +94,6 @@ public: private: Json::Value *getOrCreateJson(const std::string &modname); - bool writeJson(const std::string &modname, const Json::Value &json); std::string m_storage_dir; std::unordered_map m_mod_storage; diff --git a/src/emerge.cpp b/src/emerge.cpp index 5b778db69..d6d6e630a 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -646,7 +646,7 @@ void *EmergeThread::run() std::map modified_blocks; m_map = &m_server->m_env->getServerMap(); - m_emerge = m_server->m_emerge; + m_emerge = m_server->getEmergeManager(); m_mapgen = m_emerge->m_mapgens[id]; enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index 87c1c51eb..6e7e22f86 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -19,8 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "httpfetch.h" #include "porting.h" // for sleep_ms(), get_sysinfo(), secure_rand_fill_buf() -#include -#include #include #include #include @@ -152,9 +150,9 @@ bool httpfetch_async_get(u64 caller, HTTPFetchResult &fetch_result) static size_t httpfetch_writefunction( char *ptr, size_t size, size_t nmemb, void *userdata) { - std::ostringstream *stream = (std::ostringstream*)userdata; + auto *dest = reinterpret_cast(userdata); size_t count = size * nmemb; - stream->write(ptr, count); + dest->append(ptr, count); return count; } @@ -215,7 +213,6 @@ private: CURLM *multi = nullptr; HTTPFetchRequest request; HTTPFetchResult result; - std::ostringstream oss; struct curl_slist *http_header = nullptr; curl_mime *multipart_mime = nullptr; }; @@ -225,8 +222,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_, CurlHandlePool *pool_): pool(pool_), request(request_), - result(request_), - oss(std::ios::binary) + result(request_) { curl = pool->alloc(); if (!curl) @@ -277,16 +273,15 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_, curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str()); // Set up a write callback that writes to the - // ostringstream ongoing->oss, unless the data - // is to be discarded + // result struct, unless the data is to be discarded if (request.caller == HTTPFETCH_DISCARD) { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, httpfetch_discardfunction); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr); } else { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, httpfetch_writefunction); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result.data); } // Set data from fields or raw_data @@ -372,7 +367,6 @@ const HTTPFetchResult * HTTPFetchOngoing::complete(CURLcode res) { result.succeeded = (res == CURLE_OK); result.timeout = (res == CURLE_OPERATION_TIMEDOUT); - result.data = oss.str(); // Get HTTP/FTP response code result.response_code = 0; diff --git a/src/map.cpp b/src/map.cpp index cea2ed31c..d54ed1270 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -600,7 +600,7 @@ void Map::removeNodeTimer(v3s16 p) block->removeNodeTimer(p_rel); } -bool Map::determineAdditionalOcclusionCheck(const v3s16 &pos_camera, +bool Map::determineAdditionalOcclusionCheck(const v3s16 pos_camera, const core::aabbox3d &block_bounds, v3s16 &check) { /* @@ -664,7 +664,7 @@ bool Map::determineAdditionalOcclusionCheck(const v3s16 &pos_camera, return false; } -bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target, +bool Map::isOccluded(const v3s16 pos_camera, const v3s16 pos_target, float step, float stepfac, float offset, float end_offset, u32 needed_count) { v3f direction = intToFloat(pos_target - pos_camera, BS); diff --git a/src/map.h b/src/map.h index 44362bb5d..33b4627c4 100644 --- a/src/map.h +++ b/src/map.h @@ -120,14 +120,6 @@ public: virtual ~Map(); DISABLE_CLASS_COPY(Map); - /* - Drop (client) or delete (server) the map. - */ - virtual void drop() - { - delete this; - } - void addEventReceiver(MapEventReceiver *event_receiver); void removeEventReceiver(MapEventReceiver *event_receiver); // event shall be deleted by caller after the call. @@ -314,9 +306,9 @@ protected: // Can be implemented by child class virtual void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) {} - bool determineAdditionalOcclusionCheck(const v3s16 &pos_camera, - const core::aabbox3d &block_bounds, v3s16 &check); - bool isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target, + bool determineAdditionalOcclusionCheck(v3s16 pos_camera, + const core::aabbox3d &block_bounds, v3s16 &to_check); + bool isOccluded(v3s16 pos_camera, v3s16 pos_target, float step, float stepfac, float start_offset, float end_offset, u32 needed_count); }; diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index da364e4a1..f647059d7 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -492,5 +492,5 @@ size_t DecoLSystem::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) // Make sure that tree_def can't be modified, since it is shared. const auto &ref = *tree_def; - return treegen::make_ltree(*vm, p, m_ndef, ref); + return treegen::make_ltree(*vm, p, ref); } diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index ab12233c1..eaaa6c3c4 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -19,14 +19,14 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "irr_v3d.h" #include +#include "treegen.h" +#include "irr_v3d.h" #include "util/pointer.h" #include "util/numeric.h" #include "servermap.h" #include "mapblock.h" -#include "nodedef.h" -#include "treegen.h" +#include "noise.h" #include "voxelalgorithms.h" namespace treegen @@ -42,6 +42,23 @@ void TreeDef::resolveNodeNames() getIdFromNrBacklog(&fruitnode.param0, "", CONTENT_IGNORE); } +/* + L-System tree gen helper functions + + NOTE: the PseudoRandom parameters here were probably accidentally used + as by-value instead of by-reference. But don't change this now to keep + the old behaviour. +*/ +static void tree_trunk_placement(MMVManip &vmanip, v3f p0, const TreeDef &def); +static void tree_leaves_placement(MMVManip &vmanip, v3f p0, + PseudoRandom ps, const TreeDef &def); +static void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, + PseudoRandom ps, const TreeDef &def); +static void tree_fruit_placement(MMVManip &vmanip, v3f p0, const TreeDef &def); + +static void setRotationAxisRadians(core::matrix4 &M, float angle, v3f axis); +static v3f transposeMatrix(const core::matrix4 &M, v3f v); + void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, const NodeDefManager *ndef, s32 seed) { @@ -128,20 +145,18 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, } -// L-System tree LUA spawner treegen::error spawn_ltree(ServerMap *map, v3s16 p0, - const NodeDefManager *ndef, const TreeDef &tree_definition) + const TreeDef &tree_definition) { - std::map modified_blocks; MMVManip vmanip(map); v3s16 tree_blockp = getNodeBlockPos(p0); - treegen::error e; vmanip.initialEmerge(tree_blockp - v3s16(1, 1, 1), tree_blockp + v3s16(1, 3, 1)); - e = make_ltree(vmanip, p0, ndef, tree_definition); + treegen::error e = make_ltree(vmanip, p0, tree_definition); if (e != SUCCESS) return e; + std::map modified_blocks; voxalgo::blit_back_with_light(map, &vmanip, &modified_blocks); // Send a MEET_OTHER event @@ -153,9 +168,8 @@ treegen::error spawn_ltree(ServerMap *map, v3s16 p0, } -//L-System tree generator treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, - const NodeDefManager *ndef, TreeDef tree_definition) + const TreeDef &tree_definition) { s32 seed; if (tree_definition.explicit_seed) @@ -165,10 +179,10 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, PseudoRandom ps(seed); // chance of inserting abcd rules - double prop_a = 9; - double prop_b = 8; - double prop_c = 7; - double prop_d = 6; + constexpr float prop_a = 9; + constexpr float prop_b = 8; + constexpr float prop_c = 7; + constexpr float prop_d = 6; //randomize tree growth level, minimum=2 s16 iterations = tree_definition.iterations; @@ -177,13 +191,13 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, if (iterations < 2) iterations = 2; - s16 MAX_ANGLE_OFFSET = 5; - double angle_in_radians = (double)tree_definition.angle * M_PI / 180; - double angleOffset_in_radians = (s16)(ps.range(0, 1) % MAX_ANGLE_OFFSET) * M_PI / 180; + constexpr s16 MAX_ANGLE_OFFSET = 5; + float angle_in_radians = tree_definition.angle * M_PI / 180; + float angleOffset_in_radians = (s16)(ps.range(0, 1) % MAX_ANGLE_OFFSET) * M_PI / 180; //initialize rotation matrix, position and stacks for branches core::matrix4 rotation; - rotation = setRotationAxisRadians(rotation, M_PI / 2, v3f(0, 0, 1)); + setRotationAxisRadians(rotation, M_PI / 2, v3f(0, 0, 1)); v3f position; position.X = p0.X; position.Y = p0.Y; @@ -494,37 +508,37 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, break; case '+': temp_rotation.makeIdentity(); - temp_rotation = setRotationAxisRadians(temp_rotation, + setRotationAxisRadians(temp_rotation, angle_in_radians + angleOffset_in_radians, v3f(0, 0, 1)); rotation *= temp_rotation; break; case '-': temp_rotation.makeIdentity(); - temp_rotation = setRotationAxisRadians(temp_rotation, + setRotationAxisRadians(temp_rotation, angle_in_radians + angleOffset_in_radians, v3f(0, 0, -1)); rotation *= temp_rotation; break; case '&': temp_rotation.makeIdentity(); - temp_rotation = setRotationAxisRadians(temp_rotation, + setRotationAxisRadians(temp_rotation, angle_in_radians + angleOffset_in_radians, v3f(0, 1, 0)); rotation *= temp_rotation; break; case '^': temp_rotation.makeIdentity(); - temp_rotation = setRotationAxisRadians(temp_rotation, + setRotationAxisRadians(temp_rotation, angle_in_radians + angleOffset_in_radians, v3f(0, -1, 0)); rotation *= temp_rotation; break; case '*': temp_rotation.makeIdentity(); - temp_rotation = setRotationAxisRadians(temp_rotation, + setRotationAxisRadians(temp_rotation, angle_in_radians, v3f(1, 0, 0)); rotation *= temp_rotation; break; case '/': temp_rotation.makeIdentity(); - temp_rotation = setRotationAxisRadians(temp_rotation, + setRotationAxisRadians(temp_rotation, angle_in_radians, v3f(-1, 0, 0)); rotation *= temp_rotation; break; @@ -537,7 +551,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, } -void tree_trunk_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) +void tree_trunk_placement(MMVManip &vmanip, v3f p0, const TreeDef &tree_definition) { v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) @@ -554,7 +568,7 @@ void tree_trunk_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) void tree_leaves_placement(MMVManip &vmanip, v3f p0, - PseudoRandom ps, TreeDef &tree_definition) + PseudoRandom ps, const TreeDef &tree_definition) { MapNode leavesnode = tree_definition.leavesnode; if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance) @@ -578,7 +592,7 @@ void tree_leaves_placement(MMVManip &vmanip, v3f p0, void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, - PseudoRandom ps, TreeDef &tree_definition) + PseudoRandom ps, const TreeDef &tree_definition) { MapNode leavesnode = tree_definition.leavesnode; if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance) @@ -594,7 +608,7 @@ void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, } -void tree_fruit_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) +void tree_fruit_placement(MMVManip &vmanip, v3f p0, const TreeDef &tree_definition) { v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z)); if (!vmanip.m_area.contains(p1)) @@ -607,18 +621,18 @@ void tree_fruit_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition) } -irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis) +void setRotationAxisRadians(core::matrix4 &M, float angle, v3f axis) { - double c = cos(angle); - double s = sin(angle); - double t = 1.0 - c; + float c = std::cos(angle); + float s = std::sin(angle); + float t = 1.0f - c; - double tx = t * axis.X; - double ty = t * axis.Y; - double tz = t * axis.Z; - double sx = s * axis.X; - double sy = s * axis.Y; - double sz = s * axis.Z; + float tx = t * axis.X; + float ty = t * axis.Y; + float tz = t * axis.Z; + float sx = s * axis.X; + float sy = s * axis.Y; + float sz = s * axis.Z; M[0] = tx * axis.X + c; M[1] = tx * axis.Y + sz; @@ -631,19 +645,15 @@ irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3 M[8] = tz * axis.X + sy; M[9] = tz * axis.Y - sx; M[10] = tz * axis.Z + c; - return M; } -v3f transposeMatrix(irr::core::matrix4 M, v3f v) +v3f transposeMatrix(const core::matrix4 &M, v3f v) { v3f translated; - double x = M[0] * v.X + M[4] * v.Y + M[8] * v.Z +M[12]; - double y = M[1] * v.X + M[5] * v.Y + M[9] * v.Z +M[13]; - double z = M[2] * v.X + M[6] * v.Y + M[10] * v.Z +M[14]; - translated.X = x; - translated.Y = y; - translated.Z = z; + translated.X = M[0] * v.X + M[4] * v.Y + M[8] * v.Z + M[12]; + translated.Y = M[1] * v.X + M[5] * v.Y + M[9] * v.Z + M[13]; + translated.Z = M[2] * v.X + M[6] * v.Y + M[10] * v.Z + M[14]; return translated; } diff --git a/src/mapgen/treegen.h b/src/mapgen/treegen.h index bae541030..c622d3db4 100644 --- a/src/mapgen/treegen.h +++ b/src/mapgen/treegen.h @@ -21,8 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -#include -#include "noise.h" +#include +#include "irr_v3d.h" +#include "nodedef.h" +#include "mapnode.h" class MMVManip; class NodeDefManager; @@ -77,24 +79,8 @@ namespace treegen { void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, s32 seed); - // Add L-Systems tree (used by engine) - treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, - const NodeDefManager *ndef, TreeDef tree_definition); - // Spawn L-systems tree from LUA - treegen::error spawn_ltree (ServerMap *map, v3s16 p0, - const NodeDefManager *ndef, const TreeDef &tree_definition); - - // L-System tree gen helper functions - void tree_trunk_placement(MMVManip &vmanip, v3f p0, - TreeDef &tree_definition); - void tree_leaves_placement(MMVManip &vmanip, v3f p0, - PseudoRandom ps, TreeDef &tree_definition); - void tree_single_leaves_placement(MMVManip &vmanip, v3f p0, - PseudoRandom ps, TreeDef &tree_definition); - void tree_fruit_placement(MMVManip &vmanip, v3f p0, - TreeDef &tree_definition); - irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis); - - v3f transposeMatrix(irr::core::matrix4 M ,v3f v); - + // Spawn L-Systems tree on VManip + treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, const TreeDef &def); + // Helper to spawn it directly on map + treegen::error spawn_ltree(ServerMap *map, v3s16 p0, const TreeDef &def); }; // namespace treegen diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 0110f8c22..d16d59f59 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -68,7 +68,7 @@ u16 BufferedPacket::getSeqnum() const return readU16(&data[BASE_HEADER_SIZE + 1]); } -BufferedPacketPtr makePacket(Address &address, const SharedBuffer &data, +BufferedPacketPtr makePacket(const Address &address, const SharedBuffer &data, u32 protocol_id, session_t sender_peer_id, u8 channel) { u32 packet_size = data.getSize() + BASE_HEADER_SIZE; @@ -834,13 +834,6 @@ void Channel::UpdateTimers(float dtime) Peer */ -PeerHelper::PeerHelper(Peer* peer) : - m_peer(peer) -{ - if (peer && !peer->IncUseCount()) - m_peer = nullptr; -} - PeerHelper::~PeerHelper() { if (m_peer) @@ -851,32 +844,14 @@ PeerHelper::~PeerHelper() PeerHelper& PeerHelper::operator=(Peer* peer) { + if (m_peer) + m_peer->DecUseCount(); m_peer = peer; if (peer && !peer->IncUseCount()) m_peer = nullptr; return *this; } -Peer* PeerHelper::operator->() const -{ - return m_peer; -} - -Peer* PeerHelper::operator&() const -{ - return m_peer; -} - -bool PeerHelper::operator!() -{ - return ! m_peer; -} - -bool PeerHelper::operator!=(void* ptr) -{ - return ((void*) m_peer != ptr); -} - bool Peer::IncUseCount() { MutexAutoLock lock(m_exclusive_access_mutex); @@ -989,8 +964,8 @@ void Peer::Drop() delete this; } -UDPPeer::UDPPeer(session_t a_id, Address a_address, Connection* connection) : - Peer(a_address,a_id,connection) +UDPPeer::UDPPeer(session_t id, const Address &address, Connection *connection) : + Peer(id, address, connection) { for (Channel &channel : channels) channel.setWindowSize(START_RELIABLE_WINDOW_SIZE); @@ -1014,17 +989,6 @@ bool UDPPeer::isTimedOut(float timeout, std::string &reason) return false; } -bool UDPPeer::getAddress(MTProtocols type,Address& toset) -{ - if ((type == MTP_UDP) || (type == MTP_MINETEST_RELIABLE_UDP) || (type == MTP_PRIMARY)) - { - toset = address; - return true; - } - - return false; -} - void UDPPeer::reportRTT(float rtt) { if (rtt < 0.0) { @@ -1377,20 +1341,12 @@ PeerHelper Connection::getPeerNoEx(session_t peer_id) session_t Connection::lookupPeer(const Address& sender) { MutexAutoLock peerlock(m_peers_mutex); - std::map::iterator j; - j = m_peers.begin(); - for(; j != m_peers.end(); ++j) - { - Peer *peer = j->second; + for (auto &it: m_peers) { + Peer *peer = it.second; if (peer->isPendingDeletion()) continue; - Address tocheck; - - if ((peer->getAddress(MTP_MINETEST_RELIABLE_UDP, tocheck)) && (tocheck == sender)) - return peer->id; - - if ((peer->getAddress(MTP_UDP, tocheck)) && (tocheck == sender)) + if (peer->getAddress() == sender) return peer->id; } @@ -1427,12 +1383,8 @@ bool Connection::deletePeer(session_t peer_id, bool timeout) m_peer_ids.erase(it); } - Address peer_address; - //any peer has a primary address this never fails! - peer->getAddress(MTP_PRIMARY, peer_address); - // Create event - putEvent(ConnectionEvent::peerRemoved(peer_id, timeout, peer_address)); + putEvent(ConnectionEvent::peerRemoved(peer_id, timeout, peer->getAddress())); peer->Drop(); return true; @@ -1562,15 +1514,14 @@ Address Connection::GetPeerAddress(session_t peer_id) if (!peer) throw PeerNotFoundException("No address for peer found!"); - Address peer_address; - peer->getAddress(MTP_PRIMARY, peer_address); - return peer_address; + return peer->getAddress(); } float Connection::getPeerStat(session_t peer_id, rtt_stat_type type) { PeerHelper peer = getPeerNoEx(peer_id); - if (!peer) return -1; + if (!peer) + return -1; return peer->getStat(type); } @@ -1580,7 +1531,7 @@ float Connection::getLocalStat(rate_stat_type type) FATAL_ERROR_IF(!peer, "Connection::getLocalStat we couldn't get our own peer? are you serious???"); - float retval = 0.0; + float retval = 0; for (Channel &channel : dynamic_cast(&peer)->channels) { switch(type) { @@ -1609,7 +1560,7 @@ float Connection::getLocalStat(rate_stat_type type) return retval; } -session_t Connection::createPeer(Address& sender, MTProtocols protocol, int fd) +session_t Connection::createPeer(const Address &sender, int fd) { // Somebody wants to make a new connection @@ -1694,12 +1645,10 @@ void Connection::sendAck(session_t peer_id, u8 channelnum, u16 seqnum) m_sendThread->Trigger(); } -UDPPeer* Connection::createServerPeer(Address& address) +UDPPeer* Connection::createServerPeer(const Address &address) { if (ConnectedToServer()) - { throw ConnectionException("Already connected to a server"); - } UDPPeer *peer = new UDPPeer(PEER_ID_SERVER, address, this); peer->SetFullyOpen(); diff --git a/src/network/connection.h b/src/network/connection.h index 13a2cabb0..a9e5a18c5 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -25,8 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "constants.h" #include "util/pointer.h" #include "util/container.h" -#include "util/thread.h" #include "util/numeric.h" +#include "porting.h" #include "networkprotocol.h" #include #include @@ -40,12 +40,6 @@ namespace con class ConnectionReceiveThread; class ConnectionSendThread; -enum MTProtocols { - MTP_PRIMARY, - MTP_UDP, - MTP_MINETEST_RELIABLE_UDP -}; - enum rate_stat_type { CUR_DL_RATE, AVG_DL_RATE, @@ -57,18 +51,20 @@ enum rate_stat_type { class Peer; +// FIXME: Peer refcounting should generally be replaced by std::shared_ptr class PeerHelper { public: PeerHelper() = default; - PeerHelper(Peer* peer); + inline PeerHelper(Peer *peer) { *this = peer; } ~PeerHelper(); - PeerHelper& operator=(Peer* peer); - Peer* operator->() const; - bool operator!(); - Peer* operator&() const; - bool operator!=(void* ptr); + PeerHelper& operator=(Peer *peer); + inline Peer* operator->() const { return m_peer; } + inline Peer* operator&() const { return m_peer; } + + inline bool operator!() { return !m_peer; } + inline bool operator!=(std::nullptr_t) { return !!m_peer; } private: Peer *m_peer = nullptr; @@ -127,18 +123,10 @@ class Peer { public: friend class PeerHelper; - Peer(Address address_,session_t id_,Connection* connection) : - id(id_), - m_connection(connection), - address(address_), - m_last_timeout_check(porting::getTimeMs()) - { - }; - virtual ~Peer() { MutexAutoLock usage_lock(m_exclusive_access_mutex); FATAL_ERROR_IF(m_usage != 0, "Reference counting failure"); - }; + } // Unique id of the peer const session_t id; @@ -148,16 +136,25 @@ class Peer { virtual void PutReliableSendCommand(ConnectionCommandPtr &c, unsigned int max_packet_size) {}; - virtual bool getAddress(MTProtocols type, Address& toset) = 0; + virtual const Address &getAddress() const = 0; - bool isPendingDeletion() - { MutexAutoLock lock(m_exclusive_access_mutex); return m_pending_deletion; }; + bool isPendingDeletion() const { + MutexAutoLock lock(m_exclusive_access_mutex); + return m_pending_deletion; + } + void ResetTimeout() { + MutexAutoLock lock(m_exclusive_access_mutex); + m_timeout_counter = 0; + } - void ResetTimeout() - {MutexAutoLock lock(m_exclusive_access_mutex); m_timeout_counter = 0.0; }; - - bool isHalfOpen() const { return m_half_open; } - void SetFullyOpen() { m_half_open = false; } + bool isHalfOpen() const { + MutexAutoLock lock(m_exclusive_access_mutex); + return m_half_open; + } + void SetFullyOpen() { + MutexAutoLock lock(m_exclusive_access_mutex); + m_half_open = false; + } virtual bool isTimedOut(float timeout, std::string &reason); @@ -168,10 +165,8 @@ class Peer { virtual SharedBuffer addSplitPacket(u8 channel, BufferedPacketPtr &toadd, bool reliable) { - errorstream << "Peer::addSplitPacket called," - << " this is supposed to be never called!" << std::endl; - return SharedBuffer(0); - }; + FATAL_ERROR("unimplemented in abstract class"); + } virtual bool Ping(float dtime, SharedBuffer& data) { return false; }; @@ -192,7 +187,16 @@ class Peer { } return -1; } + protected: + Peer(session_t id, const Address &address, Connection *connection) : + id(id), + m_connection(connection), + address(address), + m_last_timeout_check(porting::getTimeMs()) + { + } + virtual void reportRTT(float rtt) {}; void RTTStatistics(float rtt, @@ -206,15 +210,15 @@ class Peer { bool m_pending_deletion = false; - Connection* m_connection; + Connection *m_connection; // Address of the peer Address address; // Ping timer float m_ping_timer = 0.0f; - private: + private: struct rttstats { float jitter_min = FLT_MAX; float jitter_max = 0.0f; @@ -222,8 +226,6 @@ class Peer { float min_rtt = FLT_MAX; float max_rtt = 0.0f; float avg_rtt = -1.0f; - - rttstats() = default; }; rttstats m_rtt; @@ -285,8 +287,8 @@ protected: PeerHelper getPeerNoEx(session_t peer_id); session_t lookupPeer(const Address& sender); - session_t createPeer(Address& sender, MTProtocols protocol, int fd); - UDPPeer* createServerPeer(Address& sender); + session_t createPeer(const Address& sender, int fd); + UDPPeer* createServerPeer(const Address& sender); bool deletePeer(session_t peer_id, bool timeout); void SetPeerID(session_t id) { m_peer_id = id; } diff --git a/src/network/connection_internal.h b/src/network/connection_internal.h index 1bb95d2cf..95f523be2 100644 --- a/src/network/connection_internal.h +++ b/src/network/connection_internal.h @@ -193,7 +193,7 @@ private: // This adds the base headers to the data and makes a packet out of it -BufferedPacketPtr makePacket(Address &address, const SharedBuffer &data, +BufferedPacketPtr makePacket(const Address &address, const SharedBuffer &data, u32 protocol_id, session_t sender_peer_id, u8 channel); // Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet @@ -235,9 +235,7 @@ private: class ReliablePacketBuffer { public: - ReliablePacketBuffer() = default; - - bool getFirstSeqnum(u16& result); + bool getFirstSeqnum(u16 &result); BufferedPacketPtr popFirst(); BufferedPacketPtr popSeqnum(u16 seqnum); @@ -273,6 +271,7 @@ class IncomingSplitBuffer { public: ~IncomingSplitBuffer(); + /* Returns a reference counted buffer of length != 0 when a full split packet is constructed. If not, returns one of length 0. @@ -450,13 +449,15 @@ public: friend class ConnectionSendThread; friend class Connection; - UDPPeer(u16 id, Address address, Connection *connection); + UDPPeer(session_t id, const Address &address, Connection *connection); virtual ~UDPPeer() = default; void PutReliableSendCommand(ConnectionCommandPtr &c, unsigned int max_packet_size) override; - bool getAddress(MTProtocols type, Address& toset) override; + virtual const Address &getAddress() const { + return address; + } u16 getNextSplitSequenceNumber(u8 channel) override; void setNextSplitSequenceNumber(u8 channel, u16 seqnum) override; diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index ed2bcd0b6..3d217ec6c 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -348,11 +348,9 @@ bool ConnectionSendThread::rawSendAsPacket(session_t peer_id, u8 channelnum, return false; SharedBuffer reliable = makeReliablePacket(data, seqnum); - Address peer_address; - peer->getAddress(MTP_MINETEST_RELIABLE_UDP, peer_address); // Add base headers and make a packet - BufferedPacketPtr p = con::makePacket(peer_address, reliable, + BufferedPacketPtr p = con::makePacket(peer->getAddress(), reliable, m_connection->GetProtocolID(), m_connection->GetPeerID(), channelnum); @@ -374,22 +372,14 @@ bool ConnectionSendThread::rawSendAsPacket(session_t peer_id, u8 channelnum, return false; } - Address peer_address; - if (peer->getAddress(MTP_UDP, peer_address)) { - // Add base headers and make a packet - BufferedPacketPtr p = con::makePacket(peer_address, data, - m_connection->GetProtocolID(), m_connection->GetPeerID(), - channelnum); + // Add base headers and make a packet + BufferedPacketPtr p = con::makePacket(peer->getAddress(), data, + m_connection->GetProtocolID(), m_connection->GetPeerID(), + channelnum); - // Send the packet - rawSend(p.get()); - return true; - } - - LOG(dout_con << m_connection->getDesc() - << " INFO: dropped unreliable packet for peer_id: " << peer_id - << " because of (yet) missing udp address" << std::endl); - return false; + // Send the packet + rawSend(p.get()); + return true; } void ConnectionSendThread::processReliableCommand(ConnectionCommandPtr &c) @@ -984,7 +974,7 @@ void ConnectionReceiveThread::receive(SharedBuffer &packetdata, l.logged = true; // We simply drop the packet, the client can try again. } else { - peer_id = m_connection->createPeer(sender, MTP_MINETEST_RELIABLE_UDP, 0); + peer_id = m_connection->createPeer(sender, 0); } } } @@ -999,17 +989,9 @@ void ConnectionReceiveThread::receive(SharedBuffer &packetdata, // Validate peer address - Address peer_address; - if (peer->getAddress(MTP_UDP, peer_address)) { - if (peer_address != sender) { - LOG(derr_con << m_connection->getDesc() - << " Peer " << peer_id << " sending from different address." - " Ignoring." << std::endl); - return; - } - } else { + if (sender != peer->getAddress()) { LOG(derr_con << m_connection->getDesc() - << " Peer " << peer_id << " doesn't have an address?!" + << " Peer " << peer_id << " sending from different address." " Ignoring." << std::endl); return; } @@ -1284,32 +1266,25 @@ SharedBuffer ConnectionReceiveThread::handlePacketType_Original(Channel *cha SharedBuffer ConnectionReceiveThread::handlePacketType_Split(Channel *channel, const SharedBuffer &packetdata, Peer *peer, u8 channelnum, bool reliable) { - Address peer_address; + // We have to create a packet again for buffering + // This isn't actually too bad an idea. + BufferedPacketPtr packet = con::makePacket(peer->getAddress(), + packetdata, + m_connection->GetProtocolID(), + peer->id, + channelnum); - if (peer->getAddress(MTP_UDP, peer_address)) { - // We have to create a packet again for buffering - // This isn't actually too bad an idea. - BufferedPacketPtr packet = con::makePacket(peer_address, - packetdata, - m_connection->GetProtocolID(), - peer->id, - channelnum); + // Buffer the packet + SharedBuffer data = peer->addSplitPacket(channelnum, packet, reliable); - // Buffer the packet - SharedBuffer data = peer->addSplitPacket(channelnum, packet, reliable); - - if (data.getSize() != 0) { - LOG(dout_con << m_connection->getDesc() - << "RETURNING TYPE_SPLIT: Constructed full data, " - << "size=" << data.getSize() << std::endl); - return data; - } - LOG(dout_con << m_connection->getDesc() << "BUFFERED TYPE_SPLIT" << std::endl); - throw ProcessedSilentlyException("Buffered a split packet chunk"); + if (data.getSize() != 0) { + LOG(dout_con << m_connection->getDesc() + << "RETURNING TYPE_SPLIT: Constructed full data, " + << "size=" << data.getSize() << std::endl); + return data; } - - // We should never get here. - FATAL_ERROR("Invalid execution point"); + LOG(dout_con << m_connection->getDesc() << "BUFFERED TYPE_SPLIT" << std::endl); + throw ProcessedSilentlyException("Buffered a split packet chunk"); } SharedBuffer ConnectionReceiveThread::handlePacketType_Reliable(Channel *channel, @@ -1361,15 +1336,11 @@ SharedBuffer ConnectionReceiveThread::handlePacketType_Reliable(Channel *cha } if (seqnum != channel->readNextIncomingSeqNum()) { - Address peer_address; - - // this is a reliable packet so we have a udp address for sure - peer->getAddress(MTP_MINETEST_RELIABLE_UDP, peer_address); // This one comes later, buffer it. // Actually we have to make a packet to buffer one. // Well, we have all the ingredients, so just do it. BufferedPacketPtr packet = con::makePacket( - peer_address, + peer->getAddress(), packetdata, m_connection->GetProtocolID(), peer->id, diff --git a/src/raycast.cpp b/src/raycast.cpp index 510a8f7f9..c78f6c27e 100644 --- a/src/raycast.cpp +++ b/src/raycast.cpp @@ -70,8 +70,8 @@ RaycastState::RaycastState(const core::line3d &shootline, } -bool boxLineCollision(const aabb3f &box, const v3f &start, - const v3f &dir, v3f *collision_point, v3f *collision_normal) +bool boxLineCollision(const aabb3f &box, const v3f start, + const v3f dir, v3f *collision_point, v3f *collision_normal) { if (box.isPointInside(start)) { *collision_point = start; @@ -139,8 +139,8 @@ bool boxLineCollision(const aabb3f &box, const v3f &start, return false; } -bool boxLineCollision(const aabb3f &box, const v3f &rotation, - const v3f &start, const v3f &dir, +bool boxLineCollision(const aabb3f &box, const v3f rotation, + const v3f start, const v3f dir, v3f *collision_point, v3f *collision_normal, v3f *raw_collision_normal) { // Inversely transform the ray rather than rotating the box faces; @@ -149,7 +149,8 @@ bool boxLineCollision(const aabb3f &box, const v3f &rotation, rot.makeInverse(); bool collision = boxLineCollision(box, rot * start, rot * dir, collision_point, collision_normal); - if (!collision) return collision; + if (!collision) + return collision; // Transform the results back rot.makeInverse(); diff --git a/src/raycast.h b/src/raycast.h index ea366f80b..9347b0001 100644 --- a/src/raycast.h +++ b/src/raycast.h @@ -74,9 +74,9 @@ public: * outwards of the surface. If start is in the box, zero vector. * @returns true if a collision point was found */ -bool boxLineCollision(const aabb3f &box, const v3f &start, const v3f &dir, +bool boxLineCollision(const aabb3f &box, v3f start, v3f dir, v3f *collision_point, v3f *collision_normal); -bool boxLineCollision(const aabb3f &box, const v3f &box_rotation, - const v3f &start, const v3f &dir, +bool boxLineCollision(const aabb3f &box, v3f box_rotation, + v3f start, v3f dir, v3f *collision_point, v3f *collision_normal, v3f *raw_collision_normal); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 37aba7500..b348a0f47 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -1346,7 +1346,7 @@ int ModApiEnv::l_spawn_tree(lua_State *L) ServerMap *map = &env->getServerMap(); treegen::error e; - if ((e = treegen::spawn_ltree (map, p0, ndef, tree_def)) != treegen::SUCCESS) { + if ((e = treegen::spawn_ltree (map, p0, tree_def)) != treegen::SUCCESS) { if (e == treegen::UNBALANCED_BRACKETS) { luaL_error(L, "spawn_tree(): closing ']' has no matching opening bracket"); } else { @@ -1652,7 +1652,7 @@ int ModApiEnvVM::l_spawn_tree(lua_State *L) return 0; treegen::error e; - if ((e = treegen::make_ltree(*vm, p0, ndef, tree_def)) != treegen::SUCCESS) { + if ((e = treegen::make_ltree(*vm, p0, tree_def)) != treegen::SUCCESS) { if (e == treegen::UNBALANCED_BRACKETS) { throw LuaError("spawn_tree(): closing ']' has no matching opening bracket"); } else { diff --git a/src/server.cpp b/src/server.cpp index 9e07c8c85..27b953c50 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -400,11 +400,8 @@ Server::~Server() // Delete the rest in the reverse order of creation delete m_game_settings; - delete m_emerge; delete m_banmanager; delete m_mod_storage_database; - delete m_startup_server_map; // if available - delete m_script; delete m_rollback; delete m_itemdef; delete m_nodedef; @@ -438,7 +435,7 @@ void Server::init() } // Create emerge manager - m_emerge = new EmergeManager(this, m_metrics_backend.get()); + m_emerge = std::make_unique(this, m_metrics_backend.get()); // Create ban manager std::string ban_path = m_path_world + DIR_DELIM "ipban.txt"; @@ -460,13 +457,13 @@ void Server::init() MutexAutoLock envlock(m_env_mutex); // Create the Map (loads map_meta.txt, overriding configured mapgen params) - ServerMap *servermap = new ServerMap(m_path_world, this, m_emerge, m_metrics_backend.get()); - m_startup_server_map = servermap; + auto startup_server_map = std::make_unique(m_path_world, this, + m_emerge.get(), m_metrics_backend.get()); // Initialize scripting infostream << "Server: Initializing Lua" << std::endl; - m_script = new ServerScripting(this); + m_script = std::make_unique(this); // Must be created before mod loading because we have some inventory creation m_inventory_mgr = std::make_unique(); @@ -474,7 +471,7 @@ void Server::init() m_script->loadBuiltin(); m_gamespec.checkAndLog(); - m_modmgr->loadMods(m_script); + m_modmgr->loadMods(*m_script); m_script->saveGlobals(); @@ -506,19 +503,18 @@ void Server::init() m_craftdef->initHashes(this); // Initialize Environment - m_startup_server_map = nullptr; // Ownership moved to ServerEnvironment - m_env = new ServerEnvironment(servermap, m_script, this, - m_path_world, m_metrics_backend.get()); + m_env = new ServerEnvironment(std::move(startup_server_map), + this, m_metrics_backend.get()); m_env->init(); m_inventory_mgr->setEnv(m_env); m_clients.setEnv(m_env); - if (!servermap->settings_mgr.makeMapgenParams()) - FATAL_ERROR("Couldn't create any mapgen type"); - // Initialize mapgens - m_emerge->initMapgens(servermap->getMapgenParams()); + auto &servermap = m_env->getServerMap(); + if (!servermap.settings_mgr.makeMapgenParams()) + FATAL_ERROR("Couldn't create any mapgen type"); + m_emerge->initMapgens(servermap.getMapgenParams()); if (g_settings->getBool("enable_rollback_recording")) { // Create rollback manager @@ -532,7 +528,7 @@ void Server::init() m_script->initAsync(); // Register us to receive map edit events - servermap->addEventReceiver(this); + servermap.addEventReceiver(this); m_env->loadMeta(); @@ -1502,8 +1498,7 @@ void Server::SendInventory(RemotePlayer *player, bool incremental) player->inventory.setModified(false); player->setModified(true); - const std::string &s = os.str(); - pkt.putRawString(s.c_str(), s.size()); + pkt.putRawString(os.str()); Send(&pkt); } @@ -1638,32 +1633,30 @@ void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, pkt << p.amount << p.time; + std::ostringstream os(std::ios_base::binary); if (protocol_version >= 42) { // Serialize entire thing - std::ostringstream os(std::ios_base::binary); p.pos.serialize(os); p.vel.serialize(os); p.acc.serialize(os); p.exptime.serialize(os); p.size.serialize(os); - pkt.putRawString(os.str()); } else { // serialize legacy fields only (compatibility) - std::ostringstream os(std::ios_base::binary); p.pos.start.legacySerialize(os); p.vel.start.legacySerialize(os); p.acc.start.legacySerialize(os); p.exptime.start.legacySerialize(os); p.size.start.legacySerialize(os); - pkt.putRawString(os.str()); } + pkt.putRawString(os.str()); pkt << p.collisiondetection; pkt.putLongString(p.texture.string); pkt << id << p.vertical << p.collision_removal << attached_id; { - std::ostringstream os(std::ios_base::binary); + os.str(""); p.animation.serialize(os, protocol_version); pkt.putRawString(os.str()); } @@ -1671,7 +1664,7 @@ void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, pkt << p.node.param0 << p.node.param2 << p.node_tile; { // serialize new fields - std::ostringstream os(std::ios_base::binary); + os.str(""); if (protocol_version < 42) { // initial bias for older properties pkt << p.pos.start.bias @@ -2121,7 +2114,7 @@ void Server::SendActiveObjectMessages(session_t peer_id, const std::string &data NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES, datas.size(), peer_id); - pkt.putRawString(datas.c_str(), datas.size()); + pkt.putRawString(datas); auto &ccf = clientCommandFactoryTable[pkt.getCommand()]; m_clients.sendCustom(pkt.getPeerId(), reliable ? ccf.channel : 1, &pkt, reliable); @@ -2459,7 +2452,7 @@ void Server::SendBlocks(float dtime) total_sending += client->getSendingCount(); const auto old_count = queue.size(); - client->GetNextBlocks(m_env,m_emerge, dtime, queue); + client->GetNextBlocks(m_env, m_emerge.get(), dtime, queue); unique_clients += queue.size() > old_count ? 1 : 0; } } @@ -2693,7 +2686,7 @@ void Server::sendRequestedMedia(session_t peer_id, // Note that applying a "real" bin packing algorithm here is not necessarily // an improvement (might even perform worse) since games usually have lots - // of files larger than 5KB and the current algorithm already minimized + // of files larger than 5KB and the current algorithm already minimizes // the amount of bunches quite well (at the expense of overshooting). u32 file_size_bunch_total = 0; @@ -3800,7 +3793,7 @@ bool Server::rollbackRevertActions(const std::list &actions, std::list *log) { infostream<<"Server::rollbackRevertActions(len="<getMap()); + auto *map = &m_env->getServerMap(); // Fail if no actions to handle if (actions.empty()) { @@ -3989,24 +3982,22 @@ void Server::requestShutdown(const std::string &msg, bool reconnect, float delay } else if (delay < 0.0f && m_shutdown_state.isTimerRunning()) { // Negative delay, cancel shutdown if requested m_shutdown_state.reset(); - std::wstringstream ws; - ws << L"*** Server shutdown canceled."; + const char *s = "*** Server shutdown canceled."; - infostream << wide_to_utf8(ws.str()).c_str() << std::endl; - SendChatMessage(PEER_ID_INEXISTENT, ws.str()); - // m_shutdown_* are already handled, skip. + infostream << s << std::endl; + SendChatMessage(PEER_ID_INEXISTENT, utf8_to_wide(s)); + // m_shutdown_state already handled, skip. return; } else if (delay > 0.0f) { // Positive delay, tell the clients when the server will shut down - std::wstringstream ws; + std::ostringstream oss; - ws << L"*** Server shutting down in " - << duration_to_string(myround(delay)).c_str() - << "."; + oss << "*** Server shutting down in " + << duration_to_string(myround(delay)) << "."; - infostream << wide_to_utf8(ws.str()).c_str() << std::endl; - SendChatMessage(PEER_ID_INEXISTENT, ws.str()); + infostream << oss.str() << std::endl; + SendChatMessage(PEER_ID_INEXISTENT, utf8_to_wide(oss.str())); } m_shutdown_state.trigger(delay, msg, reconnect); diff --git a/src/server.h b/src/server.h index 9facfb29d..7158cbb64 100644 --- a/src/server.h +++ b/src/server.h @@ -280,7 +280,7 @@ public: void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id); // Envlock and conlock should be locked when using scriptapi - ServerScripting *getScriptIface(){ return m_script; } + inline ServerScripting *getScriptIface() { return m_script.get(); } // actions: time-reversed list // Return value: success/failure @@ -294,7 +294,7 @@ public: virtual ICraftDefManager* getCraftDefManager(); virtual u16 allocateUnknownNodeId(const std::string &name); IRollbackManager *getRollbackManager() { return m_rollback; } - virtual EmergeManager *getEmergeManager() { return m_emerge; } + virtual EmergeManager *getEmergeManager() { return m_emerge.get(); } virtual ModStorageDatabase *getModStorageDatabase() { return m_mod_storage_database; } IWritableItemDefManager* getWritableItemDefManager(); @@ -432,6 +432,16 @@ public: // Environment mutex (envlock) std::mutex m_env_mutex; +protected: + /* Do not add more members here, this is only required to make unit tests work. */ + + // Scripting + // Envlock and conlock should be locked when using Lua + std::unique_ptr m_script; + + // Mods + std::unique_ptr m_modmgr; + private: friend class EmergeThread; friend class RemoteClient; @@ -478,7 +488,6 @@ private: void SendBreath(session_t peer_id, u16 breath); void SendAccessDenied(session_t peer_id, AccessDeniedCode reason, const std::string &custom_reason, bool reconnect = false); - void SendAccessDenied_Legacy(session_t peer_id, const std::wstring &reason); void SendDeathscreen(session_t peer_id, bool set_camera_point_target, v3f camera_point_target); void SendItemDef(session_t peer_id, IItemDefManager *itemdef, u16 protocol_version); @@ -608,6 +617,8 @@ private: u16 m_max_chatmessage_length; // For "dedicated" server list flag bool m_dedicated; + + // Game settings layer Settings *m_game_settings = nullptr; // Thread can set; step() will throw as ServerError @@ -626,10 +637,6 @@ private: // Environment ServerEnvironment *m_env = nullptr; - // Reference to the server map until ServerEnvironment is initialized - // after that this variable must be a nullptr - ServerMap *m_startup_server_map = nullptr; - // server connection std::shared_ptr m_con; @@ -640,11 +647,7 @@ private: IRollbackManager *m_rollback = nullptr; // Emerge manager - EmergeManager *m_emerge = nullptr; - - // Scripting - // Envlock and conlock should be locked when using Lua - ServerScripting *m_script = nullptr; + std::unique_ptr m_emerge; // Item definition manager IWritableItemDefManager *m_itemdef; @@ -655,9 +658,6 @@ private: // Craft definition manager IWritableCraftDefManager *m_craftdef; - // Mods - std::unique_ptr m_modmgr; - std::unordered_map server_translations; /* diff --git a/src/server/mods.cpp b/src/server/mods.cpp index 98a4165de..8d0152ba2 100644 --- a/src/server/mods.cpp +++ b/src/server/mods.cpp @@ -50,7 +50,7 @@ ServerModManager::ServerModManager(const std::string &worldpath): } // This function cannot be currenctly easily tested but it should be ASAP -void ServerModManager::loadMods(ServerScripting *script) +void ServerModManager::loadMods(ServerScripting &script) { // Print mods infostream << "Server: Loading mods: "; @@ -65,13 +65,13 @@ void ServerModManager::loadMods(ServerScripting *script) std::string script_path = mod.path + DIR_DELIM + "init.lua"; auto t = porting::getTimeMs(); - script->loadMod(script_path, mod.name); + script.loadMod(script_path, mod.name); infostream << "Mod \"" << mod.name << "\" loaded after " << (porting::getTimeMs() - t) << " ms" << std::endl; } // Run a callback when mods are loaded - script->on_mods_loaded(); + script.on_mods_loaded(); } const ModSpec *ServerModManager::getModSpec(const std::string &modname) const diff --git a/src/server/mods.h b/src/server/mods.h index 70edeb2c6..f6a40bf69 100644 --- a/src/server/mods.h +++ b/src/server/mods.h @@ -22,12 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content/mod_configuration.h" #include -class MetricsBackend; -class MetricCounter; class ServerScripting; /** - * Manage server mods + * Manages server mods * * All new calls to this class must be tested in test_servermodmanager.cpp */ @@ -36,12 +34,20 @@ class ServerModManager ModConfiguration configuration; public: + /** * Creates a ServerModManager which targets worldpath * @param worldpath */ ServerModManager(const std::string &worldpath); - void loadMods(ServerScripting *script); + + /** + * Creates an empty ServerModManager. For testing purposes. + * Note: definition looks like this so it isn't accidentally used. + */ + explicit ServerModManager(std::nullptr_t) {}; + + void loadMods(ServerScripting &script); const ModSpec *getModSpec(const std::string &modname) const; void getModNames(std::vector &modlist) const; diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 6b8e645a7..8a7b568eb 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "scripting_server.h" #include "server.h" #include "util/serialize.h" +#include "util/numeric.h" #include "util/basic_macros.h" #include "util/pointedthing.h" #include "threading/mutex_auto_lock.h" @@ -158,8 +159,7 @@ void LBMManager::loadIntroductionTimes(const std::string ×, // Storing it in a map first instead of // handling the stuff directly in the loop // removes all duplicate entries. - // TODO make this std::unordered_map - std::map introduction_times; + std::unordered_map introduction_times; /* The introduction times string consists of name~time entries, @@ -181,13 +181,11 @@ void LBMManager::loadIntroductionTimes(const std::string ×, } // Put stuff from introduction_times into m_lbm_lookup - for (std::map::const_iterator it = introduction_times.begin(); - it != introduction_times.end(); ++it) { - const std::string &name = it->first; - u32 time = it->second; + for (auto &it : introduction_times) { + const std::string &name = it.first; + u32 time = it.second; - std::map::iterator def_it = - m_lbm_defs.find(name); + auto def_it = m_lbm_defs.find(name); if (def_it == m_lbm_defs.end()) { // This seems to be an LBM entry for // an LBM we haven't loaded. Discard it. @@ -298,7 +296,7 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, ActiveBlockList */ -void fillRadiusBlock(v3s16 p0, s16 r, std::set &list) +static void fillRadiusBlock(v3s16 p0, s16 r, std::set &list) { v3s16 p; for(p.X=p0.X-r; p.X<=p0.X+r; p.X++) @@ -313,7 +311,7 @@ void fillRadiusBlock(v3s16 p0, s16 r, std::set &list) } } -void fillViewConeBlock(v3s16 p0, +static void fillViewConeBlock(v3s16 p0, const s16 r, const v3f camera_pos, const v3f camera_dir, @@ -435,18 +433,12 @@ void OnMapblocksChangedReceiver::onMapEditEvent(const MapEditEvent &event) ServerEnvironment */ -// Random device to seed pseudo random generators. -static std::random_device seed; - -ServerEnvironment::ServerEnvironment(ServerMap *map, - ServerScripting *script_iface, Server *server, - const std::string &path_world, MetricsBackend *mb): +ServerEnvironment::ServerEnvironment(std::unique_ptr map, + Server *server, MetricsBackend *mb): Environment(server), - m_map(map), - m_script(script_iface), - m_server(server), - m_path_world(path_world), - m_rgen(seed()) + m_map(std::move(map)), + m_script(server->getScriptIface()), + m_server(server) { m_step_time_counter = mb->addCounter( "minetest_env_step_time", "Time spent in environment step (in microseconds)"); @@ -461,7 +453,8 @@ ServerEnvironment::ServerEnvironment(ServerMap *map, void ServerEnvironment::init() { // Determine which database backend to use - std::string conf_path = m_path_world + DIR_DELIM + "world.mt"; + const std::string world_path = m_server->getWorldPath(); + const std::string conf_path = world_path + DIR_DELIM "world.mt"; Settings conf; std::string player_backend_name = "sqlite3"; @@ -475,7 +468,7 @@ void ServerEnvironment::init() u16 blocksize = 16; conf.getU16NoEx("blocksize", blocksize); if (blocksize != MAP_BLOCKSIZE) { - throw BaseException(std::string("The map's blocksize is not supported.")); + throw BaseException("The map's blocksize is not supported."); } // Read those values before setting defaults @@ -524,8 +517,8 @@ void ServerEnvironment::init() << "please read http://wiki.minetest.net/Database_backends." << std::endl; } - m_player_database = openPlayerDatabase(player_backend_name, m_path_world, conf); - m_auth_database = openAuthDatabase(auth_backend_name, m_path_world, conf); + m_player_database = openPlayerDatabase(player_backend_name, world_path, conf); + m_auth_database = openAuthDatabase(auth_backend_name, world_path, conf); if (m_map && m_script->has_on_mapblocks_changed()) { m_map->addEventReceiver(&m_on_mapblocks_changed_receiver); @@ -547,8 +540,7 @@ ServerEnvironment::~ServerEnvironment() assert(m_active_blocks.size() == 0); // deactivateBlocksAndObjects does this // Drop/delete map - if (m_map) - m_map->drop(); + m_map.reset(); // Delete ActiveBlockModifiers for (ABMWithState &m_abm : m_abms) { @@ -702,7 +694,7 @@ void ServerEnvironment::saveMeta() if (!m_meta_loaded) return; - std::string path = m_path_world + DIR_DELIM "env_meta.txt"; + std::string path = m_server->getWorldPath() + DIR_DELIM "env_meta.txt"; // Open file and serialize std::ostringstream ss(std::ios_base::binary); @@ -730,8 +722,10 @@ void ServerEnvironment::loadMeta() SANITY_CHECK(!m_meta_loaded); m_meta_loaded = true; + std::string path = m_server->getWorldPath() + DIR_DELIM "env_meta.txt"; + // If file doesn't exist, load default environment metadata - if (!fs::PathExists(m_path_world + DIR_DELIM "env_meta.txt")) { + if (!fs::PathExists(path)) { infostream << "ServerEnvironment: Loading default environment metadata" << std::endl; loadDefaultMeta(); @@ -740,8 +734,6 @@ void ServerEnvironment::loadMeta() infostream << "ServerEnvironment: Loading environment metadata" << std::endl; - std::string path = m_path_world + DIR_DELIM "env_meta.txt"; - // Open file and deserialize std::ifstream is(path.c_str(), std::ios_base::binary); if (!is.good()) { @@ -786,8 +778,7 @@ void ServerEnvironment::loadMeta() } m_lbm_mgr.loadIntroductionTimes(lbm_introduction_times, m_server, m_game_time); - m_day_count = args.exists("day_count") ? - args.getU64("day_count") : 0; + m_day_count = args.exists("day_count") ? args.getU32("day_count") : 0; } /** @@ -1518,7 +1509,7 @@ void ServerEnvironment::step(float dtime) TimeTaker timer("modify in active blocks per interval"); // Shuffle to prevent persistent artifacts of ordering - std::shuffle(m_abms.begin(), m_abms.end(), m_rgen); + std::shuffle(m_abms.begin(), m_abms.end(), MyRandGenerator()); // Initialize handling of ActiveBlockModifiers ABMHandler abmhandler(m_abms, m_cache_abm_interval, this, true); @@ -1532,7 +1523,7 @@ void ServerEnvironment::step(float dtime) // Shuffle the active blocks so that each block gets an equal chance // of having its ABMs run. std::copy(m_active_blocks.m_abm_list.begin(), m_active_blocks.m_abm_list.end(), output.begin()); - std::shuffle(output.begin(), output.end(), m_rgen); + std::shuffle(output.begin(), output.end(), MyRandGenerator()); int i = 0; // determine the time budget for ABMs diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 93244760d..d5d45d0f4 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include -#include #include #include "activeobject.h" @@ -113,7 +112,7 @@ struct LBMContentMapping // many times during operation in the lbm_lookup_map. void deleteContents(); void addLBM(LoadingBlockModifierDef *lbm_def, IGameDef *gamedef); - const std::vector *lookup(content_t c) const; + const lbm_map::mapped_type *lookup(content_t c) const; }; class LBMManager @@ -145,8 +144,7 @@ private: // For m_query_mode == false: // The key of the map is the LBM def's name. - // TODO make this std::unordered_map - std::map m_lbm_defs; + std::unordered_map m_lbm_defs; // For m_query_mode == true: // The key of the map is the LBM def's first introduction time. @@ -221,8 +219,7 @@ enum ClearObjectsMode { class ServerEnvironment final : public Environment { public: - ServerEnvironment(ServerMap *map, ServerScripting *script_iface, - Server *server, const std::string &path_world, MetricsBackend *mb); + ServerEnvironment(std::unique_ptr map, Server *server, MetricsBackend *mb); ~ServerEnvironment(); void init(); @@ -457,7 +454,7 @@ private: */ // The map - ServerMap *m_map; + std::unique_ptr m_map; // Lua state ServerScripting* m_script; // Server definition @@ -466,8 +463,6 @@ private: server::ActiveObjectMgr m_ao_manager; // on_mapblocks_changed map event receiver OnMapblocksChangedReceiver m_on_mapblocks_changed_receiver; - // World path - const std::string m_path_world; // Outgoing network message buffer for active objects std::queue m_active_object_messages; // Some timers @@ -504,9 +499,6 @@ private: PlayerDatabase *m_player_database = nullptr; AuthDatabase *m_auth_database = nullptr; - // Pseudo random generator for shuffling, etc. - std::mt19937 m_rgen; - // Particles IntervalLimiter m_particle_management_interval; std::unordered_map m_particle_spawners; diff --git a/src/tool.cpp b/src/tool.cpp index 9b1dcc247..a01f82755 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -402,11 +402,11 @@ DigParams getDigParams(const ItemGroupList &groups, continue; const std::string &groupname = groupcap.first; - float time = 0; int rating = itemgroup_get(groups, groupname); - bool time_exists = cap.getTime(rating, &time); - if (!time_exists) + const auto time_o = cap.getTime(rating); + if (!time_o.has_value()) continue; + float time = *time_o; if (leveldiff > 1) time /= leveldiff; diff --git a/src/tool.h b/src/tool.h index 55a8bf914..4b25d3a62 100644 --- a/src/tool.h +++ b/src/tool.h @@ -23,11 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemgroup.h" #include "json-forwards.h" #include "common/c_types.h" -#include #include #include #include +#include +#include #include struct ItemDefinition; @@ -41,15 +42,11 @@ struct ToolGroupCap ToolGroupCap() = default; - bool getTime(int rating, float *time) const - { - std::unordered_map::const_iterator i = times.find(rating); - if (i == times.end()) { - *time = 0; - return false; - } - *time = i->second; - return true; + std::optional getTime(int rating) const { + auto i = times.find(rating); + if (i == times.end()) + return std::nullopt; + return i->second; } void toJson(Json::Value &object) const; @@ -91,7 +88,7 @@ struct ToolCapabilities struct WearBarParams { std::map colorStops; - enum BlendMode: u8 { + enum BlendMode : u8 { BLEND_MODE_CONSTANT, BLEND_MODE_LINEAR, BlendMode_END // Dummy for validity check @@ -99,7 +96,7 @@ struct WearBarParams constexpr const static EnumString es_BlendMode[3] = { {WearBarParams::BLEND_MODE_CONSTANT, "constant"}, {WearBarParams::BLEND_MODE_LINEAR, "linear"}, - {0, NULL} + {0, nullptr} }; BlendMode blend; @@ -109,7 +106,7 @@ struct WearBarParams {} WearBarParams(const video::SColor color): - WearBarParams({{0.0, color}}, WearBarParams::BLEND_MODE_CONSTANT) + WearBarParams({{0.0f, color}}, WearBarParams::BLEND_MODE_CONSTANT) {}; void serialize(std::ostream &os) const; diff --git a/src/unittest/mock_server.h b/src/unittest/mock_server.h index aa3a0ae52..6ac86b471 100644 --- a/src/unittest/mock_server.h +++ b/src/unittest/mock_server.h @@ -20,17 +20,29 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "server.h" +#include "server/mods.h" +#include "scripting_server.h" class MockServer : public Server { public: - /* Set path_world to a real existing folder if you plan to initialize scripting! */ + /* Set `path_world` to a real existing folder if you plan to initialize scripting! */ MockServer(const std::string &path_world = "fakepath") : Server(path_world, SubgameSpec("fakespec", "fakespec"), true, Address(), true, nullptr ) {} + /* + * Use this in unit tests to create scripting. + * Note that you still need to call script->loadBuiltin() and don't forget + * a try-catch for `ModError`. + */ + void createScripting() { + m_script = std::make_unique(this); + m_modmgr = std::make_unique(nullptr); + } + void start() = delete; void stop() = delete; diff --git a/src/unittest/test_moveaction.cpp b/src/unittest/test_moveaction.cpp index 4516fcc04..0720ba267 100644 --- a/src/unittest/test_moveaction.cpp +++ b/src/unittest/test_moveaction.cpp @@ -22,8 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mock_inventorymanager.h" #include "mock_server.h" #include "mock_serveractiveobject.h" -#include "scripting_server.h" -#include "server/mods.h" class TestMoveAction : public TestBase { @@ -53,27 +51,21 @@ void TestMoveAction::runTests(IGameDef *gamedef) { MockServer server(getTestTempDirectory()); - ServerScripting server_scripting(&server); + server.createScripting(); try { - // FIXME: When removing the line below, the unittest does NOT crash - // (but it should) when running all unittests in order or registration. - // Some Lua API functions used in builtin require the Mgr to be present. - server.m_modmgr = std::make_unique(server.m_path_world); - std::string builtin = Server::getBuiltinLuaPath() + DIR_DELIM; - server_scripting.loadBuiltin(); - server_scripting.loadMod(builtin + "game" DIR_DELIM "tests" DIR_DELIM "test_moveaction.lua", BUILTIN_MOD_NAME); + auto script = server.getScriptIface(); + script->loadBuiltin(); + script->loadMod(builtin + "game" DIR_DELIM "tests" DIR_DELIM "test_moveaction.lua", BUILTIN_MOD_NAME); } catch (ModError &e) { - // Print backtrace in case of syntax errors rawstream << e.what() << std::endl; num_tests_failed = 1; return; } - server.m_script = &server_scripting; - MetricsBackend mb; - ServerEnvironment server_env(nullptr, &server_scripting, &server, "", &mb); + auto null_map = std::unique_ptr(); + ServerEnvironment server_env(std::move(null_map), &server, &mb); MockServerActiveObject obj(&server_env); TEST(testMove, &obj, gamedef); @@ -88,8 +80,6 @@ void TestMoveAction::runTests(IGameDef *gamedef) TEST(testCallbacks, &obj, &server); TEST(testCallbacksSwap, &obj, &server); - - server.m_script = nullptr; // Do not free stack memory } static ItemStack parse_itemstack(const char *s) diff --git a/src/unittest/test_sao.cpp b/src/unittest/test_sao.cpp index bedc3403b..abacd15eb 100644 --- a/src/unittest/test_sao.cpp +++ b/src/unittest/test_sao.cpp @@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "test.h" #include "mock_server.h" -#include "scripting_server.h" #include "server/luaentity_sao.h" #include "emerge.h" @@ -73,10 +72,11 @@ void TestSAO::runTests(IGameDef *gamedef) ofs2 << "backend = dummy\n"; } - ServerScripting server_scripting(&server); + server.createScripting(); try { - server_scripting.loadBuiltin(); - server_scripting.loadMod(helper_lua, BUILTIN_MOD_NAME); + auto script = server.getScriptIface(); + script->loadBuiltin(); + script->loadMod(helper_lua, BUILTIN_MOD_NAME); } catch (ModError &e) { rawstream << e.what() << std::endl; num_tests_failed = 1; @@ -88,8 +88,8 @@ void TestSAO::runTests(IGameDef *gamedef) // EmergeManager should become mockable MetricsBackend mb; EmergeManager emerge(&server, &mb); - auto *map = new ServerMap(server.getWorldPath(), gamedef, &emerge, &mb); - ServerEnvironment env(map, &server_scripting, &server, "", &mb); + auto map = std::make_unique(server.getWorldPath(), gamedef, &emerge, &mb); + ServerEnvironment env(std::move(map), &server, &mb); env.loadMeta(); m_step_interval = std::max( diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index 423049a37..b500c4d1e 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // myrand -PcgRandom g_pcgrand; +static PcgRandom g_pcgrand; u32 myrand() { @@ -187,7 +187,7 @@ s16 adjustDist(s16 dist, float zoom_fov) return std::round(adjustDist((float)dist, zoom_fov)); } -void setPitchYawRollRad(core::matrix4 &m, const v3f &rot) +void setPitchYawRollRad(core::matrix4 &m, v3f rot) { f64 a1 = rot.Z, a2 = rot.X, a3 = rot.Y; f64 c1 = cos(a1), s1 = sin(a1); diff --git a/src/util/numeric.h b/src/util/numeric.h index ec3145734..c31dcb9fb 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -250,6 +250,16 @@ int myrand_range(int min, int max); float myrand_range(float min, float max); float myrand_float(); +// Implements a C++11 UniformRandomBitGenerator using the above functions +struct MyRandGenerator { + typedef u32 result_type; + static constexpr result_type min() { return 0; } + static constexpr result_type max() { return MYRAND_RANGE; } + inline result_type operator()() { + return myrand(); + } +}; + /* Miscellaneous functions */ @@ -448,18 +458,18 @@ inline void wrappedApproachShortest(T ¤t, const T target, const T stepsize } } -void setPitchYawRollRad(core::matrix4 &m, const v3f &rot); +void setPitchYawRollRad(core::matrix4 &m, v3f rot); -inline void setPitchYawRoll(core::matrix4 &m, const v3f &rot) +inline void setPitchYawRoll(core::matrix4 &m, v3f rot) { - setPitchYawRollRad(m, rot * core::DEGTORAD64); + setPitchYawRollRad(m, rot * core::DEGTORAD); } v3f getPitchYawRollRad(const core::matrix4 &m); inline v3f getPitchYawRoll(const core::matrix4 &m) { - return getPitchYawRollRad(m) * core::RADTODEG64; + return getPitchYawRollRad(m) * core::RADTODEG; } // Muliply the RGB value of a color linearly, and clamp to black/white diff --git a/src/util/string.cpp b/src/util/string.cpp index 534459e2a..844b6dff8 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -574,7 +574,7 @@ bool parseColorString(const std::string &value, video::SColor &color, bool quiet return success; } -std::string encodeHexColorString(const video::SColor &color) +std::string encodeHexColorString(video::SColor color) { std::string color_string = "#"; const char red = color.getRed(); diff --git a/src/util/string.h b/src/util/string.h index 36c374bdf..ac45463d7 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -97,7 +97,7 @@ char *mystrtok_r(char *s, const char *sep, char **lasts) noexcept; u64 read_seed(const char *str); bool parseColorString(const std::string &value, video::SColor &color, bool quiet, unsigned char default_alpha = 0xff); -std::string encodeHexColorString(const video::SColor &color); +std::string encodeHexColorString(video::SColor color); /** From 5727d74d37597927f3b67cfa5a8cefc1eee4fc85 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 17 Mar 2024 22:55:37 +0100 Subject: [PATCH 58/91] Avoid including client headers on server builds --- src/client/client.h | 5 ++++- src/client/clientenvironment.h | 4 ++++ src/client/game.h | 4 ++++ src/client/renderingengine.h | 4 ++++ src/client/sound.h | 4 ++++ src/main.cpp | 4 +--- src/unittest/test.cpp | 1 - src/util/string.h | 4 ++++ 8 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/client/client.h b/src/client/client.h index 9f898e78a..42049791f 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -36,9 +36,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "network/peerhandler.h" #include "gameparams.h" #include "clientdynamicinfo.h" -#include #include "util/numeric.h" +#ifdef SERVER +#error Do not include in server builds +#endif + #define CLIENT_CHAT_MESSAGE_LIMIT_PER_10S 10.0f struct ClientEvent; diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index 407473be7..bdb8b9726 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -24,6 +24,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "activeobjectmgr.h" // client::ActiveObjectMgr #include +#ifdef SERVER +#error Do not include in server builds +#endif + class ClientSimpleObject; class ClientMap; class ClientScripting; diff --git a/src/client/game.h b/src/client/game.h index c1e8bb0a5..0282e5ea9 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -22,6 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes.h" #include +#ifdef SERVER +#error Do not include in server builds +#endif + class InputHandler; class ChatBackend; class RenderingEngine; diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 948485d82..b8ae62fc4 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -30,6 +30,10 @@ with this program; if not, write to the Free Software Foundation, Inc., // include the shadow mapper classes too #include "client/shadows/dynamicshadowsrender.h" +#ifdef SERVER +#error Do not include in server builds +#endif + struct VideoDriverInfo { std::string name; std::string friendly_name; diff --git a/src/client/sound.h b/src/client/sound.h index 132da708e..8b19f7761 100644 --- a/src/client/sound.h +++ b/src/client/sound.h @@ -26,6 +26,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include +#ifdef SERVER +#error Do not include in server builds +#endif + struct SoundSpec; class SoundFallbackPathProvider diff --git a/src/main.cpp b/src/main.cpp index e7ec6dd53..763a8ae37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,9 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "irrlichttypes.h" // must be included before anything irrlicht, see comment in the file +#include "irrlichttypes_bloated.h" #include "irrlicht.h" // createDevice -#include "irrlichttypes_extrabloated.h" #include "irrlicht_changes/printing.h" #include "benchmark/benchmark.h" #include "chat_interface.h" @@ -28,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "filesys.h" #include "version.h" -#include "client/game.h" #include "defaultsettings.h" #include "gettext.h" #include "log.h" diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 761c90813..1fd9001bf 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "test.h" -#include "client/sound.h" #include "nodedef.h" #include "itemdef.h" #include "dummygamedef.h" diff --git a/src/util/string.h b/src/util/string.h index ac45463d7..beb75b6d3 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -20,7 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_bloated.h" +#ifndef SERVER #include "irrString.h" +#endif #include #include #include @@ -732,6 +734,7 @@ inline std::string str_join(const std::vector &list, return oss.str(); } +#ifndef SERVER /** * Create a UTF8 std::string from an irr::core::stringw. */ @@ -749,6 +752,7 @@ inline irr::core::stringw utf8_to_stringw(std::string_view input) std::wstring str = utf8_to_wide(input); return irr::core::stringw(str.c_str(), str.size()); } +#endif /** * Sanitize the name of a new directory. This consists of two stages: From b42b03bc4062eb8dca004b7787ce557d1b4c936e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 24 Mar 2024 11:50:41 +0100 Subject: [PATCH 59/91] Restrict lua_api_deploy workflow to main repo --- .github/workflows/lua_api_deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lua_api_deploy.yml b/.github/workflows/lua_api_deploy.yml index bcefb0972..e42335a78 100644 --- a/.github/workflows/lua_api_deploy.yml +++ b/.github/workflows/lua_api_deploy.yml @@ -16,8 +16,8 @@ on: jobs: build: - runs-on: ubuntu-22.04 - + if: github.repository == 'minetest/minetest' + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 6c4a110679b2c39bf5518aa395145789d05dda60 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 24 Mar 2024 17:18:58 +0000 Subject: [PATCH 60/91] Add world-independent storage directory for mods (#12315) Fixes #4821 --- .gitignore | 1 + doc/lua_api.md | 6 ++++++ src/gamedef.h | 1 + src/script/cpp_api/s_security.cpp | 7 +++++++ src/script/lua_api/l_server.cpp | 20 ++++++++++++++++++++ src/script/lua_api/l_server.h | 3 +++ src/server.cpp | 4 ++++ src/server.h | 2 ++ 8 files changed, 44 insertions(+) diff --git a/.gitignore b/.gitignore index d996a0d4c..c9fc16611 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ AppDir /clientmods/* !/clientmods/preview/ /client/mod_storage/ +/mod_data ## Configuration/log files minetest.conf diff --git a/doc/lua_api.md b/doc/lua_api.md index be11a4c5d..b0bcdf34e 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5306,6 +5306,12 @@ Utilities * `minetest.get_worldpath()`: returns e.g. `"/home/user/.minetest/world"` * Useful for storing custom data +* `minetest.get_mod_data_path()`: returns e.g. `"/home/user/.minetest/mod_data/mymod"` + * Useful for storing custom data *independently of worlds*. + * Must be called during mod load time. + * Can read or write to this directory at any time. + * It's possible that multiple Minetest instances are running at the same + time, which may lead to corruption if you are not careful. * `minetest.is_singleplayer()` * `minetest.features`: Table containing API feature flags diff --git a/src/gamedef.h b/src/gamedef.h index 0f17cabf9..9a6c55ab1 100644 --- a/src/gamedef.h +++ b/src/gamedef.h @@ -75,6 +75,7 @@ public: virtual const ModSpec* getModSpec(const std::string &modname) const = 0; virtual const SubgameSpec* getGameSpec() const { return nullptr; } virtual std::string getWorldPath() const { return ""; } + virtual std::string getModDataPath() const { return ""; } virtual ModStorageDatabase *getModStorageDatabase() = 0; virtual bool joinModChannel(const std::string &channel) = 0; diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index 8f5c261b2..cadeafdd1 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -600,6 +600,13 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, } } + // Allow read/write access to all mod common dirs + str = fs::AbsolutePath(gamedef->getModDataPath()); + if (!str.empty() && fs::PathStartsWith(abs_path, str)) { + if (write_allowed) *write_allowed = true; + return true; + } + str = fs::AbsolutePath(gamedef->getWorldPath()); if (!str.empty()) { // Don't allow access to other paths in the world mod/game path. diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 7fd086910..185287dd7 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "environment.h" #include "remoteplayer.h" #include "log.h" +#include "filesys.h" #include // request_shutdown() @@ -507,6 +508,24 @@ int ModApiServer::l_get_worldpath(lua_State *L) return 1; } +// get_mod_data_path() +int ModApiServer::l_get_mod_data_path(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + std::string modname = ScriptApiBase::getCurrentModNameInsecure(L); + if (modname.empty()) + return 0; + + const Server *srv = getServer(L); + std::string path = srv->getModDataPath() + DIR_DELIM + modname; + if (!fs::CreateAllDirs(path)) + throw LuaError("Failed to create dir"); + + lua_pushstring(L, path.c_str()); + return 1; +} + // sound_play(spec, parameters, [ephemeral]) int ModApiServer::l_sound_play(lua_State *L) { @@ -716,6 +735,7 @@ void ModApiServer::Initialize(lua_State *L, int top) API_FCT(get_server_status); API_FCT(get_server_uptime); API_FCT(get_server_max_lag); + API_FCT(get_mod_data_path); API_FCT(get_worldpath); API_FCT(is_singleplayer); diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h index 33dd814b4..505dce735 100644 --- a/src/script/lua_api/l_server.h +++ b/src/script/lua_api/l_server.h @@ -39,6 +39,9 @@ private: // get_worldpath() static int l_get_worldpath(lua_State *L); + // get_mod_data_path() + static int l_get_mod_data_path(lua_State *L); + // is_singleplayer() static int l_is_singleplayer(lua_State *L); diff --git a/src/server.cpp b/src/server.cpp index 27b953c50..5dd2d4691 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -317,6 +317,10 @@ Server::Server( "Number of map edit events"); m_lag_gauge->set(g_settings->getFloat("dedicated_server_step")); + + m_path_mod_data = porting::path_user + DIR_DELIM "mod_data"; + if (!fs::CreateDir(m_path_mod_data)) + throw ServerError("Failed to create mod data dir"); } Server::~Server() diff --git a/src/server.h b/src/server.h index 7158cbb64..16c1ea4cc 100644 --- a/src/server.h +++ b/src/server.h @@ -306,6 +306,7 @@ public: virtual const SubgameSpec* getGameSpec() const { return &m_gamespec; } static std::string getBuiltinLuaPath(); virtual std::string getWorldPath() const { return m_path_world; } + virtual std::string getModDataPath() const { return m_path_mod_data; } inline bool isSingleplayer() const { return m_simple_singleplayer_mode; } @@ -609,6 +610,7 @@ private: */ // World directory std::string m_path_world; + std::string m_path_mod_data; // Subgame specification SubgameSpec m_gamespec; // If true, do not allow multiple players and hide some multiplayer From 24cc33e7046fc4b90bf8e1b2fd2546c699fc6eee Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 24 Mar 2024 17:19:23 +0000 Subject: [PATCH 61/91] Add button_url[] and hypertext element to allow mods to open web pages (#13825) Fixes #12500 --- builtin/mainmenu/tab_about.lua | 6 +- doc/lua_api.md | 19 ++ games/devtest/mods/testformspec/formspec.lua | 8 +- src/client/game.cpp | 7 + src/gui/CMakeLists.txt | 1 + src/gui/guiFormSpecMenu.cpp | 23 ++- src/gui/guiFormSpecMenu.h | 1 + src/gui/guiHyperText.cpp | 14 ++ src/gui/guiOpenURL.cpp | 196 +++++++++++++++++++ src/gui/guiOpenURL.h | 50 +++++ src/gui/mainmenumanager.h | 19 +- src/unittest/test_utilities.cpp | 19 ++ src/util/CMakeLists.txt | 1 + src/util/colorize.cpp | 113 +++++++++++ src/util/colorize.h | 34 ++++ src/util/string.cpp | 34 ++++ src/util/string.h | 22 +-- 17 files changed, 530 insertions(+), 37 deletions(-) create mode 100644 src/gui/guiOpenURL.cpp create mode 100644 src/gui/guiOpenURL.h create mode 100644 src/util/colorize.cpp create mode 100644 src/util/colorize.h diff --git a/builtin/mainmenu/tab_about.lua b/builtin/mainmenu/tab_about.lua index 8c5573399..1805acc81 100644 --- a/builtin/mainmenu/tab_about.lua +++ b/builtin/mainmenu/tab_about.lua @@ -158,7 +158,7 @@ return { "style[label_button;border=false]" .. "button[0.1,3.4;5.3,0.5;label_button;" .. core.formspec_escape(version.project .. " " .. version.string) .. "]" .. - "button[1.5,4.1;2.5,0.8;homepage;minetest.net]" .. + "button_url[1.5,4.1;2.5,0.8;homepage;minetest.net;https://www.minetest.net/]" .. "hypertext[5.5,0.25;9.75,6.6;credits;" .. minetest.formspec_escape(hypertext) .. "]" -- Render information @@ -188,10 +188,6 @@ return { end, cbf_button_handler = function(this, fields, name, tabdata) - if fields.homepage then - core.open_url("https://www.minetest.net") - end - if fields.share_debug then local path = core.get_user_path() .. DIR_DELIM .. "debug.txt" core.share_file(path) diff --git a/doc/lua_api.md b/doc/lua_api.md index b0bcdf34e..3a2e1f47d 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -3017,6 +3017,16 @@ Elements centered on `H`. With the new coordinate system, `H` will modify the height. * `label` is the text on the button +### `button_url[,;,;;

+ * + * \section intro Introduction + * + * Welcome to the Irrlicht Engine API documentation. + * Here you'll find any information you'll need to develop applications with + * the Irrlicht Engine. If you are looking for a tutorial on how to start, you'll + * find some on the homepage of the Irrlicht Engine at + * irrlicht.sourceforge.net + * or inside the SDK in the examples directory. + * + * The Irrlicht Engine is intended to be an easy-to-use 3d engine, so + * this documentation is an important part of it. If you have any questions or + * suggestions, just send a email to the author of the engine, Nikolaus Gebhardt + * (niko (at) irrlicht3d.org). + * + * + * \section links Links + * + * Namespaces: A very good place to start reading + * the documentation.
+ * Class list: List of all classes with descriptions.
+ * Class members: Good place to find forgotten features.
+ * + * \section irrexample Short example + * + * A simple application, starting up the engine, loading a Quake 2 animated + * model file and the corresponding texture, animating and displaying it + * in front of a blue background and placing a user controlable 3d camera + * would look like the following code. I think this example shows the usage + * of the engine quite well: + * + * \code + * #include + * using namespace irr; + * + * int main() + * { + * // start up the engine + * IrrlichtDevice *device = createDevice(video::EDT_OPENGL, + * core::dimension2d(640,480)); + * + * video::IVideoDriver* driver = device->getVideoDriver(); + * scene::ISceneManager* scenemgr = device->getSceneManager(); + * + * device->setWindowCaption(L"Hello World!"); + * + * // load and show quake2 .md2 model + * scene::ISceneNode* node = scenemgr->addAnimatedMeshSceneNode( + * scenemgr->getMesh("quake2model.md2")); + * + * // if everything worked, add a texture and disable lighting + * if (node) + * { + * node->setMaterialTexture(0, driver->getTexture("texture.bmp")); + * node->setMaterialFlag(video::EMF_LIGHTING, false); + * } + * + * // add a first person shooter style user controlled camera + * scenemgr->addCameraSceneNodeFPS(); + * + * // draw everything + * while(device->run() && driver) + * { + * driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,255)); + * scenemgr->drawAll(); + * driver->endScene(); + * } + * + * // delete device + * device->drop(); + * return 0; + * } + * \endcode + * + * Irrlicht can load a lot of file formats automatically, see irr::scene::ISceneManager::getMesh() + * for a detailed list. So if you would like to replace the simple blue screen background by + * a cool Quake 3 Map, optimized by an octree, just insert this code + * somewhere before the while loop: + * + * \code + * // add .pk3 archive to the file system + * device->getFileSystem()->addZipFileArchive("quake3map.pk3"); + * + * // load .bsp file and show it using an octree + * scenemgr->addOctreeSceneNode( + * scenemgr->getMesh("quake3map.bsp")); + * \endcode + * + * As you can see, the engine uses namespaces. Everything in the engine is + * placed into the namespace 'irr', but there are also 5 sub namespaces. + * You can find a list of all namespaces with descriptions at the + * namespaces page. + * This is also a good place to start reading the documentation. If you + * don't want to write the namespace names all the time, just use all namespaces like + * this: + * \code + * using namespace core; + * using namespace scene; + * using namespace video; + * using namespace io; + * using namespace gui; + * \endcode + * + * There is a lot more the engine can do, but I hope this gave a short + * overview over the basic features of the engine. For more examples, please take + * a look into the examples directory of the SDK. + */ + +#include "SIrrCreationParameters.h" + +//! Everything in the Irrlicht Engine can be found in this namespace. +namespace irr +{ +//! Creates an Irrlicht device. The Irrlicht device is the root object for using the engine. +/** If you need more parameters to be passed to the creation of the Irrlicht Engine device, +use the createDeviceEx() function. +\param driverType: Type of the video driver to use. +\param windowSize: Size of the window or the video mode in fullscreen mode. +\param bits: Bits per pixel in fullscreen mode. Ignored if windowed mode. +\param fullscreen: Should be set to true if the device should run in fullscreen. Otherwise + the device runs in windowed mode. +\param stencilbuffer: Specifies if the stencil buffer should be enabled. Set this to true, +if you want the engine be able to draw stencil buffer shadows. Note that not all +devices are able to use the stencil buffer. If they don't no shadows will be drawn. +\param vsync: Specifies vertical synchronization: If set to true, the driver will wait +for the vertical retrace period, otherwise not. +\param receiver: A user created event receiver. +\return Returns pointer to the created IrrlichtDevice or null if the +device could not be created. +*/ +extern "C" IRRLICHT_API IrrlichtDevice *IRRCALLCONV createDevice( + video::E_DRIVER_TYPE driverType = video::EDT_OPENGL, + // parentheses are necessary for some compilers + const core::dimension2d &windowSize = (core::dimension2d(640, 480)), + u32 bits = 32, + bool fullscreen = false, + bool stencilbuffer = true, + bool vsync = false, + IEventReceiver *receiver = 0); + +//! Creates an Irrlicht device with the option to specify advanced parameters. +/** Usually you should used createDevice() for creating an Irrlicht Engine device. +Use this function only if you wish to specify advanced parameters like a window +handle in which the device should be created. +\param parameters: Structure containing advanced parameters for the creation of the device. +See irr::SIrrlichtCreationParameters for details. +\return Returns pointer to the created IrrlichtDevice or null if the +device could not be created. */ +extern "C" IRRLICHT_API IrrlichtDevice *IRRCALLCONV createDeviceEx( + const SIrrlichtCreationParameters ¶meters); + +// THE FOLLOWING IS AN EMPTY LIST OF ALL SUB NAMESPACES +// EXISTING ONLY FOR THE DOCUMENTATION SOFTWARE DOXYGEN. + +//! Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace. +namespace core +{ +} + +//! The gui namespace contains useful classes for easy creation of a graphical user interface. +namespace gui +{ +} + +//! This namespace provides interfaces for input/output: Reading and writing files, accessing zip archives, ... +namespace io +{ +} + +//! All scene management can be found in this namespace: Mesh loading, special scene nodes like octrees and billboards, ... +namespace scene +{ +} + +//! The video namespace contains classes for accessing the video driver. All 2d and 3d rendering is done here. +namespace video +{ +} +} + +/*! \file irrlicht.h + \brief Main header file of the irrlicht, the only file needed to include. +*/ diff --git a/irr/include/irrpack.h b/irr/include/irrpack.h new file mode 100644 index 000000000..5887cda63 --- /dev/null +++ b/irr/include/irrpack.h @@ -0,0 +1,25 @@ +// Copyright (C) 2007-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// include this file right before the data structures to be 1-aligned +// and add to each structure the PACK_STRUCT define just like this: +// struct mystruct +// { +// ... +// } PACK_STRUCT; +// Always include the irrunpack.h file right after the last type declared +// like this, and do not put any other types with different alignment +// in between! + +// byte-align structures +#if defined(_MSC_VER) +#pragma warning(disable : 4103) +#pragma pack(push, packing) +#pragma pack(1) +#define PACK_STRUCT +#elif defined(__GNUC__) +#define PACK_STRUCT __attribute__((packed)) +#else +#error compiler not supported +#endif diff --git a/irr/include/irrunpack.h b/irr/include/irrunpack.h new file mode 100644 index 000000000..999e1ea05 --- /dev/null +++ b/irr/include/irrunpack.h @@ -0,0 +1,13 @@ +// Copyright (C) 2007-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// include this file to switch back to default alignment +// file belongs to irrpack.h, see there for more info + +// Default alignment +#if defined(_MSC_VER) +#pragma pack(pop, packing) +#endif + +#undef PACK_STRUCT diff --git a/irr/include/line2d.h b/irr/include/line2d.h new file mode 100644 index 000000000..fb58f0b7a --- /dev/null +++ b/irr/include/line2d.h @@ -0,0 +1,380 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" +#include "vector2d.h" + +namespace irr +{ +namespace core +{ + +//! 2D line between two points with intersection methods. +template +class line2d +{ +public: + //! Default constructor for line going from (0,0) to (1,1). + constexpr line2d() : + start(0, 0), end(1, 1) {} + //! Constructor for line between the two points. + constexpr line2d(T xa, T ya, T xb, T yb) : + start(xa, ya), end(xb, yb) {} + //! Constructor for line between the two points given as vectors. + constexpr line2d(const vector2d &start, const vector2d &end) : + start(start), end(end) {} + + // operators + + line2d operator+(const vector2d &point) const { return line2d(start + point, end + point); } + line2d &operator+=(const vector2d &point) + { + start += point; + end += point; + return *this; + } + + line2d operator-(const vector2d &point) const { return line2d(start - point, end - point); } + line2d &operator-=(const vector2d &point) + { + start -= point; + end -= point; + return *this; + } + + constexpr bool operator==(const line2d &other) const + { + return (start == other.start && end == other.end) || (end == other.start && start == other.end); + } + constexpr bool operator!=(const line2d &other) const + { + return !(start == other.start && end == other.end) || (end == other.start && start == other.end); + } + + // functions + //! Set this line to new line going through the two points. + void setLine(const T &xa, const T &ya, const T &xb, const T &yb) + { + start.set(xa, ya); + end.set(xb, yb); + } + //! Set this line to new line going through the two points. + void setLine(const vector2d &nstart, const vector2d &nend) + { + start.set(nstart); + end.set(nend); + } + //! Set this line to new line given as parameter. + void setLine(const line2d &line) + { + start.set(line.start); + end.set(line.end); + } + + //! Get length of line + /** \return Length of the line. */ + T getLength() const { return start.getDistanceFrom(end); } + + //! Get squared length of the line + /** \return Squared length of line. */ + T getLengthSQ() const { return start.getDistanceFromSQ(end); } + + //! Get middle of the line + /** \return center of the line. */ + vector2d getMiddle() const + { + return (start + end) / (T)2; + } + + //! Get the vector of the line. + /** \return The vector of the line. */ + vector2d getVector() const { return vector2d(end.X - start.X, end.Y - start.Y); } + + /*! Check if this segment intersects another segment, + or if segments are coincident (colinear). */ + bool intersectAsSegments(const line2d &other) const + { + // Taken from: + // http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/ + + // Find the four orientations needed for general and + // special cases + s32 o1 = start.checkOrientation(end, other.start); + s32 o2 = start.checkOrientation(end, other.end); + s32 o3 = other.start.checkOrientation(other.end, start); + s32 o4 = other.start.checkOrientation(other.end, end); + + // General case + if (o1 != o2 && o3 != o4) + return true; + + // Special Cases to check if segments are colinear + if (o1 == 0 && other.start.isBetweenPoints(start, end)) + return true; + if (o2 == 0 && other.end.isBetweenPoints(start, end)) + return true; + if (o3 == 0 && start.isBetweenPoints(other.start, other.end)) + return true; + if (o4 == 0 && end.isBetweenPoints(other.start, other.end)) + return true; + + return false; // Doesn't fall in any of the above cases + } + + /*! Check if 2 segments are incident (intersects in exactly 1 point).*/ + bool incidentSegments(const line2d &other) const + { + return start.checkOrientation(end, other.start) != start.checkOrientation(end, other.end) && other.start.checkOrientation(other.end, start) != other.start.checkOrientation(other.end, end); + } + + /*! Check if 2 lines/segments are parallel or nearly parallel.*/ + bool nearlyParallel(const line2d &line, const T factor = relativeErrorFactor()) const + { + const vector2d a = getVector(); + const vector2d b = line.getVector(); + + return a.nearlyParallel(b, factor); + } + + /*! returns a intersection point of 2 lines (if lines are not parallel). Behaviour + undefined if lines are parallel or coincident. + It's on optimized intersectWith with checkOnlySegments=false and ignoreCoincidentLines=true + */ + vector2d fastLinesIntersection(const line2d &l) const + { + const f32 commonDenominator = (f32)((l.end.Y - l.start.Y) * (end.X - start.X) - + (l.end.X - l.start.X) * (end.Y - start.Y)); + + if (commonDenominator != 0.f) { + const f32 numeratorA = (f32)((l.end.X - l.start.X) * (start.Y - l.start.Y) - + (l.end.Y - l.start.Y) * (start.X - l.start.X)); + + const f32 uA = numeratorA / commonDenominator; + + // Calculate the intersection point. + return vector2d( + (T)(start.X + uA * (end.X - start.X)), + (T)(start.Y + uA * (end.Y - start.Y))); + } else + return l.start; + } + + /*! Check if this line intersect a segment. The eventual intersection point is returned in "out".*/ + bool lineIntersectSegment(const line2d &segment, vector2d &out) const + { + if (nearlyParallel(segment)) + return false; + + out = fastLinesIntersection(segment); + + return out.isBetweenPoints(segment.start, segment.end); + } + + //! Tests if this line intersects with another line. + /** \param l: Other line to test intersection with. + \param checkOnlySegments: Default is to check intersection between the begin and endpoints. + When set to false the function will check for the first intersection point when extending the lines. + \param out: If there is an intersection, the location of the + intersection will be stored in this vector. + \param ignoreCoincidentLines: When true coincident lines (lines above each other) are never considered as intersecting. + When false the center of the overlapping part is returned. + \return True if there is an intersection, false if not. */ + bool intersectWith(const line2d &l, vector2d &out, bool checkOnlySegments = true, bool ignoreCoincidentLines = false) const + { + // Uses the method given at: + // http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ + const f32 commonDenominator = (f32)((l.end.Y - l.start.Y) * (end.X - start.X) - + (l.end.X - l.start.X) * (end.Y - start.Y)); + + const f32 numeratorA = (f32)((l.end.X - l.start.X) * (start.Y - l.start.Y) - + (l.end.Y - l.start.Y) * (start.X - l.start.X)); + + const f32 numeratorB = (f32)((end.X - start.X) * (start.Y - l.start.Y) - + (end.Y - start.Y) * (start.X - l.start.X)); + + if (equals(commonDenominator, 0.f)) { + // The lines are either coincident or parallel + // if both numerators are 0, the lines are coincident + if (!ignoreCoincidentLines && equals(numeratorA, 0.f) && equals(numeratorB, 0.f)) { + // Try and find a common endpoint + if (l.start == start || l.end == start) + out = start; + else if (l.end == end || l.start == end) + out = end; + // now check if the two segments are disjunct + else if (l.start.X > start.X && l.end.X > start.X && l.start.X > end.X && l.end.X > end.X) + return false; + else if (l.start.Y > start.Y && l.end.Y > start.Y && l.start.Y > end.Y && l.end.Y > end.Y) + return false; + else if (l.start.X < start.X && l.end.X < start.X && l.start.X < end.X && l.end.X < end.X) + return false; + else if (l.start.Y < start.Y && l.end.Y < start.Y && l.start.Y < end.Y && l.end.Y < end.Y) + return false; + // else the lines are overlapping to some extent + else { + // find the points which are not contributing to the + // common part + vector2d maxp; + vector2d minp; + if ((start.X > l.start.X && start.X > l.end.X && start.X > end.X) || (start.Y > l.start.Y && start.Y > l.end.Y && start.Y > end.Y)) + maxp = start; + else if ((end.X > l.start.X && end.X > l.end.X && end.X > start.X) || (end.Y > l.start.Y && end.Y > l.end.Y && end.Y > start.Y)) + maxp = end; + else if ((l.start.X > start.X && l.start.X > l.end.X && l.start.X > end.X) || (l.start.Y > start.Y && l.start.Y > l.end.Y && l.start.Y > end.Y)) + maxp = l.start; + else + maxp = l.end; + if (maxp != start && ((start.X < l.start.X && start.X < l.end.X && start.X < end.X) || (start.Y < l.start.Y && start.Y < l.end.Y && start.Y < end.Y))) + minp = start; + else if (maxp != end && ((end.X < l.start.X && end.X < l.end.X && end.X < start.X) || (end.Y < l.start.Y && end.Y < l.end.Y && end.Y < start.Y))) + minp = end; + else if (maxp != l.start && ((l.start.X < start.X && l.start.X < l.end.X && l.start.X < end.X) || (l.start.Y < start.Y && l.start.Y < l.end.Y && l.start.Y < end.Y))) + minp = l.start; + else + minp = l.end; + + // one line is contained in the other. Pick the center + // of the remaining points, which overlap for sure + out = core::vector2d(); + if (start != maxp && start != minp) + out += start; + if (end != maxp && end != minp) + out += end; + if (l.start != maxp && l.start != minp) + out += l.start; + if (l.end != maxp && l.end != minp) + out += l.end; + out.X = (T)(out.X / 2); + out.Y = (T)(out.Y / 2); + } + + return true; // coincident + } + + return false; // parallel + } + + // Get the point of intersection on this line, checking that + // it is within the line segment. + const f32 uA = numeratorA / commonDenominator; + if (checkOnlySegments) { + if (uA < 0.f || uA > 1.f) + return false; // Outside the line segment + + const f32 uB = numeratorB / commonDenominator; + if (uB < 0.f || uB > 1.f) + return false; // Outside the line segment + } + + // Calculate the intersection point. + out.X = (T)(start.X + uA * (end.X - start.X)); + out.Y = (T)(start.Y + uA * (end.Y - start.Y)); + return true; + } + + //! Get unit vector of the line. + /** \return Unit vector of this line. */ + vector2d getUnitVector() const + { + T len = (T)(1.0 / getLength()); + return vector2d((end.X - start.X) * len, (end.Y - start.Y) * len); + } + + //! Get angle between this line and given line. + /** \param l Other line for test. + \return Angle in degrees. */ + f64 getAngleWith(const line2d &l) const + { + vector2d vect = getVector(); + vector2d vect2 = l.getVector(); + return vect.getAngleWith(vect2); + } + + //! Tells us if the given point lies to the left, right, or on the line. + /** \return 0 if the point is on the line + <0 if to the left, or >0 if to the right. */ + T getPointOrientation(const vector2d &point) const + { + return ((end.X - start.X) * (point.Y - start.Y) - + (point.X - start.X) * (end.Y - start.Y)); + } + + //! Check if the given point is a member of the line + /** \return True if point is between start and end, else false. */ + bool isPointOnLine(const vector2d &point) const + { + T d = getPointOrientation(point); + return (d == 0 && point.isBetweenPoints(start, end)); + } + + //! Check if the given point is between start and end of the line. + /** Assumes that the point is already somewhere on the line. */ + bool isPointBetweenStartAndEnd(const vector2d &point) const + { + return point.isBetweenPoints(start, end); + } + + //! Get the closest point on this line to a point + /** \param point: Starting search at this point + \param checkOnlySegments: Default (true) is to return a point on the line-segment (between begin and end) of the line. + When set to false the function will check for the first the closest point on the the line even when outside the segment. */ + vector2d getClosestPoint(const vector2d &point, bool checkOnlySegments = true) const + { + vector2d c((f64)(point.X - start.X), (f64)(point.Y - start.Y)); + vector2d v((f64)(end.X - start.X), (f64)(end.Y - start.Y)); + f64 d = v.getLength(); + if (d == 0) // can't tell much when the line is just a single point + return start; + v /= d; + f64 t = v.dotProduct(c); + + if (checkOnlySegments) { + if (t < 0) + return vector2d((T)start.X, (T)start.Y); + if (t > d) + return vector2d((T)end.X, (T)end.Y); + } + + v *= t; + return vector2d((T)(start.X + v.X), (T)(start.Y + v.Y)); + } + + //! Start point of the line. + vector2d start; + //! End point of the line. + vector2d end; +}; + +// partial specialization to optimize lines (avoiding casts) +template <> +inline vector2df line2d::getClosestPoint(const vector2df &point, bool checkOnlySegments) const +{ + const vector2df c = point - start; + vector2df v = end - start; + const f32 d = (f32)v.getLength(); + if (d == 0) // can't tell much when the line is just a single point + return start; + v /= d; + const f32 t = v.dotProduct(c); + + if (checkOnlySegments) { + if (t < 0) + return start; + if (t > d) + return end; + } + + v *= t; + return start + v; +} + +//! Typedef for an f32 line. +typedef line2d line2df; +//! Typedef for an integer line. +typedef line2d line2di; + +} // end namespace core +} // end namespace irr diff --git a/irr/include/line3d.h b/irr/include/line3d.h new file mode 100644 index 000000000..ea198fba4 --- /dev/null +++ b/irr/include/line3d.h @@ -0,0 +1,165 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" +#include "vector3d.h" + +namespace irr +{ +namespace core +{ + +//! 3D line between two points with intersection methods. +template +class line3d +{ +public: + //! Default constructor + /** line from (0,0,0) to (1,1,1) */ + constexpr line3d() : + start(0, 0, 0), end(1, 1, 1) {} + //! Constructor with two points + constexpr line3d(T xa, T ya, T za, T xb, T yb, T zb) : + start(xa, ya, za), end(xb, yb, zb) {} + //! Constructor with two points as vectors + constexpr line3d(const vector3d &start, const vector3d &end) : + start(start), end(end) {} + + // operators + + line3d operator+(const vector3d &point) const { return line3d(start + point, end + point); } + line3d &operator+=(const vector3d &point) + { + start += point; + end += point; + return *this; + } + + line3d operator-(const vector3d &point) const { return line3d(start - point, end - point); } + line3d &operator-=(const vector3d &point) + { + start -= point; + end -= point; + return *this; + } + + constexpr bool operator==(const line3d &other) const + { + return (start == other.start && end == other.end) || (end == other.start && start == other.end); + } + constexpr bool operator!=(const line3d &other) const + { + return !(start == other.start && end == other.end) || (end == other.start && start == other.end); + } + + // functions + //! Set this line to a new line going through the two points. + void setLine(const T &xa, const T &ya, const T &za, const T &xb, const T &yb, const T &zb) + { + start.set(xa, ya, za); + end.set(xb, yb, zb); + } + //! Set this line to a new line going through the two points. + void setLine(const vector3d &nstart, const vector3d &nend) + { + start.set(nstart); + end.set(nend); + } + //! Set this line to new line given as parameter. + void setLine(const line3d &line) + { + start.set(line.start); + end.set(line.end); + } + + //! Get length of line + /** \return Length of line. */ + T getLength() const { return start.getDistanceFrom(end); } + + //! Get squared length of line + /** \return Squared length of line. */ + T getLengthSQ() const { return start.getDistanceFromSQ(end); } + + //! Get middle of line + /** \return Center of line. */ + vector3d getMiddle() const + { + return (start + end) / (T)2; + } + + //! Get vector of line + /** \return vector of line. */ + vector3d getVector() const + { + return end - start; + } + + //! Check if the given point is between start and end of the line. + /** Assumes that the point is already somewhere on the line. + \param point The point to test. + \return True if point is on the line between start and end, else false. + */ + bool isPointBetweenStartAndEnd(const vector3d &point) const + { + return point.isBetweenPoints(start, end); + } + + //! Get the closest point on this line to a point + /** \param point The point to compare to. + \return The nearest point which is part of the line. */ + vector3d getClosestPoint(const vector3d &point) const + { + vector3d c = point - start; + vector3d v = end - start; + T d = (T)v.getLength(); + v /= d; + T t = v.dotProduct(c); + + if (t < (T)0.0) + return start; + if (t > d) + return end; + + v *= t; + return start + v; + } + + //! Check if the line intersects with a sphere + /** \param sorigin: Origin of the sphere. + \param sradius: Radius of the sphere. + \param outdistance: The distance to the first intersection point. + \return True if there is an intersection. + If there is one, the distance to the first intersection point + is stored in outdistance. */ + bool getIntersectionWithSphere(const vector3d &sorigin, T sradius, f64 &outdistance) const + { + const vector3d q = sorigin - start; + T c = q.getLength(); + T v = q.dotProduct(getVector().normalize()); + T d = sradius * sradius - (c * c - v * v); + + if (d < 0.0) + return false; + + outdistance = v - core::squareroot(d); + return true; + } + + // member variables + + //! Start point of line + vector3d start; + //! End point of line + vector3d end; +}; + +//! Typedef for an f32 line. +typedef line3d line3df; +//! Typedef for an integer line. +typedef line3d line3di; + +} // end namespace core +} // end namespace irr diff --git a/irr/include/matrix4.h b/irr/include/matrix4.h new file mode 100644 index 000000000..374fc6e4a --- /dev/null +++ b/irr/include/matrix4.h @@ -0,0 +1,2282 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include // memset, memcpy +#include "irrMath.h" +#include "vector3d.h" +#include "vector2d.h" +#include "plane3d.h" +#include "aabbox3d.h" +#include "rect.h" +#include "IrrCompileConfig.h" // for IRRLICHT_API + +// enable this to keep track of changes to the matrix +// and make simpler identity check for seldom changing matrices +// otherwise identity check will always compare the elements +// #define USE_MATRIX_TEST + +namespace irr +{ +namespace core +{ + +//! 4x4 matrix. Mostly used as transformation matrix for 3d calculations. +/** The matrix is a D3D style matrix, row major with translations in the 4th row. */ +template +class CMatrix4 +{ +public: + //! Constructor Flags + enum eConstructor + { + EM4CONST_NOTHING = 0, + EM4CONST_COPY, + EM4CONST_IDENTITY, + EM4CONST_TRANSPOSED, + EM4CONST_INVERSE, + EM4CONST_INVERSE_TRANSPOSED + }; + + //! Default constructor + /** \param constructor Choose the initialization style */ + CMatrix4(eConstructor constructor = EM4CONST_IDENTITY); + + //! Constructor with value initialization + constexpr CMatrix4(const T &r0c0, const T &r0c1, const T &r0c2, const T &r0c3, + const T &r1c0, const T &r1c1, const T &r1c2, const T &r1c3, + const T &r2c0, const T &r2c1, const T &r2c2, const T &r2c3, + const T &r3c0, const T &r3c1, const T &r3c2, const T &r3c3) + { + M[0] = r0c0; + M[1] = r0c1; + M[2] = r0c2; + M[3] = r0c3; + M[4] = r1c0; + M[5] = r1c1; + M[6] = r1c2; + M[7] = r1c3; + M[8] = r2c0; + M[9] = r2c1; + M[10] = r2c2; + M[11] = r2c3; + M[12] = r3c0; + M[13] = r3c1; + M[14] = r3c2; + M[15] = r3c3; + } + + //! Copy constructor + /** \param other Other matrix to copy from + \param constructor Choose the initialization style */ + CMatrix4(const CMatrix4 &other, eConstructor constructor = EM4CONST_COPY); + + //! Simple operator for directly accessing every element of the matrix. + T &operator()(const s32 row, const s32 col) + { +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return M[row * 4 + col]; + } + + //! Simple operator for directly accessing every element of the matrix. + const T &operator()(const s32 row, const s32 col) const { return M[row * 4 + col]; } + + //! Simple operator for linearly accessing every element of the matrix. + T &operator[](u32 index) + { +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return M[index]; + } + + //! Simple operator for linearly accessing every element of the matrix. + const T &operator[](u32 index) const { return M[index]; } + + //! Sets this matrix equal to the other matrix. + CMatrix4 &operator=(const CMatrix4 &other) = default; + + //! Sets all elements of this matrix to the value. + inline CMatrix4 &operator=(const T &scalar); + + //! Returns pointer to internal array + const T *pointer() const { return M; } + T *pointer() + { +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return M; + } + + //! Returns true if other matrix is equal to this matrix. + constexpr bool operator==(const CMatrix4 &other) const + { +#if defined(USE_MATRIX_TEST) + if (definitelyIdentityMatrix && other.definitelyIdentityMatrix) + return true; +#endif + for (s32 i = 0; i < 16; ++i) + if (M[i] != other.M[i]) + return false; + + return true; + } + + //! Returns true if other matrix is not equal to this matrix. + constexpr bool operator!=(const CMatrix4 &other) const + { + return !(*this == other); + } + + //! Add another matrix. + CMatrix4 operator+(const CMatrix4 &other) const; + + //! Add another matrix. + CMatrix4 &operator+=(const CMatrix4 &other); + + //! Subtract another matrix. + CMatrix4 operator-(const CMatrix4 &other) const; + + //! Subtract another matrix. + CMatrix4 &operator-=(const CMatrix4 &other); + + //! set this matrix to the product of two matrices + /** Calculate b*a */ + inline CMatrix4 &setbyproduct(const CMatrix4 &other_a, const CMatrix4 &other_b); + + //! Set this matrix to the product of two matrices + /** Calculate b*a, no optimization used, + use it if you know you never have an identity matrix */ + CMatrix4 &setbyproduct_nocheck(const CMatrix4 &other_a, const CMatrix4 &other_b); + + //! Multiply by another matrix. + /** Calculate other*this */ + CMatrix4 operator*(const CMatrix4 &other) const; + + //! Multiply by another matrix. + /** Like calling: (*this) = (*this) * other + */ + CMatrix4 &operator*=(const CMatrix4 &other); + + //! Multiply by scalar. + CMatrix4 operator*(const T &scalar) const; + + //! Multiply by scalar. + CMatrix4 &operator*=(const T &scalar); + + //! Set matrix to identity. + inline CMatrix4 &makeIdentity(); + + //! Returns true if the matrix is the identity matrix + inline bool isIdentity() const; + + //! Returns true if the matrix is orthogonal + inline bool isOrthogonal() const; + + //! Returns true if the matrix is the identity matrix + bool isIdentity_integer_base() const; + + //! Set the translation of the current matrix. Will erase any previous values. + CMatrix4 &setTranslation(const vector3d &translation); + + //! Gets the current translation + vector3d getTranslation() const; + + //! Set the inverse translation of the current matrix. Will erase any previous values. + CMatrix4 &setInverseTranslation(const vector3d &translation); + + //! Make a rotation matrix from Euler angles. The 4th row and column are unmodified. + inline CMatrix4 &setRotationRadians(const vector3d &rotation); + + //! Make a rotation matrix from Euler angles. The 4th row and column are unmodified. + CMatrix4 &setRotationDegrees(const vector3d &rotation); + + //! Get the rotation, as set by setRotation() when you already know the scale used to create the matrix + /** NOTE: The scale needs to be the correct one used to create this matrix. + You can _not_ use the result of getScale(), but have to save your scale + variable in another place (like ISceneNode does). + NOTE: No scale value can be 0 or the result is undefined. + NOTE: It does not necessarily return the *same* Euler angles as those set by setRotationDegrees(), + but the rotation will be equivalent, i.e. will have the same result when used to rotate a vector or node. + NOTE: It will (usually) give wrong results when further transformations have been added in the matrix (like shear). + WARNING: There have been troubles with this function over the years and we may still have missed some corner cases. + It's generally safer to keep the rotation and scale you used to create the matrix around and work with those. + */ + core::vector3d getRotationDegrees(const vector3d &scale) const; + + //! Returns the rotation, as set by setRotation(). + /** NOTE: You will have the same end-rotation as used in setRotation, but it might not use the same axis values. + NOTE: This only works correct if no other matrix operations have been done on the inner 3x3 matrix besides + setting rotation (so no scale/shear). Thought it (probably) works as long as scale doesn't flip handedness. + NOTE: It does not necessarily return the *same* Euler angles as those set by setRotationDegrees(), + but the rotation will be equivalent, i.e. will have the same result when used to rotate a vector or node. + */ + core::vector3d getRotationDegrees() const; + + //! Make an inverted rotation matrix from Euler angles. + /** The 4th row and column are unmodified. */ + inline CMatrix4 &setInverseRotationRadians(const vector3d &rotation); + + //! Make an inverted rotation matrix from Euler angles. + /** The 4th row and column are unmodified. */ + inline CMatrix4 &setInverseRotationDegrees(const vector3d &rotation); + + //! Make a rotation matrix from angle and axis, assuming left handed rotation. + /** The 4th row and column are unmodified. */ + inline CMatrix4 &setRotationAxisRadians(const T &angle, const vector3d &axis); + + //! Set Scale + CMatrix4 &setScale(const vector3d &scale); + + //! Set Scale + CMatrix4 &setScale(const T scale) { return setScale(core::vector3d(scale, scale, scale)); } + + //! Get Scale + core::vector3d getScale() const; + + //! Translate a vector by the inverse of the translation part of this matrix. + void inverseTranslateVect(vector3df &vect) const; + + //! Rotate a vector by the inverse of the rotation part of this matrix. + void inverseRotateVect(vector3df &vect) const; + + //! Rotate a vector by the rotation part of this matrix. + void rotateVect(vector3df &vect) const; + + //! An alternate transform vector method, writing into a second vector + void rotateVect(core::vector3df &out, const core::vector3df &in) const; + + //! An alternate transform vector method, writing into an array of 3 floats + void rotateVect(T *out, const core::vector3df &in) const; + + //! Transforms the vector by this matrix + /** This operation is performed as if the vector was 4d with the 4th component =1 */ + void transformVect(vector3df &vect) const; + + //! Transforms input vector by this matrix and stores result in output vector + /** This operation is performed as if the vector was 4d with the 4th component =1 */ + void transformVect(vector3df &out, const vector3df &in) const; + + //! An alternate transform vector method, writing into an array of 4 floats + /** This operation is performed as if the vector was 4d with the 4th component =1. + NOTE: out[3] will be written to (4th vector component)*/ + void transformVect(T *out, const core::vector3df &in) const; + + //! An alternate transform vector method, reading from and writing to an array of 3 floats + /** This operation is performed as if the vector was 4d with the 4th component =1 + NOTE: out[3] will be written to (4th vector component)*/ + void transformVec3(T *out, const T *in) const; + + //! An alternate transform vector method, reading from and writing to an array of 4 floats + void transformVec4(T *out, const T *in) const; + + //! Translate a vector by the translation part of this matrix. + /** This operation is performed as if the vector was 4d with the 4th component =1 */ + void translateVect(vector3df &vect) const; + + //! Transforms a plane by this matrix + void transformPlane(core::plane3d &plane) const; + + //! Transforms a plane by this matrix + void transformPlane(const core::plane3d &in, core::plane3d &out) const; + + //! Transforms a axis aligned bounding box + void transformBoxEx(core::aabbox3d &box) const; + + //! Multiplies this matrix by a 1x4 matrix + void multiplyWith1x4Matrix(T *matrix) const; + + //! Calculates inverse of matrix. Slow. + /** \return Returns false if there is no inverse matrix.*/ + bool makeInverse(); + + //! Inverts a primitive matrix which only contains a translation and a rotation + /** \param out: where result matrix is written to. */ + bool getInversePrimitive(CMatrix4 &out) const; + + //! Gets the inverse matrix of this one + /** \param out: where result matrix is written to. + \return Returns false if there is no inverse matrix. */ + bool getInverse(CMatrix4 &out) const; + + //! Builds a right-handed perspective projection matrix based on a field of view + //\param zClipFromZero: Clipping of z can be projected from 0 to w when true (D3D style) and from -w to w when false (OGL style). + CMatrix4 &buildProjectionMatrixPerspectiveFovRH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero = true); + + //! Builds a left-handed perspective projection matrix based on a field of view + CMatrix4 &buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero = true); + + //! Builds a left-handed perspective projection matrix based on a field of view, with far plane at infinity + CMatrix4 &buildProjectionMatrixPerspectiveFovInfinityLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 epsilon = 0); + + //! Builds a right-handed perspective projection matrix. + CMatrix4 &buildProjectionMatrixPerspectiveRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero = true); + + //! Builds a left-handed perspective projection matrix. + CMatrix4 &buildProjectionMatrixPerspectiveLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero = true); + + //! Builds a left-handed orthogonal projection matrix. + //\param zClipFromZero: Clipping of z can be projected from 0 to 1 when true (D3D style) and from -1 to 1 when false (OGL style). + CMatrix4 &buildProjectionMatrixOrthoLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero = true); + + //! Builds a right-handed orthogonal projection matrix. + CMatrix4 &buildProjectionMatrixOrthoRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero = true); + + //! Builds a left-handed look-at matrix. + CMatrix4 &buildCameraLookAtMatrixLH( + const vector3df &position, + const vector3df &target, + const vector3df &upVector); + + //! Builds a right-handed look-at matrix. + CMatrix4 &buildCameraLookAtMatrixRH( + const vector3df &position, + const vector3df &target, + const vector3df &upVector); + + //! Builds a matrix that flattens geometry into a plane. + /** \param light: light source + \param plane: plane into which the geometry if flattened into + \param point: value between 0 and 1, describing the light source. + If this is 1, it is a point light, if it is 0, it is a directional light. */ + CMatrix4 &buildShadowMatrix(const core::vector3df &light, core::plane3df plane, f32 point = 1.0f); + + //! Builds a matrix which transforms a normalized Device Coordinate to Device Coordinates. + /** Used to scale <-1,-1><1,1> to viewport, for example from <-1,-1> <1,1> to the viewport <0,0><0,640> */ + CMatrix4 &buildNDCToDCMatrix(const core::rect &area, f32 zScale); + + //! Creates a new matrix as interpolated matrix from two other ones. + /** \param b: other matrix to interpolate with + \param time: Must be a value between 0 and 1. */ + CMatrix4 interpolate(const core::CMatrix4 &b, f32 time) const; + + //! Gets transposed matrix + CMatrix4 getTransposed() const; + + //! Gets transposed matrix + inline void getTransposed(CMatrix4 &dest) const; + + //! Builds a matrix that rotates from one vector to another + /** \param from: vector to rotate from + \param to: vector to rotate to + */ + CMatrix4 &buildRotateFromTo(const core::vector3df &from, const core::vector3df &to); + + //! Builds a combined matrix which translates to a center before rotation and translates from origin afterwards + /** \param center Position to rotate around + \param translate Translation applied after the rotation + */ + void setRotationCenter(const core::vector3df ¢er, const core::vector3df &translate); + + //! Builds a matrix which rotates a source vector to a look vector over an arbitrary axis + /** \param camPos: viewer position in world coo + \param center: object position in world-coo and rotation pivot + \param translation: object final translation from center + \param axis: axis to rotate about + \param from: source vector to rotate from + */ + void buildAxisAlignedBillboard(const core::vector3df &camPos, + const core::vector3df ¢er, + const core::vector3df &translation, + const core::vector3df &axis, + const core::vector3df &from); + + /* + construct 2D Texture transformations + rotate about center, scale, and transform. + */ + //! Set to a texture transformation matrix with the given parameters. + CMatrix4 &buildTextureTransform(f32 rotateRad, + const core::vector2df &rotatecenter, + const core::vector2df &translate, + const core::vector2df &scale); + + //! Set texture transformation rotation + /** Rotate about z axis, recenter at (0.5,0.5). + Doesn't clear other elements than those affected + \param radAngle Angle in radians + \return Altered matrix */ + CMatrix4 &setTextureRotationCenter(f32 radAngle); + + //! Set texture transformation translation + /** Doesn't clear other elements than those affected. + \param x Offset on x axis + \param y Offset on y axis + \return Altered matrix */ + CMatrix4 &setTextureTranslate(f32 x, f32 y); + + //! Get texture transformation translation + /** \param x returns offset on x axis + \param y returns offset on y axis */ + void getTextureTranslate(f32 &x, f32 &y) const; + + //! Set texture transformation translation, using a transposed representation + /** Doesn't clear other elements than those affected. + \param x Offset on x axis + \param y Offset on y axis + \return Altered matrix */ + CMatrix4 &setTextureTranslateTransposed(f32 x, f32 y); + + //! Set texture transformation scale + /** Doesn't clear other elements than those affected. + \param sx Scale factor on x axis + \param sy Scale factor on y axis + \return Altered matrix. */ + CMatrix4 &setTextureScale(f32 sx, f32 sy); + + //! Get texture transformation scale + /** \param sx Returns x axis scale factor + \param sy Returns y axis scale factor */ + void getTextureScale(f32 &sx, f32 &sy) const; + + //! Set texture transformation scale, and recenter at (0.5,0.5) + /** Doesn't clear other elements than those affected. + \param sx Scale factor on x axis + \param sy Scale factor on y axis + \return Altered matrix. */ + CMatrix4 &setTextureScaleCenter(f32 sx, f32 sy); + + //! Sets all matrix data members at once + CMatrix4 &setM(const T *data); + + //! Sets if the matrix is definitely identity matrix + void setDefinitelyIdentityMatrix(bool isDefinitelyIdentityMatrix); + + //! Gets if the matrix is definitely identity matrix + bool getDefinitelyIdentityMatrix() const; + + //! Compare two matrices using the equal method + bool equals(const core::CMatrix4 &other, const T tolerance = (T)ROUNDING_ERROR_f64) const; + +private: + //! Matrix data, stored in row-major order + T M[16]; +#if defined(USE_MATRIX_TEST) + //! Flag is this matrix is identity matrix + mutable u32 definitelyIdentityMatrix; +#endif +}; + +// Default constructor +template +inline CMatrix4::CMatrix4(eConstructor constructor) +#if defined(USE_MATRIX_TEST) + : + definitelyIdentityMatrix(BIT_UNTESTED) +#endif +{ + switch (constructor) { + case EM4CONST_NOTHING: + case EM4CONST_COPY: + break; + case EM4CONST_IDENTITY: + case EM4CONST_INVERSE: + default: + makeIdentity(); + break; + } +} + +// Copy constructor +template +inline CMatrix4::CMatrix4(const CMatrix4 &other, eConstructor constructor) +#if defined(USE_MATRIX_TEST) + : + definitelyIdentityMatrix(BIT_UNTESTED) +#endif +{ + switch (constructor) { + case EM4CONST_IDENTITY: + makeIdentity(); + break; + case EM4CONST_NOTHING: + break; + case EM4CONST_COPY: + *this = other; + break; + case EM4CONST_TRANSPOSED: + other.getTransposed(*this); + break; + case EM4CONST_INVERSE: + if (!other.getInverse(*this)) + memset(M, 0, 16 * sizeof(T)); + break; + case EM4CONST_INVERSE_TRANSPOSED: + if (!other.getInverse(*this)) + memset(M, 0, 16 * sizeof(T)); + else + *this = getTransposed(); + break; + } +} + +//! Add another matrix. +template +inline CMatrix4 CMatrix4::operator+(const CMatrix4 &other) const +{ + CMatrix4 temp(EM4CONST_NOTHING); + + temp[0] = M[0] + other[0]; + temp[1] = M[1] + other[1]; + temp[2] = M[2] + other[2]; + temp[3] = M[3] + other[3]; + temp[4] = M[4] + other[4]; + temp[5] = M[5] + other[5]; + temp[6] = M[6] + other[6]; + temp[7] = M[7] + other[7]; + temp[8] = M[8] + other[8]; + temp[9] = M[9] + other[9]; + temp[10] = M[10] + other[10]; + temp[11] = M[11] + other[11]; + temp[12] = M[12] + other[12]; + temp[13] = M[13] + other[13]; + temp[14] = M[14] + other[14]; + temp[15] = M[15] + other[15]; + + return temp; +} + +//! Add another matrix. +template +inline CMatrix4 &CMatrix4::operator+=(const CMatrix4 &other) +{ + M[0] += other[0]; + M[1] += other[1]; + M[2] += other[2]; + M[3] += other[3]; + M[4] += other[4]; + M[5] += other[5]; + M[6] += other[6]; + M[7] += other[7]; + M[8] += other[8]; + M[9] += other[9]; + M[10] += other[10]; + M[11] += other[11]; + M[12] += other[12]; + M[13] += other[13]; + M[14] += other[14]; + M[15] += other[15]; + + return *this; +} + +//! Subtract another matrix. +template +inline CMatrix4 CMatrix4::operator-(const CMatrix4 &other) const +{ + CMatrix4 temp(EM4CONST_NOTHING); + + temp[0] = M[0] - other[0]; + temp[1] = M[1] - other[1]; + temp[2] = M[2] - other[2]; + temp[3] = M[3] - other[3]; + temp[4] = M[4] - other[4]; + temp[5] = M[5] - other[5]; + temp[6] = M[6] - other[6]; + temp[7] = M[7] - other[7]; + temp[8] = M[8] - other[8]; + temp[9] = M[9] - other[9]; + temp[10] = M[10] - other[10]; + temp[11] = M[11] - other[11]; + temp[12] = M[12] - other[12]; + temp[13] = M[13] - other[13]; + temp[14] = M[14] - other[14]; + temp[15] = M[15] - other[15]; + + return temp; +} + +//! Subtract another matrix. +template +inline CMatrix4 &CMatrix4::operator-=(const CMatrix4 &other) +{ + M[0] -= other[0]; + M[1] -= other[1]; + M[2] -= other[2]; + M[3] -= other[3]; + M[4] -= other[4]; + M[5] -= other[5]; + M[6] -= other[6]; + M[7] -= other[7]; + M[8] -= other[8]; + M[9] -= other[9]; + M[10] -= other[10]; + M[11] -= other[11]; + M[12] -= other[12]; + M[13] -= other[13]; + M[14] -= other[14]; + M[15] -= other[15]; + + return *this; +} + +//! Multiply by scalar. +template +inline CMatrix4 CMatrix4::operator*(const T &scalar) const +{ + CMatrix4 temp(EM4CONST_NOTHING); + + temp[0] = M[0] * scalar; + temp[1] = M[1] * scalar; + temp[2] = M[2] * scalar; + temp[3] = M[3] * scalar; + temp[4] = M[4] * scalar; + temp[5] = M[5] * scalar; + temp[6] = M[6] * scalar; + temp[7] = M[7] * scalar; + temp[8] = M[8] * scalar; + temp[9] = M[9] * scalar; + temp[10] = M[10] * scalar; + temp[11] = M[11] * scalar; + temp[12] = M[12] * scalar; + temp[13] = M[13] * scalar; + temp[14] = M[14] * scalar; + temp[15] = M[15] * scalar; + + return temp; +} + +//! Multiply by scalar. +template +inline CMatrix4 &CMatrix4::operator*=(const T &scalar) +{ + M[0] *= scalar; + M[1] *= scalar; + M[2] *= scalar; + M[3] *= scalar; + M[4] *= scalar; + M[5] *= scalar; + M[6] *= scalar; + M[7] *= scalar; + M[8] *= scalar; + M[9] *= scalar; + M[10] *= scalar; + M[11] *= scalar; + M[12] *= scalar; + M[13] *= scalar; + M[14] *= scalar; + M[15] *= scalar; + + return *this; +} + +//! Multiply by another matrix. +template +inline CMatrix4 &CMatrix4::operator*=(const CMatrix4 &other) +{ +#if defined(USE_MATRIX_TEST) + // do checks on your own in order to avoid copy creation + if (!other.isIdentity()) { + if (this->isIdentity()) { + return (*this = other); + } else { + CMatrix4 temp(*this); + return setbyproduct_nocheck(temp, other); + } + } + return *this; +#else + CMatrix4 temp(*this); + return setbyproduct_nocheck(temp, other); +#endif +} + +//! multiply by another matrix +// set this matrix to the product of two other matrices +// goal is to reduce stack use and copy +template +inline CMatrix4 &CMatrix4::setbyproduct_nocheck(const CMatrix4 &other_a, const CMatrix4 &other_b) +{ + const T *m1 = other_a.M; + const T *m2 = other_b.M; + + M[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]; + M[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3]; + M[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3]; + M[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3]; + + M[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7]; + M[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7]; + M[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7]; + M[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7]; + + M[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11]; + M[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11]; + M[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11]; + M[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11]; + + M[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15]; + M[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15]; + M[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15]; + M[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15]; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +//! multiply by another matrix +// set this matrix to the product of two other matrices +// goal is to reduce stack use and copy +template +inline CMatrix4 &CMatrix4::setbyproduct(const CMatrix4 &other_a, const CMatrix4 &other_b) +{ +#if defined(USE_MATRIX_TEST) + if (other_a.isIdentity()) + return (*this = other_b); + else if (other_b.isIdentity()) + return (*this = other_a); + else + return setbyproduct_nocheck(other_a, other_b); +#else + return setbyproduct_nocheck(other_a, other_b); +#endif +} + +//! multiply by another matrix +template +inline CMatrix4 CMatrix4::operator*(const CMatrix4 &m2) const +{ +#if defined(USE_MATRIX_TEST) + // Testing purpose.. + if (this->isIdentity()) + return m2; + if (m2.isIdentity()) + return *this; +#endif + + CMatrix4 m3(EM4CONST_NOTHING); + + const T *m1 = M; + + m3[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]; + m3[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3]; + m3[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3]; + m3[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3]; + + m3[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7]; + m3[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7]; + m3[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7]; + m3[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7]; + + m3[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11]; + m3[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11]; + m3[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11]; + m3[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11]; + + m3[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15]; + m3[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15]; + m3[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15]; + m3[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15]; + return m3; +} + +template +inline vector3d CMatrix4::getTranslation() const +{ + return vector3d(M[12], M[13], M[14]); +} + +template +inline CMatrix4 &CMatrix4::setTranslation(const vector3d &translation) +{ + M[12] = translation.X; + M[13] = translation.Y; + M[14] = translation.Z; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +template +inline CMatrix4 &CMatrix4::setInverseTranslation(const vector3d &translation) +{ + M[12] = -translation.X; + M[13] = -translation.Y; + M[14] = -translation.Z; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +template +inline CMatrix4 &CMatrix4::setScale(const vector3d &scale) +{ + M[0] = scale.X; + M[5] = scale.Y; + M[10] = scale.Z; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +//! Returns the absolute values of the scales of the matrix. +/** +Note: You only get back original values if the matrix only set the scale. +Otherwise the result is a scale you can use to normalize the matrix axes, +but it's usually no longer what you did set with setScale. +*/ +template +inline vector3d CMatrix4::getScale() const +{ + // See http://www.robertblum.com/articles/2005/02/14/decomposing-matrices + + // Deal with the 0 rotation case first + // Prior to Irrlicht 1.6, we always returned this value. + if (core::iszero(M[1]) && core::iszero(M[2]) && + core::iszero(M[4]) && core::iszero(M[6]) && + core::iszero(M[8]) && core::iszero(M[9])) + return vector3d(M[0], M[5], M[10]); + + // We have to do the full calculation. + return vector3d(sqrtf(M[0] * M[0] + M[1] * M[1] + M[2] * M[2]), + sqrtf(M[4] * M[4] + M[5] * M[5] + M[6] * M[6]), + sqrtf(M[8] * M[8] + M[9] * M[9] + M[10] * M[10])); +} + +template +inline CMatrix4 &CMatrix4::setRotationDegrees(const vector3d &rotation) +{ + return setRotationRadians(rotation * core::DEGTORAD); +} + +template +inline CMatrix4 &CMatrix4::setInverseRotationDegrees(const vector3d &rotation) +{ + return setInverseRotationRadians(rotation * core::DEGTORAD); +} + +template +inline CMatrix4 &CMatrix4::setRotationRadians(const vector3d &rotation) +{ + const f64 cr = cos(rotation.X); + const f64 sr = sin(rotation.X); + const f64 cp = cos(rotation.Y); + const f64 sp = sin(rotation.Y); + const f64 cy = cos(rotation.Z); + const f64 sy = sin(rotation.Z); + + M[0] = (T)(cp * cy); + M[1] = (T)(cp * sy); + M[2] = (T)(-sp); + + const f64 srsp = sr * sp; + const f64 crsp = cr * sp; + + M[4] = (T)(srsp * cy - cr * sy); + M[5] = (T)(srsp * sy + cr * cy); + M[6] = (T)(sr * cp); + + M[8] = (T)(crsp * cy + sr * sy); + M[9] = (T)(crsp * sy - sr * cy); + M[10] = (T)(cr * cp); +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +//! Returns a rotation which (mostly) works in combination with the given scale +/** +This code was originally written by by Chev (assuming no scaling back then, +we can be blamed for all problems added by regarding scale) +*/ +template +inline core::vector3d CMatrix4::getRotationDegrees(const vector3d &scale_) const +{ + const CMatrix4 &mat = *this; + const core::vector3d scale(core::iszero(scale_.X) ? FLT_MAX : scale_.X, core::iszero(scale_.Y) ? FLT_MAX : scale_.Y, core::iszero(scale_.Z) ? FLT_MAX : scale_.Z); + const core::vector3d invScale(core::reciprocal(scale.X), core::reciprocal(scale.Y), core::reciprocal(scale.Z)); + + f64 Y = -asin(core::clamp(mat[2] * invScale.X, -1.0, 1.0)); + const f64 C = cos(Y); + Y *= RADTODEG64; + + f64 rotx, roty, X, Z; + + if (!core::iszero((T)C)) { + const f64 invC = core::reciprocal(C); + rotx = mat[10] * invC * invScale.Z; + roty = mat[6] * invC * invScale.Y; + X = atan2(roty, rotx) * RADTODEG64; + rotx = mat[0] * invC * invScale.X; + roty = mat[1] * invC * invScale.X; + Z = atan2(roty, rotx) * RADTODEG64; + } else { + X = 0.0; + rotx = mat[5] * invScale.Y; + roty = -mat[4] * invScale.Y; + Z = atan2(roty, rotx) * RADTODEG64; + } + + // fix values that get below zero + if (X < 0.0) + X += 360.0; + if (Y < 0.0) + Y += 360.0; + if (Z < 0.0) + Z += 360.0; + + return vector3d((T)X, (T)Y, (T)Z); +} + +//! Returns a rotation that is equivalent to that set by setRotationDegrees(). +template +inline core::vector3d CMatrix4::getRotationDegrees() const +{ + // Note: Using getScale() here make it look like it could do matrix decomposition. + // It can't! It works (or should work) as long as rotation doesn't flip the handedness + // aka scale swapping 1 or 3 axes. (I think we could catch that as well by comparing + // crossproduct of first 2 axes to direction of third axis, but TODO) + // And maybe it should also offer the solution for the simple calculation + // without regarding scaling as Irrlicht did before 1.7 + core::vector3d scale(getScale()); + + // We assume the matrix uses rotations instead of negative scaling 2 axes. + // Otherwise it fails even for some simple cases, like rotating around + // 2 axes by 180° which getScale thinks is a negative scaling. + if (scale.Y < 0 && scale.Z < 0) { + scale.Y = -scale.Y; + scale.Z = -scale.Z; + } else if (scale.X < 0 && scale.Z < 0) { + scale.X = -scale.X; + scale.Z = -scale.Z; + } else if (scale.X < 0 && scale.Y < 0) { + scale.X = -scale.X; + scale.Y = -scale.Y; + } + + return getRotationDegrees(scale); +} + +//! Sets matrix to rotation matrix of inverse angles given as parameters +template +inline CMatrix4 &CMatrix4::setInverseRotationRadians(const vector3d &rotation) +{ + f64 cr = cos(rotation.X); + f64 sr = sin(rotation.X); + f64 cp = cos(rotation.Y); + f64 sp = sin(rotation.Y); + f64 cy = cos(rotation.Z); + f64 sy = sin(rotation.Z); + + M[0] = (T)(cp * cy); + M[4] = (T)(cp * sy); + M[8] = (T)(-sp); + + f64 srsp = sr * sp; + f64 crsp = cr * sp; + + M[1] = (T)(srsp * cy - cr * sy); + M[5] = (T)(srsp * sy + cr * cy); + M[9] = (T)(sr * cp); + + M[2] = (T)(crsp * cy + sr * sy); + M[6] = (T)(crsp * sy - sr * cy); + M[10] = (T)(cr * cp); +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +//! Sets matrix to rotation matrix defined by axis and angle, assuming LH rotation +template +inline CMatrix4 &CMatrix4::setRotationAxisRadians(const T &angle, const vector3d &axis) +{ + const f64 c = cos(angle); + const f64 s = sin(angle); + const f64 t = 1.0 - c; + + const f64 tx = t * axis.X; + const f64 ty = t * axis.Y; + const f64 tz = t * axis.Z; + + const f64 sx = s * axis.X; + const f64 sy = s * axis.Y; + const f64 sz = s * axis.Z; + + M[0] = (T)(tx * axis.X + c); + M[1] = (T)(tx * axis.Y + sz); + M[2] = (T)(tx * axis.Z - sy); + + M[4] = (T)(ty * axis.X - sz); + M[5] = (T)(ty * axis.Y + c); + M[6] = (T)(ty * axis.Z + sx); + + M[8] = (T)(tz * axis.X + sy); + M[9] = (T)(tz * axis.Y - sx); + M[10] = (T)(tz * axis.Z + c); + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +/*! + */ +template +inline CMatrix4 &CMatrix4::makeIdentity() +{ + memset(M, 0, 16 * sizeof(T)); + M[0] = M[5] = M[10] = M[15] = (T)1; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = true; +#endif + return *this; +} + +/* + check identity with epsilon + solve floating range problems.. +*/ +template +inline bool CMatrix4::isIdentity() const +{ +#if defined(USE_MATRIX_TEST) + if (definitelyIdentityMatrix) + return true; +#endif + if (!core::equals(M[12], (T)0) || !core::equals(M[13], (T)0) || !core::equals(M[14], (T)0) || !core::equals(M[15], (T)1)) + return false; + + if (!core::equals(M[0], (T)1) || !core::equals(M[1], (T)0) || !core::equals(M[2], (T)0) || !core::equals(M[3], (T)0)) + return false; + + if (!core::equals(M[4], (T)0) || !core::equals(M[5], (T)1) || !core::equals(M[6], (T)0) || !core::equals(M[7], (T)0)) + return false; + + if (!core::equals(M[8], (T)0) || !core::equals(M[9], (T)0) || !core::equals(M[10], (T)1) || !core::equals(M[11], (T)0)) + return false; +/* + if (!core::equals( M[ 0], (T)1 ) || + !core::equals( M[ 5], (T)1 ) || + !core::equals( M[10], (T)1 ) || + !core::equals( M[15], (T)1 )) + return false; + + for (s32 i=0; i<4; ++i) + for (s32 j=0; j<4; ++j) + if ((j != i) && (!iszero((*this)(i,j)))) + return false; +*/ +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = true; +#endif + return true; +} + +/* Check orthogonality of matrix. */ +template +inline bool CMatrix4::isOrthogonal() const +{ + T dp = M[0] * M[4] + M[1] * M[5] + M[2] * M[6] + M[3] * M[7]; + if (!iszero(dp)) + return false; + dp = M[0] * M[8] + M[1] * M[9] + M[2] * M[10] + M[3] * M[11]; + if (!iszero(dp)) + return false; + dp = M[0] * M[12] + M[1] * M[13] + M[2] * M[14] + M[3] * M[15]; + if (!iszero(dp)) + return false; + dp = M[4] * M[8] + M[5] * M[9] + M[6] * M[10] + M[7] * M[11]; + if (!iszero(dp)) + return false; + dp = M[4] * M[12] + M[5] * M[13] + M[6] * M[14] + M[7] * M[15]; + if (!iszero(dp)) + return false; + dp = M[8] * M[12] + M[9] * M[13] + M[10] * M[14] + M[11] * M[15]; + return (iszero(dp)); +} + +/* + doesn't solve floating range problems.. + but takes care on +/- 0 on translation because we are changing it.. + reducing floating point branches + but it needs the floats in memory.. +*/ +template +inline bool CMatrix4::isIdentity_integer_base() const +{ +#if defined(USE_MATRIX_TEST) + if (definitelyIdentityMatrix) + return true; +#endif + if (IR(M[0]) != F32_VALUE_1) + return false; + if (IR(M[1]) != 0) + return false; + if (IR(M[2]) != 0) + return false; + if (IR(M[3]) != 0) + return false; + + if (IR(M[4]) != 0) + return false; + if (IR(M[5]) != F32_VALUE_1) + return false; + if (IR(M[6]) != 0) + return false; + if (IR(M[7]) != 0) + return false; + + if (IR(M[8]) != 0) + return false; + if (IR(M[9]) != 0) + return false; + if (IR(M[10]) != F32_VALUE_1) + return false; + if (IR(M[11]) != 0) + return false; + + if (IR(M[12]) != 0) + return false; + if (IR(M[13]) != 0) + return false; + if (IR(M[13]) != 0) + return false; + if (IR(M[15]) != F32_VALUE_1) + return false; + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = true; +#endif + return true; +} + +template +inline void CMatrix4::rotateVect(vector3df &vect) const +{ + vector3d tmp(static_cast(vect.X), static_cast(vect.Y), static_cast(vect.Z)); + vect.X = static_cast(tmp.X * M[0] + tmp.Y * M[4] + tmp.Z * M[8]); + vect.Y = static_cast(tmp.X * M[1] + tmp.Y * M[5] + tmp.Z * M[9]); + vect.Z = static_cast(tmp.X * M[2] + tmp.Y * M[6] + tmp.Z * M[10]); +} + +//! An alternate transform vector method, writing into a second vector +template +inline void CMatrix4::rotateVect(core::vector3df &out, const core::vector3df &in) const +{ + out.X = in.X * M[0] + in.Y * M[4] + in.Z * M[8]; + out.Y = in.X * M[1] + in.Y * M[5] + in.Z * M[9]; + out.Z = in.X * M[2] + in.Y * M[6] + in.Z * M[10]; +} + +//! An alternate transform vector method, writing into an array of 3 floats +template +inline void CMatrix4::rotateVect(T *out, const core::vector3df &in) const +{ + out[0] = in.X * M[0] + in.Y * M[4] + in.Z * M[8]; + out[1] = in.X * M[1] + in.Y * M[5] + in.Z * M[9]; + out[2] = in.X * M[2] + in.Y * M[6] + in.Z * M[10]; +} + +template +inline void CMatrix4::inverseRotateVect(vector3df &vect) const +{ + vector3d tmp(static_cast(vect.X), static_cast(vect.Y), static_cast(vect.Z)); + vect.X = static_cast(tmp.X * M[0] + tmp.Y * M[1] + tmp.Z * M[2]); + vect.Y = static_cast(tmp.X * M[4] + tmp.Y * M[5] + tmp.Z * M[6]); + vect.Z = static_cast(tmp.X * M[8] + tmp.Y * M[9] + tmp.Z * M[10]); +} + +template +inline void CMatrix4::transformVect(vector3df &vect) const +{ + T vector[3]; + + vector[0] = vect.X * M[0] + vect.Y * M[4] + vect.Z * M[8] + M[12]; + vector[1] = vect.X * M[1] + vect.Y * M[5] + vect.Z * M[9] + M[13]; + vector[2] = vect.X * M[2] + vect.Y * M[6] + vect.Z * M[10] + M[14]; + + vect.X = static_cast(vector[0]); + vect.Y = static_cast(vector[1]); + vect.Z = static_cast(vector[2]); +} + +template +inline void CMatrix4::transformVect(vector3df &out, const vector3df &in) const +{ + out.X = in.X * M[0] + in.Y * M[4] + in.Z * M[8] + M[12]; + out.Y = in.X * M[1] + in.Y * M[5] + in.Z * M[9] + M[13]; + out.Z = in.X * M[2] + in.Y * M[6] + in.Z * M[10] + M[14]; +} + +template +inline void CMatrix4::transformVect(T *out, const core::vector3df &in) const +{ + out[0] = in.X * M[0] + in.Y * M[4] + in.Z * M[8] + M[12]; + out[1] = in.X * M[1] + in.Y * M[5] + in.Z * M[9] + M[13]; + out[2] = in.X * M[2] + in.Y * M[6] + in.Z * M[10] + M[14]; + out[3] = in.X * M[3] + in.Y * M[7] + in.Z * M[11] + M[15]; +} + +template +inline void CMatrix4::transformVec3(T *out, const T *in) const +{ + out[0] = in[0] * M[0] + in[1] * M[4] + in[2] * M[8] + M[12]; + out[1] = in[0] * M[1] + in[1] * M[5] + in[2] * M[9] + M[13]; + out[2] = in[0] * M[2] + in[1] * M[6] + in[2] * M[10] + M[14]; +} + +template +inline void CMatrix4::transformVec4(T *out, const T *in) const +{ + out[0] = in[0] * M[0] + in[1] * M[4] + in[2] * M[8] + in[3] * M[12]; + out[1] = in[0] * M[1] + in[1] * M[5] + in[2] * M[9] + in[3] * M[13]; + out[2] = in[0] * M[2] + in[1] * M[6] + in[2] * M[10] + in[3] * M[14]; + out[3] = in[0] * M[3] + in[1] * M[7] + in[2] * M[11] + in[3] * M[15]; +} + +//! Transforms a plane by this matrix +template +inline void CMatrix4::transformPlane(core::plane3d &plane) const +{ + vector3df member; + // Transform the plane member point, i.e. rotate, translate and scale it. + transformVect(member, plane.getMemberPoint()); + + // Transform the normal by the transposed inverse of the matrix + CMatrix4 transposedInverse(*this, EM4CONST_INVERSE_TRANSPOSED); + vector3df normal = plane.Normal; + transposedInverse.rotateVect(normal); + plane.setPlane(member, normal.normalize()); +} + +//! Transforms a plane by this matrix +template +inline void CMatrix4::transformPlane(const core::plane3d &in, core::plane3d &out) const +{ + out = in; + transformPlane(out); +} + +//! Transforms a axis aligned bounding box more accurately than transformBox() +template +inline void CMatrix4::transformBoxEx(core::aabbox3d &box) const +{ +#if defined(USE_MATRIX_TEST) + if (isIdentity()) + return; +#endif + + const f32 Amin[3] = {box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z}; + const f32 Amax[3] = {box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z}; + + f32 Bmin[3]; + f32 Bmax[3]; + + Bmin[0] = Bmax[0] = M[12]; + Bmin[1] = Bmax[1] = M[13]; + Bmin[2] = Bmax[2] = M[14]; + + const CMatrix4 &m = *this; + + for (u32 i = 0; i < 3; ++i) { + for (u32 j = 0; j < 3; ++j) { + const f32 a = m(j, i) * Amin[j]; + const f32 b = m(j, i) * Amax[j]; + + if (a < b) { + Bmin[i] += a; + Bmax[i] += b; + } else { + Bmin[i] += b; + Bmax[i] += a; + } + } + } + + box.MinEdge.X = Bmin[0]; + box.MinEdge.Y = Bmin[1]; + box.MinEdge.Z = Bmin[2]; + + box.MaxEdge.X = Bmax[0]; + box.MaxEdge.Y = Bmax[1]; + box.MaxEdge.Z = Bmax[2]; +} + +//! Multiplies this matrix by a 1x4 matrix +template +inline void CMatrix4::multiplyWith1x4Matrix(T *matrix) const +{ + /* + 0 1 2 3 + 4 5 6 7 + 8 9 10 11 + 12 13 14 15 + */ + + T mat[4]; + mat[0] = matrix[0]; + mat[1] = matrix[1]; + mat[2] = matrix[2]; + mat[3] = matrix[3]; + + matrix[0] = M[0] * mat[0] + M[4] * mat[1] + M[8] * mat[2] + M[12] * mat[3]; + matrix[1] = M[1] * mat[0] + M[5] * mat[1] + M[9] * mat[2] + M[13] * mat[3]; + matrix[2] = M[2] * mat[0] + M[6] * mat[1] + M[10] * mat[2] + M[14] * mat[3]; + matrix[3] = M[3] * mat[0] + M[7] * mat[1] + M[11] * mat[2] + M[15] * mat[3]; +} + +template +inline void CMatrix4::inverseTranslateVect(vector3df &vect) const +{ + vect.X = vect.X - M[12]; + vect.Y = vect.Y - M[13]; + vect.Z = vect.Z - M[14]; +} + +template +inline void CMatrix4::translateVect(vector3df &vect) const +{ + vect.X = vect.X + M[12]; + vect.Y = vect.Y + M[13]; + vect.Z = vect.Z + M[14]; +} + +template +inline bool CMatrix4::getInverse(CMatrix4 &out) const +{ + /// Calculates the inverse of this Matrix + /// The inverse is calculated using Cramers rule. + /// If no inverse exists then 'false' is returned. + +#if defined(USE_MATRIX_TEST) + if (this->isIdentity()) { + out = *this; + return true; + } +#endif + const CMatrix4 &m = *this; + + f32 d = (m[0] * m[5] - m[1] * m[4]) * (m[10] * m[15] - m[11] * m[14]) - + (m[0] * m[6] - m[2] * m[4]) * (m[9] * m[15] - m[11] * m[13]) + + (m[0] * m[7] - m[3] * m[4]) * (m[9] * m[14] - m[10] * m[13]) + + (m[1] * m[6] - m[2] * m[5]) * (m[8] * m[15] - m[11] * m[12]) - + (m[1] * m[7] - m[3] * m[5]) * (m[8] * m[14] - m[10] * m[12]) + + (m[2] * m[7] - m[3] * m[6]) * (m[8] * m[13] - m[9] * m[12]); + + if (core::iszero(d, FLT_MIN)) + return false; + + d = core::reciprocal(d); + + out[0] = d * (m[5] * (m[10] * m[15] - m[11] * m[14]) + + m[6] * (m[11] * m[13] - m[9] * m[15]) + + m[7] * (m[9] * m[14] - m[10] * m[13])); + out[1] = d * (m[9] * (m[2] * m[15] - m[3] * m[14]) + + m[10] * (m[3] * m[13] - m[1] * m[15]) + + m[11] * (m[1] * m[14] - m[2] * m[13])); + out[2] = d * (m[13] * (m[2] * m[7] - m[3] * m[6]) + + m[14] * (m[3] * m[5] - m[1] * m[7]) + + m[15] * (m[1] * m[6] - m[2] * m[5])); + out[3] = d * (m[1] * (m[7] * m[10] - m[6] * m[11]) + + m[2] * (m[5] * m[11] - m[7] * m[9]) + + m[3] * (m[6] * m[9] - m[5] * m[10])); + out[4] = d * (m[6] * (m[8] * m[15] - m[11] * m[12]) + + m[7] * (m[10] * m[12] - m[8] * m[14]) + + m[4] * (m[11] * m[14] - m[10] * m[15])); + out[5] = d * (m[10] * (m[0] * m[15] - m[3] * m[12]) + + m[11] * (m[2] * m[12] - m[0] * m[14]) + + m[8] * (m[3] * m[14] - m[2] * m[15])); + out[6] = d * (m[14] * (m[0] * m[7] - m[3] * m[4]) + + m[15] * (m[2] * m[4] - m[0] * m[6]) + + m[12] * (m[3] * m[6] - m[2] * m[7])); + out[7] = d * (m[2] * (m[7] * m[8] - m[4] * m[11]) + + m[3] * (m[4] * m[10] - m[6] * m[8]) + + m[0] * (m[6] * m[11] - m[7] * m[10])); + out[8] = d * (m[7] * (m[8] * m[13] - m[9] * m[12]) + + m[4] * (m[9] * m[15] - m[11] * m[13]) + + m[5] * (m[11] * m[12] - m[8] * m[15])); + out[9] = d * (m[11] * (m[0] * m[13] - m[1] * m[12]) + + m[8] * (m[1] * m[15] - m[3] * m[13]) + + m[9] * (m[3] * m[12] - m[0] * m[15])); + out[10] = d * (m[15] * (m[0] * m[5] - m[1] * m[4]) + + m[12] * (m[1] * m[7] - m[3] * m[5]) + + m[13] * (m[3] * m[4] - m[0] * m[7])); + out[11] = d * (m[3] * (m[5] * m[8] - m[4] * m[9]) + + m[0] * (m[7] * m[9] - m[5] * m[11]) + + m[1] * (m[4] * m[11] - m[7] * m[8])); + out[12] = d * (m[4] * (m[10] * m[13] - m[9] * m[14]) + + m[5] * (m[8] * m[14] - m[10] * m[12]) + + m[6] * (m[9] * m[12] - m[8] * m[13])); + out[13] = d * (m[8] * (m[2] * m[13] - m[1] * m[14]) + + m[9] * (m[0] * m[14] - m[2] * m[12]) + + m[10] * (m[1] * m[12] - m[0] * m[13])); + out[14] = d * (m[12] * (m[2] * m[5] - m[1] * m[6]) + + m[13] * (m[0] * m[6] - m[2] * m[4]) + + m[14] * (m[1] * m[4] - m[0] * m[5])); + out[15] = d * (m[0] * (m[5] * m[10] - m[6] * m[9]) + + m[1] * (m[6] * m[8] - m[4] * m[10]) + + m[2] * (m[4] * m[9] - m[5] * m[8])); + +#if defined(USE_MATRIX_TEST) + out.definitelyIdentityMatrix = definitelyIdentityMatrix; +#endif + return true; +} + +//! Inverts a primitive matrix which only contains a translation and a rotation +//! \param out: where result matrix is written to. +template +inline bool CMatrix4::getInversePrimitive(CMatrix4 &out) const +{ + out.M[0] = M[0]; + out.M[1] = M[4]; + out.M[2] = M[8]; + out.M[3] = 0; + + out.M[4] = M[1]; + out.M[5] = M[5]; + out.M[6] = M[9]; + out.M[7] = 0; + + out.M[8] = M[2]; + out.M[9] = M[6]; + out.M[10] = M[10]; + out.M[11] = 0; + + out.M[12] = (T) - (M[12] * M[0] + M[13] * M[1] + M[14] * M[2]); + out.M[13] = (T) - (M[12] * M[4] + M[13] * M[5] + M[14] * M[6]); + out.M[14] = (T) - (M[12] * M[8] + M[13] * M[9] + M[14] * M[10]); + out.M[15] = 1; + +#if defined(USE_MATRIX_TEST) + out.definitelyIdentityMatrix = definitelyIdentityMatrix; +#endif + return true; +} + +/*! + */ +template +inline bool CMatrix4::makeInverse() +{ +#if defined(USE_MATRIX_TEST) + if (definitelyIdentityMatrix) + return true; +#endif + CMatrix4 temp(EM4CONST_NOTHING); + + if (getInverse(temp)) { + *this = temp; + return true; + } + + return false; +} + +template +inline CMatrix4 &CMatrix4::operator=(const T &scalar) +{ + for (s32 i = 0; i < 16; ++i) + M[i] = scalar; + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a right-handed perspective projection matrix based on a field of view +template +inline CMatrix4 &CMatrix4::buildProjectionMatrixPerspectiveFovRH( + f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero) +{ + const f64 h = reciprocal(tan(fieldOfViewRadians * 0.5)); + _IRR_DEBUG_BREAK_IF(aspectRatio == 0.f); // divide by zero + const T w = static_cast(h / aspectRatio); + + _IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero + M[0] = w; + M[1] = 0; + M[2] = 0; + M[3] = 0; + + M[4] = 0; + M[5] = (T)h; + M[6] = 0; + M[7] = 0; + + M[8] = 0; + M[9] = 0; + // M[10] + M[11] = -1; + + M[12] = 0; + M[13] = 0; + // M[14] + M[15] = 0; + + if (zClipFromZero) { // DirectX version + M[10] = (T)(zFar / (zNear - zFar)); + M[14] = (T)(zNear * zFar / (zNear - zFar)); + } else // OpenGL version + { + M[10] = (T)((zFar + zNear) / (zNear - zFar)); + M[14] = (T)(2.0f * zNear * zFar / (zNear - zFar)); + } + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a left-handed perspective projection matrix based on a field of view +template +inline CMatrix4 &CMatrix4::buildProjectionMatrixPerspectiveFovLH( + f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero) +{ + const f64 h = reciprocal(tan(fieldOfViewRadians * 0.5)); + _IRR_DEBUG_BREAK_IF(aspectRatio == 0.f); // divide by zero + const T w = static_cast(h / aspectRatio); + + _IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero + M[0] = w; + M[1] = 0; + M[2] = 0; + M[3] = 0; + + M[4] = 0; + M[5] = (T)h; + M[6] = 0; + M[7] = 0; + + M[8] = 0; + M[9] = 0; + // M[10] + M[11] = 1; + + M[12] = 0; + M[13] = 0; + // M[14] + M[15] = 0; + + if (zClipFromZero) { // DirectX version + M[10] = (T)(zFar / (zFar - zNear)); + M[14] = (T)(-zNear * zFar / (zFar - zNear)); + } else // OpenGL version + { + M[10] = (T)((zFar + zNear) / (zFar - zNear)); + M[14] = (T)(2.0f * zNear * zFar / (zNear - zFar)); + } + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a left-handed perspective projection matrix based on a field of view, with far plane culling at infinity +template +inline CMatrix4 &CMatrix4::buildProjectionMatrixPerspectiveFovInfinityLH( + f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 epsilon) +{ + const f64 h = reciprocal(tan(fieldOfViewRadians * 0.5)); + _IRR_DEBUG_BREAK_IF(aspectRatio == 0.f); // divide by zero + const T w = static_cast(h / aspectRatio); + + M[0] = w; + M[1] = 0; + M[2] = 0; + M[3] = 0; + + M[4] = 0; + M[5] = (T)h; + M[6] = 0; + M[7] = 0; + + M[8] = 0; + M[9] = 0; + M[10] = (T)(1.f - epsilon); + M[11] = 1; + + M[12] = 0; + M[13] = 0; + M[14] = (T)(zNear * (epsilon - 1.f)); + M[15] = 0; + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a left-handed orthogonal projection matrix. +template +inline CMatrix4 &CMatrix4::buildProjectionMatrixOrthoLH( + f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero) +{ + _IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero + M[0] = (T)(2 / widthOfViewVolume); + M[1] = 0; + M[2] = 0; + M[3] = 0; + + M[4] = 0; + M[5] = (T)(2 / heightOfViewVolume); + M[6] = 0; + M[7] = 0; + + M[8] = 0; + M[9] = 0; + // M[10] + M[11] = 0; + + M[12] = 0; + M[13] = 0; + // M[14] + M[15] = 1; + + if (zClipFromZero) { + M[10] = (T)(1 / (zFar - zNear)); + M[14] = (T)(zNear / (zNear - zFar)); + } else { + M[10] = (T)(2 / (zFar - zNear)); + M[14] = (T) - (zFar + zNear) / (zFar - zNear); + } + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a right-handed orthogonal projection matrix. +template +inline CMatrix4 &CMatrix4::buildProjectionMatrixOrthoRH( + f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero) +{ + _IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero + M[0] = (T)(2 / widthOfViewVolume); + M[1] = 0; + M[2] = 0; + M[3] = 0; + + M[4] = 0; + M[5] = (T)(2 / heightOfViewVolume); + M[6] = 0; + M[7] = 0; + + M[8] = 0; + M[9] = 0; + // M[10] + M[11] = 0; + + M[12] = 0; + M[13] = 0; + // M[14] + M[15] = 1; + + if (zClipFromZero) { + M[10] = (T)(1 / (zNear - zFar)); + M[14] = (T)(zNear / (zNear - zFar)); + } else { + M[10] = (T)(2 / (zNear - zFar)); + M[14] = (T) - (zFar + zNear) / (zFar - zNear); + } + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a right-handed perspective projection matrix. +template +inline CMatrix4 &CMatrix4::buildProjectionMatrixPerspectiveRH( + f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero) +{ + _IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero + M[0] = (T)(2 * zNear / widthOfViewVolume); + M[1] = 0; + M[2] = 0; + M[3] = 0; + + M[4] = 0; + M[5] = (T)(2 * zNear / heightOfViewVolume); + M[6] = 0; + M[7] = 0; + + M[8] = 0; + M[9] = 0; + // M[10] + M[11] = -1; + + M[12] = 0; + M[13] = 0; + // M[14] + M[15] = 0; + + if (zClipFromZero) { // DirectX version + M[10] = (T)(zFar / (zNear - zFar)); + M[14] = (T)(zNear * zFar / (zNear - zFar)); + } else // OpenGL version + { + M[10] = (T)((zFar + zNear) / (zNear - zFar)); + M[14] = (T)(2.0f * zNear * zFar / (zNear - zFar)); + } + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a left-handed perspective projection matrix. +template +inline CMatrix4 &CMatrix4::buildProjectionMatrixPerspectiveLH( + f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero) +{ + _IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero + _IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero + M[0] = (T)(2 * zNear / widthOfViewVolume); + M[1] = 0; + M[2] = 0; + M[3] = 0; + + M[4] = 0; + M[5] = (T)(2 * zNear / heightOfViewVolume); + M[6] = 0; + M[7] = 0; + + M[8] = 0; + M[9] = 0; + // M[10] + M[11] = 1; + + M[12] = 0; + M[13] = 0; + // M[14] = (T)(zNear*zFar/(zNear-zFar)); + M[15] = 0; + + if (zClipFromZero) { // DirectX version + M[10] = (T)(zFar / (zFar - zNear)); + M[14] = (T)(zNear * zFar / (zNear - zFar)); + } else // OpenGL version + { + M[10] = (T)((zFar + zNear) / (zFar - zNear)); + M[14] = (T)(2.0f * zNear * zFar / (zNear - zFar)); + } + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a matrix that flattens geometry into a plane. +template +inline CMatrix4 &CMatrix4::buildShadowMatrix(const core::vector3df &light, core::plane3df plane, f32 point) +{ + plane.Normal.normalize(); + const f32 d = plane.Normal.dotProduct(light); + + M[0] = (T)(-plane.Normal.X * light.X + d); + M[1] = (T)(-plane.Normal.X * light.Y); + M[2] = (T)(-plane.Normal.X * light.Z); + M[3] = (T)(-plane.Normal.X * point); + + M[4] = (T)(-plane.Normal.Y * light.X); + M[5] = (T)(-plane.Normal.Y * light.Y + d); + M[6] = (T)(-plane.Normal.Y * light.Z); + M[7] = (T)(-plane.Normal.Y * point); + + M[8] = (T)(-plane.Normal.Z * light.X); + M[9] = (T)(-plane.Normal.Z * light.Y); + M[10] = (T)(-plane.Normal.Z * light.Z + d); + M[11] = (T)(-plane.Normal.Z * point); + + M[12] = (T)(-plane.D * light.X); + M[13] = (T)(-plane.D * light.Y); + M[14] = (T)(-plane.D * light.Z); + M[15] = (T)(-plane.D * point + d); +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a left-handed look-at matrix. +template +inline CMatrix4 &CMatrix4::buildCameraLookAtMatrixLH( + const vector3df &position, + const vector3df &target, + const vector3df &upVector) +{ + vector3df zaxis = target - position; + zaxis.normalize(); + + vector3df xaxis = upVector.crossProduct(zaxis); + xaxis.normalize(); + + vector3df yaxis = zaxis.crossProduct(xaxis); + + M[0] = (T)xaxis.X; + M[1] = (T)yaxis.X; + M[2] = (T)zaxis.X; + M[3] = 0; + + M[4] = (T)xaxis.Y; + M[5] = (T)yaxis.Y; + M[6] = (T)zaxis.Y; + M[7] = 0; + + M[8] = (T)xaxis.Z; + M[9] = (T)yaxis.Z; + M[10] = (T)zaxis.Z; + M[11] = 0; + + M[12] = (T)-xaxis.dotProduct(position); + M[13] = (T)-yaxis.dotProduct(position); + M[14] = (T)-zaxis.dotProduct(position); + M[15] = 1; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// Builds a right-handed look-at matrix. +template +inline CMatrix4 &CMatrix4::buildCameraLookAtMatrixRH( + const vector3df &position, + const vector3df &target, + const vector3df &upVector) +{ + vector3df zaxis = position - target; + zaxis.normalize(); + + vector3df xaxis = upVector.crossProduct(zaxis); + xaxis.normalize(); + + vector3df yaxis = zaxis.crossProduct(xaxis); + + M[0] = (T)xaxis.X; + M[1] = (T)yaxis.X; + M[2] = (T)zaxis.X; + M[3] = 0; + + M[4] = (T)xaxis.Y; + M[5] = (T)yaxis.Y; + M[6] = (T)zaxis.Y; + M[7] = 0; + + M[8] = (T)xaxis.Z; + M[9] = (T)yaxis.Z; + M[10] = (T)zaxis.Z; + M[11] = 0; + + M[12] = (T)-xaxis.dotProduct(position); + M[13] = (T)-yaxis.dotProduct(position); + M[14] = (T)-zaxis.dotProduct(position); + M[15] = 1; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// creates a new matrix as interpolated matrix from this and the passed one. +template +inline CMatrix4 CMatrix4::interpolate(const core::CMatrix4 &b, f32 time) const +{ + CMatrix4 mat(EM4CONST_NOTHING); + + for (u32 i = 0; i < 16; i += 4) { + mat.M[i + 0] = (T)(M[i + 0] + (b.M[i + 0] - M[i + 0]) * time); + mat.M[i + 1] = (T)(M[i + 1] + (b.M[i + 1] - M[i + 1]) * time); + mat.M[i + 2] = (T)(M[i + 2] + (b.M[i + 2] - M[i + 2]) * time); + mat.M[i + 3] = (T)(M[i + 3] + (b.M[i + 3] - M[i + 3]) * time); + } + return mat; +} + +// returns transposed matrix +template +inline CMatrix4 CMatrix4::getTransposed() const +{ + CMatrix4 t(EM4CONST_NOTHING); + getTransposed(t); + return t; +} + +// returns transposed matrix +template +inline void CMatrix4::getTransposed(CMatrix4 &o) const +{ + o[0] = M[0]; + o[1] = M[4]; + o[2] = M[8]; + o[3] = M[12]; + + o[4] = M[1]; + o[5] = M[5]; + o[6] = M[9]; + o[7] = M[13]; + + o[8] = M[2]; + o[9] = M[6]; + o[10] = M[10]; + o[11] = M[14]; + + o[12] = M[3]; + o[13] = M[7]; + o[14] = M[11]; + o[15] = M[15]; +#if defined(USE_MATRIX_TEST) + o.definitelyIdentityMatrix = definitelyIdentityMatrix; +#endif +} + +// used to scale <-1,-1><1,1> to viewport +template +inline CMatrix4 &CMatrix4::buildNDCToDCMatrix(const core::rect &viewport, f32 zScale) +{ + const f32 scaleX = (viewport.getWidth() - 0.75f) * 0.5f; + const f32 scaleY = -(viewport.getHeight() - 0.75f) * 0.5f; + + const f32 dx = -0.5f + ((viewport.UpperLeftCorner.X + viewport.LowerRightCorner.X) * 0.5f); + const f32 dy = -0.5f + ((viewport.UpperLeftCorner.Y + viewport.LowerRightCorner.Y) * 0.5f); + + makeIdentity(); + M[12] = (T)dx; + M[13] = (T)dy; + return setScale(core::vector3d((T)scaleX, (T)scaleY, (T)zScale)); +} + +//! Builds a matrix that rotates from one vector to another +/** \param from: vector to rotate from +\param to: vector to rotate to + + http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix/index.htm + */ +template +inline CMatrix4 &CMatrix4::buildRotateFromTo(const core::vector3df &from, const core::vector3df &to) +{ + // unit vectors + core::vector3df f(from); + core::vector3df t(to); + f.normalize(); + t.normalize(); + + // axis multiplication by sin + core::vector3df vs(t.crossProduct(f)); + + // axis of rotation + core::vector3df v(vs); + v.normalize(); + + // cosine angle + T ca = f.dotProduct(t); + + core::vector3df vt(v * (1 - ca)); + + M[0] = vt.X * v.X + ca; + M[5] = vt.Y * v.Y + ca; + M[10] = vt.Z * v.Z + ca; + + vt.X *= v.Y; + vt.Z *= v.X; + vt.Y *= v.Z; + + M[1] = vt.X - vs.Z; + M[2] = vt.Z + vs.Y; + M[3] = 0; + + M[4] = vt.X + vs.Z; + M[6] = vt.Y - vs.X; + M[7] = 0; + + M[8] = vt.Z - vs.Y; + M[9] = vt.Y + vs.X; + M[11] = 0; + + M[12] = 0; + M[13] = 0; + M[14] = 0; + M[15] = 1; + + return *this; +} + +//! Builds a matrix which rotates a source vector to a look vector over an arbitrary axis +/** \param camPos: viewer position in world coord +\param center: object position in world-coord, rotation pivot +\param translation: object final translation from center +\param axis: axis to rotate about +\param from: source vector to rotate from + */ +template +inline void CMatrix4::buildAxisAlignedBillboard( + const core::vector3df &camPos, + const core::vector3df ¢er, + const core::vector3df &translation, + const core::vector3df &axis, + const core::vector3df &from) +{ + // axis of rotation + core::vector3df up = axis; + up.normalize(); + const core::vector3df forward = (camPos - center).normalize(); + const core::vector3df right = up.crossProduct(forward).normalize(); + + // correct look vector + const core::vector3df look = right.crossProduct(up); + + // rotate from to + // axis multiplication by sin + const core::vector3df vs = look.crossProduct(from); + + // cosine angle + const f32 ca = from.dotProduct(look); + + core::vector3df vt(up * (1.f - ca)); + + M[0] = static_cast(vt.X * up.X + ca); + M[5] = static_cast(vt.Y * up.Y + ca); + M[10] = static_cast(vt.Z * up.Z + ca); + + vt.X *= up.Y; + vt.Z *= up.X; + vt.Y *= up.Z; + + M[1] = static_cast(vt.X - vs.Z); + M[2] = static_cast(vt.Z + vs.Y); + M[3] = 0; + + M[4] = static_cast(vt.X + vs.Z); + M[6] = static_cast(vt.Y - vs.X); + M[7] = 0; + + M[8] = static_cast(vt.Z - vs.Y); + M[9] = static_cast(vt.Y + vs.X); + M[11] = 0; + + setRotationCenter(center, translation); +} + +//! Builds a combined matrix which translate to a center before rotation and translate afterward +template +inline void CMatrix4::setRotationCenter(const core::vector3df ¢er, const core::vector3df &translation) +{ + M[12] = -M[0] * center.X - M[4] * center.Y - M[8] * center.Z + (center.X - translation.X); + M[13] = -M[1] * center.X - M[5] * center.Y - M[9] * center.Z + (center.Y - translation.Y); + M[14] = -M[2] * center.X - M[6] * center.Y - M[10] * center.Z + (center.Z - translation.Z); + M[15] = (T)1.0; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif +} + +/*! + Generate texture coordinates as linear functions so that: + u = Ux*x + Uy*y + Uz*z + Uw + v = Vx*x + Vy*y + Vz*z + Vw + The matrix M for this case is: + Ux Vx 0 0 + Uy Vy 0 0 + Uz Vz 0 0 + Uw Vw 0 0 +*/ + +template +inline CMatrix4 &CMatrix4::buildTextureTransform(f32 rotateRad, + const core::vector2df &rotatecenter, + const core::vector2df &translate, + const core::vector2df &scale) +{ + const f32 c = cosf(rotateRad); + const f32 s = sinf(rotateRad); + + M[0] = (T)(c * scale.X); + M[1] = (T)(s * scale.Y); + M[2] = 0; + M[3] = 0; + + M[4] = (T)(-s * scale.X); + M[5] = (T)(c * scale.Y); + M[6] = 0; + M[7] = 0; + + M[8] = (T)(c * scale.X * rotatecenter.X + -s * rotatecenter.Y + translate.X); + M[9] = (T)(s * scale.Y * rotatecenter.X + c * rotatecenter.Y + translate.Y); + M[10] = 1; + M[11] = 0; + + M[12] = 0; + M[13] = 0; + M[14] = 0; + M[15] = 1; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// rotate about z axis, center ( 0.5, 0.5 ) +template +inline CMatrix4 &CMatrix4::setTextureRotationCenter(f32 rotateRad) +{ + const f32 c = cosf(rotateRad); + const f32 s = sinf(rotateRad); + M[0] = (T)c; + M[1] = (T)s; + + M[4] = (T)-s; + M[5] = (T)c; + + M[8] = (T)(0.5f * (s - c) + 0.5f); + M[9] = (T)(-0.5f * (s + c) + 0.5f); + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = definitelyIdentityMatrix && (rotateRad == 0.0f); +#endif + return *this; +} + +template +inline CMatrix4 &CMatrix4::setTextureTranslate(f32 x, f32 y) +{ + M[8] = (T)x; + M[9] = (T)y; + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = definitelyIdentityMatrix && (x == 0.0f) && (y == 0.0f); +#endif + return *this; +} + +template +inline void CMatrix4::getTextureTranslate(f32 &x, f32 &y) const +{ + x = (f32)M[8]; + y = (f32)M[9]; +} + +template +inline CMatrix4 &CMatrix4::setTextureTranslateTransposed(f32 x, f32 y) +{ + M[2] = (T)x; + M[6] = (T)y; + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = definitelyIdentityMatrix && (x == 0.0f) && (y == 0.0f); +#endif + return *this; +} + +template +inline CMatrix4 &CMatrix4::setTextureScale(f32 sx, f32 sy) +{ + M[0] = (T)sx; + M[5] = (T)sy; +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = definitelyIdentityMatrix && (sx == 1.0f) && (sy == 1.0f); +#endif + return *this; +} + +template +inline void CMatrix4::getTextureScale(f32 &sx, f32 &sy) const +{ + sx = (f32)M[0]; + sy = (f32)M[5]; +} + +template +inline CMatrix4 &CMatrix4::setTextureScaleCenter(f32 sx, f32 sy) +{ + M[0] = (T)sx; + M[5] = (T)sy; + M[8] = (T)(0.5f - 0.5f * sx); + M[9] = (T)(0.5f - 0.5f * sy); + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = definitelyIdentityMatrix && (sx == 1.0f) && (sy == 1.0f); +#endif + return *this; +} + +// sets all matrix data members at once +template +inline CMatrix4 &CMatrix4::setM(const T *data) +{ + memcpy(M, data, 16 * sizeof(T)); + +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = false; +#endif + return *this; +} + +// sets if the matrix is definitely identity matrix +template +inline void CMatrix4::setDefinitelyIdentityMatrix(bool isDefinitelyIdentityMatrix) +{ +#if defined(USE_MATRIX_TEST) + definitelyIdentityMatrix = isDefinitelyIdentityMatrix; +#else + (void)isDefinitelyIdentityMatrix; // prevent compiler warning +#endif +} + +// gets if the matrix is definitely identity matrix +template +inline bool CMatrix4::getDefinitelyIdentityMatrix() const +{ +#if defined(USE_MATRIX_TEST) + return definitelyIdentityMatrix; +#else + return false; +#endif +} + +//! Compare two matrices using the equal method +template +inline bool CMatrix4::equals(const core::CMatrix4 &other, const T tolerance) const +{ +#if defined(USE_MATRIX_TEST) + if (definitelyIdentityMatrix && other.definitelyIdentityMatrix) + return true; +#endif + for (s32 i = 0; i < 16; ++i) + if (!core::equals(M[i], other.M[i], tolerance)) + return false; + + return true; +} + +// Multiply by scalar. +template +inline CMatrix4 operator*(const T scalar, const CMatrix4 &mat) +{ + return mat * scalar; +} + +//! Typedef for f32 matrix +typedef CMatrix4 matrix4; + +//! global const identity matrix +IRRLICHT_API extern const matrix4 IdentityMatrix; + +} // end namespace core +} // end namespace irr diff --git a/irr/include/mt_opengl.h b/irr/include/mt_opengl.h new file mode 100755 index 000000000..32d3f1c0a --- /dev/null +++ b/irr/include/mt_opengl.h @@ -0,0 +1,3195 @@ +// This code was generated by scripts/BindingGenerator.lua +// Do not modify it, modify and run the generator instead. + +#pragma once + +#include +#include +#include "IrrCompileConfig.h" // for IRRLICHT_API +#include "irrTypes.h" +#include "IContextManager.h" +#include + +#ifndef APIENTRY + #define APIENTRY KHRONOS_APIENTRY +#endif +#ifndef APIENTRYP + #define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI + #define GLAPI extern +#endif + +class OpenGLProcedures { +private: + // ./glcorearb.h + typedef void GLvoid; + typedef unsigned int GLenum; + typedef khronos_float_t GLfloat; + typedef int GLint; + typedef int GLsizei; + typedef unsigned int GLbitfield; + typedef double GLdouble; + typedef unsigned int GLuint; + typedef unsigned char GLboolean; + typedef khronos_uint8_t GLubyte; + typedef khronos_float_t GLclampf; + typedef double GLclampd; + typedef khronos_ssize_t GLsizeiptr; + typedef khronos_intptr_t GLintptr; + typedef char GLchar; + typedef khronos_int16_t GLshort; + typedef khronos_int8_t GLbyte; + typedef khronos_uint16_t GLushort; + typedef khronos_uint16_t GLhalf; + typedef struct __GLsync *GLsync; + typedef khronos_uint64_t GLuint64; + typedef khronos_int64_t GLint64; + typedef khronos_uint64_t GLuint64EXT; + typedef void *GLeglImageOES; + typedef khronos_int64_t GLint64EXT; + + typedef void *GLeglClientBufferEXT; + // The script will miss this particular typedef thinking it's a PFN, + // so we have to paste it in manually. It's the only such type in OpenGL. + typedef void (APIENTRY *GLDEBUGPROC) + (GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); + + typedef void (APIENTRYP PFNGLCULLFACEPROC_MT) (GLenum mode); + typedef void (APIENTRYP PFNGLFRONTFACEPROC_MT) (GLenum mode); + typedef void (APIENTRYP PFNGLHINTPROC_MT) (GLenum target, GLenum mode); + typedef void (APIENTRYP PFNGLLINEWIDTHPROC_MT) (GLfloat width); + typedef void (APIENTRYP PFNGLPOINTSIZEPROC_MT) (GLfloat size); + typedef void (APIENTRYP PFNGLPOLYGONMODEPROC_MT) (GLenum face, GLenum mode); + typedef void (APIENTRYP PFNGLSCISSORPROC_MT) (GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLTEXPARAMETERFPROC_MT) (GLenum target, GLenum pname, GLfloat param); + typedef void (APIENTRYP PFNGLTEXPARAMETERFVPROC_MT) (GLenum target, GLenum pname, const GLfloat * params); + typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC_MT) (GLenum target, GLenum pname, GLint param); + typedef void (APIENTRYP PFNGLTEXPARAMETERIVPROC_MT) (GLenum target, GLenum pname, const GLint * params); + typedef void (APIENTRYP PFNGLTEXIMAGE1DPROC_MT) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC_MT) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLDRAWBUFFERPROC_MT) (GLenum buf); + typedef void (APIENTRYP PFNGLCLEARPROC_MT) (GLbitfield mask); + typedef void (APIENTRYP PFNGLCLEARCOLORPROC_MT) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + typedef void (APIENTRYP PFNGLCLEARSTENCILPROC_MT) (GLint s); + typedef void (APIENTRYP PFNGLCLEARDEPTHPROC_MT) (GLdouble depth); + typedef void (APIENTRYP PFNGLSTENCILMASKPROC_MT) (GLuint mask); + typedef void (APIENTRYP PFNGLCOLORMASKPROC_MT) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + typedef void (APIENTRYP PFNGLDEPTHMASKPROC_MT) (GLboolean flag); + typedef void (APIENTRYP PFNGLDISABLEPROC_MT) (GLenum cap); + typedef void (APIENTRYP PFNGLENABLEPROC_MT) (GLenum cap); + typedef void (APIENTRYP PFNGLFINISHPROC_MT) ( void); + typedef void (APIENTRYP PFNGLFLUSHPROC_MT) ( void); + typedef void (APIENTRYP PFNGLBLENDFUNCPROC_MT) (GLenum sfactor, GLenum dfactor); + typedef void (APIENTRYP PFNGLLOGICOPPROC_MT) (GLenum opcode); + typedef void (APIENTRYP PFNGLSTENCILFUNCPROC_MT) (GLenum func, GLint ref, GLuint mask); + typedef void (APIENTRYP PFNGLSTENCILOPPROC_MT) (GLenum fail, GLenum zfail, GLenum zpass); + typedef void (APIENTRYP PFNGLDEPTHFUNCPROC_MT) (GLenum func); + typedef void (APIENTRYP PFNGLPIXELSTOREFPROC_MT) (GLenum pname, GLfloat param); + typedef void (APIENTRYP PFNGLPIXELSTOREIPROC_MT) (GLenum pname, GLint param); + typedef void (APIENTRYP PFNGLREADBUFFERPROC_MT) (GLenum src); + typedef void (APIENTRYP PFNGLREADPIXELSPROC_MT) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void * pixels); + typedef void (APIENTRYP PFNGLGETBOOLEANVPROC_MT) (GLenum pname, GLboolean * data); + typedef void (APIENTRYP PFNGLGETDOUBLEVPROC_MT) (GLenum pname, GLdouble * data); + typedef GLenum (APIENTRYP PFNGLGETERRORPROC_MT) ( void); + typedef void (APIENTRYP PFNGLGETFLOATVPROC_MT) (GLenum pname, GLfloat * data); + typedef void (APIENTRYP PFNGLGETINTEGERVPROC_MT) (GLenum pname, GLint * data); + typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC_MT) (GLenum name); + typedef void (APIENTRYP PFNGLGETTEXIMAGEPROC_MT) (GLenum target, GLint level, GLenum format, GLenum type, void * pixels); + typedef void (APIENTRYP PFNGLGETTEXPARAMETERFVPROC_MT) (GLenum target, GLenum pname, GLfloat * params); + typedef void (APIENTRYP PFNGLGETTEXPARAMETERIVPROC_MT) (GLenum target, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERFVPROC_MT) (GLenum target, GLint level, GLenum pname, GLfloat * params); + typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERIVPROC_MT) (GLenum target, GLint level, GLenum pname, GLint * params); + typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC_MT) (GLenum cap); + typedef void (APIENTRYP PFNGLDEPTHRANGEPROC_MT) (GLdouble n, GLdouble f); + typedef void (APIENTRYP PFNGLVIEWPORTPROC_MT) (GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLDRAWARRAYSPROC_MT) (GLenum mode, GLint first, GLsizei count); + typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC_MT) (GLenum mode, GLsizei count, GLenum type, const void * indices); + typedef void (APIENTRYP PFNGLGETPOINTERVPROC_MT) (GLenum pname, void ** params); + typedef void (APIENTRYP PFNGLPOLYGONOFFSETPROC_MT) (GLfloat factor, GLfloat units); + typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DPROC_MT) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); + typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DPROC_MT) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); + typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); + typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLBINDTEXTUREPROC_MT) (GLenum target, GLuint texture); + typedef void (APIENTRYP PFNGLDELETETEXTURESPROC_MT) (GLsizei n, const GLuint * textures); + typedef void (APIENTRYP PFNGLGENTEXTURESPROC_MT) (GLsizei n, GLuint * textures); + typedef GLboolean (APIENTRYP PFNGLISTEXTUREPROC_MT) (GLuint texture); + typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC_MT) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void * indices); + typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC_MT) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC_MT) (GLenum texture); + typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC_MT) (GLfloat value, GLboolean invert); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC_MT) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC_MT) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC_MT) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC_MT) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC_MT) (GLenum target, GLint level, void * img); + typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC_MT) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); + typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC_MT) (GLenum mode, const GLint * first, const GLsizei * count, GLsizei drawcount); + typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC_MT) (GLenum mode, const GLsizei * count, GLenum type, const void *const* indices, GLsizei drawcount); + typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC_MT) (GLenum pname, GLfloat param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC_MT) (GLenum pname, const GLfloat * params); + typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC_MT) (GLenum pname, GLint param); + typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC_MT) (GLenum pname, const GLint * params); + typedef void (APIENTRYP PFNGLBLENDCOLORPROC_MT) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC_MT) (GLenum mode); + typedef void (APIENTRYP PFNGLGENQUERIESPROC_MT) (GLsizei n, GLuint * ids); + typedef void (APIENTRYP PFNGLDELETEQUERIESPROC_MT) (GLsizei n, const GLuint * ids); + typedef GLboolean (APIENTRYP PFNGLISQUERYPROC_MT) (GLuint id); + typedef void (APIENTRYP PFNGLBEGINQUERYPROC_MT) (GLenum target, GLuint id); + typedef void (APIENTRYP PFNGLENDQUERYPROC_MT) (GLenum target); + typedef void (APIENTRYP PFNGLGETQUERYIVPROC_MT) (GLenum target, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC_MT) (GLuint id, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC_MT) (GLuint id, GLenum pname, GLuint * params); + typedef void (APIENTRYP PFNGLBINDBUFFERPROC_MT) (GLenum target, GLuint buffer); + typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC_MT) (GLsizei n, const GLuint * buffers); + typedef void (APIENTRYP PFNGLGENBUFFERSPROC_MT) (GLsizei n, GLuint * buffers); + typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC_MT) (GLuint buffer); + typedef void (APIENTRYP PFNGLBUFFERDATAPROC_MT) (GLenum target, GLsizeiptr size, const void * data, GLenum usage); + typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC_MT) (GLenum target, GLintptr offset, GLsizeiptr size, const void * data); + typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC_MT) (GLenum target, GLintptr offset, GLsizeiptr size, void * data); + typedef void * (APIENTRYP PFNGLMAPBUFFERPROC_MT) (GLenum target, GLenum access); + typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC_MT) (GLenum target); + typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC_MT) (GLenum target, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC_MT) (GLenum target, GLenum pname, void ** params); + typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC_MT) (GLenum modeRGB, GLenum modeAlpha); + typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC_MT) (GLsizei n, const GLenum * bufs); + typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC_MT) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); + typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC_MT) (GLenum face, GLenum func, GLint ref, GLuint mask); + typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC_MT) (GLenum face, GLuint mask); + typedef void (APIENTRYP PFNGLATTACHSHADERPROC_MT) (GLuint program, GLuint shader); + typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC_MT) (GLuint program, GLuint index, const GLchar * name); + typedef void (APIENTRYP PFNGLCOMPILESHADERPROC_MT) (GLuint shader); + typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC_MT) ( void); + typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC_MT) (GLenum type); + typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC_MT) (GLuint program); + typedef void (APIENTRYP PFNGLDELETESHADERPROC_MT) (GLuint shader); + typedef void (APIENTRYP PFNGLDETACHSHADERPROC_MT) (GLuint program, GLuint shader); + typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC_MT) (GLuint index); + typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC_MT) (GLuint index); + typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC_MT) (GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name); + typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC_MT) (GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name); + typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC_MT) (GLuint program, GLsizei maxCount, GLsizei * count, GLuint * shaders); + typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC_MT) (GLuint program, const GLchar * name); + typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC_MT) (GLuint program, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC_MT) (GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog); + typedef void (APIENTRYP PFNGLGETSHADERIVPROC_MT) (GLuint shader, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC_MT) (GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog); + typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC_MT) (GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * source); + typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC_MT) (GLuint program, const GLchar * name); + typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC_MT) (GLuint program, GLint location, GLfloat * params); + typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC_MT) (GLuint program, GLint location, GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC_MT) (GLuint index, GLenum pname, GLdouble * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC_MT) (GLuint index, GLenum pname, GLfloat * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC_MT) (GLuint index, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC_MT) (GLuint index, GLenum pname, void ** pointer); + typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC_MT) (GLuint program); + typedef GLboolean (APIENTRYP PFNGLISSHADERPROC_MT) (GLuint shader); + typedef void (APIENTRYP PFNGLLINKPROGRAMPROC_MT) (GLuint program); + typedef void (APIENTRYP PFNGLSHADERSOURCEPROC_MT) (GLuint shader, GLsizei count, const GLchar *const* string, const GLint * length); + typedef void (APIENTRYP PFNGLUSEPROGRAMPROC_MT) (GLuint program); + typedef void (APIENTRYP PFNGLUNIFORM1FPROC_MT) (GLint location, GLfloat v0); + typedef void (APIENTRYP PFNGLUNIFORM2FPROC_MT) (GLint location, GLfloat v0, GLfloat v1); + typedef void (APIENTRYP PFNGLUNIFORM3FPROC_MT) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); + typedef void (APIENTRYP PFNGLUNIFORM4FPROC_MT) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); + typedef void (APIENTRYP PFNGLUNIFORM1IPROC_MT) (GLint location, GLint v0); + typedef void (APIENTRYP PFNGLUNIFORM2IPROC_MT) (GLint location, GLint v0, GLint v1); + typedef void (APIENTRYP PFNGLUNIFORM3IPROC_MT) (GLint location, GLint v0, GLint v1, GLint v2); + typedef void (APIENTRYP PFNGLUNIFORM4IPROC_MT) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); + typedef void (APIENTRYP PFNGLUNIFORM1FVPROC_MT) (GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM2FVPROC_MT) (GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM3FVPROC_MT) (GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM4FVPROC_MT) (GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORM1IVPROC_MT) (GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM2IVPROC_MT) (GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM3IVPROC_MT) (GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORM4IVPROC_MT) (GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC_MT) (GLuint program); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC_MT) (GLuint index, GLdouble x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC_MT) (GLuint index, GLfloat x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC_MT) (GLuint index, const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC_MT) (GLuint index, GLshort x); + typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC_MT) (GLuint index, const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC_MT) (GLuint index, GLdouble x, GLdouble y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC_MT) (GLuint index, GLfloat x, GLfloat y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC_MT) (GLuint index, const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC_MT) (GLuint index, GLshort x, GLshort y); + typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC_MT) (GLuint index, const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC_MT) (GLuint index, GLdouble x, GLdouble y, GLdouble z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC_MT) (GLuint index, GLfloat x, GLfloat y, GLfloat z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC_MT) (GLuint index, const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC_MT) (GLuint index, GLshort x, GLshort y, GLshort z); + typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC_MT) (GLuint index, const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC_MT) (GLuint index, const GLbyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC_MT) (GLuint index, const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC_MT) (GLuint index, const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC_MT) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC_MT) (GLuint index, const GLubyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC_MT) (GLuint index, const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC_MT) (GLuint index, const GLushort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC_MT) (GLuint index, const GLbyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC_MT) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC_MT) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC_MT) (GLuint index, const GLfloat * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC_MT) (GLuint index, const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC_MT) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC_MT) (GLuint index, const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC_MT) (GLuint index, const GLubyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC_MT) (GLuint index, const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC_MT) (GLuint index, const GLushort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC_MT) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void * pointer); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLCOLORMASKIPROC_MT) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); + typedef void (APIENTRYP PFNGLENABLEIPROC_MT) (GLenum target, GLuint index); + typedef void (APIENTRYP PFNGLDISABLEIPROC_MT) (GLenum target, GLuint index); + typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC_MT) (GLenum target, GLuint index); + typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC_MT) (GLenum primitiveMode); + typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC_MT) ( void); + typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC_MT) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); + typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC_MT) (GLenum target, GLuint index, GLuint buffer); + typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC_MT) (GLuint program, GLsizei count, const GLchar *const* varyings, GLenum bufferMode); + typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC_MT) (GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLsizei * size, GLenum * type, GLchar * name); + typedef void (APIENTRYP PFNGLCLAMPCOLORPROC_MT) (GLenum target, GLenum clamp); + typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC_MT) (GLuint id, GLenum mode); + typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC_MT) ( void); + typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC_MT) (GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC_MT) (GLuint index, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC_MT) (GLuint index, GLenum pname, GLuint * params); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC_MT) (GLuint index, GLint x); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC_MT) (GLuint index, GLint x, GLint y); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC_MT) (GLuint index, GLint x, GLint y, GLint z); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC_MT) (GLuint index, GLint x, GLint y, GLint z, GLint w); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC_MT) (GLuint index, GLuint x); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC_MT) (GLuint index, GLuint x, GLuint y); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC_MT) (GLuint index, GLuint x, GLuint y, GLuint z); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC_MT) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC_MT) (GLuint index, const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC_MT) (GLuint index, const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC_MT) (GLuint index, const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC_MT) (GLuint index, const GLint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC_MT) (GLuint index, const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC_MT) (GLuint index, const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC_MT) (GLuint index, const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC_MT) (GLuint index, const GLuint * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC_MT) (GLuint index, const GLbyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC_MT) (GLuint index, const GLshort * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC_MT) (GLuint index, const GLubyte * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC_MT) (GLuint index, const GLushort * v); + typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC_MT) (GLuint program, GLint location, GLuint * params); + typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC_MT) (GLuint program, GLuint color, const GLchar * name); + typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC_MT) (GLuint program, const GLchar * name); + typedef void (APIENTRYP PFNGLUNIFORM1UIPROC_MT) (GLint location, GLuint v0); + typedef void (APIENTRYP PFNGLUNIFORM2UIPROC_MT) (GLint location, GLuint v0, GLuint v1); + typedef void (APIENTRYP PFNGLUNIFORM3UIPROC_MT) (GLint location, GLuint v0, GLuint v1, GLuint v2); + typedef void (APIENTRYP PFNGLUNIFORM4UIPROC_MT) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC_MT) (GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC_MT) (GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC_MT) (GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC_MT) (GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC_MT) (GLenum target, GLenum pname, const GLint * params); + typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC_MT) (GLenum target, GLenum pname, const GLuint * params); + typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC_MT) (GLenum target, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC_MT) (GLenum target, GLenum pname, GLuint * params); + typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC_MT) (GLenum buffer, GLint drawbuffer, const GLint * value); + typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC_MT) (GLenum buffer, GLint drawbuffer, const GLuint * value); + typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC_MT) (GLenum buffer, GLint drawbuffer, const GLfloat * value); + typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC_MT) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); + typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC_MT) (GLenum name, GLuint index); + typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC_MT) (GLuint renderbuffer); + typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC_MT) (GLenum target, GLuint renderbuffer); + typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC_MT) (GLsizei n, const GLuint * renderbuffers); + typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC_MT) (GLsizei n, GLuint * renderbuffers); + typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC_MT) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC_MT) (GLenum target, GLenum pname, GLint * params); + typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC_MT) (GLuint framebuffer); + typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC_MT) (GLenum target, GLuint framebuffer); + typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC_MT) (GLsizei n, const GLuint * framebuffers); + typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC_MT) (GLsizei n, GLuint * framebuffers); + typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC_MT) (GLenum target); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC_MT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC_MT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC_MT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); + typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC_MT) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC_MT) (GLenum target, GLenum attachment, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC_MT) (GLenum target); + typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC_MT) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); + typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC_MT) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC_MT) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); + typedef void * (APIENTRYP PFNGLMAPBUFFERRANGEPROC_MT) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); + typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC_MT) (GLenum target, GLintptr offset, GLsizeiptr length); + typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC_MT) (GLuint array); + typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC_MT) (GLsizei n, const GLuint * arrays); + typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC_MT) (GLsizei n, GLuint * arrays); + typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC_MT) (GLuint array); + typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC_MT) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); + typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC_MT) (GLenum mode, GLsizei count, GLenum type, const void * indices, GLsizei instancecount); + typedef void (APIENTRYP PFNGLTEXBUFFERPROC_MT) (GLenum target, GLenum internalformat, GLuint buffer); + typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC_MT) (GLuint index); + typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC_MT) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC_MT) (GLuint program, GLsizei uniformCount, const GLchar *const* uniformNames, GLuint * uniformIndices); + typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC_MT) (GLuint program, GLsizei uniformCount, const GLuint * uniformIndices, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC_MT) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei * length, GLchar * uniformName); + typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC_MT) (GLuint program, const GLchar * uniformBlockName); + typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC_MT) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC_MT) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei * length, GLchar * uniformBlockName); + typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC_MT) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); + typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC_MT) (GLenum mode, GLsizei count, GLenum type, const void * indices, GLint basevertex); + typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC_MT) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void * indices, GLint basevertex); + typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC_MT) (GLenum mode, GLsizei count, GLenum type, const void * indices, GLsizei instancecount, GLint basevertex); + typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC_MT) (GLenum mode, const GLsizei * count, GLenum type, const void *const* indices, GLsizei drawcount, const GLint * basevertex); + typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC_MT) (GLenum mode); + typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC_MT) (GLenum condition, GLbitfield flags); + typedef GLboolean (APIENTRYP PFNGLISSYNCPROC_MT) (GLsync sync); + typedef void (APIENTRYP PFNGLDELETESYNCPROC_MT) (GLsync sync); + typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC_MT) (GLsync sync, GLbitfield flags, GLuint64 timeout); + typedef void (APIENTRYP PFNGLWAITSYNCPROC_MT) (GLsync sync, GLbitfield flags, GLuint64 timeout); + typedef void (APIENTRYP PFNGLGETINTEGER64VPROC_MT) (GLenum pname, GLint64 * data); + typedef void (APIENTRYP PFNGLGETSYNCIVPROC_MT) (GLsync sync, GLenum pname, GLsizei count, GLsizei * length, GLint * values); + typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC_MT) (GLenum target, GLenum pname, GLint64 * params); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC_MT) (GLenum target, GLenum attachment, GLuint texture, GLint level); + typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC_MT) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); + typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC_MT) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); + typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC_MT) (GLenum pname, GLuint index, GLfloat * val); + typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC_MT) (GLuint maskNumber, GLbitfield mask); + typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC_MT) (GLuint program, GLuint colorNumber, GLuint index, const GLchar * name); + typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC_MT) (GLuint program, const GLchar * name); + typedef void (APIENTRYP PFNGLGENSAMPLERSPROC_MT) (GLsizei count, GLuint * samplers); + typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC_MT) (GLsizei count, const GLuint * samplers); + typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC_MT) (GLuint sampler); + typedef void (APIENTRYP PFNGLBINDSAMPLERPROC_MT) (GLuint unit, GLuint sampler); + typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC_MT) (GLuint sampler, GLenum pname, GLint param); + typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC_MT) (GLuint sampler, GLenum pname, const GLint * param); + typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC_MT) (GLuint sampler, GLenum pname, GLfloat param); + typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC_MT) (GLuint sampler, GLenum pname, const GLfloat * param); + typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC_MT) (GLuint sampler, GLenum pname, const GLint * param); + typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC_MT) (GLuint sampler, GLenum pname, const GLuint * param); + typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC_MT) (GLuint sampler, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC_MT) (GLuint sampler, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC_MT) (GLuint sampler, GLenum pname, GLfloat * params); + typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC_MT) (GLuint sampler, GLenum pname, GLuint * params); + typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC_MT) (GLuint id, GLenum target); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC_MT) (GLuint id, GLenum pname, GLint64 * params); + typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC_MT) (GLuint id, GLenum pname, GLuint64 * params); + typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC_MT) (GLuint index, GLuint divisor); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC_MT) (GLuint index, GLenum type, GLboolean normalized, GLuint value); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC_MT) (GLuint index, GLenum type, GLboolean normalized, const GLuint * value); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC_MT) (GLuint index, GLenum type, GLboolean normalized, GLuint value); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC_MT) (GLuint index, GLenum type, GLboolean normalized, const GLuint * value); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC_MT) (GLuint index, GLenum type, GLboolean normalized, GLuint value); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC_MT) (GLuint index, GLenum type, GLboolean normalized, const GLuint * value); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC_MT) (GLuint index, GLenum type, GLboolean normalized, GLuint value); + typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC_MT) (GLuint index, GLenum type, GLboolean normalized, const GLuint * value); + typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC_MT) (GLfloat value); + typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC_MT) (GLuint buf, GLenum mode); + typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC_MT) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); + typedef void (APIENTRYP PFNGLBLENDFUNCIPROC_MT) (GLuint buf, GLenum src, GLenum dst); + typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC_MT) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); + typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC_MT) (GLenum mode, const void * indirect); + typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC_MT) (GLenum mode, GLenum type, const void * indirect); + typedef void (APIENTRYP PFNGLUNIFORM1DPROC_MT) (GLint location, GLdouble x); + typedef void (APIENTRYP PFNGLUNIFORM2DPROC_MT) (GLint location, GLdouble x, GLdouble y); + typedef void (APIENTRYP PFNGLUNIFORM3DPROC_MT) (GLint location, GLdouble x, GLdouble y, GLdouble z); + typedef void (APIENTRYP PFNGLUNIFORM4DPROC_MT) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); + typedef void (APIENTRYP PFNGLUNIFORM1DVPROC_MT) (GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORM2DVPROC_MT) (GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORM3DVPROC_MT) (GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORM4DVPROC_MT) (GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC_MT) (GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC_MT) (GLuint program, GLint location, GLdouble * params); + typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC_MT) (GLuint program, GLenum shadertype, const GLchar * name); + typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC_MT) (GLuint program, GLenum shadertype, const GLchar * name); + typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC_MT) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint * values); + typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC_MT) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei * length, GLchar * name); + typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC_MT) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei * length, GLchar * name); + typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC_MT) (GLenum shadertype, GLsizei count, const GLuint * indices); + typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC_MT) (GLenum shadertype, GLint location, GLuint * params); + typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC_MT) (GLuint program, GLenum shadertype, GLenum pname, GLint * values); + typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC_MT) (GLenum pname, GLint value); + typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC_MT) (GLenum pname, const GLfloat * values); + typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC_MT) (GLenum target, GLuint id); + typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC_MT) (GLsizei n, const GLuint * ids); + typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC_MT) (GLsizei n, GLuint * ids); + typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC_MT) (GLuint id); + typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC_MT) ( void); + typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC_MT) ( void); + typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC_MT) (GLenum mode, GLuint id); + typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC_MT) (GLenum mode, GLuint id, GLuint stream); + typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC_MT) (GLenum target, GLuint index, GLuint id); + typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC_MT) (GLenum target, GLuint index); + typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC_MT) (GLenum target, GLuint index, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC_MT) ( void); + typedef void (APIENTRYP PFNGLSHADERBINARYPROC_MT) (GLsizei count, const GLuint * shaders, GLenum binaryFormat, const void * binary, GLsizei length); + typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC_MT) (GLenum shadertype, GLenum precisiontype, GLint * range, GLint * precision); + typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC_MT) (GLfloat n, GLfloat f); + typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC_MT) (GLfloat d); + typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC_MT) (GLuint program, GLsizei bufSize, GLsizei * length, GLenum * binaryFormat, void * binary); + typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC_MT) (GLuint program, GLenum binaryFormat, const void * binary, GLsizei length); + typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC_MT) (GLuint program, GLenum pname, GLint value); + typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC_MT) (GLuint pipeline, GLbitfield stages, GLuint program); + typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC_MT) (GLuint pipeline, GLuint program); + typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC_MT) (GLenum type, GLsizei count, const GLchar *const* strings); + typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC_MT) (GLuint pipeline); + typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC_MT) (GLsizei n, const GLuint * pipelines); + typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC_MT) (GLsizei n, GLuint * pipelines); + typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC_MT) (GLuint pipeline); + typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC_MT) (GLuint pipeline, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC_MT) (GLuint program, GLint location, GLint v0); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC_MT) (GLuint program, GLint location, GLfloat v0); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC_MT) (GLuint program, GLint location, GLdouble v0); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC_MT) (GLuint program, GLint location, GLuint v0); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC_MT) (GLuint program, GLint location, GLint v0, GLint v1); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC_MT) (GLuint program, GLint location, GLfloat v0, GLfloat v1); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC_MT) (GLuint program, GLint location, GLdouble v0, GLdouble v1); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC_MT) (GLuint program, GLint location, GLuint v0, GLuint v1); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC_MT) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC_MT) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC_MT) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC_MT) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC_MT) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC_MT) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC_MT) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC_MT) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC_MT) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble * value); + typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC_MT) (GLuint pipeline); + typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC_MT) (GLuint pipeline, GLsizei bufSize, GLsizei * length, GLchar * infoLog); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC_MT) (GLuint index, GLdouble x); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC_MT) (GLuint index, GLdouble x, GLdouble y); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC_MT) (GLuint index, GLdouble x, GLdouble y, GLdouble z); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC_MT) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC_MT) (GLuint index, const GLdouble * v); + typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC_MT) (GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC_MT) (GLuint index, GLenum pname, GLdouble * params); + typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC_MT) (GLuint first, GLsizei count, const GLfloat * v); + typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC_MT) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); + typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC_MT) (GLuint index, const GLfloat * v); + typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC_MT) (GLuint first, GLsizei count, const GLint * v); + typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC_MT) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC_MT) (GLuint index, const GLint * v); + typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC_MT) (GLuint first, GLsizei count, const GLdouble * v); + typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC_MT) (GLuint index, GLdouble n, GLdouble f); + typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC_MT) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); + typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC_MT) (GLenum mode, GLsizei count, GLenum type, const void * indices, GLsizei instancecount, GLuint baseinstance); + typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC_MT) (GLenum mode, GLsizei count, GLenum type, const void * indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); + typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC_MT) (GLenum target, GLenum internalformat, GLenum pname, GLsizei count, GLint * params); + typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC_MT) (GLuint program, GLuint bufferIndex, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC_MT) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); + typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC_MT) (GLbitfield barriers); + typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC_MT) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); + typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC_MT) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC_MT) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); + typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC_MT) (GLenum mode, GLuint id, GLsizei instancecount); + typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC_MT) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); + typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC_MT) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void * data); + typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC_MT) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void * data); + typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC_MT) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); + typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC_MT) (GLintptr indirect); + typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC_MT) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); + typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC_MT) (GLenum target, GLenum pname, GLint param); + typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC_MT) (GLenum target, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC_MT) (GLenum target, GLenum internalformat, GLenum pname, GLsizei count, GLint64 * params); + typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); + typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC_MT) (GLuint texture, GLint level); + typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC_MT) (GLuint buffer, GLintptr offset, GLsizeiptr length); + typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC_MT) (GLuint buffer); + typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC_MT) (GLenum target, GLsizei numAttachments, const GLenum * attachments); + typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC_MT) (GLenum target, GLsizei numAttachments, const GLenum * attachments, GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC_MT) (GLenum mode, const void * indirect, GLsizei drawcount, GLsizei stride); + typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC_MT) (GLenum mode, GLenum type, const void * indirect, GLsizei drawcount, GLsizei stride); + typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC_MT) (GLuint program, GLenum programInterface, GLenum pname, GLint * params); + typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC_MT) (GLuint program, GLenum programInterface, const GLchar * name); + typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC_MT) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei * length, GLchar * name); + typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC_MT) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum * props, GLsizei count, GLsizei * length, GLint * params); + typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC_MT) (GLuint program, GLenum programInterface, const GLchar * name); + typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC_MT) (GLuint program, GLenum programInterface, const GLchar * name); + typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC_MT) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); + typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC_MT) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); + typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC_MT) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); + typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC_MT) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); + typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC_MT) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); + typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC_MT) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); + typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC_MT) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); + typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC_MT) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); + typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC_MT) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); + typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC_MT) (GLuint attribindex, GLuint bindingindex); + typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC_MT) (GLuint bindingindex, GLuint divisor); + typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC_MT) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint * ids, GLboolean enabled); + typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC_MT) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar * buf); + typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC_MT) (GLDEBUGPROC callback, const void * userParam); + typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC_MT) (GLuint count, GLsizei bufSize, GLenum * sources, GLenum * types, GLuint * ids, GLenum * severities, GLsizei * lengths, GLchar * messageLog); + typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC_MT) (GLenum source, GLuint id, GLsizei length, const GLchar * message); + typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC_MT) ( void); + typedef void (APIENTRYP PFNGLOBJECTLABELPROC_MT) (GLenum identifier, GLuint name, GLsizei length, const GLchar * label); + typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC_MT) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei * length, GLchar * label); + typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC_MT) (const void * ptr, GLsizei length, const GLchar * label); + typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC_MT) (const void * ptr, GLsizei bufSize, GLsizei * length, GLchar * label); + typedef void (APIENTRYP PFNGLBUFFERSTORAGEPROC_MT) (GLenum target, GLsizeiptr size, const void * data, GLbitfield flags); + typedef void (APIENTRYP PFNGLCLEARTEXIMAGEPROC_MT) (GLuint texture, GLint level, GLenum format, GLenum type, const void * data); + typedef void (APIENTRYP PFNGLCLEARTEXSUBIMAGEPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); + typedef void (APIENTRYP PFNGLBINDBUFFERSBASEPROC_MT) (GLenum target, GLuint first, GLsizei count, const GLuint * buffers); + typedef void (APIENTRYP PFNGLBINDBUFFERSRANGEPROC_MT) (GLenum target, GLuint first, GLsizei count, const GLuint * buffers, const GLintptr * offsets, const GLsizeiptr * sizes); + typedef void (APIENTRYP PFNGLBINDTEXTURESPROC_MT) (GLuint first, GLsizei count, const GLuint * textures); + typedef void (APIENTRYP PFNGLBINDSAMPLERSPROC_MT) (GLuint first, GLsizei count, const GLuint * samplers); + typedef void (APIENTRYP PFNGLBINDIMAGETEXTURESPROC_MT) (GLuint first, GLsizei count, const GLuint * textures); + typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERSPROC_MT) (GLuint first, GLsizei count, const GLuint * buffers, const GLintptr * offsets, const GLsizei * strides); + typedef void (APIENTRYP PFNGLCLIPCONTROLPROC_MT) (GLenum origin, GLenum depth); + typedef void (APIENTRYP PFNGLCREATETRANSFORMFEEDBACKSPROC_MT) (GLsizei n, GLuint * ids); + typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKBUFFERBASEPROC_MT) (GLuint xfb, GLuint index, GLuint buffer); + typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKBUFFERRANGEPROC_MT) (GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); + typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKIVPROC_MT) (GLuint xfb, GLenum pname, GLint * param); + typedef void (APIENTRYP PFNGLCREATEBUFFERSPROC_MT) (GLsizei n, GLuint * buffers); + typedef void (APIENTRYP PFNGLNAMEDBUFFERSTORAGEPROC_MT) (GLuint buffer, GLsizeiptr size, const void * data, GLbitfield flags); + typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAPROC_MT) (GLuint buffer, GLsizeiptr size, const void * data, GLenum usage); + typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAPROC_MT) (GLuint buffer, GLintptr offset, GLsizeiptr size, const void * data); + typedef void (APIENTRYP PFNGLCOPYNAMEDBUFFERSUBDATAPROC_MT) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAPROC_MT) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void * data); + typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAPROC_MT) (GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void * data); + typedef void * (APIENTRYP PFNGLMAPNAMEDBUFFERPROC_MT) (GLuint buffer, GLenum access); + typedef void * (APIENTRYP PFNGLMAPNAMEDBUFFERRANGEPROC_MT) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); + typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFERPROC_MT) (GLuint buffer); + typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEPROC_MT) (GLuint buffer, GLintptr offset, GLsizeiptr length); + typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVPROC_MT) (GLuint buffer, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERI64VPROC_MT) (GLuint buffer, GLenum pname, GLint64 * params); + typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVPROC_MT) (GLuint buffer, GLenum pname, void ** params); + typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAPROC_MT) (GLuint buffer, GLintptr offset, GLsizeiptr size, void * data); + typedef void (APIENTRYP PFNGLCREATEFRAMEBUFFERSPROC_MT) (GLsizei n, GLuint * framebuffers); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFERPROC_MT) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIPROC_MT) (GLuint framebuffer, GLenum pname, GLint param); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREPROC_MT) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYERPROC_MT) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERDRAWBUFFERPROC_MT) (GLuint framebuffer, GLenum buf); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC_MT) (GLuint framebuffer, GLsizei n, const GLenum * bufs); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC_MT) (GLuint framebuffer, GLenum src); + typedef void (APIENTRYP PFNGLINVALIDATENAMEDFRAMEBUFFERDATAPROC_MT) (GLuint framebuffer, GLsizei numAttachments, const GLenum * attachments); + typedef void (APIENTRYP PFNGLINVALIDATENAMEDFRAMEBUFFERSUBDATAPROC_MT) (GLuint framebuffer, GLsizei numAttachments, const GLenum * attachments, GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERIVPROC_MT) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint * value); + typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERUIVPROC_MT) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint * value); + typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERFVPROC_MT) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat * value); + typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERFIPROC_MT) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); + typedef void (APIENTRYP PFNGLBLITNAMEDFRAMEBUFFERPROC_MT) (GLuint readFramebuffer, GLuint drawFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); + typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC_MT) (GLuint framebuffer, GLenum target); + typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVPROC_MT) (GLuint framebuffer, GLenum pname, GLint * param); + typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVPROC_MT) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLCREATERENDERBUFFERSPROC_MT) (GLsizei n, GLuint * renderbuffers); + typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEPROC_MT) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEPROC_MT) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVPROC_MT) (GLuint renderbuffer, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLCREATETEXTURESPROC_MT) (GLenum target, GLsizei n, GLuint * textures); + typedef void (APIENTRYP PFNGLTEXTUREBUFFERPROC_MT) (GLuint texture, GLenum internalformat, GLuint buffer); + typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEPROC_MT) (GLuint texture, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); + typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DPROC_MT) (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width); + typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DPROC_MT) (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DPROC_MT) (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); + typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEPROC_MT) (GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); + typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEPROC_MT) (GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); + typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * pixels); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void * data); + typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); + typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFPROC_MT) (GLuint texture, GLenum pname, GLfloat param); + typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVPROC_MT) (GLuint texture, GLenum pname, const GLfloat * param); + typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIPROC_MT) (GLuint texture, GLenum pname, GLint param); + typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVPROC_MT) (GLuint texture, GLenum pname, const GLint * params); + typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVPROC_MT) (GLuint texture, GLenum pname, const GLuint * params); + typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVPROC_MT) (GLuint texture, GLenum pname, const GLint * param); + typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPPROC_MT) (GLuint texture); + typedef void (APIENTRYP PFNGLBINDTEXTUREUNITPROC_MT) (GLuint unit, GLuint texture); + typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEPROC_MT) (GLuint texture, GLint level, GLenum format, GLenum type, GLsizei bufSize, void * pixels); + typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEPROC_MT) (GLuint texture, GLint level, GLsizei bufSize, void * pixels); + typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVPROC_MT) (GLuint texture, GLint level, GLenum pname, GLfloat * params); + typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVPROC_MT) (GLuint texture, GLint level, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVPROC_MT) (GLuint texture, GLenum pname, GLfloat * params); + typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVPROC_MT) (GLuint texture, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVPROC_MT) (GLuint texture, GLenum pname, GLuint * params); + typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVPROC_MT) (GLuint texture, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLCREATEVERTEXARRAYSPROC_MT) (GLsizei n, GLuint * arrays); + typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYATTRIBPROC_MT) (GLuint vaobj, GLuint index); + typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYATTRIBPROC_MT) (GLuint vaobj, GLuint index); + typedef void (APIENTRYP PFNGLVERTEXARRAYELEMENTBUFFERPROC_MT) (GLuint vaobj, GLuint buffer); + typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBUFFERPROC_MT) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); + typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBUFFERSPROC_MT) (GLuint vaobj, GLuint first, GLsizei count, const GLuint * buffers, const GLintptr * offsets, const GLsizei * strides); + typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBBINDINGPROC_MT) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); + typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBFORMATPROC_MT) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); + typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBIFORMATPROC_MT) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); + typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBLFORMATPROC_MT) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); + typedef void (APIENTRYP PFNGLVERTEXARRAYBINDINGDIVISORPROC_MT) (GLuint vaobj, GLuint bindingindex, GLuint divisor); + typedef void (APIENTRYP PFNGLGETVERTEXARRAYIVPROC_MT) (GLuint vaobj, GLenum pname, GLint * param); + typedef void (APIENTRYP PFNGLGETVERTEXARRAYINDEXEDIVPROC_MT) (GLuint vaobj, GLuint index, GLenum pname, GLint * param); + typedef void (APIENTRYP PFNGLGETVERTEXARRAYINDEXED64IVPROC_MT) (GLuint vaobj, GLuint index, GLenum pname, GLint64 * param); + typedef void (APIENTRYP PFNGLCREATESAMPLERSPROC_MT) (GLsizei n, GLuint * samplers); + typedef void (APIENTRYP PFNGLCREATEPROGRAMPIPELINESPROC_MT) (GLsizei n, GLuint * pipelines); + typedef void (APIENTRYP PFNGLCREATEQUERIESPROC_MT) (GLenum target, GLsizei n, GLuint * ids); + typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTI64VPROC_MT) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); + typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTIVPROC_MT) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); + typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTUI64VPROC_MT) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); + typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTUIVPROC_MT) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); + typedef void (APIENTRYP PFNGLMEMORYBARRIERBYREGIONPROC_MT) (GLbitfield barriers); + typedef void (APIENTRYP PFNGLGETTEXTURESUBIMAGEPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLsizei bufSize, void * pixels); + typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTURESUBIMAGEPROC_MT) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei bufSize, void * pixels); + typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSPROC_MT) ( void); + typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEPROC_MT) (GLenum target, GLint lod, GLsizei bufSize, void * pixels); + typedef void (APIENTRYP PFNGLGETNTEXIMAGEPROC_MT) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void * pixels); + typedef void (APIENTRYP PFNGLGETNUNIFORMDVPROC_MT) (GLuint program, GLint location, GLsizei bufSize, GLdouble * params); + typedef void (APIENTRYP PFNGLGETNUNIFORMFVPROC_MT) (GLuint program, GLint location, GLsizei bufSize, GLfloat * params); + typedef void (APIENTRYP PFNGLGETNUNIFORMIVPROC_MT) (GLuint program, GLint location, GLsizei bufSize, GLint * params); + typedef void (APIENTRYP PFNGLGETNUNIFORMUIVPROC_MT) (GLuint program, GLint location, GLsizei bufSize, GLuint * params); + typedef void (APIENTRYP PFNGLREADNPIXELSPROC_MT) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void * data); + typedef void (APIENTRYP PFNGLTEXTUREBARRIERPROC_MT) ( void); + typedef void (APIENTRYP PFNGLSPECIALIZESHADERPROC_MT) (GLuint shader, const GLchar * pEntryPoint, GLuint numSpecializationConstants, const GLuint * pConstantIndex, const GLuint * pConstantValue); + typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC_MT) (GLenum mode, const void * indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); + typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC_MT) (GLenum mode, GLenum type, const void * indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); + typedef void (APIENTRYP PFNGLPOLYGONOFFSETCLAMPPROC_MT) (GLfloat factor, GLfloat units, GLfloat clamp); + typedef void (APIENTRYP PFNGLPRIMITIVEBOUNDINGBOXPROC_MT) (GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW); + typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLEPROC_MT) (GLuint texture); + typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLEPROC_MT) (GLuint texture, GLuint sampler); + typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTPROC_MT) (GLuint64 handle); + typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTPROC_MT) (GLuint64 handle); + typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLEPROC_MT) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); + typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTPROC_MT) (GLuint64 handle, GLenum access); + typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTPROC_MT) (GLuint64 handle); + typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64PROC_MT) (GLint location, GLuint64 value); + typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VPROC_MT) (GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64PROC_MT) (GLuint program, GLint location, GLuint64 value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint64 * values); + typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTPROC_MT) (GLuint64 handle); + typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTPROC_MT) (GLuint64 handle); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64PROC_MT) (GLuint index, GLuint64 x); + typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VPROC_MT) (GLuint index, const GLuint64 * v); + typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VPROC_MT) (GLuint index, GLenum pname, GLuint64 * params); + typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTPROC_MT) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); + typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEGROUPSIZEPROC_MT) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z); + typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEPROC_MT) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); + typedef void (APIENTRYP PFNGLUNIFORM1I64PROC_MT) (GLint location, GLint64 x); + typedef void (APIENTRYP PFNGLUNIFORM2I64PROC_MT) (GLint location, GLint64 x, GLint64 y); + typedef void (APIENTRYP PFNGLUNIFORM3I64PROC_MT) (GLint location, GLint64 x, GLint64 y, GLint64 z); + typedef void (APIENTRYP PFNGLUNIFORM4I64PROC_MT) (GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w); + typedef void (APIENTRYP PFNGLUNIFORM1I64VPROC_MT) (GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLUNIFORM2I64VPROC_MT) (GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLUNIFORM3I64VPROC_MT) (GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLUNIFORM4I64VPROC_MT) (GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLUNIFORM1UI64PROC_MT) (GLint location, GLuint64 x); + typedef void (APIENTRYP PFNGLUNIFORM2UI64PROC_MT) (GLint location, GLuint64 x, GLuint64 y); + typedef void (APIENTRYP PFNGLUNIFORM3UI64PROC_MT) (GLint location, GLuint64 x, GLuint64 y, GLuint64 z); + typedef void (APIENTRYP PFNGLUNIFORM4UI64PROC_MT) (GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w); + typedef void (APIENTRYP PFNGLUNIFORM1UI64VPROC_MT) (GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLUNIFORM2UI64VPROC_MT) (GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLUNIFORM3UI64VPROC_MT) (GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLUNIFORM4UI64VPROC_MT) (GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLGETUNIFORMI64VPROC_MT) (GLuint program, GLint location, GLint64 * params); + typedef void (APIENTRYP PFNGLGETUNIFORMUI64VPROC_MT) (GLuint program, GLint location, GLuint64 * params); + typedef void (APIENTRYP PFNGLGETNUNIFORMI64VPROC_MT) (GLuint program, GLint location, GLsizei bufSize, GLint64 * params); + typedef void (APIENTRYP PFNGLGETNUNIFORMUI64VPROC_MT) (GLuint program, GLint location, GLsizei bufSize, GLuint64 * params); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64PROC_MT) (GLuint program, GLint location, GLint64 x); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64PROC_MT) (GLuint program, GLint location, GLint64 x, GLint64 y); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64PROC_MT) (GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64PROC_MT) (GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64PROC_MT) (GLuint program, GLint location, GLuint64 x); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64PROC_MT) (GLuint program, GLint location, GLuint64 x, GLuint64 y); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64PROC_MT) (GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64PROC_MT) (GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VPROC_MT) (GLuint program, GLint location, GLsizei count, const GLuint64 * value); + typedef void (APIENTRYP PFNGLMAXSHADERCOMPILERTHREADSPROC_MT) (GLuint count); + typedef void (APIENTRYP PFNGLFRAMEBUFFERSAMPLELOCATIONSFVPROC_MT) (GLenum target, GLuint start, GLsizei count, const GLfloat * v); + typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERSAMPLELOCATIONSFVPROC_MT) (GLuint framebuffer, GLuint start, GLsizei count, const GLfloat * v); + typedef void (APIENTRYP PFNGLEVALUATEDEPTHVALUESPROC_MT) ( void); + typedef void (APIENTRYP PFNGLNAMEDSTRINGPROC_MT) (GLenum type, GLint namelen, const GLchar * name, GLint stringlen, const GLchar * string); + typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGPROC_MT) (GLint namelen, const GLchar * name); + typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEPROC_MT) (GLuint shader, GLsizei count, const GLchar *const* path, const GLint * length); + typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGPROC_MT) (GLint namelen, const GLchar * name); + typedef void (APIENTRYP PFNGLGETNAMEDSTRINGPROC_MT) (GLint namelen, const GLchar * name, GLsizei bufSize, GLint * stringlen, GLchar * string); + typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVPROC_MT) (GLint namelen, const GLchar * name, GLenum pname, GLint * params); + typedef void (APIENTRYP PFNGLBUFFERPAGECOMMITMENTPROC_MT) (GLenum target, GLintptr offset, GLsizeiptr size, GLboolean commit); + typedef void (APIENTRYP PFNGLNAMEDBUFFERPAGECOMMITMENTPROC_MT) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit); + typedef void (APIENTRYP PFNGLTEXPAGECOMMITMENTPROC_MT) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit); + + std::unordered_set extensions; +public: + // Call this once after creating the context. + void LoadAllProcedures(irr::video::IContextManager *cmgr); + // Check if an extension is supported. + inline bool IsExtensionPresent(const std::string &ext) const + { + return extensions.count(ext) > 0; + } + + PFNGLCULLFACEPROC_MT CullFace = NULL; + PFNGLFRONTFACEPROC_MT FrontFace = NULL; + PFNGLHINTPROC_MT Hint = NULL; + PFNGLLINEWIDTHPROC_MT LineWidth = NULL; + PFNGLPOINTSIZEPROC_MT PointSize = NULL; + PFNGLPOLYGONMODEPROC_MT PolygonMode = NULL; + PFNGLSCISSORPROC_MT Scissor = NULL; + PFNGLTEXPARAMETERFPROC_MT TexParameterf = NULL; + PFNGLTEXPARAMETERFVPROC_MT TexParameterfv = NULL; + PFNGLTEXPARAMETERIPROC_MT TexParameteri = NULL; + PFNGLTEXPARAMETERIVPROC_MT TexParameteriv = NULL; + PFNGLTEXIMAGE1DPROC_MT TexImage1D = NULL; + PFNGLTEXIMAGE2DPROC_MT TexImage2D = NULL; + PFNGLDRAWBUFFERPROC_MT DrawBuffer = NULL; + PFNGLCLEARPROC_MT Clear = NULL; + PFNGLCLEARCOLORPROC_MT ClearColor = NULL; + PFNGLCLEARSTENCILPROC_MT ClearStencil = NULL; + PFNGLCLEARDEPTHPROC_MT ClearDepth = NULL; + PFNGLSTENCILMASKPROC_MT StencilMask = NULL; + PFNGLCOLORMASKPROC_MT ColorMask = NULL; + PFNGLDEPTHMASKPROC_MT DepthMask = NULL; + PFNGLDISABLEPROC_MT Disable = NULL; + PFNGLENABLEPROC_MT Enable = NULL; + PFNGLFINISHPROC_MT Finish = NULL; + PFNGLFLUSHPROC_MT Flush = NULL; + PFNGLBLENDFUNCPROC_MT BlendFunc = NULL; + PFNGLLOGICOPPROC_MT LogicOp = NULL; + PFNGLSTENCILFUNCPROC_MT StencilFunc = NULL; + PFNGLSTENCILOPPROC_MT StencilOp = NULL; + PFNGLDEPTHFUNCPROC_MT DepthFunc = NULL; + PFNGLPIXELSTOREFPROC_MT PixelStoref = NULL; + PFNGLPIXELSTOREIPROC_MT PixelStorei = NULL; + PFNGLREADBUFFERPROC_MT ReadBuffer = NULL; + PFNGLREADPIXELSPROC_MT ReadPixels = NULL; + PFNGLGETBOOLEANVPROC_MT GetBooleanv = NULL; + PFNGLGETDOUBLEVPROC_MT GetDoublev = NULL; + PFNGLGETERRORPROC_MT GetError = NULL; + PFNGLGETFLOATVPROC_MT GetFloatv = NULL; + PFNGLGETINTEGERVPROC_MT GetIntegerv = NULL; + PFNGLGETSTRINGPROC_MT GetString = NULL; + PFNGLGETTEXIMAGEPROC_MT GetTexImage = NULL; + PFNGLGETTEXPARAMETERFVPROC_MT GetTexParameterfv = NULL; + PFNGLGETTEXPARAMETERIVPROC_MT GetTexParameteriv = NULL; + PFNGLGETTEXLEVELPARAMETERFVPROC_MT GetTexLevelParameterfv = NULL; + PFNGLGETTEXLEVELPARAMETERIVPROC_MT GetTexLevelParameteriv = NULL; + PFNGLISENABLEDPROC_MT IsEnabled = NULL; + PFNGLDEPTHRANGEPROC_MT DepthRange = NULL; + PFNGLVIEWPORTPROC_MT Viewport = NULL; + PFNGLDRAWARRAYSPROC_MT DrawArrays = NULL; + PFNGLDRAWELEMENTSPROC_MT DrawElements = NULL; + PFNGLGETPOINTERVPROC_MT GetPointerv = NULL; + PFNGLPOLYGONOFFSETPROC_MT PolygonOffset = NULL; + PFNGLCOPYTEXIMAGE1DPROC_MT CopyTexImage1D = NULL; + PFNGLCOPYTEXIMAGE2DPROC_MT CopyTexImage2D = NULL; + PFNGLCOPYTEXSUBIMAGE1DPROC_MT CopyTexSubImage1D = NULL; + PFNGLCOPYTEXSUBIMAGE2DPROC_MT CopyTexSubImage2D = NULL; + PFNGLTEXSUBIMAGE1DPROC_MT TexSubImage1D = NULL; + PFNGLTEXSUBIMAGE2DPROC_MT TexSubImage2D = NULL; + PFNGLBINDTEXTUREPROC_MT BindTexture = NULL; + PFNGLDELETETEXTURESPROC_MT DeleteTextures = NULL; + PFNGLGENTEXTURESPROC_MT GenTextures = NULL; + PFNGLISTEXTUREPROC_MT IsTexture = NULL; + PFNGLDRAWRANGEELEMENTSPROC_MT DrawRangeElements = NULL; + PFNGLTEXIMAGE3DPROC_MT TexImage3D = NULL; + PFNGLTEXSUBIMAGE3DPROC_MT TexSubImage3D = NULL; + PFNGLCOPYTEXSUBIMAGE3DPROC_MT CopyTexSubImage3D = NULL; + PFNGLACTIVETEXTUREPROC_MT ActiveTexture = NULL; + PFNGLSAMPLECOVERAGEPROC_MT SampleCoverage = NULL; + PFNGLCOMPRESSEDTEXIMAGE3DPROC_MT CompressedTexImage3D = NULL; + PFNGLCOMPRESSEDTEXIMAGE2DPROC_MT CompressedTexImage2D = NULL; + PFNGLCOMPRESSEDTEXIMAGE1DPROC_MT CompressedTexImage1D = NULL; + PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC_MT CompressedTexSubImage3D = NULL; + PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC_MT CompressedTexSubImage2D = NULL; + PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC_MT CompressedTexSubImage1D = NULL; + PFNGLGETCOMPRESSEDTEXIMAGEPROC_MT GetCompressedTexImage = NULL; + PFNGLBLENDFUNCSEPARATEPROC_MT BlendFuncSeparate = NULL; + PFNGLMULTIDRAWARRAYSPROC_MT MultiDrawArrays = NULL; + PFNGLMULTIDRAWELEMENTSPROC_MT MultiDrawElements = NULL; + PFNGLPOINTPARAMETERFPROC_MT PointParameterf = NULL; + PFNGLPOINTPARAMETERFVPROC_MT PointParameterfv = NULL; + PFNGLPOINTPARAMETERIPROC_MT PointParameteri = NULL; + PFNGLPOINTPARAMETERIVPROC_MT PointParameteriv = NULL; + PFNGLBLENDCOLORPROC_MT BlendColor = NULL; + PFNGLBLENDEQUATIONPROC_MT BlendEquation = NULL; + PFNGLGENQUERIESPROC_MT GenQueries = NULL; + PFNGLDELETEQUERIESPROC_MT DeleteQueries = NULL; + PFNGLISQUERYPROC_MT IsQuery = NULL; + PFNGLBEGINQUERYPROC_MT BeginQuery = NULL; + PFNGLENDQUERYPROC_MT EndQuery = NULL; + PFNGLGETQUERYIVPROC_MT GetQueryiv = NULL; + PFNGLGETQUERYOBJECTIVPROC_MT GetQueryObjectiv = NULL; + PFNGLGETQUERYOBJECTUIVPROC_MT GetQueryObjectuiv = NULL; + PFNGLBINDBUFFERPROC_MT BindBuffer = NULL; + PFNGLDELETEBUFFERSPROC_MT DeleteBuffers = NULL; + PFNGLGENBUFFERSPROC_MT GenBuffers = NULL; + PFNGLISBUFFERPROC_MT IsBuffer = NULL; + PFNGLBUFFERDATAPROC_MT BufferData = NULL; + PFNGLBUFFERSUBDATAPROC_MT BufferSubData = NULL; + PFNGLGETBUFFERSUBDATAPROC_MT GetBufferSubData = NULL; + PFNGLMAPBUFFERPROC_MT MapBuffer = NULL; + PFNGLUNMAPBUFFERPROC_MT UnmapBuffer = NULL; + PFNGLGETBUFFERPARAMETERIVPROC_MT GetBufferParameteriv = NULL; + PFNGLGETBUFFERPOINTERVPROC_MT GetBufferPointerv = NULL; + PFNGLBLENDEQUATIONSEPARATEPROC_MT BlendEquationSeparate = NULL; + PFNGLDRAWBUFFERSPROC_MT DrawBuffers = NULL; + PFNGLSTENCILOPSEPARATEPROC_MT StencilOpSeparate = NULL; + PFNGLSTENCILFUNCSEPARATEPROC_MT StencilFuncSeparate = NULL; + PFNGLSTENCILMASKSEPARATEPROC_MT StencilMaskSeparate = NULL; + PFNGLATTACHSHADERPROC_MT AttachShader = NULL; + PFNGLBINDATTRIBLOCATIONPROC_MT BindAttribLocation = NULL; + PFNGLCOMPILESHADERPROC_MT CompileShader = NULL; + PFNGLCREATEPROGRAMPROC_MT CreateProgram = NULL; + PFNGLCREATESHADERPROC_MT CreateShader = NULL; + PFNGLDELETEPROGRAMPROC_MT DeleteProgram = NULL; + PFNGLDELETESHADERPROC_MT DeleteShader = NULL; + PFNGLDETACHSHADERPROC_MT DetachShader = NULL; + PFNGLDISABLEVERTEXATTRIBARRAYPROC_MT DisableVertexAttribArray = NULL; + PFNGLENABLEVERTEXATTRIBARRAYPROC_MT EnableVertexAttribArray = NULL; + PFNGLGETACTIVEATTRIBPROC_MT GetActiveAttrib = NULL; + PFNGLGETACTIVEUNIFORMPROC_MT GetActiveUniform = NULL; + PFNGLGETATTACHEDSHADERSPROC_MT GetAttachedShaders = NULL; + PFNGLGETATTRIBLOCATIONPROC_MT GetAttribLocation = NULL; + PFNGLGETPROGRAMIVPROC_MT GetProgramiv = NULL; + PFNGLGETPROGRAMINFOLOGPROC_MT GetProgramInfoLog = NULL; + PFNGLGETSHADERIVPROC_MT GetShaderiv = NULL; + PFNGLGETSHADERINFOLOGPROC_MT GetShaderInfoLog = NULL; + PFNGLGETSHADERSOURCEPROC_MT GetShaderSource = NULL; + PFNGLGETUNIFORMLOCATIONPROC_MT GetUniformLocation = NULL; + PFNGLGETUNIFORMFVPROC_MT GetUniformfv = NULL; + PFNGLGETUNIFORMIVPROC_MT GetUniformiv = NULL; + PFNGLGETVERTEXATTRIBDVPROC_MT GetVertexAttribdv = NULL; + PFNGLGETVERTEXATTRIBFVPROC_MT GetVertexAttribfv = NULL; + PFNGLGETVERTEXATTRIBIVPROC_MT GetVertexAttribiv = NULL; + PFNGLGETVERTEXATTRIBPOINTERVPROC_MT GetVertexAttribPointerv = NULL; + PFNGLISPROGRAMPROC_MT IsProgram = NULL; + PFNGLISSHADERPROC_MT IsShader = NULL; + PFNGLLINKPROGRAMPROC_MT LinkProgram = NULL; + PFNGLSHADERSOURCEPROC_MT ShaderSource = NULL; + PFNGLUSEPROGRAMPROC_MT UseProgram = NULL; + PFNGLUNIFORM1FPROC_MT Uniform1f = NULL; + PFNGLUNIFORM2FPROC_MT Uniform2f = NULL; + PFNGLUNIFORM3FPROC_MT Uniform3f = NULL; + PFNGLUNIFORM4FPROC_MT Uniform4f = NULL; + PFNGLUNIFORM1IPROC_MT Uniform1i = NULL; + PFNGLUNIFORM2IPROC_MT Uniform2i = NULL; + PFNGLUNIFORM3IPROC_MT Uniform3i = NULL; + PFNGLUNIFORM4IPROC_MT Uniform4i = NULL; + PFNGLUNIFORM1FVPROC_MT Uniform1fv = NULL; + PFNGLUNIFORM2FVPROC_MT Uniform2fv = NULL; + PFNGLUNIFORM3FVPROC_MT Uniform3fv = NULL; + PFNGLUNIFORM4FVPROC_MT Uniform4fv = NULL; + PFNGLUNIFORM1IVPROC_MT Uniform1iv = NULL; + PFNGLUNIFORM2IVPROC_MT Uniform2iv = NULL; + PFNGLUNIFORM3IVPROC_MT Uniform3iv = NULL; + PFNGLUNIFORM4IVPROC_MT Uniform4iv = NULL; + PFNGLUNIFORMMATRIX2FVPROC_MT UniformMatrix2fv = NULL; + PFNGLUNIFORMMATRIX3FVPROC_MT UniformMatrix3fv = NULL; + PFNGLUNIFORMMATRIX4FVPROC_MT UniformMatrix4fv = NULL; + PFNGLVALIDATEPROGRAMPROC_MT ValidateProgram = NULL; + PFNGLVERTEXATTRIB1DPROC_MT VertexAttrib1d = NULL; + PFNGLVERTEXATTRIB1DVPROC_MT VertexAttrib1dv = NULL; + PFNGLVERTEXATTRIB1FPROC_MT VertexAttrib1f = NULL; + PFNGLVERTEXATTRIB1FVPROC_MT VertexAttrib1fv = NULL; + PFNGLVERTEXATTRIB1SPROC_MT VertexAttrib1s = NULL; + PFNGLVERTEXATTRIB1SVPROC_MT VertexAttrib1sv = NULL; + PFNGLVERTEXATTRIB2DPROC_MT VertexAttrib2d = NULL; + PFNGLVERTEXATTRIB2DVPROC_MT VertexAttrib2dv = NULL; + PFNGLVERTEXATTRIB2FPROC_MT VertexAttrib2f = NULL; + PFNGLVERTEXATTRIB2FVPROC_MT VertexAttrib2fv = NULL; + PFNGLVERTEXATTRIB2SPROC_MT VertexAttrib2s = NULL; + PFNGLVERTEXATTRIB2SVPROC_MT VertexAttrib2sv = NULL; + PFNGLVERTEXATTRIB3DPROC_MT VertexAttrib3d = NULL; + PFNGLVERTEXATTRIB3DVPROC_MT VertexAttrib3dv = NULL; + PFNGLVERTEXATTRIB3FPROC_MT VertexAttrib3f = NULL; + PFNGLVERTEXATTRIB3FVPROC_MT VertexAttrib3fv = NULL; + PFNGLVERTEXATTRIB3SPROC_MT VertexAttrib3s = NULL; + PFNGLVERTEXATTRIB3SVPROC_MT VertexAttrib3sv = NULL; + PFNGLVERTEXATTRIB4NBVPROC_MT VertexAttrib4Nbv = NULL; + PFNGLVERTEXATTRIB4NIVPROC_MT VertexAttrib4Niv = NULL; + PFNGLVERTEXATTRIB4NSVPROC_MT VertexAttrib4Nsv = NULL; + PFNGLVERTEXATTRIB4NUBPROC_MT VertexAttrib4Nub = NULL; + PFNGLVERTEXATTRIB4NUBVPROC_MT VertexAttrib4Nubv = NULL; + PFNGLVERTEXATTRIB4NUIVPROC_MT VertexAttrib4Nuiv = NULL; + PFNGLVERTEXATTRIB4NUSVPROC_MT VertexAttrib4Nusv = NULL; + PFNGLVERTEXATTRIB4BVPROC_MT VertexAttrib4bv = NULL; + PFNGLVERTEXATTRIB4DPROC_MT VertexAttrib4d = NULL; + PFNGLVERTEXATTRIB4DVPROC_MT VertexAttrib4dv = NULL; + PFNGLVERTEXATTRIB4FPROC_MT VertexAttrib4f = NULL; + PFNGLVERTEXATTRIB4FVPROC_MT VertexAttrib4fv = NULL; + PFNGLVERTEXATTRIB4IVPROC_MT VertexAttrib4iv = NULL; + PFNGLVERTEXATTRIB4SPROC_MT VertexAttrib4s = NULL; + PFNGLVERTEXATTRIB4SVPROC_MT VertexAttrib4sv = NULL; + PFNGLVERTEXATTRIB4UBVPROC_MT VertexAttrib4ubv = NULL; + PFNGLVERTEXATTRIB4UIVPROC_MT VertexAttrib4uiv = NULL; + PFNGLVERTEXATTRIB4USVPROC_MT VertexAttrib4usv = NULL; + PFNGLVERTEXATTRIBPOINTERPROC_MT VertexAttribPointer = NULL; + PFNGLUNIFORMMATRIX2X3FVPROC_MT UniformMatrix2x3fv = NULL; + PFNGLUNIFORMMATRIX3X2FVPROC_MT UniformMatrix3x2fv = NULL; + PFNGLUNIFORMMATRIX2X4FVPROC_MT UniformMatrix2x4fv = NULL; + PFNGLUNIFORMMATRIX4X2FVPROC_MT UniformMatrix4x2fv = NULL; + PFNGLUNIFORMMATRIX3X4FVPROC_MT UniformMatrix3x4fv = NULL; + PFNGLUNIFORMMATRIX4X3FVPROC_MT UniformMatrix4x3fv = NULL; + PFNGLCOLORMASKIPROC_MT ColorMaski = NULL; + PFNGLENABLEIPROC_MT Enablei = NULL; + PFNGLDISABLEIPROC_MT Disablei = NULL; + PFNGLISENABLEDIPROC_MT IsEnabledi = NULL; + PFNGLBEGINTRANSFORMFEEDBACKPROC_MT BeginTransformFeedback = NULL; + PFNGLENDTRANSFORMFEEDBACKPROC_MT EndTransformFeedback = NULL; + PFNGLBINDBUFFERRANGEPROC_MT BindBufferRange = NULL; + PFNGLBINDBUFFERBASEPROC_MT BindBufferBase = NULL; + PFNGLTRANSFORMFEEDBACKVARYINGSPROC_MT TransformFeedbackVaryings = NULL; + PFNGLGETTRANSFORMFEEDBACKVARYINGPROC_MT GetTransformFeedbackVarying = NULL; + PFNGLCLAMPCOLORPROC_MT ClampColor = NULL; + PFNGLBEGINCONDITIONALRENDERPROC_MT BeginConditionalRender = NULL; + PFNGLENDCONDITIONALRENDERPROC_MT EndConditionalRender = NULL; + PFNGLVERTEXATTRIBIPOINTERPROC_MT VertexAttribIPointer = NULL; + PFNGLGETVERTEXATTRIBIIVPROC_MT GetVertexAttribIiv = NULL; + PFNGLGETVERTEXATTRIBIUIVPROC_MT GetVertexAttribIuiv = NULL; + PFNGLVERTEXATTRIBI1IPROC_MT VertexAttribI1i = NULL; + PFNGLVERTEXATTRIBI2IPROC_MT VertexAttribI2i = NULL; + PFNGLVERTEXATTRIBI3IPROC_MT VertexAttribI3i = NULL; + PFNGLVERTEXATTRIBI4IPROC_MT VertexAttribI4i = NULL; + PFNGLVERTEXATTRIBI1UIPROC_MT VertexAttribI1ui = NULL; + PFNGLVERTEXATTRIBI2UIPROC_MT VertexAttribI2ui = NULL; + PFNGLVERTEXATTRIBI3UIPROC_MT VertexAttribI3ui = NULL; + PFNGLVERTEXATTRIBI4UIPROC_MT VertexAttribI4ui = NULL; + PFNGLVERTEXATTRIBI1IVPROC_MT VertexAttribI1iv = NULL; + PFNGLVERTEXATTRIBI2IVPROC_MT VertexAttribI2iv = NULL; + PFNGLVERTEXATTRIBI3IVPROC_MT VertexAttribI3iv = NULL; + PFNGLVERTEXATTRIBI4IVPROC_MT VertexAttribI4iv = NULL; + PFNGLVERTEXATTRIBI1UIVPROC_MT VertexAttribI1uiv = NULL; + PFNGLVERTEXATTRIBI2UIVPROC_MT VertexAttribI2uiv = NULL; + PFNGLVERTEXATTRIBI3UIVPROC_MT VertexAttribI3uiv = NULL; + PFNGLVERTEXATTRIBI4UIVPROC_MT VertexAttribI4uiv = NULL; + PFNGLVERTEXATTRIBI4BVPROC_MT VertexAttribI4bv = NULL; + PFNGLVERTEXATTRIBI4SVPROC_MT VertexAttribI4sv = NULL; + PFNGLVERTEXATTRIBI4UBVPROC_MT VertexAttribI4ubv = NULL; + PFNGLVERTEXATTRIBI4USVPROC_MT VertexAttribI4usv = NULL; + PFNGLGETUNIFORMUIVPROC_MT GetUniformuiv = NULL; + PFNGLBINDFRAGDATALOCATIONPROC_MT BindFragDataLocation = NULL; + PFNGLGETFRAGDATALOCATIONPROC_MT GetFragDataLocation = NULL; + PFNGLUNIFORM1UIPROC_MT Uniform1ui = NULL; + PFNGLUNIFORM2UIPROC_MT Uniform2ui = NULL; + PFNGLUNIFORM3UIPROC_MT Uniform3ui = NULL; + PFNGLUNIFORM4UIPROC_MT Uniform4ui = NULL; + PFNGLUNIFORM1UIVPROC_MT Uniform1uiv = NULL; + PFNGLUNIFORM2UIVPROC_MT Uniform2uiv = NULL; + PFNGLUNIFORM3UIVPROC_MT Uniform3uiv = NULL; + PFNGLUNIFORM4UIVPROC_MT Uniform4uiv = NULL; + PFNGLTEXPARAMETERIIVPROC_MT TexParameterIiv = NULL; + PFNGLTEXPARAMETERIUIVPROC_MT TexParameterIuiv = NULL; + PFNGLGETTEXPARAMETERIIVPROC_MT GetTexParameterIiv = NULL; + PFNGLGETTEXPARAMETERIUIVPROC_MT GetTexParameterIuiv = NULL; + PFNGLCLEARBUFFERIVPROC_MT ClearBufferiv = NULL; + PFNGLCLEARBUFFERUIVPROC_MT ClearBufferuiv = NULL; + PFNGLCLEARBUFFERFVPROC_MT ClearBufferfv = NULL; + PFNGLCLEARBUFFERFIPROC_MT ClearBufferfi = NULL; + PFNGLGETSTRINGIPROC_MT GetStringi = NULL; + PFNGLISRENDERBUFFERPROC_MT IsRenderbuffer = NULL; + PFNGLBINDRENDERBUFFERPROC_MT BindRenderbuffer = NULL; + PFNGLDELETERENDERBUFFERSPROC_MT DeleteRenderbuffers = NULL; + PFNGLGENRENDERBUFFERSPROC_MT GenRenderbuffers = NULL; + PFNGLRENDERBUFFERSTORAGEPROC_MT RenderbufferStorage = NULL; + PFNGLGETRENDERBUFFERPARAMETERIVPROC_MT GetRenderbufferParameteriv = NULL; + PFNGLISFRAMEBUFFERPROC_MT IsFramebuffer = NULL; + PFNGLBINDFRAMEBUFFERPROC_MT BindFramebuffer = NULL; + PFNGLDELETEFRAMEBUFFERSPROC_MT DeleteFramebuffers = NULL; + PFNGLGENFRAMEBUFFERSPROC_MT GenFramebuffers = NULL; + PFNGLCHECKFRAMEBUFFERSTATUSPROC_MT CheckFramebufferStatus = NULL; + PFNGLFRAMEBUFFERTEXTURE1DPROC_MT FramebufferTexture1D = NULL; + PFNGLFRAMEBUFFERTEXTURE2DPROC_MT FramebufferTexture2D = NULL; + PFNGLFRAMEBUFFERTEXTURE3DPROC_MT FramebufferTexture3D = NULL; + PFNGLFRAMEBUFFERRENDERBUFFERPROC_MT FramebufferRenderbuffer = NULL; + PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC_MT GetFramebufferAttachmentParameteriv = NULL; + PFNGLGENERATEMIPMAPPROC_MT GenerateMipmap = NULL; + PFNGLBLITFRAMEBUFFERPROC_MT BlitFramebuffer = NULL; + PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC_MT RenderbufferStorageMultisample = NULL; + PFNGLFRAMEBUFFERTEXTURELAYERPROC_MT FramebufferTextureLayer = NULL; + PFNGLMAPBUFFERRANGEPROC_MT MapBufferRange = NULL; + PFNGLFLUSHMAPPEDBUFFERRANGEPROC_MT FlushMappedBufferRange = NULL; + PFNGLBINDVERTEXARRAYPROC_MT BindVertexArray = NULL; + PFNGLDELETEVERTEXARRAYSPROC_MT DeleteVertexArrays = NULL; + PFNGLGENVERTEXARRAYSPROC_MT GenVertexArrays = NULL; + PFNGLISVERTEXARRAYPROC_MT IsVertexArray = NULL; + PFNGLDRAWARRAYSINSTANCEDPROC_MT DrawArraysInstanced = NULL; + PFNGLDRAWELEMENTSINSTANCEDPROC_MT DrawElementsInstanced = NULL; + PFNGLTEXBUFFERPROC_MT TexBuffer = NULL; + PFNGLPRIMITIVERESTARTINDEXPROC_MT PrimitiveRestartIndex = NULL; + PFNGLCOPYBUFFERSUBDATAPROC_MT CopyBufferSubData = NULL; + PFNGLGETUNIFORMINDICESPROC_MT GetUniformIndices = NULL; + PFNGLGETACTIVEUNIFORMSIVPROC_MT GetActiveUniformsiv = NULL; + PFNGLGETACTIVEUNIFORMNAMEPROC_MT GetActiveUniformName = NULL; + PFNGLGETUNIFORMBLOCKINDEXPROC_MT GetUniformBlockIndex = NULL; + PFNGLGETACTIVEUNIFORMBLOCKIVPROC_MT GetActiveUniformBlockiv = NULL; + PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC_MT GetActiveUniformBlockName = NULL; + PFNGLUNIFORMBLOCKBINDINGPROC_MT UniformBlockBinding = NULL; + PFNGLDRAWELEMENTSBASEVERTEXPROC_MT DrawElementsBaseVertex = NULL; + PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC_MT DrawRangeElementsBaseVertex = NULL; + PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC_MT DrawElementsInstancedBaseVertex = NULL; + PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC_MT MultiDrawElementsBaseVertex = NULL; + PFNGLPROVOKINGVERTEXPROC_MT ProvokingVertex = NULL; + PFNGLFENCESYNCPROC_MT FenceSync = NULL; + PFNGLISSYNCPROC_MT IsSync = NULL; + PFNGLDELETESYNCPROC_MT DeleteSync = NULL; + PFNGLCLIENTWAITSYNCPROC_MT ClientWaitSync = NULL; + PFNGLWAITSYNCPROC_MT WaitSync = NULL; + PFNGLGETINTEGER64VPROC_MT GetInteger64v = NULL; + PFNGLGETSYNCIVPROC_MT GetSynciv = NULL; + PFNGLGETBUFFERPARAMETERI64VPROC_MT GetBufferParameteri64v = NULL; + PFNGLFRAMEBUFFERTEXTUREPROC_MT FramebufferTexture = NULL; + PFNGLTEXIMAGE2DMULTISAMPLEPROC_MT TexImage2DMultisample = NULL; + PFNGLTEXIMAGE3DMULTISAMPLEPROC_MT TexImage3DMultisample = NULL; + PFNGLGETMULTISAMPLEFVPROC_MT GetMultisamplefv = NULL; + PFNGLSAMPLEMASKIPROC_MT SampleMaski = NULL; + PFNGLBINDFRAGDATALOCATIONINDEXEDPROC_MT BindFragDataLocationIndexed = NULL; + PFNGLGETFRAGDATAINDEXPROC_MT GetFragDataIndex = NULL; + PFNGLGENSAMPLERSPROC_MT GenSamplers = NULL; + PFNGLDELETESAMPLERSPROC_MT DeleteSamplers = NULL; + PFNGLISSAMPLERPROC_MT IsSampler = NULL; + PFNGLBINDSAMPLERPROC_MT BindSampler = NULL; + PFNGLSAMPLERPARAMETERIPROC_MT SamplerParameteri = NULL; + PFNGLSAMPLERPARAMETERIVPROC_MT SamplerParameteriv = NULL; + PFNGLSAMPLERPARAMETERFPROC_MT SamplerParameterf = NULL; + PFNGLSAMPLERPARAMETERFVPROC_MT SamplerParameterfv = NULL; + PFNGLSAMPLERPARAMETERIIVPROC_MT SamplerParameterIiv = NULL; + PFNGLSAMPLERPARAMETERIUIVPROC_MT SamplerParameterIuiv = NULL; + PFNGLGETSAMPLERPARAMETERIVPROC_MT GetSamplerParameteriv = NULL; + PFNGLGETSAMPLERPARAMETERIIVPROC_MT GetSamplerParameterIiv = NULL; + PFNGLGETSAMPLERPARAMETERFVPROC_MT GetSamplerParameterfv = NULL; + PFNGLGETSAMPLERPARAMETERIUIVPROC_MT GetSamplerParameterIuiv = NULL; + PFNGLQUERYCOUNTERPROC_MT QueryCounter = NULL; + PFNGLGETQUERYOBJECTI64VPROC_MT GetQueryObjecti64v = NULL; + PFNGLGETQUERYOBJECTUI64VPROC_MT GetQueryObjectui64v = NULL; + PFNGLVERTEXATTRIBDIVISORPROC_MT VertexAttribDivisor = NULL; + PFNGLVERTEXATTRIBP1UIPROC_MT VertexAttribP1ui = NULL; + PFNGLVERTEXATTRIBP1UIVPROC_MT VertexAttribP1uiv = NULL; + PFNGLVERTEXATTRIBP2UIPROC_MT VertexAttribP2ui = NULL; + PFNGLVERTEXATTRIBP2UIVPROC_MT VertexAttribP2uiv = NULL; + PFNGLVERTEXATTRIBP3UIPROC_MT VertexAttribP3ui = NULL; + PFNGLVERTEXATTRIBP3UIVPROC_MT VertexAttribP3uiv = NULL; + PFNGLVERTEXATTRIBP4UIPROC_MT VertexAttribP4ui = NULL; + PFNGLVERTEXATTRIBP4UIVPROC_MT VertexAttribP4uiv = NULL; + PFNGLMINSAMPLESHADINGPROC_MT MinSampleShading = NULL; + PFNGLBLENDEQUATIONIPROC_MT BlendEquationi = NULL; + PFNGLBLENDEQUATIONSEPARATEIPROC_MT BlendEquationSeparatei = NULL; + PFNGLBLENDFUNCIPROC_MT BlendFunci = NULL; + PFNGLBLENDFUNCSEPARATEIPROC_MT BlendFuncSeparatei = NULL; + PFNGLDRAWARRAYSINDIRECTPROC_MT DrawArraysIndirect = NULL; + PFNGLDRAWELEMENTSINDIRECTPROC_MT DrawElementsIndirect = NULL; + PFNGLUNIFORM1DPROC_MT Uniform1d = NULL; + PFNGLUNIFORM2DPROC_MT Uniform2d = NULL; + PFNGLUNIFORM3DPROC_MT Uniform3d = NULL; + PFNGLUNIFORM4DPROC_MT Uniform4d = NULL; + PFNGLUNIFORM1DVPROC_MT Uniform1dv = NULL; + PFNGLUNIFORM2DVPROC_MT Uniform2dv = NULL; + PFNGLUNIFORM3DVPROC_MT Uniform3dv = NULL; + PFNGLUNIFORM4DVPROC_MT Uniform4dv = NULL; + PFNGLUNIFORMMATRIX2DVPROC_MT UniformMatrix2dv = NULL; + PFNGLUNIFORMMATRIX3DVPROC_MT UniformMatrix3dv = NULL; + PFNGLUNIFORMMATRIX4DVPROC_MT UniformMatrix4dv = NULL; + PFNGLUNIFORMMATRIX2X3DVPROC_MT UniformMatrix2x3dv = NULL; + PFNGLUNIFORMMATRIX2X4DVPROC_MT UniformMatrix2x4dv = NULL; + PFNGLUNIFORMMATRIX3X2DVPROC_MT UniformMatrix3x2dv = NULL; + PFNGLUNIFORMMATRIX3X4DVPROC_MT UniformMatrix3x4dv = NULL; + PFNGLUNIFORMMATRIX4X2DVPROC_MT UniformMatrix4x2dv = NULL; + PFNGLUNIFORMMATRIX4X3DVPROC_MT UniformMatrix4x3dv = NULL; + PFNGLGETUNIFORMDVPROC_MT GetUniformdv = NULL; + PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC_MT GetSubroutineUniformLocation = NULL; + PFNGLGETSUBROUTINEINDEXPROC_MT GetSubroutineIndex = NULL; + PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC_MT GetActiveSubroutineUniformiv = NULL; + PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC_MT GetActiveSubroutineUniformName = NULL; + PFNGLGETACTIVESUBROUTINENAMEPROC_MT GetActiveSubroutineName = NULL; + PFNGLUNIFORMSUBROUTINESUIVPROC_MT UniformSubroutinesuiv = NULL; + PFNGLGETUNIFORMSUBROUTINEUIVPROC_MT GetUniformSubroutineuiv = NULL; + PFNGLGETPROGRAMSTAGEIVPROC_MT GetProgramStageiv = NULL; + PFNGLPATCHPARAMETERIPROC_MT PatchParameteri = NULL; + PFNGLPATCHPARAMETERFVPROC_MT PatchParameterfv = NULL; + PFNGLBINDTRANSFORMFEEDBACKPROC_MT BindTransformFeedback = NULL; + PFNGLDELETETRANSFORMFEEDBACKSPROC_MT DeleteTransformFeedbacks = NULL; + PFNGLGENTRANSFORMFEEDBACKSPROC_MT GenTransformFeedbacks = NULL; + PFNGLISTRANSFORMFEEDBACKPROC_MT IsTransformFeedback = NULL; + PFNGLPAUSETRANSFORMFEEDBACKPROC_MT PauseTransformFeedback = NULL; + PFNGLRESUMETRANSFORMFEEDBACKPROC_MT ResumeTransformFeedback = NULL; + PFNGLDRAWTRANSFORMFEEDBACKPROC_MT DrawTransformFeedback = NULL; + PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC_MT DrawTransformFeedbackStream = NULL; + PFNGLBEGINQUERYINDEXEDPROC_MT BeginQueryIndexed = NULL; + PFNGLENDQUERYINDEXEDPROC_MT EndQueryIndexed = NULL; + PFNGLGETQUERYINDEXEDIVPROC_MT GetQueryIndexediv = NULL; + PFNGLRELEASESHADERCOMPILERPROC_MT ReleaseShaderCompiler = NULL; + PFNGLSHADERBINARYPROC_MT ShaderBinary = NULL; + PFNGLGETSHADERPRECISIONFORMATPROC_MT GetShaderPrecisionFormat = NULL; + PFNGLDEPTHRANGEFPROC_MT DepthRangef = NULL; + PFNGLCLEARDEPTHFPROC_MT ClearDepthf = NULL; + PFNGLGETPROGRAMBINARYPROC_MT GetProgramBinary = NULL; + PFNGLPROGRAMBINARYPROC_MT ProgramBinary = NULL; + PFNGLPROGRAMPARAMETERIPROC_MT ProgramParameteri = NULL; + PFNGLUSEPROGRAMSTAGESPROC_MT UseProgramStages = NULL; + PFNGLACTIVESHADERPROGRAMPROC_MT ActiveShaderProgram = NULL; + PFNGLCREATESHADERPROGRAMVPROC_MT CreateShaderProgramv = NULL; + PFNGLBINDPROGRAMPIPELINEPROC_MT BindProgramPipeline = NULL; + PFNGLDELETEPROGRAMPIPELINESPROC_MT DeleteProgramPipelines = NULL; + PFNGLGENPROGRAMPIPELINESPROC_MT GenProgramPipelines = NULL; + PFNGLISPROGRAMPIPELINEPROC_MT IsProgramPipeline = NULL; + PFNGLGETPROGRAMPIPELINEIVPROC_MT GetProgramPipelineiv = NULL; + PFNGLPROGRAMUNIFORM1IPROC_MT ProgramUniform1i = NULL; + PFNGLPROGRAMUNIFORM1IVPROC_MT ProgramUniform1iv = NULL; + PFNGLPROGRAMUNIFORM1FPROC_MT ProgramUniform1f = NULL; + PFNGLPROGRAMUNIFORM1FVPROC_MT ProgramUniform1fv = NULL; + PFNGLPROGRAMUNIFORM1DPROC_MT ProgramUniform1d = NULL; + PFNGLPROGRAMUNIFORM1DVPROC_MT ProgramUniform1dv = NULL; + PFNGLPROGRAMUNIFORM1UIPROC_MT ProgramUniform1ui = NULL; + PFNGLPROGRAMUNIFORM1UIVPROC_MT ProgramUniform1uiv = NULL; + PFNGLPROGRAMUNIFORM2IPROC_MT ProgramUniform2i = NULL; + PFNGLPROGRAMUNIFORM2IVPROC_MT ProgramUniform2iv = NULL; + PFNGLPROGRAMUNIFORM2FPROC_MT ProgramUniform2f = NULL; + PFNGLPROGRAMUNIFORM2FVPROC_MT ProgramUniform2fv = NULL; + PFNGLPROGRAMUNIFORM2DPROC_MT ProgramUniform2d = NULL; + PFNGLPROGRAMUNIFORM2DVPROC_MT ProgramUniform2dv = NULL; + PFNGLPROGRAMUNIFORM2UIPROC_MT ProgramUniform2ui = NULL; + PFNGLPROGRAMUNIFORM2UIVPROC_MT ProgramUniform2uiv = NULL; + PFNGLPROGRAMUNIFORM3IPROC_MT ProgramUniform3i = NULL; + PFNGLPROGRAMUNIFORM3IVPROC_MT ProgramUniform3iv = NULL; + PFNGLPROGRAMUNIFORM3FPROC_MT ProgramUniform3f = NULL; + PFNGLPROGRAMUNIFORM3FVPROC_MT ProgramUniform3fv = NULL; + PFNGLPROGRAMUNIFORM3DPROC_MT ProgramUniform3d = NULL; + PFNGLPROGRAMUNIFORM3DVPROC_MT ProgramUniform3dv = NULL; + PFNGLPROGRAMUNIFORM3UIPROC_MT ProgramUniform3ui = NULL; + PFNGLPROGRAMUNIFORM3UIVPROC_MT ProgramUniform3uiv = NULL; + PFNGLPROGRAMUNIFORM4IPROC_MT ProgramUniform4i = NULL; + PFNGLPROGRAMUNIFORM4IVPROC_MT ProgramUniform4iv = NULL; + PFNGLPROGRAMUNIFORM4FPROC_MT ProgramUniform4f = NULL; + PFNGLPROGRAMUNIFORM4FVPROC_MT ProgramUniform4fv = NULL; + PFNGLPROGRAMUNIFORM4DPROC_MT ProgramUniform4d = NULL; + PFNGLPROGRAMUNIFORM4DVPROC_MT ProgramUniform4dv = NULL; + PFNGLPROGRAMUNIFORM4UIPROC_MT ProgramUniform4ui = NULL; + PFNGLPROGRAMUNIFORM4UIVPROC_MT ProgramUniform4uiv = NULL; + PFNGLPROGRAMUNIFORMMATRIX2FVPROC_MT ProgramUniformMatrix2fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX3FVPROC_MT ProgramUniformMatrix3fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX4FVPROC_MT ProgramUniformMatrix4fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX2DVPROC_MT ProgramUniformMatrix2dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX3DVPROC_MT ProgramUniformMatrix3dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX4DVPROC_MT ProgramUniformMatrix4dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC_MT ProgramUniformMatrix2x3fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC_MT ProgramUniformMatrix3x2fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC_MT ProgramUniformMatrix2x4fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC_MT ProgramUniformMatrix4x2fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC_MT ProgramUniformMatrix3x4fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC_MT ProgramUniformMatrix4x3fv = NULL; + PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC_MT ProgramUniformMatrix2x3dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC_MT ProgramUniformMatrix3x2dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC_MT ProgramUniformMatrix2x4dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC_MT ProgramUniformMatrix4x2dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC_MT ProgramUniformMatrix3x4dv = NULL; + PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC_MT ProgramUniformMatrix4x3dv = NULL; + PFNGLVALIDATEPROGRAMPIPELINEPROC_MT ValidateProgramPipeline = NULL; + PFNGLGETPROGRAMPIPELINEINFOLOGPROC_MT GetProgramPipelineInfoLog = NULL; + PFNGLVERTEXATTRIBL1DPROC_MT VertexAttribL1d = NULL; + PFNGLVERTEXATTRIBL2DPROC_MT VertexAttribL2d = NULL; + PFNGLVERTEXATTRIBL3DPROC_MT VertexAttribL3d = NULL; + PFNGLVERTEXATTRIBL4DPROC_MT VertexAttribL4d = NULL; + PFNGLVERTEXATTRIBL1DVPROC_MT VertexAttribL1dv = NULL; + PFNGLVERTEXATTRIBL2DVPROC_MT VertexAttribL2dv = NULL; + PFNGLVERTEXATTRIBL3DVPROC_MT VertexAttribL3dv = NULL; + PFNGLVERTEXATTRIBL4DVPROC_MT VertexAttribL4dv = NULL; + PFNGLVERTEXATTRIBLPOINTERPROC_MT VertexAttribLPointer = NULL; + PFNGLGETVERTEXATTRIBLDVPROC_MT GetVertexAttribLdv = NULL; + PFNGLVIEWPORTARRAYVPROC_MT ViewportArrayv = NULL; + PFNGLVIEWPORTINDEXEDFPROC_MT ViewportIndexedf = NULL; + PFNGLVIEWPORTINDEXEDFVPROC_MT ViewportIndexedfv = NULL; + PFNGLSCISSORARRAYVPROC_MT ScissorArrayv = NULL; + PFNGLSCISSORINDEXEDPROC_MT ScissorIndexed = NULL; + PFNGLSCISSORINDEXEDVPROC_MT ScissorIndexedv = NULL; + PFNGLDEPTHRANGEARRAYVPROC_MT DepthRangeArrayv = NULL; + PFNGLDEPTHRANGEINDEXEDPROC_MT DepthRangeIndexed = NULL; + PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC_MT DrawArraysInstancedBaseInstance = NULL; + PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC_MT DrawElementsInstancedBaseInstance = NULL; + PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC_MT DrawElementsInstancedBaseVertexBaseInstance = NULL; + PFNGLGETINTERNALFORMATIVPROC_MT GetInternalformativ = NULL; + PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC_MT GetActiveAtomicCounterBufferiv = NULL; + PFNGLBINDIMAGETEXTUREPROC_MT BindImageTexture = NULL; + PFNGLMEMORYBARRIERPROC_MT MemoryBarrier = NULL; + PFNGLTEXSTORAGE1DPROC_MT TexStorage1D = NULL; + PFNGLTEXSTORAGE2DPROC_MT TexStorage2D = NULL; + PFNGLTEXSTORAGE3DPROC_MT TexStorage3D = NULL; + PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC_MT DrawTransformFeedbackInstanced = NULL; + PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC_MT DrawTransformFeedbackStreamInstanced = NULL; + PFNGLCLEARBUFFERDATAPROC_MT ClearBufferData = NULL; + PFNGLCLEARBUFFERSUBDATAPROC_MT ClearBufferSubData = NULL; + PFNGLDISPATCHCOMPUTEPROC_MT DispatchCompute = NULL; + PFNGLDISPATCHCOMPUTEINDIRECTPROC_MT DispatchComputeIndirect = NULL; + PFNGLCOPYIMAGESUBDATAPROC_MT CopyImageSubData = NULL; + PFNGLFRAMEBUFFERPARAMETERIPROC_MT FramebufferParameteri = NULL; + PFNGLGETFRAMEBUFFERPARAMETERIVPROC_MT GetFramebufferParameteriv = NULL; + PFNGLGETINTERNALFORMATI64VPROC_MT GetInternalformati64v = NULL; + PFNGLINVALIDATETEXSUBIMAGEPROC_MT InvalidateTexSubImage = NULL; + PFNGLINVALIDATETEXIMAGEPROC_MT InvalidateTexImage = NULL; + PFNGLINVALIDATEBUFFERSUBDATAPROC_MT InvalidateBufferSubData = NULL; + PFNGLINVALIDATEBUFFERDATAPROC_MT InvalidateBufferData = NULL; + PFNGLINVALIDATEFRAMEBUFFERPROC_MT InvalidateFramebuffer = NULL; + PFNGLINVALIDATESUBFRAMEBUFFERPROC_MT InvalidateSubFramebuffer = NULL; + PFNGLMULTIDRAWARRAYSINDIRECTPROC_MT MultiDrawArraysIndirect = NULL; + PFNGLMULTIDRAWELEMENTSINDIRECTPROC_MT MultiDrawElementsIndirect = NULL; + PFNGLGETPROGRAMINTERFACEIVPROC_MT GetProgramInterfaceiv = NULL; + PFNGLGETPROGRAMRESOURCEINDEXPROC_MT GetProgramResourceIndex = NULL; + PFNGLGETPROGRAMRESOURCENAMEPROC_MT GetProgramResourceName = NULL; + PFNGLGETPROGRAMRESOURCEIVPROC_MT GetProgramResourceiv = NULL; + PFNGLGETPROGRAMRESOURCELOCATIONPROC_MT GetProgramResourceLocation = NULL; + PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC_MT GetProgramResourceLocationIndex = NULL; + PFNGLSHADERSTORAGEBLOCKBINDINGPROC_MT ShaderStorageBlockBinding = NULL; + PFNGLTEXBUFFERRANGEPROC_MT TexBufferRange = NULL; + PFNGLTEXSTORAGE2DMULTISAMPLEPROC_MT TexStorage2DMultisample = NULL; + PFNGLTEXSTORAGE3DMULTISAMPLEPROC_MT TexStorage3DMultisample = NULL; + PFNGLTEXTUREVIEWPROC_MT TextureView = NULL; + PFNGLBINDVERTEXBUFFERPROC_MT BindVertexBuffer = NULL; + PFNGLVERTEXATTRIBFORMATPROC_MT VertexAttribFormat = NULL; + PFNGLVERTEXATTRIBIFORMATPROC_MT VertexAttribIFormat = NULL; + PFNGLVERTEXATTRIBLFORMATPROC_MT VertexAttribLFormat = NULL; + PFNGLVERTEXATTRIBBINDINGPROC_MT VertexAttribBinding = NULL; + PFNGLVERTEXBINDINGDIVISORPROC_MT VertexBindingDivisor = NULL; + PFNGLDEBUGMESSAGECONTROLPROC_MT DebugMessageControl = NULL; + PFNGLDEBUGMESSAGEINSERTPROC_MT DebugMessageInsert = NULL; + PFNGLDEBUGMESSAGECALLBACKPROC_MT DebugMessageCallback = NULL; + PFNGLGETDEBUGMESSAGELOGPROC_MT GetDebugMessageLog = NULL; + PFNGLPUSHDEBUGGROUPPROC_MT PushDebugGroup = NULL; + PFNGLPOPDEBUGGROUPPROC_MT PopDebugGroup = NULL; + PFNGLOBJECTLABELPROC_MT ObjectLabel = NULL; + PFNGLGETOBJECTLABELPROC_MT GetObjectLabel = NULL; + PFNGLOBJECTPTRLABELPROC_MT ObjectPtrLabel = NULL; + PFNGLGETOBJECTPTRLABELPROC_MT GetObjectPtrLabel = NULL; + PFNGLBUFFERSTORAGEPROC_MT BufferStorage = NULL; + PFNGLCLEARTEXIMAGEPROC_MT ClearTexImage = NULL; + PFNGLCLEARTEXSUBIMAGEPROC_MT ClearTexSubImage = NULL; + PFNGLBINDBUFFERSBASEPROC_MT BindBuffersBase = NULL; + PFNGLBINDBUFFERSRANGEPROC_MT BindBuffersRange = NULL; + PFNGLBINDTEXTURESPROC_MT BindTextures = NULL; + PFNGLBINDSAMPLERSPROC_MT BindSamplers = NULL; + PFNGLBINDIMAGETEXTURESPROC_MT BindImageTextures = NULL; + PFNGLBINDVERTEXBUFFERSPROC_MT BindVertexBuffers = NULL; + PFNGLCLIPCONTROLPROC_MT ClipControl = NULL; + PFNGLCREATETRANSFORMFEEDBACKSPROC_MT CreateTransformFeedbacks = NULL; + PFNGLTRANSFORMFEEDBACKBUFFERBASEPROC_MT TransformFeedbackBufferBase = NULL; + PFNGLTRANSFORMFEEDBACKBUFFERRANGEPROC_MT TransformFeedbackBufferRange = NULL; + PFNGLGETTRANSFORMFEEDBACKIVPROC_MT GetTransformFeedbackiv = NULL; + PFNGLCREATEBUFFERSPROC_MT CreateBuffers = NULL; + PFNGLNAMEDBUFFERSTORAGEPROC_MT NamedBufferStorage = NULL; + PFNGLNAMEDBUFFERDATAPROC_MT NamedBufferData = NULL; + PFNGLNAMEDBUFFERSUBDATAPROC_MT NamedBufferSubData = NULL; + PFNGLCOPYNAMEDBUFFERSUBDATAPROC_MT CopyNamedBufferSubData = NULL; + PFNGLCLEARNAMEDBUFFERDATAPROC_MT ClearNamedBufferData = NULL; + PFNGLCLEARNAMEDBUFFERSUBDATAPROC_MT ClearNamedBufferSubData = NULL; + PFNGLMAPNAMEDBUFFERPROC_MT MapNamedBuffer = NULL; + PFNGLMAPNAMEDBUFFERRANGEPROC_MT MapNamedBufferRange = NULL; + PFNGLUNMAPNAMEDBUFFERPROC_MT UnmapNamedBuffer = NULL; + PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEPROC_MT FlushMappedNamedBufferRange = NULL; + PFNGLGETNAMEDBUFFERPARAMETERIVPROC_MT GetNamedBufferParameteriv = NULL; + PFNGLGETNAMEDBUFFERPARAMETERI64VPROC_MT GetNamedBufferParameteri64v = NULL; + PFNGLGETNAMEDBUFFERPOINTERVPROC_MT GetNamedBufferPointerv = NULL; + PFNGLGETNAMEDBUFFERSUBDATAPROC_MT GetNamedBufferSubData = NULL; + PFNGLCREATEFRAMEBUFFERSPROC_MT CreateFramebuffers = NULL; + PFNGLNAMEDFRAMEBUFFERRENDERBUFFERPROC_MT NamedFramebufferRenderbuffer = NULL; + PFNGLNAMEDFRAMEBUFFERPARAMETERIPROC_MT NamedFramebufferParameteri = NULL; + PFNGLNAMEDFRAMEBUFFERTEXTUREPROC_MT NamedFramebufferTexture = NULL; + PFNGLNAMEDFRAMEBUFFERTEXTURELAYERPROC_MT NamedFramebufferTextureLayer = NULL; + PFNGLNAMEDFRAMEBUFFERDRAWBUFFERPROC_MT NamedFramebufferDrawBuffer = NULL; + PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC_MT NamedFramebufferDrawBuffers = NULL; + PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC_MT NamedFramebufferReadBuffer = NULL; + PFNGLINVALIDATENAMEDFRAMEBUFFERDATAPROC_MT InvalidateNamedFramebufferData = NULL; + PFNGLINVALIDATENAMEDFRAMEBUFFERSUBDATAPROC_MT InvalidateNamedFramebufferSubData = NULL; + PFNGLCLEARNAMEDFRAMEBUFFERIVPROC_MT ClearNamedFramebufferiv = NULL; + PFNGLCLEARNAMEDFRAMEBUFFERUIVPROC_MT ClearNamedFramebufferuiv = NULL; + PFNGLCLEARNAMEDFRAMEBUFFERFVPROC_MT ClearNamedFramebufferfv = NULL; + PFNGLCLEARNAMEDFRAMEBUFFERFIPROC_MT ClearNamedFramebufferfi = NULL; + PFNGLBLITNAMEDFRAMEBUFFERPROC_MT BlitNamedFramebuffer = NULL; + PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC_MT CheckNamedFramebufferStatus = NULL; + PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVPROC_MT GetNamedFramebufferParameteriv = NULL; + PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVPROC_MT GetNamedFramebufferAttachmentParameteriv = NULL; + PFNGLCREATERENDERBUFFERSPROC_MT CreateRenderbuffers = NULL; + PFNGLNAMEDRENDERBUFFERSTORAGEPROC_MT NamedRenderbufferStorage = NULL; + PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEPROC_MT NamedRenderbufferStorageMultisample = NULL; + PFNGLGETNAMEDRENDERBUFFERPARAMETERIVPROC_MT GetNamedRenderbufferParameteriv = NULL; + PFNGLCREATETEXTURESPROC_MT CreateTextures = NULL; + PFNGLTEXTUREBUFFERPROC_MT TextureBuffer = NULL; + PFNGLTEXTUREBUFFERRANGEPROC_MT TextureBufferRange = NULL; + PFNGLTEXTURESTORAGE1DPROC_MT TextureStorage1D = NULL; + PFNGLTEXTURESTORAGE2DPROC_MT TextureStorage2D = NULL; + PFNGLTEXTURESTORAGE3DPROC_MT TextureStorage3D = NULL; + PFNGLTEXTURESTORAGE2DMULTISAMPLEPROC_MT TextureStorage2DMultisample = NULL; + PFNGLTEXTURESTORAGE3DMULTISAMPLEPROC_MT TextureStorage3DMultisample = NULL; + PFNGLTEXTURESUBIMAGE1DPROC_MT TextureSubImage1D = NULL; + PFNGLTEXTURESUBIMAGE2DPROC_MT TextureSubImage2D = NULL; + PFNGLTEXTURESUBIMAGE3DPROC_MT TextureSubImage3D = NULL; + PFNGLCOMPRESSEDTEXTURESUBIMAGE1DPROC_MT CompressedTextureSubImage1D = NULL; + PFNGLCOMPRESSEDTEXTURESUBIMAGE2DPROC_MT CompressedTextureSubImage2D = NULL; + PFNGLCOMPRESSEDTEXTURESUBIMAGE3DPROC_MT CompressedTextureSubImage3D = NULL; + PFNGLCOPYTEXTURESUBIMAGE1DPROC_MT CopyTextureSubImage1D = NULL; + PFNGLCOPYTEXTURESUBIMAGE2DPROC_MT CopyTextureSubImage2D = NULL; + PFNGLCOPYTEXTURESUBIMAGE3DPROC_MT CopyTextureSubImage3D = NULL; + PFNGLTEXTUREPARAMETERFPROC_MT TextureParameterf = NULL; + PFNGLTEXTUREPARAMETERFVPROC_MT TextureParameterfv = NULL; + PFNGLTEXTUREPARAMETERIPROC_MT TextureParameteri = NULL; + PFNGLTEXTUREPARAMETERIIVPROC_MT TextureParameterIiv = NULL; + PFNGLTEXTUREPARAMETERIUIVPROC_MT TextureParameterIuiv = NULL; + PFNGLTEXTUREPARAMETERIVPROC_MT TextureParameteriv = NULL; + PFNGLGENERATETEXTUREMIPMAPPROC_MT GenerateTextureMipmap = NULL; + PFNGLBINDTEXTUREUNITPROC_MT BindTextureUnit = NULL; + PFNGLGETTEXTUREIMAGEPROC_MT GetTextureImage = NULL; + PFNGLGETCOMPRESSEDTEXTUREIMAGEPROC_MT GetCompressedTextureImage = NULL; + PFNGLGETTEXTURELEVELPARAMETERFVPROC_MT GetTextureLevelParameterfv = NULL; + PFNGLGETTEXTURELEVELPARAMETERIVPROC_MT GetTextureLevelParameteriv = NULL; + PFNGLGETTEXTUREPARAMETERFVPROC_MT GetTextureParameterfv = NULL; + PFNGLGETTEXTUREPARAMETERIIVPROC_MT GetTextureParameterIiv = NULL; + PFNGLGETTEXTUREPARAMETERIUIVPROC_MT GetTextureParameterIuiv = NULL; + PFNGLGETTEXTUREPARAMETERIVPROC_MT GetTextureParameteriv = NULL; + PFNGLCREATEVERTEXARRAYSPROC_MT CreateVertexArrays = NULL; + PFNGLDISABLEVERTEXARRAYATTRIBPROC_MT DisableVertexArrayAttrib = NULL; + PFNGLENABLEVERTEXARRAYATTRIBPROC_MT EnableVertexArrayAttrib = NULL; + PFNGLVERTEXARRAYELEMENTBUFFERPROC_MT VertexArrayElementBuffer = NULL; + PFNGLVERTEXARRAYVERTEXBUFFERPROC_MT VertexArrayVertexBuffer = NULL; + PFNGLVERTEXARRAYVERTEXBUFFERSPROC_MT VertexArrayVertexBuffers = NULL; + PFNGLVERTEXARRAYATTRIBBINDINGPROC_MT VertexArrayAttribBinding = NULL; + PFNGLVERTEXARRAYATTRIBFORMATPROC_MT VertexArrayAttribFormat = NULL; + PFNGLVERTEXARRAYATTRIBIFORMATPROC_MT VertexArrayAttribIFormat = NULL; + PFNGLVERTEXARRAYATTRIBLFORMATPROC_MT VertexArrayAttribLFormat = NULL; + PFNGLVERTEXARRAYBINDINGDIVISORPROC_MT VertexArrayBindingDivisor = NULL; + PFNGLGETVERTEXARRAYIVPROC_MT GetVertexArrayiv = NULL; + PFNGLGETVERTEXARRAYINDEXEDIVPROC_MT GetVertexArrayIndexediv = NULL; + PFNGLGETVERTEXARRAYINDEXED64IVPROC_MT GetVertexArrayIndexed64iv = NULL; + PFNGLCREATESAMPLERSPROC_MT CreateSamplers = NULL; + PFNGLCREATEPROGRAMPIPELINESPROC_MT CreateProgramPipelines = NULL; + PFNGLCREATEQUERIESPROC_MT CreateQueries = NULL; + PFNGLGETQUERYBUFFEROBJECTI64VPROC_MT GetQueryBufferObjecti64v = NULL; + PFNGLGETQUERYBUFFEROBJECTIVPROC_MT GetQueryBufferObjectiv = NULL; + PFNGLGETQUERYBUFFEROBJECTUI64VPROC_MT GetQueryBufferObjectui64v = NULL; + PFNGLGETQUERYBUFFEROBJECTUIVPROC_MT GetQueryBufferObjectuiv = NULL; + PFNGLMEMORYBARRIERBYREGIONPROC_MT MemoryBarrierByRegion = NULL; + PFNGLGETTEXTURESUBIMAGEPROC_MT GetTextureSubImage = NULL; + PFNGLGETCOMPRESSEDTEXTURESUBIMAGEPROC_MT GetCompressedTextureSubImage = NULL; + PFNGLGETGRAPHICSRESETSTATUSPROC_MT GetGraphicsResetStatus = NULL; + PFNGLGETNCOMPRESSEDTEXIMAGEPROC_MT GetnCompressedTexImage = NULL; + PFNGLGETNTEXIMAGEPROC_MT GetnTexImage = NULL; + PFNGLGETNUNIFORMDVPROC_MT GetnUniformdv = NULL; + PFNGLGETNUNIFORMFVPROC_MT GetnUniformfv = NULL; + PFNGLGETNUNIFORMIVPROC_MT GetnUniformiv = NULL; + PFNGLGETNUNIFORMUIVPROC_MT GetnUniformuiv = NULL; + PFNGLREADNPIXELSPROC_MT ReadnPixels = NULL; + PFNGLTEXTUREBARRIERPROC_MT TextureBarrier = NULL; + PFNGLSPECIALIZESHADERPROC_MT SpecializeShader = NULL; + PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC_MT MultiDrawArraysIndirectCount = NULL; + PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC_MT MultiDrawElementsIndirectCount = NULL; + PFNGLPOLYGONOFFSETCLAMPPROC_MT PolygonOffsetClamp = NULL; + PFNGLPRIMITIVEBOUNDINGBOXPROC_MT PrimitiveBoundingBox = NULL; + PFNGLGETTEXTUREHANDLEPROC_MT GetTextureHandle = NULL; + PFNGLGETTEXTURESAMPLERHANDLEPROC_MT GetTextureSamplerHandle = NULL; + PFNGLMAKETEXTUREHANDLERESIDENTPROC_MT MakeTextureHandleResident = NULL; + PFNGLMAKETEXTUREHANDLENONRESIDENTPROC_MT MakeTextureHandleNonResident = NULL; + PFNGLGETIMAGEHANDLEPROC_MT GetImageHandle = NULL; + PFNGLMAKEIMAGEHANDLERESIDENTPROC_MT MakeImageHandleResident = NULL; + PFNGLMAKEIMAGEHANDLENONRESIDENTPROC_MT MakeImageHandleNonResident = NULL; + PFNGLUNIFORMHANDLEUI64PROC_MT UniformHandleui64 = NULL; + PFNGLUNIFORMHANDLEUI64VPROC_MT UniformHandleui64v = NULL; + PFNGLPROGRAMUNIFORMHANDLEUI64PROC_MT ProgramUniformHandleui64 = NULL; + PFNGLPROGRAMUNIFORMHANDLEUI64VPROC_MT ProgramUniformHandleui64v = NULL; + PFNGLISTEXTUREHANDLERESIDENTPROC_MT IsTextureHandleResident = NULL; + PFNGLISIMAGEHANDLERESIDENTPROC_MT IsImageHandleResident = NULL; + PFNGLVERTEXATTRIBL1UI64PROC_MT VertexAttribL1ui64 = NULL; + PFNGLVERTEXATTRIBL1UI64VPROC_MT VertexAttribL1ui64v = NULL; + PFNGLGETVERTEXATTRIBLUI64VPROC_MT GetVertexAttribLui64v = NULL; + PFNGLCREATESYNCFROMCLEVENTPROC_MT CreateSyncFromCLevent = NULL; + PFNGLDISPATCHCOMPUTEGROUPSIZEPROC_MT DispatchComputeGroupSize = NULL; + PFNGLFRAMEBUFFERTEXTUREFACEPROC_MT FramebufferTextureFace = NULL; + PFNGLUNIFORM1I64PROC_MT Uniform1i64 = NULL; + PFNGLUNIFORM2I64PROC_MT Uniform2i64 = NULL; + PFNGLUNIFORM3I64PROC_MT Uniform3i64 = NULL; + PFNGLUNIFORM4I64PROC_MT Uniform4i64 = NULL; + PFNGLUNIFORM1I64VPROC_MT Uniform1i64v = NULL; + PFNGLUNIFORM2I64VPROC_MT Uniform2i64v = NULL; + PFNGLUNIFORM3I64VPROC_MT Uniform3i64v = NULL; + PFNGLUNIFORM4I64VPROC_MT Uniform4i64v = NULL; + PFNGLUNIFORM1UI64PROC_MT Uniform1ui64 = NULL; + PFNGLUNIFORM2UI64PROC_MT Uniform2ui64 = NULL; + PFNGLUNIFORM3UI64PROC_MT Uniform3ui64 = NULL; + PFNGLUNIFORM4UI64PROC_MT Uniform4ui64 = NULL; + PFNGLUNIFORM1UI64VPROC_MT Uniform1ui64v = NULL; + PFNGLUNIFORM2UI64VPROC_MT Uniform2ui64v = NULL; + PFNGLUNIFORM3UI64VPROC_MT Uniform3ui64v = NULL; + PFNGLUNIFORM4UI64VPROC_MT Uniform4ui64v = NULL; + PFNGLGETUNIFORMI64VPROC_MT GetUniformi64v = NULL; + PFNGLGETUNIFORMUI64VPROC_MT GetUniformui64v = NULL; + PFNGLGETNUNIFORMI64VPROC_MT GetnUniformi64v = NULL; + PFNGLGETNUNIFORMUI64VPROC_MT GetnUniformui64v = NULL; + PFNGLPROGRAMUNIFORM1I64PROC_MT ProgramUniform1i64 = NULL; + PFNGLPROGRAMUNIFORM2I64PROC_MT ProgramUniform2i64 = NULL; + PFNGLPROGRAMUNIFORM3I64PROC_MT ProgramUniform3i64 = NULL; + PFNGLPROGRAMUNIFORM4I64PROC_MT ProgramUniform4i64 = NULL; + PFNGLPROGRAMUNIFORM1I64VPROC_MT ProgramUniform1i64v = NULL; + PFNGLPROGRAMUNIFORM2I64VPROC_MT ProgramUniform2i64v = NULL; + PFNGLPROGRAMUNIFORM3I64VPROC_MT ProgramUniform3i64v = NULL; + PFNGLPROGRAMUNIFORM4I64VPROC_MT ProgramUniform4i64v = NULL; + PFNGLPROGRAMUNIFORM1UI64PROC_MT ProgramUniform1ui64 = NULL; + PFNGLPROGRAMUNIFORM2UI64PROC_MT ProgramUniform2ui64 = NULL; + PFNGLPROGRAMUNIFORM3UI64PROC_MT ProgramUniform3ui64 = NULL; + PFNGLPROGRAMUNIFORM4UI64PROC_MT ProgramUniform4ui64 = NULL; + PFNGLPROGRAMUNIFORM1UI64VPROC_MT ProgramUniform1ui64v = NULL; + PFNGLPROGRAMUNIFORM2UI64VPROC_MT ProgramUniform2ui64v = NULL; + PFNGLPROGRAMUNIFORM3UI64VPROC_MT ProgramUniform3ui64v = NULL; + PFNGLPROGRAMUNIFORM4UI64VPROC_MT ProgramUniform4ui64v = NULL; + PFNGLMAXSHADERCOMPILERTHREADSPROC_MT MaxShaderCompilerThreads = NULL; + PFNGLFRAMEBUFFERSAMPLELOCATIONSFVPROC_MT FramebufferSampleLocationsfv = NULL; + PFNGLNAMEDFRAMEBUFFERSAMPLELOCATIONSFVPROC_MT NamedFramebufferSampleLocationsfv = NULL; + PFNGLEVALUATEDEPTHVALUESPROC_MT EvaluateDepthValues = NULL; + PFNGLNAMEDSTRINGPROC_MT NamedString = NULL; + PFNGLDELETENAMEDSTRINGPROC_MT DeleteNamedString = NULL; + PFNGLCOMPILESHADERINCLUDEPROC_MT CompileShaderInclude = NULL; + PFNGLISNAMEDSTRINGPROC_MT IsNamedString = NULL; + PFNGLGETNAMEDSTRINGPROC_MT GetNamedString = NULL; + PFNGLGETNAMEDSTRINGIVPROC_MT GetNamedStringiv = NULL; + PFNGLBUFFERPAGECOMMITMENTPROC_MT BufferPageCommitment = NULL; + PFNGLNAMEDBUFFERPAGECOMMITMENTPROC_MT NamedBufferPageCommitment = NULL; + PFNGLTEXPAGECOMMITMENTPROC_MT TexPageCommitment = NULL; + + static constexpr const GLenum DEPTH_BUFFER_BIT = 0x00000100; + static constexpr const GLenum STENCIL_BUFFER_BIT = 0x00000400; + static constexpr const GLenum COLOR_BUFFER_BIT = 0x00004000; + static constexpr const GLenum POINTS = 0x0000; + static constexpr const GLenum LINES = 0x0001; + static constexpr const GLenum LINE_LOOP = 0x0002; + static constexpr const GLenum LINE_STRIP = 0x0003; + static constexpr const GLenum TRIANGLES = 0x0004; + static constexpr const GLenum TRIANGLE_STRIP = 0x0005; + static constexpr const GLenum TRIANGLE_FAN = 0x0006; + static constexpr const GLenum QUADS = 0x0007; + static constexpr const GLenum NEVER = 0x0200; + static constexpr const GLenum LESS = 0x0201; + static constexpr const GLenum EQUAL = 0x0202; + static constexpr const GLenum LEQUAL = 0x0203; + static constexpr const GLenum GREATER = 0x0204; + static constexpr const GLenum NOTEQUAL = 0x0205; + static constexpr const GLenum GEQUAL = 0x0206; + static constexpr const GLenum ALWAYS = 0x0207; + static constexpr const GLenum SRC_COLOR = 0x0300; + static constexpr const GLenum ONE_MINUS_SRC_COLOR = 0x0301; + static constexpr const GLenum SRC_ALPHA = 0x0302; + static constexpr const GLenum ONE_MINUS_SRC_ALPHA = 0x0303; + static constexpr const GLenum DST_ALPHA = 0x0304; + static constexpr const GLenum ONE_MINUS_DST_ALPHA = 0x0305; + static constexpr const GLenum DST_COLOR = 0x0306; + static constexpr const GLenum ONE_MINUS_DST_COLOR = 0x0307; + static constexpr const GLenum SRC_ALPHA_SATURATE = 0x0308; + static constexpr const GLenum FRONT_LEFT = 0x0400; + static constexpr const GLenum FRONT_RIGHT = 0x0401; + static constexpr const GLenum BACK_LEFT = 0x0402; + static constexpr const GLenum BACK_RIGHT = 0x0403; + static constexpr const GLenum FRONT = 0x0404; + static constexpr const GLenum BACK = 0x0405; + static constexpr const GLenum LEFT = 0x0406; + static constexpr const GLenum RIGHT = 0x0407; + static constexpr const GLenum FRONT_AND_BACK = 0x0408; + static constexpr const GLenum INVALID_ENUM = 0x0500; + static constexpr const GLenum INVALID_VALUE = 0x0501; + static constexpr const GLenum INVALID_OPERATION = 0x0502; + static constexpr const GLenum OUT_OF_MEMORY = 0x0505; + static constexpr const GLenum CW = 0x0900; + static constexpr const GLenum CCW = 0x0901; + static constexpr const GLenum POINT_SIZE = 0x0B11; + static constexpr const GLenum POINT_SIZE_RANGE = 0x0B12; + static constexpr const GLenum POINT_SIZE_GRANULARITY = 0x0B13; + static constexpr const GLenum LINE_SMOOTH = 0x0B20; + static constexpr const GLenum LINE_WIDTH = 0x0B21; + static constexpr const GLenum LINE_WIDTH_RANGE = 0x0B22; + static constexpr const GLenum LINE_WIDTH_GRANULARITY = 0x0B23; + static constexpr const GLenum POLYGON_MODE = 0x0B40; + static constexpr const GLenum POLYGON_SMOOTH = 0x0B41; + static constexpr const GLenum CULL_FACE = 0x0B44; + static constexpr const GLenum CULL_FACE_MODE = 0x0B45; + static constexpr const GLenum FRONT_FACE = 0x0B46; + static constexpr const GLenum DEPTH_RANGE = 0x0B70; + static constexpr const GLenum DEPTH_TEST = 0x0B71; + static constexpr const GLenum DEPTH_WRITEMASK = 0x0B72; + static constexpr const GLenum DEPTH_CLEAR_VALUE = 0x0B73; + static constexpr const GLenum DEPTH_FUNC = 0x0B74; + static constexpr const GLenum STENCIL_TEST = 0x0B90; + static constexpr const GLenum STENCIL_CLEAR_VALUE = 0x0B91; + static constexpr const GLenum STENCIL_FUNC = 0x0B92; + static constexpr const GLenum STENCIL_VALUE_MASK = 0x0B93; + static constexpr const GLenum STENCIL_FAIL = 0x0B94; + static constexpr const GLenum STENCIL_PASS_DEPTH_FAIL = 0x0B95; + static constexpr const GLenum STENCIL_PASS_DEPTH_PASS = 0x0B96; + static constexpr const GLenum STENCIL_REF = 0x0B97; + static constexpr const GLenum STENCIL_WRITEMASK = 0x0B98; + static constexpr const GLenum VIEWPORT = 0x0BA2; + static constexpr const GLenum DITHER = 0x0BD0; + static constexpr const GLenum BLEND_DST = 0x0BE0; + static constexpr const GLenum BLEND_SRC = 0x0BE1; + static constexpr const GLenum BLEND = 0x0BE2; + static constexpr const GLenum LOGIC_OP_MODE = 0x0BF0; + static constexpr const GLenum DRAW_BUFFER = 0x0C01; + static constexpr const GLenum READ_BUFFER = 0x0C02; + static constexpr const GLenum SCISSOR_BOX = 0x0C10; + static constexpr const GLenum SCISSOR_TEST = 0x0C11; + static constexpr const GLenum COLOR_CLEAR_VALUE = 0x0C22; + static constexpr const GLenum COLOR_WRITEMASK = 0x0C23; + static constexpr const GLenum DOUBLEBUFFER = 0x0C32; + static constexpr const GLenum STEREO = 0x0C33; + static constexpr const GLenum LINE_SMOOTH_HINT = 0x0C52; + static constexpr const GLenum POLYGON_SMOOTH_HINT = 0x0C53; + static constexpr const GLenum UNPACK_SWAP_BYTES = 0x0CF0; + static constexpr const GLenum UNPACK_LSB_FIRST = 0x0CF1; + static constexpr const GLenum UNPACK_ROW_LENGTH = 0x0CF2; + static constexpr const GLenum UNPACK_SKIP_ROWS = 0x0CF3; + static constexpr const GLenum UNPACK_SKIP_PIXELS = 0x0CF4; + static constexpr const GLenum UNPACK_ALIGNMENT = 0x0CF5; + static constexpr const GLenum PACK_SWAP_BYTES = 0x0D00; + static constexpr const GLenum PACK_LSB_FIRST = 0x0D01; + static constexpr const GLenum PACK_ROW_LENGTH = 0x0D02; + static constexpr const GLenum PACK_SKIP_ROWS = 0x0D03; + static constexpr const GLenum PACK_SKIP_PIXELS = 0x0D04; + static constexpr const GLenum PACK_ALIGNMENT = 0x0D05; + static constexpr const GLenum MAX_TEXTURE_SIZE = 0x0D33; + static constexpr const GLenum MAX_VIEWPORT_DIMS = 0x0D3A; + static constexpr const GLenum SUBPIXEL_BITS = 0x0D50; + static constexpr const GLenum TEXTURE_1D = 0x0DE0; + static constexpr const GLenum TEXTURE_2D = 0x0DE1; + static constexpr const GLenum TEXTURE_WIDTH = 0x1000; + static constexpr const GLenum TEXTURE_HEIGHT = 0x1001; + static constexpr const GLenum TEXTURE_BORDER_COLOR = 0x1004; + static constexpr const GLenum DONT_CARE = 0x1100; + static constexpr const GLenum FASTEST = 0x1101; + static constexpr const GLenum NICEST = 0x1102; + static constexpr const GLenum BYTE = 0x1400; + static constexpr const GLenum UNSIGNED_BYTE = 0x1401; + static constexpr const GLenum SHORT = 0x1402; + static constexpr const GLenum UNSIGNED_SHORT = 0x1403; + static constexpr const GLenum INT = 0x1404; + static constexpr const GLenum UNSIGNED_INT = 0x1405; + static constexpr const GLenum FLOAT = 0x1406; + static constexpr const GLenum STACK_OVERFLOW = 0x0503; + static constexpr const GLenum STACK_UNDERFLOW = 0x0504; + static constexpr const GLenum CLEAR = 0x1500; + static constexpr const GLenum AND = 0x1501; + static constexpr const GLenum AND_REVERSE = 0x1502; + static constexpr const GLenum COPY = 0x1503; + static constexpr const GLenum AND_INVERTED = 0x1504; + static constexpr const GLenum NOOP = 0x1505; + static constexpr const GLenum XOR = 0x1506; + static constexpr const GLenum OR = 0x1507; + static constexpr const GLenum NOR = 0x1508; + static constexpr const GLenum EQUIV = 0x1509; + static constexpr const GLenum INVERT = 0x150A; + static constexpr const GLenum OR_REVERSE = 0x150B; + static constexpr const GLenum COPY_INVERTED = 0x150C; + static constexpr const GLenum OR_INVERTED = 0x150D; + static constexpr const GLenum NAND = 0x150E; + static constexpr const GLenum SET = 0x150F; + static constexpr const GLenum TEXTURE = 0x1702; + static constexpr const GLenum COLOR = 0x1800; + static constexpr const GLenum DEPTH = 0x1801; + static constexpr const GLenum STENCIL = 0x1802; + static constexpr const GLenum STENCIL_INDEX = 0x1901; + static constexpr const GLenum DEPTH_COMPONENT = 0x1902; + static constexpr const GLenum RED = 0x1903; + static constexpr const GLenum GREEN = 0x1904; + static constexpr const GLenum BLUE = 0x1905; + static constexpr const GLenum ALPHA = 0x1906; + static constexpr const GLenum RGB = 0x1907; + static constexpr const GLenum RGBA = 0x1908; + static constexpr const GLenum POINT = 0x1B00; + static constexpr const GLenum LINE = 0x1B01; + static constexpr const GLenum FILL = 0x1B02; + static constexpr const GLenum KEEP = 0x1E00; + static constexpr const GLenum REPLACE = 0x1E01; + static constexpr const GLenum INCR = 0x1E02; + static constexpr const GLenum DECR = 0x1E03; + static constexpr const GLenum VENDOR = 0x1F00; + static constexpr const GLenum RENDERER = 0x1F01; + static constexpr const GLenum VERSION = 0x1F02; + static constexpr const GLenum EXTENSIONS = 0x1F03; + static constexpr const GLenum NEAREST = 0x2600; + static constexpr const GLenum LINEAR = 0x2601; + static constexpr const GLenum NEAREST_MIPMAP_NEAREST = 0x2700; + static constexpr const GLenum LINEAR_MIPMAP_NEAREST = 0x2701; + static constexpr const GLenum NEAREST_MIPMAP_LINEAR = 0x2702; + static constexpr const GLenum LINEAR_MIPMAP_LINEAR = 0x2703; + static constexpr const GLenum TEXTURE_MAG_FILTER = 0x2800; + static constexpr const GLenum TEXTURE_MIN_FILTER = 0x2801; + static constexpr const GLenum TEXTURE_WRAP_S = 0x2802; + static constexpr const GLenum TEXTURE_WRAP_T = 0x2803; + static constexpr const GLenum REPEAT = 0x2901; + static constexpr const GLenum COLOR_LOGIC_OP = 0x0BF2; + static constexpr const GLenum POLYGON_OFFSET_UNITS = 0x2A00; + static constexpr const GLenum POLYGON_OFFSET_POINT = 0x2A01; + static constexpr const GLenum POLYGON_OFFSET_LINE = 0x2A02; + static constexpr const GLenum POLYGON_OFFSET_FILL = 0x8037; + static constexpr const GLenum POLYGON_OFFSET_FACTOR = 0x8038; + static constexpr const GLenum TEXTURE_BINDING_1D = 0x8068; + static constexpr const GLenum TEXTURE_BINDING_2D = 0x8069; + static constexpr const GLenum TEXTURE_INTERNAL_FORMAT = 0x1003; + static constexpr const GLenum TEXTURE_RED_SIZE = 0x805C; + static constexpr const GLenum TEXTURE_GREEN_SIZE = 0x805D; + static constexpr const GLenum TEXTURE_BLUE_SIZE = 0x805E; + static constexpr const GLenum TEXTURE_ALPHA_SIZE = 0x805F; + static constexpr const GLenum DOUBLE = 0x140A; + static constexpr const GLenum PROXY_TEXTURE_1D = 0x8063; + static constexpr const GLenum PROXY_TEXTURE_2D = 0x8064; + static constexpr const GLenum R3_G3_B2 = 0x2A10; + static constexpr const GLenum RGB4 = 0x804F; + static constexpr const GLenum RGB5 = 0x8050; + static constexpr const GLenum RGB8 = 0x8051; + static constexpr const GLenum RGB10 = 0x8052; + static constexpr const GLenum RGB12 = 0x8053; + static constexpr const GLenum RGB16 = 0x8054; + static constexpr const GLenum RGBA2 = 0x8055; + static constexpr const GLenum RGBA4 = 0x8056; + static constexpr const GLenum RGB5_A1 = 0x8057; + static constexpr const GLenum RGBA8 = 0x8058; + static constexpr const GLenum RGB10_A2 = 0x8059; + static constexpr const GLenum RGBA12 = 0x805A; + static constexpr const GLenum RGBA16 = 0x805B; + static constexpr const GLenum VERTEX_ARRAY = 0x8074; + static constexpr const GLenum UNSIGNED_BYTE_3_3_2 = 0x8032; + static constexpr const GLenum UNSIGNED_SHORT_4_4_4_4 = 0x8033; + static constexpr const GLenum UNSIGNED_SHORT_5_5_5_1 = 0x8034; + static constexpr const GLenum UNSIGNED_INT_8_8_8_8 = 0x8035; + static constexpr const GLenum UNSIGNED_INT_10_10_10_2 = 0x8036; + static constexpr const GLenum TEXTURE_BINDING_3D = 0x806A; + static constexpr const GLenum PACK_SKIP_IMAGES = 0x806B; + static constexpr const GLenum PACK_IMAGE_HEIGHT = 0x806C; + static constexpr const GLenum UNPACK_SKIP_IMAGES = 0x806D; + static constexpr const GLenum UNPACK_IMAGE_HEIGHT = 0x806E; + static constexpr const GLenum TEXTURE_3D = 0x806F; + static constexpr const GLenum PROXY_TEXTURE_3D = 0x8070; + static constexpr const GLenum TEXTURE_DEPTH = 0x8071; + static constexpr const GLenum TEXTURE_WRAP_R = 0x8072; + static constexpr const GLenum MAX_3D_TEXTURE_SIZE = 0x8073; + static constexpr const GLenum UNSIGNED_BYTE_2_3_3_REV = 0x8362; + static constexpr const GLenum UNSIGNED_SHORT_5_6_5 = 0x8363; + static constexpr const GLenum UNSIGNED_SHORT_5_6_5_REV = 0x8364; + static constexpr const GLenum UNSIGNED_SHORT_4_4_4_4_REV = 0x8365; + static constexpr const GLenum UNSIGNED_SHORT_1_5_5_5_REV = 0x8366; + static constexpr const GLenum UNSIGNED_INT_8_8_8_8_REV = 0x8367; + static constexpr const GLenum UNSIGNED_INT_2_10_10_10_REV = 0x8368; + static constexpr const GLenum BGR = 0x80E0; + static constexpr const GLenum BGRA = 0x80E1; + static constexpr const GLenum MAX_ELEMENTS_VERTICES = 0x80E8; + static constexpr const GLenum MAX_ELEMENTS_INDICES = 0x80E9; + static constexpr const GLenum CLAMP_TO_EDGE = 0x812F; + static constexpr const GLenum TEXTURE_MIN_LOD = 0x813A; + static constexpr const GLenum TEXTURE_MAX_LOD = 0x813B; + static constexpr const GLenum TEXTURE_BASE_LEVEL = 0x813C; + static constexpr const GLenum TEXTURE_MAX_LEVEL = 0x813D; + static constexpr const GLenum SMOOTH_POINT_SIZE_RANGE = 0x0B12; + static constexpr const GLenum SMOOTH_POINT_SIZE_GRANULARITY = 0x0B13; + static constexpr const GLenum SMOOTH_LINE_WIDTH_RANGE = 0x0B22; + static constexpr const GLenum SMOOTH_LINE_WIDTH_GRANULARITY = 0x0B23; + static constexpr const GLenum ALIASED_LINE_WIDTH_RANGE = 0x846E; + static constexpr const GLenum TEXTURE0 = 0x84C0; + static constexpr const GLenum TEXTURE1 = 0x84C1; + static constexpr const GLenum TEXTURE2 = 0x84C2; + static constexpr const GLenum TEXTURE3 = 0x84C3; + static constexpr const GLenum TEXTURE4 = 0x84C4; + static constexpr const GLenum TEXTURE5 = 0x84C5; + static constexpr const GLenum TEXTURE6 = 0x84C6; + static constexpr const GLenum TEXTURE7 = 0x84C7; + static constexpr const GLenum TEXTURE8 = 0x84C8; + static constexpr const GLenum TEXTURE9 = 0x84C9; + static constexpr const GLenum TEXTURE10 = 0x84CA; + static constexpr const GLenum TEXTURE11 = 0x84CB; + static constexpr const GLenum TEXTURE12 = 0x84CC; + static constexpr const GLenum TEXTURE13 = 0x84CD; + static constexpr const GLenum TEXTURE14 = 0x84CE; + static constexpr const GLenum TEXTURE15 = 0x84CF; + static constexpr const GLenum TEXTURE16 = 0x84D0; + static constexpr const GLenum TEXTURE17 = 0x84D1; + static constexpr const GLenum TEXTURE18 = 0x84D2; + static constexpr const GLenum TEXTURE19 = 0x84D3; + static constexpr const GLenum TEXTURE20 = 0x84D4; + static constexpr const GLenum TEXTURE21 = 0x84D5; + static constexpr const GLenum TEXTURE22 = 0x84D6; + static constexpr const GLenum TEXTURE23 = 0x84D7; + static constexpr const GLenum TEXTURE24 = 0x84D8; + static constexpr const GLenum TEXTURE25 = 0x84D9; + static constexpr const GLenum TEXTURE26 = 0x84DA; + static constexpr const GLenum TEXTURE27 = 0x84DB; + static constexpr const GLenum TEXTURE28 = 0x84DC; + static constexpr const GLenum TEXTURE29 = 0x84DD; + static constexpr const GLenum TEXTURE30 = 0x84DE; + static constexpr const GLenum TEXTURE31 = 0x84DF; + static constexpr const GLenum ACTIVE_TEXTURE = 0x84E0; + static constexpr const GLenum MULTISAMPLE = 0x809D; + static constexpr const GLenum SAMPLE_ALPHA_TO_COVERAGE = 0x809E; + static constexpr const GLenum SAMPLE_ALPHA_TO_ONE = 0x809F; + static constexpr const GLenum SAMPLE_COVERAGE = 0x80A0; + static constexpr const GLenum SAMPLE_BUFFERS = 0x80A8; + static constexpr const GLenum SAMPLES = 0x80A9; + static constexpr const GLenum SAMPLE_COVERAGE_VALUE = 0x80AA; + static constexpr const GLenum SAMPLE_COVERAGE_INVERT = 0x80AB; + static constexpr const GLenum TEXTURE_CUBE_MAP = 0x8513; + static constexpr const GLenum TEXTURE_BINDING_CUBE_MAP = 0x8514; + static constexpr const GLenum TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515; + static constexpr const GLenum TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516; + static constexpr const GLenum TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517; + static constexpr const GLenum TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518; + static constexpr const GLenum TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519; + static constexpr const GLenum TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A; + static constexpr const GLenum PROXY_TEXTURE_CUBE_MAP = 0x851B; + static constexpr const GLenum MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C; + static constexpr const GLenum COMPRESSED_RGB = 0x84ED; + static constexpr const GLenum COMPRESSED_RGBA = 0x84EE; + static constexpr const GLenum TEXTURE_COMPRESSION_HINT = 0x84EF; + static constexpr const GLenum TEXTURE_COMPRESSED_IMAGE_SIZE = 0x86A0; + static constexpr const GLenum TEXTURE_COMPRESSED = 0x86A1; + static constexpr const GLenum NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2; + static constexpr const GLenum COMPRESSED_TEXTURE_FORMATS = 0x86A3; + static constexpr const GLenum CLAMP_TO_BORDER = 0x812D; + static constexpr const GLenum BLEND_DST_RGB = 0x80C8; + static constexpr const GLenum BLEND_SRC_RGB = 0x80C9; + static constexpr const GLenum BLEND_DST_ALPHA = 0x80CA; + static constexpr const GLenum BLEND_SRC_ALPHA = 0x80CB; + static constexpr const GLenum POINT_FADE_THRESHOLD_SIZE = 0x8128; + static constexpr const GLenum DEPTH_COMPONENT16 = 0x81A5; + static constexpr const GLenum DEPTH_COMPONENT24 = 0x81A6; + static constexpr const GLenum DEPTH_COMPONENT32 = 0x81A7; + static constexpr const GLenum MIRRORED_REPEAT = 0x8370; + static constexpr const GLenum MAX_TEXTURE_LOD_BIAS = 0x84FD; + static constexpr const GLenum TEXTURE_LOD_BIAS = 0x8501; + static constexpr const GLenum INCR_WRAP = 0x8507; + static constexpr const GLenum DECR_WRAP = 0x8508; + static constexpr const GLenum TEXTURE_DEPTH_SIZE = 0x884A; + static constexpr const GLenum TEXTURE_COMPARE_MODE = 0x884C; + static constexpr const GLenum TEXTURE_COMPARE_FUNC = 0x884D; + static constexpr const GLenum BLEND_COLOR = 0x8005; + static constexpr const GLenum BLEND_EQUATION = 0x8009; + static constexpr const GLenum CONSTANT_COLOR = 0x8001; + static constexpr const GLenum ONE_MINUS_CONSTANT_COLOR = 0x8002; + static constexpr const GLenum CONSTANT_ALPHA = 0x8003; + static constexpr const GLenum ONE_MINUS_CONSTANT_ALPHA = 0x8004; + static constexpr const GLenum FUNC_ADD = 0x8006; + static constexpr const GLenum FUNC_REVERSE_SUBTRACT = 0x800B; + static constexpr const GLenum FUNC_SUBTRACT = 0x800A; + static constexpr const GLenum MIN = 0x8007; + static constexpr const GLenum MAX = 0x8008; + static constexpr const GLenum BUFFER_SIZE = 0x8764; + static constexpr const GLenum BUFFER_USAGE = 0x8765; + static constexpr const GLenum QUERY_COUNTER_BITS = 0x8864; + static constexpr const GLenum CURRENT_QUERY = 0x8865; + static constexpr const GLenum QUERY_RESULT = 0x8866; + static constexpr const GLenum QUERY_RESULT_AVAILABLE = 0x8867; + static constexpr const GLenum ARRAY_BUFFER = 0x8892; + static constexpr const GLenum ELEMENT_ARRAY_BUFFER = 0x8893; + static constexpr const GLenum ARRAY_BUFFER_BINDING = 0x8894; + static constexpr const GLenum ELEMENT_ARRAY_BUFFER_BINDING = 0x8895; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F; + static constexpr const GLenum READ_ONLY = 0x88B8; + static constexpr const GLenum WRITE_ONLY = 0x88B9; + static constexpr const GLenum READ_WRITE = 0x88BA; + static constexpr const GLenum BUFFER_ACCESS = 0x88BB; + static constexpr const GLenum BUFFER_MAPPED = 0x88BC; + static constexpr const GLenum BUFFER_MAP_POINTER = 0x88BD; + static constexpr const GLenum STREAM_DRAW = 0x88E0; + static constexpr const GLenum STREAM_READ = 0x88E1; + static constexpr const GLenum STREAM_COPY = 0x88E2; + static constexpr const GLenum STATIC_DRAW = 0x88E4; + static constexpr const GLenum STATIC_READ = 0x88E5; + static constexpr const GLenum STATIC_COPY = 0x88E6; + static constexpr const GLenum DYNAMIC_DRAW = 0x88E8; + static constexpr const GLenum DYNAMIC_READ = 0x88E9; + static constexpr const GLenum DYNAMIC_COPY = 0x88EA; + static constexpr const GLenum SAMPLES_PASSED = 0x8914; + static constexpr const GLenum SRC1_ALPHA = 0x8589; + static constexpr const GLenum BLEND_EQUATION_RGB = 0x8009; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_SIZE = 0x8623; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_TYPE = 0x8625; + static constexpr const GLenum CURRENT_VERTEX_ATTRIB = 0x8626; + static constexpr const GLenum VERTEX_PROGRAM_POINT_SIZE = 0x8642; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_POINTER = 0x8645; + static constexpr const GLenum STENCIL_BACK_FUNC = 0x8800; + static constexpr const GLenum STENCIL_BACK_FAIL = 0x8801; + static constexpr const GLenum STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802; + static constexpr const GLenum STENCIL_BACK_PASS_DEPTH_PASS = 0x8803; + static constexpr const GLenum MAX_DRAW_BUFFERS = 0x8824; + static constexpr const GLenum DRAW_BUFFER0 = 0x8825; + static constexpr const GLenum DRAW_BUFFER1 = 0x8826; + static constexpr const GLenum DRAW_BUFFER2 = 0x8827; + static constexpr const GLenum DRAW_BUFFER3 = 0x8828; + static constexpr const GLenum DRAW_BUFFER4 = 0x8829; + static constexpr const GLenum DRAW_BUFFER5 = 0x882A; + static constexpr const GLenum DRAW_BUFFER6 = 0x882B; + static constexpr const GLenum DRAW_BUFFER7 = 0x882C; + static constexpr const GLenum DRAW_BUFFER8 = 0x882D; + static constexpr const GLenum DRAW_BUFFER9 = 0x882E; + static constexpr const GLenum DRAW_BUFFER10 = 0x882F; + static constexpr const GLenum DRAW_BUFFER11 = 0x8830; + static constexpr const GLenum DRAW_BUFFER12 = 0x8831; + static constexpr const GLenum DRAW_BUFFER13 = 0x8832; + static constexpr const GLenum DRAW_BUFFER14 = 0x8833; + static constexpr const GLenum DRAW_BUFFER15 = 0x8834; + static constexpr const GLenum BLEND_EQUATION_ALPHA = 0x883D; + static constexpr const GLenum MAX_VERTEX_ATTRIBS = 0x8869; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A; + static constexpr const GLenum MAX_TEXTURE_IMAGE_UNITS = 0x8872; + static constexpr const GLenum FRAGMENT_SHADER = 0x8B30; + static constexpr const GLenum VERTEX_SHADER = 0x8B31; + static constexpr const GLenum MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49; + static constexpr const GLenum MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A; + static constexpr const GLenum MAX_VARYING_FLOATS = 0x8B4B; + static constexpr const GLenum MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C; + static constexpr const GLenum MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D; + static constexpr const GLenum SHADER_TYPE = 0x8B4F; + static constexpr const GLenum FLOAT_VEC2 = 0x8B50; + static constexpr const GLenum FLOAT_VEC3 = 0x8B51; + static constexpr const GLenum FLOAT_VEC4 = 0x8B52; + static constexpr const GLenum INT_VEC2 = 0x8B53; + static constexpr const GLenum INT_VEC3 = 0x8B54; + static constexpr const GLenum INT_VEC4 = 0x8B55; + static constexpr const GLenum BOOL = 0x8B56; + static constexpr const GLenum BOOL_VEC2 = 0x8B57; + static constexpr const GLenum BOOL_VEC3 = 0x8B58; + static constexpr const GLenum BOOL_VEC4 = 0x8B59; + static constexpr const GLenum FLOAT_MAT2 = 0x8B5A; + static constexpr const GLenum FLOAT_MAT3 = 0x8B5B; + static constexpr const GLenum FLOAT_MAT4 = 0x8B5C; + static constexpr const GLenum SAMPLER_1D = 0x8B5D; + static constexpr const GLenum SAMPLER_2D = 0x8B5E; + static constexpr const GLenum SAMPLER_3D = 0x8B5F; + static constexpr const GLenum SAMPLER_CUBE = 0x8B60; + static constexpr const GLenum SAMPLER_1D_SHADOW = 0x8B61; + static constexpr const GLenum SAMPLER_2D_SHADOW = 0x8B62; + static constexpr const GLenum DELETE_STATUS = 0x8B80; + static constexpr const GLenum COMPILE_STATUS = 0x8B81; + static constexpr const GLenum LINK_STATUS = 0x8B82; + static constexpr const GLenum VALIDATE_STATUS = 0x8B83; + static constexpr const GLenum INFO_LOG_LENGTH = 0x8B84; + static constexpr const GLenum ATTACHED_SHADERS = 0x8B85; + static constexpr const GLenum ACTIVE_UNIFORMS = 0x8B86; + static constexpr const GLenum ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87; + static constexpr const GLenum SHADER_SOURCE_LENGTH = 0x8B88; + static constexpr const GLenum ACTIVE_ATTRIBUTES = 0x8B89; + static constexpr const GLenum ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A; + static constexpr const GLenum FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8B8B; + static constexpr const GLenum SHADING_LANGUAGE_VERSION = 0x8B8C; + static constexpr const GLenum CURRENT_PROGRAM = 0x8B8D; + static constexpr const GLenum POINT_SPRITE_COORD_ORIGIN = 0x8CA0; + static constexpr const GLenum LOWER_LEFT = 0x8CA1; + static constexpr const GLenum UPPER_LEFT = 0x8CA2; + static constexpr const GLenum STENCIL_BACK_REF = 0x8CA3; + static constexpr const GLenum STENCIL_BACK_VALUE_MASK = 0x8CA4; + static constexpr const GLenum STENCIL_BACK_WRITEMASK = 0x8CA5; + static constexpr const GLenum PIXEL_PACK_BUFFER = 0x88EB; + static constexpr const GLenum PIXEL_UNPACK_BUFFER = 0x88EC; + static constexpr const GLenum PIXEL_PACK_BUFFER_BINDING = 0x88ED; + static constexpr const GLenum PIXEL_UNPACK_BUFFER_BINDING = 0x88EF; + static constexpr const GLenum FLOAT_MAT2x3 = 0x8B65; + static constexpr const GLenum FLOAT_MAT2x4 = 0x8B66; + static constexpr const GLenum FLOAT_MAT3x2 = 0x8B67; + static constexpr const GLenum FLOAT_MAT3x4 = 0x8B68; + static constexpr const GLenum FLOAT_MAT4x2 = 0x8B69; + static constexpr const GLenum FLOAT_MAT4x3 = 0x8B6A; + static constexpr const GLenum SRGB = 0x8C40; + static constexpr const GLenum SRGB8 = 0x8C41; + static constexpr const GLenum SRGB_ALPHA = 0x8C42; + static constexpr const GLenum SRGB8_ALPHA8 = 0x8C43; + static constexpr const GLenum COMPRESSED_SRGB = 0x8C48; + static constexpr const GLenum COMPRESSED_SRGB_ALPHA = 0x8C49; + static constexpr const GLenum COMPARE_REF_TO_TEXTURE = 0x884E; + static constexpr const GLenum CLIP_DISTANCE0 = 0x3000; + static constexpr const GLenum CLIP_DISTANCE1 = 0x3001; + static constexpr const GLenum CLIP_DISTANCE2 = 0x3002; + static constexpr const GLenum CLIP_DISTANCE3 = 0x3003; + static constexpr const GLenum CLIP_DISTANCE4 = 0x3004; + static constexpr const GLenum CLIP_DISTANCE5 = 0x3005; + static constexpr const GLenum CLIP_DISTANCE6 = 0x3006; + static constexpr const GLenum CLIP_DISTANCE7 = 0x3007; + static constexpr const GLenum MAX_CLIP_DISTANCES = 0x0D32; + static constexpr const GLenum MAJOR_VERSION = 0x821B; + static constexpr const GLenum MINOR_VERSION = 0x821C; + static constexpr const GLenum NUM_EXTENSIONS = 0x821D; + static constexpr const GLenum CONTEXT_FLAGS = 0x821E; + static constexpr const GLenum COMPRESSED_RED = 0x8225; + static constexpr const GLenum COMPRESSED_RG = 0x8226; + static constexpr const GLenum CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT = 0x00000001; + static constexpr const GLenum RGBA32F = 0x8814; + static constexpr const GLenum RGB32F = 0x8815; + static constexpr const GLenum RGBA16F = 0x881A; + static constexpr const GLenum RGB16F = 0x881B; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_INTEGER = 0x88FD; + static constexpr const GLenum MAX_ARRAY_TEXTURE_LAYERS = 0x88FF; + static constexpr const GLenum MIN_PROGRAM_TEXEL_OFFSET = 0x8904; + static constexpr const GLenum MAX_PROGRAM_TEXEL_OFFSET = 0x8905; + static constexpr const GLenum CLAMP_READ_COLOR = 0x891C; + static constexpr const GLenum FIXED_ONLY = 0x891D; + static constexpr const GLenum MAX_VARYING_COMPONENTS = 0x8B4B; + static constexpr const GLenum TEXTURE_1D_ARRAY = 0x8C18; + static constexpr const GLenum PROXY_TEXTURE_1D_ARRAY = 0x8C19; + static constexpr const GLenum TEXTURE_2D_ARRAY = 0x8C1A; + static constexpr const GLenum PROXY_TEXTURE_2D_ARRAY = 0x8C1B; + static constexpr const GLenum TEXTURE_BINDING_1D_ARRAY = 0x8C1C; + static constexpr const GLenum TEXTURE_BINDING_2D_ARRAY = 0x8C1D; + static constexpr const GLenum R11F_G11F_B10F = 0x8C3A; + static constexpr const GLenum UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B; + static constexpr const GLenum RGB9_E5 = 0x8C3D; + static constexpr const GLenum UNSIGNED_INT_5_9_9_9_REV = 0x8C3E; + static constexpr const GLenum TEXTURE_SHARED_SIZE = 0x8C3F; + static constexpr const GLenum TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH = 0x8C76; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_MODE = 0x8C7F; + static constexpr const GLenum MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 0x8C80; + static constexpr const GLenum TRANSFORM_FEEDBACK_VARYINGS = 0x8C83; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_START = 0x8C84; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_SIZE = 0x8C85; + static constexpr const GLenum PRIMITIVES_GENERATED = 0x8C87; + static constexpr const GLenum TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN = 0x8C88; + static constexpr const GLenum RASTERIZER_DISCARD = 0x8C89; + static constexpr const GLenum MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 0x8C8A; + static constexpr const GLenum MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B; + static constexpr const GLenum INTERLEAVED_ATTRIBS = 0x8C8C; + static constexpr const GLenum SEPARATE_ATTRIBS = 0x8C8D; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER = 0x8C8E; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8C8F; + static constexpr const GLenum RGBA32UI = 0x8D70; + static constexpr const GLenum RGB32UI = 0x8D71; + static constexpr const GLenum RGBA16UI = 0x8D76; + static constexpr const GLenum RGB16UI = 0x8D77; + static constexpr const GLenum RGBA8UI = 0x8D7C; + static constexpr const GLenum RGB8UI = 0x8D7D; + static constexpr const GLenum RGBA32I = 0x8D82; + static constexpr const GLenum RGB32I = 0x8D83; + static constexpr const GLenum RGBA16I = 0x8D88; + static constexpr const GLenum RGB16I = 0x8D89; + static constexpr const GLenum RGBA8I = 0x8D8E; + static constexpr const GLenum RGB8I = 0x8D8F; + static constexpr const GLenum RED_INTEGER = 0x8D94; + static constexpr const GLenum GREEN_INTEGER = 0x8D95; + static constexpr const GLenum BLUE_INTEGER = 0x8D96; + static constexpr const GLenum RGB_INTEGER = 0x8D98; + static constexpr const GLenum RGBA_INTEGER = 0x8D99; + static constexpr const GLenum BGR_INTEGER = 0x8D9A; + static constexpr const GLenum BGRA_INTEGER = 0x8D9B; + static constexpr const GLenum SAMPLER_1D_ARRAY = 0x8DC0; + static constexpr const GLenum SAMPLER_2D_ARRAY = 0x8DC1; + static constexpr const GLenum SAMPLER_1D_ARRAY_SHADOW = 0x8DC3; + static constexpr const GLenum SAMPLER_2D_ARRAY_SHADOW = 0x8DC4; + static constexpr const GLenum SAMPLER_CUBE_SHADOW = 0x8DC5; + static constexpr const GLenum UNSIGNED_INT_VEC2 = 0x8DC6; + static constexpr const GLenum UNSIGNED_INT_VEC3 = 0x8DC7; + static constexpr const GLenum UNSIGNED_INT_VEC4 = 0x8DC8; + static constexpr const GLenum INT_SAMPLER_1D = 0x8DC9; + static constexpr const GLenum INT_SAMPLER_2D = 0x8DCA; + static constexpr const GLenum INT_SAMPLER_3D = 0x8DCB; + static constexpr const GLenum INT_SAMPLER_CUBE = 0x8DCC; + static constexpr const GLenum INT_SAMPLER_1D_ARRAY = 0x8DCE; + static constexpr const GLenum INT_SAMPLER_2D_ARRAY = 0x8DCF; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_1D = 0x8DD1; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_2D = 0x8DD2; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_3D = 0x8DD3; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_1D_ARRAY = 0x8DD6; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7; + static constexpr const GLenum QUERY_WAIT = 0x8E13; + static constexpr const GLenum QUERY_NO_WAIT = 0x8E14; + static constexpr const GLenum QUERY_BY_REGION_WAIT = 0x8E15; + static constexpr const GLenum QUERY_BY_REGION_NO_WAIT = 0x8E16; + static constexpr const GLenum BUFFER_ACCESS_FLAGS = 0x911F; + static constexpr const GLenum BUFFER_MAP_LENGTH = 0x9120; + static constexpr const GLenum BUFFER_MAP_OFFSET = 0x9121; + static constexpr const GLenum DEPTH_COMPONENT32F = 0x8CAC; + static constexpr const GLenum DEPTH32F_STENCIL8 = 0x8CAD; + static constexpr const GLenum FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD; + static constexpr const GLenum INVALID_FRAMEBUFFER_OPERATION = 0x0506; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING = 0x8210; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE = 0x8211; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_RED_SIZE = 0x8212; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_GREEN_SIZE = 0x8213; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_BLUE_SIZE = 0x8214; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE = 0x8215; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE = 0x8216; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE = 0x8217; + static constexpr const GLenum FRAMEBUFFER_DEFAULT = 0x8218; + static constexpr const GLenum FRAMEBUFFER_UNDEFINED = 0x8219; + static constexpr const GLenum DEPTH_STENCIL_ATTACHMENT = 0x821A; + static constexpr const GLenum MAX_RENDERBUFFER_SIZE = 0x84E8; + static constexpr const GLenum DEPTH_STENCIL = 0x84F9; + static constexpr const GLenum UNSIGNED_INT_24_8 = 0x84FA; + static constexpr const GLenum DEPTH24_STENCIL8 = 0x88F0; + static constexpr const GLenum TEXTURE_STENCIL_SIZE = 0x88F1; + static constexpr const GLenum TEXTURE_RED_TYPE = 0x8C10; + static constexpr const GLenum TEXTURE_GREEN_TYPE = 0x8C11; + static constexpr const GLenum TEXTURE_BLUE_TYPE = 0x8C12; + static constexpr const GLenum TEXTURE_ALPHA_TYPE = 0x8C13; + static constexpr const GLenum TEXTURE_DEPTH_TYPE = 0x8C16; + static constexpr const GLenum UNSIGNED_NORMALIZED = 0x8C17; + static constexpr const GLenum FRAMEBUFFER_BINDING = 0x8CA6; + static constexpr const GLenum DRAW_FRAMEBUFFER_BINDING = 0x8CA6; + static constexpr const GLenum RENDERBUFFER_BINDING = 0x8CA7; + static constexpr const GLenum READ_FRAMEBUFFER = 0x8CA8; + static constexpr const GLenum DRAW_FRAMEBUFFER = 0x8CA9; + static constexpr const GLenum READ_FRAMEBUFFER_BINDING = 0x8CAA; + static constexpr const GLenum RENDERBUFFER_SAMPLES = 0x8CAB; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER = 0x8CD4; + static constexpr const GLenum FRAMEBUFFER_COMPLETE = 0x8CD5; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = 0x8CDB; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_READ_BUFFER = 0x8CDC; + static constexpr const GLenum FRAMEBUFFER_UNSUPPORTED = 0x8CDD; + static constexpr const GLenum MAX_COLOR_ATTACHMENTS = 0x8CDF; + static constexpr const GLenum COLOR_ATTACHMENT0 = 0x8CE0; + static constexpr const GLenum COLOR_ATTACHMENT1 = 0x8CE1; + static constexpr const GLenum COLOR_ATTACHMENT2 = 0x8CE2; + static constexpr const GLenum COLOR_ATTACHMENT3 = 0x8CE3; + static constexpr const GLenum COLOR_ATTACHMENT4 = 0x8CE4; + static constexpr const GLenum COLOR_ATTACHMENT5 = 0x8CE5; + static constexpr const GLenum COLOR_ATTACHMENT6 = 0x8CE6; + static constexpr const GLenum COLOR_ATTACHMENT7 = 0x8CE7; + static constexpr const GLenum COLOR_ATTACHMENT8 = 0x8CE8; + static constexpr const GLenum COLOR_ATTACHMENT9 = 0x8CE9; + static constexpr const GLenum COLOR_ATTACHMENT10 = 0x8CEA; + static constexpr const GLenum COLOR_ATTACHMENT11 = 0x8CEB; + static constexpr const GLenum COLOR_ATTACHMENT12 = 0x8CEC; + static constexpr const GLenum COLOR_ATTACHMENT13 = 0x8CED; + static constexpr const GLenum COLOR_ATTACHMENT14 = 0x8CEE; + static constexpr const GLenum COLOR_ATTACHMENT15 = 0x8CEF; + static constexpr const GLenum COLOR_ATTACHMENT16 = 0x8CF0; + static constexpr const GLenum COLOR_ATTACHMENT17 = 0x8CF1; + static constexpr const GLenum COLOR_ATTACHMENT18 = 0x8CF2; + static constexpr const GLenum COLOR_ATTACHMENT19 = 0x8CF3; + static constexpr const GLenum COLOR_ATTACHMENT20 = 0x8CF4; + static constexpr const GLenum COLOR_ATTACHMENT21 = 0x8CF5; + static constexpr const GLenum COLOR_ATTACHMENT22 = 0x8CF6; + static constexpr const GLenum COLOR_ATTACHMENT23 = 0x8CF7; + static constexpr const GLenum COLOR_ATTACHMENT24 = 0x8CF8; + static constexpr const GLenum COLOR_ATTACHMENT25 = 0x8CF9; + static constexpr const GLenum COLOR_ATTACHMENT26 = 0x8CFA; + static constexpr const GLenum COLOR_ATTACHMENT27 = 0x8CFB; + static constexpr const GLenum COLOR_ATTACHMENT28 = 0x8CFC; + static constexpr const GLenum COLOR_ATTACHMENT29 = 0x8CFD; + static constexpr const GLenum COLOR_ATTACHMENT30 = 0x8CFE; + static constexpr const GLenum COLOR_ATTACHMENT31 = 0x8CFF; + static constexpr const GLenum DEPTH_ATTACHMENT = 0x8D00; + static constexpr const GLenum STENCIL_ATTACHMENT = 0x8D20; + static constexpr const GLenum FRAMEBUFFER = 0x8D40; + static constexpr const GLenum RENDERBUFFER = 0x8D41; + static constexpr const GLenum RENDERBUFFER_WIDTH = 0x8D42; + static constexpr const GLenum RENDERBUFFER_HEIGHT = 0x8D43; + static constexpr const GLenum RENDERBUFFER_INTERNAL_FORMAT = 0x8D44; + static constexpr const GLenum STENCIL_INDEX1 = 0x8D46; + static constexpr const GLenum STENCIL_INDEX4 = 0x8D47; + static constexpr const GLenum STENCIL_INDEX8 = 0x8D48; + static constexpr const GLenum STENCIL_INDEX16 = 0x8D49; + static constexpr const GLenum RENDERBUFFER_RED_SIZE = 0x8D50; + static constexpr const GLenum RENDERBUFFER_GREEN_SIZE = 0x8D51; + static constexpr const GLenum RENDERBUFFER_BLUE_SIZE = 0x8D52; + static constexpr const GLenum RENDERBUFFER_ALPHA_SIZE = 0x8D53; + static constexpr const GLenum RENDERBUFFER_DEPTH_SIZE = 0x8D54; + static constexpr const GLenum RENDERBUFFER_STENCIL_SIZE = 0x8D55; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56; + static constexpr const GLenum MAX_SAMPLES = 0x8D57; + static constexpr const GLenum FRAMEBUFFER_SRGB = 0x8DB9; + static constexpr const GLenum HALF_FLOAT = 0x140B; + static constexpr const GLenum MAP_READ_BIT = 0x0001; + static constexpr const GLenum MAP_WRITE_BIT = 0x0002; + static constexpr const GLenum MAP_INVALIDATE_RANGE_BIT = 0x0004; + static constexpr const GLenum MAP_INVALIDATE_BUFFER_BIT = 0x0008; + static constexpr const GLenum MAP_FLUSH_EXPLICIT_BIT = 0x0010; + static constexpr const GLenum MAP_UNSYNCHRONIZED_BIT = 0x0020; + static constexpr const GLenum COMPRESSED_RED_RGTC1 = 0x8DBB; + static constexpr const GLenum COMPRESSED_SIGNED_RED_RGTC1 = 0x8DBC; + static constexpr const GLenum COMPRESSED_RG_RGTC2 = 0x8DBD; + static constexpr const GLenum COMPRESSED_SIGNED_RG_RGTC2 = 0x8DBE; + static constexpr const GLenum RG = 0x8227; + static constexpr const GLenum RG_INTEGER = 0x8228; + static constexpr const GLenum R8 = 0x8229; + static constexpr const GLenum R16 = 0x822A; + static constexpr const GLenum RG8 = 0x822B; + static constexpr const GLenum RG16 = 0x822C; + static constexpr const GLenum R16F = 0x822D; + static constexpr const GLenum R32F = 0x822E; + static constexpr const GLenum RG16F = 0x822F; + static constexpr const GLenum RG32F = 0x8230; + static constexpr const GLenum R8I = 0x8231; + static constexpr const GLenum R8UI = 0x8232; + static constexpr const GLenum R16I = 0x8233; + static constexpr const GLenum R16UI = 0x8234; + static constexpr const GLenum R32I = 0x8235; + static constexpr const GLenum R32UI = 0x8236; + static constexpr const GLenum RG8I = 0x8237; + static constexpr const GLenum RG8UI = 0x8238; + static constexpr const GLenum RG16I = 0x8239; + static constexpr const GLenum RG16UI = 0x823A; + static constexpr const GLenum RG32I = 0x823B; + static constexpr const GLenum RG32UI = 0x823C; + static constexpr const GLenum VERTEX_ARRAY_BINDING = 0x85B5; + static constexpr const GLenum SAMPLER_2D_RECT = 0x8B63; + static constexpr const GLenum SAMPLER_2D_RECT_SHADOW = 0x8B64; + static constexpr const GLenum SAMPLER_BUFFER = 0x8DC2; + static constexpr const GLenum INT_SAMPLER_2D_RECT = 0x8DCD; + static constexpr const GLenum INT_SAMPLER_BUFFER = 0x8DD0; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_2D_RECT = 0x8DD5; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_BUFFER = 0x8DD8; + static constexpr const GLenum TEXTURE_BUFFER = 0x8C2A; + static constexpr const GLenum MAX_TEXTURE_BUFFER_SIZE = 0x8C2B; + static constexpr const GLenum TEXTURE_BINDING_BUFFER = 0x8C2C; + static constexpr const GLenum TEXTURE_BUFFER_DATA_STORE_BINDING = 0x8C2D; + static constexpr const GLenum TEXTURE_RECTANGLE = 0x84F5; + static constexpr const GLenum TEXTURE_BINDING_RECTANGLE = 0x84F6; + static constexpr const GLenum PROXY_TEXTURE_RECTANGLE = 0x84F7; + static constexpr const GLenum MAX_RECTANGLE_TEXTURE_SIZE = 0x84F8; + static constexpr const GLenum R8_SNORM = 0x8F94; + static constexpr const GLenum RG8_SNORM = 0x8F95; + static constexpr const GLenum RGB8_SNORM = 0x8F96; + static constexpr const GLenum RGBA8_SNORM = 0x8F97; + static constexpr const GLenum R16_SNORM = 0x8F98; + static constexpr const GLenum RG16_SNORM = 0x8F99; + static constexpr const GLenum RGB16_SNORM = 0x8F9A; + static constexpr const GLenum RGBA16_SNORM = 0x8F9B; + static constexpr const GLenum SIGNED_NORMALIZED = 0x8F9C; + static constexpr const GLenum PRIMITIVE_RESTART = 0x8F9D; + static constexpr const GLenum PRIMITIVE_RESTART_INDEX = 0x8F9E; + static constexpr const GLenum COPY_READ_BUFFER = 0x8F36; + static constexpr const GLenum COPY_WRITE_BUFFER = 0x8F37; + static constexpr const GLenum UNIFORM_BUFFER = 0x8A11; + static constexpr const GLenum UNIFORM_BUFFER_BINDING = 0x8A28; + static constexpr const GLenum UNIFORM_BUFFER_START = 0x8A29; + static constexpr const GLenum UNIFORM_BUFFER_SIZE = 0x8A2A; + static constexpr const GLenum MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B; + static constexpr const GLenum MAX_GEOMETRY_UNIFORM_BLOCKS = 0x8A2C; + static constexpr const GLenum MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D; + static constexpr const GLenum MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E; + static constexpr const GLenum MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F; + static constexpr const GLenum MAX_UNIFORM_BLOCK_SIZE = 0x8A30; + static constexpr const GLenum MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31; + static constexpr const GLenum MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS = 0x8A32; + static constexpr const GLenum MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33; + static constexpr const GLenum UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34; + static constexpr const GLenum ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH = 0x8A35; + static constexpr const GLenum ACTIVE_UNIFORM_BLOCKS = 0x8A36; + static constexpr const GLenum UNIFORM_TYPE = 0x8A37; + static constexpr const GLenum UNIFORM_SIZE = 0x8A38; + static constexpr const GLenum UNIFORM_NAME_LENGTH = 0x8A39; + static constexpr const GLenum UNIFORM_BLOCK_INDEX = 0x8A3A; + static constexpr const GLenum UNIFORM_OFFSET = 0x8A3B; + static constexpr const GLenum UNIFORM_ARRAY_STRIDE = 0x8A3C; + static constexpr const GLenum UNIFORM_MATRIX_STRIDE = 0x8A3D; + static constexpr const GLenum UNIFORM_IS_ROW_MAJOR = 0x8A3E; + static constexpr const GLenum UNIFORM_BLOCK_BINDING = 0x8A3F; + static constexpr const GLenum UNIFORM_BLOCK_DATA_SIZE = 0x8A40; + static constexpr const GLenum UNIFORM_BLOCK_NAME_LENGTH = 0x8A41; + static constexpr const GLenum UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42; + static constexpr const GLenum UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43; + static constexpr const GLenum UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44; + static constexpr const GLenum UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER = 0x8A45; + static constexpr const GLenum UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46; + static constexpr const GLenum INVALID_INDEX = 0xFFFFFFFFu; + static constexpr const GLenum CONTEXT_CORE_PROFILE_BIT = 0x00000001; + static constexpr const GLenum CONTEXT_COMPATIBILITY_PROFILE_BIT = 0x00000002; + static constexpr const GLenum LINES_ADJACENCY = 0x000A; + static constexpr const GLenum LINE_STRIP_ADJACENCY = 0x000B; + static constexpr const GLenum TRIANGLES_ADJACENCY = 0x000C; + static constexpr const GLenum TRIANGLE_STRIP_ADJACENCY = 0x000D; + static constexpr const GLenum PROGRAM_POINT_SIZE = 0x8642; + static constexpr const GLenum MAX_GEOMETRY_TEXTURE_IMAGE_UNITS = 0x8C29; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_LAYERED = 0x8DA7; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS = 0x8DA8; + static constexpr const GLenum GEOMETRY_SHADER = 0x8DD9; + static constexpr const GLenum GEOMETRY_VERTICES_OUT = 0x8916; + static constexpr const GLenum GEOMETRY_INPUT_TYPE = 0x8917; + static constexpr const GLenum GEOMETRY_OUTPUT_TYPE = 0x8918; + static constexpr const GLenum MAX_GEOMETRY_UNIFORM_COMPONENTS = 0x8DDF; + static constexpr const GLenum MAX_GEOMETRY_OUTPUT_VERTICES = 0x8DE0; + static constexpr const GLenum MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS = 0x8DE1; + static constexpr const GLenum MAX_VERTEX_OUTPUT_COMPONENTS = 0x9122; + static constexpr const GLenum MAX_GEOMETRY_INPUT_COMPONENTS = 0x9123; + static constexpr const GLenum MAX_GEOMETRY_OUTPUT_COMPONENTS = 0x9124; + static constexpr const GLenum MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125; + static constexpr const GLenum CONTEXT_PROFILE_MASK = 0x9126; + static constexpr const GLenum DEPTH_CLAMP = 0x864F; + static constexpr const GLenum QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION = 0x8E4C; + static constexpr const GLenum FIRST_VERTEX_CONVENTION = 0x8E4D; + static constexpr const GLenum LAST_VERTEX_CONVENTION = 0x8E4E; + static constexpr const GLenum PROVOKING_VERTEX = 0x8E4F; + static constexpr const GLenum TEXTURE_CUBE_MAP_SEAMLESS = 0x884F; + static constexpr const GLenum MAX_SERVER_WAIT_TIMEOUT = 0x9111; + static constexpr const GLenum OBJECT_TYPE = 0x9112; + static constexpr const GLenum SYNC_CONDITION = 0x9113; + static constexpr const GLenum SYNC_STATUS = 0x9114; + static constexpr const GLenum SYNC_FLAGS = 0x9115; + static constexpr const GLenum SYNC_FENCE = 0x9116; + static constexpr const GLenum SYNC_GPU_COMMANDS_COMPLETE = 0x9117; + static constexpr const GLenum UNSIGNALED = 0x9118; + static constexpr const GLenum SIGNALED = 0x9119; + static constexpr const GLenum ALREADY_SIGNALED = 0x911A; + static constexpr const GLenum TIMEOUT_EXPIRED = 0x911B; + static constexpr const GLenum CONDITION_SATISFIED = 0x911C; + static constexpr const GLenum _WAIT_FAILED = 0x911D; + static constexpr const GLuint64 TIMEOUT_IGNORED = 0xFFFFFFFFFFFFFFFFull; + static constexpr const GLenum SYNC_FLUSH_COMMANDS_BIT = 0x00000001; + static constexpr const GLenum SAMPLE_POSITION = 0x8E50; + static constexpr const GLenum SAMPLE_MASK = 0x8E51; + static constexpr const GLenum SAMPLE_MASK_VALUE = 0x8E52; + static constexpr const GLenum MAX_SAMPLE_MASK_WORDS = 0x8E59; + static constexpr const GLenum TEXTURE_2D_MULTISAMPLE = 0x9100; + static constexpr const GLenum PROXY_TEXTURE_2D_MULTISAMPLE = 0x9101; + static constexpr const GLenum TEXTURE_2D_MULTISAMPLE_ARRAY = 0x9102; + static constexpr const GLenum PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY = 0x9103; + static constexpr const GLenum TEXTURE_BINDING_2D_MULTISAMPLE = 0x9104; + static constexpr const GLenum TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY = 0x9105; + static constexpr const GLenum TEXTURE_SAMPLES = 0x9106; + static constexpr const GLenum TEXTURE_FIXED_SAMPLE_LOCATIONS = 0x9107; + static constexpr const GLenum SAMPLER_2D_MULTISAMPLE = 0x9108; + static constexpr const GLenum INT_SAMPLER_2D_MULTISAMPLE = 0x9109; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE = 0x910A; + static constexpr const GLenum SAMPLER_2D_MULTISAMPLE_ARRAY = 0x910B; + static constexpr const GLenum INT_SAMPLER_2D_MULTISAMPLE_ARRAY = 0x910C; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY = 0x910D; + static constexpr const GLenum MAX_COLOR_TEXTURE_SAMPLES = 0x910E; + static constexpr const GLenum MAX_DEPTH_TEXTURE_SAMPLES = 0x910F; + static constexpr const GLenum MAX_INTEGER_SAMPLES = 0x9110; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE; + static constexpr const GLenum SRC1_COLOR = 0x88F9; + static constexpr const GLenum ONE_MINUS_SRC1_COLOR = 0x88FA; + static constexpr const GLenum ONE_MINUS_SRC1_ALPHA = 0x88FB; + static constexpr const GLenum MAX_DUAL_SOURCE_DRAW_BUFFERS = 0x88FC; + static constexpr const GLenum ANY_SAMPLES_PASSED = 0x8C2F; + static constexpr const GLenum SAMPLER_BINDING = 0x8919; + static constexpr const GLenum RGB10_A2UI = 0x906F; + static constexpr const GLenum TEXTURE_SWIZZLE_R = 0x8E42; + static constexpr const GLenum TEXTURE_SWIZZLE_G = 0x8E43; + static constexpr const GLenum TEXTURE_SWIZZLE_B = 0x8E44; + static constexpr const GLenum TEXTURE_SWIZZLE_A = 0x8E45; + static constexpr const GLenum TEXTURE_SWIZZLE_RGBA = 0x8E46; + static constexpr const GLenum TIME_ELAPSED = 0x88BF; + static constexpr const GLenum TIMESTAMP = 0x8E28; + static constexpr const GLenum INT_2_10_10_10_REV = 0x8D9F; + static constexpr const GLenum SAMPLE_SHADING = 0x8C36; + static constexpr const GLenum MIN_SAMPLE_SHADING_VALUE = 0x8C37; + static constexpr const GLenum MIN_PROGRAM_TEXTURE_GATHER_OFFSET = 0x8E5E; + static constexpr const GLenum MAX_PROGRAM_TEXTURE_GATHER_OFFSET = 0x8E5F; + static constexpr const GLenum TEXTURE_CUBE_MAP_ARRAY = 0x9009; + static constexpr const GLenum TEXTURE_BINDING_CUBE_MAP_ARRAY = 0x900A; + static constexpr const GLenum PROXY_TEXTURE_CUBE_MAP_ARRAY = 0x900B; + static constexpr const GLenum SAMPLER_CUBE_MAP_ARRAY = 0x900C; + static constexpr const GLenum SAMPLER_CUBE_MAP_ARRAY_SHADOW = 0x900D; + static constexpr const GLenum INT_SAMPLER_CUBE_MAP_ARRAY = 0x900E; + static constexpr const GLenum UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY = 0x900F; + static constexpr const GLenum DRAW_INDIRECT_BUFFER = 0x8F3F; + static constexpr const GLenum DRAW_INDIRECT_BUFFER_BINDING = 0x8F43; + static constexpr const GLenum GEOMETRY_SHADER_INVOCATIONS = 0x887F; + static constexpr const GLenum MAX_GEOMETRY_SHADER_INVOCATIONS = 0x8E5A; + static constexpr const GLenum MIN_FRAGMENT_INTERPOLATION_OFFSET = 0x8E5B; + static constexpr const GLenum MAX_FRAGMENT_INTERPOLATION_OFFSET = 0x8E5C; + static constexpr const GLenum FRAGMENT_INTERPOLATION_OFFSET_BITS = 0x8E5D; + static constexpr const GLenum MAX_VERTEX_STREAMS = 0x8E71; + static constexpr const GLenum DOUBLE_VEC2 = 0x8FFC; + static constexpr const GLenum DOUBLE_VEC3 = 0x8FFD; + static constexpr const GLenum DOUBLE_VEC4 = 0x8FFE; + static constexpr const GLenum DOUBLE_MAT2 = 0x8F46; + static constexpr const GLenum DOUBLE_MAT3 = 0x8F47; + static constexpr const GLenum DOUBLE_MAT4 = 0x8F48; + static constexpr const GLenum DOUBLE_MAT2x3 = 0x8F49; + static constexpr const GLenum DOUBLE_MAT2x4 = 0x8F4A; + static constexpr const GLenum DOUBLE_MAT3x2 = 0x8F4B; + static constexpr const GLenum DOUBLE_MAT3x4 = 0x8F4C; + static constexpr const GLenum DOUBLE_MAT4x2 = 0x8F4D; + static constexpr const GLenum DOUBLE_MAT4x3 = 0x8F4E; + static constexpr const GLenum ACTIVE_SUBROUTINES = 0x8DE5; + static constexpr const GLenum ACTIVE_SUBROUTINE_UNIFORMS = 0x8DE6; + static constexpr const GLenum ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS = 0x8E47; + static constexpr const GLenum ACTIVE_SUBROUTINE_MAX_LENGTH = 0x8E48; + static constexpr const GLenum ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH = 0x8E49; + static constexpr const GLenum MAX_SUBROUTINES = 0x8DE7; + static constexpr const GLenum MAX_SUBROUTINE_UNIFORM_LOCATIONS = 0x8DE8; + static constexpr const GLenum NUM_COMPATIBLE_SUBROUTINES = 0x8E4A; + static constexpr const GLenum COMPATIBLE_SUBROUTINES = 0x8E4B; + static constexpr const GLenum PATCHES = 0x000E; + static constexpr const GLenum PATCH_VERTICES = 0x8E72; + static constexpr const GLenum PATCH_DEFAULT_INNER_LEVEL = 0x8E73; + static constexpr const GLenum PATCH_DEFAULT_OUTER_LEVEL = 0x8E74; + static constexpr const GLenum TESS_CONTROL_OUTPUT_VERTICES = 0x8E75; + static constexpr const GLenum TESS_GEN_MODE = 0x8E76; + static constexpr const GLenum TESS_GEN_SPACING = 0x8E77; + static constexpr const GLenum TESS_GEN_VERTEX_ORDER = 0x8E78; + static constexpr const GLenum TESS_GEN_POINT_MODE = 0x8E79; + static constexpr const GLenum ISOLINES = 0x8E7A; + static constexpr const GLenum FRACTIONAL_ODD = 0x8E7B; + static constexpr const GLenum FRACTIONAL_EVEN = 0x8E7C; + static constexpr const GLenum MAX_PATCH_VERTICES = 0x8E7D; + static constexpr const GLenum MAX_TESS_GEN_LEVEL = 0x8E7E; + static constexpr const GLenum MAX_TESS_CONTROL_UNIFORM_COMPONENTS = 0x8E7F; + static constexpr const GLenum MAX_TESS_EVALUATION_UNIFORM_COMPONENTS = 0x8E80; + static constexpr const GLenum MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS = 0x8E81; + static constexpr const GLenum MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS = 0x8E82; + static constexpr const GLenum MAX_TESS_CONTROL_OUTPUT_COMPONENTS = 0x8E83; + static constexpr const GLenum MAX_TESS_PATCH_COMPONENTS = 0x8E84; + static constexpr const GLenum MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS = 0x8E85; + static constexpr const GLenum MAX_TESS_EVALUATION_OUTPUT_COMPONENTS = 0x8E86; + static constexpr const GLenum MAX_TESS_CONTROL_UNIFORM_BLOCKS = 0x8E89; + static constexpr const GLenum MAX_TESS_EVALUATION_UNIFORM_BLOCKS = 0x8E8A; + static constexpr const GLenum MAX_TESS_CONTROL_INPUT_COMPONENTS = 0x886C; + static constexpr const GLenum MAX_TESS_EVALUATION_INPUT_COMPONENTS = 0x886D; + static constexpr const GLenum MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS = 0x8E1E; + static constexpr const GLenum MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS = 0x8E1F; + static constexpr const GLenum UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER = 0x84F0; + static constexpr const GLenum UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER = 0x84F1; + static constexpr const GLenum TESS_EVALUATION_SHADER = 0x8E87; + static constexpr const GLenum TESS_CONTROL_SHADER = 0x8E88; + static constexpr const GLenum TRANSFORM_FEEDBACK = 0x8E22; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_PAUSED = 0x8E23; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_ACTIVE = 0x8E24; + static constexpr const GLenum TRANSFORM_FEEDBACK_BINDING = 0x8E25; + static constexpr const GLenum MAX_TRANSFORM_FEEDBACK_BUFFERS = 0x8E70; + static constexpr const GLenum FIXED = 0x140C; + static constexpr const GLenum IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A; + static constexpr const GLenum IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B; + static constexpr const GLenum LOW_FLOAT = 0x8DF0; + static constexpr const GLenum MEDIUM_FLOAT = 0x8DF1; + static constexpr const GLenum HIGH_FLOAT = 0x8DF2; + static constexpr const GLenum LOW_INT = 0x8DF3; + static constexpr const GLenum MEDIUM_INT = 0x8DF4; + static constexpr const GLenum HIGH_INT = 0x8DF5; + static constexpr const GLenum SHADER_COMPILER = 0x8DFA; + static constexpr const GLenum SHADER_BINARY_FORMATS = 0x8DF8; + static constexpr const GLenum NUM_SHADER_BINARY_FORMATS = 0x8DF9; + static constexpr const GLenum MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB; + static constexpr const GLenum MAX_VARYING_VECTORS = 0x8DFC; + static constexpr const GLenum MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD; + static constexpr const GLenum RGB565 = 0x8D62; + static constexpr const GLenum PROGRAM_BINARY_RETRIEVABLE_HINT = 0x8257; + static constexpr const GLenum PROGRAM_BINARY_LENGTH = 0x8741; + static constexpr const GLenum NUM_PROGRAM_BINARY_FORMATS = 0x87FE; + static constexpr const GLenum PROGRAM_BINARY_FORMATS = 0x87FF; + static constexpr const GLenum VERTEX_SHADER_BIT = 0x00000001; + static constexpr const GLenum FRAGMENT_SHADER_BIT = 0x00000002; + static constexpr const GLenum GEOMETRY_SHADER_BIT = 0x00000004; + static constexpr const GLenum TESS_CONTROL_SHADER_BIT = 0x00000008; + static constexpr const GLenum TESS_EVALUATION_SHADER_BIT = 0x00000010; + static constexpr const GLenum ALL_SHADER_BITS = 0xFFFFFFFF; + static constexpr const GLenum PROGRAM_SEPARABLE = 0x8258; + static constexpr const GLenum ACTIVE_PROGRAM = 0x8259; + static constexpr const GLenum PROGRAM_PIPELINE_BINDING = 0x825A; + static constexpr const GLenum MAX_VIEWPORTS = 0x825B; + static constexpr const GLenum VIEWPORT_SUBPIXEL_BITS = 0x825C; + static constexpr const GLenum VIEWPORT_BOUNDS_RANGE = 0x825D; + static constexpr const GLenum LAYER_PROVOKING_VERTEX = 0x825E; + static constexpr const GLenum VIEWPORT_INDEX_PROVOKING_VERTEX = 0x825F; + static constexpr const GLenum UNDEFINED_VERTEX = 0x8260; + static constexpr const GLenum COPY_READ_BUFFER_BINDING = 0x8F36; + static constexpr const GLenum COPY_WRITE_BUFFER_BINDING = 0x8F37; + static constexpr const GLenum TRANSFORM_FEEDBACK_ACTIVE = 0x8E24; + static constexpr const GLenum TRANSFORM_FEEDBACK_PAUSED = 0x8E23; + static constexpr const GLenum UNPACK_COMPRESSED_BLOCK_WIDTH = 0x9127; + static constexpr const GLenum UNPACK_COMPRESSED_BLOCK_HEIGHT = 0x9128; + static constexpr const GLenum UNPACK_COMPRESSED_BLOCK_DEPTH = 0x9129; + static constexpr const GLenum UNPACK_COMPRESSED_BLOCK_SIZE = 0x912A; + static constexpr const GLenum PACK_COMPRESSED_BLOCK_WIDTH = 0x912B; + static constexpr const GLenum PACK_COMPRESSED_BLOCK_HEIGHT = 0x912C; + static constexpr const GLenum PACK_COMPRESSED_BLOCK_DEPTH = 0x912D; + static constexpr const GLenum PACK_COMPRESSED_BLOCK_SIZE = 0x912E; + static constexpr const GLenum NUM_SAMPLE_COUNTS = 0x9380; + static constexpr const GLenum MIN_MAP_BUFFER_ALIGNMENT = 0x90BC; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER = 0x92C0; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_BINDING = 0x92C1; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_START = 0x92C2; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_SIZE = 0x92C3; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_DATA_SIZE = 0x92C4; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS = 0x92C5; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES = 0x92C6; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER = 0x92C7; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER = 0x92C8; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER = 0x92C9; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER = 0x92CA; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER = 0x92CB; + static constexpr const GLenum MAX_VERTEX_ATOMIC_COUNTER_BUFFERS = 0x92CC; + static constexpr const GLenum MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS = 0x92CD; + static constexpr const GLenum MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS = 0x92CE; + static constexpr const GLenum MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS = 0x92CF; + static constexpr const GLenum MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS = 0x92D0; + static constexpr const GLenum MAX_COMBINED_ATOMIC_COUNTER_BUFFERS = 0x92D1; + static constexpr const GLenum MAX_VERTEX_ATOMIC_COUNTERS = 0x92D2; + static constexpr const GLenum MAX_TESS_CONTROL_ATOMIC_COUNTERS = 0x92D3; + static constexpr const GLenum MAX_TESS_EVALUATION_ATOMIC_COUNTERS = 0x92D4; + static constexpr const GLenum MAX_GEOMETRY_ATOMIC_COUNTERS = 0x92D5; + static constexpr const GLenum MAX_FRAGMENT_ATOMIC_COUNTERS = 0x92D6; + static constexpr const GLenum MAX_COMBINED_ATOMIC_COUNTERS = 0x92D7; + static constexpr const GLenum MAX_ATOMIC_COUNTER_BUFFER_SIZE = 0x92D8; + static constexpr const GLenum MAX_ATOMIC_COUNTER_BUFFER_BINDINGS = 0x92DC; + static constexpr const GLenum ACTIVE_ATOMIC_COUNTER_BUFFERS = 0x92D9; + static constexpr const GLenum UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX = 0x92DA; + static constexpr const GLenum UNSIGNED_INT_ATOMIC_COUNTER = 0x92DB; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_BARRIER_BIT = 0x00000001; + static constexpr const GLenum ELEMENT_ARRAY_BARRIER_BIT = 0x00000002; + static constexpr const GLenum UNIFORM_BARRIER_BIT = 0x00000004; + static constexpr const GLenum TEXTURE_FETCH_BARRIER_BIT = 0x00000008; + static constexpr const GLenum SHADER_IMAGE_ACCESS_BARRIER_BIT = 0x00000020; + static constexpr const GLenum COMMAND_BARRIER_BIT = 0x00000040; + static constexpr const GLenum PIXEL_BUFFER_BARRIER_BIT = 0x00000080; + static constexpr const GLenum TEXTURE_UPDATE_BARRIER_BIT = 0x00000100; + static constexpr const GLenum BUFFER_UPDATE_BARRIER_BIT = 0x00000200; + static constexpr const GLenum FRAMEBUFFER_BARRIER_BIT = 0x00000400; + static constexpr const GLenum TRANSFORM_FEEDBACK_BARRIER_BIT = 0x00000800; + static constexpr const GLenum ATOMIC_COUNTER_BARRIER_BIT = 0x00001000; + static constexpr const GLenum ALL_BARRIER_BITS = 0xFFFFFFFF; + static constexpr const GLenum MAX_IMAGE_UNITS = 0x8F38; + static constexpr const GLenum MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS = 0x8F39; + static constexpr const GLenum IMAGE_BINDING_NAME = 0x8F3A; + static constexpr const GLenum IMAGE_BINDING_LEVEL = 0x8F3B; + static constexpr const GLenum IMAGE_BINDING_LAYERED = 0x8F3C; + static constexpr const GLenum IMAGE_BINDING_LAYER = 0x8F3D; + static constexpr const GLenum IMAGE_BINDING_ACCESS = 0x8F3E; + static constexpr const GLenum IMAGE_1D = 0x904C; + static constexpr const GLenum IMAGE_2D = 0x904D; + static constexpr const GLenum IMAGE_3D = 0x904E; + static constexpr const GLenum IMAGE_2D_RECT = 0x904F; + static constexpr const GLenum IMAGE_CUBE = 0x9050; + static constexpr const GLenum IMAGE_BUFFER = 0x9051; + static constexpr const GLenum IMAGE_1D_ARRAY = 0x9052; + static constexpr const GLenum IMAGE_2D_ARRAY = 0x9053; + static constexpr const GLenum IMAGE_CUBE_MAP_ARRAY = 0x9054; + static constexpr const GLenum IMAGE_2D_MULTISAMPLE = 0x9055; + static constexpr const GLenum IMAGE_2D_MULTISAMPLE_ARRAY = 0x9056; + static constexpr const GLenum INT_IMAGE_1D = 0x9057; + static constexpr const GLenum INT_IMAGE_2D = 0x9058; + static constexpr const GLenum INT_IMAGE_3D = 0x9059; + static constexpr const GLenum INT_IMAGE_2D_RECT = 0x905A; + static constexpr const GLenum INT_IMAGE_CUBE = 0x905B; + static constexpr const GLenum INT_IMAGE_BUFFER = 0x905C; + static constexpr const GLenum INT_IMAGE_1D_ARRAY = 0x905D; + static constexpr const GLenum INT_IMAGE_2D_ARRAY = 0x905E; + static constexpr const GLenum INT_IMAGE_CUBE_MAP_ARRAY = 0x905F; + static constexpr const GLenum INT_IMAGE_2D_MULTISAMPLE = 0x9060; + static constexpr const GLenum INT_IMAGE_2D_MULTISAMPLE_ARRAY = 0x9061; + static constexpr const GLenum UNSIGNED_INT_IMAGE_1D = 0x9062; + static constexpr const GLenum UNSIGNED_INT_IMAGE_2D = 0x9063; + static constexpr const GLenum UNSIGNED_INT_IMAGE_3D = 0x9064; + static constexpr const GLenum UNSIGNED_INT_IMAGE_2D_RECT = 0x9065; + static constexpr const GLenum UNSIGNED_INT_IMAGE_CUBE = 0x9066; + static constexpr const GLenum UNSIGNED_INT_IMAGE_BUFFER = 0x9067; + static constexpr const GLenum UNSIGNED_INT_IMAGE_1D_ARRAY = 0x9068; + static constexpr const GLenum UNSIGNED_INT_IMAGE_2D_ARRAY = 0x9069; + static constexpr const GLenum UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY = 0x906A; + static constexpr const GLenum UNSIGNED_INT_IMAGE_2D_MULTISAMPLE = 0x906B; + static constexpr const GLenum UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY = 0x906C; + static constexpr const GLenum MAX_IMAGE_SAMPLES = 0x906D; + static constexpr const GLenum IMAGE_BINDING_FORMAT = 0x906E; + static constexpr const GLenum IMAGE_FORMAT_COMPATIBILITY_TYPE = 0x90C7; + static constexpr const GLenum IMAGE_FORMAT_COMPATIBILITY_BY_SIZE = 0x90C8; + static constexpr const GLenum IMAGE_FORMAT_COMPATIBILITY_BY_CLASS = 0x90C9; + static constexpr const GLenum MAX_VERTEX_IMAGE_UNIFORMS = 0x90CA; + static constexpr const GLenum MAX_TESS_CONTROL_IMAGE_UNIFORMS = 0x90CB; + static constexpr const GLenum MAX_TESS_EVALUATION_IMAGE_UNIFORMS = 0x90CC; + static constexpr const GLenum MAX_GEOMETRY_IMAGE_UNIFORMS = 0x90CD; + static constexpr const GLenum MAX_FRAGMENT_IMAGE_UNIFORMS = 0x90CE; + static constexpr const GLenum MAX_COMBINED_IMAGE_UNIFORMS = 0x90CF; + static constexpr const GLenum COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C; + static constexpr const GLenum COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 0x8E8D; + static constexpr const GLenum COMPRESSED_RGB_BPTC_SIGNED_FLOAT = 0x8E8E; + static constexpr const GLenum COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT = 0x8E8F; + static constexpr const GLenum TEXTURE_IMMUTABLE_FORMAT = 0x912F; + static constexpr const GLenum NUM_SHADING_LANGUAGE_VERSIONS = 0x82E9; + static constexpr const GLenum VERTEX_ATTRIB_ARRAY_LONG = 0x874E; + static constexpr const GLenum COMPRESSED_RGB8_ETC2 = 0x9274; + static constexpr const GLenum COMPRESSED_SRGB8_ETC2 = 0x9275; + static constexpr const GLenum COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276; + static constexpr const GLenum COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277; + static constexpr const GLenum COMPRESSED_RGBA8_ETC2_EAC = 0x9278; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279; + static constexpr const GLenum COMPRESSED_R11_EAC = 0x9270; + static constexpr const GLenum COMPRESSED_SIGNED_R11_EAC = 0x9271; + static constexpr const GLenum COMPRESSED_RG11_EAC = 0x9272; + static constexpr const GLenum COMPRESSED_SIGNED_RG11_EAC = 0x9273; + static constexpr const GLenum PRIMITIVE_RESTART_FIXED_INDEX = 0x8D69; + static constexpr const GLenum ANY_SAMPLES_PASSED_CONSERVATIVE = 0x8D6A; + static constexpr const GLenum MAX_ELEMENT_INDEX = 0x8D6B; + static constexpr const GLenum COMPUTE_SHADER = 0x91B9; + static constexpr const GLenum MAX_COMPUTE_UNIFORM_BLOCKS = 0x91BB; + static constexpr const GLenum MAX_COMPUTE_TEXTURE_IMAGE_UNITS = 0x91BC; + static constexpr const GLenum MAX_COMPUTE_IMAGE_UNIFORMS = 0x91BD; + static constexpr const GLenum MAX_COMPUTE_SHARED_MEMORY_SIZE = 0x8262; + static constexpr const GLenum MAX_COMPUTE_UNIFORM_COMPONENTS = 0x8263; + static constexpr const GLenum MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS = 0x8264; + static constexpr const GLenum MAX_COMPUTE_ATOMIC_COUNTERS = 0x8265; + static constexpr const GLenum MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS = 0x8266; + static constexpr const GLenum MAX_COMPUTE_WORK_GROUP_INVOCATIONS = 0x90EB; + static constexpr const GLenum MAX_COMPUTE_WORK_GROUP_COUNT = 0x91BE; + static constexpr const GLenum MAX_COMPUTE_WORK_GROUP_SIZE = 0x91BF; + static constexpr const GLenum COMPUTE_WORK_GROUP_SIZE = 0x8267; + static constexpr const GLenum UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER = 0x90EC; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER = 0x90ED; + static constexpr const GLenum DISPATCH_INDIRECT_BUFFER = 0x90EE; + static constexpr const GLenum DISPATCH_INDIRECT_BUFFER_BINDING = 0x90EF; + static constexpr const GLenum COMPUTE_SHADER_BIT = 0x00000020; + static constexpr const GLenum DEBUG_OUTPUT_SYNCHRONOUS = 0x8242; + static constexpr const GLenum DEBUG_NEXT_LOGGED_MESSAGE_LENGTH = 0x8243; + static constexpr const GLenum DEBUG_CALLBACK_FUNCTION = 0x8244; + static constexpr const GLenum DEBUG_CALLBACK_USER_PARAM = 0x8245; + static constexpr const GLenum DEBUG_SOURCE_API = 0x8246; + static constexpr const GLenum DEBUG_SOURCE_WINDOW_SYSTEM = 0x8247; + static constexpr const GLenum DEBUG_SOURCE_SHADER_COMPILER = 0x8248; + static constexpr const GLenum DEBUG_SOURCE_THIRD_PARTY = 0x8249; + static constexpr const GLenum DEBUG_SOURCE_APPLICATION = 0x824A; + static constexpr const GLenum DEBUG_SOURCE_OTHER = 0x824B; + static constexpr const GLenum DEBUG_TYPE_ERROR = 0x824C; + static constexpr const GLenum DEBUG_TYPE_DEPRECATED_BEHAVIOR = 0x824D; + static constexpr const GLenum DEBUG_TYPE_UNDEFINED_BEHAVIOR = 0x824E; + static constexpr const GLenum DEBUG_TYPE_PORTABILITY = 0x824F; + static constexpr const GLenum DEBUG_TYPE_PERFORMANCE = 0x8250; + static constexpr const GLenum DEBUG_TYPE_OTHER = 0x8251; + static constexpr const GLenum MAX_DEBUG_MESSAGE_LENGTH = 0x9143; + static constexpr const GLenum MAX_DEBUG_LOGGED_MESSAGES = 0x9144; + static constexpr const GLenum DEBUG_LOGGED_MESSAGES = 0x9145; + static constexpr const GLenum DEBUG_SEVERITY_HIGH = 0x9146; + static constexpr const GLenum DEBUG_SEVERITY_MEDIUM = 0x9147; + static constexpr const GLenum DEBUG_SEVERITY_LOW = 0x9148; + static constexpr const GLenum DEBUG_TYPE_MARKER = 0x8268; + static constexpr const GLenum DEBUG_TYPE_PUSH_GROUP = 0x8269; + static constexpr const GLenum DEBUG_TYPE_POP_GROUP = 0x826A; + static constexpr const GLenum DEBUG_SEVERITY_NOTIFICATION = 0x826B; + static constexpr const GLenum MAX_DEBUG_GROUP_STACK_DEPTH = 0x826C; + static constexpr const GLenum DEBUG_GROUP_STACK_DEPTH = 0x826D; + static constexpr const GLenum BUFFER = 0x82E0; + static constexpr const GLenum SHADER = 0x82E1; + static constexpr const GLenum PROGRAM = 0x82E2; + static constexpr const GLenum QUERY = 0x82E3; + static constexpr const GLenum PROGRAM_PIPELINE = 0x82E4; + static constexpr const GLenum SAMPLER = 0x82E6; + static constexpr const GLenum MAX_LABEL_LENGTH = 0x82E8; + static constexpr const GLenum DEBUG_OUTPUT = 0x92E0; + static constexpr const GLenum CONTEXT_FLAG_DEBUG_BIT = 0x00000002; + static constexpr const GLenum MAX_UNIFORM_LOCATIONS = 0x826E; + static constexpr const GLenum FRAMEBUFFER_DEFAULT_WIDTH = 0x9310; + static constexpr const GLenum FRAMEBUFFER_DEFAULT_HEIGHT = 0x9311; + static constexpr const GLenum FRAMEBUFFER_DEFAULT_LAYERS = 0x9312; + static constexpr const GLenum FRAMEBUFFER_DEFAULT_SAMPLES = 0x9313; + static constexpr const GLenum FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS = 0x9314; + static constexpr const GLenum MAX_FRAMEBUFFER_WIDTH = 0x9315; + static constexpr const GLenum MAX_FRAMEBUFFER_HEIGHT = 0x9316; + static constexpr const GLenum MAX_FRAMEBUFFER_LAYERS = 0x9317; + static constexpr const GLenum MAX_FRAMEBUFFER_SAMPLES = 0x9318; + static constexpr const GLenum INTERNALFORMAT_SUPPORTED = 0x826F; + static constexpr const GLenum INTERNALFORMAT_PREFERRED = 0x8270; + static constexpr const GLenum INTERNALFORMAT_RED_SIZE = 0x8271; + static constexpr const GLenum INTERNALFORMAT_GREEN_SIZE = 0x8272; + static constexpr const GLenum INTERNALFORMAT_BLUE_SIZE = 0x8273; + static constexpr const GLenum INTERNALFORMAT_ALPHA_SIZE = 0x8274; + static constexpr const GLenum INTERNALFORMAT_DEPTH_SIZE = 0x8275; + static constexpr const GLenum INTERNALFORMAT_STENCIL_SIZE = 0x8276; + static constexpr const GLenum INTERNALFORMAT_SHARED_SIZE = 0x8277; + static constexpr const GLenum INTERNALFORMAT_RED_TYPE = 0x8278; + static constexpr const GLenum INTERNALFORMAT_GREEN_TYPE = 0x8279; + static constexpr const GLenum INTERNALFORMAT_BLUE_TYPE = 0x827A; + static constexpr const GLenum INTERNALFORMAT_ALPHA_TYPE = 0x827B; + static constexpr const GLenum INTERNALFORMAT_DEPTH_TYPE = 0x827C; + static constexpr const GLenum INTERNALFORMAT_STENCIL_TYPE = 0x827D; + static constexpr const GLenum MAX_WIDTH = 0x827E; + static constexpr const GLenum MAX_HEIGHT = 0x827F; + static constexpr const GLenum MAX_DEPTH = 0x8280; + static constexpr const GLenum MAX_LAYERS = 0x8281; + static constexpr const GLenum MAX_COMBINED_DIMENSIONS = 0x8282; + static constexpr const GLenum COLOR_COMPONENTS = 0x8283; + static constexpr const GLenum DEPTH_COMPONENTS = 0x8284; + static constexpr const GLenum STENCIL_COMPONENTS = 0x8285; + static constexpr const GLenum COLOR_RENDERABLE = 0x8286; + static constexpr const GLenum DEPTH_RENDERABLE = 0x8287; + static constexpr const GLenum STENCIL_RENDERABLE = 0x8288; + static constexpr const GLenum FRAMEBUFFER_RENDERABLE = 0x8289; + static constexpr const GLenum FRAMEBUFFER_RENDERABLE_LAYERED = 0x828A; + static constexpr const GLenum FRAMEBUFFER_BLEND = 0x828B; + static constexpr const GLenum READ_PIXELS = 0x828C; + static constexpr const GLenum READ_PIXELS_FORMAT = 0x828D; + static constexpr const GLenum READ_PIXELS_TYPE = 0x828E; + static constexpr const GLenum TEXTURE_IMAGE_FORMAT = 0x828F; + static constexpr const GLenum TEXTURE_IMAGE_TYPE = 0x8290; + static constexpr const GLenum GET_TEXTURE_IMAGE_FORMAT = 0x8291; + static constexpr const GLenum GET_TEXTURE_IMAGE_TYPE = 0x8292; + static constexpr const GLenum MIPMAP = 0x8293; + static constexpr const GLenum MANUAL_GENERATE_MIPMAP = 0x8294; + static constexpr const GLenum AUTO_GENERATE_MIPMAP = 0x8295; + static constexpr const GLenum COLOR_ENCODING = 0x8296; + static constexpr const GLenum SRGB_READ = 0x8297; + static constexpr const GLenum SRGB_WRITE = 0x8298; + static constexpr const GLenum FILTER = 0x829A; + static constexpr const GLenum VERTEX_TEXTURE = 0x829B; + static constexpr const GLenum TESS_CONTROL_TEXTURE = 0x829C; + static constexpr const GLenum TESS_EVALUATION_TEXTURE = 0x829D; + static constexpr const GLenum GEOMETRY_TEXTURE = 0x829E; + static constexpr const GLenum FRAGMENT_TEXTURE = 0x829F; + static constexpr const GLenum COMPUTE_TEXTURE = 0x82A0; + static constexpr const GLenum TEXTURE_SHADOW = 0x82A1; + static constexpr const GLenum TEXTURE_GATHER = 0x82A2; + static constexpr const GLenum TEXTURE_GATHER_SHADOW = 0x82A3; + static constexpr const GLenum SHADER_IMAGE_LOAD = 0x82A4; + static constexpr const GLenum SHADER_IMAGE_STORE = 0x82A5; + static constexpr const GLenum SHADER_IMAGE_ATOMIC = 0x82A6; + static constexpr const GLenum IMAGE_TEXEL_SIZE = 0x82A7; + static constexpr const GLenum IMAGE_COMPATIBILITY_CLASS = 0x82A8; + static constexpr const GLenum IMAGE_PIXEL_FORMAT = 0x82A9; + static constexpr const GLenum IMAGE_PIXEL_TYPE = 0x82AA; + static constexpr const GLenum SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST = 0x82AC; + static constexpr const GLenum SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST = 0x82AD; + static constexpr const GLenum SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE = 0x82AE; + static constexpr const GLenum SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE = 0x82AF; + static constexpr const GLenum TEXTURE_COMPRESSED_BLOCK_WIDTH = 0x82B1; + static constexpr const GLenum TEXTURE_COMPRESSED_BLOCK_HEIGHT = 0x82B2; + static constexpr const GLenum TEXTURE_COMPRESSED_BLOCK_SIZE = 0x82B3; + static constexpr const GLenum CLEAR_BUFFER = 0x82B4; + static constexpr const GLenum TEXTURE_VIEW = 0x82B5; + static constexpr const GLenum VIEW_COMPATIBILITY_CLASS = 0x82B6; + static constexpr const GLenum FULL_SUPPORT = 0x82B7; + static constexpr const GLenum CAVEAT_SUPPORT = 0x82B8; + static constexpr const GLenum IMAGE_CLASS_4_X_32 = 0x82B9; + static constexpr const GLenum IMAGE_CLASS_2_X_32 = 0x82BA; + static constexpr const GLenum IMAGE_CLASS_1_X_32 = 0x82BB; + static constexpr const GLenum IMAGE_CLASS_4_X_16 = 0x82BC; + static constexpr const GLenum IMAGE_CLASS_2_X_16 = 0x82BD; + static constexpr const GLenum IMAGE_CLASS_1_X_16 = 0x82BE; + static constexpr const GLenum IMAGE_CLASS_4_X_8 = 0x82BF; + static constexpr const GLenum IMAGE_CLASS_2_X_8 = 0x82C0; + static constexpr const GLenum IMAGE_CLASS_1_X_8 = 0x82C1; + static constexpr const GLenum IMAGE_CLASS_11_11_10 = 0x82C2; + static constexpr const GLenum IMAGE_CLASS_10_10_10_2 = 0x82C3; + static constexpr const GLenum VIEW_CLASS_128_BITS = 0x82C4; + static constexpr const GLenum VIEW_CLASS_96_BITS = 0x82C5; + static constexpr const GLenum VIEW_CLASS_64_BITS = 0x82C6; + static constexpr const GLenum VIEW_CLASS_48_BITS = 0x82C7; + static constexpr const GLenum VIEW_CLASS_32_BITS = 0x82C8; + static constexpr const GLenum VIEW_CLASS_24_BITS = 0x82C9; + static constexpr const GLenum VIEW_CLASS_16_BITS = 0x82CA; + static constexpr const GLenum VIEW_CLASS_8_BITS = 0x82CB; + static constexpr const GLenum VIEW_CLASS_S3TC_DXT1_RGB = 0x82CC; + static constexpr const GLenum VIEW_CLASS_S3TC_DXT1_RGBA = 0x82CD; + static constexpr const GLenum VIEW_CLASS_S3TC_DXT3_RGBA = 0x82CE; + static constexpr const GLenum VIEW_CLASS_S3TC_DXT5_RGBA = 0x82CF; + static constexpr const GLenum VIEW_CLASS_RGTC1_RED = 0x82D0; + static constexpr const GLenum VIEW_CLASS_RGTC2_RG = 0x82D1; + static constexpr const GLenum VIEW_CLASS_BPTC_UNORM = 0x82D2; + static constexpr const GLenum VIEW_CLASS_BPTC_FLOAT = 0x82D3; + static constexpr const GLenum UNIFORM = 0x92E1; + static constexpr const GLenum UNIFORM_BLOCK = 0x92E2; + static constexpr const GLenum PROGRAM_INPUT = 0x92E3; + static constexpr const GLenum PROGRAM_OUTPUT = 0x92E4; + static constexpr const GLenum BUFFER_VARIABLE = 0x92E5; + static constexpr const GLenum SHADER_STORAGE_BLOCK = 0x92E6; + static constexpr const GLenum VERTEX_SUBROUTINE = 0x92E8; + static constexpr const GLenum TESS_CONTROL_SUBROUTINE = 0x92E9; + static constexpr const GLenum TESS_EVALUATION_SUBROUTINE = 0x92EA; + static constexpr const GLenum GEOMETRY_SUBROUTINE = 0x92EB; + static constexpr const GLenum FRAGMENT_SUBROUTINE = 0x92EC; + static constexpr const GLenum COMPUTE_SUBROUTINE = 0x92ED; + static constexpr const GLenum VERTEX_SUBROUTINE_UNIFORM = 0x92EE; + static constexpr const GLenum TESS_CONTROL_SUBROUTINE_UNIFORM = 0x92EF; + static constexpr const GLenum TESS_EVALUATION_SUBROUTINE_UNIFORM = 0x92F0; + static constexpr const GLenum GEOMETRY_SUBROUTINE_UNIFORM = 0x92F1; + static constexpr const GLenum FRAGMENT_SUBROUTINE_UNIFORM = 0x92F2; + static constexpr const GLenum COMPUTE_SUBROUTINE_UNIFORM = 0x92F3; + static constexpr const GLenum TRANSFORM_FEEDBACK_VARYING = 0x92F4; + static constexpr const GLenum ACTIVE_RESOURCES = 0x92F5; + static constexpr const GLenum MAX_NAME_LENGTH = 0x92F6; + static constexpr const GLenum MAX_NUM_ACTIVE_VARIABLES = 0x92F7; + static constexpr const GLenum MAX_NUM_COMPATIBLE_SUBROUTINES = 0x92F8; + static constexpr const GLenum NAME_LENGTH = 0x92F9; + static constexpr const GLenum TYPE = 0x92FA; + static constexpr const GLenum ARRAY_SIZE = 0x92FB; + static constexpr const GLenum OFFSET = 0x92FC; + static constexpr const GLenum BLOCK_INDEX = 0x92FD; + static constexpr const GLenum ARRAY_STRIDE = 0x92FE; + static constexpr const GLenum MATRIX_STRIDE = 0x92FF; + static constexpr const GLenum IS_ROW_MAJOR = 0x9300; + static constexpr const GLenum ATOMIC_COUNTER_BUFFER_INDEX = 0x9301; + static constexpr const GLenum BUFFER_BINDING = 0x9302; + static constexpr const GLenum BUFFER_DATA_SIZE = 0x9303; + static constexpr const GLenum NUM_ACTIVE_VARIABLES = 0x9304; + static constexpr const GLenum ACTIVE_VARIABLES = 0x9305; + static constexpr const GLenum REFERENCED_BY_VERTEX_SHADER = 0x9306; + static constexpr const GLenum REFERENCED_BY_TESS_CONTROL_SHADER = 0x9307; + static constexpr const GLenum REFERENCED_BY_TESS_EVALUATION_SHADER = 0x9308; + static constexpr const GLenum REFERENCED_BY_GEOMETRY_SHADER = 0x9309; + static constexpr const GLenum REFERENCED_BY_FRAGMENT_SHADER = 0x930A; + static constexpr const GLenum REFERENCED_BY_COMPUTE_SHADER = 0x930B; + static constexpr const GLenum TOP_LEVEL_ARRAY_SIZE = 0x930C; + static constexpr const GLenum TOP_LEVEL_ARRAY_STRIDE = 0x930D; + static constexpr const GLenum LOCATION = 0x930E; + static constexpr const GLenum LOCATION_INDEX = 0x930F; + static constexpr const GLenum IS_PER_PATCH = 0x92E7; + static constexpr const GLenum SHADER_STORAGE_BUFFER = 0x90D2; + static constexpr const GLenum SHADER_STORAGE_BUFFER_BINDING = 0x90D3; + static constexpr const GLenum SHADER_STORAGE_BUFFER_START = 0x90D4; + static constexpr const GLenum SHADER_STORAGE_BUFFER_SIZE = 0x90D5; + static constexpr const GLenum MAX_VERTEX_SHADER_STORAGE_BLOCKS = 0x90D6; + static constexpr const GLenum MAX_GEOMETRY_SHADER_STORAGE_BLOCKS = 0x90D7; + static constexpr const GLenum MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS = 0x90D8; + static constexpr const GLenum MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS = 0x90D9; + static constexpr const GLenum MAX_FRAGMENT_SHADER_STORAGE_BLOCKS = 0x90DA; + static constexpr const GLenum MAX_COMPUTE_SHADER_STORAGE_BLOCKS = 0x90DB; + static constexpr const GLenum MAX_COMBINED_SHADER_STORAGE_BLOCKS = 0x90DC; + static constexpr const GLenum MAX_SHADER_STORAGE_BUFFER_BINDINGS = 0x90DD; + static constexpr const GLenum MAX_SHADER_STORAGE_BLOCK_SIZE = 0x90DE; + static constexpr const GLenum SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT = 0x90DF; + static constexpr const GLenum SHADER_STORAGE_BARRIER_BIT = 0x00002000; + static constexpr const GLenum MAX_COMBINED_SHADER_OUTPUT_RESOURCES = 0x8F39; + static constexpr const GLenum DEPTH_STENCIL_TEXTURE_MODE = 0x90EA; + static constexpr const GLenum TEXTURE_BUFFER_OFFSET = 0x919D; + static constexpr const GLenum TEXTURE_BUFFER_SIZE = 0x919E; + static constexpr const GLenum TEXTURE_BUFFER_OFFSET_ALIGNMENT = 0x919F; + static constexpr const GLenum TEXTURE_VIEW_MIN_LEVEL = 0x82DB; + static constexpr const GLenum TEXTURE_VIEW_NUM_LEVELS = 0x82DC; + static constexpr const GLenum TEXTURE_VIEW_MIN_LAYER = 0x82DD; + static constexpr const GLenum TEXTURE_VIEW_NUM_LAYERS = 0x82DE; + static constexpr const GLenum TEXTURE_IMMUTABLE_LEVELS = 0x82DF; + static constexpr const GLenum VERTEX_ATTRIB_BINDING = 0x82D4; + static constexpr const GLenum VERTEX_ATTRIB_RELATIVE_OFFSET = 0x82D5; + static constexpr const GLenum VERTEX_BINDING_DIVISOR = 0x82D6; + static constexpr const GLenum VERTEX_BINDING_OFFSET = 0x82D7; + static constexpr const GLenum VERTEX_BINDING_STRIDE = 0x82D8; + static constexpr const GLenum MAX_VERTEX_ATTRIB_RELATIVE_OFFSET = 0x82D9; + static constexpr const GLenum MAX_VERTEX_ATTRIB_BINDINGS = 0x82DA; + static constexpr const GLenum VERTEX_BINDING_BUFFER = 0x8F4F; + static constexpr const GLenum MAX_VERTEX_ATTRIB_STRIDE = 0x82E5; + static constexpr const GLenum PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED = 0x8221; + static constexpr const GLenum TEXTURE_BUFFER_BINDING = 0x8C2A; + static constexpr const GLenum MAP_PERSISTENT_BIT = 0x0040; + static constexpr const GLenum MAP_COHERENT_BIT = 0x0080; + static constexpr const GLenum DYNAMIC_STORAGE_BIT = 0x0100; + static constexpr const GLenum CLIENT_STORAGE_BIT = 0x0200; + static constexpr const GLenum CLIENT_MAPPED_BUFFER_BARRIER_BIT = 0x00004000; + static constexpr const GLenum BUFFER_IMMUTABLE_STORAGE = 0x821F; + static constexpr const GLenum BUFFER_STORAGE_FLAGS = 0x8220; + static constexpr const GLenum CLEAR_TEXTURE = 0x9365; + static constexpr const GLenum LOCATION_COMPONENT = 0x934A; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_INDEX = 0x934B; + static constexpr const GLenum TRANSFORM_FEEDBACK_BUFFER_STRIDE = 0x934C; + static constexpr const GLenum QUERY_BUFFER = 0x9192; + static constexpr const GLenum QUERY_BUFFER_BARRIER_BIT = 0x00008000; + static constexpr const GLenum QUERY_BUFFER_BINDING = 0x9193; + static constexpr const GLenum QUERY_RESULT_NO_WAIT = 0x9194; + static constexpr const GLenum MIRROR_CLAMP_TO_EDGE = 0x8743; + static constexpr const GLenum CONTEXT_LOST = 0x0507; + static constexpr const GLenum NEGATIVE_ONE_TO_ONE = 0x935E; + static constexpr const GLenum ZERO_TO_ONE = 0x935F; + static constexpr const GLenum CLIP_ORIGIN = 0x935C; + static constexpr const GLenum CLIP_DEPTH_MODE = 0x935D; + static constexpr const GLenum QUERY_WAIT_INVERTED = 0x8E17; + static constexpr const GLenum QUERY_NO_WAIT_INVERTED = 0x8E18; + static constexpr const GLenum QUERY_BY_REGION_WAIT_INVERTED = 0x8E19; + static constexpr const GLenum QUERY_BY_REGION_NO_WAIT_INVERTED = 0x8E1A; + static constexpr const GLenum MAX_CULL_DISTANCES = 0x82F9; + static constexpr const GLenum MAX_COMBINED_CLIP_AND_CULL_DISTANCES = 0x82FA; + static constexpr const GLenum TEXTURE_TARGET = 0x1006; + static constexpr const GLenum QUERY_TARGET = 0x82EA; + static constexpr const GLenum GUILTY_CONTEXT_RESET = 0x8253; + static constexpr const GLenum INNOCENT_CONTEXT_RESET = 0x8254; + static constexpr const GLenum UNKNOWN_CONTEXT_RESET = 0x8255; + static constexpr const GLenum RESET_NOTIFICATION_STRATEGY = 0x8256; + static constexpr const GLenum LOSE_CONTEXT_ON_RESET = 0x8252; + static constexpr const GLenum NO_RESET_NOTIFICATION = 0x8261; + static constexpr const GLenum CONTEXT_FLAG_ROBUST_ACCESS_BIT = 0x00000004; + static constexpr const GLenum CONTEXT_RELEASE_BEHAVIOR = 0x82FB; + static constexpr const GLenum CONTEXT_RELEASE_BEHAVIOR_FLUSH = 0x82FC; + static constexpr const GLenum SHADER_BINARY_FORMAT_SPIR_V = 0x9551; + static constexpr const GLenum SPIR_V_BINARY = 0x9552; + static constexpr const GLenum PARAMETER_BUFFER = 0x80EE; + static constexpr const GLenum PARAMETER_BUFFER_BINDING = 0x80EF; + static constexpr const GLenum CONTEXT_FLAG_NO_ERROR_BIT = 0x00000008; + static constexpr const GLenum VERTICES_SUBMITTED = 0x82EE; + static constexpr const GLenum PRIMITIVES_SUBMITTED = 0x82EF; + static constexpr const GLenum VERTEX_SHADER_INVOCATIONS = 0x82F0; + static constexpr const GLenum TESS_CONTROL_SHADER_PATCHES = 0x82F1; + static constexpr const GLenum TESS_EVALUATION_SHADER_INVOCATIONS = 0x82F2; + static constexpr const GLenum GEOMETRY_SHADER_PRIMITIVES_EMITTED = 0x82F3; + static constexpr const GLenum FRAGMENT_SHADER_INVOCATIONS = 0x82F4; + static constexpr const GLenum COMPUTE_SHADER_INVOCATIONS = 0x82F5; + static constexpr const GLenum CLIPPING_INPUT_PRIMITIVES = 0x82F6; + static constexpr const GLenum CLIPPING_OUTPUT_PRIMITIVES = 0x82F7; + static constexpr const GLenum POLYGON_OFFSET_CLAMP = 0x8E1B; + static constexpr const GLenum SPIR_V_EXTENSIONS = 0x9553; + static constexpr const GLenum NUM_SPIR_V_EXTENSIONS = 0x9554; + static constexpr const GLenum TEXTURE_MAX_ANISOTROPY = 0x84FE; + static constexpr const GLenum MAX_TEXTURE_MAX_ANISOTROPY = 0x84FF; + static constexpr const GLenum TRANSFORM_FEEDBACK_OVERFLOW = 0x82EC; + static constexpr const GLenum TRANSFORM_FEEDBACK_STREAM_OVERFLOW = 0x82ED; + static constexpr const GLenum PRIMITIVE_BOUNDING_BOX = 0x92BE; + static constexpr const GLenum MULTISAMPLE_LINE_WIDTH_RANGE = 0x9381; + static constexpr const GLenum MULTISAMPLE_LINE_WIDTH_GRANULARITY = 0x9382; + static constexpr const GLenum UNSIGNED_INT64 = 0x140F; + static constexpr const GLenum SYNC_CL_EVENT = 0x8240; + static constexpr const GLenum SYNC_CL_EVENT_COMPLETE = 0x8241; + static constexpr const GLenum MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS = 0x9344; + static constexpr const GLenum MAX_COMPUTE_FIXED_GROUP_INVOCATIONS = 0x90EB; + static constexpr const GLenum MAX_COMPUTE_VARIABLE_GROUP_SIZE = 0x9345; + static constexpr const GLenum MAX_COMPUTE_FIXED_GROUP_SIZE = 0x91BF; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_LAYER_COUNT = 0x8DA9; + static constexpr const GLenum MAX_GEOMETRY_VARYING_COMPONENTS = 0x8DDD; + static constexpr const GLenum MAX_VERTEX_VARYING_COMPONENTS = 0x8DDE; + static constexpr const GLenum INT64 = 0x140E; + static constexpr const GLenum INT64_VEC2 = 0x8FE9; + static constexpr const GLenum INT64_VEC3 = 0x8FEA; + static constexpr const GLenum INT64_VEC4 = 0x8FEB; + static constexpr const GLenum UNSIGNED_INT64_VEC2 = 0x8FF5; + static constexpr const GLenum UNSIGNED_INT64_VEC3 = 0x8FF6; + static constexpr const GLenum UNSIGNED_INT64_VEC4 = 0x8FF7; + static constexpr const GLenum SRGB_DECODE = 0x8299; + static constexpr const GLenum VIEW_CLASS_EAC_R11 = 0x9383; + static constexpr const GLenum VIEW_CLASS_EAC_RG11 = 0x9384; + static constexpr const GLenum VIEW_CLASS_ETC2_RGB = 0x9385; + static constexpr const GLenum VIEW_CLASS_ETC2_RGBA = 0x9386; + static constexpr const GLenum VIEW_CLASS_ETC2_EAC_RGBA = 0x9387; + static constexpr const GLenum VIEW_CLASS_ASTC_4x4_RGBA = 0x9388; + static constexpr const GLenum VIEW_CLASS_ASTC_5x4_RGBA = 0x9389; + static constexpr const GLenum VIEW_CLASS_ASTC_5x5_RGBA = 0x938A; + static constexpr const GLenum VIEW_CLASS_ASTC_6x5_RGBA = 0x938B; + static constexpr const GLenum VIEW_CLASS_ASTC_6x6_RGBA = 0x938C; + static constexpr const GLenum VIEW_CLASS_ASTC_8x5_RGBA = 0x938D; + static constexpr const GLenum VIEW_CLASS_ASTC_8x6_RGBA = 0x938E; + static constexpr const GLenum VIEW_CLASS_ASTC_8x8_RGBA = 0x938F; + static constexpr const GLenum VIEW_CLASS_ASTC_10x5_RGBA = 0x9390; + static constexpr const GLenum VIEW_CLASS_ASTC_10x6_RGBA = 0x9391; + static constexpr const GLenum VIEW_CLASS_ASTC_10x8_RGBA = 0x9392; + static constexpr const GLenum VIEW_CLASS_ASTC_10x10_RGBA = 0x9393; + static constexpr const GLenum VIEW_CLASS_ASTC_12x10_RGBA = 0x9394; + static constexpr const GLenum VIEW_CLASS_ASTC_12x12_RGBA = 0x9395; + static constexpr const GLenum MAX_SHADER_COMPILER_THREADS = 0x91B0; + static constexpr const GLenum COMPLETION_STATUS = 0x91B1; + static constexpr const GLenum SAMPLE_LOCATION_SUBPIXEL_BITS = 0x933D; + static constexpr const GLenum SAMPLE_LOCATION_PIXEL_GRID_WIDTH = 0x933E; + static constexpr const GLenum SAMPLE_LOCATION_PIXEL_GRID_HEIGHT = 0x933F; + static constexpr const GLenum PROGRAMMABLE_SAMPLE_LOCATION_TABLE_SIZE = 0x9340; + static constexpr const GLenum SAMPLE_LOCATION = 0x8E50; + static constexpr const GLenum PROGRAMMABLE_SAMPLE_LOCATION = 0x9341; + static constexpr const GLenum FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS = 0x9342; + static constexpr const GLenum FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID = 0x9343; + static constexpr const GLenum SHADER_INCLUDE = 0x8DAE; + static constexpr const GLenum NAMED_STRING_LENGTH = 0x8DE9; + static constexpr const GLenum NAMED_STRING_TYPE = 0x8DEA; + static constexpr const GLenum SPARSE_STORAGE_BIT = 0x0400; + static constexpr const GLenum SPARSE_BUFFER_PAGE_SIZE = 0x82F8; + static constexpr const GLenum TEXTURE_SPARSE = 0x91A6; + static constexpr const GLenum VIRTUAL_PAGE_SIZE_INDEX = 0x91A7; + static constexpr const GLenum NUM_SPARSE_LEVELS = 0x91AA; + static constexpr const GLenum NUM_VIRTUAL_PAGE_SIZES = 0x91A8; + static constexpr const GLenum VIRTUAL_PAGE_SIZE_X = 0x9195; + static constexpr const GLenum VIRTUAL_PAGE_SIZE_Y = 0x9196; + static constexpr const GLenum VIRTUAL_PAGE_SIZE_Z = 0x9197; + static constexpr const GLenum MAX_SPARSE_TEXTURE_SIZE = 0x9198; + static constexpr const GLenum MAX_SPARSE_3D_TEXTURE_SIZE = 0x9199; + static constexpr const GLenum MAX_SPARSE_ARRAY_TEXTURE_LAYERS = 0x919A; + static constexpr const GLenum SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS = 0x91A9; + static constexpr const GLenum TEXTURE_BUFFER_FORMAT = 0x8C2E; + static constexpr const GLenum TEXTURE_REDUCTION_MODE = 0x9366; + static constexpr const GLenum WEIGHTED_AVERAGE = 0x9367; + static constexpr const GLenum MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS = 0x8F9F; + static constexpr const GLenum MULTIPLY = 0x9294; + static constexpr const GLenum SCREEN = 0x9295; + static constexpr const GLenum OVERLAY = 0x9296; + static constexpr const GLenum DARKEN = 0x9297; + static constexpr const GLenum LIGHTEN = 0x9298; + static constexpr const GLenum COLORDODGE = 0x9299; + static constexpr const GLenum COLORBURN = 0x929A; + static constexpr const GLenum HARDLIGHT = 0x929B; + static constexpr const GLenum SOFTLIGHT = 0x929C; + static constexpr const GLenum _DIFFERENCE = 0x929E; + static constexpr const GLenum EXCLUSION = 0x92A0; + static constexpr const GLenum HSL_HUE = 0x92AD; + static constexpr const GLenum HSL_SATURATION = 0x92AE; + static constexpr const GLenum HSL_COLOR = 0x92AF; + static constexpr const GLenum HSL_LUMINOSITY = 0x92B0; + static constexpr const GLenum BLEND_ADVANCED_COHERENT = 0x9285; + static constexpr const GLenum CONTEXT_ROBUST_ACCESS = 0x90F3; + static constexpr const GLenum SUBGROUP_SIZE = 0x9532; + static constexpr const GLenum SUBGROUP_SUPPORTED_STAGES = 0x9533; + static constexpr const GLenum SUBGROUP_SUPPORTED_FEATURES = 0x9534; + static constexpr const GLenum SUBGROUP_QUAD_ALL_STAGES = 0x9535; + static constexpr const GLenum SUBGROUP_FEATURE_BASIC_BIT = 0x00000001; + static constexpr const GLenum SUBGROUP_FEATURE_VOTE_BIT = 0x00000002; + static constexpr const GLenum SUBGROUP_FEATURE_ARITHMETIC_BIT = 0x00000004; + static constexpr const GLenum SUBGROUP_FEATURE_BALLOT_BIT = 0x00000008; + static constexpr const GLenum SUBGROUP_FEATURE_SHUFFLE_BIT = 0x00000010; + static constexpr const GLenum SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT = 0x00000020; + static constexpr const GLenum SUBGROUP_FEATURE_CLUSTERED_BIT = 0x00000040; + static constexpr const GLenum SUBGROUP_FEATURE_QUAD_BIT = 0x00000080; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_4x4 = 0x93B0; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_5x4 = 0x93B1; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_5x5 = 0x93B2; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_6x5 = 0x93B3; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_6x6 = 0x93B4; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_8x5 = 0x93B5; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_8x6 = 0x93B6; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_8x8 = 0x93B7; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_10x5 = 0x93B8; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_10x6 = 0x93B9; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_10x8 = 0x93BA; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_10x10 = 0x93BB; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_12x10 = 0x93BC; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_12x12 = 0x93BD; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_4x4 = 0x93D0; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_5x4 = 0x93D1; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_5x5 = 0x93D2; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_6x5 = 0x93D3; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_6x6 = 0x93D4; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_8x5 = 0x93D5; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_8x6 = 0x93D6; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_8x8 = 0x93D7; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_10x5 = 0x93D8; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_10x6 = 0x93D9; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_10x8 = 0x93DA; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_10x10 = 0x93DB; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_12x10 = 0x93DC; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_12x12 = 0x93DD; + static constexpr const GLenum PROGRAM_PIPELINE_OBJECT = 0x8A4F; + static constexpr const GLenum PROGRAM_OBJECT = 0x8B40; + static constexpr const GLenum SHADER_OBJECT = 0x8B48; + static constexpr const GLenum BUFFER_OBJECT = 0x9151; + static constexpr const GLenum QUERY_OBJECT = 0x9153; + static constexpr const GLenum VERTEX_ARRAY_OBJECT = 0x9154; + static constexpr const GLenum PROGRAM_MATRIX = 0x8E2D; + static constexpr const GLenum TRANSPOSE_PROGRAM_MATRIX = 0x8E2E; + static constexpr const GLenum PROGRAM_MATRIX_STACK_DEPTH = 0x8E2F; + static constexpr const GLenum RASTER_MULTISAMPLE = 0x9327; + static constexpr const GLenum RASTER_SAMPLES = 0x9328; + static constexpr const GLenum MAX_RASTER_SAMPLES = 0x9329; + static constexpr const GLenum RASTER_FIXED_SAMPLE_LOCATIONS = 0x932A; + static constexpr const GLenum MULTISAMPLE_RASTERIZATION_ALLOWED = 0x932B; + static constexpr const GLenum EFFECTIVE_RASTER_SAMPLES = 0x932C; + static constexpr const GLenum FRAGMENT_SHADER_DISCARDS_SAMPLES = 0x8A52; + static constexpr const GLenum COMPRESSED_RGB_S3TC_DXT1 = 0x83F0; + static constexpr const GLenum COMPRESSED_RGBA_S3TC_DXT1 = 0x83F1; + static constexpr const GLenum COMPRESSED_RGBA_S3TC_DXT3 = 0x83F2; + static constexpr const GLenum COMPRESSED_RGBA_S3TC_DXT5 = 0x83F3; + static constexpr const GLenum SR8 = 0x8FBD; + static constexpr const GLenum SRG8 = 0x8FBE; + static constexpr const GLenum TEXTURE_SRGB_DECODE = 0x8A48; + static constexpr const GLenum DECODE = 0x8A49; + static constexpr const GLenum SKIP_DECODE = 0x8A4A; + static constexpr const GLenum ALPHA8 = 0x803C; + static constexpr const GLenum LUMINANCE8 = 0x8040; + static constexpr const GLenum LUMINANCE8_ALPHA8 = 0x8045; + static constexpr const GLenum ALPHA32F = 0x8816; + static constexpr const GLenum LUMINANCE32F = 0x8818; + static constexpr const GLenum LUMINANCE_ALPHA32F = 0x8819; + static constexpr const GLenum ALPHA16F = 0x881C; + static constexpr const GLenum LUMINANCE16F = 0x881E; + static constexpr const GLenum LUMINANCE_ALPHA16F = 0x881F; + static constexpr const GLenum BGRA8 = 0x93A1; + static constexpr const GLenum INCLUSIVE = 0x8F10; + static constexpr const GLenum EXCLUSIVE = 0x8F11; + static constexpr const GLenum WINDOW_RECTANGLE = 0x8F12; + static constexpr const GLenum WINDOW_RECTANGLE_MODE = 0x8F13; + static constexpr const GLenum MAX_WINDOW_RECTANGLES = 0x8F14; + static constexpr const GLenum NUM_WINDOW_RECTANGLES = 0x8F15; + static constexpr const GLenum TEXTURE_EXTERNAL = 0x8D65; + static constexpr const GLenum TEXTURE_BINDING_EXTERNAL = 0x8D67; + static constexpr const GLenum REQUIRED_TEXTURE_IMAGE_UNITS = 0x8D68; + static constexpr const GLenum SAMPLER_EXTERNAL = 0x8D66; + static constexpr const GLenum ETC1_RGB8 = 0x8D64; + static constexpr const GLenum PALETTE4_RGB8 = 0x8B90; + static constexpr const GLenum PALETTE4_RGBA8 = 0x8B91; + static constexpr const GLenum PALETTE4_R5_G6_B5 = 0x8B92; + static constexpr const GLenum PALETTE4_RGBA4 = 0x8B93; + static constexpr const GLenum PALETTE4_RGB5_A1 = 0x8B94; + static constexpr const GLenum PALETTE8_RGB8 = 0x8B95; + static constexpr const GLenum PALETTE8_RGBA8 = 0x8B96; + static constexpr const GLenum PALETTE8_R5_G6_B5 = 0x8B97; + static constexpr const GLenum PALETTE8_RGBA4 = 0x8B98; + static constexpr const GLenum PALETTE8_RGB5_A1 = 0x8B99; + static constexpr const GLenum GEOMETRY_LINKED_VERTICES_OUT = 0x8916; + static constexpr const GLenum GEOMETRY_LINKED_INPUT_TYPE = 0x8917; + static constexpr const GLenum GEOMETRY_LINKED_OUTPUT_TYPE = 0x8918; + static constexpr const GLenum LUMINANCE4_ALPHA4 = 0x8043; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET = 0x8CD4; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_3x3x3 = 0x93C0; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_4x3x3 = 0x93C1; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_4x4x3 = 0x93C2; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_4x4x4 = 0x93C3; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_5x4x4 = 0x93C4; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_5x5x4 = 0x93C5; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_5x5x5 = 0x93C6; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_6x5x5 = 0x93C7; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_6x6x5 = 0x93C8; + static constexpr const GLenum COMPRESSED_RGBA_ASTC_6x6x6 = 0x93C9; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3 = 0x93E0; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3 = 0x93E1; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3 = 0x93E2; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4 = 0x93E3; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4 = 0x93E4; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4 = 0x93E5; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5 = 0x93E6; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5 = 0x93E7; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5 = 0x93E8; + static constexpr const GLenum COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6 = 0x93E9; + static constexpr const GLenum INT_10_10_10_2 = 0x8DF7; + static constexpr const GLenum MALI_PROGRAM_BINARY_ARM = 0x8F61; + static constexpr const GLenum MALI_SHADER_BINARY_ARM = 0x8F60; + static constexpr const GLenum FETCH_PER_SAMPLE_ARM = 0x8F65; + static constexpr const GLenum FRAGMENT_SHADER_FRAMEBUFFER_FETCH_MRT_ARM = 0x8F66; + static constexpr const GLenum TEXTURE_UNNORMALIZED_COORDINATES_ARM = 0x8F6A; + static constexpr const GLenum SMAPHS30_PROGRAM_BINARY_DMP = 0x9251; + static constexpr const GLenum SMAPHS_PROGRAM_BINARY_DMP = 0x9252; + static constexpr const GLenum DMP_PROGRAM_BINARY_DMP = 0x9253; + static constexpr const GLenum SHADER_BINARY_DMP = 0x9250; + static constexpr const GLenum SURFACE_COMPRESSION = 0x96C0; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_NONE = 0x96C1; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_DEFAULT = 0x96C2; + static constexpr const GLenum SAMPLER_EXTERNAL_2D_Y2Y = 0x8BE7; + static constexpr const GLenum GPU_DISJOINT = 0x8FBB; + static constexpr const GLenum SHADING_RATE_1X1_PIXELS = 0x96A6; + static constexpr const GLenum SHADING_RATE_1X2_PIXELS = 0x96A7; + static constexpr const GLenum SHADING_RATE_2X1_PIXELS = 0x96A8; + static constexpr const GLenum SHADING_RATE_2X2_PIXELS = 0x96A9; + static constexpr const GLenum SHADING_RATE_1X4_PIXELS = 0x96AA; + static constexpr const GLenum SHADING_RATE_4X1_PIXELS = 0x96AB; + static constexpr const GLenum SHADING_RATE_4X2_PIXELS = 0x96AC; + static constexpr const GLenum SHADING_RATE_2X4_PIXELS = 0x96AD; + static constexpr const GLenum SHADING_RATE_4X4_PIXELS = 0x96AE; + static constexpr const GLenum SHADING_RATE = 0x96D0; + static constexpr const GLenum SHADING_RATE_ATTACHMENT = 0x96D1; + static constexpr const GLenum FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP = 0x96D2; + static constexpr const GLenum FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE = 0x96D3; + static constexpr const GLenum FRAGMENT_SHADING_RATE_COMBINER_OP_MIN = 0x96D4; + static constexpr const GLenum FRAGMENT_SHADING_RATE_COMBINER_OP_MAX = 0x96D5; + static constexpr const GLenum FRAGMENT_SHADING_RATE_COMBINER_OP_MUL = 0x96D6; + static constexpr const GLenum MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH = 0x96D7; + static constexpr const GLenum MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH = 0x96D8; + static constexpr const GLenum MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT = 0x96D9; + static constexpr const GLenum MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT = 0x96DA; + static constexpr const GLenum MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_ASPECT_RATIO = 0x96DB; + static constexpr const GLenum MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_LAYERS = 0x96DC; + static constexpr const GLenum FRAGMENT_SHADING_RATE_WITH_SHADER_DEPTH_STENCIL_WRITES_SUPPORTED = 0x96DD; + static constexpr const GLenum FRAGMENT_SHADING_RATE_WITH_SAMPLE_MASK_SUPPORTED = 0x96DE; + static constexpr const GLenum FRAGMENT_SHADING_RATE_ATTACHMENT_WITH_DEFAULT_FRAMEBUFFER_SUPPORTED = 0x96DF; + static constexpr const GLenum FRAGMENT_SHADING_RATE_NON_TRIVIAL_COMBINERS_SUPPORTED = 0x8F6F; + static constexpr const GLenum TEXTURE_TILING = 0x9580; + static constexpr const GLenum DEDICATED_MEMORY_OBJECT = 0x9581; + static constexpr const GLenum PROTECTED_MEMORY_OBJECT = 0x959B; + static constexpr const GLenum NUM_TILING_TYPES = 0x9582; + static constexpr const GLenum TILING_TYPES = 0x9583; + static constexpr const GLenum OPTIMAL_TILING = 0x9584; + static constexpr const GLenum LINEAR_TILING = 0x9585; + static constexpr const GLenum NUM_DEVICE_UUIDS = 0x9596; + static constexpr const GLenum DEVICE_UUID = 0x9597; + static constexpr const GLenum DRIVER_UUID = 0x9598; + static constexpr const GLenum HANDLE_TYPE_OPAQUE_FD = 0x9586; + static constexpr const GLenum HANDLE_TYPE_OPAQUE_WIN32 = 0x9587; + static constexpr const GLenum HANDLE_TYPE_OPAQUE_WIN32_KMT = 0x9588; + static constexpr const GLenum DEVICE_LUID = 0x9599; + static constexpr const GLenum DEVICE_NODE_MASK = 0x959A; + static constexpr const GLenum HANDLE_TYPE_D3D12_TILEPOOL = 0x9589; + static constexpr const GLenum HANDLE_TYPE_D3D12_RESOURCE = 0x958A; + static constexpr const GLenum HANDLE_TYPE_D3D11_IMAGE = 0x958B; + static constexpr const GLenum HANDLE_TYPE_D3D11_IMAGE_KMT = 0x958C; + static constexpr const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES = 0x8D6C; + static constexpr const GLenum COLOR_ATTACHMENT = 0x90F0; + static constexpr const GLenum MULTIVIEW = 0x90F1; + static constexpr const GLenum MAX_MULTIVIEW_BUFFERS = 0x90F2; + static constexpr const GLenum CONTEXT_FLAG_PROTECTED_CONTENT_BIT = 0x00000010; + static constexpr const GLenum TEXTURE_PROTECTED = 0x8BFA; + static constexpr const GLenum COMPRESSED_SRGB_PVRTC_2BPPV1 = 0x8A54; + static constexpr const GLenum COMPRESSED_SRGB_PVRTC_4BPPV1 = 0x8A55; + static constexpr const GLenum COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1 = 0x8A56; + static constexpr const GLenum COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1 = 0x8A57; + static constexpr const GLenum LAYOUT_GENERAL = 0x958D; + static constexpr const GLenum LAYOUT_COLOR_ATTACHMENT = 0x958E; + static constexpr const GLenum LAYOUT_DEPTH_STENCIL_ATTACHMENT = 0x958F; + static constexpr const GLenum LAYOUT_DEPTH_STENCIL_READ_ONLY = 0x9590; + static constexpr const GLenum LAYOUT_SHADER_READ_ONLY = 0x9591; + static constexpr const GLenum LAYOUT_TRANSFER_SRC = 0x9592; + static constexpr const GLenum LAYOUT_TRANSFER_DST = 0x9593; + static constexpr const GLenum LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT = 0x9530; + static constexpr const GLenum LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY = 0x9531; + static constexpr const GLenum HANDLE_TYPE_D3D12_FENCE = 0x9594; + static constexpr const GLenum D3D12_FENCE_VALUE = 0x9595; + static constexpr const GLenum MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE = 0x8F63; + static constexpr const GLenum MAX_SHADER_PIXEL_LOCAL_STORAGE_SIZE = 0x8F67; + static constexpr const GLenum SHADER_PIXEL_LOCAL_STORAGE = 0x8F64; + static constexpr const GLenum MAX_SHADER_COMBINED_LOCAL_STORAGE_FAST_SIZE = 0x9650; + static constexpr const GLenum MAX_SHADER_COMBINED_LOCAL_STORAGE_SIZE = 0x9651; + static constexpr const GLenum FRAMEBUFFER_INCOMPLETE_INSUFFICIENT_SHADER_COMBINED_LOCAL_STORAGE = 0x9652; + static constexpr const GLenum TEXTURE_ASTC_DECODE_PRECISION = 0x8F69; + static constexpr const GLenum COMPRESSED_RED_GREEN_RGTC2 = 0x8DBD; + static constexpr const GLenum COMPRESSED_SIGNED_RED_GREEN_RGTC2 = 0x8DBE; + static constexpr const GLenum COMPRESSED_SRGB_S3TC_DXT1 = 0x8C4C; + static constexpr const GLenum COMPRESSED_SRGB_ALPHA_S3TC_DXT1 = 0x8C4D; + static constexpr const GLenum COMPRESSED_SRGB_ALPHA_S3TC_DXT3 = 0x8C4E; + static constexpr const GLenum COMPRESSED_SRGB_ALPHA_S3TC_DXT5 = 0x8C4F; + static constexpr const GLenum TEXTURE_FORMAT_SRGB_OVERRIDE = 0x8FBF; + static constexpr const GLenum NUM_SURFACE_COMPRESSION_FIXED_RATES = 0x8F6E; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_1BPC = 0x96C4; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_2BPC = 0x96C5; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_3BPC = 0x96C6; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_4BPC = 0x96C7; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_5BPC = 0x96C8; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_6BPC = 0x96C9; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_7BPC = 0x96CA; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_8BPC = 0x96CB; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_9BPC = 0x96CC; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_10BPC = 0x96CD; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_11BPC = 0x96CE; + static constexpr const GLenum SURFACE_COMPRESSION_FIXED_RATE_12BPC = 0x96CF; + static constexpr const GLenum GCCSO_SHADER_BINARY_FJ = 0x9260; + static constexpr const GLenum STATE_RESTORE = 0x8BDC; + static constexpr const GLenum SHADER_BINARY_VIV = 0x8FC4; + + static constexpr const GLenum ZERO = 0; + static constexpr const GLenum ONE = 1; + static constexpr const GLenum NONE = 0; +}; + +// Global GL procedures object. +IRRLICHT_API extern OpenGLProcedures GL; diff --git a/irr/include/path.h b/irr/include/path.h new file mode 100644 index 000000000..06476ef7b --- /dev/null +++ b/irr/include/path.h @@ -0,0 +1,86 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine" and the "irrXML" project. +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrString.h" + +namespace irr +{ +namespace io +{ + +//! Type used for all file system related strings. +/** This type will transparently handle different file system encodings. + NOTE: For historical reasons the tool-functions using io::path are all in coreutil.h +*/ +typedef core::string path; + +// Type only exists for historcal reasons, paths are always char now. +static_assert(sizeof(fschar_t) == sizeof(char)); + +//! Used in places where we identify objects by a filename, but don't actually work with the real filename +/** Irrlicht is internally not case-sensitive when it comes to names. + Also this class is a first step towards support for correctly serializing renamed objects. +*/ +struct SNamedPath +{ + //! Constructor + SNamedPath() {} + + //! Constructor + SNamedPath(const path &p) : + Path(p), InternalName(PathToName(p)) + { + } + + //! Is smaller comparator + bool operator<(const SNamedPath &other) const + { + return InternalName < other.InternalName; + } + + //! Set the path. + void setPath(const path &p) + { + Path = p; + InternalName = PathToName(p); + } + + //! Get the path. + const path &getPath() const + { + return Path; + }; + + //! Get the name which is used to identify the file. + //! This string is similar to the names and filenames used before Irrlicht 1.7 + const path &getInternalName() const + { + return InternalName; + } + + //! Implicit cast to io::path + operator core::stringc() const + { + return core::stringc(getPath()); + } + +protected: + // convert the given path string to a name string. + path PathToName(const path &p) const + { + path name(p); + name.replace('\\', '/'); + name.make_lower(); + return name; + } + +private: + path Path; + path InternalName; +}; + +} // io +} // irr diff --git a/irr/include/plane3d.h b/irr/include/plane3d.h new file mode 100644 index 000000000..4003325b5 --- /dev/null +++ b/irr/include/plane3d.h @@ -0,0 +1,244 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrMath.h" +#include "vector3d.h" + +namespace irr +{ +namespace core +{ + +//! Enumeration for intersection relations of 3d objects +enum EIntersectionRelation3D +{ + ISREL3D_FRONT = 0, + ISREL3D_BACK, + ISREL3D_PLANAR, + ISREL3D_SPANNING, + ISREL3D_CLIPPED +}; + +//! Template plane class with some intersection testing methods. +/** It has to be ensured, that the normal is always normalized. The constructors + and setters of this class will not ensure this automatically. So any normal + passed in has to be normalized in advance. No change to the normal will be + made by any of the class methods. +*/ +template +class plane3d +{ +public: + // Constructors + + plane3d() : + Normal(0, 1, 0) { recalculateD(vector3d(0, 0, 0)); } + + plane3d(const vector3d &MPoint, const vector3d &Normal) : + Normal(Normal) { recalculateD(MPoint); } + + plane3d(T px, T py, T pz, T nx, T ny, T nz) : + Normal(nx, ny, nz) { recalculateD(vector3d(px, py, pz)); } + + plane3d(const vector3d &point1, const vector3d &point2, const vector3d &point3) + { + setPlane(point1, point2, point3); + } + + plane3d(const vector3d &normal, const T d) : + Normal(normal), D(d) {} + + // operators + + inline bool operator==(const plane3d &other) const { return (equals(D, other.D) && Normal == other.Normal); } + + inline bool operator!=(const plane3d &other) const { return !(*this == other); } + + // functions + + void setPlane(const vector3d &point, const vector3d &nvector) + { + Normal = nvector; + recalculateD(point); + } + + void setPlane(const vector3d &nvect, T d) + { + Normal = nvect; + D = d; + } + + void setPlane(const vector3d &point1, const vector3d &point2, const vector3d &point3) + { + // creates the plane from 3 memberpoints + Normal = (point2 - point1).crossProduct(point3 - point1); + Normal.normalize(); + + recalculateD(point1); + } + + //! Get an intersection with a 3d line. + /** \param lineVect Vector of the line to intersect with. + \param linePoint Point of the line to intersect with. + \param outIntersection Place to store the intersection point, if there is one. + \return True if there was an intersection, false if there was not. + */ + bool getIntersectionWithLine(const vector3d &linePoint, + const vector3d &lineVect, + vector3d &outIntersection) const + { + T t2 = Normal.dotProduct(lineVect); + + if (t2 == 0) + return false; + + T t = -(Normal.dotProduct(linePoint) + D) / t2; + outIntersection = linePoint + (lineVect * t); + return true; + } + + //! Get percentage of line between two points where an intersection with this plane happens. + /** Only useful if known that there is an intersection. + \param linePoint1 Point1 of the line to intersect with. + \param linePoint2 Point2 of the line to intersect with. + \return Where on a line between two points an intersection with this plane happened. + For example, 0.5 is returned if the intersection happened exactly in the middle of the two points. + */ + f32 getKnownIntersectionWithLine(const vector3d &linePoint1, + const vector3d &linePoint2) const + { + vector3d vect = linePoint2 - linePoint1; + T t2 = (f32)Normal.dotProduct(vect); + return (f32) - ((Normal.dotProduct(linePoint1) + D) / t2); + } + + //! Get an intersection with a 3d line, limited between two 3d points. + /** \param linePoint1 Point 1 of the line. + \param linePoint2 Point 2 of the line. + \param outIntersection Place to store the intersection point, if there is one. + \return True if there was an intersection, false if there was not. + */ + bool getIntersectionWithLimitedLine( + const vector3d &linePoint1, + const vector3d &linePoint2, + vector3d &outIntersection) const + { + return (getIntersectionWithLine(linePoint1, linePoint2 - linePoint1, outIntersection) && + outIntersection.isBetweenPoints(linePoint1, linePoint2)); + } + + //! Classifies the relation of a point to this plane. + /** \param point Point to classify its relation. + \return ISREL3D_FRONT if the point is in front of the plane, + ISREL3D_BACK if the point is behind of the plane, and + ISREL3D_PLANAR if the point is within the plane. */ + EIntersectionRelation3D classifyPointRelation(const vector3d &point) const + { + const T d = Normal.dotProduct(point) + D; + + if (d < -ROUNDING_ERROR_f32) + return ISREL3D_BACK; + + if (d > ROUNDING_ERROR_f32) + return ISREL3D_FRONT; + + return ISREL3D_PLANAR; + } + + //! Recalculates the distance from origin by applying a new member point to the plane. + void recalculateD(const vector3d &MPoint) + { + D = -MPoint.dotProduct(Normal); + } + + //! Gets a member point of the plane. + vector3d getMemberPoint() const + { + return Normal * -D; + } + + //! Tests if there is an intersection with the other plane + /** \return True if there is a intersection. */ + bool existsIntersection(const plane3d &other) const + { + vector3d cross = other.Normal.crossProduct(Normal); + return cross.getLength() > core::ROUNDING_ERROR_f32; + } + + //! Intersects this plane with another. + /** \param other Other plane to intersect with. + \param outLinePoint Base point of intersection line. + \param outLineVect Vector of intersection. + \return True if there is a intersection, false if not. */ + bool getIntersectionWithPlane(const plane3d &other, + vector3d &outLinePoint, + vector3d &outLineVect) const + { + const T fn00 = Normal.getLength(); + const T fn01 = Normal.dotProduct(other.Normal); + const T fn11 = other.Normal.getLength(); + const f64 det = fn00 * fn11 - fn01 * fn01; + + if (fabs(det) < ROUNDING_ERROR_f64) + return false; + + const f64 invdet = 1.0 / det; + const f64 fc0 = (fn11 * -D + fn01 * other.D) * invdet; + const f64 fc1 = (fn00 * -other.D + fn01 * D) * invdet; + + outLineVect = Normal.crossProduct(other.Normal); + outLinePoint = Normal * (T)fc0 + other.Normal * (T)fc1; + return true; + } + + //! Get the intersection point with two other planes if there is one. + bool getIntersectionWithPlanes(const plane3d &o1, + const plane3d &o2, vector3d &outPoint) const + { + vector3d linePoint, lineVect; + if (getIntersectionWithPlane(o1, linePoint, lineVect)) + return o2.getIntersectionWithLine(linePoint, lineVect, outPoint); + + return false; + } + + //! Test if the triangle would be front or backfacing from any point. + /** Thus, this method assumes a camera position from + which the triangle is definitely visible when looking into + the given direction. + Note that this only works if the normal is Normalized. + Do not use this method with points as it will give wrong results! + \param lookDirection: Look direction. + \return True if the plane is front facing and + false if it is backfacing. */ + bool isFrontFacing(const vector3d &lookDirection) const + { + const f32 d = Normal.dotProduct(lookDirection); + return F32_LOWER_EQUAL_0(d); + } + + //! Get the distance to a point. + /** Note that this only works if the normal is normalized. */ + T getDistanceTo(const vector3d &point) const + { + return point.dotProduct(Normal) + D; + } + + //! Normal vector of the plane. + vector3d Normal; + + //! Distance from origin. + T D; +}; + +//! Typedef for a f32 3d plane. +typedef plane3d plane3df; + +//! Typedef for an integer 3d plane. +typedef plane3d plane3di; + +} // end namespace core +} // end namespace irr diff --git a/irr/include/position2d.h b/irr/include/position2d.h new file mode 100644 index 000000000..ff0d30f4f --- /dev/null +++ b/irr/include/position2d.h @@ -0,0 +1,28 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +//! As of Irrlicht 1.6, position2d is a synonym for vector2d. +/** You should consider position2d to be deprecated, and use vector2d by preference. */ + +#pragma once + +#include "vector2d.h" + +namespace irr +{ +namespace core +{ + +// Use typedefs where possible as they are more explicit... + +//! \deprecated position2d is now a synonym for vector2d, but vector2d should be used directly. +typedef vector2d position2df; + +//! \deprecated position2d is now a synonym for vector2d, but vector2d should be used directly. +typedef vector2d position2di; +} // namespace core +} // namespace irr + +// ...and use a #define to catch the rest, for (e.g.) position2d +#define position2d vector2d diff --git a/irr/include/quaternion.h b/irr/include/quaternion.h new file mode 100644 index 000000000..5a2e16367 --- /dev/null +++ b/irr/include/quaternion.h @@ -0,0 +1,712 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" +#include "irrMath.h" +#include "matrix4.h" +#include "vector3d.h" + +// NOTE: You *only* need this when updating an application from Irrlicht before 1.8 to Irrlicht 1.8 or later. +// Between Irrlicht 1.7 and Irrlicht 1.8 the quaternion-matrix conversions changed. +// Before the fix they had mixed left- and right-handed rotations. +// To test if your code was affected by the change enable IRR_TEST_BROKEN_QUATERNION_USE and try to compile your application. +// This defines removes those functions so you get compile errors anywhere you use them in your code. +// For every line with a compile-errors you have to change the corresponding lines like that: +// - When you pass the matrix to the quaternion constructor then replace the matrix by the transposed matrix. +// - For uses of getMatrix() you have to use quaternion::getMatrix_transposed instead. +// #define IRR_TEST_BROKEN_QUATERNION_USE + +namespace irr +{ +namespace core +{ + +//! Quaternion class for representing rotations. +/** It provides cheap combinations and avoids gimbal locks. +Also useful for interpolations. */ +class quaternion +{ +public: + //! Default Constructor + constexpr quaternion() : + X(0.0f), Y(0.0f), Z(0.0f), W(1.0f) {} + + //! Constructor + constexpr quaternion(f32 x, f32 y, f32 z, f32 w) : + X(x), Y(y), Z(z), W(w) {} + + //! Constructor which converts Euler angles (radians) to a quaternion + quaternion(f32 x, f32 y, f32 z); + + //! Constructor which converts Euler angles (radians) to a quaternion + quaternion(const vector3df &vec); + +#ifndef IRR_TEST_BROKEN_QUATERNION_USE + //! Constructor which converts a matrix to a quaternion + quaternion(const matrix4 &mat); +#endif + + //! Equality operator + constexpr bool operator==(const quaternion &other) const + { + return ((X == other.X) && + (Y == other.Y) && + (Z == other.Z) && + (W == other.W)); + } + + //! inequality operator + constexpr bool operator!=(const quaternion &other) const + { + return !(*this == other); + } + +#ifndef IRR_TEST_BROKEN_QUATERNION_USE + //! Matrix assignment operator + inline quaternion &operator=(const matrix4 &other); +#endif + + //! Add operator + quaternion operator+(const quaternion &other) const; + + //! Multiplication operator + //! Be careful, unfortunately the operator order here is opposite of that in CMatrix4::operator* + quaternion operator*(const quaternion &other) const; + + //! Multiplication operator with scalar + quaternion operator*(f32 s) const; + + //! Multiplication operator with scalar + quaternion &operator*=(f32 s); + + //! Multiplication operator + vector3df operator*(const vector3df &v) const; + + //! Multiplication operator + quaternion &operator*=(const quaternion &other); + + //! Calculates the dot product + inline f32 dotProduct(const quaternion &other) const; + + //! Sets new quaternion + inline quaternion &set(f32 x, f32 y, f32 z, f32 w); + + //! Sets new quaternion based on Euler angles (radians) + inline quaternion &set(f32 x, f32 y, f32 z); + + //! Sets new quaternion based on Euler angles (radians) + inline quaternion &set(const core::vector3df &vec); + + //! Sets new quaternion from other quaternion + inline quaternion &set(const core::quaternion &quat); + + //! returns if this quaternion equals the other one, taking floating point rounding errors into account + inline bool equals(const quaternion &other, + const f32 tolerance = ROUNDING_ERROR_f32) const; + + //! Normalizes the quaternion + inline quaternion &normalize(); + +#ifndef IRR_TEST_BROKEN_QUATERNION_USE + //! Creates a matrix from this quaternion + matrix4 getMatrix() const; +#endif + //! Faster method to create a rotation matrix, you should normalize the quaternion before! + void getMatrixFast(matrix4 &dest) const; + + //! Creates a matrix from this quaternion + void getMatrix(matrix4 &dest, const core::vector3df &translation = core::vector3df()) const; + + /*! + Creates a matrix from this quaternion + Rotate about a center point + shortcut for + core::quaternion q; + q.rotationFromTo ( vin[i].Normal, forward ); + q.getMatrixCenter ( lookat, center, newPos ); + + core::matrix4 m2; + m2.setInverseTranslation ( center ); + lookat *= m2; + + core::matrix4 m3; + m2.setTranslation ( newPos ); + lookat *= m3; + + */ + void getMatrixCenter(matrix4 &dest, const core::vector3df ¢er, const core::vector3df &translation) const; + + //! Creates a matrix from this quaternion + inline void getMatrix_transposed(matrix4 &dest) const; + + //! Inverts this quaternion + quaternion &makeInverse(); + + //! Set this quaternion to the linear interpolation between two quaternions + /** NOTE: lerp result is *not* a normalized quaternion. In most cases + you will want to use lerpN instead as most other quaternion functions expect + to work with a normalized quaternion. + \param q1 First quaternion to be interpolated. + \param q2 Second quaternion to be interpolated. + \param time Progress of interpolation. For time=0 the result is + q1, for time=1 the result is q2. Otherwise interpolation + between q1 and q2. Result is not normalized. + */ + quaternion &lerp(quaternion q1, quaternion q2, f32 time); + + //! Set this quaternion to the linear interpolation between two quaternions and normalize the result + /** + \param q1 First quaternion to be interpolated. + \param q2 Second quaternion to be interpolated. + \param time Progress of interpolation. For time=0 the result is + q1, for time=1 the result is q2. Otherwise interpolation + between q1 and q2. Result is normalized. + */ + quaternion &lerpN(quaternion q1, quaternion q2, f32 time); + + //! Set this quaternion to the result of the spherical interpolation between two quaternions + /** \param q1 First quaternion to be interpolated. + \param q2 Second quaternion to be interpolated. + \param time Progress of interpolation. For time=0 the result is + q1, for time=1 the result is q2. Otherwise interpolation + between q1 and q2. + \param threshold To avoid inaccuracies at the end (time=1) the + interpolation switches to linear interpolation at some point. + This value defines how much of the remaining interpolation will + be calculated with lerp. Everything from 1-threshold up will be + linear interpolation. + */ + quaternion &slerp(quaternion q1, quaternion q2, + f32 time, f32 threshold = .05f); + + //! Set this quaternion to represent a rotation from angle and axis. + /** Axis must be unit length. + The quaternion representing the rotation is + q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k). + \param angle Rotation Angle in radians. + \param axis Rotation axis. */ + quaternion &fromAngleAxis(f32 angle, const vector3df &axis); + + //! Fills an angle (radians) around an axis (unit vector) + void toAngleAxis(f32 &angle, core::vector3df &axis) const; + + //! Output this quaternion to an Euler angle (radians) + void toEuler(vector3df &euler) const; + + //! Set quaternion to identity + quaternion &makeIdentity(); + + //! Set quaternion to represent a rotation from one vector to another. + quaternion &rotationFromTo(const vector3df &from, const vector3df &to); + + //! Quaternion elements. + f32 X; // vectorial (imaginary) part + f32 Y; + f32 Z; + f32 W; // real part +}; + +// Constructor which converts Euler angles to a quaternion +inline quaternion::quaternion(f32 x, f32 y, f32 z) +{ + set(x, y, z); +} + +// Constructor which converts Euler angles to a quaternion +inline quaternion::quaternion(const vector3df &vec) +{ + set(vec.X, vec.Y, vec.Z); +} + +#ifndef IRR_TEST_BROKEN_QUATERNION_USE +// Constructor which converts a matrix to a quaternion +inline quaternion::quaternion(const matrix4 &mat) +{ + (*this) = mat; +} +#endif + +#ifndef IRR_TEST_BROKEN_QUATERNION_USE +// matrix assignment operator +inline quaternion &quaternion::operator=(const matrix4 &m) +{ + const f32 diag = m[0] + m[5] + m[10] + 1; + + if (diag > 0.0f) { + const f32 scale = sqrtf(diag) * 2.0f; // get scale from diagonal + + // TODO: speed this up + X = (m[6] - m[9]) / scale; + Y = (m[8] - m[2]) / scale; + Z = (m[1] - m[4]) / scale; + W = 0.25f * scale; + } else { + if (m[0] > m[5] && m[0] > m[10]) { + // 1st element of diag is greatest value + // find scale according to 1st element, and double it + const f32 scale = sqrtf(1.0f + m[0] - m[5] - m[10]) * 2.0f; + + // TODO: speed this up + X = 0.25f * scale; + Y = (m[4] + m[1]) / scale; + Z = (m[2] + m[8]) / scale; + W = (m[6] - m[9]) / scale; + } else if (m[5] > m[10]) { + // 2nd element of diag is greatest value + // find scale according to 2nd element, and double it + const f32 scale = sqrtf(1.0f + m[5] - m[0] - m[10]) * 2.0f; + + // TODO: speed this up + X = (m[4] + m[1]) / scale; + Y = 0.25f * scale; + Z = (m[9] + m[6]) / scale; + W = (m[8] - m[2]) / scale; + } else { + // 3rd element of diag is greatest value + // find scale according to 3rd element, and double it + const f32 scale = sqrtf(1.0f + m[10] - m[0] - m[5]) * 2.0f; + + // TODO: speed this up + X = (m[8] + m[2]) / scale; + Y = (m[9] + m[6]) / scale; + Z = 0.25f * scale; + W = (m[1] - m[4]) / scale; + } + } + + return normalize(); +} +#endif + +// multiplication operator +inline quaternion quaternion::operator*(const quaternion &other) const +{ + quaternion tmp; + + tmp.W = (other.W * W) - (other.X * X) - (other.Y * Y) - (other.Z * Z); + tmp.X = (other.W * X) + (other.X * W) + (other.Y * Z) - (other.Z * Y); + tmp.Y = (other.W * Y) + (other.Y * W) + (other.Z * X) - (other.X * Z); + tmp.Z = (other.W * Z) + (other.Z * W) + (other.X * Y) - (other.Y * X); + + return tmp; +} + +// multiplication operator +inline quaternion quaternion::operator*(f32 s) const +{ + return quaternion(s * X, s * Y, s * Z, s * W); +} + +// multiplication operator +inline quaternion &quaternion::operator*=(f32 s) +{ + X *= s; + Y *= s; + Z *= s; + W *= s; + return *this; +} + +// multiplication operator +inline quaternion &quaternion::operator*=(const quaternion &other) +{ + return (*this = other * (*this)); +} + +// add operator +inline quaternion quaternion::operator+(const quaternion &b) const +{ + return quaternion(X + b.X, Y + b.Y, Z + b.Z, W + b.W); +} + +#ifndef IRR_TEST_BROKEN_QUATERNION_USE +// Creates a matrix from this quaternion +inline matrix4 quaternion::getMatrix() const +{ + core::matrix4 m; + getMatrix(m); + return m; +} +#endif + +//! Faster method to create a rotation matrix, you should normalize the quaternion before! +inline void quaternion::getMatrixFast(matrix4 &dest) const +{ + // TODO: + // gpu quaternion skinning => fast Bones transform chain O_O YEAH! + // http://www.mrelusive.com/publications/papers/SIMD-From-Quaternion-to-Matrix-and-Back.pdf + dest[0] = 1.0f - 2.0f * Y * Y - 2.0f * Z * Z; + dest[1] = 2.0f * X * Y + 2.0f * Z * W; + dest[2] = 2.0f * X * Z - 2.0f * Y * W; + dest[3] = 0.0f; + + dest[4] = 2.0f * X * Y - 2.0f * Z * W; + dest[5] = 1.0f - 2.0f * X * X - 2.0f * Z * Z; + dest[6] = 2.0f * Z * Y + 2.0f * X * W; + dest[7] = 0.0f; + + dest[8] = 2.0f * X * Z + 2.0f * Y * W; + dest[9] = 2.0f * Z * Y - 2.0f * X * W; + dest[10] = 1.0f - 2.0f * X * X - 2.0f * Y * Y; + dest[11] = 0.0f; + + dest[12] = 0.f; + dest[13] = 0.f; + dest[14] = 0.f; + dest[15] = 1.f; + + dest.setDefinitelyIdentityMatrix(false); +} + +/*! + Creates a matrix from this quaternion +*/ +inline void quaternion::getMatrix(matrix4 &dest, + const core::vector3df ¢er) const +{ + // ok creating a copy may be slower, but at least avoid internal + // state chance (also because otherwise we cannot keep this method "const"). + + quaternion q(*this); + q.normalize(); + f32 X = q.X; + f32 Y = q.Y; + f32 Z = q.Z; + f32 W = q.W; + + dest[0] = 1.0f - 2.0f * Y * Y - 2.0f * Z * Z; + dest[1] = 2.0f * X * Y + 2.0f * Z * W; + dest[2] = 2.0f * X * Z - 2.0f * Y * W; + dest[3] = 0.0f; + + dest[4] = 2.0f * X * Y - 2.0f * Z * W; + dest[5] = 1.0f - 2.0f * X * X - 2.0f * Z * Z; + dest[6] = 2.0f * Z * Y + 2.0f * X * W; + dest[7] = 0.0f; + + dest[8] = 2.0f * X * Z + 2.0f * Y * W; + dest[9] = 2.0f * Z * Y - 2.0f * X * W; + dest[10] = 1.0f - 2.0f * X * X - 2.0f * Y * Y; + dest[11] = 0.0f; + + dest[12] = center.X; + dest[13] = center.Y; + dest[14] = center.Z; + dest[15] = 1.f; + + dest.setDefinitelyIdentityMatrix(false); +} + +/*! + Creates a matrix from this quaternion + Rotate about a center point + shortcut for + core::quaternion q; + q.rotationFromTo(vin[i].Normal, forward); + q.getMatrix(lookat, center); + + core::matrix4 m2; + m2.setInverseTranslation(center); + lookat *= m2; +*/ +inline void quaternion::getMatrixCenter(matrix4 &dest, + const core::vector3df ¢er, + const core::vector3df &translation) const +{ + quaternion q(*this); + q.normalize(); + f32 X = q.X; + f32 Y = q.Y; + f32 Z = q.Z; + f32 W = q.W; + + dest[0] = 1.0f - 2.0f * Y * Y - 2.0f * Z * Z; + dest[1] = 2.0f * X * Y + 2.0f * Z * W; + dest[2] = 2.0f * X * Z - 2.0f * Y * W; + dest[3] = 0.0f; + + dest[4] = 2.0f * X * Y - 2.0f * Z * W; + dest[5] = 1.0f - 2.0f * X * X - 2.0f * Z * Z; + dest[6] = 2.0f * Z * Y + 2.0f * X * W; + dest[7] = 0.0f; + + dest[8] = 2.0f * X * Z + 2.0f * Y * W; + dest[9] = 2.0f * Z * Y - 2.0f * X * W; + dest[10] = 1.0f - 2.0f * X * X - 2.0f * Y * Y; + dest[11] = 0.0f; + + dest.setRotationCenter(center, translation); +} + +// Creates a matrix from this quaternion +inline void quaternion::getMatrix_transposed(matrix4 &dest) const +{ + quaternion q(*this); + q.normalize(); + f32 X = q.X; + f32 Y = q.Y; + f32 Z = q.Z; + f32 W = q.W; + + dest[0] = 1.0f - 2.0f * Y * Y - 2.0f * Z * Z; + dest[4] = 2.0f * X * Y + 2.0f * Z * W; + dest[8] = 2.0f * X * Z - 2.0f * Y * W; + dest[12] = 0.0f; + + dest[1] = 2.0f * X * Y - 2.0f * Z * W; + dest[5] = 1.0f - 2.0f * X * X - 2.0f * Z * Z; + dest[9] = 2.0f * Z * Y + 2.0f * X * W; + dest[13] = 0.0f; + + dest[2] = 2.0f * X * Z + 2.0f * Y * W; + dest[6] = 2.0f * Z * Y - 2.0f * X * W; + dest[10] = 1.0f - 2.0f * X * X - 2.0f * Y * Y; + dest[14] = 0.0f; + + dest[3] = 0.f; + dest[7] = 0.f; + dest[11] = 0.f; + dest[15] = 1.f; + + dest.setDefinitelyIdentityMatrix(false); +} + +// Inverts this quaternion +inline quaternion &quaternion::makeInverse() +{ + X = -X; + Y = -Y; + Z = -Z; + return *this; +} + +// sets new quaternion +inline quaternion &quaternion::set(f32 x, f32 y, f32 z, f32 w) +{ + X = x; + Y = y; + Z = z; + W = w; + return *this; +} + +// sets new quaternion based on Euler angles +inline quaternion &quaternion::set(f32 x, f32 y, f32 z) +{ + f64 angle; + + angle = x * 0.5; + const f64 sr = sin(angle); + const f64 cr = cos(angle); + + angle = y * 0.5; + const f64 sp = sin(angle); + const f64 cp = cos(angle); + + angle = z * 0.5; + const f64 sy = sin(angle); + const f64 cy = cos(angle); + + const f64 cpcy = cp * cy; + const f64 spcy = sp * cy; + const f64 cpsy = cp * sy; + const f64 spsy = sp * sy; + + X = (f32)(sr * cpcy - cr * spsy); + Y = (f32)(cr * spcy + sr * cpsy); + Z = (f32)(cr * cpsy - sr * spcy); + W = (f32)(cr * cpcy + sr * spsy); + + return normalize(); +} + +// sets new quaternion based on Euler angles +inline quaternion &quaternion::set(const core::vector3df &vec) +{ + return set(vec.X, vec.Y, vec.Z); +} + +// sets new quaternion based on other quaternion +inline quaternion &quaternion::set(const core::quaternion &quat) +{ + return (*this = quat); +} + +//! returns if this quaternion equals the other one, taking floating point rounding errors into account +inline bool quaternion::equals(const quaternion &other, const f32 tolerance) const +{ + return core::equals(X, other.X, tolerance) && + core::equals(Y, other.Y, tolerance) && + core::equals(Z, other.Z, tolerance) && + core::equals(W, other.W, tolerance); +} + +// normalizes the quaternion +inline quaternion &quaternion::normalize() +{ + // removed conditional branch since it may slow down and anyway the condition was + // false even after normalization in some cases. + return (*this *= (f32)reciprocal_squareroot((f64)(X * X + Y * Y + Z * Z + W * W))); +} + +// Set this quaternion to the result of the linear interpolation between two quaternions +inline quaternion &quaternion::lerp(quaternion q1, quaternion q2, f32 time) +{ + const f32 scale = 1.0f - time; + return (*this = (q1 * scale) + (q2 * time)); +} + +// Set this quaternion to the result of the linear interpolation between two quaternions and normalize the result +inline quaternion &quaternion::lerpN(quaternion q1, quaternion q2, f32 time) +{ + const f32 scale = 1.0f - time; + return (*this = ((q1 * scale) + (q2 * time)).normalize()); +} + +// set this quaternion to the result of the interpolation between two quaternions +inline quaternion &quaternion::slerp(quaternion q1, quaternion q2, f32 time, f32 threshold) +{ + f32 angle = q1.dotProduct(q2); + + // make sure we use the short rotation + if (angle < 0.0f) { + q1 *= -1.0f; + angle *= -1.0f; + } + + if (angle <= (1 - threshold)) { // spherical interpolation + const f32 theta = acosf(angle); + const f32 invsintheta = reciprocal(sinf(theta)); + const f32 scale = sinf(theta * (1.0f - time)) * invsintheta; + const f32 invscale = sinf(theta * time) * invsintheta; + return (*this = (q1 * scale) + (q2 * invscale)); + } else // linear interpolation + return lerpN(q1, q2, time); +} + +// calculates the dot product +inline f32 quaternion::dotProduct(const quaternion &q2) const +{ + return (X * q2.X) + (Y * q2.Y) + (Z * q2.Z) + (W * q2.W); +} + +//! axis must be unit length, angle in radians +inline quaternion &quaternion::fromAngleAxis(f32 angle, const vector3df &axis) +{ + const f32 fHalfAngle = 0.5f * angle; + const f32 fSin = sinf(fHalfAngle); + W = cosf(fHalfAngle); + X = fSin * axis.X; + Y = fSin * axis.Y; + Z = fSin * axis.Z; + return *this; +} + +inline void quaternion::toAngleAxis(f32 &angle, core::vector3df &axis) const +{ + const f32 scale = sqrtf(X * X + Y * Y + Z * Z); + + if (core::iszero(scale) || W > 1.0f || W < -1.0f) { + angle = 0.0f; + axis.X = 0.0f; + axis.Y = 1.0f; + axis.Z = 0.0f; + } else { + const f32 invscale = reciprocal(scale); + angle = 2.0f * acosf(W); + axis.X = X * invscale; + axis.Y = Y * invscale; + axis.Z = Z * invscale; + } +} + +inline void quaternion::toEuler(vector3df &euler) const +{ + const f64 sqw = W * W; + const f64 sqx = X * X; + const f64 sqy = Y * Y; + const f64 sqz = Z * Z; + const f64 test = 2.0 * (Y * W - X * Z); + + if (core::equals(test, 1.0, 0.000001)) { + // heading = rotation about z-axis + euler.Z = (f32)(-2.0 * atan2(X, W)); + // bank = rotation about x-axis + euler.X = 0; + // attitude = rotation about y-axis + euler.Y = (f32)(core::PI64 / 2.0); + } else if (core::equals(test, -1.0, 0.000001)) { + // heading = rotation about z-axis + euler.Z = (f32)(2.0 * atan2(X, W)); + // bank = rotation about x-axis + euler.X = 0; + // attitude = rotation about y-axis + euler.Y = (f32)(core::PI64 / -2.0); + } else { + // heading = rotation about z-axis + euler.Z = (f32)atan2(2.0 * (X * Y + Z * W), (sqx - sqy - sqz + sqw)); + // bank = rotation about x-axis + euler.X = (f32)atan2(2.0 * (Y * Z + X * W), (-sqx - sqy + sqz + sqw)); + // attitude = rotation about y-axis + euler.Y = (f32)asin(clamp(test, -1.0, 1.0)); + } +} + +inline vector3df quaternion::operator*(const vector3df &v) const +{ + // nVidia SDK implementation + + vector3df uv, uuv; + const vector3df qvec(X, Y, Z); + uv = qvec.crossProduct(v); + uuv = qvec.crossProduct(uv); + uv *= (2.0f * W); + uuv *= 2.0f; + + return v + uv + uuv; +} + +// set quaternion to identity +inline core::quaternion &quaternion::makeIdentity() +{ + W = 1.f; + X = 0.f; + Y = 0.f; + Z = 0.f; + return *this; +} + +inline core::quaternion &quaternion::rotationFromTo(const vector3df &from, const vector3df &to) +{ + // Based on Stan Melax's article in Game Programming Gems + // Optimized by Robert Eisele: https://raw.org/proof/quaternion-from-two-vectors + + // Copy, since cannot modify local + vector3df v0 = from; + vector3df v1 = to; + v0.normalize(); + v1.normalize(); + + const f32 d = v0.dotProduct(v1); + if (d >= 1.0f) { // If dot == 1, vectors are the same + return makeIdentity(); + } else if (d <= -1.0f) { // exactly opposite + core::vector3df axis(1.0f, 0.f, 0.f); + axis = axis.crossProduct(v0); + if (axis.getLength() == 0) { + axis.set(0.f, 1.f, 0.f); + axis = axis.crossProduct(v0); + } + // same as fromAngleAxis(core::PI, axis).normalize(); + return set(axis.X, axis.Y, axis.Z, 0).normalize(); + } + + const vector3df c = v0.crossProduct(v1); + return set(c.X, c.Y, c.Z, 1 + d).normalize(); +} + +} // end namespace core +} // end namespace irr diff --git a/irr/include/rect.h b/irr/include/rect.h new file mode 100644 index 000000000..bced2d59e --- /dev/null +++ b/irr/include/rect.h @@ -0,0 +1,281 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" +#include "dimension2d.h" +#include "position2d.h" + +namespace irr +{ +namespace core +{ + +//! Rectangle template. +/** Mostly used by 2D GUI elements and for 2D drawing methods. +It has 2 positions instead of position and dimension and a fast +method for collision detection with other rectangles and points. + +Coordinates are (0,0) for top-left corner, and increasing to the right +and to the bottom. +*/ +template +class rect +{ +public: + //! Default constructor creating empty rectangle at (0,0) + constexpr rect() : + UpperLeftCorner(0, 0), LowerRightCorner(0, 0) {} + + //! Constructor with two corners + constexpr rect(T x, T y, T x2, T y2) : + UpperLeftCorner(x, y), LowerRightCorner(x2, y2) {} + + //! Constructor with two corners + constexpr rect(const position2d &upperLeft, const position2d &lowerRight) : + UpperLeftCorner(upperLeft), LowerRightCorner(lowerRight) {} + + //! Constructor with upper left corner and dimension + template + constexpr rect(const position2d &pos, const dimension2d &size) : + UpperLeftCorner(pos), LowerRightCorner(pos.X + size.Width, pos.Y + size.Height) + { + } + + //! Constructor with upper left at 0,0 and lower right using dimension + template + explicit constexpr rect(const dimension2d &size) : + UpperLeftCorner(0, 0), LowerRightCorner(size.Width, size.Height) + { + } + + //! move right by given numbers + rect operator+(const position2d &pos) const + { + rect ret(*this); + return ret += pos; + } + + //! move right by given numbers + rect &operator+=(const position2d &pos) + { + UpperLeftCorner += pos; + LowerRightCorner += pos; + return *this; + } + + //! move left by given numbers + rect operator-(const position2d &pos) const + { + rect ret(*this); + return ret -= pos; + } + + //! move left by given numbers + rect &operator-=(const position2d &pos) + { + UpperLeftCorner -= pos; + LowerRightCorner -= pos; + return *this; + } + + //! equality operator + constexpr bool operator==(const rect &other) const + { + return (UpperLeftCorner == other.UpperLeftCorner && + LowerRightCorner == other.LowerRightCorner); + } + + //! inequality operator + constexpr bool operator!=(const rect &other) const + { + return (UpperLeftCorner != other.UpperLeftCorner || + LowerRightCorner != other.LowerRightCorner); + } + + //! compares size of rectangles + bool operator<(const rect &other) const + { + return getArea() < other.getArea(); + } + + //! Returns size of rectangle + T getArea() const + { + return getWidth() * getHeight(); + } + + //! Returns if a 2d point is within this rectangle. + /** \param pos Position to test if it lies within this rectangle. + \return True if the position is within the rectangle, false if not. */ + bool isPointInside(const position2d &pos) const + { + return (UpperLeftCorner.X <= pos.X && + UpperLeftCorner.Y <= pos.Y && + LowerRightCorner.X >= pos.X && + LowerRightCorner.Y >= pos.Y); + } + + //! Check if the rectangle collides with another rectangle. + /** \param other Rectangle to test collision with + \return True if the rectangles collide. */ + bool isRectCollided(const rect &other) const + { + return (LowerRightCorner.Y > other.UpperLeftCorner.Y && + UpperLeftCorner.Y < other.LowerRightCorner.Y && + LowerRightCorner.X > other.UpperLeftCorner.X && + UpperLeftCorner.X < other.LowerRightCorner.X); + } + + //! Clips this rectangle with another one. + /** \param other Rectangle to clip with */ + void clipAgainst(const rect &other) + { + if (other.LowerRightCorner.X < LowerRightCorner.X) + LowerRightCorner.X = other.LowerRightCorner.X; + if (other.LowerRightCorner.Y < LowerRightCorner.Y) + LowerRightCorner.Y = other.LowerRightCorner.Y; + + if (other.UpperLeftCorner.X > LowerRightCorner.X) + LowerRightCorner.X = other.UpperLeftCorner.X; + if (other.UpperLeftCorner.Y > LowerRightCorner.Y) + LowerRightCorner.Y = other.UpperLeftCorner.Y; + + if (other.LowerRightCorner.X < UpperLeftCorner.X) + UpperLeftCorner.X = other.LowerRightCorner.X; + if (other.LowerRightCorner.Y < UpperLeftCorner.Y) + UpperLeftCorner.Y = other.LowerRightCorner.Y; + + if (other.UpperLeftCorner.X > UpperLeftCorner.X) + UpperLeftCorner.X = other.UpperLeftCorner.X; + if (other.UpperLeftCorner.Y > UpperLeftCorner.Y) + UpperLeftCorner.Y = other.UpperLeftCorner.Y; + } + + //! Moves this rectangle to fit inside another one. + /** \return True on success, false if not possible */ + bool constrainTo(const rect &other) + { + if (other.getWidth() < getWidth() || other.getHeight() < getHeight()) + return false; + + T diff = other.LowerRightCorner.X - LowerRightCorner.X; + if (diff < 0) { + LowerRightCorner.X += diff; + UpperLeftCorner.X += diff; + } + + diff = other.LowerRightCorner.Y - LowerRightCorner.Y; + if (diff < 0) { + LowerRightCorner.Y += diff; + UpperLeftCorner.Y += diff; + } + + diff = UpperLeftCorner.X - other.UpperLeftCorner.X; + if (diff < 0) { + UpperLeftCorner.X -= diff; + LowerRightCorner.X -= diff; + } + + diff = UpperLeftCorner.Y - other.UpperLeftCorner.Y; + if (diff < 0) { + UpperLeftCorner.Y -= diff; + LowerRightCorner.Y -= diff; + } + + return true; + } + + //! Get width of rectangle. + T getWidth() const + { + return LowerRightCorner.X - UpperLeftCorner.X; + } + + //! Get height of rectangle. + T getHeight() const + { + return LowerRightCorner.Y - UpperLeftCorner.Y; + } + + //! If the lower right corner of the rect is smaller then the upper left, the points are swapped. + void repair() + { + if (LowerRightCorner.X < UpperLeftCorner.X) { + T t = LowerRightCorner.X; + LowerRightCorner.X = UpperLeftCorner.X; + UpperLeftCorner.X = t; + } + + if (LowerRightCorner.Y < UpperLeftCorner.Y) { + T t = LowerRightCorner.Y; + LowerRightCorner.Y = UpperLeftCorner.Y; + UpperLeftCorner.Y = t; + } + } + + //! Returns if the rect is valid to draw. + /** It would be invalid if the UpperLeftCorner is lower or more + right than the LowerRightCorner. */ + bool isValid() const + { + return ((LowerRightCorner.X >= UpperLeftCorner.X) && + (LowerRightCorner.Y >= UpperLeftCorner.Y)); + } + + //! Get the center of the rectangle + position2d getCenter() const + { + return position2d( + (UpperLeftCorner.X + LowerRightCorner.X) / 2, + (UpperLeftCorner.Y + LowerRightCorner.Y) / 2); + } + + //! Get the dimensions of the rectangle + dimension2d getSize() const + { + return dimension2d(getWidth(), getHeight()); + } + + //! Adds a point to the rectangle + /** Causes the rectangle to grow bigger if point is outside of + the box + \param p Point to add to the box. */ + void addInternalPoint(const position2d &p) + { + addInternalPoint(p.X, p.Y); + } + + //! Adds a point to the bounding rectangle + /** Causes the rectangle to grow bigger if point is outside of + the box + \param x X-Coordinate of the point to add to this box. + \param y Y-Coordinate of the point to add to this box. */ + void addInternalPoint(T x, T y) + { + if (x > LowerRightCorner.X) + LowerRightCorner.X = x; + if (y > LowerRightCorner.Y) + LowerRightCorner.Y = y; + + if (x < UpperLeftCorner.X) + UpperLeftCorner.X = x; + if (y < UpperLeftCorner.Y) + UpperLeftCorner.Y = y; + } + + //! Upper left corner + position2d UpperLeftCorner; + //! Lower right corner + position2d LowerRightCorner; +}; + +//! Rectangle with float values +typedef rect rectf; +//! Rectangle with int values +typedef rect recti; + +} // end namespace core +} // end namespace irr diff --git a/irr/include/vector2d.h b/irr/include/vector2d.h new file mode 100644 index 000000000..4c41389f4 --- /dev/null +++ b/irr/include/vector2d.h @@ -0,0 +1,503 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrMath.h" +#include "dimension2d.h" + +#include + +namespace irr +{ +namespace core +{ + +//! 2d vector template class with lots of operators and methods. +/** As of Irrlicht 1.6, this class supersedes position2d, which should + be considered deprecated. */ +template +class vector2d +{ +public: + //! Default constructor (null vector) + constexpr vector2d() : + X(0), Y(0) {} + //! Constructor with two different values + constexpr vector2d(T nx, T ny) : + X(nx), Y(ny) {} + //! Constructor with the same value for both members + explicit constexpr vector2d(T n) : + X(n), Y(n) {} + + constexpr vector2d(const dimension2d &other) : + X(other.Width), Y(other.Height) {} + + // operators + + vector2d operator-() const { return vector2d(-X, -Y); } + + vector2d &operator=(const dimension2d &other) + { + X = other.Width; + Y = other.Height; + return *this; + } + + vector2d operator+(const vector2d &other) const { return vector2d(X + other.X, Y + other.Y); } + vector2d operator+(const dimension2d &other) const { return vector2d(X + other.Width, Y + other.Height); } + vector2d &operator+=(const vector2d &other) + { + X += other.X; + Y += other.Y; + return *this; + } + vector2d operator+(const T v) const { return vector2d(X + v, Y + v); } + vector2d &operator+=(const T v) + { + X += v; + Y += v; + return *this; + } + vector2d &operator+=(const dimension2d &other) + { + X += other.Width; + Y += other.Height; + return *this; + } + + vector2d operator-(const vector2d &other) const { return vector2d(X - other.X, Y - other.Y); } + vector2d operator-(const dimension2d &other) const { return vector2d(X - other.Width, Y - other.Height); } + vector2d &operator-=(const vector2d &other) + { + X -= other.X; + Y -= other.Y; + return *this; + } + vector2d operator-(const T v) const { return vector2d(X - v, Y - v); } + vector2d &operator-=(const T v) + { + X -= v; + Y -= v; + return *this; + } + vector2d &operator-=(const dimension2d &other) + { + X -= other.Width; + Y -= other.Height; + return *this; + } + + vector2d operator*(const vector2d &other) const { return vector2d(X * other.X, Y * other.Y); } + vector2d &operator*=(const vector2d &other) + { + X *= other.X; + Y *= other.Y; + return *this; + } + vector2d operator*(const T v) const { return vector2d(X * v, Y * v); } + vector2d &operator*=(const T v) + { + X *= v; + Y *= v; + return *this; + } + + vector2d operator/(const vector2d &other) const { return vector2d(X / other.X, Y / other.Y); } + vector2d &operator/=(const vector2d &other) + { + X /= other.X; + Y /= other.Y; + return *this; + } + vector2d operator/(const T v) const { return vector2d(X / v, Y / v); } + vector2d &operator/=(const T v) + { + X /= v; + Y /= v; + return *this; + } + + T &operator[](u32 index) + { + _IRR_DEBUG_BREAK_IF(index > 1) // access violation + + return *(&X + index); + } + + const T &operator[](u32 index) const + { + _IRR_DEBUG_BREAK_IF(index > 1) // access violation + + return *(&X + index); + } + + //! sort in order X, Y. + constexpr bool operator<=(const vector2d &other) const + { + return !(*this > other); + } + + //! sort in order X, Y. + constexpr bool operator>=(const vector2d &other) const + { + return !(*this < other); + } + + //! sort in order X, Y. + constexpr bool operator<(const vector2d &other) const + { + return X < other.X || (X == other.X && Y < other.Y); + } + + //! sort in order X, Y. + constexpr bool operator>(const vector2d &other) const + { + return X > other.X || (X == other.X && Y > other.Y); + } + + constexpr bool operator==(const vector2d &other) const + { + return X == other.X && Y == other.Y; + } + + constexpr bool operator!=(const vector2d &other) const + { + return !(*this == other); + } + + // functions + + //! Checks if this vector equals the other one. + /** Takes floating point rounding errors into account. + \param other Vector to compare with. + \return True if the two vector are (almost) equal, else false. */ + bool equals(const vector2d &other) const + { + return core::equals(X, other.X) && core::equals(Y, other.Y); + } + + vector2d &set(T nx, T ny) + { + X = nx; + Y = ny; + return *this; + } + vector2d &set(const vector2d &p) + { + X = p.X; + Y = p.Y; + return *this; + } + + //! Gets the length of the vector. + /** \return The length of the vector. */ + T getLength() const { return core::squareroot(X * X + Y * Y); } + + //! Get the squared length of this vector + /** This is useful because it is much faster than getLength(). + \return The squared length of the vector. */ + T getLengthSQ() const { return X * X + Y * Y; } + + //! Get the dot product of this vector with another. + /** \param other Other vector to take dot product with. + \return The dot product of the two vectors. */ + T dotProduct(const vector2d &other) const + { + return X * other.X + Y * other.Y; + } + + //! check if this vector is parallel to another vector + bool nearlyParallel(const vector2d &other, const T factor = relativeErrorFactor()) const + { + // https://eagergames.wordpress.com/2017/04/01/fast-parallel-lines-and-vectors-test/ + // if a || b then a.x/a.y = b.x/b.y (similar triangles) + // if a || b then either both x are 0 or both y are 0. + + return equalsRelative(X * other.Y, other.X * Y, factor) && // a bit counterintuitive, but makes sure that + // only y or only x are 0, and at same time deals + // with the case where one vector is zero vector. + (X * other.X + Y * other.Y) != 0; + } + + //! Gets distance from another point. + /** Here, the vector is interpreted as a point in 2-dimensional space. + \param other Other vector to measure from. + \return Distance from other point. */ + T getDistanceFrom(const vector2d &other) const + { + return vector2d(X - other.X, Y - other.Y).getLength(); + } + + //! Returns squared distance from another point. + /** Here, the vector is interpreted as a point in 2-dimensional space. + \param other Other vector to measure from. + \return Squared distance from other point. */ + T getDistanceFromSQ(const vector2d &other) const + { + return vector2d(X - other.X, Y - other.Y).getLengthSQ(); + } + + //! rotates the point anticlockwise around a center by an amount of degrees. + /** \param degrees Amount of degrees to rotate by, anticlockwise. + \param center Rotation center. + \return This vector after transformation. */ + vector2d &rotateBy(f64 degrees, const vector2d ¢er = vector2d()) + { + degrees *= DEGTORAD64; + const f64 cs = cos(degrees); + const f64 sn = sin(degrees); + + X -= center.X; + Y -= center.Y; + + set((T)(X * cs - Y * sn), (T)(X * sn + Y * cs)); + + X += center.X; + Y += center.Y; + return *this; + } + + //! Normalize the vector. + /** The null vector is left untouched. + \return Reference to this vector, after normalization. */ + vector2d &normalize() + { + f32 length = (f32)(X * X + Y * Y); + if (length == 0) + return *this; + length = core::reciprocal_squareroot(length); + X = (T)(X * length); + Y = (T)(Y * length); + return *this; + } + + //! Calculates the angle of this vector in degrees in the trigonometric sense. + /** 0 is to the right (3 o'clock), values increase counter-clockwise. + This method has been suggested by Pr3t3nd3r. + \return Returns a value between 0 and 360. */ + f64 getAngleTrig() const + { + if (Y == 0) + return X < 0 ? 180 : 0; + else if (X == 0) + return Y < 0 ? 270 : 90; + + if (Y > 0) + if (X > 0) + return atan((irr::f64)Y / (irr::f64)X) * RADTODEG64; + else + return 180.0 - atan((irr::f64)Y / -(irr::f64)X) * RADTODEG64; + else if (X > 0) + return 360.0 - atan(-(irr::f64)Y / (irr::f64)X) * RADTODEG64; + else + return 180.0 + atan(-(irr::f64)Y / -(irr::f64)X) * RADTODEG64; + } + + //! Calculates the angle of this vector in degrees in the counter trigonometric sense. + /** 0 is to the right (3 o'clock), values increase clockwise. + \return Returns a value between 0 and 360. */ + inline f64 getAngle() const + { + if (Y == 0) // corrected thanks to a suggestion by Jox + return X < 0 ? 180 : 0; + else if (X == 0) + return Y < 0 ? 90 : 270; + + // don't use getLength here to avoid precision loss with s32 vectors + // avoid floating-point trouble as sqrt(y*y) is occasionally larger than y, so clamp + const f64 tmp = core::clamp(Y / sqrt((f64)(X * X + Y * Y)), -1.0, 1.0); + const f64 angle = atan(core::squareroot(1 - tmp * tmp) / tmp) * RADTODEG64; + + if (X > 0 && Y > 0) + return angle + 270; + else if (X > 0 && Y < 0) + return angle + 90; + else if (X < 0 && Y < 0) + return 90 - angle; + else if (X < 0 && Y > 0) + return 270 - angle; + + return angle; + } + + //! Calculates the angle between this vector and another one in degree. + /** \param b Other vector to test with. + \return Returns a value between 0 and 90. */ + inline f64 getAngleWith(const vector2d &b) const + { + f64 tmp = (f64)(X * b.X + Y * b.Y); + + if (tmp == 0.0) + return 90.0; + + tmp = tmp / core::squareroot((f64)((X * X + Y * Y) * (b.X * b.X + b.Y * b.Y))); + if (tmp < 0.0) + tmp = -tmp; + if (tmp > 1.0) // avoid floating-point trouble + tmp = 1.0; + + return atan(sqrt(1 - tmp * tmp) / tmp) * RADTODEG64; + } + + //! Returns if this vector interpreted as a point is on a line between two other points. + /** It is assumed that the point is on the line. + \param begin Beginning vector to compare between. + \param end Ending vector to compare between. + \return True if this vector is between begin and end, false if not. */ + bool isBetweenPoints(const vector2d &begin, const vector2d &end) const + { + // . end + // / + // / + // / + // . begin + // - + // - + // . this point (am I inside or outside)? + // + if (begin.X != end.X) { + return ((begin.X <= X && X <= end.X) || + (begin.X >= X && X >= end.X)); + } else { + return ((begin.Y <= Y && Y <= end.Y) || + (begin.Y >= Y && Y >= end.Y)); + } + } + + //! Creates an interpolated vector between this vector and another vector. + /** \param other The other vector to interpolate with. + \param d Interpolation value between 0.0f (all the other vector) and 1.0f (all this vector). + Note that this is the opposite direction of interpolation to getInterpolated_quadratic() + \return An interpolated vector. This vector is not modified. */ + vector2d getInterpolated(const vector2d &other, f64 d) const + { + const f64 inv = 1.0f - d; + return vector2d((T)(other.X * inv + X * d), (T)(other.Y * inv + Y * d)); + } + + //! Creates a quadratically interpolated vector between this and two other vectors. + /** \param v2 Second vector to interpolate with. + \param v3 Third vector to interpolate with (maximum at 1.0f) + \param d Interpolation value between 0.0f (all this vector) and 1.0f (all the 3rd vector). + Note that this is the opposite direction of interpolation to getInterpolated() and interpolate() + \return An interpolated vector. This vector is not modified. */ + vector2d getInterpolated_quadratic(const vector2d &v2, const vector2d &v3, f64 d) const + { + // this*(1-d)*(1-d) + 2 * v2 * (1-d) + v3 * d * d; + const f64 inv = 1.0f - d; + const f64 mul0 = inv * inv; + const f64 mul1 = 2.0f * d * inv; + const f64 mul2 = d * d; + + return vector2d((T)(X * mul0 + v2.X * mul1 + v3.X * mul2), + (T)(Y * mul0 + v2.Y * mul1 + v3.Y * mul2)); + } + + /*! Test if this point and another 2 points taken as triplet + are colinear, clockwise, anticlockwise. This can be used also + to check winding order in triangles for 2D meshes. + \return 0 if points are colinear, 1 if clockwise, 2 if anticlockwise + */ + s32 checkOrientation(const vector2d &b, const vector2d &c) const + { + // Example of clockwise points + // + // ^ Y + // | A + // | . . + // | . . + // | C.....B + // +---------------> X + + T val = (b.Y - Y) * (c.X - b.X) - + (b.X - X) * (c.Y - b.Y); + + if (val == 0) + return 0; // colinear + + return (val > 0) ? 1 : 2; // clock or counterclock wise + } + + /*! Returns true if points (a,b,c) are clockwise on the X,Y plane*/ + inline bool areClockwise(const vector2d &b, const vector2d &c) const + { + T val = (b.Y - Y) * (c.X - b.X) - + (b.X - X) * (c.Y - b.Y); + + return val > 0; + } + + /*! Returns true if points (a,b,c) are counterclockwise on the X,Y plane*/ + inline bool areCounterClockwise(const vector2d &b, const vector2d &c) const + { + T val = (b.Y - Y) * (c.X - b.X) - + (b.X - X) * (c.Y - b.Y); + + return val < 0; + } + + //! Sets this vector to the linearly interpolated vector between a and b. + /** \param a first vector to interpolate with, maximum at 1.0f + \param b second vector to interpolate with, maximum at 0.0f + \param d Interpolation value between 0.0f (all vector b) and 1.0f (all vector a) + Note that this is the opposite direction of interpolation to getInterpolated_quadratic() + */ + vector2d &interpolate(const vector2d &a, const vector2d &b, f64 d) + { + X = (T)((f64)b.X + ((a.X - b.X) * d)); + Y = (T)((f64)b.Y + ((a.Y - b.Y) * d)); + return *this; + } + + //! X coordinate of vector. + T X; + + //! Y coordinate of vector. + T Y; +}; + +//! Typedef for f32 2d vector. +typedef vector2d vector2df; + +//! Typedef for integer 2d vector. +typedef vector2d vector2di; + +template +vector2d operator*(const S scalar, const vector2d &vector) +{ + return vector * scalar; +} + +// These methods are declared in dimension2d, but need definitions of vector2d +template +dimension2d::dimension2d(const vector2d &other) : + Width(other.X), Height(other.Y) +{ +} + +template +bool dimension2d::operator==(const vector2d &other) const +{ + return Width == other.X && Height == other.Y; +} + +} // end namespace core +} // end namespace irr + +namespace std +{ + +template +struct hash> +{ + size_t operator()(const irr::core::vector2d &vec) const + { + size_t h1 = hash()(vec.X); + size_t h2 = hash()(vec.Y); + return (h1 << (4 * sizeof(h1)) | h1 >> (4 * sizeof(h1))) ^ h2; + } +}; + +} diff --git a/irr/include/vector3d.h b/irr/include/vector3d.h new file mode 100644 index 000000000..a69f17e16 --- /dev/null +++ b/irr/include/vector3d.h @@ -0,0 +1,549 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrMath.h" + +#include + +namespace irr +{ +namespace core +{ + +//! 3d vector template class with lots of operators and methods. +/** The vector3d class is used in Irrlicht for three main purposes: + 1) As a direction vector (most of the methods assume this). + 2) As a position in 3d space (which is synonymous with a direction vector from the origin to this position). + 3) To hold three Euler rotations, where X is pitch, Y is yaw and Z is roll. +*/ +template +class vector3d +{ +public: + //! Default constructor (null vector). + constexpr vector3d() : + X(0), Y(0), Z(0) {} + //! Constructor with three different values + constexpr vector3d(T nx, T ny, T nz) : + X(nx), Y(ny), Z(nz) {} + //! Constructor with the same value for all elements + explicit constexpr vector3d(T n) : + X(n), Y(n), Z(n) {} + + // operators + + vector3d operator-() const { return vector3d(-X, -Y, -Z); } + + vector3d operator+(const vector3d &other) const { return vector3d(X + other.X, Y + other.Y, Z + other.Z); } + vector3d &operator+=(const vector3d &other) + { + X += other.X; + Y += other.Y; + Z += other.Z; + return *this; + } + vector3d operator+(const T val) const { return vector3d(X + val, Y + val, Z + val); } + vector3d &operator+=(const T val) + { + X += val; + Y += val; + Z += val; + return *this; + } + + vector3d operator-(const vector3d &other) const { return vector3d(X - other.X, Y - other.Y, Z - other.Z); } + vector3d &operator-=(const vector3d &other) + { + X -= other.X; + Y -= other.Y; + Z -= other.Z; + return *this; + } + vector3d operator-(const T val) const { return vector3d(X - val, Y - val, Z - val); } + vector3d &operator-=(const T val) + { + X -= val; + Y -= val; + Z -= val; + return *this; + } + + vector3d operator*(const vector3d &other) const { return vector3d(X * other.X, Y * other.Y, Z * other.Z); } + vector3d &operator*=(const vector3d &other) + { + X *= other.X; + Y *= other.Y; + Z *= other.Z; + return *this; + } + vector3d operator*(const T v) const { return vector3d(X * v, Y * v, Z * v); } + vector3d &operator*=(const T v) + { + X *= v; + Y *= v; + Z *= v; + return *this; + } + + vector3d operator/(const vector3d &other) const { return vector3d(X / other.X, Y / other.Y, Z / other.Z); } + vector3d &operator/=(const vector3d &other) + { + X /= other.X; + Y /= other.Y; + Z /= other.Z; + return *this; + } + vector3d operator/(const T v) const { return vector3d(X / v, Y / v, Z / v); } + vector3d &operator/=(const T v) + { + X /= v; + Y /= v; + Z /= v; + return *this; + } + + T &operator[](u32 index) + { + _IRR_DEBUG_BREAK_IF(index > 2) // access violation + + return *(&X + index); + } + + const T &operator[](u32 index) const + { + _IRR_DEBUG_BREAK_IF(index > 2) // access violation + + return *(&X + index); + } + + //! sort in order X, Y, Z. + constexpr bool operator<=(const vector3d &other) const + { + return !(*this > other); + } + + //! sort in order X, Y, Z. + constexpr bool operator>=(const vector3d &other) const + { + return !(*this < other); + } + + //! sort in order X, Y, Z. + constexpr bool operator<(const vector3d &other) const + { + return X < other.X || (X == other.X && Y < other.Y) || + (X == other.X && Y == other.Y && Z < other.Z); + } + + //! sort in order X, Y, Z. + constexpr bool operator>(const vector3d &other) const + { + return X > other.X || (X == other.X && Y > other.Y) || + (X == other.X && Y == other.Y && Z > other.Z); + } + + constexpr bool operator==(const vector3d &other) const + { + return X == other.X && Y == other.Y && Z == other.Z; + } + + constexpr bool operator!=(const vector3d &other) const + { + return !(*this == other); + } + + // functions + + //! Checks if this vector equals the other one. + /** Takes floating point rounding errors into account. + \param other Vector to compare with. + \return True if the two vector are (almost) equal, else false. */ + bool equals(const vector3d &other) const + { + return core::equals(X, other.X) && core::equals(Y, other.Y) && core::equals(Z, other.Z); + } + + vector3d &set(const T nx, const T ny, const T nz) + { + X = nx; + Y = ny; + Z = nz; + return *this; + } + vector3d &set(const vector3d &p) + { + X = p.X; + Y = p.Y; + Z = p.Z; + return *this; + } + + //! Get length of the vector. + T getLength() const { return core::squareroot(X * X + Y * Y + Z * Z); } + + //! Get squared length of the vector. + /** This is useful because it is much faster than getLength(). + \return Squared length of the vector. */ + T getLengthSQ() const { return X * X + Y * Y + Z * Z; } + + //! Get the dot product with another vector. + T dotProduct(const vector3d &other) const + { + return X * other.X + Y * other.Y + Z * other.Z; + } + + //! Get distance from another point. + /** Here, the vector is interpreted as point in 3 dimensional space. */ + T getDistanceFrom(const vector3d &other) const + { + return vector3d(X - other.X, Y - other.Y, Z - other.Z).getLength(); + } + + //! Returns squared distance from another point. + /** Here, the vector is interpreted as point in 3 dimensional space. */ + T getDistanceFromSQ(const vector3d &other) const + { + return vector3d(X - other.X, Y - other.Y, Z - other.Z).getLengthSQ(); + } + + //! Calculates the cross product with another vector. + /** \param p Vector to multiply with. + \return Cross product of this vector with p. */ + vector3d crossProduct(const vector3d &p) const + { + return vector3d(Y * p.Z - Z * p.Y, Z * p.X - X * p.Z, X * p.Y - Y * p.X); + } + + //! Returns if this vector interpreted as a point is on a line between two other points. + /** It is assumed that the point is on the line. + \param begin Beginning vector to compare between. + \param end Ending vector to compare between. + \return True if this vector is between begin and end, false if not. */ + bool isBetweenPoints(const vector3d &begin, const vector3d &end) const + { + const T f = (end - begin).getLengthSQ(); + return getDistanceFromSQ(begin) <= f && + getDistanceFromSQ(end) <= f; + } + + //! Normalizes the vector. + /** In case of the 0 vector the result is still 0, otherwise + the length of the vector will be 1. + \return Reference to this vector after normalization. */ + vector3d &normalize() + { + f64 length = X * X + Y * Y + Z * Z; + if (length == 0) // this check isn't an optimization but prevents getting NAN in the sqrt. + return *this; + length = core::reciprocal_squareroot(length); + + X = (T)(X * length); + Y = (T)(Y * length); + Z = (T)(Z * length); + return *this; + } + + //! Sets the length of the vector to a new value + vector3d &setLength(T newlength) + { + normalize(); + return (*this *= newlength); + } + + //! Inverts the vector. + vector3d &invert() + { + X *= -1; + Y *= -1; + Z *= -1; + return *this; + } + + //! Rotates the vector by a specified number of degrees around the Y axis and the specified center. + /** CAREFUL: For historical reasons rotateXZBy uses a right-handed rotation + (maybe to make it more similar to the 2D vector rotations which are counterclockwise). + To have this work the same way as rest of Irrlicht (nodes, matrices, other rotateBy functions) pass -1*degrees in here. + \param degrees Number of degrees to rotate around the Y axis. + \param center The center of the rotation. */ + void rotateXZBy(f64 degrees, const vector3d ¢er = vector3d()) + { + degrees *= DEGTORAD64; + f64 cs = cos(degrees); + f64 sn = sin(degrees); + X -= center.X; + Z -= center.Z; + set((T)(X * cs - Z * sn), Y, (T)(X * sn + Z * cs)); + X += center.X; + Z += center.Z; + } + + //! Rotates the vector by a specified number of degrees around the Z axis and the specified center. + /** \param degrees: Number of degrees to rotate around the Z axis. + \param center: The center of the rotation. */ + void rotateXYBy(f64 degrees, const vector3d ¢er = vector3d()) + { + degrees *= DEGTORAD64; + f64 cs = cos(degrees); + f64 sn = sin(degrees); + X -= center.X; + Y -= center.Y; + set((T)(X * cs - Y * sn), (T)(X * sn + Y * cs), Z); + X += center.X; + Y += center.Y; + } + + //! Rotates the vector by a specified number of degrees around the X axis and the specified center. + /** \param degrees: Number of degrees to rotate around the X axis. + \param center: The center of the rotation. */ + void rotateYZBy(f64 degrees, const vector3d ¢er = vector3d()) + { + degrees *= DEGTORAD64; + f64 cs = cos(degrees); + f64 sn = sin(degrees); + Z -= center.Z; + Y -= center.Y; + set(X, (T)(Y * cs - Z * sn), (T)(Y * sn + Z * cs)); + Z += center.Z; + Y += center.Y; + } + + //! Creates an interpolated vector between this vector and another vector. + /** \param other The other vector to interpolate with. + \param d Interpolation value between 0.0f (all the other vector) and 1.0f (all this vector). + Note that this is the opposite direction of interpolation to getInterpolated_quadratic() + \return An interpolated vector. This vector is not modified. */ + vector3d getInterpolated(const vector3d &other, f64 d) const + { + const f64 inv = 1.0 - d; + return vector3d((T)(other.X * inv + X * d), (T)(other.Y * inv + Y * d), (T)(other.Z * inv + Z * d)); + } + + //! Creates a quadratically interpolated vector between this and two other vectors. + /** \param v2 Second vector to interpolate with. + \param v3 Third vector to interpolate with (maximum at 1.0f) + \param d Interpolation value between 0.0f (all this vector) and 1.0f (all the 3rd vector). + Note that this is the opposite direction of interpolation to getInterpolated() and interpolate() + \return An interpolated vector. This vector is not modified. */ + vector3d getInterpolated_quadratic(const vector3d &v2, const vector3d &v3, f64 d) const + { + // this*(1-d)*(1-d) + 2 * v2 * (1-d) + v3 * d * d; + const f64 inv = (T)1.0 - d; + const f64 mul0 = inv * inv; + const f64 mul1 = (T)2.0 * d * inv; + const f64 mul2 = d * d; + + return vector3d((T)(X * mul0 + v2.X * mul1 + v3.X * mul2), + (T)(Y * mul0 + v2.Y * mul1 + v3.Y * mul2), + (T)(Z * mul0 + v2.Z * mul1 + v3.Z * mul2)); + } + + //! Sets this vector to the linearly interpolated vector between a and b. + /** \param a first vector to interpolate with, maximum at 1.0f + \param b second vector to interpolate with, maximum at 0.0f + \param d Interpolation value between 0.0f (all vector b) and 1.0f (all vector a) + Note that this is the opposite direction of interpolation to getInterpolated_quadratic() + */ + vector3d &interpolate(const vector3d &a, const vector3d &b, f64 d) + { + X = (T)((f64)b.X + ((a.X - b.X) * d)); + Y = (T)((f64)b.Y + ((a.Y - b.Y) * d)); + Z = (T)((f64)b.Z + ((a.Z - b.Z) * d)); + return *this; + } + + //! Get the rotations that would make a (0,0,1) direction vector point in the same direction as this direction vector. + /** Thanks to Arras on the Irrlicht forums for this method. This utility method is very useful for + orienting scene nodes towards specific targets. For example, if this vector represents the difference + between two scene nodes, then applying the result of getHorizontalAngle() to one scene node will point + it at the other one. + Example code: + // Where target and seeker are of type ISceneNode* + const vector3df toTarget(target->getAbsolutePosition() - seeker->getAbsolutePosition()); + const vector3df requiredRotation = toTarget.getHorizontalAngle(); + seeker->setRotation(requiredRotation); + + \return A rotation vector containing the X (pitch) and Y (raw) rotations (in degrees) that when applied to a + +Z (e.g. 0, 0, 1) direction vector would make it point in the same direction as this vector. The Z (roll) rotation + is always 0, since two Euler rotations are sufficient to point in any given direction. */ + vector3d getHorizontalAngle() const + { + vector3d angle; + + // tmp avoids some precision troubles on some compilers when working with T=s32 + f64 tmp = (atan2((f64)X, (f64)Z) * RADTODEG64); + angle.Y = (T)tmp; + + if (angle.Y < 0) + angle.Y += 360; + if (angle.Y >= 360) + angle.Y -= 360; + + const f64 z1 = core::squareroot(X * X + Z * Z); + + tmp = (atan2((f64)z1, (f64)Y) * RADTODEG64 - 90.0); + angle.X = (T)tmp; + + if (angle.X < 0) + angle.X += 360; + if (angle.X >= 360) + angle.X -= 360; + + return angle; + } + + //! Get the spherical coordinate angles + /** This returns Euler degrees for the point represented by + this vector. The calculation assumes the pole at (0,1,0) and + returns the angles in X and Y. + */ + vector3d getSphericalCoordinateAngles() const + { + vector3d angle; + const f64 length = X * X + Y * Y + Z * Z; + + if (length) { + if (X != 0) { + angle.Y = (T)(atan2((f64)Z, (f64)X) * RADTODEG64); + } else if (Z < 0) + angle.Y = 180; + + angle.X = (T)(acos(Y * core::reciprocal_squareroot(length)) * RADTODEG64); + } + return angle; + } + + //! Builds a direction vector from (this) rotation vector. + /** This vector is assumed to be a rotation vector composed of 3 Euler angle rotations, in degrees. + The implementation performs the same calculations as using a matrix to do the rotation. + + \param[in] forwards The direction representing "forwards" which will be rotated by this vector. + If you do not provide a direction, then the +Z axis (0, 0, 1) will be assumed to be forwards. + \return A direction vector calculated by rotating the forwards direction by the 3 Euler angles + (in degrees) represented by this vector. */ + vector3d rotationToDirection(const vector3d &forwards = vector3d(0, 0, 1)) const + { + const f64 cr = cos(core::DEGTORAD64 * X); + const f64 sr = sin(core::DEGTORAD64 * X); + const f64 cp = cos(core::DEGTORAD64 * Y); + const f64 sp = sin(core::DEGTORAD64 * Y); + const f64 cy = cos(core::DEGTORAD64 * Z); + const f64 sy = sin(core::DEGTORAD64 * Z); + + const f64 srsp = sr * sp; + const f64 crsp = cr * sp; + + const f64 pseudoMatrix[] = { + (cp * cy), (cp * sy), (-sp), + (srsp * cy - cr * sy), (srsp * sy + cr * cy), (sr * cp), + (crsp * cy + sr * sy), (crsp * sy - sr * cy), (cr * cp)}; + + return vector3d( + (T)(forwards.X * pseudoMatrix[0] + + forwards.Y * pseudoMatrix[3] + + forwards.Z * pseudoMatrix[6]), + (T)(forwards.X * pseudoMatrix[1] + + forwards.Y * pseudoMatrix[4] + + forwards.Z * pseudoMatrix[7]), + (T)(forwards.X * pseudoMatrix[2] + + forwards.Y * pseudoMatrix[5] + + forwards.Z * pseudoMatrix[8])); + } + + //! Fills an array of 4 values with the vector data (usually floats). + /** Useful for setting in shader constants for example. The fourth value + will always be 0. */ + void getAs4Values(T *array) const + { + array[0] = X; + array[1] = Y; + array[2] = Z; + array[3] = 0; + } + + //! Fills an array of 3 values with the vector data (usually floats). + /** Useful for setting in shader constants for example.*/ + void getAs3Values(T *array) const + { + array[0] = X; + array[1] = Y; + array[2] = Z; + } + + //! X coordinate of the vector + T X; + + //! Y coordinate of the vector + T Y; + + //! Z coordinate of the vector + T Z; +}; + +//! partial specialization for integer vectors +// Implementer note: inline keyword needed due to template specialization for s32. Otherwise put specialization into a .cpp +template <> +inline vector3d vector3d::operator/(s32 val) const +{ + return core::vector3d(X / val, Y / val, Z / val); +} +template <> +inline vector3d &vector3d::operator/=(s32 val) +{ + X /= val; + Y /= val; + Z /= val; + return *this; +} + +template <> +inline vector3d vector3d::getSphericalCoordinateAngles() const +{ + vector3d angle; + const f64 length = X * X + Y * Y + Z * Z; + + if (length) { + if (X != 0) { + angle.Y = round32((f32)(atan2((f64)Z, (f64)X) * RADTODEG64)); + } else if (Z < 0) + angle.Y = 180; + + angle.X = round32((f32)(acos(Y * core::reciprocal_squareroot(length)) * RADTODEG64)); + } + return angle; +} + +//! Typedef for a f32 3d vector. +typedef vector3d vector3df; + +//! Typedef for an integer 3d vector. +typedef vector3d vector3di; + +//! Function multiplying a scalar and a vector component-wise. +template +vector3d operator*(const S scalar, const vector3d &vector) +{ + return vector * scalar; +} + +} // end namespace core +} // end namespace irr + +namespace std +{ + +template +struct hash> +{ + size_t operator()(const irr::core::vector3d &vec) const + { + size_t h1 = hash()(vec.X); + size_t h2 = hash()(vec.Y); + size_t h3 = hash()(vec.Z); + return (h1 << (5 * sizeof(h1)) | h1 >> (3 * sizeof(h1))) ^ (h2 << (2 * sizeof(h2)) | h2 >> (6 * sizeof(h2))) ^ h3; + } +}; + +} diff --git a/irr/media/Shaders/OneTextureBlend.fsh b/irr/media/Shaders/OneTextureBlend.fsh new file mode 100644 index 000000000..7ecb7e1a2 --- /dev/null +++ b/irr/media/Shaders/OneTextureBlend.fsh @@ -0,0 +1,75 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uBlendType; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color0 = vVertexColor; + vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); + + if (bool(uTextureUsage0)) + Color1 = texture2D(uTextureUnit0, vTextureCoord0); + + vec4 FinalColor = Color0 * Color1; + + if (uBlendType == 1) + { + FinalColor.w = Color0.w; + } + else if (uBlendType == 2) + { + FinalColor.w = Color1.w; + } + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + FinalColor = mix(FogColor, FinalColor, FogFactor); + } + + gl_FragColor = FinalColor; +} diff --git a/irr/media/Shaders/Renderer2D.fsh b/irr/media/Shaders/Renderer2D.fsh new file mode 100644 index 000000000..89aef7e59 --- /dev/null +++ b/irr/media/Shaders/Renderer2D.fsh @@ -0,0 +1,23 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage; +uniform sampler2D uTextureUnit; + +/* Varyings */ + +varying vec2 vTextureCoord; +varying vec4 vVertexColor; + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage)) + Color *= texture2D(uTextureUnit, vTextureCoord); + + gl_FragColor = Color; +} diff --git a/irr/media/Shaders/Renderer2D.vsh b/irr/media/Shaders/Renderer2D.vsh new file mode 100644 index 000000000..914214895 --- /dev/null +++ b/irr/media/Shaders/Renderer2D.vsh @@ -0,0 +1,24 @@ +#version 100 + +/* Attributes */ + +attribute vec4 inVertexPosition; +attribute vec4 inVertexColor; +attribute vec2 inTexCoord0; + +/* Uniforms */ + +uniform float uThickness; + +/* Varyings */ + +varying vec2 vTextureCoord; +varying vec4 vVertexColor; + +void main() +{ + gl_Position = inVertexPosition; + gl_PointSize = uThickness; + vTextureCoord = inTexCoord0; + vVertexColor = inVertexColor.bgra; +} diff --git a/irr/media/Shaders/Renderer2D_noTex.fsh b/irr/media/Shaders/Renderer2D_noTex.fsh new file mode 100644 index 000000000..600097232 --- /dev/null +++ b/irr/media/Shaders/Renderer2D_noTex.fsh @@ -0,0 +1,11 @@ +#version 100 + +precision mediump float; + +/* Varyings */ +varying vec4 vVertexColor; + +void main() +{ + gl_FragColor = vVertexColor; +} diff --git a/irr/media/Shaders/Solid.fsh b/irr/media/Shaders/Solid.fsh new file mode 100644 index 000000000..c85c6baf1 --- /dev/null +++ b/irr/media/Shaders/Solid.fsh @@ -0,0 +1,62 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + Color *= texture2D(uTextureUnit0, vTextureCoord0); + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/irr/media/Shaders/Solid.vsh b/irr/media/Shaders/Solid.vsh new file mode 100644 index 000000000..7379e5bb4 --- /dev/null +++ b/irr/media/Shaders/Solid.vsh @@ -0,0 +1,38 @@ +#version 100 + +/* Attributes */ + +attribute vec3 inVertexPosition; +attribute vec3 inVertexNormal; +attribute vec4 inVertexColor; +attribute vec2 inTexCoord0; + +/* Uniforms */ + +uniform mat4 uWVPMatrix; +uniform mat4 uWVMatrix; +uniform mat4 uNMatrix; +uniform mat4 uTMatrix0; + +uniform float uThickness; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying float vFogCoord; + +void main() +{ + gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); + gl_PointSize = uThickness; + + vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0); + vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy; + + vVertexColor = inVertexColor.bgra; + + vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; + + vFogCoord = length(Position); +} diff --git a/irr/media/Shaders/TransparentAlphaChannel.fsh b/irr/media/Shaders/TransparentAlphaChannel.fsh new file mode 100644 index 000000000..8491068aa --- /dev/null +++ b/irr/media/Shaders/TransparentAlphaChannel.fsh @@ -0,0 +1,69 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform float uAlphaRef; +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + { + Color *= texture2D(uTextureUnit0, vTextureCoord0); + + // TODO: uAlphaRef should rather control sharpness of alpha, don't know how to do that right now and this works in most cases. + if (Color.a < uAlphaRef) + discard; + } + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/irr/media/Shaders/TransparentAlphaChannelRef.fsh b/irr/media/Shaders/TransparentAlphaChannelRef.fsh new file mode 100644 index 000000000..ac762f0c2 --- /dev/null +++ b/irr/media/Shaders/TransparentAlphaChannelRef.fsh @@ -0,0 +1,66 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform float uAlphaRef; +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + Color *= texture2D(uTextureUnit0, vTextureCoord0); + + if (Color.a < uAlphaRef) + discard; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/irr/media/Shaders/TransparentVertexAlpha.fsh b/irr/media/Shaders/TransparentVertexAlpha.fsh new file mode 100644 index 000000000..c85c6baf1 --- /dev/null +++ b/irr/media/Shaders/TransparentVertexAlpha.fsh @@ -0,0 +1,62 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + Color *= texture2D(uTextureUnit0, vTextureCoord0); + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/irr/media/coolguy_opt.x b/irr/media/coolguy_opt.x new file mode 100755 index 000000000..e806d8315 --- /dev/null +++ b/irr/media/coolguy_opt.x @@ -0,0 +1,2 @@ +xof 0303txt 0032 +AnimationSet{Animation{{Armature}AnimationKey{0;2;0;4;1,0,0,0;;,29;4;1,0,0,0;;;}AnimationKey{2;2;0;3;0,0,0;;,29;3;0,0,0;;;}}Animation{{Armature_knee_r}AnimationKey{0;16;0;4;0.864183,0.503177,0,0;;,1;4;0.829812,0.558043,0,0;;,3;4;0.708698,0.705512,0,0;;,5;4;0.589108,0.808054,0,0;;,7;4;0.593659,0.804717,0,0;;,9;4;0.748627,0.662991,0,0;;,11;4;0.910305,0.413938,0,0;;,13;4;0.975925,0.218107,0,0;;,15;4;0.981302,0.192476,0,0;;,17;4;0.975476,0.220108,0,0;;,19;4;0.963662,0.267124,0,0;;,21;4;0.945893,0.324478,0,0;;,23;4;0.923816,0.382838,0,0;;,25;4;0.901205,0.433394,0,0;;,27;4;0.883429,0.468566,0,0;;,29;4;0.876305,0.481757,0,0;;;}AnimationKey{2;2;0;3;0,0,1.10139;;,29;3;0,0,1.10139;;;}}Animation{{Armature_elbow_r}AnimationKey{0;16;0;4;0.756295,0.004619,-0.619265,0.210967;;,1;4;0.771977,0.005599,-0.60257,0.202311;;,3;4;0.825501,0.009164,-0.538259,0.169533;;,5;4;0.891859,0.014253,-0.436142,0.119019;;,7;4;0.949154,0.019821,-0.308768,0.058108;;,9;4;0.983251,0.024703,-0.18057,-0.001258;;,11;4;0.995416,0.028143,-0.07812,-0.047458;;,13;4;0.996672,0.02991,-0.020368,-0.073041;;,15;4;0.996672,0.02991,-0.020368,-0.073041;;,17;4;0.995416,0.028143,-0.07812,-0.047458;;,19;4;0.983251,0.024703,-0.18057,-0.001258;;,21;4;0.949154,0.019821,-0.308768,0.058108;;,23;4;0.891859,0.014253,-0.436142,0.119019;;,25;4;0.825501,0.009164,-0.538259,0.169533;;,27;4;0.771977,0.005599,-0.60257,0.202311;;,29;4;0.750682,0.004275,-0.625038,0.213976;;;}AnimationKey{2;2;0;3;0,0,0.754892;;,29;3;0,0,0.754892;;;}}Animation{{Armature_arm_r}AnimationKey{0;16;0;4;0.28219,0.629905,0.723388,-0.017285;;,1;4;0.277641,0.632543,0.722699,-0.022614;;,3;4;0.261375,0.641615,0.719924,-0.041507;;,5;4;0.238321,0.653533,0.715186,-0.067874;;,7;4;0.212026,0.665838,0.708676,-0.097381;;,9;4;0.186345,0.676585,0.701229,-0.125643;;,11;4;0.165298,0.684491,0.694351,-0.14841;;,13;4;0.152894,0.688778,0.68998,-0.161665;;,15;4;0.152894,0.688779,0.68998,-0.161665;;,17;4;0.165298,0.684491,0.694351,-0.14841;;,19;4;0.186345,0.676585,0.701229,-0.125643;;,21;4;0.212026,0.665838,0.708676,-0.097381;;,23;4;0.238321,0.653533,0.715186,-0.067874;;,25;4;0.261375,0.641615,0.719924,-0.041507;;,27;4;0.277641,0.632543,0.722699,-0.022614;;,29;4;0.283802,0.628959,0.723623,-0.015394;;;}AnimationKey{2;2;0;3;-0.545315,0,1;;,29;3;-0.545315,0,1;;;}}Animation{{Armature_knee_l}AnimationKey{0;16;0;4;0.981896,0.189423,0,0;;,1;4;0.9814,0.191974,0,0;;,3;4;0.979127,0.203251,0,0;;,5;4;0.974526,0.224276,0,0;;,7;4;0.96645,0.256853,0,0;;,9;4;0.953088,0.302692,0,0;;,11;4;0.931731,0.36315,0,0;;,13;4;0.898645,0.438676,0,0;;,15;4;0.848226,0.529634,0,0;;,17;4;0.773692,0.633562,0,0;;,19;4;0.689831,0.72397,0,0;;,21;4;0.629304,0.777159,0,0;;,23;4;0.648685,0.761057,0,0;;,25;4;0.812268,0.583284,0,0;;,27;4;0.948066,0.318074,0,0;;,29;4;0.982049,0.188624,0,0;;;}AnimationKey{2;2;0;3;0,0,1.10139;;,29;3;0,0,1.10139;;;}}Animation{{Armature_Bone_007}AnimationKey{0;16;0;4;0.993671,-0.112331,0,0;;,1;4;0.994784,-0.102002,0,0;;,3;4;0.997507,-0.070564,0,0;;,5;4;0.999237,-0.039056,0,0;;,7;4;0.999694,-0.024737,0,0;;,9;4;0.999079,-0.042907,0,0;;,11;4;0.99677,-0.080308,0,0;;,13;4;0.993798,-0.111199,0,0;;,15;4;0.993599,-0.112965,0,0;;,17;4;0.995813,-0.091409,0,0;;,19;4;0.998181,-0.060285,0,0;;,21;4;0.999479,-0.032286,0,0;;,23;4;0.999797,-0.020142,0,0;;,25;4;0.998983,-0.045097,0,0;;,27;4;0.995813,-0.091409,0,0;;,29;4;0.993221,-0.116243,0,0;;;}AnimationKey{2;2;0;3;0,0,1.221802;;,29;3;0,0,1.221802;;;}}Animation{{Armature_elbow_l}AnimationKey{0;16;0;4;0.995195,-0.034868,-0.015799,-0.090119;;,1;4;0.993465,-0.046368,-0.030155,-0.099838;;,3;4;0.983557,-0.0879,-0.082099,-0.134715;;,5;4;0.959324,-0.146904,-0.156177,-0.183648;;,7;4;0.917546,-0.212233,-0.238611,-0.236921;;,9;4;0.864109,-0.271657,-0.314022,-0.284443;;,11;4;0.813172,-0.315829,-0.370387,-0.319087;;,13;4;0.781004,-0.339668,-0.400938,-0.337501;;,15;4;0.781004,-0.339668,-0.400938,-0.337501;;,17;4;0.813172,-0.315829,-0.370387,-0.319087;;,19;4;0.864109,-0.271657,-0.314022,-0.284443;;,21;4;0.917546,-0.212233,-0.238611,-0.236921;;,23;4;0.959324,-0.146904,-0.156177,-0.183648;;,25;4;0.983557,-0.0879,-0.082099,-0.134715;;,27;4;0.993465,-0.046368,-0.030155,-0.099838;;,29;4;0.995701,-0.030812,-0.010739,-0.086685;;;}AnimationKey{2;2;0;3;0,0,0.754892;;,29;3;0,0,0.754892;;;}}Animation{{Armature_body}AnimationKey{0;16;0;4;-0,0,0.601298,0.799025;;,1;4;-0,0,0.608144,0.793827;;,3;4;-0,0,0.627465,0.778645;;,5;4;-0,0,0.643183,0.765712;;,7;4;-0,0,0.643755,0.765231;;,9;4;-0,0,0.631076,0.775721;;,11;4;-0,0,0.613775,0.789481;;,13;4;-0,0,0.6007,0.799474;;,15;4;-0,0,0.601488,0.798882;;,17;4;-0,0,0.619499,0.784997;;,19;4;-0,0,0.643196,0.765702;;,21;4;-0,0,0.660441,0.750878;;,23;4;-0,0,0.659666,0.751559;;,25;4;-0,0,0.638264,0.769817;;,27;4;-0,0,0.611752,0.791049;;,29;4;-0,0,0.598631,0.801025;;;}AnimationKey{2;2;0;3;0,2.580534,0;;,29;3;0,2.571201,0;;;}}Animation{{Armature_leg_l}AnimationKey{0;16;0;4;0.390287,0.920693,0,0;;,1;4;0.362565,0.931959,0,0;;,3;4;0.266163,0.963928,0,0;;,5;4;0.138294,0.990391,0,0;;,7;4;0.012725,0.999919,0,0;;,9;4;-0.090194,0.995924,0,0;;,11;4;-0.162502,0.986708,0,0;;,13;4;-0.201466,0.979496,0,0;;,15;4;-0.185641,0.982618,0,0;;,17;4;-0.013697,0.999906,0,0;;,19;4;0.24238,0.970181,0,0;;,21;4;0.417271,0.908782,0,0;;,23;4;0.439308,0.898336,0,0;;,25;4;0.424255,0.905543,0,0;;,27;4;0.407664,0.913132,0,0;;,29;4;0.400263,0.9164,0,0;;;}AnimationKey{2;2;0;3;0.246294,0,-0.171352;;,29;3;0.246294,0,-0.171351;;;}}Animation{{Armature_leg_r}AnimationKey{0;16;0;4;0.174933,-0.98458,0,0;;,1;4;0.082829,-0.996564,0,0;;,3;4;-0.21147,-0.977384,0,0;;,5;4;-0.442802,-0.89662,0,0;;,7;4;-0.47604,-0.879424,0,0;;,9;4;-0.47279,-0.881175,0,0;;,11;4;-0.459567,-0.888143,0,0;;,13;4;-0.427425,-0.904051,0,0;;,15;4;-0.361724,-0.932285,0,0;;,17;4;-0.251362,-0.967893,0,0;;,19;4;-0.114531,-0.99342,0,0;;,21;4;0.021053,-0.999778,0,0;;,23;4;0.12473,-0.992191,0,0;;,25;4;0.181473,-0.983396,0,0;;,27;4;0.204037,-0.978963,0,0;;,29;4;0.208187,-0.978089,0,0;;;}AnimationKey{2;2;0;3;-0.246294,0,-0.171352;;,29;3;-0.246294,0,-0.171351;;;}}Animation{{Armature_arm_l}AnimationKey{0;16;0;4;0.200754,-0.659656,-0.716264,-0.107316;;,1;4;0.192268,-0.660735,-0.716526,-0.114246;;,3;4;0.161871,-0.663925,-0.716753,-0.138802;;,5;4;0.118745,-0.666682,-0.715211,-0.17294;;,7;4;0.069733,-0.667364,-0.710872,-0.210767;;,9;4;0.022313,-0.665594,-0.704111,-0.246404;;,11;4;-0.016046,-0.662426,-0.696821,-0.274543;;,13;4;-0.038374,-0.659874,-0.691824,-0.290643;;,15;4;-0.038373,-0.659874,-0.691824,-0.290643;;,17;4;-0.016044,-0.662427,-0.696822,-0.274543;;,19;4;0.022312,-0.665594,-0.70411,-0.246404;;,21;4;0.069733,-0.667365,-0.710872,-0.210767;;,23;4;0.118745,-0.666682,-0.715211,-0.17294;;,25;4;0.161871,-0.663925,-0.716753,-0.138802;;,27;4;0.192268,-0.660735,-0.716526,-0.114246;;,29;4;0.203757,-0.659255,-0.716151,-0.104856;;;}AnimationKey{2;2;0;3;0.545315,0,1;;,29;3;0.545315,0,1;;;}}}Frame Root{FrameTransformMatrix{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1;;}Frame Armature{FrameTransformMatrix{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1;;}Frame Armature_body{FrameTransformMatrix{-1,0,0,0,0,0,1,0,0,1,0,0,0,2.571201,0,1;;}Frame Armature_arm_r{FrameTransformMatrix{-0.047733,0.997488,-0.05233,0,0.901521,0.020464,-0.432251,0,-0.430095,-0.067809,-0.900233,0,-0.545315,0,1,1;;}Frame Armature_elbow_r{FrameTransformMatrix{0.987983,0.151721,-0.029519,0,-0.153228,0.986478,-0.058162,0,0.020295,0.061987,0.997871,0,0,0,0.754892,1;;}}}Frame Armature_arm_l{FrameTransformMatrix{-0.047732,0.994072,-0.097683,0,0.901521,0.084983,0.424309,0,0.430095,-0.067809,-0.900233,0,0.545315,0,1,1;;}Frame Armature_elbow_l{FrameTransformMatrix{0.984741,0.173286,-0.016044,0,-0.171963,0.983073,0.063221,0,0.026727,-0.059497,0.99787,0,0,0,0.754892,1;;}}}Frame Armature_leg_l{FrameTransformMatrix{1,0,0,0,0,-0.998426,-0.056453,0,0,0.056453,-0.998405,0,0.246294,0,-0.171351,1;;}Frame Armature_knee_l{FrameTransformMatrix{1,0,0,0,0,0.993861,-0.110639,0,0,0.110639,0.993861,0,0,0,1.10139,1;;}}}Frame Armature_leg_r{FrameTransformMatrix{1,0,0,0,0,-0.998426,-0.056453,0,0,0.056453,-0.998405,0,-0.246294,0,-0.171351,1;;}Frame Armature_knee_r{FrameTransformMatrix{1,0,0,0,0,0.993861,-0.110639,0,0,0.110639,0.993861,0,0,0,1.10139,1;;}}}Frame Armature_Bone_007{FrameTransformMatrix{1,0,0,0,0,1,0,0,0,0,1,0,0,0,1.221802,1;;}}}Frame cool_dude{FrameTransformMatrix{-1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,1;;}Mesh{272;0;2.440814;0.219926;,0;3.688199;0.219926;,0.466212;3.688199;0.219926;,0.466212;2.440814;0.219926;,0.466212;2.440814;0.219926;,0.466212;3.688199;0.219926;,0.466212;3.688199;-0.219926;,0.466212;2.440814;-0.219926;,0;2.440814;0.219926;,0.466212;2.440814;0.219926;,0.466212;2.440814;-0.219926;,0;2.440814;-0.219926;,0.055633;1.27575;-0.190081;,0.055633;2.35741;-0.190081;,0.055633;2.35741;0.190081;,0.055633;1.27575;0.190081;,0.055633;1.27575;0.190081;,0.055633;2.35741;0.190081;,0.43017;2.35741;0.190081;,0.43017;1.27575;0.190081;,0.43017;1.27575;0.190081;,0.43017;2.35741;0.190081;,0.43017;2.35741;-0.190081;,0.43017;1.27575;-0.190081;,0.43017;1.27575;-0.190081;,0.43017;2.35741;-0.190081;,0.055633;2.35741;-0.190081;,0.055633;1.27575;-0.190081;,0.055633;1.27575;0.190081;,0.43017;1.27575;0.190081;,0.43017;1.27575;-0.190081;,0.055633;1.27575;-0.190081;,0.43017;2.35741;0.190081;,0.055633;2.35741;0.190081;,0.055633;2.35741;-0.190081;,0.43017;2.35741;-0.190081;,0.466212;3.688199;0.219926;,0;3.688199;0.219926;,0;3.688199;-0.219926;,0.466212;3.688199;-0.219926;,0.466212;2.440814;-0.219926;,0.466212;3.688199;-0.219926;,0;3.688199;-0.219926;,0;2.440814;-0.219926;,0.769341;2.834949;-0.041122;,0.440953;3.555781;-0.041122;,0.440953;3.555781;0.207294;,0.769341;2.834949;0.207294;,0.769341;2.834949;0.207294;,0.440953;3.555781;0.207294;,0.616273;3.635651;0.207294;,0.944661;2.914819;0.207294;,0.944661;2.914819;0.207294;,0.616273;3.635651;0.207294;,0.616273;3.635651;-0.041122;,0.944661;2.914819;-0.041122;,0.944661;2.914819;-0.041122;,0.616273;3.635651;-0.041122;,0.440953;3.555781;-0.041122;,0.769341;2.834949;-0.041122;,0.769341;2.834949;0.207294;,0.944661;2.914819;0.207294;,0.944661;2.914819;-0.041122;,0.769341;2.834949;-0.041122;,0.616273;3.635651;0.207294;,0.440953;3.555781;0.207294;,0.440953;3.555781;-0.041122;,0.616273;3.635651;-0.041122;,1.104504;2.080977;-0.086788;,0.776116;2.801809;-0.086788;,0.776116;2.801809;0.161627;,1.104504;2.080977;0.161627;,1.104504;2.080977;0.161627;,0.776116;2.801809;0.161627;,0.951436;2.881679;0.161627;,1.279824;2.160847;0.161627;,1.279824;2.160847;0.161627;,0.951436;2.881679;0.161627;,0.951436;2.881679;-0.086788;,1.279824;2.160847;-0.086788;,1.279824;2.160847;-0.086788;,0.951436;2.881679;-0.086788;,0.776116;2.801809;-0.086788;,1.104504;2.080977;-0.086788;,1.104504;2.080977;0.161627;,1.279824;2.160847;0.161627;,1.279824;2.160847;-0.086788;,1.104504;2.080977;-0.086788;,0.951436;2.881679;0.161627;,0.776116;2.801809;0.161627;,0.776116;2.801809;-0.086788;,0.951436;2.881679;-0.086788;,0.055633;0.093601;-0.190081;,0.055633;1.205294;-0.190081;,0.055633;1.205294;0.190081;,0.055633;0.093601;0.190081;,0.055633;0.093601;0.190081;,0.055633;1.205294;0.190081;,0.43017;1.205294;0.190081;,0.43017;0.093601;0.190081;,0.43017;0.093601;0.190081;,0.43017;1.205294;0.190081;,0.43017;1.205294;-0.190081;,0.43017;0.093601;-0.190081;,0.43017;0.093601;-0.190081;,0.43017;1.205294;-0.190081;,0.055633;1.205294;-0.190081;,0.055633;0.093601;-0.190081;,0.055633;0.093601;0.190081;,0.43017;0.093601;0.190081;,0.43017;0.093601;-0.190081;,0.055633;0.093601;-0.190081;,0.43017;1.205294;0.190081;,0.055633;1.205294;0.190081;,0.055633;1.205294;-0.190081;,0.43017;1.205294;-0.190081;,0;3.790919;0.428464;,0;4.579204;0.428464;,0.43344;4.560537;0.409797;,0.43344;3.809586;0.409797;,0.43344;3.809586;0.409797;,0.43344;4.560537;0.409797;,0.43344;4.560537;-0.284975;,0.43344;3.809586;-0.284975;,0;3.790919;0.428464;,0.43344;3.809586;0.409797;,0.43344;3.809586;-0.284975;,0;3.790919;-0.303642;,0.43344;4.560537;0.409797;,0;4.579204;0.428464;,0;4.579204;-0.303642;,0.43344;4.560537;-0.284975;,0.43344;3.809586;-0.284975;,0.43344;4.560537;-0.284975;,0;4.579204;-0.303642;,0;3.790919;-0.303642;,0;2.440814;0.219926;,-0.466212;2.440814;0.219926;,-0.466212;3.688199;0.219926;,0;3.688199;0.219926;,-0.466212;2.440814;0.219926;,-0.466212;2.440814;-0.219926;,-0.466212;3.688199;-0.219926;,-0.466212;3.688199;0.219926;,0;2.440814;0.219926;,0;2.440814;-0.219926;,-0.466212;2.440814;-0.219926;,-0.466212;2.440814;0.219926;,-0.055633;1.27575;-0.190081;,-0.055633;1.27575;0.190081;,-0.055633;2.35741;0.190081;,-0.055633;2.35741;-0.190081;,-0.055633;1.27575;0.190081;,-0.43017;1.27575;0.190081;,-0.43017;2.35741;0.190081;,-0.055633;2.35741;0.190081;,-0.43017;1.27575;0.190081;,-0.43017;1.27575;-0.190081;,-0.43017;2.35741;-0.190081;,-0.43017;2.35741;0.190081;,-0.43017;1.27575;-0.190081;,-0.055633;1.27575;-0.190081;,-0.055633;2.35741;-0.190081;,-0.43017;2.35741;-0.190081;,-0.055633;1.27575;0.190081;,-0.055633;1.27575;-0.190081;,-0.43017;1.27575;-0.190081;,-0.43017;1.27575;0.190081;,-0.43017;2.35741;0.190081;,-0.43017;2.35741;-0.190081;,-0.055633;2.35741;-0.190081;,-0.055633;2.35741;0.190081;,-0.466212;3.688199;0.219926;,-0.466212;3.688199;-0.219926;,0;3.688199;-0.219926;,0;3.688199;0.219926;,-0.466212;2.440814;-0.219926;,0;2.440814;-0.219926;,0;3.688199;-0.219926;,-0.466212;3.688199;-0.219926;,-0.769341;2.834949;-0.041122;,-0.769341;2.834949;0.207294;,-0.440953;3.555781;0.207294;,-0.440953;3.555781;-0.041122;,-0.769341;2.834949;0.207294;,-0.944661;2.914819;0.207294;,-0.616273;3.635651;0.207294;,-0.440953;3.555781;0.207294;,-0.944661;2.914819;0.207294;,-0.944661;2.914819;-0.041122;,-0.616273;3.635651;-0.041122;,-0.616273;3.635651;0.207294;,-0.944661;2.914819;-0.041122;,-0.769341;2.834949;-0.041122;,-0.440953;3.555781;-0.041122;,-0.616273;3.635651;-0.041122;,-0.769341;2.834949;0.207294;,-0.769341;2.834949;-0.041122;,-0.944661;2.914819;-0.041122;,-0.944661;2.914819;0.207294;,-0.616273;3.635651;0.207294;,-0.616273;3.635651;-0.041122;,-0.440953;3.555781;-0.041122;,-0.440953;3.555781;0.207294;,-1.104504;2.080977;-0.086788;,-1.104504;2.080977;0.161627;,-0.776116;2.801809;0.161627;,-0.776116;2.801809;-0.086788;,-1.104504;2.080977;0.161627;,-1.279824;2.160847;0.161627;,-0.951436;2.881679;0.161627;,-0.776116;2.801809;0.161627;,-1.279824;2.160847;0.161627;,-1.279824;2.160847;-0.086788;,-0.951436;2.881679;-0.086788;,-0.951436;2.881679;0.161627;,-1.279824;2.160847;-0.086788;,-1.104504;2.080977;-0.086788;,-0.776116;2.801809;-0.086788;,-0.951436;2.881679;-0.086788;,-1.104504;2.080977;0.161627;,-1.104504;2.080977;-0.086788;,-1.279824;2.160847;-0.086788;,-1.279824;2.160847;0.161627;,-0.951436;2.881679;0.161627;,-0.951436;2.881679;-0.086788;,-0.776116;2.801809;-0.086788;,-0.776116;2.801809;0.161627;,-0.055633;0.093601;-0.190081;,-0.055633;0.093601;0.190081;,-0.055633;1.205294;0.190081;,-0.055633;1.205294;-0.190081;,-0.055633;0.093601;0.190081;,-0.43017;0.093601;0.190081;,-0.43017;1.205294;0.190081;,-0.055633;1.205294;0.190081;,-0.43017;0.093601;0.190081;,-0.43017;0.093601;-0.190081;,-0.43017;1.205294;-0.190081;,-0.43017;1.205294;0.190081;,-0.43017;0.093601;-0.190081;,-0.055633;0.093601;-0.190081;,-0.055633;1.205294;-0.190081;,-0.43017;1.205294;-0.190081;,-0.055633;0.093601;0.190081;,-0.055633;0.093601;-0.190081;,-0.43017;0.093601;-0.190081;,-0.43017;0.093601;0.190081;,-0.43017;1.205294;0.190081;,-0.43017;1.205294;-0.190081;,-0.055633;1.205294;-0.190081;,-0.055633;1.205294;0.190081;,0;3.790919;0.428464;,-0.43344;3.809586;0.409797;,-0.43344;4.560537;0.409797;,0;4.579204;0.428464;,-0.43344;3.809586;0.409797;,-0.43344;3.809586;-0.284975;,-0.43344;4.560537;-0.284975;,-0.43344;4.560537;0.409797;,0;3.790919;0.428464;,0;3.790919;-0.303642;,-0.43344;3.809586;-0.284975;,-0.43344;3.809586;0.409797;,-0.43344;4.560537;0.409797;,-0.43344;4.560537;-0.284975;,0;4.579204;-0.303642;,0;4.579204;0.428464;,-0.43344;3.809586;-0.284975;,0;3.790919;-0.303642;,0;4.579204;-0.303642;,-0.43344;4.560537;-0.284975;;68;4;3,2,1,0;,4;7,6,5,4;,4;11,10,9,8;,4;15,14,13,12;,4;19,18,17,16;,4;23,22,21,20;,4;27,26,25,24;,4;31,30,29,28;,4;35,34,33,32;,4;39,38,37,36;,4;43,42,41,40;,4;47,46,45,44;,4;51,50,49,48;,4;55,54,53,52;,4;59,58,57,56;,4;63,62,61,60;,4;67,66,65,64;,4;71,70,69,68;,4;75,74,73,72;,4;79,78,77,76;,4;83,82,81,80;,4;87,86,85,84;,4;91,90,89,88;,4;95,94,93,92;,4;99,98,97,96;,4;103,102,101,100;,4;107,106,105,104;,4;111,110,109,108;,4;115,114,113,112;,4;119,118,117,116;,4;123,122,121,120;,4;127,126,125,124;,4;131,130,129,128;,4;135,134,133,132;,4;139,138,137,136;,4;143,142,141,140;,4;147,146,145,144;,4;151,150,149,148;,4;155,154,153,152;,4;159,158,157,156;,4;163,162,161,160;,4;167,166,165,164;,4;171,170,169,168;,4;175,174,173,172;,4;179,178,177,176;,4;183,182,181,180;,4;187,186,185,184;,4;191,190,189,188;,4;195,194,193,192;,4;199,198,197,196;,4;203,202,201,200;,4;207,206,205,204;,4;211,210,209,208;,4;215,214,213,212;,4;219,218,217,216;,4;223,222,221,220;,4;227,226,225,224;,4;231,230,229,228;,4;235,234,233,232;,4;239,238,237,236;,4;243,242,241,240;,4;247,246,245,244;,4;251,250,249,248;,4;255,254,253,252;,4;259,258,257,256;,4;263,262,261,260;,4;267,266,265,264;,4;271,270,269,268;;MeshNormals{272;0;-0.707083;0.707083;,0;0.707083;0.707083;,0.577349;0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;0.577349;0.577349;,0.577349;0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0;-0.707083;0.707083;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;-0.577349;,0;-0.707083;-0.707083;,-0.577349;-0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,-0.577349;0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;0.577349;0.577349;,0.577349;0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;0.577349;0.577349;,0.577349;0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0.577349;0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;-0.577349;,0.577349;0.577349;0.577349;,-0.577349;0.577349;0.577349;,-0.577349;0.577349;-0.577349;,0.577349;0.577349;-0.577349;,0.577349;0.577349;0.577349;,0;0.707083;0.707083;,0;0.707083;-0.707083;,0.577349;0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0.577349;0.577349;-0.577349;,0;0.707083;-0.707083;,0;-0.707083;-0.707083;,-0.286019;-0.764733;-0.577349;,-0.764733;0.286019;-0.577349;,-0.764733;0.286019;0.577349;,-0.286019;-0.764733;0.577349;,-0.286019;-0.764733;0.577349;,-0.764733;0.286019;0.577349;,0.286019;0.764733;0.577349;,0.764733;-0.286019;0.577349;,0.764733;-0.286019;0.577349;,0.286019;0.764733;0.577349;,0.286019;0.764733;-0.577349;,0.764733;-0.286019;-0.577349;,0.764733;-0.286019;-0.577349;,0.286019;0.764733;-0.577349;,-0.764733;0.286019;-0.577349;,-0.286019;-0.764733;-0.577349;,-0.286019;-0.764733;0.577349;,0.764733;-0.286019;0.577349;,0.764733;-0.286019;-0.577349;,-0.286019;-0.764733;-0.577349;,0.286019;0.764733;0.577349;,-0.764733;0.286019;0.577349;,-0.764733;0.286019;-0.577349;,0.286019;0.764733;-0.577349;,-0.286019;-0.764733;-0.577349;,-0.764733;0.286019;-0.577349;,-0.764733;0.286019;0.577349;,-0.286019;-0.764733;0.577349;,-0.286019;-0.764733;0.577349;,-0.764733;0.286019;0.577349;,0.286019;0.764733;0.577349;,0.764733;-0.286019;0.577349;,0.764733;-0.286019;0.577349;,0.286019;0.764733;0.577349;,0.286019;0.764733;-0.577349;,0.764733;-0.286019;-0.577349;,0.764733;-0.286019;-0.577349;,0.286019;0.764733;-0.577349;,-0.764733;0.286019;-0.577349;,-0.286019;-0.764733;-0.577349;,-0.286019;-0.764733;0.577349;,0.764733;-0.286019;0.577349;,0.764733;-0.286019;-0.577349;,-0.286019;-0.764733;-0.577349;,0.286019;0.764733;0.577349;,-0.764733;0.286019;0.577349;,-0.764733;0.286019;-0.577349;,0.286019;0.764733;-0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,-0.577349;0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;0.577349;0.577349;,0.577349;0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;0.577349;0.577349;,0.577349;0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0.577349;0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;0.577349;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;-0.577349;,0.577349;0.577349;0.577349;,-0.577349;0.577349;0.577349;,-0.577349;0.577349;-0.577349;,0.577349;0.577349;-0.577349;,0;-0.707083;0.707083;,0;0.707083;0.707083;,0.599902;0.565722;0.565722;,0.599902;-0.565722;0.565722;,0.599902;-0.565722;0.565722;,0.599902;0.565722;0.565722;,0.599902;0.565722;-0.565722;,0.599902;-0.565722;-0.565722;,0;-0.707083;0.707083;,0.599902;-0.565722;0.565722;,0.599902;-0.565722;-0.565722;,0;-0.707083;-0.707083;,0.599902;0.565722;0.565722;,0;0.707083;0.707083;,0;0.707083;-0.707083;,0.599902;0.565722;-0.565722;,0.599902;-0.565722;-0.565722;,0.599902;0.565722;-0.565722;,0;0.707083;-0.707083;,0;-0.707083;-0.707083;,0;-0.707083;0.707083;,-0.577349;-0.577349;0.577349;,-0.577349;0.577349;0.577349;,0;0.707083;0.707083;,-0.577349;-0.577349;0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,-0.577349;0.577349;0.577349;,0;-0.707083;0.707083;,0;-0.707083;-0.707083;,-0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;0.577349;,0.577349;-0.577349;-0.577349;,0.577349;-0.577349;0.577349;,0.577349;0.577349;0.577349;,0.577349;0.577349;-0.577349;,0.577349;-0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;0.577349;0.577349;,0.577349;0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,-0.577349;0.577349;0.577349;,-0.577349;-0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0.577349;0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;0.577349;0.577349;,-0.577349;0.577349;-0.577349;,0.577349;0.577349;-0.577349;,0.577349;0.577349;0.577349;,-0.577349;0.577349;0.577349;,-0.577349;0.577349;-0.577349;,0;0.707083;-0.707083;,0;0.707083;0.707083;,-0.577349;-0.577349;-0.577349;,0;-0.707083;-0.707083;,0;0.707083;-0.707083;,-0.577349;0.577349;-0.577349;,0.286019;-0.764733;-0.577349;,0.286019;-0.764733;0.577349;,0.764733;0.286019;0.577349;,0.764733;0.286019;-0.577349;,0.286019;-0.764733;0.577349;,-0.764733;-0.286019;0.577349;,-0.286019;0.764733;0.577349;,0.764733;0.286019;0.577349;,-0.764733;-0.286019;0.577349;,-0.764733;-0.286019;-0.577349;,-0.286019;0.764733;-0.577349;,-0.286019;0.764733;0.577349;,-0.764733;-0.286019;-0.577349;,0.286019;-0.764733;-0.577349;,0.764733;0.286019;-0.577349;,-0.286019;0.764733;-0.577349;,0.286019;-0.764733;0.577349;,0.286019;-0.764733;-0.577349;,-0.764733;-0.286019;-0.577349;,-0.764733;-0.286019;0.577349;,-0.286019;0.764733;0.577349;,-0.286019;0.764733;-0.577349;,0.764733;0.286019;-0.577349;,0.764733;0.286019;0.577349;,0.286019;-0.764733;-0.577349;,0.286019;-0.764733;0.577349;,0.764733;0.286019;0.577349;,0.764733;0.286019;-0.577349;,0.286019;-0.764733;0.577349;,-0.764733;-0.286019;0.577349;,-0.286019;0.764733;0.577349;,0.764733;0.286019;0.577349;,-0.764733;-0.286019;0.577349;,-0.764733;-0.286019;-0.577349;,-0.286019;0.764733;-0.577349;,-0.286019;0.764733;0.577349;,-0.764733;-0.286019;-0.577349;,0.286019;-0.764733;-0.577349;,0.764733;0.286019;-0.577349;,-0.286019;0.764733;-0.577349;,0.286019;-0.764733;0.577349;,0.286019;-0.764733;-0.577349;,-0.764733;-0.286019;-0.577349;,-0.764733;-0.286019;0.577349;,-0.286019;0.764733;0.577349;,-0.286019;0.764733;-0.577349;,0.764733;0.286019;-0.577349;,0.764733;0.286019;0.577349;,0.577349;-0.577349;-0.577349;,0.577349;-0.577349;0.577349;,0.577349;0.577349;0.577349;,0.577349;0.577349;-0.577349;,0.577349;-0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;0.577349;0.577349;,0.577349;0.577349;0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,-0.577349;0.577349;0.577349;,-0.577349;-0.577349;-0.577349;,0.577349;-0.577349;-0.577349;,0.577349;0.577349;-0.577349;,-0.577349;0.577349;-0.577349;,0.577349;-0.577349;0.577349;,0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;-0.577349;,-0.577349;-0.577349;0.577349;,-0.577349;0.577349;0.577349;,-0.577349;0.577349;-0.577349;,0.577349;0.577349;-0.577349;,0.577349;0.577349;0.577349;,0;-0.707083;0.707083;,-0.599902;-0.565722;0.565722;,-0.599872;0.565722;0.565722;,0;0.707083;0.707083;,-0.599902;-0.565722;0.565722;,-0.599902;-0.565722;-0.565722;,-0.599872;0.565722;-0.565722;,-0.599872;0.565722;0.565722;,0;-0.707083;0.707083;,0;-0.707083;-0.707083;,-0.599902;-0.565722;-0.565722;,-0.599902;-0.565722;0.565722;,-0.599872;0.565722;0.565722;,-0.599872;0.565722;-0.565722;,0;0.707083;-0.707083;,0;0.707083;0.707083;,-0.599902;-0.565722;-0.565722;,0;-0.707083;-0.707083;,0;0.707083;-0.707083;,-0.599872;0.565722;-0.565722;;68;4;3,2,1,0;,4;7,6,5,4;,4;11,10,9,8;,4;15,14,13,12;,4;19,18,17,16;,4;23,22,21,20;,4;27,26,25,24;,4;31,30,29,28;,4;35,34,33,32;,4;39,38,37,36;,4;43,42,41,40;,4;47,46,45,44;,4;51,50,49,48;,4;55,54,53,52;,4;59,58,57,56;,4;63,62,61,60;,4;67,66,65,64;,4;71,70,69,68;,4;75,74,73,72;,4;79,78,77,76;,4;83,82,81,80;,4;87,86,85,84;,4;91,90,89,88;,4;95,94,93,92;,4;99,98,97,96;,4;103,102,101,100;,4;107,106,105,104;,4;111,110,109,108;,4;115,114,113,112;,4;119,118,117,116;,4;123,122,121,120;,4;127,126,125,124;,4;131,130,129,128;,4;135,134,133,132;,4;139,138,137,136;,4;143,142,141,140;,4;147,146,145,144;,4;151,150,149,148;,4;155,154,153,152;,4;159,158,157,156;,4;163,162,161,160;,4;167,166,165,164;,4;171,170,169,168;,4;175,174,173,172;,4;179,178,177,176;,4;183,182,181,180;,4;187,186,185,184;,4;191,190,189,188;,4;195,194,193,192;,4;199,198,197,196;,4;203,202,201,200;,4;207,206,205,204;,4;211,210,209,208;,4;215,214,213,212;,4;219,218,217,216;,4;223,222,221,220;,4;227,226,225,224;,4;231,230,229,228;,4;235,234,233,232;,4;239,238,237,236;,4;243,242,241,240;,4;247,246,245,244;,4;251,250,249,248;,4;255,254,253,252;,4;259,258,257,256;,4;263,262,261,260;,4;267,266,265,264;,4;271,270,269,268;;}MeshTextureCoords{272;0.849264;0.899246;,0.849264;0.931916;,0.861547;0.931916;,0.861547;0.899246;,0.916988;0.931916;,0.916988;0.899246;,0.9054;0.899246;,0.9054;0.931916;,0.84857;0.844707;,0.84857;0.83254;,0.836981;0.83254;,0.836981;0.844707;,0.927004;0.903587;,0.927004;0.931916;,0.937019;0.931916;,0.937019;0.903587;,0.937019;0.903587;,0.937019;0.931916;,0.946887;0.931916;,0.946887;0.903587;,0.888533;0.856954;,0.888533;0.828625;,0.878517;0.828625;,0.878517;0.856954;,0.939292;0.870917;,0.939292;0.899246;,0.949159;0.899246;,0.949159;0.870917;,0.946887;0.91117;,0.956719;0.91117;,0.956719;0.901213;,0.946887;0.901213;,0.865118;0.813135;,0.855286;0.813135;,0.855286;0.823092;,0.865118;0.823092;,0.866874;0.847426;,0.866874;0.835259;,0.855286;0.835259;,0.855286;0.847426;,0.598002;0.973516;,0.598002;0.206739;,0.309722;0.206739;,0.309722;0.973516;,0.909393;0.822135;,0.909393;0.841014;,0.915938;0.841014;,0.915938;0.822135;,0.951962;0.931916;,0.951962;0.91117;,0.946887;0.91117;,0.946887;0.931916;,0.948762;0.841801;,0.948762;0.822921;,0.942217;0.822921;,0.942217;0.841801;,0.893608;0.838075;,0.893608;0.817329;,0.888533;0.817329;,0.888533;0.838075;,0.900724;0.909292;,0.90515;0.909292;,0.90515;0.902786;,0.900724;0.902786;,0.953585;0.871994;,0.949159;0.871994;,0.949159;0.8785;,0.953585;0.8785;,0.84857;0.837995;,0.84857;0.856874;,0.855114;0.856874;,0.855114;0.837995;,0.902881;0.83746;,0.902881;0.816714;,0.897805;0.816714;,0.897805;0.83746;,0.942217;0.841801;,0.942217;0.822921;,0.935673;0.822921;,0.935673;0.841801;,0.949159;0.8785;,0.949159;0.899246;,0.954235;0.899246;,0.954235;0.8785;,0.919226;0.822135;,0.923651;0.822135;,0.923651;0.815629;,0.919226;0.815629;,0.928077;0.815629;,0.923651;0.815629;,0.923651;0.822135;,0.928077;0.822135;,0.865301;0.847426;,0.865301;0.876542;,0.875317;0.876542;,0.875317;0.847426;,0.909393;0.841014;,0.909393;0.87013;,0.919261;0.87013;,0.919261;0.841014;,0.855286;0.847426;,0.855286;0.876542;,0.865301;0.876542;,0.865301;0.847426;,0.919261;0.841014;,0.919261;0.87013;,0.929128;0.87013;,0.929128;0.841014;,0.878517;0.828625;,0.888349;0.828625;,0.88835;0.818668;,0.878517;0.818668;,0.836981;0.83254;,0.846814;0.83254;,0.846814;0.822583;,0.836981;0.822583;,0.857749;0.887894;,0.836981;0.887894;,0.837473;0.899246;,0.857257;0.899246;,0.855286;0.876542;,0.855286;0.856874;,0.836981;0.856874;,0.836981;0.876542;,0.897805;0.887893;,0.897313;0.876622;,0.879009;0.876622;,0.878517;0.887893;,0.886604;0.909292;,0.886112;0.920645;,0.9054;0.920645;,0.904908;0.909292;,0.977665;0.442421;,0.977665;0.131438;,0.799225;0.123708;,0.799225;0.450151;,0.849264;0.899246;,0.836981;0.899246;,0.836981;0.931916;,0.849264;0.931916;,0.909393;0.866576;,0.897805;0.866576;,0.897805;0.899246;,0.909393;0.899246;,0.84857;0.844707;,0.836981;0.844707;,0.836981;0.856874;,0.84857;0.856874;,0.929276;0.899246;,0.939292;0.899246;,0.939292;0.870917;,0.929276;0.870917;,0.876741;0.819096;,0.866874;0.819096;,0.866874;0.847426;,0.876741;0.847426;,0.939144;0.841801;,0.929128;0.841801;,0.929128;0.87013;,0.939144;0.87013;,0.949011;0.841801;,0.939144;0.841801;,0.939144;0.87013;,0.949011;0.87013;,0.836981;0.812626;,0.836981;0.822583;,0.846814;0.822583;,0.846814;0.812626;,0.909393;0.812178;,0.909393;0.822135;,0.919226;0.822135;,0.919226;0.812178;,0.866874;0.823092;,0.855286;0.823092;,0.855286;0.835259;,0.866874;0.835259;,0.021442;0.973516;,0.309722;0.973516;,0.309722;0.206739;,0.021442;0.206739;,0.916039;0.841014;,0.922583;0.841014;,0.922583;0.822135;,0.916039;0.822135;,0.907956;0.816714;,0.902881;0.816714;,0.902881;0.83746;,0.907956;0.83746;,0.929128;0.822135;,0.922583;0.822135;,0.922583;0.841014;,0.929128;0.841014;,0.853645;0.817249;,0.84857;0.817249;,0.84857;0.837995;,0.853645;0.837995;,0.900724;0.909292;,0.900724;0.902786;,0.895944;0.902786;,0.895944;0.909292;,0.93896;0.816415;,0.93896;0.822921;,0.94374;0.822921;,0.94374;0.816415;,0.935673;0.822921;,0.929128;0.822921;,0.929128;0.841801;,0.935673;0.841801;,0.954087;0.849384;,0.949011;0.849384;,0.949011;0.87013;,0.954087;0.87013;,0.895077;0.838075;,0.888533;0.838075;,0.888533;0.856954;,0.895077;0.856954;,0.948762;0.841801;,0.953838;0.841801;,0.953838;0.821055;,0.948762;0.821055;,0.94374;0.816415;,0.94374;0.822921;,0.94852;0.822921;,0.94852;0.816415;,0.949011;0.842878;,0.949011;0.849384;,0.953791;0.849384;,0.953791;0.842878;,0.919409;0.87013;,0.909393;0.87013;,0.909393;0.899246;,0.919409;0.899246;,0.897805;0.866576;,0.907672;0.866576;,0.907672;0.83746;,0.897805;0.83746;,0.927004;0.9028;,0.916988;0.9028;,0.916988;0.931916;,0.927004;0.931916;,0.929276;0.87013;,0.919409;0.87013;,0.919409;0.899246;,0.929276;0.899246;,0.93896;0.822921;,0.93896;0.812965;,0.929128;0.812965;,0.929128;0.822921;,0.886112;0.899336;,0.886112;0.909292;,0.895944;0.909292;,0.895944;0.899336;,0.857749;0.887894;,0.857257;0.876542;,0.837473;0.876542;,0.836981;0.887894;,0.896821;0.856954;,0.878517;0.856954;,0.878517;0.876622;,0.896821;0.876622;,0.897805;0.887893;,0.878517;0.887893;,0.879009;0.899246;,0.897313;0.899246;,0.886604;0.931916;,0.904908;0.931916;,0.9054;0.920645;,0.886112;0.920645;,0.620785;0.44242;,0.799225;0.450151;,0.799225;0.123708;,0.620785;0.131438;;}XSkinMeshHeader{3;9;10;}SkinWeights{"Armature_arm_l";24;44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,66;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;-0.047733,0.901521,0.430095,0,-0.097683,0.424309,-0.900233,0,-0.994073,-0.084983,0.06781,0,0.374873,-2.006904,2.980378,1;;}SkinWeights{"Armature_elbow_r";24;216,219,218,213,212,215,214,209,224,208,227,211,226,210,206,221,207,220,204,223,205,222,225,217;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;0.102316,0.92166,-0.374266,0,-0.090709,-0.366028,-0.926173,0,-0.990608,0.128712,0.046152,0,0.402018,1.853661,2.350172,1;;}SkinWeights{"Armature_arm_r";24;186,187,184,185,182,183,180,194,195,203,202,192,193,201,200,199,190,198,191,197,188,196,189,181;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;-0.047733,0.901521,-0.430095,0,-0.05233,-0.432251,-0.900234,0,-0.997489,-0.020464,0.067809,0,0.160852,2.035269,2.980378,1;;}SkinWeights{"Armature_knee_l";24;105,99,114,106,98,115,107,101,93,108,100,92,109,103,95,110,102,94,111,97,112,104,113,96;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;1,0,0,0,0,0.054357,-0.998522,0,0,0.998501,0.054355,0,-0.246294,-0.008592,1.301673,1;;}SkinWeights{"Armature_Bone_007";40;132,133,134,135,124,125,126,252,253,254,255,121,122,264,265,123,267,268,269,270,116,256,258,259,260,261,262,263,271,266,120,119,117,128,129,127,130,118,131,257;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;1,0,0,0,0,0,1,0,0,-1,0,0,0,0,-3.793003,1;;}SkinWeights{"Armature_elbow_l";24;88,80,72,91,83,75,90,82,74,70,85,77,71,84,76,68,87,79,69,86,78,89,81,73;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;0.102316,0.92166,0.374266,0,-0.008222,0.377011,-0.926173,0,-0.994719,0.091686,0.046152,0,-0.014321,-1.896701,2.350171,1;;}SkinWeights{"Armature_knee_r";24;249,235,250,234,251,229,244,228,245,231,246,230,247,240,241,242,243,237,236,239,238,233,248,232;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;1,0,0,0,0,0.054357,-0.998522,0,0,0.998501,0.054355,0,0.246294,-0.008592,1.301673,1;;}SkinWeights{"Armature_leg_l";38;0,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,40,43,136,145,177,144;0.055873,0.852304,0.852304,0.82998,0.055873,0.852304,0.82998,0.054606,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0.82998,0.054606,0.055873,0.054606,0.054606,0.055873;1,0,0,0,0,-0.056452,-0.998405,0,0,0.998385,-0.056452,0,-0.246294,0.135476,2.396023,1;;}SkinWeights{"Armature_leg_r";38;0,170,169,11,168,151,150,149,148,147,146,176,145,177,144,159,158,157,156,155,154,153,167,136,166,137,165,164,163,140,162,141,161,43,160,152,8,171;0.055873,1,1,0.054606,1,1,1,1,1,0.852304,0.82998,0.82998,0.054606,0.054606,0.055873,1,1,1,1,1,1,1,1,0.055873,1,0.852304,1,1,1,0.852304,1,0.82998,1,0.054606,1,1,0.055873,1;1,0,0,0,0,-0.056452,-0.998405,0,0,0.998385,-0.056452,0,0.246294,0.135476,2.396023,1;;}SkinWeights{"Armature_body";40;0,1,2,3,4,5,6,7,8,9,10,11,36,37,38,39,40,41,42,43,136,137,138,139,140,147,141,146,142,145,143,144,179,174,178,173,177,172,176,175;0.888255,1,1,0.147696,0.147696,1,1,0.17002,0.888255,0.147696,0.17002,0.890788,1,1,1,1,0.17002,1,1,0.890788,0.888255,0.147696,1,1,0.147696,0.147696,0.17002,0.17002,1,0.890788,1,0.888255,1,1,1,1,0.890788,1,0.17002,1;1,0,0,0,0,0,1,0,0,-1,0,0,0,0,-2.571201,1;;}}}}} \ No newline at end of file diff --git a/irr/media/cooltexture.png b/irr/media/cooltexture.png new file mode 100755 index 0000000000000000000000000000000000000000..fcc219ac7ea95c2ad9b49ad0064835638cb51c69 GIT binary patch literal 4828 zcmd5=XH*kFwho{Y1O!1KbO8|%sX?TQqSR0X>0J;)k={EB(nOG6LXj>4p-Tx>5u_@i zNef61K|+yGl90{r+4uAP+q3VTGc$M2Ju`D>?#wOoB|O#Bpufs-6#xLxYiT|)1OO<= zT?zn@l1wHURiwy-#!J)O7XYAT{%55CN51C_#L#(^a%fs87FdAw@?3P*MyCRlCo}xEWq6L_V5h156#?KN(4RaMhTZ)?iz$HKw0Kfi`{v2$?J%19gOb zLU&u1QLYC_!9l^Hqi>XfZU8ir*hffWHO*!RNX zO_@yBVx2&r;NPZ=WHLGQb`r;ZLTkoSrE{E@BJ;9^I3XD}Cp{TEiCJ7a&fb|%?T_YY zU9+r|=hAt!HqK6FbD6a6q?QS+@W-&{Jumb3g|9f;9Dbh}eHh3S0r=|pTT3ldg|L9` zWeoPw&e6?{g!_E<_r6%RW5Q8JGt}DB+|vpxymz2M-|+q zL6f;HCB+%T4`5AGUun1|>FyP~(oAb&Vi@P3b&Cd^i-rRbC8wx2ic}yS$j2wpwI9Y6 zAjFKkp9#yWhjz1Y>l0LHop53t18>B|*;ZU!+);Oa!D02N^@@wD>-_mfZHaKLuw6Cav-C)j7dw6ATrd~&w{A;3zxz+2}E6n9DX;p zty^}JMOZ4rGDeF;(pad89+x1{=6gDH%WT=kRZx!C)v z|KO}_65Sa9uM=)CdzpBUH@TC`s4XmXBwHkg0?Q6X1nK$3OUfA_@8=!=6sm z)oG7b+rWx!ZIML#Or?txCa%}jQ;&m_nLn;D3Z~pu5JU|uye)vtveJrQr?~5tQTh7W zsDczDH}dql3OZL`5)`(X3(bSU#;BJ@+9^lh2Je-xO1yjMi-F8 zs4lE8n6gXPp6k&}IP!iBzHK9*J!rV&9CEZdhQ~dyH8%E-?rK1xP?d!tJB#hU>2UNC z3(7yTN6QCNH2A}@kp08#SSZlWpq36OagsHFVuM|1R9oR`Y9C4ee89GN|>Uu7a z5Q(Z!d2`4Cw?sYQZ^sC8-*EG1_cmPMj!fFZQZl7~Q$!UbnG5|MSs55KcrJHyzKhVE zOy*X^^)u^-5e^1t_#8<$lCR1>^3zQhw7J@lvw10*RrVBut?KZo&lA$j&~Efw4nOHS z7~o{qAibew!|l#7zf-TH?<-RW31kFivs}6On87TU2loBoOW8{3o5t}Eo?cE^&!Q0& z&&ITG6&^T*CDrm_NDA4#i zKPVq=P|Tm5{$5;TY!GxlG&YBTt}?f}yWc zPOr6Kx3Su6crtQ$So;yj^`Fs`ZDj(MgQ_!5hN`{w0q`iGWi_2KYdfSr}Wq+ytMEJ9>iU9Y}}UIH50= z|8Y`%rl?7WmAH1*r%!dAhr{}jxXDwqFv5xUWgqnC#PhhBv-`0@38YnO2Z`oN4Z{Yn zsSX~po~DpUpR>aa7EzNMH*RcqL>#UUY48NE|7viU6Cx%_iXDXr-SOJcohBQE=T3PQ z&@Pq9+A!o63oV1CX^dgj)Y;Kib#=9AosBzaKoQ&71pQIi-Q7LPE-U!j8i=x<+3%tk zT)6WG!fnp5U|Tlu#aIn)$nZSoFyD?j{s}(zTs&6d3gO$EH*a|JPgn4yed04AeO)E` zCcWR6U@JWWPiL(pLf!A5OdeQ#P=m1R_;I;lNgst+jOoVg6xM_T2hZu3FRDE&C(+R) z@BOA^+SiZYcgZdoBEai59W&S}i!WMDKJ%j>uwjR5w|(68$I!dAh$?8pHkx<0=P%xi zG}twC5mUUAJNt@B_44>;6MiSVqq-BvukmP%X%32*yG%oAHkH&|$fH~B;G$g4`3YX> z=gJ7PgJz)9#96<;e!L=Bm>!h81?+Mh90GxjqN@g4*i>PpZMAi|)E}d2U9`Jg7b>asuN zC1m$3+!#l=wz8f~l2&ofS0R1sQ`ig+TyNbhwgq>j1b*(C|5VwW_^0LGvYFIZ&g*tp zqH>c|qRSmbl*>nKI34LIA#EUtKFRr}x1vySzAfB>iCQN;H z)hBYdw0BM$@wjOHIZS<<&@J@^DC7mnVml0=pcwVsl-Hk0`00)~fQ^PQjo@uXAcOaiN^*EzXMaaqK zm)ec{h&f$u!{&0Kd1U%7S8iXONmr=vDVljAi>Ewv%4AhmrOGcQue66e`m&s*f#K6N zF}$lkzD@;<47u~k>hwoba@2^mjpPF9p^ZMqx`%d9JcS%sG^k(@a&Z#q47>6ks4-T| z`V!87>UkZQxVeG}Z<%fy@EoVAx@c>E7x?TWA(Zn)4|tjvOE^P2L-fhgandPgfTA_0 zc3#7o2&er8dAIBw-hPQ|mK5X$8t(ttW!Jq9qi!H!Qc4^2&qq@W)|@7b2w}*RGxTIf0=`}3GgIIMF7K7V zpVYPNS`lF%LSt|RRM5LL{o)KFUO#JA!K#g{xuLz@k2VrD&Xnn1q(pYNvX)3)EH_$QYQB4ZeBRz(A*+D4R`{w{2Q zqmsibr6V0LM%y{CH<~W6DG?d$!D|}z$KJEAz_0M8>)mtBHOF61DHNiOV}=3)=Xz6d zWKHsO`5T2Y|Nh9HhTUs?)A_Qp-`e0Q{volF6fzt}U7Rey7P^e_xm1vBpS{8ezJIgB z`)ZPu82mQ%>hSxLtL!gLTzENMVP79km;T6nx*(qcpc@&=}*OIjcxgr znqza{g3@`nv7nhPwwIJ#$DVX1isva=`M^V-0K!kv3;ZQ3W! z%cT6Gw#OPRv-t(1@J^WOBwTnCdjv>Na(LyN8Ju6fhYY>ruQvHCuXsy_%1dd(ol@e! zXa&BMfe*-;J8Y96&+Ifq;a#ic3u}HmDziDcJJ_W0lKxC1?psES437E8-#RLDBt*O( zJ2uB#b<`r2R`w@_YJ}*?jP$*xk5vQbxRMHv#?zaQ(?t@67yjqWxR=F?`oI^ugflY_mxl{}z#A5?ktrLSjR&P(R%F*}g1G zwOB}1z=*7mM6`&vn%v%-zF^-4A9_HY%26N!f7~UY-OM!63$lO;q~R-yIMJNRCM#=( zc^V8ts4ciP>iq#wEC!HS)wp}#B$bosCae9KurNjxmt$-WAeQ%we0mKdEQ_ z%DtFS`OCmHwCEACD%;c`8r2T8+YYMqZ?#s94=#F!k@a^qI$Q6XZR-BE=rrA3QG@uf z>1_(|z437U)X^=;LLg}W&$Xk964Pa8ftZ@GJs!+$->QpKEa_ZVRdbyPuQ7lPT2qWp zaF8v;fAhUy%ngsRMV;{uv>&>agM&e3#iGF|rP`s0o*ap;psqsQ!JG)noKp5)j>h{X zektmf9f)iBxg+EymiU8qjt}NEmK#}XaKn`HD|tb8R0a{0mn1dLQ*2~Z%#Mb~C4y>i zrywY6C^qB$yO11>u14(}{~D3_d6w+n$E^fo%Ffp|zvWvZM0-Vka?udZe2!A_gu=i9 z2FIgxSEK7)pWByN?5^YpkUj9%i$8svAx9~Fo9D*(JZ&B;_Y0}>=OEdBRV!Ey>6f0HCF&_XMtL_xc|=%FgZp literal 0 HcmV?d00001 diff --git a/irr/scripts/BindingGenerator.lua b/irr/scripts/BindingGenerator.lua new file mode 100755 index 000000000..0f9ffa764 --- /dev/null +++ b/irr/scripts/BindingGenerator.lua @@ -0,0 +1,453 @@ +#!/usr/bin/lua +-- BindingGenerator.lua (c) hecks 2021 +-- This script is a part of IrrlichtMT, released under the same license. + +-- By default we assume you're running this from /scripts/ +-- and that you have the necessary headers there (gitignored for your convenience) +local sourceTreePath = os.getenv( "IRRMTREPO" ) or ".."; +-- Otherwise run this from wherever you want and set the above env variable. +local glHeaderPath = os.getenv( "GLHEADERPATH" ) or "."; +-- GL headers will be looked for in the current directory or GLHEADERPATH. +-- At the moment we require: +-- "glcorearb.h" +-- "gl2ext.h" +-- Files other than glcorearb.h are only parsed for vendor specific defines +-- and aliases. Otherwise we only use what exists in glcorearb.h, further +-- restricted to procedures that are either core or ARB. + + +-- Emulate a portion of the libraries that this was written against. +getmetatable( "" ).__index = string; +getmetatable( "" ).__len = string.len; +getmetatable( "" ).__call = string.format; +function string:Split( pat ) + local r = {}; + local pos = 1; + local from, to; + while pos and pos <= #self do + from, to = self:find( pat, pos ); + if not from then + break; + end + r[#r+1] = self:sub( pos, from - 1 ); + pos = to + 1; + end + r[#r+1] = self:sub( pos, #self ); + return r; +end +function string:TrimBothEnds() + return self:gsub("^%s+",""):gsub("%s+$",""); +end +local List; +List = function( t ) + return setmetatable( t or {}, { + __index = { + Add = function( t, v ) + t[#t+1] = v; + end; + AddFormat = function( t, str, ... ) + t:Add( str( ... ) ); + end; + Where = function( t, f ) + local r = {}; + for i=1, #t do + if f(t[i]) then r[#r+1] = t[i]; end + end + return List( r ); + end; + Select = function( t, f ) + local r = {}; + for i=1, #t do + r[#r+1] = f( t[i] ); + end + return List( r ); + end; + Join = function( t, n ) + local r = {}; + for i=1, #t do + r[i] = t[i]; + end + for i=1, #n do + r[#r+1] = n[i]; + end + return List( r ); + end; + Concat = table.concat; + }; + } ); +end + + +------------ Header parsing ------------ + +-- GL and GLES alike +local driverVendors = { + "NV", "AMD", "INTEL", "OVR", "QCOM", "IMG", "ANGLE", "APPLE", "MESA" +} +local vendorSuffixes = { + "ARB", "EXT", "KHR", "OES", + unpack( driverVendors ) +}; +local vendorSuffixPattern = {}; +local constSuffixPattern = {}; +for i=1, #vendorSuffixes do + vendorSuffixPattern[i] = vendorSuffixes[i] .. "$"; + constSuffixPattern[i] = ("_%s$")( vendorSuffixes[i] ); +end +local constBanned = {}; +for i=1, #driverVendors do + constBanned[driverVendors[i]] = true; +end +-- Strip the uppercase extension vendor suffix from a name. +local function StripVendorSuffix( str, const ) + local patterns = const and constSuffixPattern or vendorSuffixPattern; + local n; + for i=1, #patterns do + str, n = str:gsub( patterns[i], "" ); + if n > 0 then + return str, vendorSuffixes[i]; + end + end + return str; +end + +-- Normalize the type of an argument or return, also stripping any suffix +-- and normalizing all whitespace regions to single spaces. +local function NormalizeType( str ) + local chunks = str:Split( "%s+" ); + for j=1, #chunks do + chunks[j] = StripVendorSuffix( chunks[j] ); + end + local T = table.concat(chunks, " " ); + return T:TrimBothEnds(); +end + +-- Normalize an argument, returning the normalized type and the name separately, +-- always sticking the * of a pointer to the type rather than the name. +-- We need this to generate a normalized arg list and function signature (below) +local function NormalizeArgument( str ) + local chunks = str:Split( "%s+" ); + for j=1, #chunks do + chunks[j] = StripVendorSuffix( chunks[j] ); + end + local last = chunks[#chunks]; + local name = last:match( "[%w_]+$" ); + chunks[#chunks] = #name ~= #last and last:sub( 1, #last-#name) or nil; + local T = table.concat(chunks, " " ):TrimBothEnds(); + return T, name +end + +-- Normalize an argument list so that two matching prototypes +-- will produce the same table if fed to this function. +local function NormalizeArgList( str ) + local args = str:Split( ",%s*" ); + local r = {}; + for i=1, #args do + local T, name = NormalizeArgument( args[i] ); + r[i] = { T, name }; + end + return r; +end + +-- Normalize a function signature into a unique string for keying +-- in such a way that if two different GL procedures may be assigned +-- to the same function pointer, this will produce an identical string for both. +-- This makes it possible to detect function aliases that may work as a fallback. +-- You still have to check for the appropriate extension. +local function NormalizeFunctionSignature( T, str ) + local args = str:Split( ",%s*" ); + local r = {}; + for i=1, #args do + r[i] = NormalizeArgument( args[i] ); + end + return ("%s(%s)")( T, table.concat( r, ", " ) ); +end + +-- Mangle the PFN name so that we don't collide with a +-- typedef from any of the GL headers. +local pfnFormat = "PFNGL%sPROC_MT"; + +--( T, name, args ) +local typedefFormat = "\ttypedef %s (APIENTRYP %s) (%s);" +-- Generate a PFN...GL style typedef for a procedure +-- +local function GetProcedureTypedef( proc ) + local args = {}; + for i=1, #proc.args do + args[i] = ("%s %s")( unpack( proc.args[i] ) ) + end + return typedefFormat( proc.retType, pfnFormat( proc.name:upper() ), table.concat( args, ", " ) ); +end + +local procedures = List(); +local nameset = {}; +local definitions = List(); +local consts = List(); + +--[[ + Structured procedure representation: + + ProcSpec = { + string name; -- Normalized name as it appears in the GL spec + string? vendor; -- Uppercase vendor string (ARB, EXT, AMD, NV etc) + string signature; + string retType; + args = { { type, name } }; + }; +]] +-- Parse a whole header, extracting the data. +local function ParseHeader( path, into, apiRegex, defs, consts, nameSet, noNewNames ) + defs:AddFormat( "\t// %s", path ); + local f = assert( io.open( path, "r" ), "Could not open " .. path ); + for line in f:lines() do + -- Do not parse PFN typedefs; they're easily reconstructible. + local T, rawName, args = line:match( apiRegex ); + if T then + T = NormalizeType( T ); + -- Strip the 'gl' namespace prefix. + local procName = rawName:sub(3,-1); + local name, vendor = StripVendorSuffix( procName ); + if not (noNewNames and nameSet[name]) then + nameSet[name] = true; + into:Add{ + name = name; + vendor = vendor; + -- pfnType = pfnFormat( procName:upper() ); + signature = NormalizeFunctionSignature( T, args ); + retType = T; + args = NormalizeArgList( args ); + }; + end + elseif ( line:find( "#" ) and not line:find( "#include" ) ) then + local rawName, value = line:match( "#define%s+GL_([_%w]+)%s+0x(%w+)" ); + if rawName and value then + local name, vendor = StripVendorSuffix( rawName, true ); + if not constBanned[vendor] then + consts:Add{ name = name, vendor = vendor, value = "0x"..value }; + end + end + ::skip:: + elseif( line:find( "typedef" ) and not line:find( "%(" ) ) then + -- Passthrough non-PFN typedefs + defs:Add( "\t" .. line ); + end + end + defs:Add ""; + f:close(); +end + +------------ Parse the headers ------------ + +-- ES/gl2.h is a subset of glcorearb.h and does not need parsing. + +local funcRegex = "GLAPI%s+(.+)APIENTRY%s+(%w+)%s*%((.*)%)"; +local funcRegexES = "GL_APICALL%s+(.+)GL_APIENTRY%s+(%w+)%s*%((.*)%)"; +ParseHeader( glHeaderPath .. "/glcorearb.h", procedures, funcRegex, definitions, consts, nameset ); +ParseHeader( glHeaderPath .. "/gl2ext.h", procedures, funcRegexES, List(), consts, nameset, true ); +-- Typedefs are redirected to a dummy list here on purpose. +-- The only unique typedef from gl2ext is this: +definitions:Add "\ttypedef void *GLeglClientBufferEXT;"; + +------------ Sort out constants ------------ + +local cppConsts = List(); +do + local constBuckets = {}; + for i=1, #consts do + local vendor = consts[i].vendor or "core"; + constBuckets[consts[i].name] = constBuckets[consts[i].name] or {}; + constBuckets[consts[i].name][vendor] = consts[i].value; + end + local names = {}; + for i=1, #consts do + local k = consts[i].name; + local b = constBuckets[k]; + if k == "WAIT_FAILED" or k == "DIFFERENCE" then + -- This is why using #define as const is evil. + k = "_" .. k; + end + if b and not names[k] then + names[k] = true; + -- I have empirically tested that constants in GL with the same name do not differ, + -- at least for these suffixes. + local v = b.core or b.KHR or b.ARB or b.OES or b.EXT; + if v then + local T = v:find( "ull" ) and "GLuint64" or "GLenum"; + cppConsts:AddFormat( "\tstatic constexpr const %s %s = %s;", T, k, v ); + end + end + end +end + + +------------ Sort out procedures ------------ + +local procTable = {}; + +local coreProcedures = procedures:Where( function(x) return not x.vendor; end ); +local arbProcedures = procedures:Where( function(x) return x.vendor == "ARB"; end ); + +-- Only consider core and ARB functions. +local nameList = coreProcedures:Join( arbProcedures ):Select( + function(p) + return p.name; + end ); + +local nameSet = {}; +local uniqueNames = List(); + +for s, k in ipairs( nameList ) do + if not nameSet[k] then + nameSet[k] = true; + uniqueNames:Add( k ); + end +end + +for i=1, #procedures do + local p = procedures[i]; + procTable[p.name] = procTable[p.name] or {}; + local key = p.vendor or "core"; + procTable[p.name][key] = p; +end + +local priorityList = List{ "core", "ARB", "OES", "KHR" }; + +local typedefs = List(); +local pointers = List(); +local loader = List(); + +for s, str in ipairs( uniqueNames ) do + pointers:Add( ("\t%s %s = NULL;")( pfnFormat( str:upper() ), str ) ); + local typeDefGenerated = false; + for i=1, #priorityList do + local k = priorityList[i]; + local proc = procTable[str][k] + if proc then + if not typeDefGenerated then + typedefs:Add( GetProcedureTypedef( proc ) ); + typeDefGenerated = true; + end + local vendor = k == "core" and "" or k; + loader:AddFormat( + '\tif (!%s) %s = (%s)cmgr->getProcAddress("%s");\n', + str, str, pfnFormat( proc.name:upper() ), ("gl%s%s")(str,vendor) + ); + end + end +end + + +------------ Write files ------------ + +-- Write loader header +local f = io.open( sourceTreePath .. "/include/mt_opengl.h", "wb" ); +f:write[[ +// This code was generated by scripts/BindingGenerator.lua +// Do not modify it, modify and run the generator instead. + +#pragma once + +#include +#include +#include "IrrCompileConfig.h" // for IRRLICHT_API +#include "irrTypes.h" +#include "IContextManager.h" +#include + +#ifndef APIENTRY + #define APIENTRY KHRONOS_APIENTRY +#endif +#ifndef APIENTRYP + #define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI + #define GLAPI extern +#endif + +]]; + +f:write[[ +class OpenGLProcedures { +private: +]]; +f:write( definitions:Concat( "\n" ) ); +f:write( "\n" ); +f:write[[ + // The script will miss this particular typedef thinking it's a PFN, + // so we have to paste it in manually. It's the only such type in OpenGL. + typedef void (APIENTRY *GLDEBUGPROC) + (GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); + +]] +f:write( typedefs:Concat( "\n" ) ); +f:write( "\n\n" ); +f:write [[ + std::unordered_set extensions; +public: + // Call this once after creating the context. + void LoadAllProcedures(irr::video::IContextManager *cmgr); + // Check if an extension is supported. + inline bool IsExtensionPresent(const std::string &ext) const + { + return extensions.count(ext) > 0; + } + +]]; +f:write( pointers:Concat( "\n" ) ); +f:write( "\n\n" ); +f:write( cppConsts:Concat( "\n" ) ); +f:write( "\n\n" ); +f:write[[ + static constexpr const GLenum ZERO = 0; + static constexpr const GLenum ONE = 1; + static constexpr const GLenum NONE = 0; +]]; +f:write( "};\n" ); +f:write( "\n// Global GL procedures object.\n" ); +f:write( "IRRLICHT_API extern OpenGLProcedures GL;\n" ); +f:close(); + +-- Write loader implementation +f = io.open( sourceTreePath .. "/src/mt_opengl_loader.cpp", "wb" ); +f:write[[ +// This code was generated by scripts/BindingGenerator.lua +// Do not modify it, modify and run the generator instead. + +#include "mt_opengl.h" +#include +#include + +OpenGLProcedures GL = OpenGLProcedures(); + +void OpenGLProcedures::LoadAllProcedures(irr::video::IContextManager *cmgr) +{ + +]]; +f:write( loader:Concat() ); +f:write[[ + + // OpenGL 3 way to enumerate extensions + GLint ext_count = 0; + GetIntegerv(NUM_EXTENSIONS, &ext_count); + extensions.reserve(ext_count); + for (GLint k = 0; k < ext_count; k++) { + auto tmp = GetStringi(EXTENSIONS, k); + if (tmp) + extensions.emplace((char*)tmp); + } + if (!extensions.empty()) + return; + + // OpenGL 2 / ES 2 way to enumerate extensions + auto ext_str = GetString(EXTENSIONS); + if (!ext_str) + return; + // get the extension string, chop it up + std::stringstream ext_ss((char*)ext_str); + std::string tmp; + while (std::getline(ext_ss, tmp, ' ')) + extensions.emplace(tmp); + +} +]]; +f:close(); diff --git a/irr/scripts/ci-build-android.sh b/irr/scripts/ci-build-android.sh new file mode 100755 index 000000000..a865e56a4 --- /dev/null +++ b/irr/scripts/ci-build-android.sh @@ -0,0 +1,123 @@ +#!/bin/bash -e + +# NOTE: this code is mostly copied from minetest_android_deps +# + +png_ver=1.6.40 +jpeg_ver=3.0.1 + +download () { + get_tar_archive libpng "https://download.sourceforge.net/libpng/libpng-${png_ver}.tar.gz" + get_tar_archive libjpeg "https://download.sourceforge.net/libjpeg-turbo/libjpeg-turbo-${jpeg_ver}.tar.gz" +} + +build () { + # Build libjpg and libpng first because Irrlicht needs them + mkdir -p libpng + pushd libpng + $srcdir/libpng/configure --host=$CROSS_PREFIX + make && make DESTDIR=$PWD install + popd + + mkdir -p libjpeg + pushd libjpeg + cmake $srcdir/libjpeg "${CMAKE_FLAGS[@]}" -DENABLE_SHARED=OFF + make && make DESTDIR=$PWD install + popd + + local libpng=$PWD/libpng/usr/local/lib/libpng.a + local libjpeg=$(echo $PWD/libjpeg/opt/libjpeg-turbo/lib*/libjpeg.a) + cmake $srcdir/irrlicht "${CMAKE_FLAGS[@]}" \ + -DBUILD_SHARED_LIBS=OFF \ + -DPNG_LIBRARY=$libpng \ + -DPNG_PNG_INCLUDE_DIR=$(dirname "$libpng")/../include \ + -DJPEG_LIBRARY=$libjpeg \ + -DJPEG_INCLUDE_DIR=$(dirname "$libjpeg")/../include + make + + cp -p lib/Android/libIrrlichtMt.a $libpng $libjpeg $pkgdir/ + cp -a $srcdir/irrlicht/include $pkgdir/include + cp -a $srcdir/irrlicht/media/Shaders $pkgdir/Shaders +} + +get_tar_archive () { + # $1: folder to extract to, $2: URL + local filename="${2##*/}" + [ -d "$1" ] && return 0 + wget -c "$2" -O "$filename" + mkdir -p "$1" + tar -xaf "$filename" -C "$1" --strip-components=1 + rm "$filename" +} + +_setup_toolchain () { + local toolchain=$(echo "$ANDROID_NDK"/toolchains/llvm/prebuilt/*) + if [ ! -d "$toolchain" ]; then + echo "Android NDK path not specified or incorrect"; return 1 + fi + export PATH="$toolchain/bin:$ANDROID_NDK:$PATH" + + unset CFLAGS CPPFLAGS CXXFLAGS + + TARGET_ABI="$1" + API=21 + if [ "$TARGET_ABI" == armeabi-v7a ]; then + CROSS_PREFIX=armv7a-linux-androideabi + CFLAGS="-mthumb" + CXXFLAGS="-mthumb" + elif [ "$TARGET_ABI" == arm64-v8a ]; then + CROSS_PREFIX=aarch64-linux-android + elif [ "$TARGET_ABI" == x86 ]; then + CROSS_PREFIX=i686-linux-android + CFLAGS="-mssse3 -mfpmath=sse" + CXXFLAGS="-mssse3 -mfpmath=sse" + elif [ "$TARGET_ABI" == x86_64 ]; then + CROSS_PREFIX=x86_64-linux-android + else + echo "Invalid ABI given"; return 1 + fi + export CC=$CROSS_PREFIX$API-clang + export CXX=$CROSS_PREFIX$API-clang++ + export AR=llvm-ar + export RANLIB=llvm-ranlib + export CFLAGS="-fPIC ${CFLAGS}" + export CXXFLAGS="-fPIC ${CXXFLAGS}" + + CMAKE_FLAGS=( + "-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake" + "-DANDROID_ABI=$TARGET_ABI" "-DANDROID_NATIVE_API_LEVEL=$API" + "-DCMAKE_BUILD_TYPE=Release" + ) + + # make sure pkg-config doesn't interfere + export PKG_CONFIG=/bin/false + + export MAKEFLAGS="-j$(nproc)" +} + +_run_build () { + local abi=$1 + irrdir=$PWD + + mkdir -p $RUNNER_TEMP/src + cd $RUNNER_TEMP/src + srcdir=$PWD + [ -d irrlicht ] || ln -s $irrdir irrlicht + download + + builddir=$RUNNER_TEMP/build/irrlicht-$abi + pkgdir=$RUNNER_TEMP/pkg/$abi/Irrlicht + rm -rf "$pkgdir" + mkdir -p "$builddir" "$pkgdir" + + cd "$builddir" + build +} + +if [ $# -lt 1 ]; then + echo "Usage: ci-build-android.sh " + exit 1 +fi + +_setup_toolchain $1 +_run_build $1 diff --git a/irr/scripts/ci-build-mingw.sh b/irr/scripts/ci-build-mingw.sh new file mode 100755 index 000000000..b1fdd7b99 --- /dev/null +++ b/irr/scripts/ci-build-mingw.sh @@ -0,0 +1,70 @@ +#!/bin/bash -e +topdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +[[ -z "$CC" || -z "$CXX" ]] && exit 255 +variant=win32 +[[ "$(basename "$CXX")" == "x86_64-"* ]] && variant=win64 +with_sdl=0 +[[ "$extras" == *"-sdl"* ]] && with_sdl=1 +#with_gl3=0 +#[[ "$extras" == *"-gl3"* ]] && with_gl3=1 + +libjpeg_version=3.0.1 +libpng_version=1.6.40 +sdl2_version=2.28.5 +zlib_version=1.3.1 + +download () { + local url=$1 + local filename=${url##*/} + local foldername=${filename%%[.-]*} + + [ -d "./$foldername" ] && return 0 + [ -e "$filename" ] || wget "$url" -O "$filename" + sha256sum -w -c <(grep -F "$filename" "$topdir/sha256sums.txt") + unzip -o "$filename" -d "$foldername" +} + +libs=$PWD/libs +mkdir -p libs +pushd libs +libhost="http://minetest.kitsunemimi.pw" +download "$libhost/llvm/libjpeg-$libjpeg_version-$variant.zip" +download "$libhost/llvm/libpng-$libpng_version-$variant.zip" +[ $with_sdl -eq 1 ] && download "$libhost/llvm/sdl2-$sdl2_version-$variant.zip" +download "$libhost/llvm/zlib-$zlib_version-$variant.zip" +popd + +tmp=( + -DCMAKE_SYSTEM_NAME=Windows \ + -DPNG_LIBRARY=$libs/libpng/lib/libpng.dll.a \ + -DPNG_PNG_INCLUDE_DIR=$libs/libpng/include \ + -DJPEG_LIBRARY=$libs/libjpeg/lib/libjpeg.dll.a \ + -DJPEG_INCLUDE_DIR=$libs/libjpeg/include \ + -DZLIB_LIBRARY=$libs/zlib/lib/libz.dll.a \ + -DZLIB_INCLUDE_DIR=$libs/zlib/include +) +if [ $with_sdl -eq 1 ]; then + tmp+=( + -DUSE_SDL2=ON + -DCMAKE_PREFIX_PATH=$libs/sdl2/lib/cmake + ) +else + tmp+=(-DUSE_SDL2=OFF) +fi +#[ $with_gl3 -eq 1 ] && tmp+=(-DENABLE_OPENGL=OFF -DENABLE_OPENGL3=ON) + +cmake . "${tmp[@]}" +make -j$(nproc) + +if [ "$1" = "package" ]; then + make DESTDIR=$PWD/_install install + # strip library + "${CXX%-*}-strip" --strip-unneeded _install/usr/local/lib/*.dll + # bundle the DLLs that are specific to Irrlicht (kind of a hack) + shopt -s nullglob + cp -p $libs/*/bin/{libjpeg,libpng,SDL}*.dll _install/usr/local/lib/ + # create a ZIP + (cd _install/usr/local; zip -9r "$OLDPWD/irrlicht-$variant$extras.zip" -- *) +fi +exit 0 diff --git a/irr/scripts/ci-get-mingw.sh b/irr/scripts/ci-get-mingw.sh new file mode 100755 index 000000000..9cf933fea --- /dev/null +++ b/irr/scripts/ci-get-mingw.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +topdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +name=llvm-mingw-20231128-ucrt-ubuntu-20.04-x86_64.tar.xz +wget "https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/$name" -O "$name" +sha256sum -w -c <(grep -F "$name" "$topdir/sha256sums.txt") +sudo tar -xaf "$name" -C /usr --strip-components=1 +rm -f "$name" diff --git a/irr/scripts/sha256sums.txt b/irr/scripts/sha256sums.txt new file mode 100644 index 000000000..0c080de3b --- /dev/null +++ b/irr/scripts/sha256sums.txt @@ -0,0 +1,9 @@ +0f21ff3be90311092fe32e0e30878ef3ae9d9437b8d9ac25ef279e0d84e9bb8e llvm-mingw-20231128-ucrt-ubuntu-20.04-x86_64.tar.xz +53dfd31285f470fcf0dca88217c5cf9c557729af6d103afae5936e72ddc38d3c libjpeg-3.0.1-win32.zip +3d44e0740914e6878300e30653aad39e974821b5d7f6c2567e246b4eb04a5324 libjpeg-3.0.1-win64.zip +6baf4e819bfb3573760524b5dc9a04b5e479090d6d2046b86cf39a3107c0071f libpng-1.6.40-win32.zip +c02e029f01fce44baea7f4aecfd2564bd8a03507c0c6af8b03339ae0452c8b7d libpng-1.6.40-win64.zip +f9f890af960e92fd3f532f2e9ac00681c33bc67a722e000dfdaeb41b0064f1a0 sdl2-2.28.5-win32.zip +8dde2c6963544b7d8a2e87c128ebbdf51ad0e70c7e2df986ff4e963ce9996d9b sdl2-2.28.5-win64.zip +8af10515d57dbfee5d2106cd66cafa2adeb4270d4c6047ccbf7e8b5d2d50681c zlib-1.3.1-win32.zip +ad43f5d23052590c65633530743e5d622cc76b33c109072e6fd7b487aff56bca zlib-1.3.1-win64.zip diff --git a/irr/src/Android/CAndroidAssetFileArchive.cpp b/irr/src/Android/CAndroidAssetFileArchive.cpp new file mode 100644 index 000000000..59df2d2a1 --- /dev/null +++ b/irr/src/Android/CAndroidAssetFileArchive.cpp @@ -0,0 +1,100 @@ +// Copyright (C) 2002-2011 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CAndroidAssetReader.h" + +#include "CReadFile.h" +#include "coreutil.h" +#include "CAndroidAssetFileArchive.h" +#include "CIrrDeviceAndroid.h" +#include "os.h" // for logging (just keep it in even when not needed right now as it's used all the time) + +#include +#include +#include + +namespace irr +{ +namespace io +{ + +CAndroidAssetFileArchive::CAndroidAssetFileArchive(AAssetManager *assetManager, bool ignoreCase, bool ignorePaths) : + CFileList("/asset", ignoreCase, ignorePaths), AssetManager(assetManager) +{ +} + +CAndroidAssetFileArchive::~CAndroidAssetFileArchive() +{ +} + +//! get the archive type +E_FILE_ARCHIVE_TYPE CAndroidAssetFileArchive::getType() const +{ + return EFAT_ANDROID_ASSET; +} + +const IFileList *CAndroidAssetFileArchive::getFileList() const +{ + // The assert_manager can not read directory names, so + // getFileList returns only files in folders which have been added. + return this; +} + +//! opens a file by file name +IReadFile *CAndroidAssetFileArchive::createAndOpenFile(const io::path &filename) +{ + CAndroidAssetReader *reader = new CAndroidAssetReader(AssetManager, filename); + + if (reader->isOpen()) + return reader; + + reader->drop(); + return NULL; +} + +//! opens a file by index +IReadFile *CAndroidAssetFileArchive::createAndOpenFile(u32 index) +{ + const io::path &filename(getFullFileName(index)); + if (filename.empty()) + return 0; + + return createAndOpenFile(filename); +} + +void CAndroidAssetFileArchive::addDirectoryToFileList(const io::path &dirname_) +{ + io::path dirname(dirname_); + fschar_t lastChar = dirname.lastChar(); + if (lastChar == '/' || lastChar == '\\') + dirname.erase(dirname.size() - 1); + + // os::Printer::log("addDirectoryToFileList:", dirname.c_str(), ELL_DEBUG); + if (findFile(dirname, true) >= 0) + return; // was already added + + AAssetDir *dir = AAssetManager_openDir(AssetManager, core::stringc(dirname).c_str()); + if (!dir) + return; + + // add directory itself + addItem(dirname, 0, 0, /*isDir*/ true, getFileCount()); + + // add all files in folder. + // Note: AAssetDir_getNextFileName does not return directory names (neither does any other NDK function) + while (const char *filename = AAssetDir_getNextFileName(dir)) { + core::stringc full_filename = dirname == "" ? filename + : dirname + "/" + filename; + + // We can't get the size without opening the file - so for performance + // reasons we set the file size to 0. + // TODO: Does this really cost so much performance that it's worth losing this information? Dirs are usually just added once at startup... + addItem(full_filename, /*offet*/ 0, /*size*/ 0, /*isDir*/ false, getFileCount()); + // os::Printer::log("addItem:", full_filename.c_str(), ELL_DEBUG); + } + AAssetDir_close(dir); +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/Android/CAndroidAssetFileArchive.h b/irr/src/Android/CAndroidAssetFileArchive.h new file mode 100644 index 000000000..3ca815ed5 --- /dev/null +++ b/irr/src/Android/CAndroidAssetFileArchive.h @@ -0,0 +1,58 @@ +// Copyright (C) 2012 Joerg Henrichs +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IReadFile.h" +#include "IFileArchive.h" +#include "CFileList.h" + +#include + +namespace irr +{ +namespace io +{ + +/*! + Android asset file system written August 2012 by J.Henrichs (later reworked by others). +*/ +class CAndroidAssetFileArchive : public virtual IFileArchive, + virtual CFileList +{ +public: + //! constructor + CAndroidAssetFileArchive(AAssetManager *assetManager, bool ignoreCase, bool ignorePaths); + + //! destructor + virtual ~CAndroidAssetFileArchive(); + + //! opens a file by file name + virtual IReadFile *createAndOpenFile(const io::path &filename); + + //! opens a file by index + virtual IReadFile *createAndOpenFile(u32 index); + + //! returns the list of files + virtual const IFileList *getFileList() const; + + //! get the archive type + virtual E_FILE_ARCHIVE_TYPE getType() const; + + //! Add a directory to read files from. Since the Android + //! API does not return names of directories, they need to + //! be added manually. + virtual void addDirectoryToFileList(const io::path &filename); + + //! return the name (id) of the file Archive + const io::path &getArchiveName() const override { return Path; } + +protected: + //! Android's asset manager + AAssetManager *AssetManager; + +}; // CAndroidAssetFileArchive + +} // end namespace io +} // end namespace irr diff --git a/irr/src/Android/CAndroidAssetReader.cpp b/irr/src/Android/CAndroidAssetReader.cpp new file mode 100644 index 000000000..bf3c51af8 --- /dev/null +++ b/irr/src/Android/CAndroidAssetReader.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2002-2011 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CAndroidAssetReader.h" + +#include "CReadFile.h" +#include "coreutil.h" +#include "CAndroidAssetReader.h" +#include "CIrrDeviceAndroid.h" + +#include +#include + +namespace irr +{ +namespace io +{ + +CAndroidAssetReader::CAndroidAssetReader(AAssetManager *assetManager, const io::path &filename) : + AssetManager(assetManager), Filename(filename) +{ + Asset = AAssetManager_open(AssetManager, + core::stringc(filename).c_str(), + AASSET_MODE_RANDOM); +} + +CAndroidAssetReader::~CAndroidAssetReader() +{ + if (Asset) + AAsset_close(Asset); +} + +size_t CAndroidAssetReader::read(void *buffer, size_t sizeToRead) +{ + int readBytes = AAsset_read(Asset, buffer, sizeToRead); + if (readBytes >= 0) + return size_t(readBytes); + return 0; // direct fd access is not possible (for example, if the asset is compressed). +} + +bool CAndroidAssetReader::seek(long finalPos, bool relativeMovement) +{ + off_t status = AAsset_seek(Asset, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET); + + return status + 1; +} + +long CAndroidAssetReader::getSize() const +{ + return AAsset_getLength(Asset); +} + +long CAndroidAssetReader::getPos() const +{ + return AAsset_getLength(Asset) - AAsset_getRemainingLength(Asset); +} + +const io::path &CAndroidAssetReader::getFileName() const +{ + return Filename; +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/Android/CAndroidAssetReader.h b/irr/src/Android/CAndroidAssetReader.h new file mode 100644 index 000000000..9f6156f3f --- /dev/null +++ b/irr/src/Android/CAndroidAssetReader.h @@ -0,0 +1,64 @@ +// Copyright (C) 2012 Joerg Henrichs +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IReadFile.h" + +struct AAssetManager; +struct AAsset; +struct ANativeActivity; + +namespace irr +{ +namespace io +{ + +class CAndroidAssetReader : public virtual IReadFile +{ +public: + CAndroidAssetReader(AAssetManager *assetManager, const io::path &filename); + + virtual ~CAndroidAssetReader(); + + //! Reads an amount of bytes from the file. + /** \param buffer Pointer to buffer where read bytes are written to. + \param sizeToRead Amount of bytes to read from the file. + \return How many bytes were read. */ + virtual size_t read(void *buffer, size_t sizeToRead); + + //! Changes position in file + /** \param finalPos Destination position in the file. + \param relativeMovement If set to true, the position in the file is + changed relative to current position. Otherwise the position is changed + from beginning of file. + \return True if successful, otherwise false. */ + virtual bool seek(long finalPos, bool relativeMovement = false); + + //! Get size of file. + /** \return Size of the file in bytes. */ + virtual long getSize() const; + + //! Get the current position in the file. + /** \return Current position in the file in bytes. */ + virtual long getPos() const; + + //! Get name of file. + /** \return File name as zero terminated character string. */ + virtual const io::path &getFileName() const; + + /** Return true if the file could be opened. */ + bool isOpen() const { return Asset != NULL; } + +private: + //! Android's asset manager + AAssetManager *AssetManager; + + // An asset, i.e. file + AAsset *Asset; + path Filename; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/Android/CIrrDeviceAndroid.cpp b/irr/src/Android/CIrrDeviceAndroid.cpp new file mode 100644 index 000000000..35c33ef6f --- /dev/null +++ b/irr/src/Android/CIrrDeviceAndroid.cpp @@ -0,0 +1,828 @@ +// Copyright (C) 2002-2007 Nikolaus Gebhardt +// Copyright (C) 2007-2011 Christian Stehno +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CIrrDeviceAndroid.h" + +#include "os.h" +#include "CFileSystem.h" +#include "CAndroidAssetReader.h" +#include "CAndroidAssetFileArchive.h" +#include "CKeyEventWrapper.h" +#include "CEGLManager.h" +#include "ISceneManager.h" +#include "IGUIEnvironment.h" +#include "CEGLManager.h" + +namespace irr +{ +namespace video +{ +IVideoDriver *createOGLES1Driver(const SIrrlichtCreationParameters ¶ms, + io::IFileSystem *io, video::IContextManager *contextManager); + +IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters ¶ms, + io::IFileSystem *io, video::IContextManager *contextManager); +} +} + +namespace irr +{ + +CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters ¶m) : + CIrrDeviceStub(param), Accelerometer(0), Gyroscope(0), Initialized(false), + Stopped(true), Paused(true), Focused(false), JNIEnvAttachedToVM(0) +{ +#ifdef _DEBUG + setDebugName("CIrrDeviceAndroid"); +#endif + + // Get the interface to the native Android activity. + Android = (android_app *)(param.PrivateData); + + // Set the private data so we can use it in any static callbacks. + Android->userData = this; + + // Set the default command handler. This is a callback function that the Android + // OS invokes to send the native activity messages. + Android->onAppCmd = handleAndroidCommand; + + createKeyMap(); + + // Create a sensor manager to receive touch screen events from the java activity. + SensorManager = ASensorManager_getInstance(); + SensorEventQueue = ASensorManager_createEventQueue(SensorManager, Android->looper, LOOPER_ID_USER, 0, 0); + Android->onInputEvent = handleInput; + + // Create EGL manager. + ContextManager = new video::CEGLManager(); + + os::Printer::log("Waiting for Android activity window to be created.", ELL_DEBUG); + + do { + s32 Events = 0; + android_poll_source *Source = 0; + + while ((ALooper_pollAll((!Initialized || isWindowActive()) ? 0 : -1, 0, &Events, (void **)&Source)) >= 0) { + if (Source) + Source->process(Android, Source); + } + } while (!Initialized); +} + +CIrrDeviceAndroid::~CIrrDeviceAndroid() +{ + if (GUIEnvironment) { + GUIEnvironment->drop(); + GUIEnvironment = 0; + } + + if (SceneManager) { + SceneManager->drop(); + SceneManager = 0; + } + + if (VideoDriver) { + VideoDriver->drop(); + VideoDriver = 0; + } +} + +bool CIrrDeviceAndroid::run() +{ + if (!Initialized) + return false; + + os::Timer::tick(); + + s32 id; + s32 Events = 0; + android_poll_source *Source = 0; + + while ((id = ALooper_pollAll(0, 0, &Events, (void **)&Source)) >= 0) { + if (Source) + Source->process(Android, Source); + + // if a sensor has data, we'll process it now. + if (id == LOOPER_ID_USER) { + ASensorEvent sensorEvent; + while (ASensorEventQueue_getEvents(SensorEventQueue, &sensorEvent, 1) > 0) { + switch (sensorEvent.type) { + case ASENSOR_TYPE_ACCELEROMETER: + SEvent accEvent; + accEvent.EventType = EET_ACCELEROMETER_EVENT; + accEvent.AccelerometerEvent.X = sensorEvent.acceleration.x; + accEvent.AccelerometerEvent.Y = sensorEvent.acceleration.y; + accEvent.AccelerometerEvent.Z = sensorEvent.acceleration.z; + + postEventFromUser(accEvent); + break; + + case ASENSOR_TYPE_GYROSCOPE: + SEvent gyroEvent; + gyroEvent.EventType = EET_GYROSCOPE_EVENT; + gyroEvent.GyroscopeEvent.X = sensorEvent.vector.x; + gyroEvent.GyroscopeEvent.Y = sensorEvent.vector.y; + gyroEvent.GyroscopeEvent.Z = sensorEvent.vector.z; + + postEventFromUser(gyroEvent); + break; + default: + break; + } + } + } + + if (!Initialized) + break; + } + + return Initialized; +} + +void CIrrDeviceAndroid::yield() +{ + struct timespec ts = {0, 1}; + nanosleep(&ts, NULL); +} + +void CIrrDeviceAndroid::sleep(u32 timeMs, bool pauseTimer) +{ + const bool wasStopped = Timer ? Timer->isStopped() : true; + + struct timespec ts; + ts.tv_sec = (time_t)(timeMs / 1000); + ts.tv_nsec = (long)(timeMs % 1000) * 1000000; + + if (pauseTimer && !wasStopped) + Timer->stop(); + + nanosleep(&ts, NULL); + + if (pauseTimer && !wasStopped) + Timer->start(); +} + +void CIrrDeviceAndroid::setWindowCaption(const wchar_t *text) +{ +} + +bool CIrrDeviceAndroid::isWindowActive() const +{ + return (Focused && !Paused && !Stopped); +} + +bool CIrrDeviceAndroid::isWindowFocused() const +{ + return Focused; +} + +bool CIrrDeviceAndroid::isWindowMinimized() const +{ + return !Focused; +} + +bool CIrrDeviceAndroid::isWindowVisible() const +{ + return !Stopped; +} + +void CIrrDeviceAndroid::closeDevice() +{ + ANativeActivity_finish(Android->activity); +} + +void CIrrDeviceAndroid::setResizable(bool resize) +{ +} + +void CIrrDeviceAndroid::minimizeWindow() +{ +} + +void CIrrDeviceAndroid::maximizeWindow() +{ +} + +void CIrrDeviceAndroid::restoreWindow() +{ +} + +core::position2di CIrrDeviceAndroid::getWindowPosition() +{ + return core::position2di(0, 0); +} + +E_DEVICE_TYPE CIrrDeviceAndroid::getType() const +{ + return EIDT_ANDROID; +} + +void CIrrDeviceAndroid::handleAndroidCommand(android_app *app, int32_t cmd) +{ + CIrrDeviceAndroid *device = (CIrrDeviceAndroid *)app->userData; + + SEvent event; + event.EventType = EET_SYSTEM_EVENT; + event.SystemEvent.EventType = ESET_ANDROID_CMD; + event.SystemEvent.AndroidCmd.Cmd = cmd; + if (device->postEventFromUser(event)) + return; + + switch (cmd) { + case APP_CMD_INPUT_CHANGED: + os::Printer::log("Android command APP_CMD_INPUT_CHANGED", ELL_DEBUG); + break; + case APP_CMD_WINDOW_RESIZED: + os::Printer::log("Android command APP_CMD_WINDOW_RESIZED", ELL_DEBUG); + break; + case APP_CMD_WINDOW_REDRAW_NEEDED: + os::Printer::log("Android command APP_CMD_WINDOW_REDRAW_NEEDED", ELL_DEBUG); + break; + case APP_CMD_SAVE_STATE: + os::Printer::log("Android command APP_CMD_SAVE_STATE", ELL_DEBUG); + break; + case APP_CMD_CONTENT_RECT_CHANGED: + os::Printer::log("Android command APP_CMD_CONTENT_RECT_CHANGED", ELL_DEBUG); + break; + case APP_CMD_CONFIG_CHANGED: + os::Printer::log("Android command APP_CMD_CONFIG_CHANGED", ELL_DEBUG); + break; + case APP_CMD_LOW_MEMORY: + os::Printer::log("Android command APP_CMD_LOW_MEMORY", ELL_DEBUG); + break; + case APP_CMD_START: + os::Printer::log("Android command APP_CMD_START", ELL_DEBUG); + device->Stopped = false; + break; + case APP_CMD_INIT_WINDOW: + os::Printer::log("Android command APP_CMD_INIT_WINDOW", ELL_DEBUG); + device->getExposedVideoData().OGLESAndroid.Window = app->window; + + if (device->CreationParams.WindowSize.Width == 0 || device->CreationParams.WindowSize.Height == 0) { + device->CreationParams.WindowSize.Width = ANativeWindow_getWidth(app->window); + device->CreationParams.WindowSize.Height = ANativeWindow_getHeight(app->window); + } + + device->getContextManager()->initialize(device->CreationParams, device->ExposedVideoData); + device->getContextManager()->generateSurface(); + device->getContextManager()->generateContext(); + device->getContextManager()->activateContext(device->getContextManager()->getContext()); + + if (!device->Initialized) { + io::CAndroidAssetFileArchive *assets = new io::CAndroidAssetFileArchive(device->Android->activity->assetManager, false, false); + assets->addDirectoryToFileList(""); + device->FileSystem->addFileArchive(assets); + assets->drop(); + + device->createDriver(); + + if (device->VideoDriver) + device->createGUIAndScene(); + } + device->Initialized = true; + break; + case APP_CMD_TERM_WINDOW: + os::Printer::log("Android command APP_CMD_TERM_WINDOW", ELL_DEBUG); + device->getContextManager()->destroySurface(); + break; + case APP_CMD_GAINED_FOCUS: + os::Printer::log("Android command APP_CMD_GAINED_FOCUS", ELL_DEBUG); + device->Focused = true; + break; + case APP_CMD_LOST_FOCUS: + os::Printer::log("Android command APP_CMD_LOST_FOCUS", ELL_DEBUG); + device->Focused = false; + break; + case APP_CMD_DESTROY: + os::Printer::log("Android command APP_CMD_DESTROY", ELL_DEBUG); + if (device->JNIEnvAttachedToVM) { + device->JNIEnvAttachedToVM = 0; + device->Android->activity->vm->DetachCurrentThread(); + } + device->Initialized = false; + break; + case APP_CMD_PAUSE: + os::Printer::log("Android command APP_CMD_PAUSE", ELL_DEBUG); + device->Paused = true; + break; + case APP_CMD_STOP: + os::Printer::log("Android command APP_CMD_STOP", ELL_DEBUG); + device->Stopped = true; + break; + case APP_CMD_RESUME: + os::Printer::log("Android command APP_CMD_RESUME", ELL_DEBUG); + device->Paused = false; + break; + default: + break; + } +} + +s32 CIrrDeviceAndroid::handleInput(android_app *app, AInputEvent *androidEvent) +{ + CIrrDeviceAndroid *device = (CIrrDeviceAndroid *)app->userData; + s32 status = 0; + + switch (AInputEvent_getType(androidEvent)) { + case AINPUT_EVENT_TYPE_MOTION: { + SEvent event; + event.EventType = EET_TOUCH_INPUT_EVENT; + + s32 eventAction = AMotionEvent_getAction(androidEvent); + s32 eventType = eventAction & AMOTION_EVENT_ACTION_MASK; + +#if 0 + // Useful for debugging. We might have to pass some of those infos on at some point. + // but preferably device independent (so iphone can use same irrlicht flags). + int32_t flags = AMotionEvent_getFlags(androidEvent); + os::Printer::log("flags: ", core::stringc(flags).c_str(), ELL_DEBUG); + int32_t metaState = AMotionEvent_getMetaState(androidEvent); + os::Printer::log("metaState: ", core::stringc(metaState).c_str(), ELL_DEBUG); + int32_t edgeFlags = AMotionEvent_getEdgeFlags(androidEvent); + os::Printer::log("edgeFlags: ", core::stringc(flags).c_str(), ELL_DEBUG); +#endif + + bool touchReceived = true; + + switch (eventType) { + case AMOTION_EVENT_ACTION_DOWN: + case AMOTION_EVENT_ACTION_POINTER_DOWN: + event.TouchInput.Event = ETIE_PRESSED_DOWN; + break; + case AMOTION_EVENT_ACTION_MOVE: + event.TouchInput.Event = ETIE_MOVED; + break; + case AMOTION_EVENT_ACTION_UP: + case AMOTION_EVENT_ACTION_POINTER_UP: + case AMOTION_EVENT_ACTION_CANCEL: + event.TouchInput.Event = ETIE_LEFT_UP; + break; + default: + touchReceived = false; + break; + } + + if (touchReceived) { + // Process all touches for move action. + if (event.TouchInput.Event == ETIE_MOVED) { + s32 pointerCount = AMotionEvent_getPointerCount(androidEvent); + + for (s32 i = 0; i < pointerCount; ++i) { + event.TouchInput.ID = AMotionEvent_getPointerId(androidEvent, i); + event.TouchInput.X = AMotionEvent_getX(androidEvent, i); + event.TouchInput.Y = AMotionEvent_getY(androidEvent, i); + event.TouchInput.touchedCount = AMotionEvent_getPointerCount(androidEvent); + + device->postEventFromUser(event); + } + } else // Process one touch for other actions. + { + s32 pointerIndex = (eventAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + + event.TouchInput.ID = AMotionEvent_getPointerId(androidEvent, pointerIndex); + event.TouchInput.X = AMotionEvent_getX(androidEvent, pointerIndex); + event.TouchInput.Y = AMotionEvent_getY(androidEvent, pointerIndex); + event.TouchInput.touchedCount = AMotionEvent_getPointerCount(androidEvent); + + device->postEventFromUser(event); + } + + status = 1; + } + } break; + case AINPUT_EVENT_TYPE_KEY: { + SEvent event; + event.EventType = EET_KEY_INPUT_EVENT; + + int32_t keyCode = AKeyEvent_getKeyCode(androidEvent); + // os::Printer::log("keyCode: ", core::stringc(keyCode).c_str(), ELL_DEBUG); + + int32_t keyAction = AKeyEvent_getAction(androidEvent); + int32_t keyMetaState = AKeyEvent_getMetaState(androidEvent); + + if (keyCode >= 0 && (u32)keyCode < device->KeyMap.size()) + event.KeyInput.Key = device->KeyMap[keyCode]; + else + event.KeyInput.Key = KEY_UNKNOWN; + event.KeyInput.SystemKeyCode = (u32)keyCode; + if (keyAction == AKEY_EVENT_ACTION_DOWN) + event.KeyInput.PressedDown = true; + else if (keyAction == AKEY_EVENT_ACTION_UP) + event.KeyInput.PressedDown = false; + else if (keyAction == AKEY_EVENT_ACTION_MULTIPLE) { + // TODO: Multiple duplicate key events have occurred in a row, + // or a complex string is being delivered. The repeat_count + // property of the key event contains the number of times the + // given key code should be executed. + // I guess this might necessary for more complicated i18n key input, + // but don't see yet how to handle this correctly. + } + + /* no use for meta keys so far. + if ( keyMetaState & AMETA_ALT_ON + || keyMetaState & AMETA_ALT_LEFT_ON + || keyMetaState & AMETA_ALT_RIGHT_ON ) + ; + // what is a sym? + if ( keyMetaState & AMETA_SYM_ON ) + ; + */ + if (keyMetaState & AMETA_SHIFT_ON || keyMetaState & AMETA_SHIFT_LEFT_ON || keyMetaState & AMETA_SHIFT_RIGHT_ON) + event.KeyInput.Shift = true; + else + event.KeyInput.Shift = false; + event.KeyInput.Control = false; + + // Having memory allocations + going through JNI for each key-press is pretty bad (slow). + // So we do it only for those keys which are likely text-characters and avoid it for all other keys. + // So it's fast for keys like game controller input and special keys. And text keys are typically + // only used or entering text and not for gaming on Android, so speed likely doesn't matter there too much. + if (event.KeyInput.Key > 0) { + // TODO: + // Not sure why we have to attach a JNIEnv here, but it won't work when doing that in the constructor or + // trying to use the activity->env. My best guess is that the event-handling happens in an own thread. + // It means JNIEnvAttachedToVM will never get detached as I don't know a safe way where to do that + // (we could attach & detach each time, but that would probably be slow) + // Also - it has to be each time as it get's invalid when the application mode changes. + if (device->Initialized && device->Android && device->Android->activity && device->Android->activity->vm) { + JavaVMAttachArgs attachArgs; + attachArgs.version = JNI_VERSION_1_6; + attachArgs.name = 0; + attachArgs.group = NULL; + + // Not a big problem calling it each time - it's a no-op when the thread already is attached. + // And we have to do that as someone else can have detached the thread in the meantime. + jint result = device->Android->activity->vm->AttachCurrentThread(&device->JNIEnvAttachedToVM, &attachArgs); + if (result == JNI_ERR) { + os::Printer::log("AttachCurrentThread for the JNI environment failed.", ELL_WARNING); + device->JNIEnvAttachedToVM = 0; + } + + if (device->JNIEnvAttachedToVM) { + jni::CKeyEventWrapper *keyEventWrapper = new jni::CKeyEventWrapper(device->JNIEnvAttachedToVM, keyAction, keyCode); + event.KeyInput.Char = keyEventWrapper->getUnicodeChar(keyMetaState); + delete keyEventWrapper; + } + } + if (event.KeyInput.Key == KEY_BACK) { + event.KeyInput.Char = 0x08; // same key-code as on other operating systems. Otherwise we have to handle too much system specific stuff in the editbox. + } + // os::Printer::log("char-code: ", core::stringc((int)event.KeyInput.Char).c_str(), ELL_DEBUG); + + } else { + // os::Printer::log("keyCode: ", core::stringc(keyCode).c_str(), ELL_DEBUG); + event.KeyInput.Char = 0; + } + + status = device->postEventFromUser(event); + } break; + default: + break; + } + + return status; +} + +void CIrrDeviceAndroid::createDriver() +{ + switch (CreationParams.DriverType) { + case video::EDT_OGLES1: +#ifdef _IRR_COMPILE_WITH_OGLES1_ + VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager); +#else + os::Printer::log("No OpenGL ES 1.0 support compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_OGLES2: +#ifdef _IRR_COMPILE_WITH_OGLES2_ + VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); +#else + os::Printer::log("No OpenGL ES 2.0 support compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_NULL: + VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); + break; + case video::EDT_OPENGL: + os::Printer::log("This driver is not available in Android. Try OpenGL ES 1.0 or ES 2.0.", ELL_ERROR); + break; + default: + os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); + break; + } +} + +video::SExposedVideoData &CIrrDeviceAndroid::getExposedVideoData() +{ + return ExposedVideoData; +} + +void CIrrDeviceAndroid::createKeyMap() +{ + KeyMap.set_used(223); + + KeyMap[0] = KEY_UNKNOWN; // AKEYCODE_UNKNOWN + KeyMap[1] = KEY_LBUTTON; // AKEYCODE_SOFT_LEFT + KeyMap[2] = KEY_RBUTTON; // AKEYCODE_SOFT_RIGHT + KeyMap[3] = KEY_HOME; // AKEYCODE_HOME + KeyMap[4] = KEY_CANCEL; // AKEYCODE_BACK + KeyMap[5] = KEY_UNKNOWN; // AKEYCODE_CALL + KeyMap[6] = KEY_UNKNOWN; // AKEYCODE_ENDCALL + KeyMap[7] = KEY_KEY_0; // AKEYCODE_0 + KeyMap[8] = KEY_KEY_1; // AKEYCODE_1 + KeyMap[9] = KEY_KEY_2; // AKEYCODE_2 + KeyMap[10] = KEY_KEY_3; // AKEYCODE_3 + KeyMap[11] = KEY_KEY_4; // AKEYCODE_4 + KeyMap[12] = KEY_KEY_5; // AKEYCODE_5 + KeyMap[13] = KEY_KEY_6; // AKEYCODE_6 + KeyMap[14] = KEY_KEY_7; // AKEYCODE_7 + KeyMap[15] = KEY_KEY_8; // AKEYCODE_8 + KeyMap[16] = KEY_KEY_9; // AKEYCODE_9 + KeyMap[17] = KEY_UNKNOWN; // AKEYCODE_STAR + KeyMap[18] = KEY_UNKNOWN; // AKEYCODE_POUND + KeyMap[19] = KEY_UP; // AKEYCODE_DPAD_UP + KeyMap[20] = KEY_DOWN; // AKEYCODE_DPAD_DOWN + KeyMap[21] = KEY_LEFT; // AKEYCODE_DPAD_LEFT + KeyMap[22] = KEY_RIGHT; // AKEYCODE_DPAD_RIGHT + KeyMap[23] = KEY_SELECT; // AKEYCODE_DPAD_CENTER + KeyMap[24] = KEY_VOLUME_DOWN; // AKEYCODE_VOLUME_UP + KeyMap[25] = KEY_VOLUME_UP; // AKEYCODE_VOLUME_DOWN + KeyMap[26] = KEY_UNKNOWN; // AKEYCODE_POWER + KeyMap[27] = KEY_UNKNOWN; // AKEYCODE_CAMERA + KeyMap[28] = KEY_CLEAR; // AKEYCODE_CLEAR + KeyMap[29] = KEY_KEY_A; // AKEYCODE_A + KeyMap[30] = KEY_KEY_B; // AKEYCODE_B + KeyMap[31] = KEY_KEY_C; // AKEYCODE_C + KeyMap[32] = KEY_KEY_D; // AKEYCODE_D + KeyMap[33] = KEY_KEY_E; // AKEYCODE_E + KeyMap[34] = KEY_KEY_F; // AKEYCODE_F + KeyMap[35] = KEY_KEY_G; // AKEYCODE_G + KeyMap[36] = KEY_KEY_H; // AKEYCODE_H + KeyMap[37] = KEY_KEY_I; // AKEYCODE_I + KeyMap[38] = KEY_KEY_J; // AKEYCODE_J + KeyMap[39] = KEY_KEY_K; // AKEYCODE_K + KeyMap[40] = KEY_KEY_L; // AKEYCODE_L + KeyMap[41] = KEY_KEY_M; // AKEYCODE_M + KeyMap[42] = KEY_KEY_N; // AKEYCODE_N + KeyMap[43] = KEY_KEY_O; // AKEYCODE_O + KeyMap[44] = KEY_KEY_P; // AKEYCODE_P + KeyMap[45] = KEY_KEY_Q; // AKEYCODE_Q + KeyMap[46] = KEY_KEY_R; // AKEYCODE_R + KeyMap[47] = KEY_KEY_S; // AKEYCODE_S + KeyMap[48] = KEY_KEY_T; // AKEYCODE_T + KeyMap[49] = KEY_KEY_U; // AKEYCODE_U + KeyMap[50] = KEY_KEY_V; // AKEYCODE_V + KeyMap[51] = KEY_KEY_W; // AKEYCODE_W + KeyMap[52] = KEY_KEY_X; // AKEYCODE_X + KeyMap[53] = KEY_KEY_Y; // AKEYCODE_Y + KeyMap[54] = KEY_KEY_Z; // AKEYCODE_Z + KeyMap[55] = KEY_COMMA; // AKEYCODE_COMMA + KeyMap[56] = KEY_PERIOD; // AKEYCODE_PERIOD + KeyMap[57] = KEY_MENU; // AKEYCODE_ALT_LEFT + KeyMap[58] = KEY_MENU; // AKEYCODE_ALT_RIGHT + KeyMap[59] = KEY_LSHIFT; // AKEYCODE_SHIFT_LEFT + KeyMap[60] = KEY_RSHIFT; // AKEYCODE_SHIFT_RIGHT + KeyMap[61] = KEY_TAB; // AKEYCODE_TAB + KeyMap[62] = KEY_SPACE; // AKEYCODE_SPACE + KeyMap[63] = KEY_UNKNOWN; // AKEYCODE_SYM + KeyMap[64] = KEY_UNKNOWN; // AKEYCODE_EXPLORER + KeyMap[65] = KEY_UNKNOWN; // AKEYCODE_ENVELOPE + KeyMap[66] = KEY_RETURN; // AKEYCODE_ENTER + KeyMap[67] = KEY_BACK; // AKEYCODE_DEL + KeyMap[68] = KEY_OEM_3; // AKEYCODE_GRAVE + KeyMap[69] = KEY_MINUS; // AKEYCODE_MINUS + KeyMap[70] = KEY_UNKNOWN; // AKEYCODE_EQUALS + KeyMap[71] = KEY_UNKNOWN; // AKEYCODE_LEFT_BRACKET + KeyMap[72] = KEY_UNKNOWN; // AKEYCODE_RIGHT_BRACKET + KeyMap[73] = KEY_UNKNOWN; // AKEYCODE_BACKSLASH + KeyMap[74] = KEY_UNKNOWN; // AKEYCODE_SEMICOLON + KeyMap[75] = KEY_UNKNOWN; // AKEYCODE_APOSTROPHE + KeyMap[76] = KEY_UNKNOWN; // AKEYCODE_SLASH + KeyMap[77] = KEY_UNKNOWN; // AKEYCODE_AT + KeyMap[78] = KEY_UNKNOWN; // AKEYCODE_NUM + KeyMap[79] = KEY_UNKNOWN; // AKEYCODE_HEADSETHOOK + KeyMap[80] = KEY_UNKNOWN; // AKEYCODE_FOCUS (*Camera* focus) + KeyMap[81] = KEY_PLUS; // AKEYCODE_PLUS + KeyMap[82] = KEY_MENU; // AKEYCODE_MENU + KeyMap[83] = KEY_UNKNOWN; // AKEYCODE_NOTIFICATION + KeyMap[84] = KEY_UNKNOWN; // AKEYCODE_SEARCH + KeyMap[85] = KEY_MEDIA_PLAY_PAUSE; // AKEYCODE_MEDIA_PLAY_PAUSE + KeyMap[86] = KEY_MEDIA_STOP; // AKEYCODE_MEDIA_STOP + KeyMap[87] = KEY_MEDIA_NEXT_TRACK; // AKEYCODE_MEDIA_NEXT + KeyMap[88] = KEY_MEDIA_PREV_TRACK; // AKEYCODE_MEDIA_PREVIOUS + KeyMap[89] = KEY_UNKNOWN; // AKEYCODE_MEDIA_REWIND + KeyMap[90] = KEY_UNKNOWN; // AKEYCODE_MEDIA_FAST_FORWARD + KeyMap[91] = KEY_VOLUME_MUTE; // AKEYCODE_MUTE + KeyMap[92] = KEY_PRIOR; // AKEYCODE_PAGE_UP + KeyMap[93] = KEY_NEXT; // AKEYCODE_PAGE_DOWN + KeyMap[94] = KEY_UNKNOWN; // AKEYCODE_PICTSYMBOLS + KeyMap[95] = KEY_UNKNOWN; // AKEYCODE_SWITCH_CHARSET + + // following look like controller inputs + KeyMap[96] = KEY_UNKNOWN; // AKEYCODE_BUTTON_A + KeyMap[97] = KEY_UNKNOWN; // AKEYCODE_BUTTON_B + KeyMap[98] = KEY_UNKNOWN; // AKEYCODE_BUTTON_C + KeyMap[99] = KEY_UNKNOWN; // AKEYCODE_BUTTON_X + KeyMap[100] = KEY_UNKNOWN; // AKEYCODE_BUTTON_Y + KeyMap[101] = KEY_UNKNOWN; // AKEYCODE_BUTTON_Z + KeyMap[102] = KEY_UNKNOWN; // AKEYCODE_BUTTON_L1 + KeyMap[103] = KEY_UNKNOWN; // AKEYCODE_BUTTON_R1 + KeyMap[104] = KEY_UNKNOWN; // AKEYCODE_BUTTON_L2 + KeyMap[105] = KEY_UNKNOWN; // AKEYCODE_BUTTON_R2 + KeyMap[106] = KEY_UNKNOWN; // AKEYCODE_BUTTON_THUMBL + KeyMap[107] = KEY_UNKNOWN; // AKEYCODE_BUTTON_THUMBR + KeyMap[108] = KEY_UNKNOWN; // AKEYCODE_BUTTON_START + KeyMap[109] = KEY_UNKNOWN; // AKEYCODE_BUTTON_SELECT + KeyMap[110] = KEY_UNKNOWN; // AKEYCODE_BUTTON_MODE + + KeyMap[111] = KEY_ESCAPE; // AKEYCODE_ESCAPE + KeyMap[112] = KEY_DELETE; // AKEYCODE_FORWARD_DEL + KeyMap[113] = KEY_CONTROL; // AKEYCODE_CTRL_LEFT + KeyMap[114] = KEY_CONTROL; // AKEYCODE_CTRL_RIGHT + KeyMap[115] = KEY_CAPITAL; // AKEYCODE_CAPS_LOCK + KeyMap[116] = KEY_SCROLL; // AKEYCODE_SCROLL_LOCK + KeyMap[117] = KEY_UNKNOWN; // AKEYCODE_META_LEFT + KeyMap[118] = KEY_UNKNOWN; // AKEYCODE_META_RIGHT + KeyMap[119] = KEY_UNKNOWN; // AKEYCODE_FUNCTION + KeyMap[120] = KEY_SNAPSHOT; // AKEYCODE_SYSRQ + KeyMap[121] = KEY_PAUSE; // AKEYCODE_BREAK + KeyMap[122] = KEY_HOME; // AKEYCODE_MOVE_HOME + KeyMap[123] = KEY_END; // AKEYCODE_MOVE_END + KeyMap[124] = KEY_INSERT; // AKEYCODE_INSERT + KeyMap[125] = KEY_UNKNOWN; // AKEYCODE_FORWARD + KeyMap[126] = KEY_PLAY; // AKEYCODE_MEDIA_PLAY + KeyMap[127] = KEY_MEDIA_PLAY_PAUSE; // AKEYCODE_MEDIA_PAUSE + KeyMap[128] = KEY_UNKNOWN; // AKEYCODE_MEDIA_CLOSE + KeyMap[129] = KEY_UNKNOWN; // AKEYCODE_MEDIA_EJECT + KeyMap[130] = KEY_UNKNOWN; // AKEYCODE_MEDIA_RECORD + KeyMap[131] = KEY_F1; // AKEYCODE_F1 + KeyMap[132] = KEY_F2; // AKEYCODE_F2 + KeyMap[133] = KEY_F3; // AKEYCODE_F3 + KeyMap[134] = KEY_F4; // AKEYCODE_F4 + KeyMap[135] = KEY_F5; // AKEYCODE_F5 + KeyMap[136] = KEY_F6; // AKEYCODE_F6 + KeyMap[137] = KEY_F7; // AKEYCODE_F7 + KeyMap[138] = KEY_F8; // AKEYCODE_F8 + KeyMap[139] = KEY_F9; // AKEYCODE_F9 + KeyMap[140] = KEY_F10; // AKEYCODE_F10 + KeyMap[141] = KEY_F11; // AKEYCODE_F11 + KeyMap[142] = KEY_F12; // AKEYCODE_F12 + KeyMap[143] = KEY_NUMLOCK; // AKEYCODE_NUM_LOCK + KeyMap[144] = KEY_NUMPAD0; // AKEYCODE_NUMPAD_0 + KeyMap[145] = KEY_NUMPAD1; // AKEYCODE_NUMPAD_1 + KeyMap[146] = KEY_NUMPAD2; // AKEYCODE_NUMPAD_2 + KeyMap[147] = KEY_NUMPAD3; // AKEYCODE_NUMPAD_3 + KeyMap[148] = KEY_NUMPAD4; // AKEYCODE_NUMPAD_4 + KeyMap[149] = KEY_NUMPAD5; // AKEYCODE_NUMPAD_5 + KeyMap[150] = KEY_NUMPAD6; // AKEYCODE_NUMPAD_6 + KeyMap[151] = KEY_NUMPAD7; // AKEYCODE_NUMPAD_7 + KeyMap[152] = KEY_NUMPAD8; // AKEYCODE_NUMPAD_8 + KeyMap[153] = KEY_NUMPAD9; // AKEYCODE_NUMPAD_9 + KeyMap[154] = KEY_DIVIDE; // AKEYCODE_NUMPAD_DIVIDE + KeyMap[155] = KEY_MULTIPLY; // AKEYCODE_NUMPAD_MULTIPLY + KeyMap[156] = KEY_SUBTRACT; // AKEYCODE_NUMPAD_SUBTRACT + KeyMap[157] = KEY_ADD; // AKEYCODE_NUMPAD_ADD + KeyMap[158] = KEY_UNKNOWN; // AKEYCODE_NUMPAD_DOT + KeyMap[159] = KEY_COMMA; // AKEYCODE_NUMPAD_COMMA + KeyMap[160] = KEY_RETURN; // AKEYCODE_NUMPAD_ENTER + KeyMap[161] = KEY_UNKNOWN; // AKEYCODE_NUMPAD_EQUALS + KeyMap[162] = KEY_UNKNOWN; // AKEYCODE_NUMPAD_LEFT_PAREN + KeyMap[163] = KEY_UNKNOWN; // AKEYCODE_NUMPAD_RIGHT_PAREN + KeyMap[164] = KEY_VOLUME_MUTE; // AKEYCODE_VOLUME_MUTE + KeyMap[165] = KEY_UNKNOWN; // AKEYCODE_INFO + KeyMap[166] = KEY_UNKNOWN; // AKEYCODE_CHANNEL_UP + KeyMap[167] = KEY_UNKNOWN; // AKEYCODE_CHANNEL_DOWN + KeyMap[168] = KEY_ZOOM; // AKEYCODE_ZOOM_IN + KeyMap[169] = KEY_UNKNOWN; // AKEYCODE_ZOOM_OUT + KeyMap[170] = KEY_UNKNOWN; // AKEYCODE_TV + KeyMap[171] = KEY_UNKNOWN; // AKEYCODE_WINDOW + KeyMap[172] = KEY_UNKNOWN; // AKEYCODE_GUIDE + KeyMap[173] = KEY_UNKNOWN; // AKEYCODE_DVR + KeyMap[174] = KEY_UNKNOWN; // AKEYCODE_BOOKMARK + KeyMap[175] = KEY_UNKNOWN; // AKEYCODE_CAPTIONS + KeyMap[176] = KEY_UNKNOWN; // AKEYCODE_SETTINGS + KeyMap[177] = KEY_UNKNOWN; // AKEYCODE_TV_POWER + KeyMap[178] = KEY_UNKNOWN; // AKEYCODE_TV_INPUT + KeyMap[179] = KEY_UNKNOWN; // AKEYCODE_STB_POWER + KeyMap[180] = KEY_UNKNOWN; // AKEYCODE_STB_INPUT + KeyMap[181] = KEY_UNKNOWN; // AKEYCODE_AVR_POWER + KeyMap[182] = KEY_UNKNOWN; // AKEYCODE_AVR_INPUT + KeyMap[183] = KEY_UNKNOWN; // AKEYCODE_PROG_RED + KeyMap[184] = KEY_UNKNOWN; // AKEYCODE_PROG_GREEN + KeyMap[185] = KEY_UNKNOWN; // AKEYCODE_PROG_YELLOW + KeyMap[186] = KEY_UNKNOWN; // AKEYCODE_PROG_BLUE + KeyMap[187] = KEY_UNKNOWN; // AKEYCODE_APP_SWITCH + KeyMap[188] = KEY_UNKNOWN; // AKEYCODE_BUTTON_1 + KeyMap[189] = KEY_UNKNOWN; // AKEYCODE_BUTTON_2 + KeyMap[190] = KEY_UNKNOWN; // AKEYCODE_BUTTON_3 + KeyMap[191] = KEY_UNKNOWN; // AKEYCODE_BUTTON_4 + KeyMap[192] = KEY_UNKNOWN; // AKEYCODE_BUTTON_5 + KeyMap[193] = KEY_UNKNOWN; // AKEYCODE_BUTTON_6 + KeyMap[194] = KEY_UNKNOWN; // AKEYCODE_BUTTON_7 + KeyMap[195] = KEY_UNKNOWN; // AKEYCODE_BUTTON_8 + KeyMap[196] = KEY_UNKNOWN; // AKEYCODE_BUTTON_9 + KeyMap[197] = KEY_UNKNOWN; // AKEYCODE_BUTTON_10 + KeyMap[198] = KEY_UNKNOWN; // AKEYCODE_BUTTON_11 + KeyMap[199] = KEY_UNKNOWN; // AKEYCODE_BUTTON_12 + KeyMap[200] = KEY_UNKNOWN; // AKEYCODE_BUTTON_13 + KeyMap[201] = KEY_UNKNOWN; // AKEYCODE_BUTTON_14 + KeyMap[202] = KEY_UNKNOWN; // AKEYCODE_BUTTON_15 + KeyMap[203] = KEY_UNKNOWN; // AKEYCODE_BUTTON_16 + KeyMap[204] = KEY_UNKNOWN; // AKEYCODE_LANGUAGE_SWITCH + KeyMap[205] = KEY_UNKNOWN; // AKEYCODE_MANNER_MODE + KeyMap[206] = KEY_UNKNOWN; // AKEYCODE_3D_MODE + KeyMap[207] = KEY_UNKNOWN; // AKEYCODE_CONTACTS + KeyMap[208] = KEY_UNKNOWN; // AKEYCODE_CALENDAR + KeyMap[209] = KEY_UNKNOWN; // AKEYCODE_MUSIC + KeyMap[210] = KEY_UNKNOWN; // AKEYCODE_CALCULATOR + KeyMap[211] = KEY_UNKNOWN; // AKEYCODE_ZENKAKU_HANKAKU + KeyMap[212] = KEY_UNKNOWN; // AKEYCODE_EISU + KeyMap[213] = KEY_UNKNOWN; // AKEYCODE_MUHENKAN + KeyMap[214] = KEY_UNKNOWN; // AKEYCODE_HENKAN + KeyMap[215] = KEY_UNKNOWN; // AKEYCODE_KATAKANA_HIRAGANA + KeyMap[216] = KEY_UNKNOWN; // AKEYCODE_YEN + KeyMap[217] = KEY_UNKNOWN; // AKEYCODE_RO + KeyMap[218] = KEY_UNKNOWN; // AKEYCODE_KANA + KeyMap[219] = KEY_UNKNOWN; // AKEYCODE_ASSIST + KeyMap[220] = KEY_UNKNOWN; // AKEYCODE_BRIGHTNESS_DOWN + KeyMap[221] = KEY_UNKNOWN; // AKEYCODE_BRIGHTNESS_UP , + KeyMap[222] = KEY_UNKNOWN; // AKEYCODE_MEDIA_AUDIO_TRACK +} + +bool CIrrDeviceAndroid::activateAccelerometer(float updateInterval) +{ + if (!isAccelerometerAvailable()) + return false; + + ASensorEventQueue_enableSensor(SensorEventQueue, Accelerometer); + ASensorEventQueue_setEventRate(SensorEventQueue, Accelerometer, (int32_t)(updateInterval * 1000.f * 1000.f)); // in microseconds + + os::Printer::log("Activated accelerometer", ELL_DEBUG); + return true; +} + +bool CIrrDeviceAndroid::deactivateAccelerometer() +{ + if (Accelerometer) { + ASensorEventQueue_disableSensor(SensorEventQueue, Accelerometer); + Accelerometer = 0; + os::Printer::log("Deactivated accelerometer", ELL_DEBUG); + return true; + } + + return false; +} + +bool CIrrDeviceAndroid::isAccelerometerActive() +{ + return (Accelerometer != 0); +} + +bool CIrrDeviceAndroid::isAccelerometerAvailable() +{ + if (!Accelerometer) + Accelerometer = ASensorManager_getDefaultSensor(SensorManager, ASENSOR_TYPE_ACCELEROMETER); + + return (Accelerometer != 0); +} + +bool CIrrDeviceAndroid::activateGyroscope(float updateInterval) +{ + if (!isGyroscopeAvailable()) + return false; + + ASensorEventQueue_enableSensor(SensorEventQueue, Gyroscope); + ASensorEventQueue_setEventRate(SensorEventQueue, Gyroscope, (int32_t)(updateInterval * 1000.f * 1000.f)); // in microseconds + + os::Printer::log("Activated gyroscope", ELL_DEBUG); + return true; +} + +bool CIrrDeviceAndroid::deactivateGyroscope() +{ + if (Gyroscope) { + ASensorEventQueue_disableSensor(SensorEventQueue, Gyroscope); + Gyroscope = 0; + os::Printer::log("Deactivated gyroscope", ELL_DEBUG); + return true; + } + + return false; +} + +bool CIrrDeviceAndroid::isGyroscopeActive() +{ + return (Gyroscope != 0); +} + +bool CIrrDeviceAndroid::isGyroscopeAvailable() +{ + if (!Gyroscope) + Gyroscope = ASensorManager_getDefaultSensor(SensorManager, ASENSOR_TYPE_GYROSCOPE); + + return (Gyroscope != 0); +} + +} // end namespace irr diff --git a/irr/src/Android/CIrrDeviceAndroid.h b/irr/src/Android/CIrrDeviceAndroid.h new file mode 100644 index 000000000..19a35b152 --- /dev/null +++ b/irr/src/Android/CIrrDeviceAndroid.h @@ -0,0 +1,98 @@ +// Copyright (C) 2002-2011 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "CIrrDeviceStub.h" +#include "IrrlichtDevice.h" +#include "ICursorControl.h" + +#include +#include + +namespace irr +{ +class CIrrDeviceAndroid : public CIrrDeviceStub +{ +public: + CIrrDeviceAndroid(const SIrrlichtCreationParameters ¶m); + + virtual ~CIrrDeviceAndroid(); + + virtual bool run(); + + virtual void yield(); + + virtual void sleep(u32 timeMs, bool pauseTimer = false); + + virtual void setWindowCaption(const wchar_t *text); + + virtual bool isWindowActive() const; + + virtual bool isWindowFocused() const; + + virtual bool isWindowMinimized() const; + + virtual bool isWindowVisible() const; + + virtual void closeDevice(); + + virtual void setResizable(bool resize = false); + + virtual void minimizeWindow(); + + virtual void maximizeWindow(); + + virtual void restoreWindow(); + + virtual core::position2di getWindowPosition(); + + virtual E_DEVICE_TYPE getType() const; + + virtual bool activateAccelerometer(float updateInterval); + + virtual bool deactivateAccelerometer(); + + virtual bool isAccelerometerActive(); + + virtual bool isAccelerometerAvailable(); + + virtual bool activateGyroscope(float updateInterval); + + virtual bool deactivateGyroscope(); + + virtual bool isGyroscopeActive(); + + virtual bool isGyroscopeAvailable(); + +private: + static void handleAndroidCommand(android_app *app, int32_t cmd); + + static s32 handleInput(android_app *app, AInputEvent *event); + + void createDriver(); + + void createKeyMap(); + + video::SExposedVideoData &getExposedVideoData(); + + android_app *Android; + ASensorManager *SensorManager; + ASensorEventQueue *SensorEventQueue; + const ASensor *Accelerometer; + const ASensor *Gyroscope; + + bool Initialized; + bool Stopped; + bool Paused; + bool Focused; + + JNIEnv *JNIEnvAttachedToVM; + + video::SExposedVideoData ExposedVideoData; + + core::array KeyMap; +}; + +} // end namespace irr diff --git a/irr/src/Android/CKeyEventWrapper.cpp b/irr/src/Android/CKeyEventWrapper.cpp new file mode 100644 index 000000000..4008c29c2 --- /dev/null +++ b/irr/src/Android/CKeyEventWrapper.cpp @@ -0,0 +1,52 @@ +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CKeyEventWrapper.h" + +#include "os.h" + +namespace irr +{ +namespace jni +{ + +jclass CKeyEventWrapper::Class_KeyEvent = 0; +jmethodID CKeyEventWrapper::Method_constructor = 0; +jmethodID CKeyEventWrapper::Method_getUnicodeChar = 0; + +CKeyEventWrapper::CKeyEventWrapper(JNIEnv *jniEnv, int action, int code) : + JniEnv(jniEnv), JniKeyEvent(0) +{ + if (JniEnv) { + if (!Class_KeyEvent) { + // Find java classes & functions on first call + os::Printer::log("CKeyEventWrapper first initialize", ELL_DEBUG); + jclass localClass = JniEnv->FindClass("android/view/KeyEvent"); + if (localClass) { + Class_KeyEvent = reinterpret_cast(JniEnv->NewGlobalRef(localClass)); + } + + Method_constructor = JniEnv->GetMethodID(Class_KeyEvent, "", "(II)V"); + Method_getUnicodeChar = JniEnv->GetMethodID(Class_KeyEvent, "getUnicodeChar", "(I)I"); + } + + if (Class_KeyEvent && Method_constructor) { + JniKeyEvent = JniEnv->NewObject(Class_KeyEvent, Method_constructor, action, code); + } else { + os::Printer::log("CKeyEventWrapper didn't find JNI classes/methods", ELL_WARNING); + } + } +} + +CKeyEventWrapper::~CKeyEventWrapper() +{ + JniEnv->DeleteLocalRef(JniKeyEvent); +} + +int CKeyEventWrapper::getUnicodeChar(int metaState) +{ + return JniEnv->CallIntMethod(JniKeyEvent, Method_getUnicodeChar, metaState); +} + +} // namespace jni +} // namespace irr diff --git a/irr/src/Android/CKeyEventWrapper.h b/irr/src/Android/CKeyEventWrapper.h new file mode 100644 index 000000000..9eb68697a --- /dev/null +++ b/irr/src/Android/CKeyEventWrapper.h @@ -0,0 +1,35 @@ +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include + +struct android_app; + +namespace irr +{ +namespace jni +{ + +//! Minimal JNI wrapper class around android.view.KeyEvent +//! NOTE: Only functions we actually use in the engine are wrapped +//! This is currently not written to support multithreading - meaning threads are not attached/detached to the Java VM (to be discussed) +class CKeyEventWrapper +{ +public: + CKeyEventWrapper(JNIEnv *jniEnv, int action, int code); + ~CKeyEventWrapper(); + + int getUnicodeChar(int metaState); + +private: + static jclass Class_KeyEvent; + static jmethodID Method_getUnicodeChar; + static jmethodID Method_constructor; + JNIEnv *JniEnv; + jobject JniKeyEvent; // this object in java +}; + +} // namespace jni +} // namespace irr diff --git a/irr/src/BuiltInFont.h b/irr/src/BuiltInFont.h new file mode 100644 index 000000000..1df5b7da4 --- /dev/null +++ b/irr/src/BuiltInFont.h @@ -0,0 +1,135 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +// header file generated by xxd +// for the source bitmap, see builtInFont.png + +namespace irr +{ +namespace gui +{ +const u8 BuiltInFontData[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, + 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, + 0x04, 0x03, 0x00, 0x00, 0x00, 0x31, 0x10, 0x7c, 0xf8, 0x00, 0x00, 0x00, + 0x0f, 0x50, 0x4c, 0x54, 0x45, 0x18, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xc8, 0xc8, 0xae, + 0x00, 0x00, 0x05, 0x11, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0x62, 0x50, + 0x06, 0xf0, 0x62, 0x06, 0xb6, 0xed, 0xf4, 0x3a, 0x0c, 0xff, 0xf1, 0xba, + 0x00, 0xb9, 0x41, 0xde, 0x06, 0xd9, 0x7f, 0xba, 0x07, 0x98, 0x10, 0x6a, + 0x1f, 0xd2, 0xe2, 0x9f, 0xa0, 0xf8, 0x74, 0xaa, 0x65, 0xc9, 0x32, 0x23, + 0x39, 0xc4, 0xc1, 0xe9, 0xc5, 0x83, 0x0b, 0xd6, 0x58, 0x7d, 0xf4, 0xe9, + 0xec, 0x6a, 0xac, 0x6b, 0xd5, 0xc7, 0x9e, 0xfc, 0x17, 0x62, 0x09, 0x09, + 0x4c, 0x60, 0x59, 0x0b, 0x99, 0x0a, 0x6b, 0xde, 0xc1, 0x60, 0x62, 0x82, + 0xd2, 0xc0, 0x00, 0x90, 0x58, 0x21, 0xc2, 0xc6, 0x02, 0xef, 0x00, 0x16, + 0xc1, 0x2a, 0x2e, 0x46, 0x13, 0xb5, 0x0a, 0x00, 0x48, 0xc5, 0xef, 0x62, + 0x63, 0xde, 0x00, 0xd4, 0x28, 0xea, 0xc7, 0x77, 0x8a, 0x82, 0x07, 0xa0, + 0xcb, 0xe0, 0x0c, 0x80, 0x42, 0x41, 0x0b, 0x20, 0x83, 0xb0, 0xc1, 0xc2, + 0x8d, 0x22, 0x46, 0x12, 0x13, 0x1c, 0xec, 0x5b, 0x05, 0x03, 0xd0, 0x9d, + 0xc9, 0x00, 0xbc, 0x68, 0x21, 0x10, 0xa4, 0x01, 0xe8, 0x8a, 0x68, 0xb1, + 0x24, 0x73, 0x88, 0x30, 0x2d, 0xc8, 0x98, 0x11, 0x66, 0x7e, 0x02, 0x7c, + 0x26, 0x16, 0x6f, 0xc8, 0xf3, 0x0b, 0x9e, 0xd0, 0xf1, 0xb9, 0xfc, 0x3e, + 0x9d, 0x3d, 0x79, 0xd2, 0x61, 0xf4, 0xeb, 0x4c, 0x7e, 0x2c, 0x6e, 0x0e, + 0x41, 0x29, 0xab, 0x37, 0x53, 0xed, 0xf2, 0x46, 0xe3, 0x59, 0xfd, 0x53, + 0x09, 0x28, 0x80, 0x51, 0x8c, 0xb2, 0x4c, 0x42, 0xca, 0xdc, 0x32, 0xb4, + 0x26, 0xc8, 0xb2, 0x9a, 0x0f, 0xee, 0x2e, 0x8c, 0x29, 0x1d, 0xeb, 0xd4, + 0x54, 0x3d, 0x00, 0x62, 0x03, 0x70, 0x93, 0xfb, 0x01, 0xdd, 0xa6, 0x52, + 0xc2, 0xb8, 0x81, 0x98, 0x3a, 0x4a, 0x01, 0xca, 0x57, 0xdb, 0x92, 0xf0, + 0x37, 0xe3, 0x0a, 0x26, 0x15, 0x0d, 0x0d, 0x80, 0x59, 0x2a, 0x8b, 0x1f, + 0x01, 0xa6, 0x02, 0x50, 0x3f, 0xcd, 0x3f, 0xb6, 0xe0, 0xb6, 0x40, 0xbd, + 0x60, 0x8a, 0x47, 0xb3, 0x66, 0xe6, 0xf3, 0x10, 0xa7, 0x7e, 0x8b, 0x9e, + 0x65, 0x18, 0x4f, 0x01, 0xb1, 0x89, 0xc2, 0x7f, 0x2f, 0xe5, 0xe6, 0x10, + 0xb4, 0xac, 0xde, 0x4d, 0xb5, 0xcb, 0xdf, 0x34, 0xde, 0x92, 0x1e, 0x1b, + 0x73, 0x0f, 0xe7, 0xa0, 0x73, 0x9f, 0x26, 0x94, 0xcb, 0x75, 0x3e, 0x11, + 0xdd, 0xfd, 0x40, 0x4f, 0x9b, 0x90, 0x7c, 0x7f, 0x85, 0x63, 0x45, 0x42, + 0x30, 0x41, 0x1b, 0x71, 0x67, 0x8a, 0x98, 0x3d, 0x6b, 0x60, 0x07, 0x90, + 0xc0, 0x86, 0x59, 0xb1, 0xa9, 0xbc, 0x06, 0x28, 0x11, 0xc4, 0x6c, 0x5c, + 0x2e, 0x02, 0x3c, 0x8c, 0xa9, 0xc8, 0xc4, 0x1d, 0xdb, 0x82, 0x24, 0x12, + 0xd0, 0x4b, 0x80, 0x2d, 0x3e, 0x52, 0x56, 0x96, 0xa7, 0x4d, 0xf0, 0xd1, + 0x42, 0x37, 0xaa, 0x7f, 0xf5, 0x0e, 0x00, 0xdd, 0x01, 0x48, 0xf7, 0x06, + 0x0c, 0xf1, 0x00, 0x4c, 0xe1, 0xc9, 0x09, 0x40, 0xf6, 0x16, 0xfe, 0x4d, + 0x32, 0x7f, 0x31, 0x7f, 0x2f, 0x43, 0xca, 0xd1, 0x3a, 0x27, 0x9d, 0xfb, + 0x34, 0xa1, 0x5c, 0xae, 0xd3, 0x7b, 0xc5, 0x30, 0xf3, 0x5a, 0xce, 0xa3, + 0x0e, 0xa3, 0xcd, 0x68, 0x62, 0xc7, 0x46, 0xba, 0xc2, 0x9f, 0x88, 0x00, + 0x3c, 0xef, 0x5d, 0xfe, 0x49, 0xe6, 0xf5, 0x69, 0x60, 0x1b, 0x7e, 0x02, + 0xf0, 0x6b, 0x00, 0x97, 0xbd, 0x04, 0x85, 0xac, 0x98, 0xb0, 0x62, 0x42, + 0x83, 0xc4, 0x32, 0x21, 0x78, 0xad, 0xb9, 0xa3, 0x9a, 0x5c, 0x68, 0x09, + 0x17, 0x4d, 0x58, 0xc6, 0x52, 0x9d, 0xd1, 0x96, 0x35, 0x00, 0x6b, 0x3a, + 0xdc, 0x2d, 0x00, 0x3b, 0x80, 0x5e, 0x00, 0x34, 0xdd, 0x18, 0x0d, 0x16, + 0x5b, 0x05, 0x04, 0xa3, 0xdc, 0x01, 0x98, 0x16, 0xe6, 0x92, 0x56, 0x80, + 0xa5, 0x1c, 0x2d, 0x54, 0xf4, 0xe2, 0xac, 0x8e, 0x84, 0x5b, 0x7c, 0x00, + 0x46, 0xe4, 0x37, 0x00, 0xcc, 0x4d, 0x9e, 0xc3, 0xcc, 0x67, 0x2f, 0x15, + 0x75, 0x46, 0xcb, 0xdc, 0x67, 0x4d, 0xc7, 0x46, 0xd6, 0x4a, 0x2f, 0x18, + 0x6f, 0x6b, 0xb9, 0xff, 0x57, 0x4c, 0x16, 0x7e, 0x4b, 0xa9, 0x0c, 0x33, + 0x3e, 0x01, 0x30, 0x42, 0xc3, 0xaf, 0xcf, 0x2a, 0x08, 0xa2, 0x8c, 0xfe, + 0xac, 0x02, 0x41, 0xdc, 0x3e, 0xf8, 0x14, 0x40, 0x00, 0x9f, 0x56, 0x30, + 0x34, 0x07, 0x63, 0xde, 0x95, 0x73, 0xdb, 0xa7, 0x00, 0xf7, 0xbb, 0xf2, + 0xdb, 0x3a, 0xdc, 0x5f, 0xf3, 0xbe, 0x61, 0xfb, 0xf6, 0x5d, 0x5a, 0xa7, + 0x84, 0x5d, 0xbc, 0xdd, 0x7f, 0x00, 0x36, 0x75, 0xcc, 0x25, 0x7e, 0x90, + 0xe4, 0x8d, 0x76, 0x2c, 0xa1, 0x6c, 0xad, 0xcd, 0x09, 0xb3, 0x11, 0x07, + 0xd0, 0x18, 0x70, 0x43, 0x9d, 0xa9, 0x11, 0xcb, 0xf7, 0x53, 0x2e, 0x36, + 0xa0, 0x13, 0xc0, 0xcc, 0x25, 0xb3, 0x00, 0x06, 0x6c, 0x33, 0x32, 0x4e, + 0x13, 0x91, 0x86, 0x30, 0x54, 0x04, 0xe3, 0x22, 0x1d, 0x15, 0xd8, 0x8a, + 0x35, 0x15, 0x28, 0x34, 0x67, 0x66, 0x04, 0x1b, 0xec, 0x62, 0x18, 0x77, + 0x73, 0x26, 0x59, 0x83, 0x3d, 0xfd, 0x0d, 0x00, 0x01, 0xc6, 0x91, 0x8c, + 0x53, 0x43, 0x52, 0x90, 0x0a, 0x36, 0x23, 0x5b, 0x05, 0x36, 0xd9, 0x32, + 0x7a, 0x02, 0x35, 0x73, 0x0e, 0xbf, 0x4a, 0x8b, 0x7c, 0x99, 0x96, 0x77, + 0xee, 0x95, 0x32, 0x3f, 0xca, 0x93, 0x67, 0xdf, 0xbe, 0xd5, 0x27, 0x25, + 0xe9, 0x90, 0xfc, 0xfc, 0x01, 0xd8, 0xd5, 0x9a, 0x8e, 0x0f, 0x7c, 0x61, + 0x1e, 0xd2, 0x25, 0xf1, 0x10, 0x17, 0x94, 0xd3, 0xe6, 0xb1, 0x02, 0xff, + 0xc3, 0x8f, 0x4b, 0x97, 0x2f, 0x5d, 0xd0, 0x44, 0x66, 0x5b, 0x6b, 0x9c, + 0x1b, 0x29, 0x8c, 0x99, 0x05, 0x37, 0x80, 0x86, 0x53, 0x34, 0xe0, 0xd9, + 0x76, 0x12, 0x63, 0x8c, 0x62, 0x82, 0xe2, 0xd1, 0x01, 0x25, 0x41, 0x68, + 0xee, 0xd7, 0xca, 0x0f, 0x00, 0xe9, 0x47, 0xc2, 0xa6, 0x9e, 0x47, 0xd6, + 0x32, 0x8d, 0x41, 0x99, 0xa5, 0xdd, 0x90, 0x58, 0x1c, 0x15, 0x34, 0xd9, + 0x0a, 0x96, 0x7e, 0x05, 0x18, 0x53, 0x7d, 0x59, 0x01, 0x39, 0x01, 0x94, + 0x90, 0xf8, 0x30, 0xbf, 0xb6, 0x80, 0x6e, 0x00, 0xe8, 0x1e, 0x57, 0x4c, + 0x5e, 0xb5, 0xf0, 0xf2, 0x10, 0x7f, 0x27, 0xe0, 0xe7, 0x12, 0xde, 0x90, + 0xa1, 0xe7, 0x98, 0x65, 0x4f, 0x7d, 0xf6, 0x69, 0xc6, 0x69, 0x86, 0xc3, + 0x7d, 0xd1, 0x9a, 0x8b, 0x12, 0x5a, 0x2a, 0x5d, 0xa9, 0x3e, 0x8e, 0x61, + 0xa6, 0x77, 0xf2, 0x0e, 0x9d, 0x26, 0x26, 0x2a, 0x65, 0x98, 0xda, 0x98, + 0x26, 0x5f, 0x4b, 0xb7, 0xe3, 0x54, 0xfc, 0xe2, 0x2b, 0x99, 0x44, 0x63, + 0xab, 0x03, 0x95, 0xf3, 0x6b, 0x04, 0xac, 0x1b, 0x00, 0x36, 0x59, 0xe3, + 0x6f, 0x32, 0x7b, 0x84, 0x7d, 0x07, 0x10, 0x58, 0x94, 0x15, 0xc7, 0xd0, + 0x09, 0x47, 0x05, 0xfe, 0x11, 0xc0, 0x02, 0x73, 0x0e, 0xee, 0xa0, 0xa3, + 0x82, 0xf0, 0x02, 0x20, 0x73, 0x91, 0x3e, 0x86, 0x0c, 0xd4, 0x71, 0x88, + 0xc9, 0x38, 0x63, 0xe6, 0x95, 0x72, 0x6b, 0x80, 0x64, 0xa6, 0x7c, 0x24, + 0x7f, 0xcf, 0xf5, 0x72, 0xb2, 0xe3, 0xdd, 0x54, 0xf9, 0x3a, 0x87, 0x7d, + 0x5a, 0x4e, 0x5e, 0xf4, 0x59, 0xce, 0x5d, 0xef, 0x64, 0x9e, 0x2d, 0x70, + 0xfe, 0x23, 0xac, 0xae, 0x8c, 0x41, 0x55, 0x53, 0xa9, 0x77, 0xfe, 0xaa, + 0x50, 0x92, 0x00, 0xf3, 0x03, 0x47, 0x92, 0x00, 0xf6, 0xc3, 0xcf, 0x37, + 0x2e, 0x65, 0x8a, 0x8a, 0x82, 0xad, 0x01, 0x38, 0x44, 0xfe, 0xe7, 0x2f, + 0x40, 0x9a, 0x99, 0x37, 0x32, 0x62, 0xc2, 0x5d, 0x8d, 0x72, 0x52, 0xc9, + 0x0c, 0x0b, 0xa7, 0x85, 0x01, 0xe8, 0x12, 0xa7, 0x06, 0xdf, 0x00, 0x74, + 0x00, 0x80, 0x19, 0x00, 0x17, 0xed, 0x50, 0x4c, 0xf4, 0x0b, 0x00, 0x41, + 0x67, 0x05, 0xf7, 0x16, 0x20, 0x07, 0x99, 0x91, 0x11, 0x03, 0xf0, 0xbe, + 0x08, 0x51, 0xfd, 0x10, 0xc0, 0xed, 0x7a, 0x78, 0x40, 0x39, 0xf9, 0xec, + 0x53, 0xe7, 0xd4, 0x57, 0x64, 0xee, 0x16, 0x28, 0x95, 0xd9, 0xff, 0x4f, + 0x3c, 0x7f, 0x8f, 0x99, 0xcc, 0x7c, 0x72, 0xb8, 0x46, 0x47, 0x92, 0xf0, + 0xb9, 0x14, 0x40, 0xbe, 0x73, 0xd0, 0x2e, 0xdb, 0x5e, 0x81, 0x6b, 0x3d, + 0xe7, 0xa1, 0x84, 0x8c, 0xd3, 0x1c, 0x2f, 0x3f, 0xc4, 0x13, 0x40, 0x96, + 0x43, 0x20, 0xee, 0x32, 0x62, 0x0a, 0x40, 0x4d, 0x44, 0x41, 0x49, 0x88, + 0x63, 0x2d, 0x0f, 0x96, 0x4d, 0x48, 0x19, 0x53, 0x18, 0x17, 0x7f, 0x00, + 0x66, 0x4e, 0x62, 0x12, 0x2b, 0x4e, 0xe4, 0x34, 0xcd, 0x98, 0x44, 0x96, + 0x21, 0x64, 0x3a, 0x98, 0xae, 0x8d, 0x32, 0x15, 0x28, 0x09, 0x0a, 0xad, + 0x60, 0xcd, 0xc3, 0xb4, 0x30, 0x15, 0x30, 0x08, 0x61, 0x00, 0x20, 0xe3, + 0x35, 0xd2, 0x33, 0x88, 0xd9, 0xe5, 0x7e, 0x06, 0xb2, 0x06, 0xa0, 0x47, + 0x94, 0xec, 0x20, 0xfe, 0x91, 0xa7, 0x73, 0x06, 0xf9, 0x3e, 0x83, 0xf7, + 0xf8, 0xd0, 0x0e, 0xda, 0x4d, 0x65, 0xff, 0x3f, 0xf1, 0xfc, 0x7d, 0xcd, + 0x64, 0xe6, 0x93, 0x33, 0xf3, 0x21, 0xf2, 0x76, 0x53, 0x78, 0xfc, 0x7f, + 0x94, 0xa4, 0x46, 0x17, 0x17, 0x06, 0xca, 0x80, 0xa3, 0x88, 0x03, 0xa5, + 0x06, 0x88, 0x30, 0xb0, 0xb8, 0x90, 0x69, 0x88, 0x00, 0xd8, 0x00, 0x17, + 0x07, 0x17, 0x41, 0xf2, 0x3c, 0xc2, 0x08, 0x8a, 0x55, 0x47, 0x41, 0x41, + 0x07, 0x20, 0x16, 0x21, 0xdb, 0x05, 0x14, 0x19, 0xc0, 0x30, 0x28, 0x0c, + 0x70, 0x71, 0x01, 0x06, 0x22, 0x10, 0x90, 0x3d, 0x47, 0x82, 0x48, 0xa6, + 0x23, 0x13, 0x8c, 0x02, 0x00, 0xe7, 0xfb, 0x84, 0x1b, 0xf9, 0x8e, 0xc0, + 0x23, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, + 0x82 + }; + +const u32 BuiltInFontDataSize = sizeof(BuiltInFontData); +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CAnimatedMeshSceneNode.cpp b/irr/src/CAnimatedMeshSceneNode.cpp new file mode 100644 index 000000000..c3a71f943 --- /dev/null +++ b/irr/src/CAnimatedMeshSceneNode.cpp @@ -0,0 +1,755 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CAnimatedMeshSceneNode.h" +#include "IVideoDriver.h" +#include "ISceneManager.h" +#include "S3DVertex.h" +#include "os.h" +#include "CSkinnedMesh.h" +#include "IDummyTransformationSceneNode.h" +#include "IBoneSceneNode.h" +#include "IMaterialRenderer.h" +#include "IMesh.h" +#include "IMeshCache.h" +#include "IAnimatedMesh.h" +#include "IFileSystem.h" +#include "quaternion.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CAnimatedMeshSceneNode::CAnimatedMeshSceneNode(IAnimatedMesh *mesh, + ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position, + const core::vector3df &rotation, + const core::vector3df &scale) : + IAnimatedMeshSceneNode(parent, mgr, id, position, rotation, scale), + Mesh(0), + StartFrame(0), EndFrame(0), FramesPerSecond(0.025f), + CurrentFrameNr(0.f), LastTimeMs(0), + TransitionTime(0), Transiting(0.f), TransitingBlend(0.f), + JointMode(EJUOR_NONE), JointsUsed(false), + Looping(true), ReadOnlyMaterials(false), RenderFromIdentity(false), + LoopCallBack(0), PassCount(0) +{ +#ifdef _DEBUG + setDebugName("CAnimatedMeshSceneNode"); +#endif + + setMesh(mesh); +} + +//! destructor +CAnimatedMeshSceneNode::~CAnimatedMeshSceneNode() +{ + if (LoopCallBack) + LoopCallBack->drop(); + if (Mesh) + Mesh->drop(); +} + +//! Sets the current frame. From now on the animation is played from this frame. +void CAnimatedMeshSceneNode::setCurrentFrame(f32 frame) +{ + // if you pass an out of range value, we just clamp it + CurrentFrameNr = core::clamp(frame, (f32)StartFrame, (f32)EndFrame); + + beginTransition(); // transit to this frame if enabled +} + +//! Returns the currently displayed frame number. +f32 CAnimatedMeshSceneNode::getFrameNr() const +{ + return CurrentFrameNr; +} + +//! Get CurrentFrameNr and update transiting settings +void CAnimatedMeshSceneNode::buildFrameNr(u32 timeMs) +{ + if (Transiting != 0.f) { + TransitingBlend += (f32)(timeMs)*Transiting; + if (TransitingBlend > 1.f) { + Transiting = 0.f; + TransitingBlend = 0.f; + } + } + + if (StartFrame == EndFrame) { + CurrentFrameNr = (f32)StartFrame; // Support for non animated meshes + } else if (Looping) { + // play animation looped + CurrentFrameNr += timeMs * FramesPerSecond; + + // We have no interpolation between EndFrame and StartFrame, + // the last frame must be identical to first one with our current solution. + if (FramesPerSecond > 0.f) { // forwards... + if (CurrentFrameNr > EndFrame) + CurrentFrameNr = StartFrame + fmodf(CurrentFrameNr - StartFrame, (f32)(EndFrame - StartFrame)); + } else // backwards... + { + if (CurrentFrameNr < StartFrame) + CurrentFrameNr = EndFrame - fmodf(EndFrame - CurrentFrameNr, (f32)(EndFrame - StartFrame)); + } + } else { + // play animation non looped + + CurrentFrameNr += timeMs * FramesPerSecond; + if (FramesPerSecond > 0.f) { // forwards... + if (CurrentFrameNr > (f32)EndFrame) { + CurrentFrameNr = (f32)EndFrame; + if (LoopCallBack) + LoopCallBack->OnAnimationEnd(this); + } + } else // backwards... + { + if (CurrentFrameNr < (f32)StartFrame) { + CurrentFrameNr = (f32)StartFrame; + if (LoopCallBack) + LoopCallBack->OnAnimationEnd(this); + } + } + } +} + +void CAnimatedMeshSceneNode::OnRegisterSceneNode() +{ + if (IsVisible && Mesh) { + // because this node supports rendering of mixed mode meshes consisting of + // transparent and solid material at the same time, we need to go through all + // materials, check of what type they are and register this node for the right + // render pass according to that. + + video::IVideoDriver *driver = SceneManager->getVideoDriver(); + + PassCount = 0; + int transparentCount = 0; + int solidCount = 0; + + // count transparent and solid materials in this scene node + const u32 numMaterials = ReadOnlyMaterials ? Mesh->getMeshBufferCount() : Materials.size(); + for (u32 i = 0; i < numMaterials; ++i) { + const video::SMaterial &material = ReadOnlyMaterials ? Mesh->getMeshBuffer(i)->getMaterial() : Materials[i]; + + if (driver->needsTransparentRenderPass(material)) + ++transparentCount; + else + ++solidCount; + + if (solidCount && transparentCount) + break; + } + + // register according to material types counted + + if (solidCount) + SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); + + if (transparentCount) + SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); + + ISceneNode::OnRegisterSceneNode(); + } +} + +IMesh *CAnimatedMeshSceneNode::getMeshForCurrentFrame() +{ + if (Mesh->getMeshType() != EAMT_SKINNED) { + s32 frameNr = (s32)getFrameNr(); + s32 frameBlend = (s32)(core::fract(getFrameNr()) * 1000.f); + return Mesh->getMesh(frameNr, frameBlend, StartFrame, EndFrame); + } else { + // As multiple scene nodes may be sharing the same skinned mesh, we have to + // re-animate it every frame to ensure that this node gets the mesh that it needs. + + CSkinnedMesh *skinnedMesh = static_cast(Mesh); + + if (JointMode == EJUOR_CONTROL) // write to mesh + skinnedMesh->transferJointsToMesh(JointChildSceneNodes); + else + skinnedMesh->animateMesh(getFrameNr(), 1.0f); + + // Update the skinned mesh for the current joint transforms. + skinnedMesh->skinMesh(); + + if (JointMode == EJUOR_READ) { // read from mesh + skinnedMesh->recoverJointsFromMesh(JointChildSceneNodes); + + //---slow--- + for (u32 n = 0; n < JointChildSceneNodes.size(); ++n) + if (JointChildSceneNodes[n]->getParent() == this) { + JointChildSceneNodes[n]->updateAbsolutePositionOfAllChildren(); // temp, should be an option + } + } + + if (JointMode == EJUOR_CONTROL) { + // For meshes other than EJUOR_CONTROL, this is done by calling animateMesh() + skinnedMesh->updateBoundingBox(); + } + + return skinnedMesh; + } +} + +//! OnAnimate() is called just before rendering the whole scene. +void CAnimatedMeshSceneNode::OnAnimate(u32 timeMs) +{ + if (LastTimeMs == 0) { // first frame + LastTimeMs = timeMs; + } + + // set CurrentFrameNr + buildFrameNr(timeMs - LastTimeMs); + LastTimeMs = timeMs; + + IAnimatedMeshSceneNode::OnAnimate(timeMs); +} + +//! renders the node. +void CAnimatedMeshSceneNode::render() +{ + video::IVideoDriver *driver = SceneManager->getVideoDriver(); + + if (!Mesh || !driver) + return; + + const bool isTransparentPass = + SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT; + + ++PassCount; + + scene::IMesh *m = getMeshForCurrentFrame(); + + if (m) { + Box = m->getBoundingBox(); + } else { +#ifdef _DEBUG + os::Printer::log("Animated Mesh returned no mesh to render.", Mesh->getDebugName(), ELL_WARNING); +#endif + return; + } + + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); + + for (u32 i = 0; i < m->getMeshBufferCount(); ++i) { + const bool transparent = driver->needsTransparentRenderPass(Materials[i]); + + // only render transparent buffer if this is the transparent render pass + // and solid only in solid pass + if (transparent == isTransparentPass) { + scene::IMeshBuffer *mb = m->getMeshBuffer(i); + const video::SMaterial &material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i]; + if (RenderFromIdentity) + driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); + else if (Mesh->getMeshType() == EAMT_SKINNED) + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((SSkinMeshBuffer *)mb)->Transformation); + + driver->setMaterial(material); + driver->drawMeshBuffer(mb); + } + } + + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); + + // for debug purposes only: + if (DebugDataVisible && PassCount == 1) { + video::SMaterial debug_mat; + debug_mat.Lighting = false; + debug_mat.AntiAliasing = 0; + driver->setMaterial(debug_mat); + // show normals + if (DebugDataVisible & scene::EDS_NORMALS) { + const f32 debugNormalLength = 1.f; + const video::SColor debugNormalColor = video::SColor(255, 34, 221, 221); + const u32 count = m->getMeshBufferCount(); + + // draw normals + for (u32 g = 0; g < count; ++g) { + scene::IMeshBuffer *mb = m->getMeshBuffer(g); + if (RenderFromIdentity) + driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); + else if (Mesh->getMeshType() == EAMT_SKINNED) + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((SSkinMeshBuffer *)mb)->Transformation); + + driver->drawMeshBufferNormals(mb, debugNormalLength, debugNormalColor); + } + } + + debug_mat.ZBuffer = video::ECFN_DISABLED; + debug_mat.Lighting = false; + driver->setMaterial(debug_mat); + + if (DebugDataVisible & scene::EDS_BBOX) + driver->draw3DBox(Box, video::SColor(255, 255, 255, 255)); + + // show bounding box + if (DebugDataVisible & scene::EDS_BBOX_BUFFERS) { + for (u32 g = 0; g < m->getMeshBufferCount(); ++g) { + const IMeshBuffer *mb = m->getMeshBuffer(g); + + if (Mesh->getMeshType() == EAMT_SKINNED) + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((SSkinMeshBuffer *)mb)->Transformation); + driver->draw3DBox(mb->getBoundingBox(), video::SColor(255, 190, 128, 128)); + } + } + + // show skeleton + if (DebugDataVisible & scene::EDS_SKELETON) { + if (Mesh->getMeshType() == EAMT_SKINNED) { + // draw skeleton + + for (u32 g = 0; g < ((ISkinnedMesh *)Mesh)->getAllJoints().size(); ++g) { + ISkinnedMesh::SJoint *joint = ((ISkinnedMesh *)Mesh)->getAllJoints()[g]; + + for (u32 n = 0; n < joint->Children.size(); ++n) { + driver->draw3DLine(joint->GlobalAnimatedMatrix.getTranslation(), + joint->Children[n]->GlobalAnimatedMatrix.getTranslation(), + video::SColor(255, 51, 66, 255)); + } + } + } + } + + // show mesh + if (DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY) { + debug_mat.Lighting = false; + debug_mat.Wireframe = true; + debug_mat.ZBuffer = video::ECFN_DISABLED; + driver->setMaterial(debug_mat); + + for (u32 g = 0; g < m->getMeshBufferCount(); ++g) { + const IMeshBuffer *mb = m->getMeshBuffer(g); + if (RenderFromIdentity) + driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); + else if (Mesh->getMeshType() == EAMT_SKINNED) + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((SSkinMeshBuffer *)mb)->Transformation); + driver->drawMeshBuffer(mb); + } + } + } +} + +//! Returns the current start frame number. +s32 CAnimatedMeshSceneNode::getStartFrame() const +{ + return StartFrame; +} + +//! Returns the current start frame number. +s32 CAnimatedMeshSceneNode::getEndFrame() const +{ + return EndFrame; +} + +//! sets the frames between the animation is looped. +//! the default is 0 - MaximalFrameCount of the mesh. +bool CAnimatedMeshSceneNode::setFrameLoop(s32 begin, s32 end) +{ + const s32 maxFrameCount = Mesh->getFrameCount() - 1; + if (end < begin) { + StartFrame = core::s32_clamp(end, 0, maxFrameCount); + EndFrame = core::s32_clamp(begin, StartFrame, maxFrameCount); + } else { + StartFrame = core::s32_clamp(begin, 0, maxFrameCount); + EndFrame = core::s32_clamp(end, StartFrame, maxFrameCount); + } + if (FramesPerSecond < 0) + setCurrentFrame((f32)EndFrame); + else + setCurrentFrame((f32)StartFrame); + + return true; +} + +//! sets the speed with witch the animation is played +void CAnimatedMeshSceneNode::setAnimationSpeed(f32 framesPerSecond) +{ + FramesPerSecond = framesPerSecond * 0.001f; +} + +f32 CAnimatedMeshSceneNode::getAnimationSpeed() const +{ + return FramesPerSecond * 1000.f; +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CAnimatedMeshSceneNode::getBoundingBox() const +{ + return Box; +} + +//! returns the material based on the zero based index i. +video::SMaterial &CAnimatedMeshSceneNode::getMaterial(u32 i) +{ + if (i >= Materials.size()) + return ISceneNode::getMaterial(i); + + return Materials[i]; +} + +//! returns amount of materials used by this scene node. +u32 CAnimatedMeshSceneNode::getMaterialCount() const +{ + return Materials.size(); +} + +//! Returns a pointer to a child node, which has the same transformation as +//! the corresponding joint, if the mesh in this scene node is a skinned mesh. +IBoneSceneNode *CAnimatedMeshSceneNode::getJointNode(const c8 *jointName) +{ + if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED) { + os::Printer::log("No mesh, or mesh not of skinned mesh type", ELL_WARNING); + return 0; + } + + checkJoints(); + + ISkinnedMesh *skinnedMesh = (ISkinnedMesh *)Mesh; + + const std::optional number = skinnedMesh->getJointNumber(jointName); + + if (!number.has_value()) { + os::Printer::log("Joint with specified name not found in skinned mesh", jointName, ELL_DEBUG); + return 0; + } + + if (JointChildSceneNodes.size() <= *number) { + os::Printer::log("Joint was found in mesh, but is not loaded into node", jointName, ELL_WARNING); + return 0; + } + + return JointChildSceneNodes[*number]; +} + +//! Returns a pointer to a child node, which has the same transformation as +//! the corresponding joint, if the mesh in this scene node is a skinned mesh. +IBoneSceneNode *CAnimatedMeshSceneNode::getJointNode(u32 jointID) +{ + if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED) { + os::Printer::log("No mesh, or mesh not of skinned mesh type", ELL_WARNING); + return 0; + } + + checkJoints(); + + if (JointChildSceneNodes.size() <= jointID) { + os::Printer::log("Joint not loaded into node", ELL_WARNING); + return 0; + } + + return JointChildSceneNodes[jointID]; +} + +//! Gets joint count. +u32 CAnimatedMeshSceneNode::getJointCount() const +{ + if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED) + return 0; + + ISkinnedMesh *skinnedMesh = (ISkinnedMesh *)Mesh; + + return skinnedMesh->getJointCount(); +} + +//! Removes a child from this scene node. +//! Implemented here, to be able to remove the shadow properly, if there is one, +//! or to remove attached childs. +bool CAnimatedMeshSceneNode::removeChild(ISceneNode *child) +{ + if (ISceneNode::removeChild(child)) { + if (JointsUsed) { // stop weird bugs caused while changing parents as the joints are being created + for (u32 i = 0; i < JointChildSceneNodes.size(); ++i) { + if (JointChildSceneNodes[i] == child) { + JointChildSceneNodes[i] = 0; // remove link to child + break; + } + } + } + return true; + } + + return false; +} + +//! Sets looping mode which is on by default. If set to false, +//! animations will not be looped. +void CAnimatedMeshSceneNode::setLoopMode(bool playAnimationLooped) +{ + Looping = playAnimationLooped; +} + +//! returns the current loop mode +bool CAnimatedMeshSceneNode::getLoopMode() const +{ + return Looping; +} + +//! Sets a callback interface which will be called if an animation +//! playback has ended. Set this to 0 to disable the callback again. +void CAnimatedMeshSceneNode::setAnimationEndCallback(IAnimationEndCallBack *callback) +{ + if (callback == LoopCallBack) + return; + + if (LoopCallBack) + LoopCallBack->drop(); + + LoopCallBack = callback; + + if (LoopCallBack) + LoopCallBack->grab(); +} + +//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style. +void CAnimatedMeshSceneNode::setReadOnlyMaterials(bool readonly) +{ + ReadOnlyMaterials = readonly; +} + +//! Returns if the scene node should not copy the materials of the mesh but use them in a read only style +bool CAnimatedMeshSceneNode::isReadOnlyMaterials() const +{ + return ReadOnlyMaterials; +} + +//! Sets a new mesh +void CAnimatedMeshSceneNode::setMesh(IAnimatedMesh *mesh) +{ + if (!mesh) + return; // won't set null mesh + + if (Mesh != mesh) { + if (Mesh) + Mesh->drop(); + + Mesh = mesh; + + // grab the mesh (it's non-null!) + Mesh->grab(); + } + + // get materials and bounding box + Box = Mesh->getBoundingBox(); + + IMesh *m = Mesh->getMesh(0, 0); + if (m) { + Materials.clear(); + Materials.reallocate(m->getMeshBufferCount()); + + for (u32 i = 0; i < m->getMeshBufferCount(); ++i) { + IMeshBuffer *mb = m->getMeshBuffer(i); + if (mb) + Materials.push_back(mb->getMaterial()); + else + Materials.push_back(video::SMaterial()); + } + } + + // clean up joint nodes + if (JointsUsed) { + JointsUsed = false; + checkJoints(); + } + + // get start and begin time + setAnimationSpeed(Mesh->getAnimationSpeed()); // NOTE: This had been commented out (but not removed!) in r3526. Which caused meshloader-values for speed to be ignored unless users specified explicitly. Missing a test-case where this could go wrong so I put the code back in. + setFrameLoop(0, Mesh->getFrameCount() - 1); +} + +//! updates the absolute position based on the relative and the parents position +void CAnimatedMeshSceneNode::updateAbsolutePosition() +{ + IAnimatedMeshSceneNode::updateAbsolutePosition(); +} + +//! Set the joint update mode (0-unused, 1-get joints only, 2-set joints only, 3-move and set) +void CAnimatedMeshSceneNode::setJointMode(E_JOINT_UPDATE_ON_RENDER mode) +{ + checkJoints(); + JointMode = mode; +} + +//! Sets the transition time in seconds (note: This needs to enable joints, and setJointmode maybe set to 2) +//! you must call animateJoints(), or the mesh will not animate +void CAnimatedMeshSceneNode::setTransitionTime(f32 time) +{ + const u32 ttime = (u32)core::floor32(time * 1000.0f); + if (TransitionTime == ttime) + return; + TransitionTime = ttime; + if (ttime != 0) + setJointMode(EJUOR_CONTROL); + else + setJointMode(EJUOR_NONE); +} + +//! render mesh ignoring its transformation. Used with ragdolls. (culling is unaffected) +void CAnimatedMeshSceneNode::setRenderFromIdentity(bool enable) +{ + RenderFromIdentity = enable; +} + +//! updates the joint positions of this mesh +void CAnimatedMeshSceneNode::animateJoints(bool CalculateAbsolutePositions) +{ + if (Mesh && Mesh->getMeshType() == EAMT_SKINNED) { + checkJoints(); + const f32 frame = getFrameNr(); // old? + + CSkinnedMesh *skinnedMesh = static_cast(Mesh); + + skinnedMesh->transferOnlyJointsHintsToMesh(JointChildSceneNodes); + skinnedMesh->animateMesh(frame, 1.0f); + skinnedMesh->recoverJointsFromMesh(JointChildSceneNodes); + + //----------------------------------------- + // Transition + //----------------------------------------- + + if (Transiting != 0.f) { + // Init additional matrices + if (PretransitingSave.size() < JointChildSceneNodes.size()) { + for (u32 n = PretransitingSave.size(); n < JointChildSceneNodes.size(); ++n) + PretransitingSave.push_back(core::matrix4()); + } + + for (u32 n = 0; n < JointChildSceneNodes.size(); ++n) { + //------Position------ + + JointChildSceneNodes[n]->setPosition( + core::lerp( + PretransitingSave[n].getTranslation(), + JointChildSceneNodes[n]->getPosition(), + TransitingBlend)); + + //------Rotation------ + + // Code is slow, needs to be fixed up + + const core::quaternion RotationStart(PretransitingSave[n].getRotationDegrees() * core::DEGTORAD); + const core::quaternion RotationEnd(JointChildSceneNodes[n]->getRotation() * core::DEGTORAD); + + core::quaternion QRotation; + QRotation.slerp(RotationStart, RotationEnd, TransitingBlend); + + core::vector3df tmpVector; + QRotation.toEuler(tmpVector); + tmpVector *= core::RADTODEG; // convert from radians back to degrees + JointChildSceneNodes[n]->setRotation(tmpVector); + + //------Scale------ + + // JointChildSceneNodes[n]->setScale( + // core::lerp( + // PretransitingSave[n].getScale(), + // JointChildSceneNodes[n]->getScale(), + // TransitingBlend)); + } + } + + if (CalculateAbsolutePositions) { + //---slow--- + for (u32 n = 0; n < JointChildSceneNodes.size(); ++n) { + if (JointChildSceneNodes[n]->getParent() == this) { + JointChildSceneNodes[n]->updateAbsolutePositionOfAllChildren(); // temp, should be an option + } + } + } + } +} + +/*! + */ +void CAnimatedMeshSceneNode::checkJoints() +{ + if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED) + return; + + if (!JointsUsed) { + for (u32 i = 0; i < JointChildSceneNodes.size(); ++i) + removeChild(JointChildSceneNodes[i]); + JointChildSceneNodes.clear(); + + // Create joints for SkinnedMesh + ((CSkinnedMesh *)Mesh)->addJoints(JointChildSceneNodes, this, SceneManager); + ((CSkinnedMesh *)Mesh)->recoverJointsFromMesh(JointChildSceneNodes); + + JointsUsed = true; + JointMode = EJUOR_READ; + } +} + +/*! + */ +void CAnimatedMeshSceneNode::beginTransition() +{ + if (!JointsUsed) + return; + + if (TransitionTime != 0) { + // Check the array is big enough + if (PretransitingSave.size() < JointChildSceneNodes.size()) { + for (u32 n = PretransitingSave.size(); n < JointChildSceneNodes.size(); ++n) + PretransitingSave.push_back(core::matrix4()); + } + + // Copy the position of joints + for (u32 n = 0; n < JointChildSceneNodes.size(); ++n) + PretransitingSave[n] = JointChildSceneNodes[n]->getRelativeTransformation(); + + Transiting = core::reciprocal((f32)TransitionTime); + } + TransitingBlend = 0.f; +} + +/*! + */ +ISceneNode *CAnimatedMeshSceneNode::clone(ISceneNode *newParent, ISceneManager *newManager) +{ + if (!newParent) + newParent = Parent; + if (!newManager) + newManager = SceneManager; + + CAnimatedMeshSceneNode *newNode = + new CAnimatedMeshSceneNode(Mesh, NULL, newManager, ID, RelativeTranslation, + RelativeRotation, RelativeScale); + + if (newParent) { + newNode->setParent(newParent); // not in constructor because virtual overload for updateAbsolutePosition won't be called + newNode->drop(); + } + + newNode->cloneMembers(this, newManager); + + newNode->Materials = Materials; + newNode->Box = Box; + newNode->Mesh = Mesh; + newNode->StartFrame = StartFrame; + newNode->EndFrame = EndFrame; + newNode->FramesPerSecond = FramesPerSecond; + newNode->CurrentFrameNr = CurrentFrameNr; + newNode->JointMode = JointMode; + newNode->JointsUsed = JointsUsed; + newNode->TransitionTime = TransitionTime; + newNode->Transiting = Transiting; + newNode->TransitingBlend = TransitingBlend; + newNode->Looping = Looping; + newNode->ReadOnlyMaterials = ReadOnlyMaterials; + newNode->LoopCallBack = LoopCallBack; + if (newNode->LoopCallBack) + newNode->LoopCallBack->grab(); + newNode->PassCount = PassCount; + newNode->JointChildSceneNodes = JointChildSceneNodes; + newNode->PretransitingSave = PretransitingSave; + newNode->RenderFromIdentity = RenderFromIdentity; + + return newNode; +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CAnimatedMeshSceneNode.h b/irr/src/CAnimatedMeshSceneNode.h new file mode 100644 index 000000000..0364ab527 --- /dev/null +++ b/irr/src/CAnimatedMeshSceneNode.h @@ -0,0 +1,177 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IAnimatedMeshSceneNode.h" +#include "IAnimatedMesh.h" + +#include "matrix4.h" + +namespace irr +{ +namespace scene +{ +class IDummyTransformationSceneNode; + +class CAnimatedMeshSceneNode : public IAnimatedMeshSceneNode +{ +public: + //! constructor + CAnimatedMeshSceneNode(IAnimatedMesh *mesh, ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position = core::vector3df(0, 0, 0), + const core::vector3df &rotation = core::vector3df(0, 0, 0), + const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f)); + + //! destructor + virtual ~CAnimatedMeshSceneNode(); + + //! sets the current frame. from now on the animation is played from this frame. + void setCurrentFrame(f32 frame) override; + + //! frame + void OnRegisterSceneNode() override; + + //! OnAnimate() is called just before rendering the whole scene. + void OnAnimate(u32 timeMs) override; + + //! renders the node. + void render() override; + + //! returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + //! sets the frames between the animation is looped. + //! the default is 0 - MaximalFrameCount of the mesh. + //! NOTE: setMesh will also change this value and set it to the full range of animations of the mesh + bool setFrameLoop(s32 begin, s32 end) override; + + //! Sets looping mode which is on by default. If set to false, + //! animations will not be looped. + void setLoopMode(bool playAnimationLooped) override; + + //! returns the current loop mode + bool getLoopMode() const override; + + //! Sets a callback interface which will be called if an animation + //! playback has ended. Set this to 0 to disable the callback again. + void setAnimationEndCallback(IAnimationEndCallBack *callback = 0) override; + + //! sets the speed with which the animation is played + //! NOTE: setMesh will also change this value and set it to the default speed of the mesh + void setAnimationSpeed(f32 framesPerSecond) override; + + //! gets the speed with which the animation is played + f32 getAnimationSpeed() const override; + + //! returns the material based on the zero based index i. To get the amount + //! of materials used by this scene node, use getMaterialCount(). + //! This function is needed for inserting the node into the scene hierarchy on a + //! optimal position for minimizing renderstate changes, but can also be used + //! to directly modify the material of a scene node. + video::SMaterial &getMaterial(u32 i) override; + + //! returns amount of materials used by this scene node. + u32 getMaterialCount() const override; + + //! Returns a pointer to a child node, which has the same transformation as + //! the corresponding joint, if the mesh in this scene node is a skinned mesh. + IBoneSceneNode *getJointNode(const c8 *jointName) override; + + //! same as getJointNode(const c8* jointName), but based on id + IBoneSceneNode *getJointNode(u32 jointID) override; + + //! Gets joint count. + u32 getJointCount() const override; + + //! Removes a child from this scene node. + //! Implemented here, to be able to remove the shadow properly, if there is one, + //! or to remove attached child. + bool removeChild(ISceneNode *child) override; + + //! Returns the current displayed frame number. + f32 getFrameNr() const override; + //! Returns the current start frame number. + s32 getStartFrame() const override; + //! Returns the current end frame number. + s32 getEndFrame() const override; + + //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style. + /* In this way it is possible to change the materials a mesh causing all mesh scene nodes + referencing this mesh to change too. */ + void setReadOnlyMaterials(bool readonly) override; + + //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style + bool isReadOnlyMaterials() const override; + + //! Sets a new mesh + void setMesh(IAnimatedMesh *mesh) override; + + //! Returns the current mesh + IAnimatedMesh *getMesh(void) override { return Mesh; } + + //! Returns type of the scene node + ESCENE_NODE_TYPE getType() const override { return ESNT_ANIMATED_MESH; } + + //! updates the absolute position based on the relative and the parents position + void updateAbsolutePosition() override; + + //! Set the joint update mode (0-unused, 1-get joints only, 2-set joints only, 3-move and set) + void setJointMode(E_JOINT_UPDATE_ON_RENDER mode) override; + + //! Sets the transition time in seconds (note: This needs to enable joints, and setJointmode maybe set to 2) + //! you must call animateJoints(), or the mesh will not animate + void setTransitionTime(f32 Time) override; + + //! updates the joint positions of this mesh + void animateJoints(bool CalculateAbsolutePositions = true) override; + + //! render mesh ignoring its transformation. Used with ragdolls. (culling is unaffected) + void setRenderFromIdentity(bool On) override; + + //! Creates a clone of this scene node and its children. + /** \param newParent An optional new parent. + \param newManager An optional new scene manager. + \return The newly created clone of this node. */ + ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override; + +private: + //! Get a static mesh for the current frame of this animated mesh + IMesh *getMeshForCurrentFrame(); + + void buildFrameNr(u32 timeMs); + void checkJoints(); + void beginTransition(); + + core::array Materials; + core::aabbox3d Box; + IAnimatedMesh *Mesh; + + s32 StartFrame; + s32 EndFrame; + f32 FramesPerSecond; + f32 CurrentFrameNr; + + u32 LastTimeMs; + u32 TransitionTime; // Transition time in millisecs + f32 Transiting; // is mesh transiting (plus cache of TransitionTime) + f32 TransitingBlend; // 0-1, calculated on buildFrameNr + + // 0-unused, 1-get joints only, 2-set joints only, 3-move and set + E_JOINT_UPDATE_ON_RENDER JointMode; + bool JointsUsed; + + bool Looping; + bool ReadOnlyMaterials; + bool RenderFromIdentity; + + IAnimationEndCallBack *LoopCallBack; + s32 PassCount; + + core::array JointChildSceneNodes; + core::array PretransitingSave; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CAttributeImpl.h b/irr/src/CAttributeImpl.h new file mode 100644 index 000000000..9065a7342 --- /dev/null +++ b/irr/src/CAttributeImpl.h @@ -0,0 +1,144 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CAttributes.h" +#include "fast_atof.h" +#include "ITexture.h" +#include "IVideoDriver.h" + +namespace irr +{ +namespace io +{ + +/* + Basic types, check documentation in IAttribute.h to see how they generally work. +*/ + +// Attribute implemented for boolean values +class CBoolAttribute : public IAttribute +{ +public: + CBoolAttribute(const char *name, bool value) + { + Name = name; + setBool(value); + } + + s32 getInt() const override + { + return BoolValue ? 1 : 0; + } + + f32 getFloat() const override + { + return BoolValue ? 1.0f : 0.0f; + } + + bool getBool() const override + { + return BoolValue; + } + + void setInt(s32 intValue) override + { + BoolValue = (intValue != 0); + } + + void setFloat(f32 floatValue) override + { + BoolValue = (floatValue != 0); + } + + void setBool(bool boolValue) override + { + BoolValue = boolValue; + } + + E_ATTRIBUTE_TYPE getType() const override + { + return EAT_BOOL; + } + + bool BoolValue; +}; + +// Attribute implemented for integers +class CIntAttribute : public IAttribute +{ +public: + CIntAttribute(const char *name, s32 value) + { + Name = name; + setInt(value); + } + + s32 getInt() const override + { + return Value; + } + + f32 getFloat() const override + { + return (f32)Value; + } + + void setInt(s32 intValue) override + { + Value = intValue; + } + + void setFloat(f32 floatValue) override + { + Value = (s32)floatValue; + }; + + E_ATTRIBUTE_TYPE getType() const override + { + return EAT_INT; + } + + s32 Value; +}; + +// Attribute implemented for floats +class CFloatAttribute : public IAttribute +{ +public: + CFloatAttribute(const char *name, f32 value) + { + Name = name; + setFloat(value); + } + + s32 getInt() const override + { + return (s32)Value; + } + + f32 getFloat() const override + { + return Value; + } + + void setInt(s32 intValue) override + { + Value = (f32)intValue; + } + + void setFloat(f32 floatValue) override + { + Value = floatValue; + } + + E_ATTRIBUTE_TYPE getType() const override + { + return EAT_FLOAT; + } + + f32 Value; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CAttributes.cpp b/irr/src/CAttributes.cpp new file mode 100644 index 000000000..2696d6bcf --- /dev/null +++ b/irr/src/CAttributes.cpp @@ -0,0 +1,249 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CAttributes.h" +#include "CAttributeImpl.h" +#include "ITexture.h" +#include "IVideoDriver.h" + +namespace irr +{ +namespace io +{ + +CAttributes::CAttributes(video::IVideoDriver *driver) : + Driver(driver) +{ +#ifdef _DEBUG + setDebugName("CAttributes"); +#endif + + if (Driver) + Driver->grab(); +} + +CAttributes::~CAttributes() +{ + clear(); + + if (Driver) + Driver->drop(); +} + +//! Removes all attributes +void CAttributes::clear() +{ + for (u32 i = 0; i < Attributes.size(); ++i) + Attributes[i]->drop(); + + Attributes.clear(); +} + +//! Returns attribute index from name, -1 if not found +s32 CAttributes::findAttribute(const c8 *attributeName) const +{ + for (u32 i = 0; i < Attributes.size(); ++i) + if (Attributes[i]->Name == attributeName) + return i; + + return -1; +} + +IAttribute *CAttributes::getAttributeP(const c8 *attributeName) const +{ + for (u32 i = 0; i < Attributes.size(); ++i) + if (Attributes[i]->Name == attributeName) + return Attributes[i]; + + return 0; +} + +//! Sets a attribute as boolean value +void CAttributes::setAttribute(const c8 *attributeName, bool value) +{ + IAttribute *att = getAttributeP(attributeName); + if (att) + att->setBool(value); + else { + Attributes.push_back(new CBoolAttribute(attributeName, value)); + } +} + +//! Gets a attribute as boolean value +//! \param attributeName: Name of the attribute to get. +//! \return Returns value of the attribute previously set by setAttribute() as bool +//! or 0 if attribute is not set. +bool CAttributes::getAttributeAsBool(const c8 *attributeName, bool defaultNotFound) const +{ + const IAttribute *att = getAttributeP(attributeName); + if (att) + return att->getBool(); + else + return defaultNotFound; +} + +//! Sets a attribute as integer value +void CAttributes::setAttribute(const c8 *attributeName, s32 value) +{ + IAttribute *att = getAttributeP(attributeName); + if (att) + att->setInt(value); + else { + Attributes.push_back(new CIntAttribute(attributeName, value)); + } +} + +//! Gets a attribute as integer value +//! \param attributeName: Name of the attribute to get. +//! \return Returns value of the attribute previously set by setAttribute() as integer +//! or 0 if attribute is not set. +s32 CAttributes::getAttributeAsInt(const c8 *attributeName, irr::s32 defaultNotFound) const +{ + const IAttribute *att = getAttributeP(attributeName); + if (att) + return att->getInt(); + else + return defaultNotFound; +} + +//! Sets a attribute as float value +void CAttributes::setAttribute(const c8 *attributeName, f32 value) +{ + IAttribute *att = getAttributeP(attributeName); + if (att) + att->setFloat(value); + else + Attributes.push_back(new CFloatAttribute(attributeName, value)); +} + +//! Gets a attribute as integer value +//! \param attributeName: Name of the attribute to get. +//! \return Returns value of the attribute previously set by setAttribute() as float value +//! or 0 if attribute is not set. +f32 CAttributes::getAttributeAsFloat(const c8 *attributeName, irr::f32 defaultNotFound) const +{ + const IAttribute *att = getAttributeP(attributeName); + if (att) + return att->getFloat(); + + return defaultNotFound; +} + +//! Returns amount of string attributes set in this scene manager. +u32 CAttributes::getAttributeCount() const +{ + return Attributes.size(); +} + +//! Returns string attribute name by index. +//! \param index: Index value, must be between 0 and getStringAttributeCount()-1. +const c8 *CAttributes::getAttributeName(s32 index) const +{ + if ((u32)index >= Attributes.size()) + return 0; + + return Attributes[index]->Name.c_str(); +} + +//! Returns the type of an attribute +E_ATTRIBUTE_TYPE CAttributes::getAttributeType(const c8 *attributeName) const +{ + E_ATTRIBUTE_TYPE ret = EAT_UNKNOWN; + + const IAttribute *att = getAttributeP(attributeName); + if (att) + ret = att->getType(); + + return ret; +} + +//! Returns attribute type by index. +//! \param index: Index value, must be between 0 and getAttributeCount()-1. +E_ATTRIBUTE_TYPE CAttributes::getAttributeType(s32 index) const +{ + if ((u32)index >= Attributes.size()) + return EAT_UNKNOWN; + + return Attributes[index]->getType(); +} + +//! Gets an attribute as integer value +//! \param index: Index value, must be between 0 and getAttributeCount()-1. +s32 CAttributes::getAttributeAsInt(s32 index) const +{ + if ((u32)index < Attributes.size()) + return Attributes[index]->getInt(); + else + return 0; +} + +//! Gets an attribute as float value +//! \param index: Index value, must be between 0 and getAttributeCount()-1. +f32 CAttributes::getAttributeAsFloat(s32 index) const +{ + if ((u32)index < Attributes.size()) + return Attributes[index]->getFloat(); + else + return 0.f; +} + +//! Gets an attribute as boolean value +//! \param index: Index value, must be between 0 and getAttributeCount()-1. +bool CAttributes::getAttributeAsBool(s32 index) const +{ + bool ret = false; + + if ((u32)index < Attributes.size()) + ret = Attributes[index]->getBool(); + + return ret; +} + +//! Adds an attribute as integer +void CAttributes::addInt(const c8 *attributeName, s32 value) +{ + Attributes.push_back(new CIntAttribute(attributeName, value)); +} + +//! Adds an attribute as float +void CAttributes::addFloat(const c8 *attributeName, f32 value) +{ + Attributes.push_back(new CFloatAttribute(attributeName, value)); +} + +//! Adds an attribute as bool +void CAttributes::addBool(const c8 *attributeName, bool value) +{ + Attributes.push_back(new CBoolAttribute(attributeName, value)); +} + +//! Returns if an attribute with a name exists +bool CAttributes::existsAttribute(const c8 *attributeName) const +{ + return getAttributeP(attributeName) != 0; +} + +//! Sets an attribute as boolean value +void CAttributes::setAttribute(s32 index, bool value) +{ + if ((u32)index < Attributes.size()) + Attributes[index]->setBool(value); +} + +//! Sets an attribute as integer value +void CAttributes::setAttribute(s32 index, s32 value) +{ + if ((u32)index < Attributes.size()) + Attributes[index]->setInt(value); +} + +//! Sets a attribute as float value +void CAttributes::setAttribute(s32 index, f32 value) +{ + if ((u32)index < Attributes.size()) + Attributes[index]->setFloat(value); +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CAttributes.h b/irr/src/CAttributes.h new file mode 100644 index 000000000..0fe2739b6 --- /dev/null +++ b/irr/src/CAttributes.h @@ -0,0 +1,133 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IAttributes.h" +#include "IAttribute.h" + +namespace irr +{ +namespace video +{ +class ITexture; +class IVideoDriver; +} +namespace io +{ + +//! Implementation of the IAttributes interface +class CAttributes : public IAttributes +{ +public: + CAttributes(video::IVideoDriver *driver = 0); + ~CAttributes(); + + //! Returns amount of attributes in this collection of attributes. + u32 getAttributeCount() const override; + + //! Returns attribute name by index. + //! \param index: Index value, must be between 0 and getAttributeCount()-1. + const c8 *getAttributeName(s32 index) const override; + + //! Returns the type of an attribute + //! \param attributeName: Name for the attribute + E_ATTRIBUTE_TYPE getAttributeType(const c8 *attributeName) const override; + + //! Returns attribute type by index. + //! \param index: Index value, must be between 0 and getAttributeCount()-1. + E_ATTRIBUTE_TYPE getAttributeType(s32 index) const override; + + //! Returns if an attribute with a name exists + bool existsAttribute(const c8 *attributeName) const override; + + //! Returns attribute index from name, -1 if not found + s32 findAttribute(const c8 *attributeName) const override; + + //! Removes all attributes + void clear() override; + + /* + + Integer Attribute + + */ + + //! Adds an attribute as integer + void addInt(const c8 *attributeName, s32 value) override; + + //! Sets an attribute as integer value + void setAttribute(const c8 *attributeName, s32 value) override; + + //! Gets an attribute as integer value + //! \param attributeName: Name of the attribute to get. + //! \param defaultNotFound Value returned when attributeName was not found + //! \return Returns value of the attribute previously set by setAttribute() + s32 getAttributeAsInt(const c8 *attributeName, irr::s32 defaultNotFound = 0) const override; + + //! Gets an attribute as integer value + //! \param index: Index value, must be between 0 and getAttributeCount()-1. + s32 getAttributeAsInt(s32 index) const override; + + //! Sets an attribute as integer value + void setAttribute(s32 index, s32 value) override; + + /* + + Float Attribute + + */ + + //! Adds an attribute as float + void addFloat(const c8 *attributeName, f32 value) override; + + //! Sets a attribute as float value + void setAttribute(const c8 *attributeName, f32 value) override; + + //! Gets an attribute as float value + //! \param attributeName: Name of the attribute to get. + //! \param defaultNotFound Value returned when attributeName was not found + //! \return Returns value of the attribute previously set by setAttribute() + f32 getAttributeAsFloat(const c8 *attributeName, irr::f32 defaultNotFound = 0.f) const override; + + //! Gets an attribute as float value + //! \param index: Index value, must be between 0 and getAttributeCount()-1. + f32 getAttributeAsFloat(s32 index) const override; + + //! Sets an attribute as float value + void setAttribute(s32 index, f32 value) override; + + /* + Bool Attribute + */ + + //! Adds an attribute as bool + void addBool(const c8 *attributeName, bool value) override; + + //! Sets an attribute as boolean value + void setAttribute(const c8 *attributeName, bool value) override; + + //! Gets an attribute as boolean value + //! \param attributeName: Name of the attribute to get. + //! \param defaultNotFound Value returned when attributeName was not found + //! \return Returns value of the attribute previously set by setAttribute() + bool getAttributeAsBool(const c8 *attributeName, bool defaultNotFound = false) const override; + + //! Gets an attribute as boolean value + //! \param index: Index value, must be between 0 and getAttributeCount()-1. + bool getAttributeAsBool(s32 index) const override; + + //! Sets an attribute as boolean value + void setAttribute(s32 index, bool value) override; + +protected: + core::array Attributes; + + IAttribute *getAttributeP(const c8 *attributeName) const; + + video::IVideoDriver *Driver; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CB3DMeshFileLoader.cpp b/irr/src/CB3DMeshFileLoader.cpp new file mode 100644 index 000000000..6ee24af0e --- /dev/null +++ b/irr/src/CB3DMeshFileLoader.cpp @@ -0,0 +1,949 @@ +// Copyright (C) 2006-2012 Luke Hoschke +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// B3D Mesh loader +// File format designed by Mark Sibly for the Blitz3D engine and has been +// declared public domain + +#include "CB3DMeshFileLoader.h" + +#include "IVideoDriver.h" +#include "IFileSystem.h" +#include "os.h" + +#include + +#ifdef _DEBUG +#define _B3D_READER_DEBUG +#endif + +namespace irr +{ +namespace scene +{ + +//! Constructor +CB3DMeshFileLoader::CB3DMeshFileLoader(scene::ISceneManager *smgr) : + AnimatedMesh(0), B3DFile(0), VerticesStart(0), NormalsInFile(false), + HasVertexColors(false), ShowWarning(true) +{ +#ifdef _DEBUG + setDebugName("CB3DMeshFileLoader"); +#endif +} + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".bsp") +bool CB3DMeshFileLoader::isALoadableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "b3d"); +} + +//! creates/loads an animated mesh from the file. +//! \return Pointer to the created mesh. Returns 0 if loading failed. +//! If you no longer need the mesh, you should call IAnimatedMesh::drop(). +//! See IReferenceCounted::drop() for more information. +IAnimatedMesh *CB3DMeshFileLoader::createMesh(io::IReadFile *file) +{ + if (!file) + return 0; + + B3DFile = file; + AnimatedMesh = new scene::CSkinnedMesh(); + ShowWarning = true; // If true a warning is issued if too many textures are used + VerticesStart = 0; + + if (load()) { + AnimatedMesh->finalize(); + } else { + AnimatedMesh->drop(); + AnimatedMesh = 0; + } + + return AnimatedMesh; +} + +bool CB3DMeshFileLoader::load() +{ + B3dStack.clear(); + + NormalsInFile = false; + HasVertexColors = false; + + //------ Get header ------ + + SB3dChunkHeader header; + B3DFile->read(&header, sizeof(header)); +#ifdef __BIG_ENDIAN__ + header.size = os::Byteswap::byteswap(header.size); +#endif + + if (strncmp(header.name, "BB3D", 4) != 0) { + os::Printer::log("File is not a b3d file. Loading failed (No header found)", B3DFile->getFileName(), ELL_ERROR); + return false; + } + + // Add main chunk... + B3dStack.push_back(SB3dChunk(header, B3DFile->getPos() - 8)); + + // Get file version, but ignore it, as it's not important with b3d files... + s32 fileVersion; + B3DFile->read(&fileVersion, sizeof(fileVersion)); +#ifdef __BIG_ENDIAN__ + fileVersion = os::Byteswap::byteswap(fileVersion); +#endif + + //------ Read main chunk ------ + + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) { + B3DFile->read(&header, sizeof(header)); +#ifdef __BIG_ENDIAN__ + header.size = os::Byteswap::byteswap(header.size); +#endif + B3dStack.push_back(SB3dChunk(header, B3DFile->getPos() - 8)); + + if (strncmp(B3dStack.getLast().name, "TEXS", 4) == 0) { + if (!readChunkTEXS()) + return false; + } else if (strncmp(B3dStack.getLast().name, "BRUS", 4) == 0) { + if (!readChunkBRUS()) + return false; + } else if (strncmp(B3dStack.getLast().name, "NODE", 4) == 0) { + if (!readChunkNODE((CSkinnedMesh::SJoint *)0)) + return false; + } else { + os::Printer::log("Unknown chunk found in mesh base - skipping"); + if (!B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length)) + return false; + B3dStack.erase(B3dStack.size() - 1); + } + } + + B3dStack.clear(); + + BaseVertices.clear(); + AnimatedVertices_VertexID.clear(); + AnimatedVertices_BufferID.clear(); + + Materials.clear(); + Textures.clear(); + + return true; +} + +bool CB3DMeshFileLoader::readChunkNODE(CSkinnedMesh::SJoint *inJoint) +{ + CSkinnedMesh::SJoint *joint = AnimatedMesh->addJoint(inJoint); + joint->Name = readString(); + +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "read ChunkNODE"; + os::Printer::log(logStr.c_str(), joint->Name.value_or("").c_str(), ELL_DEBUG); +#endif + + f32 position[3], scale[3], rotation[4]; + + readFloats(position, 3); + readFloats(scale, 3); + readFloats(rotation, 4); + + joint->Animatedposition = core::vector3df(position[0], position[1], position[2]); + joint->Animatedscale = core::vector3df(scale[0], scale[1], scale[2]); + joint->Animatedrotation = core::quaternion(rotation[1], rotation[2], rotation[3], rotation[0]); + + // Build LocalMatrix: + + core::matrix4 positionMatrix; + positionMatrix.setTranslation(joint->Animatedposition); + core::matrix4 scaleMatrix; + scaleMatrix.setScale(joint->Animatedscale); + core::matrix4 rotationMatrix; + joint->Animatedrotation.getMatrix_transposed(rotationMatrix); + + joint->LocalMatrix = positionMatrix * rotationMatrix * scaleMatrix; + + if (inJoint) + joint->GlobalMatrix = inJoint->GlobalMatrix * joint->LocalMatrix; + else + joint->GlobalMatrix = joint->LocalMatrix; + + while (B3dStack.getLast().startposition + B3dStack.getLast().length > B3DFile->getPos()) // this chunk repeats + { + SB3dChunkHeader header; + B3DFile->read(&header, sizeof(header)); +#ifdef __BIG_ENDIAN__ + header.size = os::Byteswap::byteswap(header.size); +#endif + + B3dStack.push_back(SB3dChunk(header, B3DFile->getPos() - 8)); + + if (strncmp(B3dStack.getLast().name, "NODE", 4) == 0) { + if (!readChunkNODE(joint)) + return false; + } else if (strncmp(B3dStack.getLast().name, "MESH", 4) == 0) { + VerticesStart = BaseVertices.size(); + if (!readChunkMESH(joint)) + return false; + } else if (strncmp(B3dStack.getLast().name, "BONE", 4) == 0) { + if (!readChunkBONE(joint)) + return false; + } else if (strncmp(B3dStack.getLast().name, "KEYS", 4) == 0) { + if (!readChunkKEYS(joint)) + return false; + } else if (strncmp(B3dStack.getLast().name, "ANIM", 4) == 0) { + if (!readChunkANIM()) + return false; + } else { + os::Printer::log("Unknown chunk found in node chunk - skipping"); + if (!B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length)) + return false; + B3dStack.erase(B3dStack.size() - 1); + } + } + + B3dStack.erase(B3dStack.size() - 1); + + return true; +} + +bool CB3DMeshFileLoader::readChunkMESH(CSkinnedMesh::SJoint *inJoint) +{ +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "read ChunkMESH"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); +#endif + + s32 brushID; + B3DFile->read(&brushID, sizeof(brushID)); +#ifdef __BIG_ENDIAN__ + brushID = os::Byteswap::byteswap(brushID); +#endif + + NormalsInFile = false; + HasVertexColors = false; + + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats + { + SB3dChunkHeader header; + B3DFile->read(&header, sizeof(header)); +#ifdef __BIG_ENDIAN__ + header.size = os::Byteswap::byteswap(header.size); +#endif + + B3dStack.push_back(SB3dChunk(header, B3DFile->getPos() - 8)); + + if (strncmp(B3dStack.getLast().name, "VRTS", 4) == 0) { + if (!readChunkVRTS(inJoint)) + return false; + } else if (strncmp(B3dStack.getLast().name, "TRIS", 4) == 0) { + scene::SSkinMeshBuffer *meshBuffer = AnimatedMesh->addMeshBuffer(); + + if (brushID == -1) { /* ok */ + } else if (brushID < 0 || (u32)brushID >= Materials.size()) { + os::Printer::log("Illegal brush ID found", B3DFile->getFileName(), ELL_ERROR); + return false; + } else { + meshBuffer->Material = Materials[brushID].Material; + } + + if (readChunkTRIS(meshBuffer, AnimatedMesh->getMeshBuffers().size() - 1, VerticesStart) == false) + return false; + + if (!NormalsInFile) { + s32 i; + + for (i = 0; i < (s32)meshBuffer->Indices.size(); i += 3) { + core::plane3df p(meshBuffer->getVertex(meshBuffer->Indices[i + 0])->Pos, + meshBuffer->getVertex(meshBuffer->Indices[i + 1])->Pos, + meshBuffer->getVertex(meshBuffer->Indices[i + 2])->Pos); + + meshBuffer->getVertex(meshBuffer->Indices[i + 0])->Normal += p.Normal; + meshBuffer->getVertex(meshBuffer->Indices[i + 1])->Normal += p.Normal; + meshBuffer->getVertex(meshBuffer->Indices[i + 2])->Normal += p.Normal; + } + + for (i = 0; i < (s32)meshBuffer->getVertexCount(); ++i) { + meshBuffer->getVertex(i)->Normal.normalize(); + BaseVertices[VerticesStart + i].Normal = meshBuffer->getVertex(i)->Normal; + } + } + } else { + os::Printer::log("Unknown chunk found in mesh - skipping"); + if (!B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length)) + return false; + B3dStack.erase(B3dStack.size() - 1); + } + } + + B3dStack.erase(B3dStack.size() - 1); + + return true; +} + +/* +VRTS: + int flags ;1=normal values present, 2=rgba values present + int tex_coord_sets ;texture coords per vertex (eg: 1 for simple U/V) max=8 + but we only support 3 + int tex_coord_set_size ;components per set (eg: 2 for simple U/V) max=4 + { + float x,y,z ;always present + float nx,ny,nz ;vertex normal: present if (flags&1) + float red,green,blue,alpha ;vertex color: present if (flags&2) + float tex_coords[tex_coord_sets][tex_coord_set_size] ;tex coords + } +*/ +bool CB3DMeshFileLoader::readChunkVRTS(CSkinnedMesh::SJoint *inJoint) +{ +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "ChunkVRTS"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); +#endif + + const s32 max_tex_coords = 3; + s32 flags, tex_coord_sets, tex_coord_set_size; + + B3DFile->read(&flags, sizeof(flags)); + B3DFile->read(&tex_coord_sets, sizeof(tex_coord_sets)); + B3DFile->read(&tex_coord_set_size, sizeof(tex_coord_set_size)); +#ifdef __BIG_ENDIAN__ + flags = os::Byteswap::byteswap(flags); + tex_coord_sets = os::Byteswap::byteswap(tex_coord_sets); + tex_coord_set_size = os::Byteswap::byteswap(tex_coord_set_size); +#endif + + if (tex_coord_sets < 0 || tex_coord_set_size < 0 || + tex_coord_sets >= max_tex_coords || tex_coord_set_size >= 4) // Something is wrong + { + os::Printer::log("tex_coord_sets or tex_coord_set_size too big", B3DFile->getFileName(), ELL_ERROR); + return false; + } + + //------ Allocate Memory, for speed -----------// + + s32 numberOfReads = 3; + + if (flags & 1) { + NormalsInFile = true; + numberOfReads += 3; + } + if (flags & 2) { + numberOfReads += 4; + HasVertexColors = true; + } + + numberOfReads += tex_coord_sets * tex_coord_set_size; + + const s32 memoryNeeded = (B3dStack.getLast().length / sizeof(f32)) / numberOfReads; + + BaseVertices.reallocate(memoryNeeded + BaseVertices.size() + 1); + AnimatedVertices_VertexID.reallocate(memoryNeeded + AnimatedVertices_VertexID.size() + 1); + + //--------------------------------------------// + + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats + { + f32 position[3]; + f32 normal[3] = {0.f, 0.f, 0.f}; + f32 color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + f32 tex_coords[max_tex_coords][4]; + + readFloats(position, 3); + + if (flags & 1) + readFloats(normal, 3); + if (flags & 2) + readFloats(color, 4); + + for (s32 i = 0; i < tex_coord_sets; ++i) + readFloats(tex_coords[i], tex_coord_set_size); + + f32 tu = 0.0f, tv = 0.0f; + if (tex_coord_sets >= 1 && tex_coord_set_size >= 2) { + tu = tex_coords[0][0]; + tv = tex_coords[0][1]; + } + + f32 tu2 = 0.0f, tv2 = 0.0f; + if (tex_coord_sets > 1 && tex_coord_set_size > 1) { + tu2 = tex_coords[1][0]; + tv2 = tex_coords[1][1]; + } + + // Create Vertex... + video::S3DVertex2TCoords Vertex(position[0], position[1], position[2], + normal[0], normal[1], normal[2], + video::SColorf(color[0], color[1], color[2], color[3]).toSColor(), + tu, tv, tu2, tv2); + + // Transform the Vertex position by nested node... + inJoint->GlobalMatrix.transformVect(Vertex.Pos); + inJoint->GlobalMatrix.rotateVect(Vertex.Normal); + + // Add it... + BaseVertices.push_back(Vertex); + + AnimatedVertices_VertexID.push_back(-1); + AnimatedVertices_BufferID.push_back(-1); + } + + B3dStack.erase(B3dStack.size() - 1); + + return true; +} + +bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *meshBuffer, u32 meshBufferID, s32 vertices_Start) +{ +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "ChunkTRIS"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); +#endif + + bool showVertexWarning = false; + + s32 triangle_brush_id; // Note: Irrlicht can't have different brushes for each triangle (using a workaround) + B3DFile->read(&triangle_brush_id, sizeof(triangle_brush_id)); +#ifdef __BIG_ENDIAN__ + triangle_brush_id = os::Byteswap::byteswap(triangle_brush_id); +#endif + + SB3dMaterial *B3dMaterial; + + if (triangle_brush_id == -1) + B3dMaterial = 0; + else if (triangle_brush_id < 0 || (u32)triangle_brush_id >= Materials.size()) { + os::Printer::log("Illegal material index found", B3DFile->getFileName(), ELL_ERROR); + return false; + } else { + B3dMaterial = &Materials[triangle_brush_id]; + meshBuffer->Material = B3dMaterial->Material; + } + + const s32 memoryNeeded = B3dStack.getLast().length / sizeof(s32); + meshBuffer->Indices.reallocate(memoryNeeded + meshBuffer->Indices.size() + 1); + + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats + { + s32 vertex_id[3]; + + B3DFile->read(vertex_id, 3 * sizeof(s32)); +#ifdef __BIG_ENDIAN__ + vertex_id[0] = os::Byteswap::byteswap(vertex_id[0]); + vertex_id[1] = os::Byteswap::byteswap(vertex_id[1]); + vertex_id[2] = os::Byteswap::byteswap(vertex_id[2]); +#endif + + // Make Ids global: + vertex_id[0] += vertices_Start; + vertex_id[1] += vertices_Start; + vertex_id[2] += vertices_Start; + + for (s32 i = 0; i < 3; ++i) { + if ((u32)vertex_id[i] >= AnimatedVertices_VertexID.size()) { + os::Printer::log("Illegal vertex index found", B3DFile->getFileName(), ELL_ERROR); + return false; + } + + if (AnimatedVertices_VertexID[vertex_id[i]] != -1) { + if (AnimatedVertices_BufferID[vertex_id[i]] != (s32)meshBufferID) { // If this vertex is linked in a different meshbuffer + AnimatedVertices_VertexID[vertex_id[i]] = -1; + AnimatedVertices_BufferID[vertex_id[i]] = -1; + showVertexWarning = true; + } + } + if (AnimatedVertices_VertexID[vertex_id[i]] == -1) { // If this vertex is not in the meshbuffer + // Check for lightmapping: + if (BaseVertices[vertex_id[i]].TCoords2 != core::vector2df(0.f, 0.f)) + meshBuffer->convertTo2TCoords(); // Will only affect the meshbuffer the first time this is called + + // Add the vertex to the meshbuffer: + if (meshBuffer->VertexType == video::EVT_STANDARD) + meshBuffer->Vertices_Standard.push_back(BaseVertices[vertex_id[i]]); + else + meshBuffer->Vertices_2TCoords.push_back(BaseVertices[vertex_id[i]]); + + // create vertex id to meshbuffer index link: + AnimatedVertices_VertexID[vertex_id[i]] = meshBuffer->getVertexCount() - 1; + AnimatedVertices_BufferID[vertex_id[i]] = meshBufferID; + + if (B3dMaterial) { + // Apply Material/Color/etc... + video::S3DVertex *Vertex = meshBuffer->getVertex(meshBuffer->getVertexCount() - 1); + + if (!HasVertexColors) + Vertex->Color = B3dMaterial->Material.DiffuseColor; + else if (Vertex->Color.getAlpha() == 255) + Vertex->Color.setAlpha((s32)(B3dMaterial->alpha * 255.0f)); + + // Use texture's scale + if (B3dMaterial->Textures[0]) { + Vertex->TCoords.X *= B3dMaterial->Textures[0]->Xscale; + Vertex->TCoords.Y *= B3dMaterial->Textures[0]->Yscale; + } + /* + if (B3dMaterial->Textures[1]) + { + Vertex->TCoords2.X *=B3dMaterial->Textures[1]->Xscale; + Vertex->TCoords2.Y *=B3dMaterial->Textures[1]->Yscale; + } + */ + } + } + } + + meshBuffer->Indices.push_back(AnimatedVertices_VertexID[vertex_id[0]]); + meshBuffer->Indices.push_back(AnimatedVertices_VertexID[vertex_id[1]]); + meshBuffer->Indices.push_back(AnimatedVertices_VertexID[vertex_id[2]]); + } + + B3dStack.erase(B3dStack.size() - 1); + + if (showVertexWarning) + os::Printer::log("B3dMeshLoader: Warning, different meshbuffers linking to the same vertex, this will cause problems with animated meshes"); + + return true; +} + +bool CB3DMeshFileLoader::readChunkBONE(CSkinnedMesh::SJoint *inJoint) +{ +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "read ChunkBONE"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); +#endif + + if (B3dStack.getLast().length > 8) { + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats + { + u32 globalVertexID; + f32 strength; + B3DFile->read(&globalVertexID, sizeof(globalVertexID)); + B3DFile->read(&strength, sizeof(strength)); +#ifdef __BIG_ENDIAN__ + globalVertexID = os::Byteswap::byteswap(globalVertexID); + strength = os::Byteswap::byteswap(strength); +#endif + globalVertexID += VerticesStart; + + if (globalVertexID >= AnimatedVertices_VertexID.size()) { + os::Printer::log("Illegal vertex index found", B3DFile->getFileName(), ELL_ERROR); + return false; + } + + if (AnimatedVertices_VertexID[globalVertexID] == -1) { + os::Printer::log("B3dMeshLoader: Weight has bad vertex id (no link to meshbuffer index found)"); + } else if (strength > 0) { + CSkinnedMesh::SWeight *weight = AnimatedMesh->addWeight(inJoint); + weight->strength = strength; + // Find the meshbuffer and Vertex index from the Global Vertex ID: + weight->vertex_id = AnimatedVertices_VertexID[globalVertexID]; + weight->buffer_id = AnimatedVertices_BufferID[globalVertexID]; + } + } + } + + B3dStack.erase(B3dStack.size() - 1); + return true; +} + +bool CB3DMeshFileLoader::readChunkKEYS(CSkinnedMesh::SJoint *inJoint) +{ +#ifdef _B3D_READER_DEBUG + // Only print first, that's just too much output otherwise + if (!inJoint || (inJoint->PositionKeys.empty() && inJoint->ScaleKeys.empty() && inJoint->RotationKeys.empty())) { + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "read ChunkKEYS"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); + } +#endif + + s32 flags; + B3DFile->read(&flags, sizeof(flags)); +#ifdef __BIG_ENDIAN__ + flags = os::Byteswap::byteswap(flags); +#endif + + CSkinnedMesh::SPositionKey *oldPosKey = 0; + core::vector3df oldPos[2]; + CSkinnedMesh::SScaleKey *oldScaleKey = 0; + core::vector3df oldScale[2]; + CSkinnedMesh::SRotationKey *oldRotKey = 0; + core::quaternion oldRot[2]; + bool isFirst[3] = {true, true, true}; + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats + { + s32 frame; + + B3DFile->read(&frame, sizeof(frame)); +#ifdef __BIG_ENDIAN__ + frame = os::Byteswap::byteswap(frame); +#endif + + // Add key frames, frames in Irrlicht are zero-based + f32 data[4]; + if (flags & 1) { + readFloats(data, 3); + if ((oldPosKey != 0) && (oldPos[0] == oldPos[1])) { + const core::vector3df pos(data[0], data[1], data[2]); + if (oldPos[1] == pos) + oldPosKey->frame = (f32)frame - 1; + else { + oldPos[0] = oldPos[1]; + oldPosKey = AnimatedMesh->addPositionKey(inJoint); + oldPosKey->frame = (f32)frame - 1; + oldPos[1].set(oldPosKey->position.set(pos)); + } + } else if (oldPosKey == 0 && isFirst[0]) { + oldPosKey = AnimatedMesh->addPositionKey(inJoint); + oldPosKey->frame = (f32)frame - 1; + oldPos[0].set(oldPosKey->position.set(data[0], data[1], data[2])); + oldPosKey = 0; + isFirst[0] = false; + } else { + if (oldPosKey != 0) + oldPos[0] = oldPos[1]; + oldPosKey = AnimatedMesh->addPositionKey(inJoint); + oldPosKey->frame = (f32)frame - 1; + oldPos[1].set(oldPosKey->position.set(data[0], data[1], data[2])); + } + } + if (flags & 2) { + readFloats(data, 3); + if ((oldScaleKey != 0) && (oldScale[0] == oldScale[1])) { + const core::vector3df scale(data[0], data[1], data[2]); + if (oldScale[1] == scale) + oldScaleKey->frame = (f32)frame - 1; + else { + oldScale[0] = oldScale[1]; + oldScaleKey = AnimatedMesh->addScaleKey(inJoint); + oldScaleKey->frame = (f32)frame - 1; + oldScale[1].set(oldScaleKey->scale.set(scale)); + } + } else if (oldScaleKey == 0 && isFirst[1]) { + oldScaleKey = AnimatedMesh->addScaleKey(inJoint); + oldScaleKey->frame = (f32)frame - 1; + oldScale[0].set(oldScaleKey->scale.set(data[0], data[1], data[2])); + oldScaleKey = 0; + isFirst[1] = false; + } else { + if (oldScaleKey != 0) + oldScale[0] = oldScale[1]; + oldScaleKey = AnimatedMesh->addScaleKey(inJoint); + oldScaleKey->frame = (f32)frame - 1; + oldScale[1].set(oldScaleKey->scale.set(data[0], data[1], data[2])); + } + } + if (flags & 4) { + readFloats(data, 4); + if ((oldRotKey != 0) && (oldRot[0] == oldRot[1])) { + // meant to be in this order since b3d stores W first + const core::quaternion rot(data[1], data[2], data[3], data[0]); + if (oldRot[1] == rot) + oldRotKey->frame = (f32)frame - 1; + else { + oldRot[0] = oldRot[1]; + oldRotKey = AnimatedMesh->addRotationKey(inJoint); + oldRotKey->frame = (f32)frame - 1; + oldRot[1].set(oldRotKey->rotation.set(data[1], data[2], data[3], data[0])); + oldRot[1].normalize(); + } + } else if (oldRotKey == 0 && isFirst[2]) { + oldRotKey = AnimatedMesh->addRotationKey(inJoint); + oldRotKey->frame = (f32)frame - 1; + // meant to be in this order since b3d stores W first + oldRot[0].set(oldRotKey->rotation.set(data[1], data[2], data[3], data[0])); + oldRot[0].normalize(); + oldRotKey = 0; + isFirst[2] = false; + } else { + if (oldRotKey != 0) + oldRot[0] = oldRot[1]; + oldRotKey = AnimatedMesh->addRotationKey(inJoint); + oldRotKey->frame = (f32)frame - 1; + // meant to be in this order since b3d stores W first + oldRot[1].set(oldRotKey->rotation.set(data[1], data[2], data[3], data[0])); + oldRot[1].normalize(); + } + } + } + + B3dStack.erase(B3dStack.size() - 1); + return true; +} + +bool CB3DMeshFileLoader::readChunkANIM() +{ +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "read ChunkANIM"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); +#endif + + s32 animFlags; // not stored\used + s32 animFrames; // not stored\used + f32 animFPS; // not stored\used + + B3DFile->read(&animFlags, sizeof(s32)); + B3DFile->read(&animFrames, sizeof(s32)); + readFloats(&animFPS, 1); + if (animFPS > 0.f) + AnimatedMesh->setAnimationSpeed(animFPS); + os::Printer::log("FPS", io::path((double)animFPS), ELL_DEBUG); + +#ifdef __BIG_ENDIAN__ + animFlags = os::Byteswap::byteswap(animFlags); + animFrames = os::Byteswap::byteswap(animFrames); +#endif + + B3dStack.erase(B3dStack.size() - 1); + return true; +} + +bool CB3DMeshFileLoader::readChunkTEXS() +{ +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "read ChunkTEXS"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); +#endif + + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats + { + Textures.push_back(SB3dTexture()); + SB3dTexture &B3dTexture = Textures.getLast(); + + B3dTexture.TextureName = readString(); + std::replace(B3dTexture.TextureName.begin(), B3dTexture.TextureName.end(), '\\', '/'); +#ifdef _B3D_READER_DEBUG + os::Printer::log("read Texture", B3dTexture.TextureName.c_str(), ELL_DEBUG); +#endif + + B3DFile->read(&B3dTexture.Flags, sizeof(s32)); + B3DFile->read(&B3dTexture.Blend, sizeof(s32)); +#ifdef __BIG_ENDIAN__ + B3dTexture.Flags = os::Byteswap::byteswap(B3dTexture.Flags); + B3dTexture.Blend = os::Byteswap::byteswap(B3dTexture.Blend); +#endif +#ifdef _B3D_READER_DEBUG + os::Printer::log("Flags", core::stringc(B3dTexture.Flags).c_str(), ELL_DEBUG); + os::Printer::log("Blend", core::stringc(B3dTexture.Blend).c_str(), ELL_DEBUG); +#endif + readFloats(&B3dTexture.Xpos, 1); + readFloats(&B3dTexture.Ypos, 1); + readFloats(&B3dTexture.Xscale, 1); + readFloats(&B3dTexture.Yscale, 1); + readFloats(&B3dTexture.Angle, 1); + } + + B3dStack.erase(B3dStack.size() - 1); + + return true; +} + +bool CB3DMeshFileLoader::readChunkBRUS() +{ +#ifdef _B3D_READER_DEBUG + core::stringc logStr; + for (u32 i = 1; i < B3dStack.size(); ++i) + logStr += "-"; + logStr += "read ChunkBRUS"; + os::Printer::log(logStr.c_str(), ELL_DEBUG); +#endif + + u32 n_texs; + B3DFile->read(&n_texs, sizeof(u32)); +#ifdef __BIG_ENDIAN__ + n_texs = os::Byteswap::byteswap(n_texs); +#endif + + // number of texture ids read for Irrlicht + const u32 num_textures = core::min_(n_texs, video::MATERIAL_MAX_TEXTURES); + // number of bytes to skip (for ignored texture ids) + const u32 n_texs_offset = (num_textures < n_texs) ? (n_texs - num_textures) : 0; + + while ((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats + { + // This is what blitz basic calls a brush, like a Irrlicht Material + + auto name = readString(); +#ifdef _B3D_READER_DEBUG + os::Printer::log("read Material", name.c_str(), ELL_DEBUG); +#endif + Materials.push_back(SB3dMaterial()); + SB3dMaterial &B3dMaterial = Materials.getLast(); + + readFloats(&B3dMaterial.red, 1); + readFloats(&B3dMaterial.green, 1); + readFloats(&B3dMaterial.blue, 1); + readFloats(&B3dMaterial.alpha, 1); + readFloats(&B3dMaterial.shininess, 1); + + B3DFile->read(&B3dMaterial.blend, sizeof(B3dMaterial.blend)); + B3DFile->read(&B3dMaterial.fx, sizeof(B3dMaterial.fx)); +#ifdef __BIG_ENDIAN__ + B3dMaterial.blend = os::Byteswap::byteswap(B3dMaterial.blend); + B3dMaterial.fx = os::Byteswap::byteswap(B3dMaterial.fx); +#endif +#ifdef _B3D_READER_DEBUG + os::Printer::log("Blend", core::stringc(B3dMaterial.blend).c_str(), ELL_DEBUG); + os::Printer::log("FX", core::stringc(B3dMaterial.fx).c_str(), ELL_DEBUG); +#endif + + u32 i; + for (i = 0; i < num_textures; ++i) { + s32 texture_id = -1; + B3DFile->read(&texture_id, sizeof(s32)); +#ifdef __BIG_ENDIAN__ + texture_id = os::Byteswap::byteswap(texture_id); +#endif + //--- Get pointers to the texture, based on the IDs --- + if ((u32)texture_id < Textures.size()) { + B3dMaterial.Textures[i] = &Textures[texture_id]; +#ifdef _B3D_READER_DEBUG + os::Printer::log("Layer", core::stringc(i).c_str(), ELL_DEBUG); + os::Printer::log("using texture", Textures[texture_id].TextureName.c_str(), ELL_DEBUG); +#endif + } else + B3dMaterial.Textures[i] = 0; + } + // skip other texture ids + for (i = 0; i < n_texs_offset; ++i) { + s32 texture_id = -1; + B3DFile->read(&texture_id, sizeof(s32)); +#ifdef __BIG_ENDIAN__ + texture_id = os::Byteswap::byteswap(texture_id); +#endif + if (ShowWarning && (texture_id != -1) && (n_texs > video::MATERIAL_MAX_TEXTURES)) { + os::Printer::log("Too many textures used in one material", B3DFile->getFileName(), ELL_WARNING); + ShowWarning = false; + } + } + + // Fixes problems when the lightmap is on the first texture: + if (B3dMaterial.Textures[0] != 0) { + if (B3dMaterial.Textures[0]->Flags & 65536) { // 65536 = secondary UV + SB3dTexture *TmpTexture; + TmpTexture = B3dMaterial.Textures[1]; + B3dMaterial.Textures[1] = B3dMaterial.Textures[0]; + B3dMaterial.Textures[0] = TmpTexture; + } + } + + // If a preceeding texture slot is empty move the others down: + for (i = num_textures; i > 0; --i) { + for (u32 j = i - 1; j < num_textures - 1; ++j) { + if (B3dMaterial.Textures[j + 1] != 0 && B3dMaterial.Textures[j] == 0) { + B3dMaterial.Textures[j] = B3dMaterial.Textures[j + 1]; + B3dMaterial.Textures[j + 1] = 0; + } + } + } + + //------ Convert blitz flags/blend to irrlicht ------- + + // Two textures: + if (B3dMaterial.Textures[1]) { + B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; + B3dMaterial.Material.ZWriteEnable = video::EZW_OFF; + } else if (B3dMaterial.Textures[0]) { // One texture: + // Flags & 0x1 is usual SOLID, 0x8 is mipmap (handled before) + if (B3dMaterial.Textures[0]->Flags & 0x2) { // (Alpha mapped) + B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + B3dMaterial.Material.ZWriteEnable = video::EZW_OFF; + } else if (B3dMaterial.Textures[0]->Flags & 0x4) //(Masked) + B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; // TODO: create color key texture + else if (B3dMaterial.alpha == 1.f) + B3dMaterial.Material.MaterialType = video::EMT_SOLID; + else { + B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; + B3dMaterial.Material.ZWriteEnable = video::EZW_OFF; + } + } else // No texture: + { + if (B3dMaterial.alpha == 1.f) + B3dMaterial.Material.MaterialType = video::EMT_SOLID; + else { + B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; + B3dMaterial.Material.ZWriteEnable = video::EZW_OFF; + } + } + + B3dMaterial.Material.DiffuseColor = video::SColorf(B3dMaterial.red, B3dMaterial.green, B3dMaterial.blue, B3dMaterial.alpha).toSColor(); + B3dMaterial.Material.ColorMaterial = video::ECM_NONE; + + //------ Material fx ------ + + if (B3dMaterial.fx & 1) { // full-bright + B3dMaterial.Material.AmbientColor = video::SColor(255, 255, 255, 255); + B3dMaterial.Material.Lighting = false; + } else + B3dMaterial.Material.AmbientColor = B3dMaterial.Material.DiffuseColor; + + if (B3dMaterial.fx & 2) // use vertex colors instead of brush color + B3dMaterial.Material.ColorMaterial = video::ECM_DIFFUSE_AND_AMBIENT; + + if (B3dMaterial.fx & 4) // flatshaded + B3dMaterial.Material.GouraudShading = false; + + if (B3dMaterial.fx & 16) // disable backface culling + B3dMaterial.Material.BackfaceCulling = false; + + if (B3dMaterial.fx & 32) { // force vertex alpha-blending + B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; + B3dMaterial.Material.ZWriteEnable = video::EZW_OFF; + } + + B3dMaterial.Material.Shininess = B3dMaterial.shininess; + } + + B3dStack.erase(B3dStack.size() - 1); + + return true; +} + +std::string CB3DMeshFileLoader::readString() +{ + std::string newstring = ""; + while (true) { + c8 character; + if (B3DFile->read(&character, sizeof(character)) == 0) + break; // eof + if (character == 0) + break; + newstring.push_back(character); + } + return newstring; +} + +void CB3DMeshFileLoader::readFloats(f32 *vec, u32 count) +{ + B3DFile->read(vec, count * sizeof(f32)); +#ifdef __BIG_ENDIAN__ + for (u32 n = 0; n < count; ++n) + vec[n] = os::Byteswap::byteswap(vec[n]); +#endif +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CB3DMeshFileLoader.h b/irr/src/CB3DMeshFileLoader.h new file mode 100644 index 000000000..808b68170 --- /dev/null +++ b/irr/src/CB3DMeshFileLoader.h @@ -0,0 +1,79 @@ +// Copyright (C) 2006-2012 Luke Hoschke +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// B3D Mesh loader +// File format designed by Mark Sibly for the Blitz3D engine and has been +// declared public domain + +#pragma once + +#include "IMeshLoader.h" +#include "ISceneManager.h" +#include "CSkinnedMesh.h" +#include "SB3DStructs.h" +#include "IReadFile.h" + +namespace irr +{ + +namespace scene +{ + +//! Meshloader for B3D format +class CB3DMeshFileLoader : public IMeshLoader +{ +public: + //! Constructor + CB3DMeshFileLoader(scene::ISceneManager *smgr); + + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".bsp") + bool isALoadableFileExtension(const io::path &filename) const override; + + //! creates/loads an animated mesh from the file. + //! \return Pointer to the created mesh. Returns 0 if loading failed. + //! If you no longer need the mesh, you should call IAnimatedMesh::drop(). + //! See IReferenceCounted::drop() for more information. + IAnimatedMesh *createMesh(io::IReadFile *file) override; + +private: + bool load(); + bool readChunkNODE(CSkinnedMesh::SJoint *InJoint); + bool readChunkMESH(CSkinnedMesh::SJoint *InJoint); + bool readChunkVRTS(CSkinnedMesh::SJoint *InJoint); + bool readChunkTRIS(scene::SSkinMeshBuffer *MeshBuffer, u32 MeshBufferID, s32 Vertices_Start); + bool readChunkBONE(CSkinnedMesh::SJoint *InJoint); + bool readChunkKEYS(CSkinnedMesh::SJoint *InJoint); + bool readChunkANIM(); + bool readChunkTEXS(); + bool readChunkBRUS(); + + std::string readString(); + void readFloats(f32 *vec, u32 count); + + core::array B3dStack; + + core::array Materials; + core::array Textures; + + core::array AnimatedVertices_VertexID; + + core::array AnimatedVertices_BufferID; + + core::array BaseVertices; + + CSkinnedMesh *AnimatedMesh; + io::IReadFile *B3DFile; + + // B3Ds have Vertex ID's local within the mesh I don't want this + // Variable needs to be class member due to recursion in calls + u32 VerticesStart; + + bool NormalsInFile; + bool HasVertexColors; + bool ShowWarning; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CBillboardSceneNode.cpp b/irr/src/CBillboardSceneNode.cpp new file mode 100644 index 000000000..ddb9d465a --- /dev/null +++ b/irr/src/CBillboardSceneNode.cpp @@ -0,0 +1,266 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CBillboardSceneNode.h" +#include "IVideoDriver.h" +#include "ISceneManager.h" +#include "ICameraSceneNode.h" +#include "os.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CBillboardSceneNode::CBillboardSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position, const core::dimension2d &size, + video::SColor colorTop, video::SColor colorBottom) : + IBillboardSceneNode(parent, mgr, id, position), + Buffer(new SMeshBuffer()) +{ +#ifdef _DEBUG + setDebugName("CBillboardSceneNode"); +#endif + + setSize(size); + + Buffer->Vertices.set_used(4); + Buffer->Indices.set_used(6); + + Buffer->Indices[0] = 0; + Buffer->Indices[1] = 2; + Buffer->Indices[2] = 1; + Buffer->Indices[3] = 0; + Buffer->Indices[4] = 3; + Buffer->Indices[5] = 2; + + Buffer->Vertices[0].TCoords.set(1.0f, 1.0f); + Buffer->Vertices[0].Color = colorBottom; + + Buffer->Vertices[1].TCoords.set(1.0f, 0.0f); + Buffer->Vertices[1].Color = colorTop; + + Buffer->Vertices[2].TCoords.set(0.0f, 0.0f); + Buffer->Vertices[2].Color = colorTop; + + Buffer->Vertices[3].TCoords.set(0.0f, 1.0f); + Buffer->Vertices[3].Color = colorBottom; +} + +CBillboardSceneNode::~CBillboardSceneNode() +{ + Buffer->drop(); +} + +//! pre render event +void CBillboardSceneNode::OnRegisterSceneNode() +{ + if (IsVisible) + SceneManager->registerNodeForRendering(this); + + ISceneNode::OnRegisterSceneNode(); +} + +//! render +void CBillboardSceneNode::render() +{ + video::IVideoDriver *driver = SceneManager->getVideoDriver(); + ICameraSceneNode *camera = SceneManager->getActiveCamera(); + + if (!camera || !driver) + return; + + // make billboard look to camera + updateMesh(camera); + + driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); + driver->setMaterial(Buffer->Material); + driver->drawMeshBuffer(Buffer); + + if (DebugDataVisible & scene::EDS_BBOX) { + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); + video::SMaterial m; + m.Lighting = false; + driver->setMaterial(m); + driver->draw3DBox(BBoxSafe, video::SColor(0, 208, 195, 152)); + } +} + +void CBillboardSceneNode::updateMesh(const irr::scene::ICameraSceneNode *camera) +{ + // billboard looks toward camera + core::vector3df pos = getAbsolutePosition(); + + core::vector3df campos = camera->getAbsolutePosition(); + core::vector3df target = camera->getTarget(); + core::vector3df up = camera->getUpVector(); + core::vector3df view = target - campos; + view.normalize(); + + core::vector3df horizontal = up.crossProduct(view); + if (horizontal.getLength() == 0) { + horizontal.set(up.Y, up.X, up.Z); + } + horizontal.normalize(); + core::vector3df topHorizontal = horizontal * 0.5f * TopEdgeWidth; + horizontal *= 0.5f * Size.Width; + + // pointing down! + core::vector3df vertical = horizontal.crossProduct(view); + vertical.normalize(); + vertical *= 0.5f * Size.Height; + + view *= -1.0f; + + core::array &vertices = Buffer->Vertices; + + for (s32 i = 0; i < 4; ++i) + vertices[i].Normal = view; + + /* Vertices are: + 2--1 + |\ | + | \| + 3--0 + */ + vertices[0].Pos = pos + horizontal + vertical; + vertices[1].Pos = pos + topHorizontal - vertical; + vertices[2].Pos = pos - topHorizontal - vertical; + vertices[3].Pos = pos - horizontal + vertical; + + Buffer->setDirty(EBT_VERTEX); + Buffer->recalculateBoundingBox(); +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CBillboardSceneNode::getBoundingBox() const +{ + // Really wrong when scaled (as the node does not scale it's vertices - maybe it should?) + return BBoxSafe; +} + +const core::aabbox3d &CBillboardSceneNode::getTransformedBillboardBoundingBox(const irr::scene::ICameraSceneNode *camera) +{ + updateMesh(camera); + return Buffer->BoundingBox; +} + +void CBillboardSceneNode::setSize(const core::dimension2d &size) +{ + Size = size; + + if (core::equals(Size.Width, 0.0f)) + Size.Width = 1.0f; + TopEdgeWidth = Size.Width; + + if (core::equals(Size.Height, 0.0f)) + Size.Height = 1.0f; + + const f32 extent = 0.5f * sqrtf(Size.Width * Size.Width + Size.Height * Size.Height); + BBoxSafe.MinEdge.set(-extent, -extent, -extent); + BBoxSafe.MaxEdge.set(extent, extent, extent); +} + +void CBillboardSceneNode::setSize(f32 height, f32 bottomEdgeWidth, f32 topEdgeWidth) +{ + Size.set(bottomEdgeWidth, height); + TopEdgeWidth = topEdgeWidth; + + if (core::equals(Size.Height, 0.0f)) + Size.Height = 1.0f; + + if (core::equals(Size.Width, 0.f) && core::equals(TopEdgeWidth, 0.f)) { + Size.Width = 1.0f; + TopEdgeWidth = 1.0f; + } + + const f32 extent = 0.5f * sqrtf(Size.Width * Size.Width + Size.Height * Size.Height); + BBoxSafe.MinEdge.set(-extent, -extent, -extent); + BBoxSafe.MaxEdge.set(extent, extent, extent); +} + +video::SMaterial &CBillboardSceneNode::getMaterial(u32 i) +{ + return Buffer->Material; +} + +//! returns amount of materials used by this scene node. +u32 CBillboardSceneNode::getMaterialCount() const +{ + return 1; +} + +//! gets the size of the billboard +const core::dimension2d &CBillboardSceneNode::getSize() const +{ + return Size; +} + +//! Gets the widths of the top and bottom edges of the billboard. +void CBillboardSceneNode::getSize(f32 &height, f32 &bottomEdgeWidth, + f32 &topEdgeWidth) const +{ + height = Size.Height; + bottomEdgeWidth = Size.Width; + topEdgeWidth = TopEdgeWidth; +} + +//! Set the color of all vertices of the billboard +//! \param overallColor: the color to set +void CBillboardSceneNode::setColor(const video::SColor &overallColor) +{ + for (u32 vertex = 0; vertex < 4; ++vertex) + Buffer->Vertices[vertex].Color = overallColor; +} + +//! Set the color of the top and bottom vertices of the billboard +//! \param topColor: the color to set the top vertices +//! \param bottomColor: the color to set the bottom vertices +void CBillboardSceneNode::setColor(const video::SColor &topColor, + const video::SColor &bottomColor) +{ + Buffer->Vertices[0].Color = bottomColor; + Buffer->Vertices[1].Color = topColor; + Buffer->Vertices[2].Color = topColor; + Buffer->Vertices[3].Color = bottomColor; +} + +//! Gets the color of the top and bottom vertices of the billboard +//! \param[out] topColor: stores the color of the top vertices +//! \param[out] bottomColor: stores the color of the bottom vertices +void CBillboardSceneNode::getColor(video::SColor &topColor, + video::SColor &bottomColor) const +{ + bottomColor = Buffer->Vertices[0].Color; + topColor = Buffer->Vertices[1].Color; +} + +//! Creates a clone of this scene node and its children. +ISceneNode *CBillboardSceneNode::clone(ISceneNode *newParent, ISceneManager *newManager) +{ + if (!newParent) + newParent = Parent; + if (!newManager) + newManager = SceneManager; + + CBillboardSceneNode *nb = new CBillboardSceneNode(newParent, + newManager, ID, RelativeTranslation, Size); + + nb->cloneMembers(this, newManager); + nb->Buffer->Material = Buffer->Material; + nb->Size = Size; + nb->TopEdgeWidth = this->TopEdgeWidth; + + video::SColor topColor, bottomColor; + getColor(topColor, bottomColor); + nb->setColor(topColor, bottomColor); + + if (newParent) + nb->drop(); + return nb; +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CBillboardSceneNode.h b/irr/src/CBillboardSceneNode.h new file mode 100644 index 000000000..f0d7f9dcf --- /dev/null +++ b/irr/src/CBillboardSceneNode.h @@ -0,0 +1,113 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IBillboardSceneNode.h" +#include "SMeshBuffer.h" + +namespace irr +{ +namespace scene +{ + +//! Scene node which is a billboard. A billboard is like a 3d sprite: A 2d element, +//! which always looks to the camera. +class CBillboardSceneNode : virtual public IBillboardSceneNode +{ +public: + //! constructor + CBillboardSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position, const core::dimension2d &size, + video::SColor colorTop = video::SColor(0xFFFFFFFF), + video::SColor colorBottom = video::SColor(0xFFFFFFFF)); + + virtual ~CBillboardSceneNode(); + + //! pre render event + void OnRegisterSceneNode() override; + + //! render + void render() override; + + //! returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + //! sets the size of the billboard + void setSize(const core::dimension2d &size) override; + + //! Sets the widths of the top and bottom edges of the billboard independently. + void setSize(f32 height, f32 bottomEdgeWidth, f32 topEdgeWidth) override; + + //! gets the size of the billboard + const core::dimension2d &getSize() const override; + + //! Gets the widths of the top and bottom edges of the billboard. + void getSize(f32 &height, f32 &bottomEdgeWidth, f32 &topEdgeWidth) const override; + + video::SMaterial &getMaterial(u32 i) override; + + //! returns amount of materials used by this scene node. + u32 getMaterialCount() const override; + + //! Set the color of all vertices of the billboard + //! \param overallColor: the color to set + void setColor(const video::SColor &overallColor) override; + + //! Set the color of the top and bottom vertices of the billboard + //! \param topColor: the color to set the top vertices + //! \param bottomColor: the color to set the bottom vertices + virtual void setColor(const video::SColor &topColor, + const video::SColor &bottomColor) override; + + //! Gets the color of the top and bottom vertices of the billboard + //! \param[out] topColor: stores the color of the top vertices + //! \param[out] bottomColor: stores the color of the bottom vertices + virtual void getColor(video::SColor &topColor, + video::SColor &bottomColor) const override; + + //! Get the real boundingbox used by the billboard (which depends on the active camera) + const core::aabbox3d &getTransformedBillboardBoundingBox(const irr::scene::ICameraSceneNode *camera) override; + + //! Get the amount of mesh buffers. + u32 getMeshBufferCount() const override + { + return Buffer ? 1 : 0; + } + + //! Get pointer to the mesh buffer. + IMeshBuffer *getMeshBuffer(u32 nr) const override + { + if (nr == 0) + return Buffer; + return 0; + } + + //! Returns type of the scene node + ESCENE_NODE_TYPE getType() const override { return ESNT_BILLBOARD; } + + //! Creates a clone of this scene node and its children. + ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override; + +protected: + void updateMesh(const irr::scene::ICameraSceneNode *camera); + +private: + //! Size.Width is the bottom edge width + core::dimension2d Size; + f32 TopEdgeWidth; + + //! BoundingBox which is large enough to contain the billboard independent of the camera + // TODO: BUG - still can be wrong with scaling < 1. Billboards should calculate relative coordinates for their mesh + // and then use the node-scaling. But needs some work... + /** Note that we can't use the real boundingbox for culling because at that point + the camera which is used to calculate the billboard is not yet updated. So we only + know the real boundingbox after rendering - which is too late for culling. */ + core::aabbox3d BBoxSafe; + + scene::SMeshBuffer *Buffer; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CBlit.h b/irr/src/CBlit.h new file mode 100644 index 000000000..90450ec2f --- /dev/null +++ b/irr/src/CBlit.h @@ -0,0 +1,942 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "SoftwareDriver2_helper.h" + +namespace irr +{ + +//! f18 - fixpoint 14.18 limit to 16k Textures +#define CBLIT_USE_FIXPOINT18 + +#if defined(CBLIT_USE_FIXPOINT18) +typedef int f18; +#define f18_one 262144 +#define f18_zero 0 +#define f32_to_f18(x) ((f18)floorf(((x) * 262144.f) + 0.f)) +#define f32_to_f32(x) (x) +#define f18_floor(x) ((x) >> 18) +#define f18_round(x) ((x + 131.072) >> 18) +#else +typedef float f18; +#define f18_one 1.f +#define f18_zero_dot_five 0.5f +#define f18_zero 0.f +#define f32_to_f18(x) (x) +#define f32_to_f32(x) (x) +#define f18_floor(x) ((int)(x)) +#define f18_round(x) ((int)(x + 0.5f)) +#endif + +struct SBlitJob +{ + AbsRectangle Dest; + AbsRectangle Source; + + u32 argb; + + const void *src; + void *dst; + + u32 width; // draw size + u32 height; + + u32 srcPixelMul; // pixel byte size + u32 dstPixelMul; + + int srcPitch; // scanline byte size. allow negative for mirror + u32 dstPitch; + + bool stretch; + f32 x_stretch; + f32 y_stretch; +}; + +// Bitfields Cohen Sutherland +enum eClipCode +{ + CLIPCODE_EMPTY = 0, + CLIPCODE_BOTTOM = 1, + CLIPCODE_TOP = 2, + CLIPCODE_LEFT = 4, + CLIPCODE_RIGHT = 8 +}; + +inline u32 GetClipCode(const AbsRectangle &r, const core::position2d &p) +{ + u32 code = CLIPCODE_EMPTY; + + if (p.X < r.x0) + code = CLIPCODE_LEFT; + else if (p.X > r.x1) + code = CLIPCODE_RIGHT; + + if (p.Y < r.y0) + code |= CLIPCODE_TOP; + else if (p.Y > r.y1) + code |= CLIPCODE_BOTTOM; + + return code; +} + +/* + */ +inline void GetClip(AbsRectangle &clipping, video::IImage *t) +{ + clipping.x0 = 0; + clipping.y0 = 0; + clipping.x1 = t->getDimension().Width - 1; + clipping.y1 = t->getDimension().Height - 1; +} + +/* + return alpha in [0;256] Granularity from 32-Bit ARGB + add highbit alpha ( alpha > 127 ? + 1 ) +*/ +static inline u32 extractAlpha(const u32 c) +{ + return (c >> 24) + (c >> 31); +} + +/* + return alpha in [0;255] Granularity and 32-Bit ARGB + add highbit alpha ( alpha > 127 ? + 1 ) +*/ +static inline u32 packAlpha(const u32 c) +{ + return (c > 127 ? c - 1 : c) << 24; +} + +/*! + Scale Color by (1/value) + value 0 - 256 ( alpha ) +*/ +inline u32 PixelLerp32(const u32 source, const u32 value) +{ + u32 srcRB = source & 0x00FF00FF; + u32 srcXG = (source & 0xFF00FF00) >> 8; + + srcRB *= value; + srcXG *= value; + + srcRB >>= 8; + // srcXG >>= 8; + + srcXG &= 0xFF00FF00; + srcRB &= 0x00FF00FF; + + return srcRB | srcXG; +} + +/*! + */ +static void executeBlit_TextureCopy_x_to_x(const SBlitJob *job) +{ + if (job->stretch) { + const f18 wscale = f32_to_f18(job->x_stretch); + const f18 hscale = f32_to_f18(job->y_stretch); + + f18 src_y = f18_zero; + + if (job->srcPixelMul == 4) { + const u32 *src = (u32 *)(job->src); + u32 *dst = (u32 *)(job->dst); + + for (u32 dy = 0; dy < job->height; ++dy, src_y += hscale) { + src = (u32 *)((u8 *)(job->src) + job->srcPitch * f18_floor(src_y)); + + f18 src_x = f18_zero; + for (u32 dx = 0; dx < job->width; ++dx, src_x += wscale) { + dst[dx] = src[f18_floor(src_x)]; + } + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } + } else if (job->srcPixelMul == 2) { + const u16 *src = (u16 *)(job->src); + u16 *dst = (u16 *)(job->dst); + + for (u32 dy = 0; dy < job->height; ++dy, src_y += hscale) { + src = (u16 *)((u8 *)(job->src) + job->srcPitch * f18_floor(src_y)); + + f18 src_x = f18_zero; + for (u32 dx = 0; dx < job->width; ++dx, src_x += wscale) { + dst[dx] = src[f18_floor(src_x)]; + } + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } + } + } else { + const size_t widthPitch = job->width * job->dstPixelMul; + const void *src = (void *)job->src; + void *dst = (void *)job->dst; + + for (u32 dy = 0; dy < job->height; ++dy) { + memcpy(dst, src, widthPitch); + + src = (void *)((u8 *)(src) + job->srcPitch); + dst = (void *)((u8 *)(dst) + job->dstPitch); + } + } +} + +/*! + */ +static void executeBlit_TextureCopy_32_to_16(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u32 *src = static_cast(job->src); + u16 *dst = static_cast(job->dst); + + if (job->stretch) { + const float wscale = job->x_stretch; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (u32 *)((u8 *)(job->src) + job->srcPitch * src_y); + + for (u32 dx = 0; dx < w; ++dx) { + const u32 src_x = (u32)(dx * wscale); + // 16 bit Blitter depends on pre-multiplied color + const u32 s = PixelLerp32(src[src_x] | 0xFF000000, extractAlpha(src[src_x])); + dst[dx] = video::A8R8G8B8toA1R5G5B5(s); + } + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } + } else { + for (u32 dy = 0; dy != h; ++dy) { + for (u32 dx = 0; dx != w; ++dx) { + // 16 bit Blitter depends on pre-multiplied color + const u32 s = PixelLerp32(src[dx] | 0xFF000000, extractAlpha(src[dx])); + dst[dx] = video::A8R8G8B8toA1R5G5B5(s); + } + + src = (u32 *)((u8 *)(src) + job->srcPitch); + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } + } +} + +/*! + */ +static void executeBlit_TextureCopy_24_to_16(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u8 *src = static_cast(job->src); + u16 *dst = static_cast(job->dst); + + if (job->stretch) { + const float wscale = job->x_stretch * 3.f; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (u8 *)(job->src) + job->srcPitch * src_y; + + for (u32 dx = 0; dx < w; ++dx) { + const u8 *src_x = src + (u32)(dx * wscale); + dst[dx] = video::RGBA16(src_x[0], src_x[1], src_x[2]); + } + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } + } else { + for (u32 dy = 0; dy != h; ++dy) { + const u8 *s = src; + for (u32 dx = 0; dx != w; ++dx) { + dst[dx] = video::RGBA16(s[0], s[1], s[2]); + s += 3; + } + + src = src + job->srcPitch; + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } + } +} + +/*! + */ +static void executeBlit_TextureCopy_16_to_32(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u16 *src = static_cast(job->src); + u32 *dst = static_cast(job->dst); + + if (job->stretch) { + const float wscale = job->x_stretch; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (u16 *)((u8 *)(job->src) + job->srcPitch * src_y); + + for (u32 dx = 0; dx < w; ++dx) { + const u32 src_x = (u32)(dx * wscale); + dst[dx] = video::A1R5G5B5toA8R8G8B8(src[src_x]); + } + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } + } else { + for (u32 dy = 0; dy != h; ++dy) { + for (u32 dx = 0; dx != w; ++dx) { + dst[dx] = video::A1R5G5B5toA8R8G8B8(src[dx]); + } + + src = (u16 *)((u8 *)(src) + job->srcPitch); + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } + } +} + +static void executeBlit_TextureCopy_16_to_24(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u16 *src = static_cast(job->src); + u8 *dst = static_cast(job->dst); + + if (job->stretch) { + const float wscale = job->x_stretch; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (u16 *)((u8 *)(job->src) + job->srcPitch * src_y); + + for (u32 dx = 0; dx < w; ++dx) { + const u32 src_x = (u32)(dx * wscale); + u32 color = video::A1R5G5B5toA8R8G8B8(src[src_x]); + u8 *writeTo = &dst[dx * 3]; + *writeTo++ = (color >> 16) & 0xFF; + *writeTo++ = (color >> 8) & 0xFF; + *writeTo++ = color & 0xFF; + } + dst += job->dstPitch; + } + } else { + for (u32 dy = 0; dy != h; ++dy) { + for (u32 dx = 0; dx != w; ++dx) { + u32 color = video::A1R5G5B5toA8R8G8B8(src[dx]); + u8 *writeTo = &dst[dx * 3]; + *writeTo++ = (color >> 16) & 0xFF; + *writeTo++ = (color >> 8) & 0xFF; + *writeTo++ = color & 0xFF; + } + + src = (u16 *)((u8 *)(src) + job->srcPitch); + dst += job->dstPitch; + } + } +} + +/*! + */ +static void executeBlit_TextureCopy_24_to_32(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u8 *src = static_cast(job->src); + u32 *dst = static_cast(job->dst); + + if (job->stretch) { + const float wscale = job->x_stretch * 3.f; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (const u8 *)job->src + (job->srcPitch * src_y); + + for (u32 dx = 0; dx < w; ++dx) { + const u8 *s = src + (u32)(dx * wscale); + dst[dx] = 0xFF000000 | s[0] << 16 | s[1] << 8 | s[2]; + } + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } + } else { + for (u32 dy = 0; dy < job->height; ++dy) { + const u8 *s = src; + + for (u32 dx = 0; dx < job->width; ++dx) { + dst[dx] = 0xFF000000 | s[0] << 16 | s[1] << 8 | s[2]; + s += 3; + } + + src = src + job->srcPitch; + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } + } +} + +static void executeBlit_TextureCopy_32_to_24(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u32 *src = static_cast(job->src); + u8 *dst = static_cast(job->dst); + + if (job->stretch) { + const float wscale = job->x_stretch; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (u32 *)((u8 *)(job->src) + job->srcPitch * src_y); + + for (u32 dx = 0; dx < w; ++dx) { + const u32 src_x = src[(u32)(dx * wscale)]; + u8 *writeTo = &dst[dx * 3]; + *writeTo++ = (src_x >> 16) & 0xFF; + *writeTo++ = (src_x >> 8) & 0xFF; + *writeTo++ = src_x & 0xFF; + } + dst += job->dstPitch; + } + } else { + for (u32 dy = 0; dy != h; ++dy) { + for (u32 dx = 0; dx != w; ++dx) { + u8 *writeTo = &dst[dx * 3]; + *writeTo++ = (src[dx] >> 16) & 0xFF; + *writeTo++ = (src[dx] >> 8) & 0xFF; + *writeTo++ = src[dx] & 0xFF; + } + + src = (u32 *)((u8 *)(src) + job->srcPitch); + dst += job->dstPitch; + } + } +} + +/*! + */ +static void executeBlit_TextureBlend_16_to_16(const SBlitJob *job) +{ + const f18 wscale = f32_to_f18(job->x_stretch); + const f18 hscale = f32_to_f18(job->y_stretch); + + f18 src_y = f18_zero; + u16 *dst = (u16 *)job->dst; + + for (u32 dy = 0; dy < job->height; ++dy, src_y += hscale) { + const u16 *src = (u16 *)((u8 *)(job->src) + job->srcPitch * f18_floor(src_y)); + f18 src_x = f18_zero; + for (u32 dx = 0; dx < job->width; ++dx, src_x += wscale) { + dst[dx] = PixelBlend16(dst[dx], src[f18_floor(src_x)]); + } + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + */ +static void executeBlit_TextureBlend_32_to_32(const SBlitJob *job) +{ + const f18 wscale = f32_to_f18(job->x_stretch); + const f18 hscale = f32_to_f18(job->y_stretch); + + f18 src_y = f18_zero; + u32 *dst = (u32 *)job->dst; + for (u32 dy = 0; dy < job->height; ++dy, src_y += hscale) { + const u32 *src = (u32 *)((u8 *)(job->src) + job->srcPitch * f18_floor(src_y)); + + f18 src_x = f18_zero; + for (u32 dx = 0; dx < job->width; ++dx, src_x += wscale) { + dst[dx] = PixelBlend32(dst[dx], src[f18_floor(src_x)]); + } + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + */ +static void executeBlit_TextureBlendColor_16_to_16(const SBlitJob *job) +{ + const u16 blend = video::A8R8G8B8toA1R5G5B5(job->argb); + + const f18 wscale = f32_to_f18(job->x_stretch); + const f18 hscale = f32_to_f18(job->y_stretch); + + f18 src_y = f18_zero; + u16 *dst = (u16 *)job->dst; + for (u32 dy = 0; dy < job->height; ++dy, src_y += hscale) { + const u16 *src = (u16 *)((u8 *)(job->src) + job->srcPitch * f18_floor(src_y)); + f18 src_x = f18_zero; + for (u32 dx = 0; dx < job->width; ++dx, src_x += wscale) { + u16 c0 = src[f18_floor(src_x)]; + if (0 == (c0 & 0x8000)) + continue; + + dst[dx] = PixelMul16_2(c0, blend); + } + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + */ +static void executeBlit_TextureBlendColor_32_to_32(const SBlitJob *job) +{ + const f18 wscale = f32_to_f18(job->x_stretch); + const f18 hscale = f32_to_f18(job->y_stretch); + + u32 *dst = (u32 *)job->dst; + f18 src_y = f18_zero; + for (u32 dy = 0; dy < job->height; ++dy, src_y += hscale) { + const u32 *src = (u32 *)((u8 *)(job->src) + job->srcPitch * f18_floor(src_y)); + + f18 src_x = f18_zero; + for (u32 dx = 0; dx < job->width; ++dx, src_x += wscale) { + dst[dx] = PixelBlend32(dst[dx], PixelMul32_2(src[f18_floor(src_x)], job->argb)); + } + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + */ +static void executeBlit_Color_16_to_16(const SBlitJob *job) +{ + const u16 c = video::A8R8G8B8toA1R5G5B5(job->argb); + u16 *dst = (u16 *)job->dst; + + for (u32 dy = 0; dy < job->height; ++dy) { + memset16(dst, c, job->srcPitch); + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + */ +static void executeBlit_Color_32_to_32(const SBlitJob *job) +{ + u32 *dst = (u32 *)job->dst; + + for (u32 dy = 0; dy < job->height; ++dy) { + memset32(dst, job->argb, job->srcPitch); + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + */ +static void executeBlit_ColorAlpha_16_to_16(const SBlitJob *job) +{ + u16 *dst = (u16 *)job->dst; + + const u16 alpha = extractAlpha(job->argb) >> 3; + if (0 == alpha) + return; + const u32 src = video::A8R8G8B8toA1R5G5B5(job->argb); + + for (u32 dy = 0; dy != job->height; ++dy) { + for (u32 dx = 0; dx != job->width; ++dx) { + dst[dx] = PixelBlend16(dst[dx], src, alpha); + } + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + */ +static void executeBlit_ColorAlpha_32_to_32(const SBlitJob *job) +{ + const u32 alpha = extractAlpha(job->argb); + if (0 == alpha) + return; + + u32 *dst = (u32 *)job->dst; + for (u32 dy = 0; dy < job->height; ++dy) { + for (u32 dx = 0; dx < job->width; ++dx) { + dst[dx] = PixelBlend32(dst[dx], job->argb, alpha); + } + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + Pixel => + color = sourceAlpha > 0 ? source, else dest + alpha = max(destAlpha, sourceAlpha) +*/ +inline u16 PixelCombine16(const u16 c2, const u16 c1) +{ + if (video::getAlpha(c1) > 0) + return c1; + else + return c2; +} + +/*! + Combine alpha channels (increases alpha / reduces transparency) +*/ +static void executeBlit_TextureCombineColor_16_to_16(const SBlitJob *job) +{ + const u32 w = job->width * 2; + const u32 h = job->height * 2; + u16 *src = (u16 *)job->src; + u16 *dst = (u16 *)job->dst; + + const u16 jobColor = video::A8R8G8B8toA1R5G5B5(job->argb); + + /* + Stretch not supported. + */ + for (u32 dy = 0; dy != h; dy++) { + for (u32 dx = 0; dx != w; dx++) { + const u16 src_x = src[dx]; + const u16 dst_x = dst[dx]; + dst[dx] = PixelCombine16(dst_x, PixelMul16_2(src_x, jobColor)); + } + src = (u16 *)((u8 *)(src) + job->srcPitch); + dst = (u16 *)((u8 *)(dst) + job->dstPitch); + } +} + +/*! + Combine alpha channels (increases alpha / reduces transparency) +*/ +static void executeBlit_TextureCombineColor_16_to_24(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u16 *src = static_cast(job->src); + u8 *dst = static_cast(job->dst); + + const u16 jobColor = video::A8R8G8B8toA1R5G5B5(job->argb); + + if (job->stretch) { + const float wscale = job->x_stretch; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (u16 *)((u8 *)(job->src) + job->srcPitch * src_y); + + for (u32 dx = 0; dx < w; ++dx) { + const u32 src_x = (u32)(dx * wscale); + u32 color = PixelMul16_2(video::A1R5G5B5toA8R8G8B8(src[src_x]), jobColor); + u8 *writeTo = &dst[dx * 3]; + if (video::getAlpha(src[src_x]) > 0) { // only overlay if source has visible alpha (alpha == 1) + *writeTo++ = (color >> 16) & 0xFF; + *writeTo++ = (color >> 8) & 0xFF; + *writeTo++ = color & 0xFF; + } + } + dst += job->dstPitch; + } + } else { + for (u32 dy = 0; dy != h; ++dy) { + for (u32 dx = 0; dx != w; ++dx) { + u32 color = PixelMul16_2(video::A1R5G5B5toA8R8G8B8(src[dx]), jobColor); + u8 *writeTo = &dst[dx * 3]; + if (video::getAlpha(src[dx]) > 0) { // only overlay if source has visible alpha (alpha == 1) + *writeTo++ = (color >> 16) & 0xFF; + *writeTo++ = (color >> 8) & 0xFF; + *writeTo++ = color & 0xFF; + } + } + + src = (u16 *)((u8 *)(src) + job->srcPitch); + dst += job->dstPitch; + } + } +} + +/*! + Pixel => + color = dest * ( 1 - SourceAlpha ) + source * SourceAlpha, + alpha = destAlpha * ( 1 - SourceAlpha ) + sourceAlpha + + where "1" means "full scale" (255) +*/ +inline u32 PixelCombine32(const u32 c2, const u32 c1) +{ + // alpha test + u32 alpha = c1 & 0xFF000000; + + if (0 == alpha) + return c2; + if (0xFF000000 == alpha) { + return c1; + } + + alpha >>= 24; + + // add highbit alpha, if ( alpha > 127 ) alpha += 1; + // stretches [0;255] to [0;256] to avoid division by 255. use division 256 == shr 8 + alpha += (alpha >> 7); + + u32 srcRB = c1 & 0x00FF00FF; + u32 srcXG = c1 & 0x0000FF00; + + u32 dstRB = c2 & 0x00FF00FF; + u32 dstXG = c2 & 0x0000FF00; + + u32 rb = srcRB - dstRB; + u32 xg = srcXG - dstXG; + + rb *= alpha; + xg *= alpha; + rb >>= 8; + xg >>= 8; + + rb += dstRB; + xg += dstXG; + + rb &= 0x00FF00FF; + xg &= 0x0000FF00; + + u32 sa = c1 >> 24; + u32 da = c2 >> 24; + u32 blendAlpha_fix8 = (sa * 256 + da * (256 - alpha)) >> 8; + return blendAlpha_fix8 << 24 | rb | xg; +} + +/*! + Combine alpha channels (increases alpha / reduces transparency) + Destination alpha is treated as full 255 +*/ +static void executeBlit_TextureCombineColor_32_to_24(const SBlitJob *job) +{ + const u32 w = job->width; + const u32 h = job->height; + const u32 *src = static_cast(job->src); + u8 *dst = static_cast(job->dst); + + if (job->stretch) { + const float wscale = job->x_stretch; + const float hscale = job->y_stretch; + + for (u32 dy = 0; dy < h; ++dy) { + const u32 src_y = (u32)(dy * hscale); + src = (u32 *)((u8 *)(job->src) + job->srcPitch * src_y); + + for (u32 dx = 0; dx < w; ++dx) { + const u32 src_x = src[(u32)(dx * wscale)]; + u8 *writeTo = &dst[dx * 3]; + const u32 dst_x = 0xFF000000 | writeTo[0] << 16 | writeTo[1] << 8 | writeTo[2]; + const u32 combo = PixelCombine32(dst_x, PixelMul32_2(src_x, job->argb)); + *writeTo++ = (combo >> 16) & 0xFF; + *writeTo++ = (combo >> 8) & 0xFF; + *writeTo++ = combo & 0xFF; + } + dst += job->dstPitch; + } + } else { + for (u32 dy = 0; dy != h; ++dy) { + for (u32 dx = 0; dx != w; ++dx) { + u8 *writeTo = &dst[dx * 3]; + const u32 dst_x = 0xFF000000 | writeTo[0] << 16 | writeTo[1] << 8 | writeTo[2]; + const u32 combo = PixelCombine32(dst_x, PixelMul32_2(src[dx], job->argb)); + *writeTo++ = (combo >> 16) & 0xFF; + *writeTo++ = (combo >> 8) & 0xFF; + *writeTo++ = combo & 0xFF; + } + + src = (u32 *)((u8 *)(src) + job->srcPitch); + dst += job->dstPitch; + } + } +} + +/*! + Combine alpha channels (increases alpha / reduces transparency) +*/ +static void executeBlit_TextureCombineColor_32_to_32(const SBlitJob *job) +{ + u32 *src = (u32 *)job->src; + u32 *dst = (u32 *)job->dst; + + for (u32 dy = 0; dy != job->height; ++dy) { + for (u32 dx = 0; dx != job->width; ++dx) { + dst[dx] = PixelCombine32(dst[dx], PixelMul32_2(src[dx], job->argb)); + } + src = (u32 *)((u8 *)(src) + job->srcPitch); + dst = (u32 *)((u8 *)(dst) + job->dstPitch); + } +} + +// Blitter Operation +enum eBlitter +{ + BLITTER_INVALID = 0, + BLITTER_COLOR, + BLITTER_COLOR_ALPHA, + BLITTER_TEXTURE, + BLITTER_TEXTURE_ALPHA_BLEND, + BLITTER_TEXTURE_ALPHA_COLOR_BLEND, + BLITTER_TEXTURE_COMBINE_ALPHA, +}; + +typedef void (*tExecuteBlit)(const SBlitJob *job); + +/*! + */ +struct blitterTable +{ + eBlitter operation; + s32 destFormat; + s32 sourceFormat; + tExecuteBlit func; +}; + +static const blitterTable blitTable[] = { + {BLITTER_TEXTURE, -2, -2, executeBlit_TextureCopy_x_to_x}, + {BLITTER_TEXTURE, video::ECF_A1R5G5B5, video::ECF_A8R8G8B8, executeBlit_TextureCopy_32_to_16}, + {BLITTER_TEXTURE, video::ECF_A1R5G5B5, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_16}, + {BLITTER_TEXTURE, video::ECF_A8R8G8B8, video::ECF_A1R5G5B5, executeBlit_TextureCopy_16_to_32}, + {BLITTER_TEXTURE, video::ECF_A8R8G8B8, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_32}, + {BLITTER_TEXTURE, video::ECF_R8G8B8, video::ECF_A1R5G5B5, executeBlit_TextureCopy_16_to_24}, + {BLITTER_TEXTURE, video::ECF_R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureCopy_32_to_24}, + {BLITTER_TEXTURE_ALPHA_BLEND, video::ECF_A1R5G5B5, video::ECF_A1R5G5B5, executeBlit_TextureBlend_16_to_16}, + {BLITTER_TEXTURE_ALPHA_BLEND, video::ECF_A8R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureBlend_32_to_32}, + {BLITTER_TEXTURE_ALPHA_COLOR_BLEND, video::ECF_A1R5G5B5, video::ECF_A1R5G5B5, executeBlit_TextureBlendColor_16_to_16}, + {BLITTER_TEXTURE_ALPHA_COLOR_BLEND, video::ECF_A8R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureBlendColor_32_to_32}, + {BLITTER_COLOR, video::ECF_A1R5G5B5, -1, executeBlit_Color_16_to_16}, + {BLITTER_COLOR, video::ECF_A8R8G8B8, -1, executeBlit_Color_32_to_32}, + {BLITTER_COLOR_ALPHA, video::ECF_A1R5G5B5, -1, executeBlit_ColorAlpha_16_to_16}, + {BLITTER_COLOR_ALPHA, video::ECF_A8R8G8B8, -1, executeBlit_ColorAlpha_32_to_32}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_A8R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureCombineColor_32_to_32}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_A8R8G8B8, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_32}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_R8G8B8, video::ECF_A8R8G8B8, executeBlit_TextureCombineColor_32_to_24}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_R8G8B8, video::ECF_R8G8B8, executeBlit_TextureCopy_x_to_x}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_A1R5G5B5, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_16}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_A1R5G5B5, video::ECF_A1R5G5B5, executeBlit_TextureCombineColor_16_to_16}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_A1R5G5B5, video::ECF_R8G8B8, executeBlit_TextureCopy_24_to_16}, + {BLITTER_TEXTURE_COMBINE_ALPHA, video::ECF_R8G8B8, video::ECF_A1R5G5B5, executeBlit_TextureCombineColor_16_to_24}, + {BLITTER_INVALID, -1, -1, 0}, + }; + +static inline tExecuteBlit getBlitter2(eBlitter operation, const video::IImage *dest, const video::IImage *source) +{ + video::ECOLOR_FORMAT sourceFormat = (video::ECOLOR_FORMAT)(source ? source->getColorFormat() : -1); + video::ECOLOR_FORMAT destFormat = (video::ECOLOR_FORMAT)(dest ? dest->getColorFormat() : -1); + + const blitterTable *b = blitTable; + + while (b->operation != BLITTER_INVALID) { + if (b->operation == operation) { + if ((b->destFormat == -1 || b->destFormat == destFormat) && + (b->sourceFormat == -1 || b->sourceFormat == sourceFormat)) + return b->func; + else if (b->destFormat == -2 && (sourceFormat == destFormat)) + return b->func; + } + b += 1; + } + return 0; +} + +// bounce clipping to texture +inline void setClip(AbsRectangle &out, const core::rect *clip, + const video::IImage *tex, s32 passnative, const core::dimension2d *tex_org) +{ + if (0 == tex) { + if (clip && passnative) { + out.x0 = clip->UpperLeftCorner.X; + out.x1 = clip->LowerRightCorner.X; + out.y0 = clip->UpperLeftCorner.Y; + out.y1 = clip->LowerRightCorner.Y; + } else { + out.x0 = 0; + out.x1 = 0; + out.y0 = 0; + out.y1 = 0; + } + return; + } + + const s32 w = tex->getDimension().Width; + const s32 h = tex->getDimension().Height; + + // driver could have changed texture size. + if (clip && tex_org && ((u32)w != tex_org->Width || (u32)h != tex_org->Height)) { + out.x0 = core::s32_clamp((clip->UpperLeftCorner.X * w) / tex_org->Width, 0, w - 1); + out.x1 = core::s32_clamp((clip->LowerRightCorner.X * w) / tex_org->Width, out.x0, w); + out.y0 = core::s32_clamp((clip->UpperLeftCorner.Y * h) / tex_org->Height, 0, h - 1); + out.y1 = core::s32_clamp((clip->LowerRightCorner.Y * h) / tex_org->Height, out.y0, h); + } else if (clip) { + // y-1 to prevent starting on illegal memory (not ideal!). + out.x0 = core::s32_clamp(clip->UpperLeftCorner.X, 0, w - 1); + out.x1 = core::s32_clamp(clip->LowerRightCorner.X, passnative ? 0 : out.x0, w); + out.y0 = core::s32_clamp(clip->UpperLeftCorner.Y, 0, h - 1); + out.y1 = core::s32_clamp(clip->LowerRightCorner.Y, passnative ? 0 : out.y0, h); + } else { + out.x0 = 0; + out.y0 = 0; + out.x1 = w; + out.y1 = h; + } +} + +/*! + a generic 2D Blitter +*/ +static s32 Blit(eBlitter operation, + video::IImage *dest, + const core::rect *destClipping, + const core::position2d *destPos, + video::IImage *const source, + const core::rect *sourceClipping, + u32 argb) +{ + tExecuteBlit blitter = getBlitter2(operation, dest, source); + if (0 == blitter) { + return 0; + } + + // Clipping + AbsRectangle sourceClip; + AbsRectangle destClip; + AbsRectangle v; + + SBlitJob job; + + setClip(sourceClip, sourceClipping, source, 1, 0); + setClip(destClip, destClipping, dest, 0, 0); + + v.x0 = destPos ? destPos->X : 0; + v.y0 = destPos ? destPos->Y : 0; + v.x1 = v.x0 + (sourceClip.x1 - sourceClip.x0); + v.y1 = v.y0 + (sourceClip.y1 - sourceClip.y0); + + if (!intersect(job.Dest, destClip, v)) + return 0; + + job.width = job.Dest.x1 - job.Dest.x0; + job.height = job.Dest.y1 - job.Dest.y0; + + job.Source.x0 = sourceClip.x0 + (job.Dest.x0 - v.x0); + job.Source.x1 = job.Source.x0 + job.width; + job.Source.y0 = sourceClip.y0 + (job.Dest.y0 - v.y0); + job.Source.y1 = job.Source.y0 + job.height; + + job.argb = argb; + + job.stretch = false; + job.x_stretch = 1.f; + job.y_stretch = 1.f; + + if (source) { + job.srcPitch = source->getPitch(); + job.srcPixelMul = source->getBytesPerPixel(); + job.src = (void *)((u8 *)source->getData() + (job.Source.y0 * job.srcPitch) + (job.Source.x0 * job.srcPixelMul)); + } else { + // use srcPitch for color operation on dest + job.srcPitch = job.width * dest->getBytesPerPixel(); + } + + job.dstPitch = dest->getPitch(); + job.dstPixelMul = dest->getBytesPerPixel(); + job.dst = (void *)((u8 *)dest->getData() + (job.Dest.y0 * job.dstPitch) + (job.Dest.x0 * job.dstPixelMul)); + + blitter(&job); + + return 1; +} + +} diff --git a/irr/src/CBoneSceneNode.cpp b/irr/src/CBoneSceneNode.cpp new file mode 100644 index 000000000..b9eb8892e --- /dev/null +++ b/irr/src/CBoneSceneNode.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CBoneSceneNode.h" + +#include + +namespace irr +{ +namespace scene +{ + +//! constructor +CBoneSceneNode::CBoneSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id, + u32 boneIndex, const std::optional &boneName) : + IBoneSceneNode(parent, mgr, id), + BoneIndex(boneIndex), + AnimationMode(EBAM_AUTOMATIC), SkinningSpace(EBSS_LOCAL) +{ +#ifdef _DEBUG + setDebugName("CBoneSceneNode"); +#endif + setName(boneName); +} + +//! Returns the index of the bone +u32 CBoneSceneNode::getBoneIndex() const +{ + return BoneIndex; +} + +//! Sets the animation mode of the bone. Returns true if successful. +bool CBoneSceneNode::setAnimationMode(E_BONE_ANIMATION_MODE mode) +{ + AnimationMode = mode; + return true; +} + +//! Gets the current animation mode of the bone +E_BONE_ANIMATION_MODE CBoneSceneNode::getAnimationMode() const +{ + return AnimationMode; +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CBoneSceneNode::getBoundingBox() const +{ + return Box; +} + +/* +//! Returns the relative transformation of the scene node. +core::matrix4 CBoneSceneNode::getRelativeTransformation() const +{ + return core::matrix4(); // RelativeTransformation; +} +*/ + +void CBoneSceneNode::OnAnimate(u32 timeMs) +{ + if (IsVisible) { + // update absolute position + // updateAbsolutePosition(); + + // perform the post render process on all children + ISceneNodeList::iterator it = Children.begin(); + for (; it != Children.end(); ++it) + (*it)->OnAnimate(timeMs); + } +} + +void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node) +{ + Node->updateAbsolutePosition(); + + ISceneNodeList::const_iterator it = Node->getChildren().begin(); + for (; it != Node->getChildren().end(); ++it) { + helper_updateAbsolutePositionOfAllChildren((*it)); + } +} + +void CBoneSceneNode::updateAbsolutePositionOfAllChildren() +{ + helper_updateAbsolutePositionOfAllChildren(this); +} + +} // namespace scene +} // namespace irr diff --git a/irr/src/CBoneSceneNode.h b/irr/src/CBoneSceneNode.h new file mode 100644 index 000000000..8e1a0f7a1 --- /dev/null +++ b/irr/src/CBoneSceneNode.h @@ -0,0 +1,70 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +// Used with SkinnedMesh and IAnimatedMeshSceneNode, for boned meshes + +#include "IBoneSceneNode.h" + +#include + +namespace irr +{ +namespace scene +{ + +class CBoneSceneNode : public IBoneSceneNode +{ +public: + //! constructor + CBoneSceneNode(ISceneNode *parent, ISceneManager *mgr, + s32 id = -1, u32 boneIndex = 0, + const std::optional &boneName = std::nullopt); + + //! Returns the index of the bone + u32 getBoneIndex() const override; + + //! Sets the animation mode of the bone. Returns true if successful. + bool setAnimationMode(E_BONE_ANIMATION_MODE mode) override; + + //! Gets the current animation mode of the bone + E_BONE_ANIMATION_MODE getAnimationMode() const override; + + //! returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + /* + //! Returns the relative transformation of the scene node. + //core::matrix4 getRelativeTransformation() const override; + */ + + void OnAnimate(u32 timeMs) override; + + void updateAbsolutePositionOfAllChildren() override; + + //! How the relative transformation of the bone is used + void setSkinningSpace(E_BONE_SKINNING_SPACE space) override + { + SkinningSpace = space; + } + + E_BONE_SKINNING_SPACE getSkinningSpace() const override + { + return SkinningSpace; + } + +private: + void helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node); + + u32 BoneIndex; + + core::aabbox3d Box; + + E_BONE_ANIMATION_MODE AnimationMode; + E_BONE_SKINNING_SPACE SkinningSpace; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CCameraSceneNode.cpp b/irr/src/CCameraSceneNode.cpp new file mode 100644 index 000000000..f8899e5ff --- /dev/null +++ b/irr/src/CCameraSceneNode.cpp @@ -0,0 +1,314 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CCameraSceneNode.h" +#include "ISceneManager.h" +#include "IVideoDriver.h" +#include "os.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CCameraSceneNode::CCameraSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position, const core::vector3df &lookat) : + ICameraSceneNode(parent, mgr, id, position), + BoundingBox(core::vector3df(0, 0, 0)), // Camera has no size. Still not sure if FLT_MAX might be the better variant + Target(lookat), UpVector(0.0f, 1.0f, 0.0f), ZNear(1.0f), ZFar(3000.0f), + InputReceiverEnabled(true), TargetAndRotationAreBound(false) +{ +#ifdef _DEBUG + setDebugName("CCameraSceneNode"); +#endif + + // set default projection + Fovy = core::PI / 2.5f; // Field of view, in radians. + Aspect = 4.0f / 3.0f; // Aspect ratio. + + const video::IVideoDriver *const d = mgr ? mgr->getVideoDriver() : 0; + if (d) { + if (d->getCurrentRenderTargetSize().Height) + Aspect = (f32)d->getCurrentRenderTargetSize().Width / + (f32)d->getCurrentRenderTargetSize().Height; + } + + ViewArea.setFarNearDistance(ZFar - ZNear); + recalculateProjectionMatrix(); + recalculateViewArea(); +} + +//! Disables or enables the camera to get key or mouse inputs. +void CCameraSceneNode::setInputReceiverEnabled(bool enabled) +{ + InputReceiverEnabled = enabled; +} + +//! Returns if the input receiver of the camera is currently enabled. +bool CCameraSceneNode::isInputReceiverEnabled() const +{ + return InputReceiverEnabled; +} + +//! Sets the projection matrix of the camera. +/** The core::matrix4 class has some methods +to build a projection matrix. e.g: core::matrix4::buildProjectionMatrixPerspectiveFovLH +\param projection: The new projection matrix of the camera. */ +void CCameraSceneNode::setProjectionMatrix(const core::matrix4 &projection, bool isOrthogonal) +{ + IsOrthogonal = isOrthogonal; + ViewArea.getTransform(video::ETS_PROJECTION) = projection; +} + +//! Gets the current projection matrix of the camera +//! \return Returns the current projection matrix of the camera. +const core::matrix4 &CCameraSceneNode::getProjectionMatrix() const +{ + return ViewArea.getTransform(video::ETS_PROJECTION); +} + +//! Gets the current view matrix of the camera +//! \return Returns the current view matrix of the camera. +const core::matrix4 &CCameraSceneNode::getViewMatrix() const +{ + return ViewArea.getTransform(video::ETS_VIEW); +} + +//! Sets a custom view matrix affector. The matrix passed here, will be +//! multiplied with the view matrix when it gets updated. +//! This allows for custom camera setups like, for example, a reflection camera. +/** \param affector: The affector matrix. */ +void CCameraSceneNode::setViewMatrixAffector(const core::matrix4 &affector) +{ + Affector = affector; +} + +//! Gets the custom view matrix affector. +const core::matrix4 &CCameraSceneNode::getViewMatrixAffector() const +{ + return Affector; +} + +//! It is possible to send mouse and key events to the camera. Most cameras +//! may ignore this input, but camera scene nodes which are created for +//! example with scene::ISceneManager::addMayaCameraSceneNode or +//! scene::ISceneManager::addFPSCameraSceneNode, may want to get this input +//! for changing their position, look at target or whatever. +bool CCameraSceneNode::OnEvent(const SEvent &event) +{ + // animators have been deleted; nothing happens here now! + return false; +} + +//! sets the look at target of the camera +//! \param pos: Look at target of the camera. +void CCameraSceneNode::setTarget(const core::vector3df &pos) +{ + Target = pos; + + if (TargetAndRotationAreBound) { + const core::vector3df toTarget = Target - getAbsolutePosition(); + ISceneNode::setRotation(toTarget.getHorizontalAngle()); + } +} + +//! Sets the rotation of the node. +/** This only modifies the relative rotation of the node. +If the camera's target and rotation are bound ( @see bindTargetAndRotation() ) +then calling this will also change the camera's target to match the rotation. +\param rotation New rotation of the node in degrees. */ +void CCameraSceneNode::setRotation(const core::vector3df &rotation) +{ + if (TargetAndRotationAreBound) + Target = getAbsolutePosition() + rotation.rotationToDirection(); + + ISceneNode::setRotation(rotation); +} + +//! Gets the current look at target of the camera +//! \return Returns the current look at target of the camera +const core::vector3df &CCameraSceneNode::getTarget() const +{ + return Target; +} + +//! sets the up vector of the camera +//! \param pos: New upvector of the camera. +void CCameraSceneNode::setUpVector(const core::vector3df &pos) +{ + UpVector = pos; +} + +//! Gets the up vector of the camera. +//! \return Returns the up vector of the camera. +const core::vector3df &CCameraSceneNode::getUpVector() const +{ + return UpVector; +} + +f32 CCameraSceneNode::getNearValue() const +{ + return ZNear; +} + +f32 CCameraSceneNode::getFarValue() const +{ + return ZFar; +} + +f32 CCameraSceneNode::getAspectRatio() const +{ + return Aspect; +} + +f32 CCameraSceneNode::getFOV() const +{ + return Fovy; +} + +void CCameraSceneNode::setNearValue(f32 f) +{ + ZNear = f; + recalculateProjectionMatrix(); + ViewArea.setFarNearDistance(ZFar - ZNear); +} + +void CCameraSceneNode::setFarValue(f32 f) +{ + ZFar = f; + recalculateProjectionMatrix(); + ViewArea.setFarNearDistance(ZFar - ZNear); +} + +void CCameraSceneNode::setAspectRatio(f32 f) +{ + Aspect = f; + recalculateProjectionMatrix(); +} + +void CCameraSceneNode::setFOV(f32 f) +{ + Fovy = f; + recalculateProjectionMatrix(); +} + +void CCameraSceneNode::recalculateProjectionMatrix() +{ + ViewArea.getTransform(video::ETS_PROJECTION).buildProjectionMatrixPerspectiveFovLH(Fovy, Aspect, ZNear, ZFar, false); + IsOrthogonal = false; +} + +//! prerender +void CCameraSceneNode::OnRegisterSceneNode() +{ + if (SceneManager->getActiveCamera() == this) + SceneManager->registerNodeForRendering(this, ESNRP_CAMERA); + + ISceneNode::OnRegisterSceneNode(); +} + +//! render +void CCameraSceneNode::render() +{ + updateMatrices(); + + video::IVideoDriver *driver = SceneManager->getVideoDriver(); + if (driver) { + driver->setTransform(video::ETS_PROJECTION, ViewArea.getTransform(video::ETS_PROJECTION)); + driver->setTransform(video::ETS_VIEW, ViewArea.getTransform(video::ETS_VIEW)); + } +} + +//! update +void CCameraSceneNode::updateMatrices() +{ + core::vector3df pos = getAbsolutePosition(); + core::vector3df tgtv = Target - pos; + tgtv.normalize(); + + // if upvector and vector to the target are the same, we have a + // problem. so solve this problem: + core::vector3df up = UpVector; + up.normalize(); + + f32 dp = tgtv.dotProduct(up); + + if (core::equals(core::abs_(dp), 1.f)) { + up.X += 0.5f; + } + + ViewArea.getTransform(video::ETS_VIEW).buildCameraLookAtMatrixLH(pos, Target, up); + ViewArea.getTransform(video::ETS_VIEW) *= Affector; + recalculateViewArea(); +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CCameraSceneNode::getBoundingBox() const +{ + return BoundingBox; +} + +//! returns the view frustum. +const SViewFrustum *CCameraSceneNode::getViewFrustum() const +{ + return &ViewArea; +} + +void CCameraSceneNode::recalculateViewArea() +{ + ViewArea.cameraPosition = getAbsolutePosition(); + + core::matrix4 m(core::matrix4::EM4CONST_NOTHING); + m.setbyproduct_nocheck(ViewArea.getTransform(video::ETS_PROJECTION), + ViewArea.getTransform(video::ETS_VIEW)); + ViewArea.setFrom(m, false); +} + +//! Set the binding between the camera's rotation adn target. +void CCameraSceneNode::bindTargetAndRotation(bool bound) +{ + TargetAndRotationAreBound = bound; +} + +//! Gets the binding between the camera's rotation and target. +bool CCameraSceneNode::getTargetAndRotationBinding(void) const +{ + return TargetAndRotationAreBound; +} + +//! Creates a clone of this scene node and its children. +ISceneNode *CCameraSceneNode::clone(ISceneNode *newParent, ISceneManager *newManager) +{ + ICameraSceneNode::clone(newParent, newManager); + + if (!newParent) + newParent = Parent; + if (!newManager) + newManager = SceneManager; + + CCameraSceneNode *nb = new CCameraSceneNode(newParent, + newManager, ID, RelativeTranslation, Target); + + nb->ISceneNode::cloneMembers(this, newManager); + nb->ICameraSceneNode::cloneMembers(this); + + nb->Target = Target; + nb->UpVector = UpVector; + nb->Fovy = Fovy; + nb->Aspect = Aspect; + nb->ZNear = ZNear; + nb->ZFar = ZFar; + nb->ViewArea = ViewArea; + nb->Affector = Affector; + nb->InputReceiverEnabled = InputReceiverEnabled; + nb->TargetAndRotationAreBound = TargetAndRotationAreBound; + + if (newParent) + nb->drop(); + return nb; +} + +} // end namespace +} // end namespace diff --git a/irr/src/CCameraSceneNode.h b/irr/src/CCameraSceneNode.h new file mode 100644 index 000000000..668756300 --- /dev/null +++ b/irr/src/CCameraSceneNode.h @@ -0,0 +1,165 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "ICameraSceneNode.h" +#include "SViewFrustum.h" + +namespace irr +{ +namespace scene +{ + +class CCameraSceneNode : public ICameraSceneNode +{ +public: + //! constructor + CCameraSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position = core::vector3df(0, 0, 0), + const core::vector3df &lookat = core::vector3df(0, 0, 100)); + + //! Sets the projection matrix of the camera. + /** The core::matrix4 class has some methods + to build a projection matrix. e.g: core::matrix4::buildProjectionMatrixPerspectiveFovLH. + Note that the matrix will only stay as set by this method until one of + the following Methods are called: setNearValue, setFarValue, setAspectRatio, setFOV. + \param projection The new projection matrix of the camera. + \param isOrthogonal Set this to true if the matrix is an orthogonal one (e.g. + from matrix4::buildProjectionMatrixOrthoLH(). */ + void setProjectionMatrix(const core::matrix4 &projection, bool isOrthogonal = false) override; + + //! Gets the current projection matrix of the camera + //! \return Returns the current projection matrix of the camera. + const core::matrix4 &getProjectionMatrix() const override; + + //! Gets the current view matrix of the camera + //! \return Returns the current view matrix of the camera. + const core::matrix4 &getViewMatrix() const override; + + //! Sets a custom view matrix affector. + /** \param affector: The affector matrix. */ + void setViewMatrixAffector(const core::matrix4 &affector) override; + + //! Gets the custom view matrix affector. + const core::matrix4 &getViewMatrixAffector() const override; + + //! It is possible to send mouse and key events to the camera. Most cameras + //! may ignore this input, but camera scene nodes which are created for + //! example with scene::ISceneManager::addMayaCameraSceneNode or + //! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input + //! for changing their position, look at target or whatever. + bool OnEvent(const SEvent &event) override; + + //! Sets the look at target of the camera + /** If the camera's target and rotation are bound ( @see bindTargetAndRotation() ) + then calling this will also change the camera's scene node rotation to match the target. + \param pos: Look at target of the camera. */ + void setTarget(const core::vector3df &pos) override; + + //! Sets the rotation of the node. + /** This only modifies the relative rotation of the node. + If the camera's target and rotation are bound ( @see bindTargetAndRotation() ) + then calling this will also change the camera's target to match the rotation. + \param rotation New rotation of the node in degrees. */ + void setRotation(const core::vector3df &rotation) override; + + //! Gets the current look at target of the camera + /** \return The current look at target of the camera */ + const core::vector3df &getTarget() const override; + + //! Sets the up vector of the camera. + //! \param pos: New upvector of the camera. + void setUpVector(const core::vector3df &pos) override; + + //! Gets the up vector of the camera. + //! \return Returns the up vector of the camera. + const core::vector3df &getUpVector() const override; + + //! Gets distance from the camera to the near plane. + //! \return Value of the near plane of the camera. + f32 getNearValue() const override; + + //! Gets the distance from the camera to the far plane. + //! \return Value of the far plane of the camera. + f32 getFarValue() const override; + + //! Get the aspect ratio of the camera. + //! \return The aspect ratio of the camera. + f32 getAspectRatio() const override; + + //! Gets the field of view of the camera. + //! \return Field of view of the camera + f32 getFOV() const override; + + //! Sets the value of the near clipping plane. (default: 1.0f) + void setNearValue(f32 zn) override; + + //! Sets the value of the far clipping plane (default: 2000.0f) + void setFarValue(f32 zf) override; + + //! Sets the aspect ratio (default: 4.0f / 3.0f) + void setAspectRatio(f32 aspect) override; + + //! Sets the field of view (Default: PI / 3.5f) + void setFOV(f32 fovy) override; + + //! PreRender event + void OnRegisterSceneNode() override; + + //! Render + void render() override; + + //! Update + void updateMatrices() override; + + //! Returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + //! Returns the view area. + const SViewFrustum *getViewFrustum() const override; + + //! Disables or enables the camera to get key or mouse inputs. + //! If this is set to true, the camera will respond to key inputs + //! otherwise not. + void setInputReceiverEnabled(bool enabled) override; + + //! Returns if the input receiver of the camera is currently enabled. + bool isInputReceiverEnabled() const override; + + //! Returns type of the scene node + ESCENE_NODE_TYPE getType() const override { return ESNT_CAMERA; } + + //! Binds the camera scene node's rotation to its target position and vice versa, or unbinds them. + void bindTargetAndRotation(bool bound) override; + + //! Queries if the camera scene node's rotation and its target position are bound together. + bool getTargetAndRotationBinding(void) const override; + + //! Creates a clone of this scene node and its children. + ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override; + +protected: + void recalculateProjectionMatrix(); + void recalculateViewArea(); + + core::aabbox3d BoundingBox; + + core::vector3df Target; + core::vector3df UpVector; + + f32 Fovy; // Field of view, in radians. + f32 Aspect; // Aspect ratio. + f32 ZNear; // value of the near view-plane. + f32 ZFar; // Z-value of the far view-plane. + + SViewFrustum ViewArea; + core::matrix4 Affector; + + bool InputReceiverEnabled; + bool TargetAndRotationAreBound; +}; + +} // end namespace +} // end namespace diff --git a/irr/src/CColorConverter.cpp b/irr/src/CColorConverter.cpp new file mode 100644 index 000000000..96b22c544 --- /dev/null +++ b/irr/src/CColorConverter.cpp @@ -0,0 +1,760 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CColorConverter.h" +#include "SColor.h" +#include "os.h" +#include "irrString.h" + +namespace irr +{ +namespace video +{ + +//! converts a monochrome bitmap to A1R5G5B5 data +void CColorConverter::convert1BitTo16Bit(const u8 *in, s16 *out, s32 width, s32 height, s32 linepad, bool flip) +{ + if (!in || !out) + return; + + if (flip) + out += width * height; + + for (s32 y = 0; y < height; ++y) { + s32 shift = 7; + if (flip) + out -= width; + + for (s32 x = 0; x < width; ++x) { + out[x] = *in >> shift & 0x01 ? (s16)0xffff : (s16)0x8000; + + if ((--shift) < 0) { // 8 pixel done + shift = 7; + ++in; + } + } + + if (shift != 7) // width did not fill last byte + ++in; + + if (!flip) + out += width; + in += linepad; + } +} + +//! converts a 4 bit palettized image to A1R5G5B5 +void CColorConverter::convert4BitTo16Bit(const u8 *in, s16 *out, s32 width, s32 height, const s32 *palette, s32 linepad, bool flip) +{ + if (!in || !out || !palette) + return; + + if (flip) + out += width * height; + + for (s32 y = 0; y < height; ++y) { + s32 shift = 4; + if (flip) + out -= width; + + for (s32 x = 0; x < width; ++x) { + out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)((*in >> shift) & 0xf)]); + + if (shift == 0) { + shift = 4; + ++in; + } else + shift = 0; + } + + if (shift == 0) // odd width + ++in; + + if (!flip) + out += width; + in += linepad; + } +} + +//! converts a 8 bit palettized image into A1R5G5B5 +void CColorConverter::convert8BitTo16Bit(const u8 *in, s16 *out, s32 width, s32 height, const s32 *palette, s32 linepad, bool flip) +{ + if (!in || !out || !palette) + return; + + if (flip) + out += width * height; + + for (s32 y = 0; y < height; ++y) { + if (flip) + out -= width; // one line back + for (s32 x = 0; x < width; ++x) { + out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)(*in)]); + ++in; + } + if (!flip) + out += width; + in += linepad; + } +} + +//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8 +void CColorConverter::convert8BitTo24Bit(const u8 *in, u8 *out, s32 width, s32 height, const u8 *palette, s32 linepad, bool flip) +{ + if (!in || !out) + return; + + const s32 lineWidth = 3 * width; + if (flip) + out += lineWidth * height; + + for (s32 y = 0; y < height; ++y) { + if (flip) + out -= lineWidth; // one line back + for (s32 x = 0; x < lineWidth; x += 3) { + if (palette) { +#ifdef __BIG_ENDIAN__ + out[x + 0] = palette[(in[0] << 2) + 0]; + out[x + 1] = palette[(in[0] << 2) + 1]; + out[x + 2] = palette[(in[0] << 2) + 2]; +#else + out[x + 0] = palette[(in[0] << 2) + 2]; + out[x + 1] = palette[(in[0] << 2) + 1]; + out[x + 2] = palette[(in[0] << 2) + 0]; +#endif + } else { + out[x + 0] = in[0]; + out[x + 1] = in[0]; + out[x + 2] = in[0]; + } + ++in; + } + if (!flip) + out += lineWidth; + in += linepad; + } +} + +//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8 +void CColorConverter::convert8BitTo32Bit(const u8 *in, u8 *out, s32 width, s32 height, const u8 *palette, s32 linepad, bool flip) +{ + if (!in || !out) + return; + + const u32 lineWidth = 4 * width; + if (flip) + out += lineWidth * height; + + u32 x; + u32 c; + for (u32 y = 0; y < (u32)height; ++y) { + if (flip) + out -= lineWidth; // one line back + + if (palette) { + for (x = 0; x < (u32)width; x += 1) { + c = in[x]; + ((u32 *)out)[x] = ((u32 *)palette)[c]; + } + } else { + for (x = 0; x < (u32)width; x += 1) { + c = in[x]; +#ifdef __BIG_ENDIAN__ + ((u32 *)out)[x] = c << 24 | c << 16 | c << 8 | 0x000000FF; +#else + ((u32 *)out)[x] = 0xFF000000 | c << 16 | c << 8 | c; +#endif + } + } + + if (!flip) + out += lineWidth; + in += width + linepad; + } +} + +//! converts 16bit data to 16bit data +void CColorConverter::convert16BitTo16Bit(const s16 *in, s16 *out, s32 width, s32 height, s32 linepad, bool flip) +{ + if (!in || !out) + return; + + if (flip) + out += width * height; + + for (s32 y = 0; y < height; ++y) { + if (flip) + out -= width; +#ifdef __BIG_ENDIAN__ + for (s32 x = 0; x < width; ++x) + out[x] = os::Byteswap::byteswap(in[x]); +#else + memcpy(out, in, width * sizeof(s16)); +#endif + if (!flip) + out += width; + in += width; + in += linepad; + } +} + +//! copies R8G8B8 24bit data to 24bit data +void CColorConverter::convert24BitTo24Bit(const u8 *in, u8 *out, s32 width, s32 height, s32 linepad, bool flip, bool bgr) +{ + if (!in || !out) + return; + + const s32 lineWidth = 3 * width; + if (flip) + out += lineWidth * height; + + for (s32 y = 0; y < height; ++y) { + if (flip) + out -= lineWidth; + if (bgr) { + for (s32 x = 0; x < lineWidth; x += 3) { + out[x + 0] = in[x + 2]; + out[x + 1] = in[x + 1]; + out[x + 2] = in[x + 0]; + } + } else { + memcpy(out, in, lineWidth); + } + if (!flip) + out += lineWidth; + in += lineWidth; + in += linepad; + } +} + +//! Resizes the surface to a new size and converts it at the same time +//! to an A8R8G8B8 format, returning the pointer to the new buffer. +void CColorConverter::convert16bitToA8R8G8B8andResize(const s16 *in, s32 *out, s32 newWidth, s32 newHeight, s32 currentWidth, s32 currentHeight) +{ + if (!newWidth || !newHeight) + return; + + // note: this is very very slow. (i didn't want to write a fast version. + // but hopefully, nobody wants to convert surfaces every frame. + + f32 sourceXStep = (f32)currentWidth / (f32)newWidth; + f32 sourceYStep = (f32)currentHeight / (f32)newHeight; + f32 sy; + s32 t; + + for (s32 x = 0; x < newWidth; ++x) { + sy = 0.0f; + + for (s32 y = 0; y < newHeight; ++y) { + t = in[(s32)(((s32)sy) * currentWidth + x * sourceXStep)]; + t = (((t >> 15) & 0x1) << 31) | (((t >> 10) & 0x1F) << 19) | + (((t >> 5) & 0x1F) << 11) | (t & 0x1F) << 3; + out[(s32)(y * newWidth + x)] = t; + + sy += sourceYStep; + } + } +} + +//! copies X8R8G8B8 32 bit data +void CColorConverter::convert32BitTo32Bit(const s32 *in, s32 *out, s32 width, s32 height, s32 linepad, bool flip) +{ + if (!in || !out) + return; + + if (flip) + out += width * height; + + for (s32 y = 0; y < height; ++y) { + if (flip) + out -= width; +#ifdef __BIG_ENDIAN__ + for (s32 x = 0; x < width; ++x) + out[x] = os::Byteswap::byteswap(in[x]); +#else + memcpy(out, in, width * sizeof(s32)); +#endif + if (!flip) + out += width; + in += width; + in += linepad; + } +} + +void CColorConverter::convert_A1R5G5B5toR8G8B8(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + dB[2] = (*sB & 0x7c00) >> 7; + dB[1] = (*sB & 0x03e0) >> 2; + dB[0] = (*sB & 0x1f) << 3; + + sB += 1; + dB += 3; + } +} + +void CColorConverter::convert_A1R5G5B5toB8G8R8(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + dB[0] = (*sB & 0x7c00) >> 7; + dB[1] = (*sB & 0x03e0) >> 2; + dB[2] = (*sB & 0x1f) << 3; + + sB += 1; + dB += 3; + } +} + +void CColorConverter::convert_A1R5G5B5toR5G5B5A1(const void *sP, s32 sN, void *dP) +{ + const u16 *sB = (const u16 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) { + *dB = (*sB << 1) | (*sB >> 15); + ++sB; + ++dB; + } +} + +void CColorConverter::convert_A1R5G5B5toA8R8G8B8(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u32 *dB = (u32 *)dP; + + for (s32 x = 0; x < sN; ++x) + *dB++ = A1R5G5B5toA8R8G8B8(*sB++); +} + +void CColorConverter::convert_A1R5G5B5toA1R5G5B5(const void *sP, s32 sN, void *dP) +{ + memcpy(dP, sP, sN * 2); +} + +void CColorConverter::convert_A1R5G5B5toR5G6B5(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) + *dB++ = A1R5G5B5toR5G6B5(*sB++); +} + +void CColorConverter::convert_A8R8G8B8toR8G8B8(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + // sB[3] is alpha + dB[0] = sB[2]; + dB[1] = sB[1]; + dB[2] = sB[0]; + + sB += 4; + dB += 3; + } +} + +void CColorConverter::convert_A8R8G8B8toB8G8R8(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + // sB[3] is alpha + dB[0] = sB[0]; + dB[1] = sB[1]; + dB[2] = sB[2]; + + sB += 4; + dB += 3; + } +} + +void CColorConverter::convert_A8R8G8B8toA8R8G8B8(const void *sP, s32 sN, void *dP) +{ + memcpy(dP, sP, sN * 4); +} + +void CColorConverter::convert_A8R8G8B8toA1R5G5B5(const void *sP, s32 sN, void *dP) +{ + u32 *sB = (u32 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) + *dB++ = A8R8G8B8toA1R5G5B5(*sB++); +} + +void CColorConverter::convert_A8R8G8B8toA1B5G5R5(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) { + s32 r = sB[0] >> 3; + s32 g = sB[1] >> 3; + s32 b = sB[2] >> 3; + s32 a = sB[3] >> 3; + + dB[0] = (a << 15) | (r << 10) | (g << 5) | (b); + + sB += 4; + dB += 1; + } +} + +void CColorConverter::convert_A8R8G8B8toR5G6B5(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) { + s32 r = sB[2] >> 3; + s32 g = sB[1] >> 2; + s32 b = sB[0] >> 3; + + dB[0] = (r << 11) | (g << 5) | (b); + + sB += 4; + dB += 1; + } +} + +void CColorConverter::convert_A8R8G8B8toR3G3B2(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + u8 r = sB[2] & 0xe0; + u8 g = (sB[1] & 0xe0) >> 3; + u8 b = (sB[0] & 0xc0) >> 6; + + dB[0] = (r | g | b); + + sB += 4; + dB += 1; + } +} + +void CColorConverter::convert_R8G8B8toR8G8B8(const void *sP, s32 sN, void *dP) +{ + memcpy(dP, sP, sN * 3); +} + +void CColorConverter::convert_R8G8B8toA8R8G8B8(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u32 *dB = (u32 *)dP; + + for (s32 x = 0; x < sN; ++x) { + *dB = 0xff000000 | (sB[0] << 16) | (sB[1] << 8) | sB[2]; + + sB += 3; + ++dB; + } +} + +void CColorConverter::convert_R8G8B8toA1R5G5B5(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) { + s32 r = sB[0] >> 3; + s32 g = sB[1] >> 3; + s32 b = sB[2] >> 3; + + dB[0] = (0x8000) | (r << 10) | (g << 5) | (b); + + sB += 3; + dB += 1; + } +} + +void CColorConverter::convert_B8G8R8toA8R8G8B8(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u32 *dB = (u32 *)dP; + + for (s32 x = 0; x < sN; ++x) { + *dB = 0xff000000 | (sB[2] << 16) | (sB[1] << 8) | sB[0]; + + sB += 3; + ++dB; + } +} + +void CColorConverter::convert_A8R8G8B8toR8G8B8A8(const void *sP, s32 sN, void *dP) +{ + const u32 *sB = (const u32 *)sP; + u32 *dB = (u32 *)dP; + + for (s32 x = 0; x < sN; ++x) { + *dB++ = (*sB << 8) | (*sB >> 24); + ++sB; + } +} + +void CColorConverter::convert_A8R8G8B8toA8B8G8R8(const void *sP, s32 sN, void *dP) +{ + const u32 *sB = (const u32 *)sP; + u32 *dB = (u32 *)dP; + + for (s32 x = 0; x < sN; ++x) { + *dB++ = (*sB & 0xff00ff00) | ((*sB & 0x00ff0000) >> 16) | ((*sB & 0x000000ff) << 16); + ++sB; + } +} + +void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + dB[0] = sB[3]; + dB[1] = sB[2]; + dB[2] = sB[1]; + dB[3] = sB[0]; + + sB += 4; + dB += 4; + } +} + +void CColorConverter::convert_R8G8B8toB8G8R8(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + dB[2] = sB[0]; + dB[1] = sB[1]; + dB[0] = sB[2]; + + sB += 3; + dB += 3; + } +} + +void CColorConverter::convert_R8G8B8toR5G6B5(const void *sP, s32 sN, void *dP) +{ + u8 *sB = (u8 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) { + s32 r = sB[0] >> 3; + s32 g = sB[1] >> 2; + s32 b = sB[2] >> 3; + + dB[0] = (r << 11) | (g << 5) | (b); + + sB += 3; + dB += 1; + } +} + +void CColorConverter::convert_R5G6B5toR5G6B5(const void *sP, s32 sN, void *dP) +{ + memcpy(dP, sP, sN * 2); +} + +void CColorConverter::convert_R5G6B5toR8G8B8(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + dB[0] = (*sB & 0xf800) >> 8; + dB[1] = (*sB & 0x07e0) >> 3; + dB[2] = (*sB & 0x001f) << 3; + + sB += 1; + dB += 3; + } +} + +void CColorConverter::convert_R5G6B5toB8G8R8(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u8 *dB = (u8 *)dP; + + for (s32 x = 0; x < sN; ++x) { + dB[2] = (*sB & 0xf800) >> 8; + dB[1] = (*sB & 0x07e0) >> 3; + dB[0] = (*sB & 0x001f) << 3; + + sB += 1; + dB += 3; + } +} + +void CColorConverter::convert_R5G6B5toA8R8G8B8(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u32 *dB = (u32 *)dP; + + for (s32 x = 0; x < sN; ++x) + *dB++ = R5G6B5toA8R8G8B8(*sB++); +} + +void CColorConverter::convert_R5G6B5toA1R5G5B5(const void *sP, s32 sN, void *dP) +{ + u16 *sB = (u16 *)sP; + u16 *dB = (u16 *)dP; + + for (s32 x = 0; x < sN; ++x) + *dB++ = R5G6B5toA1R5G5B5(*sB++); +} + +bool CColorConverter::canConvertFormat(ECOLOR_FORMAT sourceFormat, ECOLOR_FORMAT destFormat) +{ + switch (sourceFormat) { + case ECF_A1R5G5B5: + switch (destFormat) { + case ECF_A1R5G5B5: + case ECF_R5G6B5: + case ECF_A8R8G8B8: + case ECF_R8G8B8: + return true; + default: + break; + } + break; + case ECF_R5G6B5: + switch (destFormat) { + case ECF_A1R5G5B5: + case ECF_R5G6B5: + case ECF_A8R8G8B8: + case ECF_R8G8B8: + return true; + default: + break; + } + break; + case ECF_A8R8G8B8: + switch (destFormat) { + case ECF_A1R5G5B5: + case ECF_R5G6B5: + case ECF_A8R8G8B8: + case ECF_R8G8B8: + return true; + default: + break; + } + break; + case ECF_R8G8B8: + switch (destFormat) { + case ECF_A1R5G5B5: + case ECF_R5G6B5: + case ECF_A8R8G8B8: + case ECF_R8G8B8: + return true; + default: + break; + } + break; + default: + break; + } + return false; +} + +void CColorConverter::convert_viaFormat(const void *sP, ECOLOR_FORMAT sF, s32 sN, + void *dP, ECOLOR_FORMAT dF) +{ + // please also update can_convert_viaFormat when adding new conversions + switch (sF) { + case ECF_A1R5G5B5: + switch (dF) { + case ECF_A1R5G5B5: + convert_A1R5G5B5toA1R5G5B5(sP, sN, dP); + break; + case ECF_R5G6B5: + convert_A1R5G5B5toR5G6B5(sP, sN, dP); + break; + case ECF_A8R8G8B8: + convert_A1R5G5B5toA8R8G8B8(sP, sN, dP); + break; + case ECF_R8G8B8: + convert_A1R5G5B5toR8G8B8(sP, sN, dP); + break; + + default: + break; + } + break; + case ECF_R5G6B5: + switch (dF) { + case ECF_A1R5G5B5: + convert_R5G6B5toA1R5G5B5(sP, sN, dP); + break; + case ECF_R5G6B5: + convert_R5G6B5toR5G6B5(sP, sN, dP); + break; + case ECF_A8R8G8B8: + convert_R5G6B5toA8R8G8B8(sP, sN, dP); + break; + case ECF_R8G8B8: + convert_R5G6B5toR8G8B8(sP, sN, dP); + break; + + default: + break; + } + break; + case ECF_A8R8G8B8: + switch (dF) { + case ECF_A1R5G5B5: + convert_A8R8G8B8toA1R5G5B5(sP, sN, dP); + break; + case ECF_R5G6B5: + convert_A8R8G8B8toR5G6B5(sP, sN, dP); + break; + case ECF_A8R8G8B8: + convert_A8R8G8B8toA8R8G8B8(sP, sN, dP); + break; + case ECF_R8G8B8: + convert_A8R8G8B8toR8G8B8(sP, sN, dP); + break; + + default: + break; + } + break; + case ECF_R8G8B8: + switch (dF) { + case ECF_A1R5G5B5: + convert_R8G8B8toA1R5G5B5(sP, sN, dP); + break; + case ECF_R5G6B5: + convert_R8G8B8toR5G6B5(sP, sN, dP); + break; + case ECF_A8R8G8B8: + convert_R8G8B8toA8R8G8B8(sP, sN, dP); + break; + case ECF_R8G8B8: + convert_R8G8B8toR8G8B8(sP, sN, dP); + break; + + default: + break; + } + break; + + default: + break; + } +} + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CColorConverter.h b/irr/src/CColorConverter.h new file mode 100644 index 000000000..7f1628297 --- /dev/null +++ b/irr/src/CColorConverter.h @@ -0,0 +1,94 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" +#include "IImage.h" + +namespace irr +{ +namespace video +{ + +class CColorConverter +{ +public: + //! converts a monochrome bitmap to A1R5G5B5 + static void convert1BitTo16Bit(const u8 *in, s16 *out, s32 width, s32 height, s32 linepad = 0, bool flip = false); + + //! converts a 4 bit palettized image to A1R5G5B5 + static void convert4BitTo16Bit(const u8 *in, s16 *out, s32 width, s32 height, const s32 *palette, s32 linepad = 0, bool flip = false); + + //! converts a 8 bit palettized image to A1R5G5B5 + static void convert8BitTo16Bit(const u8 *in, s16 *out, s32 width, s32 height, const s32 *palette, s32 linepad = 0, bool flip = false); + + //! converts a 8 bit palettized or non palettized image (A8) into R8G8B8 + static void convert8BitTo24Bit(const u8 *in, u8 *out, s32 width, s32 height, const u8 *palette, s32 linepad = 0, bool flip = false); + + //! converts a 8 bit palettized or non palettized image (A8) into A8R8G8B8 + static void convert8BitTo32Bit(const u8 *in, u8 *out, s32 width, s32 height, const u8 *palette, s32 linepad = 0, bool flip = false); + + //! converts R8G8B8 16 bit data to A1R5G5B5 data + static void convert16BitTo16Bit(const s16 *in, s16 *out, s32 width, s32 height, s32 linepad = 0, bool flip = false); + + //! copies R8G8B8 24 bit data to 24 data, and flips and + //! mirrors the image during the process. + static void convert24BitTo24Bit(const u8 *in, u8 *out, s32 width, s32 height, s32 linepad = 0, bool flip = false, bool bgr = false); + + //! Resizes the surface to a new size and converts it at the same time + //! to an A8R8G8B8 format, returning the pointer to the new buffer. + static void convert16bitToA8R8G8B8andResize(const s16 *in, s32 *out, s32 newWidth, s32 newHeight, s32 currentWidth, s32 currentHeight); + + //! copies X8R8G8B8 32 bit data, and flips and + //! mirrors the image during the process. + static void convert32BitTo32Bit(const s32 *in, s32 *out, s32 width, s32 height, s32 linepad, bool flip = false); + + //! Functions for converting one image format to another efficiently + //! and hopefully correctly. + //! Note that the format descriptions refer to the ECOLOR_FORMAT's and not to memory layout. + //! Reasons for that go back to DX9 naming which tended to flip 32-bit and 16-bit byte orders so ARGB usually means BGRA. + //! + //! \param sP pointer to source pixel data + //! \param sN number of source pixels to copy + //! \param dP pointer to destination data buffer. must be big enough + //! to hold sN pixels in the output format. + static void convert_A1R5G5B5toR8G8B8(const void *sP, s32 sN, void *dP); + static void convert_A1R5G5B5toB8G8R8(const void *sP, s32 sN, void *dP); + static void convert_A1R5G5B5toA8R8G8B8(const void *sP, s32 sN, void *dP); + static void convert_A1R5G5B5toA1R5G5B5(const void *sP, s32 sN, void *dP); + static void convert_A1R5G5B5toR5G5B5A1(const void *sP, s32 sN, void *dP); + static void convert_A1R5G5B5toR5G6B5(const void *sP, s32 sN, void *dP); + + static void convert_A8R8G8B8toR8G8B8(const void *sP, s32 sN, void *dP); + static void convert_A8R8G8B8toB8G8R8(const void *sP, s32 sN, void *dP); + static void convert_A8R8G8B8toA8R8G8B8(const void *sP, s32 sN, void *dP); + static void convert_A8R8G8B8toA1R5G5B5(const void *sP, s32 sN, void *dP); + static void convert_A8R8G8B8toA1B5G5R5(const void *sP, s32 sN, void *dP); + static void convert_A8R8G8B8toR5G6B5(const void *sP, s32 sN, void *dP); + + static void convert_A8R8G8B8toR3G3B2(const void *sP, s32 sN, void *dP); + static void convert_R8G8B8toR8G8B8(const void *sP, s32 sN, void *dP); + static void convert_R8G8B8toA8R8G8B8(const void *sP, s32 sN, void *dP); + static void convert_R8G8B8toA1R5G5B5(const void *sP, s32 sN, void *dP); + static void convert_R8G8B8toB8G8R8(const void *sP, s32 sN, void *dP); + static void convert_R8G8B8toR5G6B5(const void *sP, s32 sN, void *dP); + static void convert_B8G8R8toA8R8G8B8(const void *sP, s32 sN, void *dP); + static void convert_B8G8R8A8toA8R8G8B8(const void *sP, s32 sN, void *dP); + static void convert_A8R8G8B8toR8G8B8A8(const void *sP, s32 sN, void *dP); + static void convert_A8R8G8B8toA8B8G8R8(const void *sP, s32 sN, void *dP); + + static void convert_R5G6B5toR5G6B5(const void *sP, s32 sN, void *dP); + static void convert_R5G6B5toR8G8B8(const void *sP, s32 sN, void *dP); + static void convert_R5G6B5toB8G8R8(const void *sP, s32 sN, void *dP); + static void convert_R5G6B5toA8R8G8B8(const void *sP, s32 sN, void *dP); + static void convert_R5G6B5toA1R5G5B5(const void *sP, s32 sN, void *dP); + static void convert_viaFormat(const void *sP, ECOLOR_FORMAT sF, s32 sN, + void *dP, ECOLOR_FORMAT dF); + // Check if convert_viaFormat is usable + static bool canConvertFormat(ECOLOR_FORMAT sourceFormat, ECOLOR_FORMAT destFormat); +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CDummyTransformationSceneNode.cpp b/irr/src/CDummyTransformationSceneNode.cpp new file mode 100644 index 000000000..73953dd38 --- /dev/null +++ b/irr/src/CDummyTransformationSceneNode.cpp @@ -0,0 +1,102 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CDummyTransformationSceneNode.h" +#include "os.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CDummyTransformationSceneNode::CDummyTransformationSceneNode( + ISceneNode *parent, ISceneManager *mgr, s32 id) : + IDummyTransformationSceneNode(parent, mgr, id) +{ +#ifdef _DEBUG + setDebugName("CDummyTransformationSceneNode"); +#endif + + setAutomaticCulling(scene::EAC_OFF); +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CDummyTransformationSceneNode::getBoundingBox() const +{ + return Box; +} + +//! Returns a reference to the current relative transformation matrix. +//! This is the matrix, this scene node uses instead of scale, translation +//! and rotation. +core::matrix4 &CDummyTransformationSceneNode::getRelativeTransformationMatrix() +{ + return RelativeTransformationMatrix; +} + +//! Returns the relative transformation of the scene node. +core::matrix4 CDummyTransformationSceneNode::getRelativeTransformation() const +{ + return RelativeTransformationMatrix; +} + +//! Creates a clone of this scene node and its children. +ISceneNode *CDummyTransformationSceneNode::clone(ISceneNode *newParent, ISceneManager *newManager) +{ + if (!newParent) + newParent = Parent; + if (!newManager) + newManager = SceneManager; + + CDummyTransformationSceneNode *nb = new CDummyTransformationSceneNode(newParent, + newManager, ID); + + nb->cloneMembers(this, newManager); + nb->RelativeTransformationMatrix = RelativeTransformationMatrix; + nb->Box = Box; + + if (newParent) + nb->drop(); + return nb; +} + +const core::vector3df &CDummyTransformationSceneNode::getScale() const +{ + os::Printer::log("CDummyTransformationSceneNode::getScale() does not contain the relative transformation.", ELL_DEBUG); + return RelativeScale; +} + +void CDummyTransformationSceneNode::setScale(const core::vector3df &scale) +{ + os::Printer::log("CDummyTransformationSceneNode::setScale() does not affect the relative transformation.", ELL_DEBUG); + RelativeScale = scale; +} + +const core::vector3df &CDummyTransformationSceneNode::getRotation() const +{ + os::Printer::log("CDummyTransformationSceneNode::getRotation() does not contain the relative transformation.", ELL_DEBUG); + return RelativeRotation; +} + +void CDummyTransformationSceneNode::setRotation(const core::vector3df &rotation) +{ + os::Printer::log("CDummyTransformationSceneNode::setRotation() does not affect the relative transformation.", ELL_DEBUG); + RelativeRotation = rotation; +} + +const core::vector3df &CDummyTransformationSceneNode::getPosition() const +{ + os::Printer::log("CDummyTransformationSceneNode::getPosition() does not contain the relative transformation.", ELL_DEBUG); + return RelativeTranslation; +} + +void CDummyTransformationSceneNode::setPosition(const core::vector3df &newpos) +{ + os::Printer::log("CDummyTransformationSceneNode::setPosition() does not affect the relative transformation.", ELL_DEBUG); + RelativeTranslation = newpos; +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CDummyTransformationSceneNode.h b/irr/src/CDummyTransformationSceneNode.h new file mode 100644 index 000000000..86fda3639 --- /dev/null +++ b/irr/src/CDummyTransformationSceneNode.h @@ -0,0 +1,55 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IDummyTransformationSceneNode.h" + +namespace irr +{ +namespace scene +{ + +class CDummyTransformationSceneNode : public IDummyTransformationSceneNode +{ +public: + //! constructor + CDummyTransformationSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id); + + //! returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + //! Returns a reference to the current relative transformation matrix. + //! This is the matrix, this scene node uses instead of scale, translation + //! and rotation. + core::matrix4 &getRelativeTransformationMatrix() override; + + //! Returns the relative transformation of the scene node. + core::matrix4 getRelativeTransformation() const override; + + //! does nothing. + void render() override {} + + //! Returns type of the scene node + ESCENE_NODE_TYPE getType() const override { return ESNT_DUMMY_TRANSFORMATION; } + + //! Creates a clone of this scene node and its children. + ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override; + +private: + // TODO: We can add least add some warnings to find troubles faster until we have + // fixed bug id 2318691. + const core::vector3df &getScale() const override; + void setScale(const core::vector3df &scale) override; + const core::vector3df &getRotation() const override; + void setRotation(const core::vector3df &rotation) override; + const core::vector3df &getPosition() const override; + void setPosition(const core::vector3df &newpos) override; + + core::matrix4 RelativeTransformationMatrix; + core::aabbox3d Box; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CEGLManager.cpp b/irr/src/CEGLManager.cpp new file mode 100644 index 000000000..971b39359 --- /dev/null +++ b/irr/src/CEGLManager.cpp @@ -0,0 +1,611 @@ +// Copyright (C) 2013 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "CEGLManager.h" + +#ifdef _IRR_COMPILE_WITH_EGL_MANAGER_ + +#include "irrString.h" +#include "irrArray.h" +#include "os.h" + +#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) +#include +#endif + +namespace irr +{ +namespace video +{ + +CEGLManager::CEGLManager() : + IContextManager(), EglWindow(0), EglDisplay(EGL_NO_DISPLAY), + EglSurface(EGL_NO_SURFACE), EglContext(EGL_NO_CONTEXT), EglConfig(0), MajorVersion(0), MinorVersion(0) +{ +#ifdef _DEBUG + setDebugName("CEGLManager"); +#endif +} + +CEGLManager::~CEGLManager() +{ + destroyContext(); + destroySurface(); + terminate(); +} + +bool CEGLManager::initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &data) +{ + // store new data + Params = params; + Data = data; + + if (EglWindow != 0 && EglDisplay != EGL_NO_DISPLAY) + return true; + + // Window is depend on platform. +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + EglWindow = (NativeWindowType)Data.OpenGLWin32.HWnd; + Data.OpenGLWin32.HDc = GetDC((HWND)EglWindow); + EglDisplay = eglGetDisplay((NativeDisplayType)Data.OpenGLWin32.HDc); +#elif defined(_IRR_EMSCRIPTEN_PLATFORM_) + EglWindow = 0; + EglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) + EglWindow = (NativeWindowType)Data.OpenGLLinux.X11Window; + EglDisplay = eglGetDisplay((NativeDisplayType)Data.OpenGLLinux.X11Display); +#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + EglWindow = (ANativeWindow *)Data.OGLESAndroid.Window; + EglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); +#elif defined(_IRR_COMPILE_WITH_FB_DEVICE_) + EglWindow = (NativeWindowType)Data.OpenGLFB.Window; + EglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); +#endif + + // We must check if EGL display is valid. + if (EglDisplay == EGL_NO_DISPLAY) { + os::Printer::log("Could not get EGL display."); + terminate(); + return false; + } + + // Initialize EGL here. + if (!eglInitialize(EglDisplay, &MajorVersion, &MinorVersion)) { + os::Printer::log("Could not initialize EGL display."); + + EglDisplay = EGL_NO_DISPLAY; + terminate(); + return false; + } else + os::Printer::log("EGL version", core::stringc(MajorVersion + (MinorVersion * 0.1f)).c_str()); + + return true; +} + +void CEGLManager::terminate() +{ + if (EglWindow == 0 && EglDisplay == EGL_NO_DISPLAY) + return; + + if (EglDisplay != EGL_NO_DISPLAY) { + // We should unbind current EGL context before terminate EGL. + eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + eglTerminate(EglDisplay); + EglDisplay = EGL_NO_DISPLAY; + } + +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + if (Data.OpenGLWin32.HDc) { + ReleaseDC((HWND)EglWindow, (HDC)Data.OpenGLWin32.HDc); + Data.OpenGLWin32.HDc = 0; + } +#endif + + MajorVersion = 0; + MinorVersion = 0; +} + +bool CEGLManager::generateSurface() +{ + if (EglDisplay == EGL_NO_DISPLAY) + return false; + + if (EglSurface != EGL_NO_SURFACE) + return true; + + // We should assign new WindowID on platforms, where WindowID may change at runtime, + // at this time only Android support this feature. + // this needs an update method instead! + +#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + EglWindow = (ANativeWindow *)Data.OGLESAndroid.Window; +#endif + +#if defined(_IRR_EMSCRIPTEN_PLATFORM_) + // eglChooseConfig is currently only implemented as stub in emscripten (version 1.37.22 at point of writing) + // But the other solution would also be fine as it also only generates a single context so there is not much to choose from. + EglConfig = chooseConfig(ECS_IRR_CHOOSE); +#else + EglConfig = chooseConfig(ECS_EGL_CHOOSE_FIRST_LOWER_EXPECTATIONS); +#endif + + if (EglConfig == 0) { + os::Printer::log("Could not get config for EGL display."); + return false; + } + +#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + EGLint Format = 0; + eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &Format); + + ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, Format); +#endif + + // Now we are able to create EGL surface. + EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, 0); + + if (EGL_NO_SURFACE == EglSurface) + EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, 0); + + if (EGL_NO_SURFACE == EglSurface) + os::Printer::log("Could not create EGL surface."); + +#ifdef EGL_VERSION_1_2 + if (MinorVersion > 1) + eglBindAPI(EGL_OPENGL_ES_API); +#endif + + if (Params.Vsync) + eglSwapInterval(EglDisplay, 1); + + return true; +} + +EGLConfig CEGLManager::chooseConfig(EConfigStyle confStyle) +{ + EGLConfig configResult = 0; + + // Find proper OpenGL BIT. + EGLint eglOpenGLBIT = 0; + switch (Params.DriverType) { + case EDT_OGLES1: + eglOpenGLBIT = EGL_OPENGL_ES_BIT; + break; + case EDT_OGLES2: + case EDT_WEBGL1: + eglOpenGLBIT = EGL_OPENGL_ES2_BIT; + break; + default: + break; + } + + if (confStyle == ECS_EGL_CHOOSE_FIRST_LOWER_EXPECTATIONS) { + EGLint Attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, Params.WithAlphaChannel ? 1 : 0, + EGL_BUFFER_SIZE, Params.Bits, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_DEPTH_SIZE, Params.ZBufferBits, + EGL_STENCIL_SIZE, Params.Stencilbuffer, + EGL_SAMPLE_BUFFERS, Params.AntiAlias ? 1 : 0, + EGL_SAMPLES, Params.AntiAlias, +#ifdef EGL_VERSION_1_3 + EGL_RENDERABLE_TYPE, eglOpenGLBIT, +#endif + EGL_NONE, 0, + }; + + EGLint numConfigs = 0; + u32 steps = 5; + + // Choose the best EGL config. + // TODO: We should also have a confStyle ECS_EGL_CHOOSE_CLOSEST + // which doesn't take first result of eglChooseConfigs, + // but the closest to requested parameters. eglChooseConfigs + // can return more than 1 result and first one might have + // "better" values than requested (more bits per pixel etc). + // So this returns the config which can do most, not the + // config which is closest to the requested parameters. + // + while (!eglChooseConfig(EglDisplay, Attribs, &configResult, 1, &numConfigs) || !numConfigs) { + switch (steps) { + case 5: // samples + if (Attribs[19] > 2) // Params.AntiAlias + --Attribs[19]; + else { + Attribs[17] = 0; // Params.Stencilbuffer + Attribs[19] = 0; // Params.AntiAlias + --steps; + } + break; + case 4: // alpha + if (Attribs[7]) { // Params.WithAlphaChannel + Attribs[7] = 0; + + if (Params.AntiAlias) { + Attribs[17] = 1; + Attribs[19] = Params.AntiAlias; + steps = 5; + } + } else + --steps; + break; + case 3: // stencil + if (Attribs[15]) { // Params.Stencilbuffer + Attribs[15] = 0; + + if (Params.AntiAlias) { + Attribs[17] = 1; + Attribs[19] = Params.AntiAlias; + steps = 5; + } + } else + --steps; + break; + case 2: // depth size + if (Attribs[13] > 16) { // Params.ZBufferBits + Attribs[13] -= 8; + } else + --steps; + break; + case 1: // buffer size + if (Attribs[9] > 16) { // Params.Bits + Attribs[9] -= 8; + } else + --steps; + break; + default: + return 0; + } + } + + if (Params.AntiAlias && !Attribs[17]) + os::Printer::log("No multisampling."); + + if (Params.WithAlphaChannel && !Attribs[7]) + os::Printer::log("No alpha."); + + if (Params.Stencilbuffer && !Attribs[15]) + os::Printer::log("No stencil buffer."); + + if (Params.ZBufferBits > Attribs[13]) + os::Printer::log("No full depth buffer."); + + if (Params.Bits > Attribs[9]) + os::Printer::log("No full color buffer."); + } else if (confStyle == ECS_IRR_CHOOSE) { + // find number of available configs + EGLint numConfigs; + if (eglGetConfigs(EglDisplay, NULL, 0, &numConfigs) == EGL_FALSE) { + testEGLError(); + return 0; + } + + if (numConfigs <= 0) + return 0; + + // Get all available configs. + EGLConfig *configs = new EGLConfig[numConfigs]; + if (eglGetConfigs(EglDisplay, configs, numConfigs, &numConfigs) == EGL_FALSE) { + testEGLError(); + return 0; + } + + // Find the best one. + core::array ratings((u32)numConfigs); + for (u32 i = 0; i < (u32)numConfigs; ++i) { + SConfigRating r; + r.config = configs[i]; + r.rating = rateConfig(r.config, eglOpenGLBIT); + + if (r.rating >= 0) + ratings.push_back(r); + } + + if (ratings.size() > 0) { + ratings.sort(); + configResult = ratings[0].config; + + if (ratings[0].rating != 0) { + // This is just to print some log info (it also rates again while doing that, but rating is cheap enough, so that doesn't matter here). + rateConfig(ratings[0].config, eglOpenGLBIT, true); + } + } + + delete[] configs; + } + + return configResult; +} + +irr::s32 CEGLManager::rateConfig(EGLConfig config, EGLint eglOpenGLBIT, bool log) +{ + // some values must be there or we ignore the config +#ifdef EGL_VERSION_1_3 + EGLint attribRenderableType = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_RENDERABLE_TYPE, &attribRenderableType); + if (attribRenderableType != eglOpenGLBIT) { + if (log) + os::Printer::log("EGL_RENDERABLE_TYPE != eglOpenGLBIT"); + return -1; + } +#endif + EGLint attribSurfaceType = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_SURFACE_TYPE, &attribSurfaceType); + if (attribSurfaceType != EGL_WINDOW_BIT) { + if (log) + os::Printer::log("EGL_SURFACE_TYPE!= EGL_WINDOW_BIT"); + return -1; + } + + // Generally we give a really bad rating if attributes are worse than requested + // We give a slight worse rating if attributes are not exact as requested + // And we use some priorities which might make sense (but not really fine-tuned, + // so if you think other priorities would be better don't worry about changing the values. + int rating = 0; + + EGLint attribBufferSize = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_BUFFER_SIZE, &attribBufferSize); + if (attribBufferSize < Params.Bits) { + if (log) + os::Printer::log("No full color buffer."); + rating += 100; + } + if (attribBufferSize > Params.Bits) { + if (log) + os::Printer::log("Larger color buffer.", ELL_DEBUG); + ++rating; + } + + EGLint attribRedSize = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_RED_SIZE, &attribRedSize); + if (attribRedSize < 5 && Params.Bits >= 4) + rating += 100; + else if (attribRedSize < 8 && Params.Bits >= 24) + rating += 10; + else if (attribRedSize >= 8 && Params.Bits < 24) + rating++; + EGLint attribGreenSize = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_GREEN_SIZE, &attribGreenSize); + if (attribGreenSize < 5 && Params.Bits >= 4) + rating += 100; + else if (attribGreenSize < 8 && Params.Bits >= 24) + rating += 10; + else if (attribGreenSize >= 8 && Params.Bits < 24) + rating++; + EGLint attribBlueSize = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_BLUE_SIZE, &attribBlueSize); + if (attribBlueSize < 5 && Params.Bits >= 4) + rating += 100; + else if (attribBlueSize < 8 && Params.Bits >= 24) + rating += 10; + else if (attribBlueSize >= 8 && Params.Bits < 24) + rating++; + + EGLint attribAlphaSize = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_ALPHA_SIZE, &attribAlphaSize); + if (Params.WithAlphaChannel && attribAlphaSize == 0) { + if (log) + os::Printer::log("No alpha."); + rating += 10; + } else if (!Params.WithAlphaChannel && attribAlphaSize > 0) { + if (log) + os::Printer::log("Got alpha (unrequested).", ELL_DEBUG); + rating++; + } + + EGLint attribStencilSize = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_STENCIL_SIZE, &attribStencilSize); + if (Params.Stencilbuffer && attribStencilSize == 0) { + if (log) + os::Printer::log("No stencil buffer."); + rating += 10; + } else if (!Params.Stencilbuffer && attribStencilSize > 0) { + if (log) + os::Printer::log("Got a stencil buffer (unrequested).", ELL_DEBUG); + rating++; + } + + EGLint attribDepthSize = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_DEPTH_SIZE, &attribDepthSize); + if (attribDepthSize < Params.ZBufferBits) { + if (log) { + if (attribDepthSize > 0) + os::Printer::log("No full depth buffer."); + else + os::Printer::log("No depth buffer."); + } + rating += 50; + } else if (attribDepthSize != Params.ZBufferBits) { + if (log) { + if (Params.ZBufferBits == 0) + os::Printer::log("Got a depth buffer (unrequested).", ELL_DEBUG); + else + os::Printer::log("Got a larger depth buffer.", ELL_DEBUG); + } + rating++; + } + + EGLint attribSampleBuffers = 0, attribSamples = 0; + eglGetConfigAttrib(EglDisplay, config, EGL_SAMPLE_BUFFERS, &attribSampleBuffers); + eglGetConfigAttrib(EglDisplay, config, EGL_SAMPLES, &attribSamples); + if (Params.AntiAlias && attribSampleBuffers == 0) { + if (log) + os::Printer::log("No multisampling."); + rating += 20; + } else if (Params.AntiAlias && attribSampleBuffers && attribSamples < Params.AntiAlias) { + if (log) + os::Printer::log("Multisampling with less samples than requested.", ELL_DEBUG); + rating += 10; + } else if (Params.AntiAlias && attribSampleBuffers && attribSamples > Params.AntiAlias) { + if (log) + os::Printer::log("Multisampling with more samples than requested.", ELL_DEBUG); + rating += 5; + } else if (!Params.AntiAlias && attribSampleBuffers > 0) { + if (log) + os::Printer::log("Got multisampling (unrequested).", ELL_DEBUG); + rating += 3; + } + + return rating; +} + +void CEGLManager::destroySurface() +{ + if (EglSurface == EGL_NO_SURFACE) + return; + + // We should unbind current EGL context before destroy EGL surface. + eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + eglDestroySurface(EglDisplay, EglSurface); + EglSurface = EGL_NO_SURFACE; +} + +bool CEGLManager::generateContext() +{ + if (EglDisplay == EGL_NO_DISPLAY || EglSurface == EGL_NO_SURFACE) + return false; + + if (EglContext != EGL_NO_CONTEXT) + return true; + + EGLint OpenGLESVersion = 0; + + switch (Params.DriverType) { + case EDT_OGLES1: + OpenGLESVersion = 1; + break; + case EDT_OGLES2: + case EDT_WEBGL1: + OpenGLESVersion = 2; + break; + default: + break; + } + + EGLint ContextAttrib[] = { +#ifdef EGL_VERSION_1_3 + EGL_CONTEXT_CLIENT_VERSION, OpenGLESVersion, +#endif + EGL_NONE, 0, + }; + + EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, ContextAttrib); + + if (testEGLError()) { + os::Printer::log("Could not create EGL context.", ELL_ERROR); + return false; + } + + os::Printer::log("EGL context created with OpenGLESVersion: ", core::stringc((int)OpenGLESVersion), ELL_DEBUG); + + return true; +} + +void CEGLManager::destroyContext() +{ + if (EglContext == EGL_NO_CONTEXT) + return; + + // We must unbind current EGL context before destroy it. + eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(EglDisplay, EglContext); + + EglContext = EGL_NO_CONTEXT; +} + +bool CEGLManager::activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) +{ + eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); + + if (testEGLError()) { + os::Printer::log("Could not make EGL context current."); + return false; + } + return true; +} + +const SExposedVideoData &CEGLManager::getContext() const +{ + return Data; +} + +void *CEGLManager::getProcAddress(const std::string &procName) +{ + return (void *)eglGetProcAddress(procName.c_str()); +} + +bool CEGLManager::swapBuffers() +{ + return (eglSwapBuffers(EglDisplay, EglSurface) == EGL_TRUE); +} + +bool CEGLManager::testEGLError() +{ +#if defined(EGL_VERSION_1_0) && defined(_DEBUG) + EGLint status = eglGetError(); + + switch (status) { + case EGL_SUCCESS: + return false; + case EGL_NOT_INITIALIZED: + os::Printer::log("Not Initialized", ELL_ERROR); + break; + case EGL_BAD_ACCESS: + os::Printer::log("Bad Access", ELL_ERROR); + break; + case EGL_BAD_ALLOC: + os::Printer::log("Bad Alloc", ELL_ERROR); + break; + case EGL_BAD_ATTRIBUTE: + os::Printer::log("Bad Attribute", ELL_ERROR); + break; + case EGL_BAD_CONTEXT: + os::Printer::log("Bad Context", ELL_ERROR); + break; + case EGL_BAD_CONFIG: + os::Printer::log("Bad Config", ELL_ERROR); + break; + case EGL_BAD_CURRENT_SURFACE: + os::Printer::log("Bad Current Surface", ELL_ERROR); + break; + case EGL_BAD_DISPLAY: + os::Printer::log("Bad Display", ELL_ERROR); + break; + case EGL_BAD_SURFACE: + os::Printer::log("Bad Surface", ELL_ERROR); + break; + case EGL_BAD_MATCH: + os::Printer::log("Bad Match", ELL_ERROR); + break; + case EGL_BAD_PARAMETER: + os::Printer::log("Bad Parameter", ELL_ERROR); + break; + case EGL_BAD_NATIVE_PIXMAP: + os::Printer::log("Bad Native Pixmap", ELL_ERROR); + break; + case EGL_BAD_NATIVE_WINDOW: + os::Printer::log("Bad Native Window", ELL_ERROR); + break; + case EGL_CONTEXT_LOST: + os::Printer::log("Context Lost", ELL_ERROR); + break; + default: + break; + }; + + return true; +#else + return false; +#endif +} + +} +} + +#endif diff --git a/irr/src/CEGLManager.h b/irr/src/CEGLManager.h new file mode 100644 index 000000000..49371e469 --- /dev/null +++ b/irr/src/CEGLManager.h @@ -0,0 +1,114 @@ +// Copyright (C) 2013 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_EGL_MANAGER_ + +#include + +#include "SIrrCreationParameters.h" +#include "SExposedVideoData.h" +#include "IContextManager.h" + +namespace irr +{ +namespace video +{ +// EGL manager. +class CEGLManager : public IContextManager +{ +public: + //! Constructor. + CEGLManager(); + + //! Destructor. + virtual ~CEGLManager(); + + // Initialize EGL. + /* This method initialize EGLand create EGL display, anyway surface and context + aren't create. */ + bool initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &data) override; + + // Terminate EGL. + /* Terminate EGL context. This method break both existed surface and context. */ + void terminate() override; + + // Create EGL surface. + /* This method create EGL surface. On some platforms eg. Android, we must + recreate surface on each resume, because WindowID may change, so existed + surface may not be valid. If EGL context already exist, this method + automatically activates it. */ + bool generateSurface() override; + + // Destroy EGL surface. + /* This method destroy EGL. On some platforms eg. Android, we should call + this method on each pause, because after resume this surface may not be valid. + Hovewer this method doesn'r break EGL context. */ + void destroySurface() override; + + // Create EGL context. + /* This method create and activate EGL context. */ + bool generateContext() override; + + // Destroy EGL context. + /* This method destroy EGL context. */ + void destroyContext() override; + + const SExposedVideoData &getContext() const override; + + bool activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) override; + + // Get procedure address. + void *getProcAddress(const std::string &procName) override; + + // Swap buffers. + bool swapBuffers() override; + +protected: + enum EConfigStyle + { + //! Get first result of eglChooseConfigs and if that fails try again by requesting simpler attributes + ECS_EGL_CHOOSE_FIRST_LOWER_EXPECTATIONS, + + //! We select our own best fit and avoid using eglChooseConfigs + ECS_IRR_CHOOSE, + }; + + EGLConfig chooseConfig(EConfigStyle confStyle); + + //! Check how close this config is to the parameters we requested + //! returns 0 is perfect, larger values are worse and < 0 is unusable. + irr::s32 rateConfig(EGLConfig config, EGLint eglOpenGLBIT, bool log = false); + + // Helper to sort EGLConfig's. (because we got no std::pair....) + struct SConfigRating + { + EGLConfig config; + irr::s32 rating; + bool operator<(const SConfigRating &other) const + { + return rating < other.rating; + } + }; + +private: + bool testEGLError(); + + NativeWindowType EglWindow; + EGLDisplay EglDisplay; + EGLSurface EglSurface; + EGLContext EglContext; + + EGLConfig EglConfig; + + SIrrlichtCreationParameters Params; + SExposedVideoData Data; + + EGLint MajorVersion; + EGLint MinorVersion; +}; +} +} +#endif diff --git a/irr/src/CEmptySceneNode.cpp b/irr/src/CEmptySceneNode.cpp new file mode 100644 index 000000000..2b965a198 --- /dev/null +++ b/irr/src/CEmptySceneNode.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CEmptySceneNode.h" +#include "ISceneManager.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CEmptySceneNode::CEmptySceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id) : + ISceneNode(parent, mgr, id) +{ +#ifdef _DEBUG + setDebugName("CEmptySceneNode"); +#endif + + setAutomaticCulling(scene::EAC_OFF); +} + +//! pre render event +void CEmptySceneNode::OnRegisterSceneNode() +{ + if (IsVisible) + SceneManager->registerNodeForRendering(this); + + ISceneNode::OnRegisterSceneNode(); +} + +//! render +void CEmptySceneNode::render() +{ + // do nothing +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CEmptySceneNode::getBoundingBox() const +{ + return Box; +} + +//! Creates a clone of this scene node and its children. +ISceneNode *CEmptySceneNode::clone(ISceneNode *newParent, ISceneManager *newManager) +{ + if (!newParent) + newParent = Parent; + if (!newManager) + newManager = SceneManager; + + CEmptySceneNode *nb = new CEmptySceneNode(newParent, + newManager, ID); + + nb->cloneMembers(this, newManager); + nb->Box = Box; + + if (newParent) + nb->drop(); + return nb; +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CEmptySceneNode.h b/irr/src/CEmptySceneNode.h new file mode 100644 index 000000000..c89ad59ae --- /dev/null +++ b/irr/src/CEmptySceneNode.h @@ -0,0 +1,40 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "ISceneNode.h" + +namespace irr +{ +namespace scene +{ + +class CEmptySceneNode : public ISceneNode +{ +public: + //! constructor + CEmptySceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id); + + //! returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + //! This method is called just before the rendering process of the whole scene. + void OnRegisterSceneNode() override; + + //! does nothing. + void render() override; + + //! Returns type of the scene node + ESCENE_NODE_TYPE getType() const override { return ESNT_EMPTY; } + + //! Creates a clone of this scene node and its children. + ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override; + +private: + core::aabbox3d Box; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CFPSCounter.cpp b/irr/src/CFPSCounter.cpp new file mode 100644 index 000000000..6717df5c9 --- /dev/null +++ b/irr/src/CFPSCounter.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CFPSCounter.h" +#include "irrMath.h" + +namespace irr +{ +namespace video +{ + +CFPSCounter::CFPSCounter() : + FPS(60), Primitive(0), StartTime(0), FramesCounted(0), + PrimitivesCounted(0), PrimitiveAverage(0), PrimitiveTotal(0) +{ +} + +//! returns current fps +s32 CFPSCounter::getFPS() const +{ + return FPS; +} + +//! returns current primitive count +u32 CFPSCounter::getPrimitive() const +{ + return Primitive; +} + +//! returns average primitive count of last period +u32 CFPSCounter::getPrimitiveAverage() const +{ + return PrimitiveAverage; +} + +//! returns accumulated primitive count since start +u32 CFPSCounter::getPrimitiveTotal() const +{ + return PrimitiveTotal; +} + +//! to be called every frame +void CFPSCounter::registerFrame(u32 now, u32 primitivesDrawn) +{ + ++FramesCounted; + PrimitiveTotal += primitivesDrawn; + PrimitivesCounted += primitivesDrawn; + Primitive = primitivesDrawn; + + const u32 milliseconds = now - StartTime; + + if (milliseconds >= 1500) { + const f32 invMilli = core::reciprocal((f32)milliseconds); + + FPS = core::ceil32((1000 * FramesCounted) * invMilli); + PrimitiveAverage = core::ceil32((1000 * PrimitivesCounted) * invMilli); + + FramesCounted = 0; + PrimitivesCounted = 0; + StartTime = now; + } +} + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CFPSCounter.h b/irr/src/CFPSCounter.h new file mode 100644 index 000000000..e73afb049 --- /dev/null +++ b/irr/src/CFPSCounter.h @@ -0,0 +1,46 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" + +namespace irr +{ +namespace video +{ + +class CFPSCounter +{ +public: + CFPSCounter(); + + //! returns current fps + s32 getFPS() const; + + //! returns primitive count + u32 getPrimitive() const; + + //! returns average primitive count of last period + u32 getPrimitiveAverage() const; + + //! returns accumulated primitive count since start + u32 getPrimitiveTotal() const; + + //! to be called every frame + void registerFrame(u32 now, u32 primitive); + +private: + s32 FPS; + u32 Primitive; + u32 StartTime; + + u32 FramesCounted; + u32 PrimitivesCounted; + u32 PrimitiveAverage; + u32 PrimitiveTotal; +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CFileList.cpp b/irr/src/CFileList.cpp new file mode 100644 index 000000000..dde8e75ac --- /dev/null +++ b/irr/src/CFileList.cpp @@ -0,0 +1,155 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CFileList.h" +#include "irrArray.h" +#include "coreutil.h" + +#include "os.h" + +namespace irr +{ +namespace io +{ + +static const io::path emptyFileListEntry; + +CFileList::CFileList(const io::path &path, bool ignoreCase, bool ignorePaths) : + IgnorePaths(ignorePaths), IgnoreCase(ignoreCase), Path(path) +{ +#ifdef _DEBUG + setDebugName("CFileList"); +#endif + + Path.replace('\\', '/'); +} + +CFileList::~CFileList() +{ + Files.clear(); +} + +u32 CFileList::getFileCount() const +{ + return Files.size(); +} + +void CFileList::sort() +{ + Files.sort(); +} + +const io::path &CFileList::getFileName(u32 index) const +{ + if (index >= Files.size()) + return emptyFileListEntry; + + return Files[index].Name; +} + +//! Gets the full name of a file in the list, path included, based on an index. +const io::path &CFileList::getFullFileName(u32 index) const +{ + if (index >= Files.size()) + return emptyFileListEntry; + + return Files[index].FullName; +} + +//! adds a file or folder +u32 CFileList::addItem(const io::path &fullPath, u32 offset, u32 size, bool isDirectory, u32 id) +{ + SFileListEntry entry; + entry.ID = id ? id : Files.size(); + entry.Offset = offset; + entry.Size = size; + entry.Name = fullPath; + entry.Name.replace('\\', '/'); + entry.IsDirectory = isDirectory; + + // remove trailing slash + if (entry.Name.lastChar() == '/') { + entry.IsDirectory = true; + entry.Name[entry.Name.size() - 1] = 0; + entry.Name.validate(); + } + + if (IgnoreCase) + entry.Name.make_lower(); + + entry.FullName = entry.Name; + + core::deletePathFromFilename(entry.Name); + + if (IgnorePaths) + entry.FullName = entry.Name; + + // os::Printer::log(Path.c_str(), entry.FullName); + + Files.push_back(entry); + + return Files.size() - 1; +} + +//! Returns the ID of a file in the file list, based on an index. +u32 CFileList::getID(u32 index) const +{ + return index < Files.size() ? Files[index].ID : 0; +} + +bool CFileList::isDirectory(u32 index) const +{ + bool ret = false; + if (index < Files.size()) + ret = Files[index].IsDirectory; + + return ret; +} + +//! Returns the size of a file +u32 CFileList::getFileSize(u32 index) const +{ + return index < Files.size() ? Files[index].Size : 0; +} + +u32 CFileList::getFileOffset(u32 index) const +{ + return index < Files.size() ? Files[index].Offset : 0; +} + +//! Searches for a file or folder within the list, returns the index +s32 CFileList::findFile(const io::path &filename, bool isDirectory = false) const +{ + SFileListEntry entry; + // we only need FullName to be set for the search + entry.FullName = filename; + entry.IsDirectory = isDirectory; + + // exchange + entry.FullName.replace('\\', '/'); + + // remove trailing slash + if (entry.FullName.lastChar() == '/') { + entry.IsDirectory = true; + entry.FullName[entry.FullName.size() - 1] = 0; + entry.FullName.validate(); + } + + if (IgnoreCase) + entry.FullName.make_lower(); + + if (IgnorePaths) + core::deletePathFromFilename(entry.FullName); + + return Files.binary_search(entry); +} + +//! Returns the base path of the file list +const io::path &CFileList::getPath() const +{ + return Path; +} + +} // end namespace irr +} // end namespace io diff --git a/irr/src/CFileList.h b/irr/src/CFileList.h new file mode 100644 index 000000000..1af975b22 --- /dev/null +++ b/irr/src/CFileList.h @@ -0,0 +1,128 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IFileList.h" +#include "irrString.h" +#include "irrArray.h" + +namespace irr +{ +namespace io +{ + +//! An entry in a list of files, can be a folder or a file. +struct SFileListEntry +{ + //! The name of the file + /** If this is a file or folder in the virtual filesystem and the archive + was created with the ignoreCase flag then the file name will be lower case. */ + io::path Name; + + //! The name of the file including the path + /** If this is a file or folder in the virtual filesystem and the archive was + created with the ignoreDirs flag then it will be the same as Name. */ + io::path FullName; + + //! The size of the file in bytes + u32 Size; + + //! The ID of the file in an archive + /** This is used to link the FileList entry to extra info held about this + file in an archive, which can hold things like data offset and CRC. */ + u32 ID; + + //! FileOffset inside an archive + u32 Offset; + + //! True if this is a folder, false if not. + bool IsDirectory; + + //! The == operator is provided so that CFileList can slowly search the list! + bool operator==(const struct SFileListEntry &other) const + { + if (IsDirectory != other.IsDirectory) + return false; + + return FullName.equals_ignore_case(other.FullName); + } + + //! The < operator is provided so that CFileList can sort and quickly search the list. + bool operator<(const struct SFileListEntry &other) const + { + if (IsDirectory != other.IsDirectory) + return IsDirectory; + + return FullName.lower_ignore_case(other.FullName); + } +}; + +//! Implementation of a file list +class CFileList : public IFileList +{ +public: + // CFileList methods + + //! Constructor + /** \param path The path of this file archive */ + CFileList(const io::path &path, bool ignoreCase, bool ignorePaths); + + //! Destructor + virtual ~CFileList(); + + //! Add as a file or folder to the list + /** \param fullPath The file name including path, up to the root of the file list. + \param isDirectory True if this is a directory rather than a file. + \param offset The offset where the file is stored in an archive + \param size The size of the file in bytes. + \param id The ID of the file in the archive which owns it */ + u32 addItem(const io::path &fullPath, u32 offset, u32 size, bool isDirectory, u32 id = 0) override; + + //! Sorts the file list. You should call this after adding any items to the file list + void sort() override; + + //! Returns the amount of files in the filelist. + u32 getFileCount() const override; + + //! Gets the name of a file in the list, based on an index. + const io::path &getFileName(u32 index) const override; + + //! Gets the full name of a file in the list, path included, based on an index. + const io::path &getFullFileName(u32 index) const override; + + //! Returns the ID of a file in the file list, based on an index. + u32 getID(u32 index) const override; + + //! Returns true if the file is a directory + bool isDirectory(u32 index) const override; + + //! Returns the size of a file + u32 getFileSize(u32 index) const override; + + //! Returns the offset of a file + u32 getFileOffset(u32 index) const override; + + //! Searches for a file or folder within the list, returns the index + s32 findFile(const io::path &filename, bool isFolder) const override; + + //! Returns the base path of the file list + const io::path &getPath() const override; + +protected: + //! Ignore paths when adding or searching for files + bool IgnorePaths; + + //! Ignore case when adding or searching for files + bool IgnoreCase; + + //! Path to the file list + io::path Path; + + //! List of files + core::array Files; +}; + +} // end namespace irr +} // end namespace io diff --git a/irr/src/CFileSystem.cpp b/irr/src/CFileSystem.cpp new file mode 100644 index 000000000..bffb703dd --- /dev/null +++ b/irr/src/CFileSystem.cpp @@ -0,0 +1,762 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CFileSystem.h" +#include "IReadFile.h" +#include "IWriteFile.h" +#include "CZipReader.h" +#include "CFileList.h" +#include "stdio.h" +#include "os.h" +#include "CReadFile.h" +#include "CMemoryFile.h" +#include "CLimitReadFile.h" +#include "CWriteFile.h" +#include + +#if defined(__STRICT_ANSI__) +#error Compiling with __STRICT_ANSI__ not supported. g++ does set this when compiling with -std=c++11 or -std=c++0x. Use instead -std=gnu++11 or -std=gnu++0x. Or use -U__STRICT_ANSI__ to disable strict ansi. +#endif + +#if defined(_IRR_WINDOWS_API_) +#include // for _chdir +#include // for _access +#include +#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_)) +#include +#include +#include +#include +#include +#include +#include +#include +#elif defined(_IRR_EMSCRIPTEN_PLATFORM_) +#include +#endif + +namespace irr +{ +namespace io +{ + +//! constructor +CFileSystem::CFileSystem() +{ +#ifdef _DEBUG + setDebugName("CFileSystem"); +#endif + + setFileListSystem(FILESYSTEM_NATIVE); + //! reset current working directory + getWorkingDirectory(); + + ArchiveLoader.push_back(new CArchiveLoaderZIP(this)); +} + +//! destructor +CFileSystem::~CFileSystem() +{ + u32 i; + + for (i = 0; i < FileArchives.size(); ++i) { + FileArchives[i]->drop(); + } + + for (i = 0; i < ArchiveLoader.size(); ++i) { + ArchiveLoader[i]->drop(); + } +} + +//! opens a file for read access +IReadFile *CFileSystem::createAndOpenFile(const io::path &filename) +{ + if (filename.empty()) + return 0; + + IReadFile *file = 0; + u32 i; + + for (i = 0; i < FileArchives.size(); ++i) { + file = FileArchives[i]->createAndOpenFile(filename); + if (file) + return file; + } + + // Create the file using an absolute path so that it matches + // the scheme used by CNullDriver::getTexture(). + return CReadFile::createReadFile(getAbsolutePath(filename)); +} + +//! Creates an IReadFile interface for treating memory like a file. +IReadFile *CFileSystem::createMemoryReadFile(const void *memory, s32 len, + const io::path &fileName, bool deleteMemoryWhenDropped) +{ + if (!memory) + return 0; + else + return new CMemoryReadFile(memory, len, fileName, deleteMemoryWhenDropped); +} + +//! Creates an IReadFile interface for reading files inside files +IReadFile *CFileSystem::createLimitReadFile(const io::path &fileName, + IReadFile *alreadyOpenedFile, long pos, long areaSize) +{ + if (!alreadyOpenedFile) + return 0; + else + return new CLimitReadFile(alreadyOpenedFile, pos, areaSize, fileName); +} + +//! Creates an IReadFile interface for treating memory like a file. +IWriteFile *CFileSystem::createMemoryWriteFile(void *memory, s32 len, + const io::path &fileName, bool deleteMemoryWhenDropped) +{ + if (!memory) + return 0; + else + return new CMemoryWriteFile(memory, len, fileName, deleteMemoryWhenDropped); +} + +//! Opens a file for write access. +IWriteFile *CFileSystem::createAndWriteFile(const io::path &filename, bool append) +{ + return CWriteFile::createWriteFile(filename, append); +} + +//! Adds an external archive loader to the engine. +void CFileSystem::addArchiveLoader(IArchiveLoader *loader) +{ + if (!loader) + return; + + loader->grab(); + ArchiveLoader.push_back(loader); +} + +//! Returns the total number of archive loaders added. +u32 CFileSystem::getArchiveLoaderCount() const +{ + return ArchiveLoader.size(); +} + +//! Gets the archive loader by index. +IArchiveLoader *CFileSystem::getArchiveLoader(u32 index) const +{ + if (index < ArchiveLoader.size()) + return ArchiveLoader[index]; + else + return 0; +} + +//! move the hirarchy of the filesystem. moves sourceIndex relative up or down +bool CFileSystem::moveFileArchive(u32 sourceIndex, s32 relative) +{ + bool r = false; + const s32 dest = (s32)sourceIndex + relative; + const s32 dir = relative < 0 ? -1 : 1; + const s32 sourceEnd = ((s32)FileArchives.size()) - 1; + IFileArchive *t; + + for (s32 s = (s32)sourceIndex; s != dest; s += dir) { + if (s < 0 || s > sourceEnd || s + dir < 0 || s + dir > sourceEnd) + continue; + + t = FileArchives[s + dir]; + FileArchives[s + dir] = FileArchives[s]; + FileArchives[s] = t; + r = true; + } + return r; +} + +//! Adds an archive to the file system. +bool CFileSystem::addFileArchive(const io::path &filename, bool ignoreCase, + bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType, + const core::stringc &password, + IFileArchive **retArchive) +{ + IFileArchive *archive = 0; + bool ret = false; + + // see if archive is already added + + s32 i; + + // do we know what type it should be? + if (archiveType == EFAT_UNKNOWN) { + // try to load archive based on file name + for (i = ArchiveLoader.size() - 1; i >= 0; --i) { + if (ArchiveLoader[i]->isALoadableFileFormat(filename)) { + archive = ArchiveLoader[i]->createArchive(filename, ignoreCase, ignorePaths); + if (archive) + break; + } + } + + // try to load archive based on content + if (!archive) { + io::IReadFile *file = createAndOpenFile(filename); + if (file) { + for (i = ArchiveLoader.size() - 1; i >= 0; --i) { + file->seek(0); + if (ArchiveLoader[i]->isALoadableFileFormat(file)) { + file->seek(0); + archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths); + if (archive) + break; + } + } + file->drop(); + } + } + } else { + // try to open archive based on archive loader type + + io::IReadFile *file = 0; + + for (i = ArchiveLoader.size() - 1; i >= 0; --i) { + if (ArchiveLoader[i]->isALoadableFileFormat(archiveType)) { + // attempt to open file + if (!file) + file = createAndOpenFile(filename); + + // is the file open? + if (file) { + // attempt to open archive + file->seek(0); + if (ArchiveLoader[i]->isALoadableFileFormat(file)) { + file->seek(0); + archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths); + if (archive) + break; + } + } else { + // couldn't open file + break; + } + } + } + + // if open, close the file + if (file) + file->drop(); + } + + if (archive) { + FileArchives.push_back(archive); + if (password.size()) + archive->Password = password; + if (retArchive) + *retArchive = archive; + ret = true; + } else { + os::Printer::log("Could not create archive for", filename, ELL_ERROR); + } + + return ret; +} + +bool CFileSystem::addFileArchive(IReadFile *file, bool ignoreCase, + bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType, + const core::stringc &password, IFileArchive **retArchive) +{ + if (!file) + return false; + + if (file) { + IFileArchive *archive = 0; + s32 i; + + if (archiveType == EFAT_UNKNOWN) { + // try to load archive based on file name + for (i = ArchiveLoader.size() - 1; i >= 0; --i) { + if (ArchiveLoader[i]->isALoadableFileFormat(file->getFileName())) { + archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths); + if (archive) + break; + } + } + + // try to load archive based on content + if (!archive) { + for (i = ArchiveLoader.size() - 1; i >= 0; --i) { + file->seek(0); + if (ArchiveLoader[i]->isALoadableFileFormat(file)) { + file->seek(0); + archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths); + if (archive) + break; + } + } + } + } else { + // try to open archive based on archive loader type + for (i = ArchiveLoader.size() - 1; i >= 0; --i) { + if (ArchiveLoader[i]->isALoadableFileFormat(archiveType)) { + // attempt to open archive + file->seek(0); + if (ArchiveLoader[i]->isALoadableFileFormat(file)) { + file->seek(0); + archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths); + if (archive) + break; + } + } + } + } + + if (archive) { + FileArchives.push_back(archive); + if (password.size()) + archive->Password = password; + if (retArchive) + *retArchive = archive; + return true; + } else { + os::Printer::log("Could not create archive for", file->getFileName(), ELL_ERROR); + } + } + + return false; +} + +//! Adds an archive to the file system. +bool CFileSystem::addFileArchive(IFileArchive *archive) +{ + if (archive) { + for (u32 i = 0; i < FileArchives.size(); ++i) { + if (archive == FileArchives[i]) { + return false; + } + } + FileArchives.push_back(archive); + archive->grab(); + + return true; + } + + return false; +} + +//! removes an archive from the file system. +bool CFileSystem::removeFileArchive(u32 index) +{ + bool ret = false; + if (index < FileArchives.size()) { + FileArchives[index]->drop(); + FileArchives.erase(index); + ret = true; + } + return ret; +} + +//! removes an archive from the file system. +bool CFileSystem::removeFileArchive(const io::path &filename) +{ + const path absPath = getAbsolutePath(filename); + for (u32 i = 0; i < FileArchives.size(); ++i) { + if (absPath == FileArchives[i]->getFileList()->getPath()) + return removeFileArchive(i); + } + return false; +} + +//! Removes an archive from the file system. +bool CFileSystem::removeFileArchive(const IFileArchive *archive) +{ + for (u32 i = 0; i < FileArchives.size(); ++i) { + if (archive == FileArchives[i]) { + return removeFileArchive(i); + } + } + return false; +} + +//! gets an archive +u32 CFileSystem::getFileArchiveCount() const +{ + return FileArchives.size(); +} + +IFileArchive *CFileSystem::getFileArchive(u32 index) +{ + return index < getFileArchiveCount() ? FileArchives[index] : 0; +} + +//! Returns the string of the current working directory +const io::path &CFileSystem::getWorkingDirectory() +{ + EFileSystemType type = FileSystemType; + + if (type != FILESYSTEM_NATIVE) { + type = FILESYSTEM_VIRTUAL; + } else { +#if defined(_IRR_WINDOWS_API_) + fschar_t tmp[_MAX_PATH]; + _getcwd(tmp, _MAX_PATH); + WorkingDirectory[FILESYSTEM_NATIVE] = tmp; + WorkingDirectory[FILESYSTEM_NATIVE].replace('\\', '/'); +#endif + +#if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_)) + + // getting the CWD is rather complex as we do not know the size + // so try it until the call was successful + // Note that neither the first nor the second parameter may be 0 according to POSIX + + u32 pathSize = 256; + char *tmpPath = new char[pathSize]; + while ((pathSize < (1 << 16)) && !(getcwd(tmpPath, pathSize))) { + delete[] tmpPath; + pathSize *= 2; + tmpPath = new char[pathSize]; + } + if (tmpPath) { + WorkingDirectory[FILESYSTEM_NATIVE] = tmpPath; + delete[] tmpPath; + } +#endif + + WorkingDirectory[type].validate(); + } + + return WorkingDirectory[type]; +} + +//! Changes the current Working Directory to the given string. +bool CFileSystem::changeWorkingDirectoryTo(const io::path &newDirectory) +{ + bool success = false; + + if (FileSystemType != FILESYSTEM_NATIVE) { + WorkingDirectory[FILESYSTEM_VIRTUAL] = newDirectory; + // is this empty string constant really intended? + flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], _IRR_TEXT("")); + success = true; + } else { + WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory; + +#if defined(_MSC_VER) + success = (_chdir(newDirectory.c_str()) == 0); +#else + success = (chdir(newDirectory.c_str()) == 0); +#endif + } + + return success; +} + +io::path CFileSystem::getAbsolutePath(const io::path &filename) const +{ + if (filename.empty()) + return filename; +#if defined(_IRR_WINDOWS_API_) + fschar_t *p = 0; + fschar_t fpath[_MAX_PATH]; + p = _fullpath(fpath, filename.c_str(), _MAX_PATH); + core::stringc tmp(p); + tmp.replace('\\', '/'); + return tmp; +#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_)) + c8 *p = 0; + c8 fpath[4096]; + fpath[0] = 0; + p = realpath(filename.c_str(), fpath); + if (!p) { + // content in fpath is unclear at this point + if (!fpath[0]) { // seems like fpath wasn't altered, use our best guess + io::path tmp(filename); + return flattenFilename(tmp); + } else + return io::path(fpath); + } + if (filename[filename.size() - 1] == '/') + return io::path(p) + _IRR_TEXT("/"); + else + return io::path(p); +#else + return io::path(filename); +#endif +} + +//! returns the directory part of a filename, i.e. all until the first +//! slash or backslash, excluding it. If no directory path is prefixed, a '.' +//! is returned. +io::path CFileSystem::getFileDir(const io::path &filename) const +{ + // find last forward or backslash + s32 lastSlash = filename.findLast('/'); + const s32 lastBackSlash = filename.findLast('\\'); + lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash; + + if ((u32)lastSlash < filename.size()) + return filename.subString(0, lastSlash); + else + return _IRR_TEXT("."); +} + +//! returns the base part of a filename, i.e. all except for the directory +//! part. If no directory path is prefixed, the full name is returned. +io::path CFileSystem::getFileBasename(const io::path &filename, bool keepExtension) const +{ + // find last forward or backslash + s32 lastSlash = filename.findLast('/'); + const s32 lastBackSlash = filename.findLast('\\'); + lastSlash = core::max_(lastSlash, lastBackSlash); + + // get number of chars after last dot + s32 end = 0; + if (!keepExtension) { + // take care to search only after last slash to check only for + // dots in the filename + end = filename.findLast('.'); + if (end == -1 || end < lastSlash) + end = 0; + else + end = filename.size() - end; + } + + if ((u32)lastSlash < filename.size()) + return filename.subString(lastSlash + 1, filename.size() - lastSlash - 1 - end); + else if (end != 0) + return filename.subString(0, filename.size() - end); + else + return filename; +} + +//! flatten a path and file name for example: "/you/me/../." becomes "/you" +io::path &CFileSystem::flattenFilename(io::path &directory, const io::path &root) const +{ + directory.replace('\\', '/'); + if (directory.lastChar() != '/') + directory.append('/'); + + io::path dir; + io::path subdir; + + s32 lastpos = 0; + s32 pos = 0; + bool lastWasRealDir = false; + + while ((pos = directory.findNext('/', lastpos)) >= 0) { + subdir = directory.subString(lastpos, pos - lastpos + 1); + + if (subdir == _IRR_TEXT("../")) { + if (lastWasRealDir) { + deletePathFromPath(dir, 2); + lastWasRealDir = (dir.size() != 0); + } else { + dir.append(subdir); + lastWasRealDir = false; + } + } else if (subdir == _IRR_TEXT("/")) { + dir = root; + } else if (subdir != _IRR_TEXT("./")) { + dir.append(subdir); + lastWasRealDir = true; + } + + lastpos = pos + 1; + } + directory = dir; + return directory; +} + +//! Get the relative filename, relative to the given directory +path CFileSystem::getRelativeFilename(const path &filename, const path &directory) const +{ + if (filename.empty() || directory.empty()) + return filename; + + io::path path1, file, ext; + core::splitFilename(getAbsolutePath(filename), &path1, &file, &ext); + io::path path2(getAbsolutePath(directory)); + std::list list1, list2; + path1.split(list1, _IRR_TEXT("/\\"), 2); + path2.split(list2, _IRR_TEXT("/\\"), 2); + std::list::const_iterator it1, it2; + it1 = list1.begin(); + it2 = list2.begin(); + +#if defined(_IRR_WINDOWS_API_) + fschar_t partition1 = 0, partition2 = 0; + io::path prefix1, prefix2; + if (it1 != list1.end()) + prefix1 = *it1; + if (it2 != list2.end()) + prefix2 = *it2; + if (prefix1.size() > 1 && prefix1[1] == _IRR_TEXT(':')) + partition1 = core::locale_lower(prefix1[0]); + if (prefix2.size() > 1 && prefix2[1] == _IRR_TEXT(':')) + partition2 = core::locale_lower(prefix2[0]); + + // must have the same prefix or we can't resolve it to a relative filename + if (partition1 != partition2) { + return filename; + } +#endif + + for (; it1 != list1.end() && it2 != list2.end() +#if defined(_IRR_WINDOWS_API_) + && (io::path(*it1).make_lower() == io::path(*it2).make_lower()) +#else + && (*it1 == *it2) +#endif + ;) { + ++it1; + ++it2; + } + path1 = _IRR_TEXT(""); + for (; it2 != list2.end(); ++it2) + path1 += _IRR_TEXT("../"); + while (it1 != list1.end()) { + path1 += *it1++; + path1 += _IRR_TEXT('/'); + } + path1 += file; + if (ext.size()) { + path1 += _IRR_TEXT('.'); + path1 += ext; + } + return path1; +} + +//! Sets the current file systen type +EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType) +{ + EFileSystemType current = FileSystemType; + FileSystemType = listType; + return current; +} + +//! Creates a list of files and directories in the current working directory +IFileList *CFileSystem::createFileList() +{ + CFileList *r = 0; + io::path Path = getWorkingDirectory(); + Path.replace('\\', '/'); + if (!Path.empty() && Path.lastChar() != '/') + Path.append('/'); + + //! Construct from native filesystem + if (FileSystemType == FILESYSTEM_NATIVE) { +// -------------------------------------------- +//! Windows version +#ifdef _IRR_WINDOWS_API_ + + r = new CFileList(Path, true, false); + + // intptr_t is optional but supported by MinGW since 2007 or earlier. + intptr_t hFile; + struct _tfinddata_t c_file; + if ((hFile = _tfindfirst(_T("*"), &c_file)) != (intptr_t)(-1L)) { + do { + r->addItem(Path + c_file.name, 0, c_file.size, (_A_SUBDIR & c_file.attrib) != 0, 0); + } while (_tfindnext(hFile, &c_file) == 0); + + _findclose(hFile); + } + +#endif + +// -------------------------------------------- +//! Linux version +#if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_)) + + r = new CFileList(Path, false, false); + + r->addItem(Path + _IRR_TEXT(".."), 0, 0, true, 0); + + //! We use the POSIX compliant methods instead of scandir + DIR *dirHandle = opendir(Path.c_str()); + if (dirHandle) { + struct dirent *dirEntry; + while ((dirEntry = readdir(dirHandle))) { + u32 size = 0; + bool isDirectory = false; + + if ((strcmp(dirEntry->d_name, ".") == 0) || + (strcmp(dirEntry->d_name, "..") == 0)) { + continue; + } + struct stat buf; + if (stat(dirEntry->d_name, &buf) == 0) { + size = buf.st_size; + isDirectory = S_ISDIR(buf.st_mode); + } +#if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__) && !defined(__HAIKU__) + // only available on some systems + else { + isDirectory = dirEntry->d_type == DT_DIR; + } +#endif + + r->addItem(Path + dirEntry->d_name, 0, size, isDirectory, 0); + } + closedir(dirHandle); + } +#endif + } else { + //! create file list for the virtual filesystem + r = new CFileList(Path, false, false); + + //! add relative navigation + SFileListEntry e2; + SFileListEntry e3; + + //! PWD + r->addItem(Path + _IRR_TEXT("."), 0, 0, true, 0); + + //! parent + r->addItem(Path + _IRR_TEXT(".."), 0, 0, true, 0); + + //! merge archives + for (u32 i = 0; i < FileArchives.size(); ++i) { + const IFileList *merge = FileArchives[i]->getFileList(); + + for (u32 j = 0; j < merge->getFileCount(); ++j) { + if (core::isInSameDirectory(Path, merge->getFullFileName(j)) == 0) { + r->addItem(merge->getFullFileName(j), merge->getFileOffset(j), merge->getFileSize(j), merge->isDirectory(j), 0); + } + } + } + } + + if (r) + r->sort(); + return r; +} + +//! Creates an empty filelist +IFileList *CFileSystem::createEmptyFileList(const io::path &path, bool ignoreCase, bool ignorePaths) +{ + return new CFileList(path, ignoreCase, ignorePaths); +} + +//! determines if a file exists and would be able to be opened. +bool CFileSystem::existFile(const io::path &filename) const +{ + for (u32 i = 0; i < FileArchives.size(); ++i) + if (FileArchives[i]->getFileList()->findFile(filename) != -1) + return true; + +#if defined(_MSC_VER) + return (_access(filename.c_str(), 0) != -1); +#elif defined(F_OK) + return (access(filename.c_str(), F_OK) != -1); +#else + return (access(filename.c_str(), 0) != -1); +#endif +} + +//! creates a filesystem which is able to open files from the ordinary file system, +//! and out of zipfiles, which are able to be added to the filesystem. +IFileSystem *createFileSystem() +{ + return new CFileSystem(); +} + +} // end namespace irr +} // end namespace io diff --git a/irr/src/CFileSystem.h b/irr/src/CFileSystem.h new file mode 100644 index 000000000..18bc7ff3f --- /dev/null +++ b/irr/src/CFileSystem.h @@ -0,0 +1,138 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IFileSystem.h" +#include "irrArray.h" + +namespace irr +{ +namespace io +{ + +class CZipReader; + +/*! + FileSystem which uses normal files and one zipfile +*/ +class CFileSystem : public IFileSystem +{ +public: + //! constructor + CFileSystem(); + + //! destructor + virtual ~CFileSystem(); + + //! opens a file for read access + IReadFile *createAndOpenFile(const io::path &filename) override; + + //! Creates an IReadFile interface for accessing memory like a file. + IReadFile *createMemoryReadFile(const void *memory, s32 len, const io::path &fileName, bool deleteMemoryWhenDropped = false) override; + + //! Creates an IReadFile interface for accessing files inside files + IReadFile *createLimitReadFile(const io::path &fileName, IReadFile *alreadyOpenedFile, long pos, long areaSize) override; + + //! Creates an IWriteFile interface for accessing memory like a file. + IWriteFile *createMemoryWriteFile(void *memory, s32 len, const io::path &fileName, bool deleteMemoryWhenDropped = false) override; + + //! Opens a file for write access. + IWriteFile *createAndWriteFile(const io::path &filename, bool append = false) override; + + //! Adds an archive to the file system. + virtual bool addFileArchive(const io::path &filename, + bool ignoreCase = true, bool ignorePaths = true, + E_FILE_ARCHIVE_TYPE archiveType = EFAT_UNKNOWN, + const core::stringc &password = "", + IFileArchive **retArchive = 0) override; + + //! Adds an archive to the file system. + virtual bool addFileArchive(IReadFile *file, bool ignoreCase = true, + bool ignorePaths = true, + E_FILE_ARCHIVE_TYPE archiveType = EFAT_UNKNOWN, + const core::stringc &password = "", + IFileArchive **retArchive = 0) override; + + //! Adds an archive to the file system. + bool addFileArchive(IFileArchive *archive) override; + + //! move the hirarchy of the filesystem. moves sourceIndex relative up or down + bool moveFileArchive(u32 sourceIndex, s32 relative) override; + + //! Adds an external archive loader to the engine. + void addArchiveLoader(IArchiveLoader *loader) override; + + //! Returns the total number of archive loaders added. + u32 getArchiveLoaderCount() const override; + + //! Gets the archive loader by index. + IArchiveLoader *getArchiveLoader(u32 index) const override; + + //! gets the file archive count + u32 getFileArchiveCount() const override; + + //! gets an archive + IFileArchive *getFileArchive(u32 index) override; + + //! removes an archive from the file system. + bool removeFileArchive(u32 index) override; + + //! removes an archive from the file system. + bool removeFileArchive(const io::path &filename) override; + + //! Removes an archive from the file system. + bool removeFileArchive(const IFileArchive *archive) override; + + //! Returns the string of the current working directory + const io::path &getWorkingDirectory() override; + + //! Changes the current Working Directory to the string given. + //! The string is operating system dependent. Under Windows it will look + //! like this: "drive:\directory\sudirectory\" + bool changeWorkingDirectoryTo(const io::path &newDirectory) override; + + //! Converts a relative path to an absolute (unique) path, resolving symbolic links + io::path getAbsolutePath(const io::path &filename) const override; + + //! Returns the directory a file is located in. + /** \param filename: The file to get the directory from */ + io::path getFileDir(const io::path &filename) const override; + + //! Returns the base part of a filename, i.e. the name without the directory + //! part. If no directory is prefixed, the full name is returned. + /** \param filename: The file to get the basename from */ + io::path getFileBasename(const io::path &filename, bool keepExtension = true) const override; + + //! flatten a path and file name for example: "/you/me/../." becomes "/you" + io::path &flattenFilename(io::path &directory, const io::path &root = "/") const override; + + //! Get the relative filename, relative to the given directory + path getRelativeFilename(const path &filename, const path &directory) const override; + + EFileSystemType setFileListSystem(EFileSystemType listType) override; + + //! Creates a list of files and directories in the current working directory + //! and returns it. + IFileList *createFileList() override; + + //! Creates an empty filelist + IFileList *createEmptyFileList(const io::path &path, bool ignoreCase, bool ignorePaths) override; + + //! determines if a file exists and would be able to be opened. + bool existFile(const io::path &filename) const override; + +private: + //! Currently used FileSystemType + EFileSystemType FileSystemType; + //! WorkingDirectory for Native and Virtual filesystems + io::path WorkingDirectory[2]; + //! currently attached ArchiveLoaders + core::array ArchiveLoader; + //! currently attached Archives + core::array FileArchives; +}; + +} // end namespace irr +} // end namespace io diff --git a/irr/src/CGLXManager.cpp b/irr/src/CGLXManager.cpp new file mode 100644 index 000000000..8593621b7 --- /dev/null +++ b/irr/src/CGLXManager.cpp @@ -0,0 +1,401 @@ +// Copyright (C) 2013 Christian Stehno +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "CGLXManager.h" + +#ifdef _IRR_COMPILE_WITH_GLX_MANAGER_ + +#include "os.h" + +#define GL_GLEXT_LEGACY 1 +#define GLX_GLXEXT_LEGACY 1 +#include +#include +#include +#include + +namespace irr +{ +namespace video +{ + +CGLXManager::CGLXManager(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &videodata, int screennr) : + Params(params), PrimaryContext(videodata), VisualInfo(0), glxFBConfig(0), GlxWin(0) +{ +#ifdef _DEBUG + setDebugName("CGLXManager"); +#endif + + CurrentContext.OpenGLLinux.X11Display = PrimaryContext.OpenGLLinux.X11Display; + + int major, minor; + Display *display = (Display *)PrimaryContext.OpenGLLinux.X11Display; + const bool isAvailableGLX = glXQueryExtension(display, &major, &minor); + + if (isAvailableGLX && glXQueryVersion(display, &major, &minor)) { +#if defined(GLX_VERSION_1_3) + typedef GLXFBConfig *(*PFNGLXCHOOSEFBCONFIGPROC)(Display *dpy, int screen, const int *attrib_list, int *nelements); + + PFNGLXCHOOSEFBCONFIGPROC glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddress(reinterpret_cast("glXChooseFBConfig")); + if (major == 1 && minor > 2 && glxChooseFBConfig) { + os::Printer::log("GLX >= 1.3", ELL_DEBUG); + // attribute array for the draw buffer + int visualAttrBuffer[] = { + GLX_RENDER_TYPE, + GLX_RGBA_BIT, + GLX_RED_SIZE, + 4, + GLX_GREEN_SIZE, + 4, + GLX_BLUE_SIZE, + 4, + GLX_ALPHA_SIZE, + Params.WithAlphaChannel ? 1 : 0, + GLX_DEPTH_SIZE, + Params.ZBufferBits, // 10,11 + GLX_DOUBLEBUFFER, + Params.Doublebuffer ? True : False, + GLX_STENCIL_SIZE, + Params.Stencilbuffer ? 1 : 0, +#if defined(GLX_VERSION_1_4) && defined(GLX_SAMPLE_BUFFERS) // we need to check the extension string! + GLX_SAMPLE_BUFFERS, + 1, + GLX_SAMPLES, + Params.AntiAlias, // 18,19 +#elif defined(GLX_ARB_multisample) + GLX_SAMPLE_BUFFERS_ARB, + 1, + GLX_SAMPLES_ARB, + Params.AntiAlias, // 18,19 +#elif defined(GLX_SGIS_multisample) + GLX_SAMPLE_BUFFERS_SGIS, + 1, + GLX_SAMPLES_SGIS, + Params.AntiAlias, // 18,19 +#endif + GLX_STEREO, + Params.Stereobuffer ? True : False, + None, + }; + + GLXFBConfig *configList = 0; + int nitems = 0; + if (Params.AntiAlias < 2) { + visualAttrBuffer[17] = 0; + visualAttrBuffer[19] = 0; + } + // first round with unchanged values + { + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + if (!configList && Params.AntiAlias) { + while (!configList && (visualAttrBuffer[19] > 1)) { + visualAttrBuffer[19] -= 1; + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + } + if (!configList) { + visualAttrBuffer[17] = 0; + visualAttrBuffer[19] = 0; + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + if (configList) { + os::Printer::log("No FSAA available.", ELL_WARNING); + Params.AntiAlias = 0; + } else { + // reenable multisampling + visualAttrBuffer[17] = 1; + visualAttrBuffer[19] = Params.AntiAlias; + } + } + } + } + // Next try with flipped stencil buffer value + // If the first round was with stencil flag it's now without + // Other way round also makes sense because some configs + // only have depth buffer combined with stencil buffer + if (!configList) { + if (Params.Stencilbuffer) + os::Printer::log("No stencilbuffer available, disabling stencil shadows.", ELL_WARNING); + Params.Stencilbuffer = !Params.Stencilbuffer; + visualAttrBuffer[15] = Params.Stencilbuffer ? 1 : 0; + + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + if (!configList && Params.AntiAlias) { + while (!configList && (visualAttrBuffer[19] > 1)) { + visualAttrBuffer[19] -= 1; + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + } + if (!configList) { + visualAttrBuffer[17] = 0; + visualAttrBuffer[19] = 0; + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + if (configList) { + os::Printer::log("No FSAA available.", ELL_WARNING); + Params.AntiAlias = 0; + } else { + // reenable multisampling + visualAttrBuffer[17] = 1; + visualAttrBuffer[19] = Params.AntiAlias; + } + } + } + } + // Next try without double buffer + if (!configList && Params.Doublebuffer) { + os::Printer::log("No doublebuffering available.", ELL_WARNING); + Params.Doublebuffer = false; + visualAttrBuffer[13] = GLX_DONT_CARE; + Params.Stencilbuffer = false; + visualAttrBuffer[15] = 0; + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + if (!configList && Params.AntiAlias) { + while (!configList && (visualAttrBuffer[19] > 1)) { + visualAttrBuffer[19] -= 1; + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + } + if (!configList) { + visualAttrBuffer[17] = 0; + visualAttrBuffer[19] = 0; + configList = glxChooseFBConfig(display, screennr, visualAttrBuffer, &nitems); + if (configList) { + os::Printer::log("No FSAA available.", ELL_WARNING); + Params.AntiAlias = 0; + } else { + // reenable multisampling + visualAttrBuffer[17] = 1; + visualAttrBuffer[19] = Params.AntiAlias; + } + } + } + } + if (configList) { + glxFBConfig = configList[0]; + XFree(configList); + typedef XVisualInfo *(*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display *dpy, GLXFBConfig config); + PFNGLXGETVISUALFROMFBCONFIGPROC glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)glXGetProcAddress(reinterpret_cast("glXGetVisualFromFBConfig")); + if (glxGetVisualFromFBConfig) + VisualInfo = glxGetVisualFromFBConfig(display, (GLXFBConfig)glxFBConfig); + } + } else +#endif + { + // attribute array for the draw buffer + int visualAttrBuffer[] = { + GLX_RGBA, GLX_USE_GL, + GLX_RED_SIZE, 4, + GLX_GREEN_SIZE, 4, + GLX_BLUE_SIZE, 4, + GLX_ALPHA_SIZE, Params.WithAlphaChannel ? 1 : 0, + GLX_DEPTH_SIZE, Params.ZBufferBits, + GLX_STENCIL_SIZE, Params.Stencilbuffer ? 1 : 0, // 12,13 + // The following attributes have no flags, but are + // either present or not. As a no-op we use + // GLX_USE_GL, which is silently ignored by glXChooseVisual + Params.Doublebuffer ? GLX_DOUBLEBUFFER : GLX_USE_GL, // 14 + Params.Stereobuffer ? GLX_STEREO : GLX_USE_GL, // 15 + None, + }; + + VisualInfo = glXChooseVisual(display, screennr, visualAttrBuffer); + if (!VisualInfo) { + if (Params.Stencilbuffer) + os::Printer::log("No stencilbuffer available, disabling.", ELL_WARNING); + Params.Stencilbuffer = !Params.Stencilbuffer; + visualAttrBuffer[13] = Params.Stencilbuffer ? 1 : 0; + + VisualInfo = glXChooseVisual(display, screennr, visualAttrBuffer); + if (!VisualInfo && Params.Doublebuffer) { + os::Printer::log("No doublebuffering available.", ELL_WARNING); + Params.Doublebuffer = false; + visualAttrBuffer[14] = GLX_USE_GL; + VisualInfo = glXChooseVisual(display, screennr, visualAttrBuffer); + } + } + } + } else + os::Printer::log("No GLX support available. OpenGL driver will not work.", ELL_WARNING); +} + +CGLXManager::~CGLXManager() +{ +} + +bool CGLXManager::initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &videodata) +{ + // store params + Params = params; + + // set display + CurrentContext.OpenGLLinux.X11Display = videodata.OpenGLLinux.X11Display; + + // now get new window + CurrentContext.OpenGLLinux.X11Window = videodata.OpenGLLinux.X11Window; + if (!PrimaryContext.OpenGLLinux.X11Window) { + PrimaryContext.OpenGLLinux.X11Window = CurrentContext.OpenGLLinux.X11Window; + } + + return true; +} + +void CGLXManager::terminate() +{ + memset((void *)&CurrentContext, 0, sizeof(CurrentContext)); +} + +bool CGLXManager::generateSurface() +{ + if (glxFBConfig) { + GlxWin = glXCreateWindow((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXFBConfig)glxFBConfig, CurrentContext.OpenGLLinux.X11Window, NULL); + if (!GlxWin) { + os::Printer::log("Could not create GLX window.", ELL_WARNING); + return false; + } + + CurrentContext.OpenGLLinux.GLXWindow = GlxWin; + } else { + CurrentContext.OpenGLLinux.GLXWindow = CurrentContext.OpenGLLinux.X11Window; + } + return true; +} + +void CGLXManager::destroySurface() +{ + if (GlxWin) + glXDestroyWindow((Display *)CurrentContext.OpenGLLinux.X11Display, GlxWin); +} + +#if defined(GLX_ARB_create_context) +static int IrrIgnoreError(Display *display, XErrorEvent *event) +{ + char msg[256]; + XGetErrorText(display, event->error_code, msg, 256); + os::Printer::log("Ignoring an X error", msg, ELL_DEBUG); + return 0; +} +#endif + +bool CGLXManager::generateContext() +{ + GLXContext context = 0; + + if (glxFBConfig) { + if (GlxWin) { +#if defined(GLX_ARB_create_context) + + PFNGLXCREATECONTEXTATTRIBSARBPROC glxCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress(reinterpret_cast("glXCreateContextAttribsARB")); + + if (glxCreateContextAttribsARB) { + os::Printer::log("GLX with GLX_ARB_create_context", ELL_DEBUG); + int contextAttrBuffer[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + // GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + None}; + XErrorHandler old = XSetErrorHandler(IrrIgnoreError); + context = glxCreateContextAttribsARB((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXFBConfig)glxFBConfig, NULL, True, contextAttrBuffer); + XSetErrorHandler(old); + // transparently fall back to legacy call + } + if (!context) +#endif + { + // create glx context + context = glXCreateNewContext((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXFBConfig)glxFBConfig, GLX_RGBA_TYPE, NULL, True); + if (!context) { + os::Printer::log("Could not create GLX rendering context.", ELL_WARNING); + return false; + } + } + } else { + os::Printer::log("GLX window was not properly created.", ELL_WARNING); + return false; + } + } else { + context = glXCreateContext((Display *)CurrentContext.OpenGLLinux.X11Display, VisualInfo, NULL, True); + if (!context) { + os::Printer::log("Could not create GLX rendering context.", ELL_WARNING); + return false; + } + } + CurrentContext.OpenGLLinux.X11Context = context; + return true; +} + +const SExposedVideoData &CGLXManager::getContext() const +{ + return CurrentContext; +} + +bool CGLXManager::activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) +{ + // TODO: handle restorePrimaryOnZero + + if (videoData.OpenGLLinux.X11Window) { + if (videoData.OpenGLLinux.X11Display && videoData.OpenGLLinux.X11Context) { + if (!glXMakeCurrent((Display *)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.GLXWindow, (GLXContext)videoData.OpenGLLinux.X11Context)) { + os::Printer::log("Context activation failed."); + return false; + } else { + CurrentContext.OpenGLLinux.GLXWindow = videoData.OpenGLLinux.GLXWindow; + CurrentContext.OpenGLLinux.X11Window = videoData.OpenGLLinux.X11Window; + CurrentContext.OpenGLLinux.X11Display = videoData.OpenGLLinux.X11Display; + } + } else { + // in case we only got a window ID, try with the existing values for display and context + if (!glXMakeCurrent((Display *)PrimaryContext.OpenGLLinux.X11Display, videoData.OpenGLLinux.GLXWindow, (GLXContext)PrimaryContext.OpenGLLinux.X11Context)) { + os::Printer::log("Context activation failed."); + return false; + } else { + CurrentContext.OpenGLLinux.GLXWindow = videoData.OpenGLLinux.GLXWindow; + CurrentContext.OpenGLLinux.X11Window = videoData.OpenGLLinux.X11Window; + CurrentContext.OpenGLLinux.X11Display = PrimaryContext.OpenGLLinux.X11Display; + } + } + } else if (!restorePrimaryOnZero && !videoData.OpenGLLinux.X11Window && !videoData.OpenGLLinux.X11Display) { + if (!glXMakeCurrent((Display *)PrimaryContext.OpenGLLinux.X11Display, None, NULL)) { + os::Printer::log("Render Context reset failed."); + return false; + } + CurrentContext.OpenGLLinux.X11Window = 0; + CurrentContext.OpenGLLinux.X11Display = 0; + } + // set back to main context + else if (CurrentContext.OpenGLLinux.X11Display != PrimaryContext.OpenGLLinux.X11Display) { + if (!glXMakeCurrent((Display *)PrimaryContext.OpenGLLinux.X11Display, PrimaryContext.OpenGLLinux.X11Window, (GLXContext)PrimaryContext.OpenGLLinux.X11Context)) { + os::Printer::log("Context activation failed."); + return false; + } else { + CurrentContext = PrimaryContext; + } + } + return true; +} + +void CGLXManager::destroyContext() +{ + if (CurrentContext.OpenGLLinux.X11Context) { + if (GlxWin) { + if (!glXMakeContextCurrent((Display *)CurrentContext.OpenGLLinux.X11Display, None, None, NULL)) + os::Printer::log("Could not release glx context.", ELL_WARNING); + } else { + if (!glXMakeCurrent((Display *)CurrentContext.OpenGLLinux.X11Display, None, NULL)) + os::Printer::log("Could not release glx context.", ELL_WARNING); + } + glXDestroyContext((Display *)CurrentContext.OpenGLLinux.X11Display, (GLXContext)CurrentContext.OpenGLLinux.X11Context); + } +} + +void *CGLXManager::getProcAddress(const std::string &procName) +{ + return (void *)glXGetProcAddressARB(reinterpret_cast(procName.c_str())); +} + +bool CGLXManager::swapBuffers() +{ + glXSwapBuffers((Display *)CurrentContext.OpenGLLinux.X11Display, CurrentContext.OpenGLLinux.GLXWindow); + return true; +} + +} +} + +#endif diff --git a/irr/src/CGLXManager.h b/irr/src/CGLXManager.h new file mode 100644 index 000000000..f940d4316 --- /dev/null +++ b/irr/src/CGLXManager.h @@ -0,0 +1,76 @@ +// Copyright (C) 2013 Christian Stehno +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_GLX_MANAGER_ + +#include "SIrrCreationParameters.h" +#include "SExposedVideoData.h" +#include "IContextManager.h" +#include "SColor.h" +#include +#include + +// we can't include glx.h here, because gl.h has incompatible types with ogl es headers and it +// cause redefinition errors, thats why we use ugly trick with void* types and casts. + +namespace irr +{ +namespace video +{ +// GLX manager. +class CGLXManager : public IContextManager +{ +public: + //! Constructor. + CGLXManager(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &videodata, int screennr); + + //! Destructor + ~CGLXManager(); + + // Initialize + bool initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &data) override; + + // Terminate + void terminate() override; + + // Create surface. + bool generateSurface() override; + + // Destroy surface. + void destroySurface() override; + + // Create context. + bool generateContext() override; + + // Destroy context. + void destroyContext() override; + + //! Get current context + const SExposedVideoData &getContext() const override; + + //! Change render context, disable old and activate new defined by videoData + bool activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) override; + + // Get procedure address. + void *getProcAddress(const std::string &procName) override; + + // Swap buffers. + bool swapBuffers() override; + + XVisualInfo *getVisual() const { return VisualInfo; } // return XVisualInfo + +private: + SIrrlichtCreationParameters Params; + SExposedVideoData PrimaryContext; + SExposedVideoData CurrentContext; + XVisualInfo *VisualInfo; + void *glxFBConfig; // GLXFBConfig + XID GlxWin; // GLXWindow +}; +} +} + +#endif diff --git a/irr/src/CGUIButton.cpp b/irr/src/CGUIButton.cpp new file mode 100644 index 000000000..f023024f9 --- /dev/null +++ b/irr/src/CGUIButton.cpp @@ -0,0 +1,500 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIButton.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "IGUIFont.h" +#include "os.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIButton::CGUIButton(IGUIEnvironment *environment, IGUIElement *parent, + s32 id, core::rect rectangle, bool noclip) : + IGUIButton(environment, parent, id, rectangle), + SpriteBank(0), OverrideFont(0), + OverrideColorEnabled(false), OverrideColor(video::SColor(101, 255, 255, 255)), + ClickTime(0), HoverTime(0), FocusTime(0), + ClickShiftState(false), ClickControlState(false), + IsPushButton(false), Pressed(false), + UseAlphaChannel(false), DrawBorder(true), ScaleImage(false) +{ +#ifdef _DEBUG + setDebugName("CGUIButton"); +#endif + setNotClipped(noclip); + + // This element can be tabbed. + setTabStop(true); + setTabOrder(-1); +} + +//! destructor +CGUIButton::~CGUIButton() +{ + if (OverrideFont) + OverrideFont->drop(); + + if (SpriteBank) + SpriteBank->drop(); +} + +//! Sets if the images should be scaled to fit the button +void CGUIButton::setScaleImage(bool scaleImage) +{ + ScaleImage = scaleImage; +} + +//! Returns whether the button scale the used images +bool CGUIButton::isScalingImage() const +{ + return ScaleImage; +} + +//! Sets if the button should use the skin to draw its border +void CGUIButton::setDrawBorder(bool border) +{ + DrawBorder = border; +} + +void CGUIButton::setSpriteBank(IGUISpriteBank *sprites) +{ + if (sprites) + sprites->grab(); + + if (SpriteBank) + SpriteBank->drop(); + + SpriteBank = sprites; +} + +void CGUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop, bool scale) +{ + ButtonSprites[(u32)state].Index = index; + ButtonSprites[(u32)state].Color = color; + ButtonSprites[(u32)state].Loop = loop; + ButtonSprites[(u32)state].Scale = scale; +} + +//! Get the sprite-index for the given state or -1 when no sprite is set +s32 CGUIButton::getSpriteIndex(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Index; +} + +//! Get the sprite color for the given state. Color is only used when a sprite is set. +video::SColor CGUIButton::getSpriteColor(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Color; +} + +//! Returns if the sprite in the given state does loop +bool CGUIButton::getSpriteLoop(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Loop; +} + +//! Returns if the sprite in the given state is scaled +bool CGUIButton::getSpriteScale(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Scale; +} + +//! called if an event happened. +bool CGUIButton::OnEvent(const SEvent &event) +{ + if (!isEnabled()) + return IGUIElement::OnEvent(event); + + switch (event.EventType) { + case EET_KEY_INPUT_EVENT: + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) { + if (!IsPushButton) + setPressed(true); + else + setPressed(!Pressed); + + return true; + } + if (Pressed && !IsPushButton && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE) { + setPressed(false); + return true; + } else if (!event.KeyInput.PressedDown && Pressed && + (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) { + + if (!IsPushButton) + setPressed(false); + + if (Parent) { + ClickShiftState = event.KeyInput.Shift; + ClickControlState = event.KeyInput.Control; + + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED; + Parent->OnEvent(newEvent); + } + return true; + } + break; + case EET_GUI_EVENT: + if (event.GUIEvent.Caller == this) { + if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { + if (!IsPushButton) + setPressed(false); + FocusTime = os::Timer::getTime(); + } else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) { + FocusTime = os::Timer::getTime(); + } else if (event.GUIEvent.EventType == EGET_ELEMENT_HOVERED || event.GUIEvent.EventType == EGET_ELEMENT_LEFT) { + HoverTime = os::Timer::getTime(); + } + } + break; + case EET_MOUSE_INPUT_EVENT: + if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { + if (!IsPushButton) + setPressed(true); + + return true; + } else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) { + bool wasPressed = Pressed; + + if (!AbsoluteClippingRect.isPointInside(core::position2d(event.MouseInput.X, event.MouseInput.Y))) { + if (!IsPushButton) + setPressed(false); + return true; + } + + if (!IsPushButton) + setPressed(false); + else { + setPressed(!Pressed); + } + + if ((!IsPushButton && wasPressed && Parent) || + (IsPushButton && wasPressed != Pressed)) { + ClickShiftState = event.MouseInput.Shift; + ClickControlState = event.MouseInput.Control; + + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED; + Parent->OnEvent(newEvent); + } + + return true; + } + break; + default: + break; + } + + return Parent ? Parent->OnEvent(event) : false; +} + +//! draws the element and its children +void CGUIButton::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + video::IVideoDriver *driver = Environment->getVideoDriver(); + + if (DrawBorder) { + if (!Pressed) { + skin->draw3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect); + } else { + skin->draw3DButtonPanePressed(this, AbsoluteRect, &AbsoluteClippingRect); + } + } + + const core::position2di buttonCenter(AbsoluteRect.getCenter()); + + EGUI_BUTTON_IMAGE_STATE imageState = getImageState(Pressed); + if (ButtonImages[(u32)imageState].Texture) { + core::position2d pos(buttonCenter); + core::rect sourceRect(ButtonImages[(u32)imageState].SourceRect); + if (sourceRect.getWidth() == 0 && sourceRect.getHeight() == 0) + sourceRect = core::rect(core::position2di(0, 0), ButtonImages[(u32)imageState].Texture->getOriginalSize()); + + pos.X -= sourceRect.getWidth() / 2; + pos.Y -= sourceRect.getHeight() / 2; + + if (Pressed) { + // Create a pressed-down effect by moving the image when it looks identical to the unpressed state image + EGUI_BUTTON_IMAGE_STATE unpressedState = getImageState(false); + if (unpressedState == imageState || ButtonImages[(u32)imageState] == ButtonImages[(u32)unpressedState]) { + pos.X += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X); + pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y); + } + } + + driver->draw2DImage(ButtonImages[(u32)imageState].Texture, + ScaleImage ? AbsoluteRect : core::rect(pos, sourceRect.getSize()), + sourceRect, &AbsoluteClippingRect, + 0, UseAlphaChannel); + } + + if (SpriteBank) { + core::position2di pos(buttonCenter); + if (Pressed) { + pos.X += skin->getSize(EGDS_BUTTON_PRESSED_SPRITE_OFFSET_X); + pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_SPRITE_OFFSET_Y); + } + + if (isEnabled()) { + // pressed / unpressed animation + EGUI_BUTTON_STATE state = Pressed ? EGBS_BUTTON_DOWN : EGBS_BUTTON_UP; + drawSprite(state, ClickTime, pos); + + // focused / unfocused animation + state = Environment->hasFocus(this) ? EGBS_BUTTON_FOCUSED : EGBS_BUTTON_NOT_FOCUSED; + drawSprite(state, FocusTime, pos); + + // mouse over / off animation + state = Environment->getHovered() == this ? EGBS_BUTTON_MOUSE_OVER : EGBS_BUTTON_MOUSE_OFF; + drawSprite(state, HoverTime, pos); + } else { + // draw disabled + drawSprite(EGBS_BUTTON_DISABLED, 0, pos); + } + } + + if (Text.size()) { + IGUIFont *font = getActiveFont(); + + core::rect rect = AbsoluteRect; + if (Pressed) { + rect.UpperLeftCorner.X += skin->getSize(EGDS_BUTTON_PRESSED_TEXT_OFFSET_X); + rect.UpperLeftCorner.Y += skin->getSize(EGDS_BUTTON_PRESSED_TEXT_OFFSET_Y); + } + + if (font) + font->draw(Text.c_str(), rect, + getActiveColor(), + true, true, &AbsoluteClippingRect); + } + + IGUIElement::draw(); +} + +void CGUIButton::drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di ¢er) +{ + u32 stateIdx = (u32)state; + + if (ButtonSprites[stateIdx].Index != -1) { + if (ButtonSprites[stateIdx].Scale) { + const video::SColor colors[] = {ButtonSprites[stateIdx].Color, ButtonSprites[stateIdx].Color, ButtonSprites[stateIdx].Color, ButtonSprites[stateIdx].Color}; + SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, AbsoluteRect, + &AbsoluteClippingRect, colors, + os::Timer::getTime() - startTime, ButtonSprites[stateIdx].Loop); + } else { + SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, center, + &AbsoluteClippingRect, ButtonSprites[stateIdx].Color, startTime, os::Timer::getTime(), + ButtonSprites[stateIdx].Loop, true); + } + } +} + +EGUI_BUTTON_IMAGE_STATE CGUIButton::getImageState(bool pressed) const +{ + // figure state we should have + EGUI_BUTTON_IMAGE_STATE state = EGBIS_IMAGE_DISABLED; + bool focused = Environment->hasFocus(this); + bool mouseOver = static_cast(Environment->getHovered()) == this; // (static cast for Borland) + if (isEnabled()) { + if (pressed) { + if (focused && mouseOver) + state = EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER; + else if (focused) + state = EGBIS_IMAGE_DOWN_FOCUSED; + else if (mouseOver) + state = EGBIS_IMAGE_DOWN_MOUSEOVER; + else + state = EGBIS_IMAGE_DOWN; + } else // !pressed + { + if (focused && mouseOver) + state = EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER; + else if (focused) + state = EGBIS_IMAGE_UP_FOCUSED; + else if (mouseOver) + state = EGBIS_IMAGE_UP_MOUSEOVER; + else + state = EGBIS_IMAGE_UP; + } + } + + // find a compatible state that has images + while (state != EGBIS_IMAGE_UP && !ButtonImages[(u32)state].Texture) { + switch (state) { + case EGBIS_IMAGE_UP_FOCUSED: + state = EGBIS_IMAGE_UP_MOUSEOVER; + break; + case EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER: + state = EGBIS_IMAGE_UP_FOCUSED; + break; + case EGBIS_IMAGE_DOWN_MOUSEOVER: + state = EGBIS_IMAGE_DOWN; + break; + case EGBIS_IMAGE_DOWN_FOCUSED: + state = EGBIS_IMAGE_DOWN_MOUSEOVER; + break; + case EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER: + state = EGBIS_IMAGE_DOWN_FOCUSED; + break; + case EGBIS_IMAGE_DISABLED: + if (pressed) + state = EGBIS_IMAGE_DOWN; + else + state = EGBIS_IMAGE_UP; + break; + default: + state = EGBIS_IMAGE_UP; + } + } + + return state; +} + +//! sets another skin independent font. if this is set to zero, the button uses the font of the skin. +void CGUIButton::setOverrideFont(IGUIFont *font) +{ + if (OverrideFont == font) + return; + + if (OverrideFont) + OverrideFont->drop(); + + OverrideFont = font; + + if (OverrideFont) + OverrideFont->grab(); +} + +//! Gets the override font (if any) +IGUIFont *CGUIButton::getOverrideFont() const +{ + return OverrideFont; +} + +//! Get the font which is used right now for drawing +IGUIFont *CGUIButton::getActiveFont() const +{ + if (OverrideFont) + return OverrideFont; + IGUISkin *skin = Environment->getSkin(); + if (skin) + return skin->getFont(EGDF_BUTTON); + return 0; +} + +//! Sets another color for the text. +void CGUIButton::setOverrideColor(video::SColor color) +{ + OverrideColor = color; + OverrideColorEnabled = true; +} + +video::SColor CGUIButton::getOverrideColor() const +{ + return OverrideColor; +} + +irr::video::SColor CGUIButton::getActiveColor() const +{ + if (OverrideColorEnabled) + return OverrideColor; + IGUISkin *skin = Environment->getSkin(); + if (skin) + return OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT); + return OverrideColor; +} + +void CGUIButton::enableOverrideColor(bool enable) +{ + OverrideColorEnabled = enable; +} + +bool CGUIButton::isOverrideColorEnabled() const +{ + return OverrideColorEnabled; +} + +void CGUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture *image, const core::rect &sourceRect) +{ + if (state >= EGBIS_COUNT) + return; + + if (image) + image->grab(); + + u32 stateIdx = (u32)state; + if (ButtonImages[stateIdx].Texture) + ButtonImages[stateIdx].Texture->drop(); + + ButtonImages[stateIdx].Texture = image; + ButtonImages[stateIdx].SourceRect = sourceRect; +} + +//! Sets if the button should behave like a push button. Which means it +//! can be in two states: Normal or Pressed. With a click on the button, +//! the user can change the state of the button. +void CGUIButton::setIsPushButton(bool isPushButton) +{ + IsPushButton = isPushButton; +} + +//! Returns if the button is currently pressed +bool CGUIButton::isPressed() const +{ + return Pressed; +} + +//! Sets the pressed state of the button if this is a pushbutton +void CGUIButton::setPressed(bool pressed) +{ + if (Pressed != pressed) { + ClickTime = os::Timer::getTime(); + Pressed = pressed; + } +} + +//! Returns whether the button is a push button +bool CGUIButton::isPushButton() const +{ + return IsPushButton; +} + +//! Sets if the alpha channel should be used for drawing images on the button (default is false) +void CGUIButton::setUseAlphaChannel(bool useAlphaChannel) +{ + UseAlphaChannel = useAlphaChannel; +} + +//! Returns if the alpha channel should be used for drawing images on the button +bool CGUIButton::isAlphaChannelUsed() const +{ + return UseAlphaChannel; +} + +bool CGUIButton::isDrawingBorder() const +{ + return DrawBorder; +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIButton.h b/irr/src/CGUIButton.h new file mode 100644 index 000000000..8ff36c9a7 --- /dev/null +++ b/irr/src/CGUIButton.h @@ -0,0 +1,241 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIButton.h" +#include "IGUISpriteBank.h" +#include "ITexture.h" +#include "SColor.h" + +namespace irr +{ +namespace gui +{ + +class CGUIButton : public IGUIButton +{ +public: + //! constructor + CGUIButton(IGUIEnvironment *environment, IGUIElement *parent, + s32 id, core::rect rectangle, bool noclip = false); + + //! destructor + virtual ~CGUIButton(); + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + + //! sets another skin independent font. if this is set to zero, the button uses the font of the skin. + void setOverrideFont(IGUIFont *font = 0) override; + + //! Gets the override font (if any) + IGUIFont *getOverrideFont() const override; + + //! Get the font which is used right now for drawing + IGUIFont *getActiveFont() const override; + + //! Sets another color for the button text. + void setOverrideColor(video::SColor color) override; + + //! Gets the override color + video::SColor getOverrideColor(void) const override; + + //! Gets the currently used text color + video::SColor getActiveColor() const override; + + //! Sets if the button text should use the override color or the color in the gui skin. + void enableOverrideColor(bool enable) override; + + //! Checks if an override color is enabled + bool isOverrideColorEnabled(void) const override; + + //! Sets an image which should be displayed on the button when it is in the given state. + void setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture *image = 0, const core::rect &sourceRect = core::rect(0, 0, 0, 0)) override; + + //! Sets an image which should be displayed on the button when it is in normal state. + void setImage(video::ITexture *image = 0) override + { + setImage(EGBIS_IMAGE_UP, image); + } + + //! Sets an image which should be displayed on the button when it is in normal state. + void setImage(video::ITexture *image, const core::rect &pos) override + { + setImage(EGBIS_IMAGE_UP, image, pos); + } + + //! Sets an image which should be displayed on the button when it is in pressed state. + void setPressedImage(video::ITexture *image = 0) override + { + setImage(EGBIS_IMAGE_DOWN, image); + } + + //! Sets an image which should be displayed on the button when it is in pressed state. + void setPressedImage(video::ITexture *image, const core::rect &pos) override + { + setImage(EGBIS_IMAGE_DOWN, image, pos); + } + + //! Sets the sprite bank used by the button + void setSpriteBank(IGUISpriteBank *bank = 0) override; + + //! Sets the animated sprite for a specific button state + /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite + \param state: State of the button to set the sprite for + \param index: The sprite number from the current sprite bank + \param color: The color of the sprite + */ + virtual void setSprite(EGUI_BUTTON_STATE state, s32 index, + video::SColor color = video::SColor(255, 255, 255, 255), + bool loop = false, bool scale = false) override; + + //! Get the sprite-index for the given state or -1 when no sprite is set + s32 getSpriteIndex(EGUI_BUTTON_STATE state) const override; + + //! Get the sprite color for the given state. Color is only used when a sprite is set. + video::SColor getSpriteColor(EGUI_BUTTON_STATE state) const override; + + //! Returns if the sprite in the given state does loop + bool getSpriteLoop(EGUI_BUTTON_STATE state) const override; + + //! Returns if the sprite in the given state is scaled + bool getSpriteScale(EGUI_BUTTON_STATE state) const override; + + //! Sets if the button should behave like a push button. Which means it + //! can be in two states: Normal or Pressed. With a click on the button, + //! the user can change the state of the button. + void setIsPushButton(bool isPushButton = true) override; + + //! Checks whether the button is a push button + bool isPushButton() const override; + + //! Sets the pressed state of the button if this is a pushbutton + void setPressed(bool pressed = true) override; + + //! Returns if the button is currently pressed + bool isPressed() const override; + + //! Sets if the button should use the skin to draw its border + void setDrawBorder(bool border = true) override; + + //! Checks if the button face and border are being drawn + bool isDrawingBorder() const override; + + //! Sets if the alpha channel should be used for drawing images on the button (default is false) + void setUseAlphaChannel(bool useAlphaChannel = true) override; + + //! Checks if the alpha channel should be used for drawing images on the button + bool isAlphaChannelUsed() const override; + + //! Sets if the button should scale the button images to fit + void setScaleImage(bool scaleImage = true) override; + + //! Checks whether the button scales the used images + bool isScalingImage() const override; + + //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event + bool getClickShiftState() const override + { + return ClickShiftState; + } + + //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event + bool getClickControlState() const override + { + return ClickControlState; + } + +protected: + void drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di ¢er); + EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const; + +private: + struct ButtonSprite + { + ButtonSprite() : + Index(-1), Loop(false), Scale(false) + { + } + + bool operator==(const ButtonSprite &other) const + { + return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale; + } + + s32 Index; + video::SColor Color; + bool Loop; + bool Scale; + }; + + ButtonSprite ButtonSprites[EGBS_COUNT]; + IGUISpriteBank *SpriteBank; + + struct ButtonImage + { + ButtonImage() : + Texture(0), SourceRect(core::rect(0, 0, 0, 0)) + { + } + + ButtonImage(const ButtonImage &other) : + Texture(0), SourceRect(core::rect(0, 0, 0, 0)) + { + *this = other; + } + + ~ButtonImage() + { + if (Texture) + Texture->drop(); + } + + ButtonImage &operator=(const ButtonImage &other) + { + if (this == &other) + return *this; + + if (other.Texture) + other.Texture->grab(); + if (Texture) + Texture->drop(); + Texture = other.Texture; + SourceRect = other.SourceRect; + return *this; + } + + bool operator==(const ButtonImage &other) const + { + return Texture == other.Texture && SourceRect == other.SourceRect; + } + + video::ITexture *Texture; + core::rect SourceRect; + }; + + ButtonImage ButtonImages[EGBIS_COUNT]; + + IGUIFont *OverrideFont; + + bool OverrideColorEnabled; + video::SColor OverrideColor; + + u32 ClickTime, HoverTime, FocusTime; + + bool ClickShiftState; + bool ClickControlState; + + bool IsPushButton; + bool Pressed; + bool UseAlphaChannel; + bool DrawBorder; + bool ScaleImage; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUICheckBox.cpp b/irr/src/CGUICheckBox.cpp new file mode 100644 index 000000000..18dd6856a --- /dev/null +++ b/irr/src/CGUICheckBox.cpp @@ -0,0 +1,198 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUICheckBox.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "IGUIFont.h" +#include "os.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUICheckBox::CGUICheckBox(bool checked, IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect rectangle) : + IGUICheckBox(environment, parent, id, rectangle), CheckTime(0), Pressed(false), Checked(checked), Border(false), Background(false) +{ +#ifdef _DEBUG + setDebugName("CGUICheckBox"); +#endif + + // this element can be tabbed into + setTabStop(true); + setTabOrder(-1); +} + +//! called if an event happened. +bool CGUICheckBox::OnEvent(const SEvent &event) +{ + if (isEnabled()) { + switch (event.EventType) { + case EET_KEY_INPUT_EVENT: + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) { + Pressed = true; + return true; + } else if (Pressed && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE) { + Pressed = false; + return true; + } else if (!event.KeyInput.PressedDown && Pressed && + (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) { + Pressed = false; + if (Parent) { + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + Checked = !Checked; + newEvent.GUIEvent.EventType = EGET_CHECKBOX_CHANGED; + Parent->OnEvent(newEvent); + } + return true; + } + break; + case EET_GUI_EVENT: + if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { + if (event.GUIEvent.Caller == this) + Pressed = false; + } + break; + case EET_MOUSE_INPUT_EVENT: + if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { + Pressed = true; + CheckTime = os::Timer::getTime(); + return true; + } else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) { + bool wasPressed = Pressed; + Pressed = false; + + if (wasPressed && Parent) { + if (!AbsoluteClippingRect.isPointInside(core::position2d(event.MouseInput.X, event.MouseInput.Y))) { + Pressed = false; + return true; + } + + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + Checked = !Checked; + newEvent.GUIEvent.EventType = EGET_CHECKBOX_CHANGED; + Parent->OnEvent(newEvent); + } + + return true; + } + break; + default: + break; + } + } + + return IGUIElement::OnEvent(event); +} + +//! draws the element and its children +void CGUICheckBox::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + if (skin) { + video::IVideoDriver *driver = Environment->getVideoDriver(); + core::rect frameRect(AbsoluteRect); + + // draw background + if (Background) { + video::SColor bgColor = skin->getColor(gui::EGDC_3D_FACE); + driver->draw2DRectangle(bgColor, frameRect, &AbsoluteClippingRect); + } + + // draw the border + if (Border) { + skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect); + frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X); + frameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X); + } + + const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); + + // the rectangle around the "checked" area. + core::rect checkRect(frameRect.UpperLeftCorner.X, + ((frameRect.getHeight() - height) / 2) + frameRect.UpperLeftCorner.Y, + 0, 0); + + checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; + checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; + + EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE; + if (isEnabled()) + col = Pressed ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE; + skin->draw3DSunkenPane(this, skin->getColor(col), + false, true, checkRect, &AbsoluteClippingRect); + + // the checked icon + if (Checked) { + skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), + CheckTime, os::Timer::getTime(), false, &AbsoluteClippingRect); + } + + // associated text + if (Text.size()) { + checkRect = frameRect; + checkRect.UpperLeftCorner.X += height + 5; + + IGUIFont *font = skin->getFont(); + if (font) { + font->draw(Text.c_str(), checkRect, + skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect); + } + } + } + IGUIElement::draw(); +} + +//! set if box is checked +void CGUICheckBox::setChecked(bool checked) +{ + Checked = checked; +} + +//! returns if box is checked +bool CGUICheckBox::isChecked() const +{ + return Checked; +} + +//! Sets whether to draw the background +void CGUICheckBox::setDrawBackground(bool draw) +{ + Background = draw; +} + +//! Checks if background drawing is enabled +bool CGUICheckBox::isDrawBackgroundEnabled() const +{ + return Background; +} + +//! Sets whether to draw the border +void CGUICheckBox::setDrawBorder(bool draw) +{ + Border = draw; +} + +//! Checks if border drawing is enabled +bool CGUICheckBox::isDrawBorderEnabled() const +{ + return Border; +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUICheckBox.h b/irr/src/CGUICheckBox.h new file mode 100644 index 000000000..2c2a98f04 --- /dev/null +++ b/irr/src/CGUICheckBox.h @@ -0,0 +1,55 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUICheckBox.h" + +namespace irr +{ +namespace gui +{ + +class CGUICheckBox : public IGUICheckBox +{ +public: + //! constructor + CGUICheckBox(bool checked, IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect rectangle); + + //! set if box is checked + void setChecked(bool checked) override; + + //! returns if box is checked + bool isChecked() const override; + + //! Sets whether to draw the background + void setDrawBackground(bool draw) override; + + //! Checks if background drawing is enabled + /** \return true if background drawing is enabled, false otherwise */ + bool isDrawBackgroundEnabled() const override; + + //! Sets whether to draw the border + void setDrawBorder(bool draw) override; + + //! Checks if border drawing is enabled + /** \return true if border drawing is enabled, false otherwise */ + bool isDrawBorderEnabled() const override; + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + +private: + u32 CheckTime; + bool Pressed; + bool Checked; + bool Border; + bool Background; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIComboBox.cpp b/irr/src/CGUIComboBox.cpp new file mode 100644 index 000000000..0088641b5 --- /dev/null +++ b/irr/src/CGUIComboBox.cpp @@ -0,0 +1,463 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIComboBox.h" + +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IGUIFont.h" +#include "IGUIButton.h" +#include "CGUIListBox.h" +#include "os.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIComboBox::CGUIComboBox(IGUIEnvironment *environment, IGUIElement *parent, + s32 id, core::rect rectangle) : + IGUIComboBox(environment, parent, id, rectangle), + ListButton(nullptr), SelectedText(nullptr), ListBox(nullptr), LastFocus(nullptr), + Selected(-1), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_CENTER), MaxSelectionRows(5), HasFocus(false), + ActiveFont(nullptr) +{ +#ifdef _DEBUG + setDebugName("CGUIComboBox"); +#endif + + IGUISkin *skin = Environment->getSkin(); + + ListButton = Environment->addButton(core::recti(0, 0, 1, 1), this, -1, L""); + if (skin && skin->getSpriteBank()) { + ListButton->setSpriteBank(skin->getSpriteBank()); + ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL)); + ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL)); + } + ListButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + ListButton->setSubElement(true); + ListButton->setTabStop(false); + + SelectedText = Environment->addStaticText(L"", core::recti(0, 0, 1, 1), false, false, this, -1, false); + SelectedText->setSubElement(true); + SelectedText->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + SelectedText->setTextAlignment(EGUIA_UPPERLEFT, EGUIA_CENTER); + if (skin) + SelectedText->setOverrideColor(skin->getColor(EGDC_BUTTON_TEXT)); + SelectedText->enableOverrideColor(true); + + updateListButtonWidth(skin ? skin->getSize(EGDS_SCROLLBAR_SIZE) : 15); + + // this element can be tabbed to + setTabStop(true); + setTabOrder(-1); +} + +void CGUIComboBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) +{ + HAlign = horizontal; + VAlign = vertical; + SelectedText->setTextAlignment(horizontal, vertical); +} + +//! Set the maximal number of rows for the selection listbox +void CGUIComboBox::setMaxSelectionRows(u32 max) +{ + MaxSelectionRows = max; + + // force recalculation of open listbox + if (ListBox) { + openCloseMenu(); + openCloseMenu(); + } +} + +//! Get the maximal number of rows for the selection listbox +u32 CGUIComboBox::getMaxSelectionRows() const +{ + return MaxSelectionRows; +} + +//! Returns amount of items in box +u32 CGUIComboBox::getItemCount() const +{ + return Items.size(); +} + +//! returns string of an item. the idx may be a value from 0 to itemCount-1 +const wchar_t *CGUIComboBox::getItem(u32 idx) const +{ + if (idx >= Items.size()) + return 0; + + return Items[idx].Name.c_str(); +} + +//! returns string of an item. the idx may be a value from 0 to itemCount-1 +u32 CGUIComboBox::getItemData(u32 idx) const +{ + if (idx >= Items.size()) + return 0; + + return Items[idx].Data; +} + +//! Returns index based on item data +s32 CGUIComboBox::getIndexForItemData(u32 data) const +{ + for (u32 i = 0; i < Items.size(); ++i) { + if (Items[i].Data == data) + return i; + } + return -1; +} + +//! Removes an item from the combo box. +void CGUIComboBox::removeItem(u32 idx) +{ + if (idx >= Items.size()) + return; + + if (Selected == (s32)idx) + setSelected(-1); + + Items.erase(idx); +} + +//! Returns caption of this element. +const wchar_t *CGUIComboBox::getText() const +{ + return getItem(Selected); +} + +//! adds an item and returns the index of it +u32 CGUIComboBox::addItem(const wchar_t *text, u32 data) +{ + Items.push_back(SComboData(text, data)); + + if (Selected == -1) + setSelected(0); + + return Items.size() - 1; +} + +//! deletes all items in the combo box +void CGUIComboBox::clear() +{ + Items.clear(); + setSelected(-1); +} + +//! returns id of selected item. returns -1 if no item is selected. +s32 CGUIComboBox::getSelected() const +{ + return Selected; +} + +//! sets the selected item. Set this to -1 if no item should be selected +void CGUIComboBox::setSelected(s32 idx) +{ + if (idx < -1 || idx >= (s32)Items.size()) + return; + + Selected = idx; + if (Selected == -1) + SelectedText->setText(L""); + else + SelectedText->setText(Items[Selected].Name.c_str()); +} + +//! Sets the selected item and emits a change event. +/** Set this to -1 if no item should be selected */ +void CGUIComboBox::setAndSendSelected(s32 idx) +{ + setSelected(idx); + sendSelectionChangedEvent(); +} + +//! called if an event happened. +bool CGUIComboBox::OnEvent(const SEvent &event) +{ + if (isEnabled()) { + switch (event.EventType) { + + case EET_KEY_INPUT_EVENT: + if (ListBox && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE) { + // hide list box + openCloseMenu(); + return true; + } else if (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE) { + if (!event.KeyInput.PressedDown) { + openCloseMenu(); + } + + ListButton->setPressed(ListBox == nullptr); + + return true; + } else if (event.KeyInput.PressedDown) { + s32 oldSelected = Selected; + bool absorb = true; + switch (event.KeyInput.Key) { + case KEY_DOWN: + setSelected(Selected + 1); + break; + case KEY_UP: + setSelected(Selected - 1); + break; + case KEY_HOME: + case KEY_PRIOR: + setSelected(0); + break; + case KEY_END: + case KEY_NEXT: + setSelected((s32)Items.size() - 1); + break; + default: + absorb = false; + } + + if (Selected < 0) + setSelected(0); + + if (Selected >= (s32)Items.size()) + setSelected((s32)Items.size() - 1); + + if (Selected != oldSelected) { + sendSelectionChangedEvent(); + return true; + } + + if (absorb) + return true; + } + break; + + case EET_GUI_EVENT: + + switch (event.GUIEvent.EventType) { + case EGET_ELEMENT_FOCUS_LOST: + if (ListBox && + (Environment->hasFocus(ListBox) || ListBox->isMyChild(event.GUIEvent.Caller)) && + event.GUIEvent.Element != this && + !isMyChild(event.GUIEvent.Element) && + !ListBox->isMyChild(event.GUIEvent.Element)) { + openCloseMenu(); + } + break; + case EGET_BUTTON_CLICKED: + if (event.GUIEvent.Caller == ListButton) { + openCloseMenu(); + return true; + } + break; + case EGET_LISTBOX_SELECTED_AGAIN: + case EGET_LISTBOX_CHANGED: + if (event.GUIEvent.Caller == ListBox) { + setSelected(ListBox->getSelected()); + if (Selected < 0 || Selected >= (s32)Items.size()) + setSelected(-1); + openCloseMenu(); + + sendSelectionChangedEvent(); + } + return true; + default: + break; + } + break; + case EET_MOUSE_INPUT_EVENT: + + switch (event.MouseInput.Event) { + case EMIE_LMOUSE_PRESSED_DOWN: { + core::position2d p(event.MouseInput.X, event.MouseInput.Y); + + // send to list box + if (ListBox && ListBox->isPointInside(p) && ListBox->OnEvent(event)) + return true; + + return true; + } + case EMIE_LMOUSE_LEFT_UP: { + core::position2d p(event.MouseInput.X, event.MouseInput.Y); + + // send to list box + if (!(ListBox && + ListBox->getAbsolutePosition().isPointInside(p) && + ListBox->OnEvent(event))) { + openCloseMenu(); + } + return true; + } + case EMIE_MOUSE_WHEEL: { + // Try scrolling parent first + if (IGUIElement::OnEvent(event)) + return true; + + s32 oldSelected = Selected; + setSelected(Selected + ((event.MouseInput.Wheel < 0) ? 1 : -1)); + + if (Selected < 0) + setSelected(0); + + if (Selected >= (s32)Items.size()) + setSelected((s32)Items.size() - 1); + + if (Selected != oldSelected) { + sendSelectionChangedEvent(); + return true; + } + + return false; + } + default: + break; + } + break; + default: + break; + } + } + + return IGUIElement::OnEvent(event); +} + +void CGUIComboBox::sendSelectionChangedEvent() +{ + if (Parent) { + SEvent event; + + event.EventType = EET_GUI_EVENT; + event.GUIEvent.Caller = this; + event.GUIEvent.Element = nullptr; + event.GUIEvent.EventType = EGET_COMBO_BOX_CHANGED; + Parent->OnEvent(event); + } +} + +void CGUIComboBox::updateListButtonWidth(s32 width) +{ + if (ListButton->getRelativePosition().getWidth() != width) { + core::rect r; + r.UpperLeftCorner.X = RelativeRect.getWidth() - width - 2; + r.LowerRightCorner.X = RelativeRect.getWidth() - 2; + r.UpperLeftCorner.Y = 2; + r.LowerRightCorner.Y = RelativeRect.getHeight() - 2; + ListButton->setRelativePosition(r); + + r.UpperLeftCorner.X = 2; + r.UpperLeftCorner.Y = 2; + r.LowerRightCorner.X = RelativeRect.getWidth() - (width + 2); + r.LowerRightCorner.Y = RelativeRect.getHeight() - 2; + SelectedText->setRelativePosition(r); + } +} + +//! draws the element and its children +void CGUIComboBox::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + + updateListButtonWidth(skin->getSize(EGDS_SCROLLBAR_SIZE)); + + // font changed while the listbox is open? + if (ActiveFont != skin->getFont() && ListBox) { + // close and re-open to use new font-size + openCloseMenu(); + openCloseMenu(); + } + + IGUIElement *currentFocus = Environment->getFocus(); + if (currentFocus != LastFocus) { + HasFocus = currentFocus == this || isMyChild(currentFocus); + LastFocus = currentFocus; + } + + // set colors each time as skin-colors can be changed + SelectedText->setBackgroundColor(skin->getColor(EGDC_HIGH_LIGHT)); + if (isEnabled()) { + SelectedText->setDrawBackground(HasFocus); + SelectedText->setOverrideColor(skin->getColor(HasFocus ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT)); + } else { + SelectedText->setDrawBackground(false); + SelectedText->setOverrideColor(skin->getColor(EGDC_GRAY_TEXT)); + } + ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL)); + ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL)); + + core::rect frameRect(AbsoluteRect); + + // draw the border + + skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_HIGH_LIGHT), + true, true, frameRect, &AbsoluteClippingRect); + + // draw children + IGUIElement::draw(); +} + +void CGUIComboBox::openCloseMenu() +{ + if (ListBox) { + // close list box + Environment->setFocus(this); + ListBox->remove(); + ListBox = nullptr; + } else { + if (Parent) { + SEvent event; + event.EventType = EET_GUI_EVENT; + event.GUIEvent.Caller = this; + event.GUIEvent.Element = nullptr; + event.GUIEvent.EventType = EGET_LISTBOX_OPENED; + + // Allow to prevent the listbox from opening. + if (Parent->OnEvent(event)) + return; + + Parent->bringToFront(this); + } + + IGUISkin *skin = Environment->getSkin(); + u32 h = Items.size(); + + if (h > getMaxSelectionRows()) + h = getMaxSelectionRows(); + if (h == 0) + h = 1; + + ActiveFont = skin->getFont(); + if (ActiveFont) + h *= (ActiveFont->getDimension(L"A").Height + 4); + + // open list box + core::rect r(0, AbsoluteRect.getHeight(), + AbsoluteRect.getWidth(), AbsoluteRect.getHeight() + h); + + ListBox = new CGUIListBox(Environment, this, -1, r, false, true, true); + ListBox->setSubElement(true); + ListBox->setNotClipped(true); + ListBox->drop(); + + // ensure that list box is always completely visible + if (ListBox->getAbsolutePosition().LowerRightCorner.Y > Environment->getRootGUIElement()->getAbsolutePosition().getHeight()) + ListBox->setRelativePosition(core::rect(0, -ListBox->getAbsolutePosition().getHeight(), AbsoluteRect.getWidth(), 0)); + + for (s32 i = 0; i < (s32)Items.size(); ++i) + ListBox->addItem(Items[i].Name.c_str()); + + ListBox->setSelected(Selected); + + // set focus + Environment->setFocus(ListBox); + } +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIComboBox.h b/irr/src/CGUIComboBox.h new file mode 100644 index 000000000..77f1eca1a --- /dev/null +++ b/irr/src/CGUIComboBox.h @@ -0,0 +1,104 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIComboBox.h" +#include "IGUIStaticText.h" +#include "irrString.h" +#include "irrArray.h" + +namespace irr +{ +namespace gui +{ +class IGUIButton; +class IGUIListBox; + +//! Single line edit box for editing simple text. +class CGUIComboBox : public IGUIComboBox +{ +public: + //! constructor + CGUIComboBox(IGUIEnvironment *environment, IGUIElement *parent, + s32 id, core::rect rectangle); + + //! Returns amount of items in box + u32 getItemCount() const override; + + //! returns string of an item. the idx may be a value from 0 to itemCount-1 + const wchar_t *getItem(u32 idx) const override; + + //! Returns item data of an item. the idx may be a value from 0 to itemCount-1 + u32 getItemData(u32 idx) const override; + + //! Returns index based on item data + s32 getIndexForItemData(u32 data) const override; + + //! adds an item and returns the index of it + u32 addItem(const wchar_t *text, u32 data) override; + + //! Removes an item from the combo box. + void removeItem(u32 id) override; + + //! deletes all items in the combo box + void clear() override; + + //! returns the text of the currently selected item + const wchar_t *getText() const override; + + //! returns id of selected item. returns -1 if no item is selected. + s32 getSelected() const override; + + //! sets the selected item. Set this to -1 if no item should be selected + void setSelected(s32 idx) override; + + //! Sets the selected item and emits a change event. + /** Set this to -1 if no item should be selected */ + void setAndSendSelected(s32 idx) override; + + //! sets the text alignment of the text part + void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override; + + //! Set the maximal number of rows for the selection listbox + void setMaxSelectionRows(u32 max) override; + + //! Get the maximal number of rows for the selection listbox + u32 getMaxSelectionRows() const override; + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + +private: + void openCloseMenu(); + void sendSelectionChangedEvent(); + void updateListButtonWidth(s32 width); + + IGUIButton *ListButton; + IGUIStaticText *SelectedText; + IGUIListBox *ListBox; + IGUIElement *LastFocus; + + struct SComboData + { + SComboData(const wchar_t *text, u32 data) : + Name(text), Data(data) {} + + core::stringw Name; + u32 Data; + }; + core::array Items; + + s32 Selected; + EGUI_ALIGNMENT HAlign, VAlign; + u32 MaxSelectionRows; + bool HasFocus; + IGUIFont *ActiveFont; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIEditBox.cpp b/irr/src/CGUIEditBox.cpp new file mode 100644 index 000000000..8d03caf4a --- /dev/null +++ b/irr/src/CGUIEditBox.cpp @@ -0,0 +1,1495 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIEditBox.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IGUIFont.h" +#include "IVideoDriver.h" +#include "rect.h" +#include "os.h" +#include "Keycodes.h" + +/* + todo: + optional scrollbars + ctrl+left/right to select word + double click/ctrl click: word select + drag to select whole words, triple click to select line + optional? dragging selected text + numerical +*/ + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIEditBox::CGUIEditBox(const wchar_t *text, bool border, + IGUIEnvironment *environment, IGUIElement *parent, s32 id, + const core::rect &rectangle) : + IGUIEditBox(environment, parent, id, rectangle), + OverwriteMode(false), MouseMarking(false), + Border(border), Background(true), OverrideColorEnabled(false), MarkBegin(0), MarkEnd(0), + OverrideColor(video::SColor(101, 255, 255, 255)), OverrideFont(0), LastBreakFont(0), + Operator(0), BlinkStartTime(0), CursorBlinkTime(350), CursorChar(L"_"), CursorPos(0), HScrollPos(0), VScrollPos(0), Max(0), + WordWrap(false), MultiLine(false), AutoScroll(true), PasswordBox(false), + PasswordChar(L'*'), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_CENTER), + CurrentTextRect(0, 0, 1, 1), FrameRect(rectangle) +{ +#ifdef _DEBUG + setDebugName("CGUIEditBox"); +#endif + + Text = text; + + if (Environment) + Operator = Environment->getOSOperator(); + + if (Operator) + Operator->grab(); + + // this element can be tabbed to + setTabStop(true); + setTabOrder(-1); + + calculateFrameRect(); + breakText(); + + calculateScrollPos(); +} + +//! destructor +CGUIEditBox::~CGUIEditBox() +{ + if (OverrideFont) + OverrideFont->drop(); + + if (Operator) + Operator->drop(); +} + +//! Sets another skin independent font. +void CGUIEditBox::setOverrideFont(IGUIFont *font) +{ + if (OverrideFont == font) + return; + + if (OverrideFont) + OverrideFont->drop(); + + OverrideFont = font; + + if (OverrideFont) + OverrideFont->grab(); + + breakText(); +} + +//! Gets the override font (if any) +IGUIFont *CGUIEditBox::getOverrideFont() const +{ + return OverrideFont; +} + +//! Get the font which is used right now for drawing +IGUIFont *CGUIEditBox::getActiveFont() const +{ + if (OverrideFont) + return OverrideFont; + IGUISkin *skin = Environment->getSkin(); + if (skin) + return skin->getFont(); + return 0; +} + +//! Sets another color for the text. +void CGUIEditBox::setOverrideColor(video::SColor color) +{ + OverrideColor = color; + OverrideColorEnabled = true; +} + +video::SColor CGUIEditBox::getOverrideColor() const +{ + return OverrideColor; +} + +//! Turns the border on or off +void CGUIEditBox::setDrawBorder(bool border) +{ + Border = border; +} + +//! Checks if border drawing is enabled +bool CGUIEditBox::isDrawBorderEnabled() const +{ + return Border; +} + +//! Sets whether to draw the background +void CGUIEditBox::setDrawBackground(bool draw) +{ + Background = draw; +} + +//! Checks if background drawing is enabled +bool CGUIEditBox::isDrawBackgroundEnabled() const +{ + return Background; +} + +//! Sets if the text should use the override color or the color in the gui skin. +void CGUIEditBox::enableOverrideColor(bool enable) +{ + OverrideColorEnabled = enable; +} + +bool CGUIEditBox::isOverrideColorEnabled() const +{ + return OverrideColorEnabled; +} + +//! Enables or disables word wrap +void CGUIEditBox::setWordWrap(bool enable) +{ + WordWrap = enable; + breakText(); +} + +void CGUIEditBox::updateAbsolutePosition() +{ + core::rect oldAbsoluteRect(AbsoluteRect); + IGUIElement::updateAbsolutePosition(); + if (oldAbsoluteRect != AbsoluteRect) { + calculateFrameRect(); + breakText(); + calculateScrollPos(); + } +} + +//! Checks if word wrap is enabled +bool CGUIEditBox::isWordWrapEnabled() const +{ + return WordWrap; +} + +//! Enables or disables newlines. +void CGUIEditBox::setMultiLine(bool enable) +{ + MultiLine = enable; + breakText(); +} + +//! Checks if multi line editing is enabled +bool CGUIEditBox::isMultiLineEnabled() const +{ + return MultiLine; +} + +void CGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar) +{ + PasswordBox = passwordBox; + if (PasswordBox) { + PasswordChar = passwordChar; + setMultiLine(false); + setWordWrap(false); + BrokenText.clear(); + } +} + +bool CGUIEditBox::isPasswordBox() const +{ + return PasswordBox; +} + +//! Sets text justification +void CGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) +{ + HAlign = horizontal; + VAlign = vertical; +} + +//! called if an event happened. +bool CGUIEditBox::OnEvent(const SEvent &event) +{ + if (isEnabled()) { + + switch (event.EventType) { + case EET_GUI_EVENT: + if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { + if (event.GUIEvent.Caller == this) { + MouseMarking = false; + setTextMarkers(0, 0); + } + } + break; + case EET_KEY_INPUT_EVENT: + if (processKey(event)) + return true; + break; + case EET_MOUSE_INPUT_EVENT: + if (processMouse(event)) + return true; + break; + case EET_STRING_INPUT_EVENT: + inputString(*event.StringInput.Str); + return true; + break; + default: + break; + } + } + + return IGUIElement::OnEvent(event); +} + +bool CGUIEditBox::processKey(const SEvent &event) +{ + if (!event.KeyInput.PressedDown) + return false; + + bool textChanged = false; + s32 newMarkBegin = MarkBegin; + s32 newMarkEnd = MarkEnd; + + // control shortcut handling + + if (event.KeyInput.Control) { + // german backlash '\' entered with control + '?' + if (event.KeyInput.Char == '\\') { + inputChar(event.KeyInput.Char); + return true; + } + + switch (event.KeyInput.Key) { + case KEY_KEY_A: + // select all + newMarkBegin = 0; + newMarkEnd = Text.size(); + break; + case KEY_KEY_C: + // copy to clipboard + if (!PasswordBox && Operator && MarkBegin != MarkEnd) { + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + core::stringc s; + wStringToUTF8(s, Text.subString(realmbgn, realmend - realmbgn)); + Operator->copyToClipboard(s.c_str()); + } + break; + case KEY_KEY_X: + // cut to the clipboard + if (!PasswordBox && Operator && MarkBegin != MarkEnd) { + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + // copy + core::stringc sc; + wStringToUTF8(sc, Text.subString(realmbgn, realmend - realmbgn)); + Operator->copyToClipboard(sc.c_str()); + + if (isEnabled()) { + // delete + core::stringw s; + s = Text.subString(0, realmbgn); + s.append(Text.subString(realmend, Text.size() - realmend)); + Text = s; + + CursorPos = realmbgn; + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } + } + break; + case KEY_KEY_V: + if (!isEnabled()) + break; + + // paste from the clipboard + if (Operator) { + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + // add the string + const c8 *p = Operator->getTextFromClipboard(); + if (p) { + irr::core::stringw widep; + core::utf8ToWString(widep, p); + + if (MarkBegin == MarkEnd) { + // insert text + core::stringw s = Text.subString(0, CursorPos); + s.append(widep); + s.append(Text.subString(CursorPos, Text.size() - CursorPos)); + + if (!Max || s.size() <= Max) { // thx to Fish FH for fix + Text = s; + s = widep; + CursorPos += s.size(); + } + } else { + // replace text + + core::stringw s = Text.subString(0, realmbgn); + s.append(widep); + s.append(Text.subString(realmend, Text.size() - realmend)); + + if (!Max || s.size() <= Max) { // thx to Fish FH for fix + Text = s; + s = widep; + CursorPos = realmbgn + s.size(); + } + } + } + + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } + break; + case KEY_HOME: + // move/highlight to start of text + if (event.KeyInput.Shift) { + newMarkEnd = CursorPos; + newMarkBegin = 0; + CursorPos = 0; + } else { + CursorPos = 0; + newMarkBegin = 0; + newMarkEnd = 0; + } + break; + case KEY_END: + // move/highlight to end of text + if (event.KeyInput.Shift) { + newMarkBegin = CursorPos; + newMarkEnd = Text.size(); + CursorPos = 0; + } else { + CursorPos = Text.size(); + newMarkBegin = 0; + newMarkEnd = 0; + } + break; + default: + return false; + } + } + // Some special keys - but only handle them if KeyInput.Char is null as on some systems (X11) they might have same key-code as ansi-keys otherwise + else if (event.KeyInput.Char == 0) { + switch (event.KeyInput.Key) { + case KEY_END: { + s32 p = Text.size(); + if (WordWrap || MultiLine) { + p = getLineFromPos(CursorPos); + p = BrokenTextPositions[p] + (s32)BrokenText[p].size(); + if (p > 0 && (Text[p - 1] == L'\r' || Text[p - 1] == L'\n')) + p -= 1; + } + + if (event.KeyInput.Shift) { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; + + newMarkEnd = p; + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } + CursorPos = p; + BlinkStartTime = os::Timer::getTime(); + } break; + case KEY_HOME: { + + s32 p = 0; + if (WordWrap || MultiLine) { + p = getLineFromPos(CursorPos); + p = BrokenTextPositions[p]; + } + + if (event.KeyInput.Shift) { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; + newMarkEnd = p; + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } + CursorPos = p; + BlinkStartTime = os::Timer::getTime(); + } break; + case KEY_LEFT: + + if (event.KeyInput.Shift) { + if (CursorPos > 0) { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; + + newMarkEnd = CursorPos - 1; + } + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } + + if (CursorPos > 0) + CursorPos--; + BlinkStartTime = os::Timer::getTime(); + break; + + case KEY_RIGHT: + if (event.KeyInput.Shift) { + if (Text.size() > (u32)CursorPos) { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; + + newMarkEnd = CursorPos + 1; + } + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } + + if (Text.size() > (u32)CursorPos) + CursorPos++; + BlinkStartTime = os::Timer::getTime(); + break; + case KEY_UP: + if (MultiLine || (WordWrap && BrokenText.size() > 1)) { + s32 lineNo = getLineFromPos(CursorPos); + s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd); + if (lineNo > 0) { + s32 cp = CursorPos - BrokenTextPositions[lineNo]; + if ((s32)BrokenText[lineNo - 1].size() < cp) + CursorPos = BrokenTextPositions[lineNo - 1] + core::max_((u32)1, BrokenText[lineNo - 1].size()) - 1; + else + CursorPos = BrokenTextPositions[lineNo - 1] + cp; + } + + if (event.KeyInput.Shift) { + newMarkBegin = mb; + newMarkEnd = CursorPos; + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } + + } else { + return false; + } + break; + case KEY_DOWN: + if (MultiLine || (WordWrap && BrokenText.size() > 1)) { + s32 lineNo = getLineFromPos(CursorPos); + s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd); + if (lineNo < (s32)BrokenText.size() - 1) { + s32 cp = CursorPos - BrokenTextPositions[lineNo]; + if ((s32)BrokenText[lineNo + 1].size() < cp) + CursorPos = BrokenTextPositions[lineNo + 1] + core::max_((u32)1, BrokenText[lineNo + 1].size()) - 1; + else + CursorPos = BrokenTextPositions[lineNo + 1] + cp; + } + + if (event.KeyInput.Shift) { + newMarkBegin = mb; + newMarkEnd = CursorPos; + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } + + } else { + return false; + } + break; + case KEY_INSERT: + if (!isEnabled()) + break; + + OverwriteMode = !OverwriteMode; + break; + case KEY_DELETE: + if (!isEnabled()) + break; + + if (keyDelete()) { + BlinkStartTime = os::Timer::getTime(); + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } + break; + default: + return false; + } + } else { + // default keyboard handling + switch (event.KeyInput.Key) { + case KEY_RETURN: + if (MultiLine) { + inputChar(L'\n'); + } else { + calculateScrollPos(); + sendGuiEvent(EGET_EDITBOX_ENTER); + } + return true; + + case KEY_BACK: + if (!isEnabled()) + break; + + if (Text.size()) { + core::stringw s; + + if (MarkBegin != MarkEnd) { + // delete marked text + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + s = Text.subString(0, realmbgn); + s.append(Text.subString(realmend, Text.size() - realmend)); + Text = s; + + CursorPos = realmbgn; + } else { + // delete text behind cursor + if (CursorPos > 0) + s = Text.subString(0, CursorPos - 1); + else + s = L""; + s.append(Text.subString(CursorPos, Text.size() - CursorPos)); + Text = s; + --CursorPos; + } + + if (CursorPos < 0) + CursorPos = 0; + BlinkStartTime = os::Timer::getTime(); + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } + break; + + case KEY_DELETE: + + // At least on X11 we get a char with 127 when the delete key is pressed. + // We get no char when the delete key on numkeys is pressed with numlock off (handled in the other case calling keyDelete as Char is then 0). + // We get a keykode != 127 when delete key on numlock is pressed with numlock on. + if (event.KeyInput.Char == 127) { + if (!isEnabled()) + break; + + if (keyDelete()) { + BlinkStartTime = os::Timer::getTime(); + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } + break; + } else { + inputChar(event.KeyInput.Char); + return true; + } + + case KEY_ESCAPE: + case KEY_TAB: + case KEY_SHIFT: + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + case KEY_F11: + case KEY_F12: + case KEY_F13: + case KEY_F14: + case KEY_F15: + case KEY_F16: + case KEY_F17: + case KEY_F18: + case KEY_F19: + case KEY_F20: + case KEY_F21: + case KEY_F22: + case KEY_F23: + case KEY_F24: + // ignore these keys + return false; + + default: + inputChar(event.KeyInput.Char); + return true; + } + } + + // Set new text markers + setTextMarkers(newMarkBegin, newMarkEnd); + + // break the text if it has changed + if (textChanged) { + breakText(); + calculateScrollPos(); + sendGuiEvent(EGET_EDITBOX_CHANGED); + } else { + calculateScrollPos(); + } + + return true; +} + +bool CGUIEditBox::keyDelete() +{ + if (Text.size() != 0) { + core::stringw s; + + if (MarkBegin != MarkEnd) { + // delete marked text + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + s = Text.subString(0, realmbgn); + s.append(Text.subString(realmend, Text.size() - realmend)); + Text = s; + + CursorPos = realmbgn; + } else { + // delete text before cursor + s = Text.subString(0, CursorPos); + s.append(Text.subString(CursorPos + 1, Text.size() - CursorPos - 1)); + Text = s; + } + + if (CursorPos > (s32)Text.size()) + CursorPos = (s32)Text.size(); + + return true; + } + + return false; +} + +//! draws the element and its children +void CGUIEditBox::draw() +{ + if (!IsVisible) + return; + + const bool focus = Environment->hasFocus(this); + + IGUISkin *skin = Environment->getSkin(); + if (!skin) + return; + + EGUI_DEFAULT_COLOR bgCol = EGDC_GRAY_EDITABLE; + if (isEnabled()) + bgCol = focus ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE; + + if (!Border && Background) { + skin->draw2DRectangle(this, skin->getColor(bgCol), AbsoluteRect, &AbsoluteClippingRect); + } + + if (Border) { + // draw the border + skin->draw3DSunkenPane(this, skin->getColor(bgCol), false, Background, AbsoluteRect, &AbsoluteClippingRect); + + calculateFrameRect(); + } + + core::rect localClipRect = FrameRect; + localClipRect.clipAgainst(AbsoluteClippingRect); + + // draw the text + + IGUIFont *font = getActiveFont(); + + s32 cursorLine = 0; + s32 charcursorpos = 0; + + if (font) { + if (LastBreakFont != font) { + breakText(); + } + + // calculate cursor pos + + core::stringw *txtLine = &Text; + s32 startPos = 0; + + core::stringw s, s2; + + // get mark position + const bool ml = (!PasswordBox && (WordWrap || MultiLine)); + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0; + const s32 hlineCount = ml ? getLineFromPos(realmend) - hlineStart + 1 : 1; + const s32 lineCount = ml ? BrokenText.size() : 1; + + // Save the override color information. + // Then, alter it if the edit box is disabled. + const bool prevOver = OverrideColorEnabled; + const video::SColor prevColor = OverrideColor; + + if (Text.size()) { + if (!isEnabled() && !OverrideColorEnabled) { + OverrideColorEnabled = true; + OverrideColor = skin->getColor(EGDC_GRAY_TEXT); + } + + for (s32 i = 0; i < lineCount; ++i) { + setTextRect(i); + + // clipping test - don't draw anything outside the visible area + core::rect c = localClipRect; + c.clipAgainst(CurrentTextRect); + if (!c.isValid()) + continue; + + // get current line + if (PasswordBox) { + if (BrokenText.size() != 1) { + BrokenText.clear(); + BrokenText.push_back(core::stringw()); + } + if (BrokenText[0].size() != Text.size()) { + BrokenText[0] = Text; + for (u32 q = 0; q < Text.size(); ++q) { + BrokenText[0][q] = PasswordChar; + } + } + txtLine = &BrokenText[0]; + startPos = 0; + } else { + txtLine = ml ? &BrokenText[i] : &Text; + startPos = ml ? BrokenTextPositions[i] : 0; + } + + // draw normal text + font->draw(txtLine->c_str(), CurrentTextRect, + OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &localClipRect); + + // draw mark and marked text + if (focus && MarkBegin != MarkEnd && i >= hlineStart && i < hlineStart + hlineCount) { + + s32 mbegin = 0, mend = 0; + s32 lineStartPos = 0, lineEndPos = txtLine->size(); + + if (i == hlineStart) { + // highlight start is on this line + s = txtLine->subString(0, realmbgn - startPos); + mbegin = font->getDimension(s.c_str()).Width; + + // deal with kerning + mbegin += font->getKerningWidth( + &((*txtLine)[realmbgn - startPos]), + realmbgn - startPos > 0 ? &((*txtLine)[realmbgn - startPos - 1]) : 0); + + lineStartPos = realmbgn - startPos; + } + if (i == hlineStart + hlineCount - 1) { + // highlight end is on this line + s2 = txtLine->subString(0, realmend - startPos); + mend = font->getDimension(s2.c_str()).Width; + lineEndPos = (s32)s2.size(); + } else + mend = font->getDimension(txtLine->c_str()).Width; + + CurrentTextRect.UpperLeftCorner.X += mbegin; + CurrentTextRect.LowerRightCorner.X = CurrentTextRect.UpperLeftCorner.X + mend - mbegin; + + // draw mark + skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), CurrentTextRect, &localClipRect); + + // draw marked text + s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos); + + if (s.size()) + font->draw(s.c_str(), CurrentTextRect, + OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT), + false, true, &localClipRect); + } + } + + // Return the override color information to its previous settings. + OverrideColorEnabled = prevOver; + OverrideColor = prevColor; + } + + // draw cursor + if (isEnabled()) { + if (WordWrap || MultiLine) { + cursorLine = getLineFromPos(CursorPos); + txtLine = &BrokenText[cursorLine]; + startPos = BrokenTextPositions[cursorLine]; + } + s = txtLine->subString(0, CursorPos - startPos); + charcursorpos = font->getDimension(s.c_str()).Width + + font->getKerningWidth(CursorChar.c_str(), CursorPos - startPos > 0 ? &((*txtLine)[CursorPos - startPos - 1]) : 0); + + if (focus && (CursorBlinkTime == 0 || (os::Timer::getTime() - BlinkStartTime) % (2 * CursorBlinkTime) < CursorBlinkTime)) { + setTextRect(cursorLine); + CurrentTextRect.UpperLeftCorner.X += charcursorpos; + + if (OverwriteMode) { + core::stringw character = Text.subString(CursorPos, 1); + s32 mend = font->getDimension(character.c_str()).Width; + // Make sure the cursor box has at least some width to it + if (mend <= 0) + mend = font->getDimension(CursorChar.c_str()).Width; + CurrentTextRect.LowerRightCorner.X = CurrentTextRect.UpperLeftCorner.X + mend; + skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), CurrentTextRect, &localClipRect); + font->draw(character.c_str(), CurrentTextRect, + OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT), + false, true, &localClipRect); + } else { + font->draw(CursorChar, CurrentTextRect, + OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &localClipRect); + } + } + } + } + + // draw children + IGUIElement::draw(); +} + +//! Sets the new caption of this element. +void CGUIEditBox::setText(const wchar_t *text) +{ + Text = text; + if (u32(CursorPos) > Text.size()) + CursorPos = Text.size(); + HScrollPos = 0; + breakText(); +} + +//! Enables or disables automatic scrolling with cursor position +//! \param enable: If set to true, the text will move around with the cursor position +void CGUIEditBox::setAutoScroll(bool enable) +{ + AutoScroll = enable; +} + +//! Checks to see if automatic scrolling is enabled +//! \return true if automatic scrolling is enabled, false if not +bool CGUIEditBox::isAutoScrollEnabled() const +{ + return AutoScroll; +} + +//! Gets the area of the text in the edit box +//! \return Returns the size in pixels of the text +core::dimension2du CGUIEditBox::getTextDimension() +{ + core::rect ret; + + setTextRect(0); + ret = CurrentTextRect; + + for (u32 i = 1; i < BrokenText.size(); ++i) { + setTextRect(i); + ret.addInternalPoint(CurrentTextRect.UpperLeftCorner); + ret.addInternalPoint(CurrentTextRect.LowerRightCorner); + } + + return core::dimension2du(ret.getSize()); +} + +//! Sets the maximum amount of characters which may be entered in the box. +//! \param max: Maximum amount of characters. If 0, the character amount is +//! infinity. +void CGUIEditBox::setMax(u32 max) +{ + Max = max; + + if (Text.size() > Max && Max != 0) + Text = Text.subString(0, Max); +} + +//! Returns maximum amount of characters, previously set by setMax(); +u32 CGUIEditBox::getMax() const +{ + return Max; +} + +//! Set the character used for the cursor. +/** By default it's "_" */ +void CGUIEditBox::setCursorChar(const wchar_t cursorChar) +{ + CursorChar[0] = cursorChar; +} + +//! Get the character used for the cursor. +wchar_t CGUIEditBox::getCursorChar() const +{ + return CursorChar[0]; +} + +//! Set the blinktime for the cursor. 2x blinktime is one full cycle. +void CGUIEditBox::setCursorBlinkTime(irr::u32 timeMs) +{ + CursorBlinkTime = timeMs; +} + +//! Get the cursor blinktime +irr::u32 CGUIEditBox::getCursorBlinkTime() const +{ + return CursorBlinkTime; +} + +bool CGUIEditBox::processMouse(const SEvent &event) +{ + switch (event.MouseInput.Event) { + case irr::EMIE_LMOUSE_LEFT_UP: + if (Environment->hasFocus(this)) { + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + if (MouseMarking) { + setTextMarkers(MarkBegin, CursorPos); + } + MouseMarking = false; + calculateScrollPos(); + return true; + } + break; + case irr::EMIE_MOUSE_MOVED: { + if (MouseMarking) { + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + setTextMarkers(MarkBegin, CursorPos); + calculateScrollPos(); + return true; + } + } break; + case EMIE_LMOUSE_PRESSED_DOWN: + if (!Environment->hasFocus(this)) { // can happen when events are manually send to the element + BlinkStartTime = os::Timer::getTime(); + MouseMarking = true; + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + setTextMarkers(CursorPos, CursorPos); + calculateScrollPos(); + return true; + } else { + if (!AbsoluteClippingRect.isPointInside( + core::position2d(event.MouseInput.X, event.MouseInput.Y))) { + return false; + } else { + // move cursor + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + + s32 newMarkBegin = MarkBegin; + if (!MouseMarking) + newMarkBegin = CursorPos; + + MouseMarking = true; + setTextMarkers(newMarkBegin, CursorPos); + calculateScrollPos(); + return true; + } + } + case EMIE_MMOUSE_PRESSED_DOWN: { + if (!AbsoluteClippingRect.isPointInside(core::position2d( + event.MouseInput.X, event.MouseInput.Y))) + return false; + + if (!Environment->hasFocus(this)) { + BlinkStartTime = os::Timer::getTime(); + } + + // move cursor and disable marking + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + MouseMarking = false; + setTextMarkers(CursorPos, CursorPos); + + // paste from the primary selection + inputString([&] { + irr::core::stringw inserted_text; + if (!Operator) + return inserted_text; + const c8 *inserted_text_utf8 = Operator->getTextFromPrimarySelection(); + if (!inserted_text_utf8) + return inserted_text; + core::utf8ToWString(inserted_text, inserted_text_utf8); + return inserted_text; + }()); + + return true; + } + default: + break; + } + + return false; +} + +s32 CGUIEditBox::getCursorPos(s32 x, s32 y) +{ + IGUIFont *font = getActiveFont(); + + const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; + + core::stringw *txtLine = 0; + s32 startPos = 0; + x += 3; + + for (u32 i = 0; i < lineCount; ++i) { + setTextRect(i); + if (i == 0 && y < CurrentTextRect.UpperLeftCorner.Y) + y = CurrentTextRect.UpperLeftCorner.Y; + if (i == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y) + y = CurrentTextRect.LowerRightCorner.Y; + + // is it inside this region? + if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y) { + // we've found the clicked line + txtLine = (WordWrap || MultiLine) ? &BrokenText[i] : &Text; + startPos = (WordWrap || MultiLine) ? BrokenTextPositions[i] : 0; + break; + } + } + + if (x < CurrentTextRect.UpperLeftCorner.X) + x = CurrentTextRect.UpperLeftCorner.X; + + if (!txtLine) + return 0; + + s32 idx = font->getCharacterFromPos(txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X); + + // click was on or left of the line + if (idx != -1) + return idx + startPos; + + // click was off the right edge of the line, go to end. + return txtLine->size() + startPos; +} + +//! Breaks the single text line. +void CGUIEditBox::breakText() +{ + if ((!WordWrap && !MultiLine)) + return; + + BrokenText.clear(); // need to reallocate :/ + BrokenTextPositions.set_used(0); + + IGUIFont *font = getActiveFont(); + if (!font) + return; + + LastBreakFont = font; + + core::stringw line; + core::stringw word; + core::stringw whitespace; + s32 lastLineStart = 0; + s32 size = Text.size(); + s32 length = 0; + s32 elWidth = RelativeRect.getWidth() - 6; + wchar_t c; + + for (s32 i = 0; i < size; ++i) { + c = Text[i]; + bool lineBreak = false; + + if (c == L'\r') { // Mac or Windows breaks + lineBreak = true; + c = 0; + if (Text[i + 1] == L'\n') { // Windows breaks + // TODO: I (Michael) think that we shouldn't change the text given by the user for whatever reason. + // Instead rework the cursor positioning to be able to handle this (but not in stable release + // branch as users might already expect this behavior). + Text.erase(i + 1); + --size; + if (CursorPos > i) + --CursorPos; + } + } else if (c == L'\n') { // Unix breaks + lineBreak = true; + c = 0; + } + + // don't break if we're not a multi-line edit box + if (!MultiLine) + lineBreak = false; + + if (c == L' ' || c == 0 || i == (size - 1)) { + // here comes the next whitespace, look if + // we can break the last word to the next line + // We also break whitespace, otherwise cursor would vanish beside the right border. + s32 whitelgth = font->getDimension(whitespace.c_str()).Width; + s32 worldlgth = font->getDimension(word.c_str()).Width; + + if (WordWrap && length + worldlgth + whitelgth > elWidth && line.size() > 0) { + // break to next line + length = worldlgth; + BrokenText.push_back(line); + BrokenTextPositions.push_back(lastLineStart); + lastLineStart = i - (s32)word.size(); + line = word; + } else { + // add word to line + line += whitespace; + line += word; + length += whitelgth + worldlgth; + } + + word = L""; + whitespace = L""; + + if (c) + whitespace += c; + + // compute line break + if (lineBreak) { + line += whitespace; + line += word; + BrokenText.push_back(line); + BrokenTextPositions.push_back(lastLineStart); + lastLineStart = i + 1; + line = L""; + word = L""; + whitespace = L""; + length = 0; + } + } else { + // yippee this is a word.. + word += c; + } + } + + line += whitespace; + line += word; + BrokenText.push_back(line); + BrokenTextPositions.push_back(lastLineStart); +} + +// TODO: that function does interpret VAlign according to line-index (indexed line is placed on top-center-bottom) +// but HAlign according to line-width (pixels) and not by row. +// Intuitively I suppose HAlign handling is better as VScrollPos should handle the line-scrolling. +// But please no one change this without also rewriting (and this time fucking testing!!!) autoscrolling (I noticed this when fixing the old autoscrolling). +void CGUIEditBox::setTextRect(s32 line) +{ + if (line < 0) + return; + + IGUIFont *font = getActiveFont(); + if (!font) + return; + + core::dimension2du d; + + // get text dimension + const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; + if (WordWrap || MultiLine) { + d = font->getDimension(BrokenText[line].c_str()); + } else { + d = font->getDimension(Text.c_str()); + d.Height = AbsoluteRect.getHeight(); + } + d.Height += font->getKerningHeight(); + + // justification + switch (HAlign) { + case EGUIA_CENTER: + // align to h centre + CurrentTextRect.UpperLeftCorner.X = (FrameRect.getWidth() / 2) - (d.Width / 2); + CurrentTextRect.LowerRightCorner.X = (FrameRect.getWidth() / 2) + (d.Width / 2); + break; + case EGUIA_LOWERRIGHT: + // align to right edge + CurrentTextRect.UpperLeftCorner.X = FrameRect.getWidth() - d.Width; + CurrentTextRect.LowerRightCorner.X = FrameRect.getWidth(); + break; + default: + // align to left edge + CurrentTextRect.UpperLeftCorner.X = 0; + CurrentTextRect.LowerRightCorner.X = d.Width; + } + + switch (VAlign) { + case EGUIA_CENTER: + // align to v centre + CurrentTextRect.UpperLeftCorner.Y = + (FrameRect.getHeight() / 2) - (lineCount * d.Height) / 2 + d.Height * line; + break; + case EGUIA_LOWERRIGHT: + // align to bottom edge + CurrentTextRect.UpperLeftCorner.Y = + FrameRect.getHeight() - lineCount * d.Height + d.Height * line; + break; + default: + // align to top edge + CurrentTextRect.UpperLeftCorner.Y = d.Height * line; + break; + } + + CurrentTextRect.UpperLeftCorner.X -= HScrollPos; + CurrentTextRect.LowerRightCorner.X -= HScrollPos; + CurrentTextRect.UpperLeftCorner.Y -= VScrollPos; + CurrentTextRect.LowerRightCorner.Y = CurrentTextRect.UpperLeftCorner.Y + d.Height; + + CurrentTextRect += FrameRect.UpperLeftCorner; +} + +s32 CGUIEditBox::getLineFromPos(s32 pos) +{ + if (!WordWrap && !MultiLine) + return 0; + + s32 i = 0; + while (i < (s32)BrokenTextPositions.size()) { + if (BrokenTextPositions[i] > pos) + return i - 1; + ++i; + } + return (s32)BrokenTextPositions.size() - 1; +} + +void CGUIEditBox::inputChar(wchar_t c) +{ + if (c == 0) + return; + core::stringw s(&c, 1); + inputString(s); +} + +void CGUIEditBox::inputString(const core::stringw &str) +{ + if (!isEnabled()) + return; + + core::stringw s; + u32 len = str.size(); + + if (MarkBegin != MarkEnd) { + // replace marked text + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + s = Text.subString(0, realmbgn); + s.append(str); + s.append(Text.subString(realmend, Text.size() - realmend)); + Text = s; + CursorPos = realmbgn + len; + } else if (OverwriteMode) { + // check to see if we are at the end of the text + if ((u32)CursorPos + len < Text.size()) { + bool isEOL = false; + s32 EOLPos; + for (u32 i = CursorPos; i < CursorPos + len && i < Max; i++) { + if (Text[i] == L'\n' || Text[i] == L'\r') { + isEOL = true; + EOLPos = i; + break; + } + } + if (!isEOL || Text.size() + len <= Max || Max == 0) { + s = Text.subString(0, CursorPos); + s.append(str); + if (isEOL) { + // just keep appending to the current line + // This follows the behavior of other gui libraries behaviors + s.append(Text.subString(EOLPos, Text.size() - EOLPos)); + } else { + // replace the next character + s.append(Text.subString(CursorPos + len, Text.size() - CursorPos - len)); + } + Text = s; + CursorPos += len; + } + } else if (Text.size() + len <= Max || Max == 0) { + // add new character because we are at the end of the string + s = Text.subString(0, CursorPos); + s.append(str); + s.append(Text.subString(CursorPos + len, Text.size() - CursorPos - len)); + Text = s; + CursorPos += len; + } + } else if (Text.size() + len <= Max || Max == 0) { + // add new character + s = Text.subString(0, CursorPos); + s.append(str); + s.append(Text.subString(CursorPos, Text.size() - CursorPos)); + Text = s; + CursorPos += len; + } + + BlinkStartTime = os::Timer::getTime(); + setTextMarkers(0, 0); + + breakText(); + calculateScrollPos(); + sendGuiEvent(EGET_EDITBOX_CHANGED); +} + +// calculate autoscroll +void CGUIEditBox::calculateScrollPos() +{ + if (!AutoScroll) + return; + + IGUIFont *font = getActiveFont(); + if (!font) + return; + + s32 cursLine = getLineFromPos(CursorPos); + if (cursLine < 0) + return; + setTextRect(cursLine); + const bool hasBrokenText = MultiLine || WordWrap; + + // Check horizonal scrolling + // NOTE: Calculations different to vertical scrolling because setTextRect interprets VAlign relative to line but HAlign not relative to row + { + // get cursor position + // get cursor area + irr::u32 cursorWidth = font->getDimension(CursorChar.c_str()).Width; + core::stringw *txtLine = hasBrokenText ? &BrokenText[cursLine] : &Text; + s32 cPos = hasBrokenText ? CursorPos - BrokenTextPositions[cursLine] : CursorPos; // column + s32 cStart = font->getDimension(txtLine->subString(0, cPos).c_str()).Width; // pixels from text-start + s32 cEnd = cStart + cursorWidth; + s32 txtWidth = font->getDimension(txtLine->c_str()).Width; + + if (txtWidth < FrameRect.getWidth()) { + // TODO: Needs a clean left and right gap removal depending on HAlign, similar to vertical scrolling tests for top/bottom. + // This check just fixes the case where it was most noticable (text smaller than clipping area). + + HScrollPos = 0; + setTextRect(cursLine); + } + + if (CurrentTextRect.UpperLeftCorner.X + cStart < FrameRect.UpperLeftCorner.X) { + // cursor to the left of the clipping area + HScrollPos -= FrameRect.UpperLeftCorner.X - (CurrentTextRect.UpperLeftCorner.X + cStart); + setTextRect(cursLine); + + // TODO: should show more characters to the left when we're scrolling left + // and the cursor reaches the border. + } else if (CurrentTextRect.UpperLeftCorner.X + cEnd > FrameRect.LowerRightCorner.X) { + // cursor to the right of the clipping area + HScrollPos += (CurrentTextRect.UpperLeftCorner.X + cEnd) - FrameRect.LowerRightCorner.X; + setTextRect(cursLine); + } + } + + // calculate vertical scrolling + if (hasBrokenText) { + irr::u32 lineHeight = font->getDimension(L"A").Height + font->getKerningHeight(); + // only up to 1 line fits? + if (lineHeight >= (irr::u32)FrameRect.getHeight()) { + VScrollPos = 0; + setTextRect(cursLine); + s32 unscrolledPos = CurrentTextRect.UpperLeftCorner.Y; + s32 pivot = FrameRect.UpperLeftCorner.Y; + switch (VAlign) { + case EGUIA_CENTER: + pivot += FrameRect.getHeight() / 2; + unscrolledPos += lineHeight / 2; + break; + case EGUIA_LOWERRIGHT: + pivot += FrameRect.getHeight(); + unscrolledPos += lineHeight; + break; + default: + break; + } + VScrollPos = unscrolledPos - pivot; + setTextRect(cursLine); + } else { + // First 2 checks are necessary when people delete lines + setTextRect(0); + if (CurrentTextRect.UpperLeftCorner.Y > FrameRect.UpperLeftCorner.Y && VAlign != EGUIA_LOWERRIGHT) { + // first line is leaving a gap on top + VScrollPos = 0; + } else if (VAlign != EGUIA_UPPERLEFT) { + u32 lastLine = BrokenTextPositions.empty() ? 0 : BrokenTextPositions.size() - 1; + setTextRect(lastLine); + if (CurrentTextRect.LowerRightCorner.Y < FrameRect.LowerRightCorner.Y) { + // last line is leaving a gap on bottom + VScrollPos -= FrameRect.LowerRightCorner.Y - CurrentTextRect.LowerRightCorner.Y; + } + } + + setTextRect(cursLine); + if (CurrentTextRect.UpperLeftCorner.Y < FrameRect.UpperLeftCorner.Y) { + // text above valid area + VScrollPos -= FrameRect.UpperLeftCorner.Y - CurrentTextRect.UpperLeftCorner.Y; + setTextRect(cursLine); + } else if (CurrentTextRect.LowerRightCorner.Y > FrameRect.LowerRightCorner.Y) { + // text below valid area + VScrollPos += CurrentTextRect.LowerRightCorner.Y - FrameRect.LowerRightCorner.Y; + setTextRect(cursLine); + } + } + } +} + +void CGUIEditBox::calculateFrameRect() +{ + FrameRect = AbsoluteRect; + IGUISkin *skin = 0; + if (Environment) + skin = Environment->getSkin(); + if (Border && skin) { + FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; + FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; + FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; + FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; + } +} + +//! set text markers +void CGUIEditBox::setTextMarkers(s32 begin, s32 end) +{ + if (begin != MarkBegin || end != MarkEnd) { + MarkBegin = begin; + MarkEnd = end; + + if (!PasswordBox && Operator && MarkBegin != MarkEnd) { + // copy to primary selection + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + core::stringc s; + wStringToUTF8(s, Text.subString(realmbgn, realmend - realmbgn)); + Operator->copyToPrimarySelection(s.c_str()); + } + + sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); + } +} + +//! send some gui event to parent +void CGUIEditBox::sendGuiEvent(EGUI_EVENT_TYPE type) +{ + if (Parent) { + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = this; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = type; + + Parent->OnEvent(e); + } +} + +//! Returns whether the element takes input from the IME +bool CGUIEditBox::acceptsIME() +{ + return isEnabled(); +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIEditBox.h b/irr/src/CGUIEditBox.h new file mode 100644 index 000000000..35ab5f73e --- /dev/null +++ b/irr/src/CGUIEditBox.h @@ -0,0 +1,196 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIEditBox.h" +#include "irrArray.h" +#include "IOSOperator.h" + +namespace irr +{ +namespace gui +{ +class CGUIEditBox : public IGUIEditBox +{ +public: + //! constructor + CGUIEditBox(const wchar_t *text, bool border, IGUIEnvironment *environment, + IGUIElement *parent, s32 id, const core::rect &rectangle); + + //! destructor + virtual ~CGUIEditBox(); + + //! Sets another skin independent font. + void setOverrideFont(IGUIFont *font = 0) override; + + //! Gets the override font (if any) + /** \return The override font (may be 0) */ + IGUIFont *getOverrideFont() const override; + + //! Get the font which is used right now for drawing + /** Currently this is the override font when one is set and the + font of the active skin otherwise */ + IGUIFont *getActiveFont() const override; + + //! Sets another color for the text. + void setOverrideColor(video::SColor color) override; + + //! Gets the override color + video::SColor getOverrideColor() const override; + + //! Sets if the text should use the override color or the + //! color in the gui skin. + void enableOverrideColor(bool enable) override; + + //! Checks if an override color is enabled + /** \return true if the override color is enabled, false otherwise */ + bool isOverrideColorEnabled(void) const override; + + //! Sets whether to draw the background + void setDrawBackground(bool draw) override; + + //! Checks if background drawing is enabled + bool isDrawBackgroundEnabled() const override; + + //! Turns the border on or off + void setDrawBorder(bool border) override; + + //! Checks if border drawing is enabled + bool isDrawBorderEnabled() const override; + + //! Enables or disables word wrap for using the edit box as multiline text editor. + void setWordWrap(bool enable) override; + + //! Checks if word wrap is enabled + //! \return true if word wrap is enabled, false otherwise + bool isWordWrapEnabled() const override; + + //! Enables or disables newlines. + /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired, + instead a newline character will be inserted. */ + void setMultiLine(bool enable) override; + + //! Checks if multi line editing is enabled + //! \return true if mult-line is enabled, false otherwise + bool isMultiLineEnabled() const override; + + //! Enables or disables automatic scrolling with cursor position + //! \param enable: If set to true, the text will move around with the cursor position + void setAutoScroll(bool enable) override; + + //! Checks to see if automatic scrolling is enabled + //! \return true if automatic scrolling is enabled, false if not + bool isAutoScrollEnabled() const override; + + //! Gets the size area of the text in the edit box + //! \return Returns the size in pixels of the text + core::dimension2du getTextDimension() override; + + //! Sets text justification + void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override; + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + + //! Sets the new caption of this element. + void setText(const wchar_t *text) override; + + //! Sets the maximum amount of characters which may be entered in the box. + //! \param max: Maximum amount of characters. If 0, the character amount is + //! infinity. + void setMax(u32 max) override; + + //! Returns maximum amount of characters, previously set by setMax(); + u32 getMax() const override; + + //! Set the character used for the cursor. + /** By default it's "_" */ + void setCursorChar(const wchar_t cursorChar) override; + + //! Get the character used for the cursor. + wchar_t getCursorChar() const override; + + //! Set the blinktime for the cursor. 2x blinktime is one full cycle. + //** \param timeMs Blinktime in milliseconds. When set to 0 the cursor is constantly on without blinking */ + void setCursorBlinkTime(irr::u32 timeMs) override; + + //! Get the cursor blinktime + irr::u32 getCursorBlinkTime() const override; + + //! Sets whether the edit box is a password box. Setting this to true will + /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x + \param passwordBox: true to enable password, false to disable + \param passwordChar: the character that is displayed instead of letters */ + void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*') override; + + //! Returns true if the edit box is currently a password box. + bool isPasswordBox() const override; + + //! Updates the absolute position, splits text if required + void updateAbsolutePosition() override; + + //! Returns whether the element takes input from the IME + bool acceptsIME() override; + +protected: + //! Breaks the single text line. + void breakText(); + //! sets the area of the given line + void setTextRect(s32 line); + //! returns the line number that the cursor is on + s32 getLineFromPos(s32 pos); + //! adds a letter to the edit box + void inputChar(wchar_t c); + //! adds a string to the edit box + void inputString(const core::stringw &str); + //! calculates the current scroll position + void calculateScrollPos(); + //! calculated the FrameRect + void calculateFrameRect(); + //! send some gui event to parent + void sendGuiEvent(EGUI_EVENT_TYPE type); + //! set text markers + void setTextMarkers(s32 begin, s32 end); + //! delete current selection or next char + bool keyDelete(); + + bool processKey(const SEvent &event); + bool processMouse(const SEvent &event); + s32 getCursorPos(s32 x, s32 y); + + bool OverwriteMode; + bool MouseMarking; + bool Border; + bool Background; + bool OverrideColorEnabled; + s32 MarkBegin; + s32 MarkEnd; + + video::SColor OverrideColor; + gui::IGUIFont *OverrideFont, *LastBreakFont; + IOSOperator *Operator; + + u32 BlinkStartTime; + irr::u32 CursorBlinkTime; + core::stringw CursorChar; // IGUIFont::draw needs stringw instead of wchar_t + s32 CursorPos; + s32 HScrollPos, VScrollPos; // scroll position in characters + u32 Max; + + bool WordWrap, MultiLine, AutoScroll, PasswordBox; + wchar_t PasswordChar; + EGUI_ALIGNMENT HAlign, VAlign; + + core::array BrokenText; + core::array BrokenTextPositions; + + core::rect CurrentTextRect, FrameRect; // temporary values +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIEnvironment.cpp b/irr/src/CGUIEnvironment.cpp new file mode 100644 index 000000000..80115ab11 --- /dev/null +++ b/irr/src/CGUIEnvironment.cpp @@ -0,0 +1,999 @@ + +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIEnvironment.h" + +#include "IVideoDriver.h" + +#include "CGUISkin.h" +#include "CGUIButton.h" +#include "CGUIScrollBar.h" +#include "CGUIFont.h" +#include "CGUISpriteBank.h" +#include "CGUIImage.h" +#include "CGUICheckBox.h" +#include "CGUIListBox.h" +#include "CGUIImageList.h" +#include "CGUIFileOpenDialog.h" +#include "CGUIStaticText.h" +#include "CGUIEditBox.h" +#include "CGUITabControl.h" +#include "CGUIComboBox.h" + +#include "IWriteFile.h" +#ifdef IRR_ENABLE_BUILTIN_FONT +#include "BuiltInFont.h" +#endif +#include "os.h" + +namespace irr +{ +namespace gui +{ + +const io::path CGUIEnvironment::DefaultFontName = "#DefaultFont"; + +//! constructor +CGUIEnvironment::CGUIEnvironment(io::IFileSystem *fs, video::IVideoDriver *driver, IOSOperator *op) : + IGUIElement(EGUIET_ROOT, 0, 0, 0, core::rect(driver ? core::dimension2d(driver->getScreenSize()) : core::dimension2d(0, 0))), + Driver(driver), Hovered(0), HoveredNoSubelement(0), Focus(0), LastHoveredMousePos(0, 0), CurrentSkin(0), + FileSystem(fs), UserReceiver(0), Operator(op), FocusFlags(EFF_SET_ON_LMOUSE_DOWN | EFF_SET_ON_TAB) +{ + if (Driver) + Driver->grab(); + + if (FileSystem) + FileSystem->grab(); + + if (Operator) + Operator->grab(); + +#ifdef _DEBUG + IGUIEnvironment::setDebugName("CGUIEnvironment"); +#endif + + loadBuiltInFont(); + + IGUISkin *skin = createSkin(gui::EGST_WINDOWS_METALLIC); + setSkin(skin); + skin->drop(); + + // set tooltip default + ToolTip.LastTime = 0; + ToolTip.EnterTime = 0; + ToolTip.LaunchTime = 1000; + ToolTip.RelaunchTime = 500; + ToolTip.Element = 0; + + // environment is root tab group + Environment = this; + setTabGroup(true); +} + +//! destructor +CGUIEnvironment::~CGUIEnvironment() +{ + clearDeletionQueue(); + + if (HoveredNoSubelement && HoveredNoSubelement != this) { + HoveredNoSubelement->drop(); + HoveredNoSubelement = 0; + } + + if (Hovered && Hovered != this) { + Hovered->drop(); + Hovered = 0; + } + + if (Focus) { + Focus->drop(); + Focus = 0; + } + + if (ToolTip.Element) { + ToolTip.Element->drop(); + ToolTip.Element = 0; + } + + // drop skin + if (CurrentSkin) { + CurrentSkin->drop(); + CurrentSkin = 0; + } + + u32 i; + + // delete all sprite banks + for (i = 0; i < Banks.size(); ++i) + if (Banks[i].Bank) + Banks[i].Bank->drop(); + + // delete all fonts + for (i = 0; i < Fonts.size(); ++i) + Fonts[i].Font->drop(); + + if (Operator) { + Operator->drop(); + Operator = 0; + } + + if (FileSystem) { + FileSystem->drop(); + FileSystem = 0; + } + + if (Driver) { + Driver->drop(); + Driver = 0; + } +} + +void CGUIEnvironment::loadBuiltInFont() +{ +#ifdef IRR_ENABLE_BUILTIN_FONT + io::IReadFile *file = FileSystem->createMemoryReadFile(BuiltInFontData, + BuiltInFontDataSize, DefaultFontName, false); + + CGUIFont *font = new CGUIFont(this, DefaultFontName); + if (!font->load(file)) { + os::Printer::log("Error: Could not load built-in Font.", ELL_ERROR); + font->drop(); + file->drop(); + return; + } + + SFont f; + f.NamedPath.setPath(DefaultFontName); + f.Font = font; + Fonts.push_back(f); + + file->drop(); +#endif +} + +//! draws all gui elements +void CGUIEnvironment::drawAll(bool useScreenSize) +{ + if (useScreenSize && Driver) { + core::dimension2d dim(Driver->getScreenSize()); + if (AbsoluteRect.LowerRightCorner.X != dim.Width || + AbsoluteRect.UpperLeftCorner.X != 0 || + AbsoluteRect.LowerRightCorner.Y != dim.Height || + AbsoluteRect.UpperLeftCorner.Y != 0) { + setRelativePosition(core::recti(0, 0, dim.Width, dim.Height)); + } + } + + // make sure tooltip is always on top + if (ToolTip.Element) + bringToFront(ToolTip.Element); + + draw(); + OnPostRender(os::Timer::getTime()); + + clearDeletionQueue(); +} + +//! sets the focus to an element +bool CGUIEnvironment::setFocus(IGUIElement *element) +{ + if (Focus == element) { + return false; + } + + // GUI Environment should just reset the focus to 0 + if (element == this) + element = 0; + + // stop element from being deleted + if (element) + element->grab(); + + // focus may change or be removed in this call + IGUIElement *currentFocus = 0; + if (Focus) { + currentFocus = Focus; + currentFocus->grab(); + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = Focus; + e.GUIEvent.Element = element; + e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST; + if (Focus->OnEvent(e)) { + if (element) + element->drop(); + currentFocus->drop(); + return false; + } + currentFocus->drop(); + currentFocus = 0; + } + + if (element) { + currentFocus = Focus; + if (currentFocus) + currentFocus->grab(); + + // send focused event + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = element; + e.GUIEvent.Element = Focus; + e.GUIEvent.EventType = EGET_ELEMENT_FOCUSED; + if (element->OnEvent(e)) { + if (element) + element->drop(); + if (currentFocus) + currentFocus->drop(); + return false; + } + } + + if (currentFocus) + currentFocus->drop(); + + if (Focus) + Focus->drop(); + + // element is the new focus so it doesn't have to be dropped + Focus = element; + + return true; +} + +//! returns the element with the focus +IGUIElement *CGUIEnvironment::getFocus() const +{ + return Focus; +} + +//! returns the element last known to be under the mouse cursor +IGUIElement *CGUIEnvironment::getHovered() const +{ + return Hovered; +} + +//! removes the focus from an element +bool CGUIEnvironment::removeFocus(IGUIElement *element) +{ + if (Focus && Focus == element) { + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = Focus; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST; + if (Focus->OnEvent(e)) { + return false; + } + } + if (Focus) { + Focus->drop(); + Focus = 0; + } + + return true; +} + +//! Returns whether the element has focus +bool CGUIEnvironment::hasFocus(const IGUIElement *element, bool checkSubElements) const +{ + if (element == Focus) + return true; + + if (!checkSubElements || !element) + return false; + + IGUIElement *f = Focus; + while (f && f->isSubElement()) { + f = f->getParent(); + if (f == element) + return true; + } + return false; +} + +//! returns the current video driver +video::IVideoDriver *CGUIEnvironment::getVideoDriver() const +{ + return Driver; +} + +//! returns the current file system +io::IFileSystem *CGUIEnvironment::getFileSystem() const +{ + return FileSystem; +} + +//! returns a pointer to the OS operator +IOSOperator *CGUIEnvironment::getOSOperator() const +{ + return Operator; +} + +//! clear all GUI elements +void CGUIEnvironment::clear() +{ + // Remove the focus + if (Focus) { + Focus->drop(); + Focus = 0; + } + + if (Hovered && Hovered != this) { + Hovered->drop(); + Hovered = 0; + } + if (HoveredNoSubelement && HoveredNoSubelement != this) { + HoveredNoSubelement->drop(); + HoveredNoSubelement = 0; + } + + getRootGUIElement()->removeAllChildren(); +} + +//! called by ui if an event happened. +bool CGUIEnvironment::OnEvent(const SEvent &event) +{ + + bool ret = false; + if (UserReceiver && (event.EventType != EET_MOUSE_INPUT_EVENT) && (event.EventType != EET_KEY_INPUT_EVENT) && (event.EventType != EET_GUI_EVENT || event.GUIEvent.Caller != this)) { + ret = UserReceiver->OnEvent(event); + } + + return ret; +} + +// +void CGUIEnvironment::OnPostRender(u32 time) +{ + // launch tooltip + if (ToolTip.Element == 0 && + HoveredNoSubelement && HoveredNoSubelement != this && + (time - ToolTip.EnterTime >= ToolTip.LaunchTime || (time - ToolTip.LastTime >= ToolTip.RelaunchTime && time - ToolTip.LastTime < ToolTip.LaunchTime)) && + HoveredNoSubelement->getToolTipText().size() && + getSkin() && + getSkin()->getFont(EGDF_TOOLTIP)) { + core::rect pos; + + pos.UpperLeftCorner = LastHoveredMousePos; + core::dimension2du dim = getSkin()->getFont(EGDF_TOOLTIP)->getDimension(HoveredNoSubelement->getToolTipText().c_str()); + dim.Width += getSkin()->getSize(EGDS_TEXT_DISTANCE_X) * 2; + dim.Height += getSkin()->getSize(EGDS_TEXT_DISTANCE_Y) * 2; + + pos.UpperLeftCorner.Y -= dim.Height + 1; + pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + dim.Height - 1; + pos.LowerRightCorner.X = pos.UpperLeftCorner.X + dim.Width; + + pos.constrainTo(getAbsolutePosition()); + + ToolTip.Element = addStaticText(HoveredNoSubelement->getToolTipText().c_str(), pos, true, true, this, -1, true); + ToolTip.Element->setOverrideColor(getSkin()->getColor(EGDC_TOOLTIP)); + ToolTip.Element->setBackgroundColor(getSkin()->getColor(EGDC_TOOLTIP_BACKGROUND)); + ToolTip.Element->setOverrideFont(getSkin()->getFont(EGDF_TOOLTIP)); + ToolTip.Element->setSubElement(true); + ToolTip.Element->grab(); + + s32 textHeight = ToolTip.Element->getTextHeight(); + pos = ToolTip.Element->getRelativePosition(); + pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + textHeight; + ToolTip.Element->setRelativePosition(pos); + } + + if (ToolTip.Element && ToolTip.Element->isVisible()) { // (isVisible() check only because we might use visibility for ToolTip one day) + ToolTip.LastTime = time; + + // got invisible or removed in the meantime? + if (!HoveredNoSubelement || + !HoveredNoSubelement->isVisible() || + !HoveredNoSubelement->getParent()) // got invisible or removed in the meantime? + { + ToolTip.Element->remove(); + ToolTip.Element->drop(); + ToolTip.Element = 0; + } + } + + IGUIElement::OnPostRender(time); +} + +void CGUIEnvironment::addToDeletionQueue(IGUIElement *element) +{ + if (!element) + return; + + element->grab(); + DeletionQueue.push_back(element); +} + +void CGUIEnvironment::clearDeletionQueue() +{ + if (DeletionQueue.empty()) + return; + + for (u32 i = 0; i < DeletionQueue.size(); ++i) { + DeletionQueue[i]->remove(); + DeletionQueue[i]->drop(); + } + + DeletionQueue.clear(); +} + +// +void CGUIEnvironment::updateHoveredElement(core::position2d mousePos) +{ + IGUIElement *lastHovered = Hovered; + IGUIElement *lastHoveredNoSubelement = HoveredNoSubelement; + LastHoveredMousePos = mousePos; + + Hovered = getElementFromPoint(mousePos); + + if (ToolTip.Element && Hovered == ToolTip.Element) { + // When the mouse is over the ToolTip we remove that so it will be re-created at a new position. + // Note that ToolTip.EnterTime does not get changed here, so it will be re-created at once. + ToolTip.Element->remove(); + ToolTip.Element->drop(); + ToolTip.Element = 0; + + // Get the real Hovered + Hovered = getElementFromPoint(mousePos); + } + + // for tooltips we want the element itself and not some of it's subelements + HoveredNoSubelement = Hovered; + while (HoveredNoSubelement && HoveredNoSubelement->isSubElement()) { + HoveredNoSubelement = HoveredNoSubelement->getParent(); + } + + if (Hovered && Hovered != this) + Hovered->grab(); + if (HoveredNoSubelement && HoveredNoSubelement != this) + HoveredNoSubelement->grab(); + + if (Hovered != lastHovered) { + SEvent event; + event.EventType = EET_GUI_EVENT; + + if (lastHovered) { + event.GUIEvent.Caller = lastHovered; + event.GUIEvent.Element = 0; + event.GUIEvent.EventType = EGET_ELEMENT_LEFT; + lastHovered->OnEvent(event); + } + + if (Hovered) { + event.GUIEvent.Caller = Hovered; + event.GUIEvent.Element = Hovered; + event.GUIEvent.EventType = EGET_ELEMENT_HOVERED; + Hovered->OnEvent(event); + } + } + + if (lastHoveredNoSubelement != HoveredNoSubelement) { + if (ToolTip.Element) { + ToolTip.Element->remove(); + ToolTip.Element->drop(); + ToolTip.Element = 0; + } + + if (HoveredNoSubelement) { + u32 now = os::Timer::getTime(); + ToolTip.EnterTime = now; + } + } + + if (lastHovered && lastHovered != this) + lastHovered->drop(); + if (lastHoveredNoSubelement && lastHoveredNoSubelement != this) + lastHoveredNoSubelement->drop(); +} + +//! This sets a new event receiver for gui events. Usually you do not have to +//! use this method, it is used by the internal engine. +void CGUIEnvironment::setUserEventReceiver(IEventReceiver *evr) +{ + UserReceiver = evr; +} + +//! posts an input event to the environment +bool CGUIEnvironment::postEventFromUser(const SEvent &event) +{ + switch (event.EventType) { + case EET_GUI_EVENT: { + // hey, why is the user sending gui events..? + } + + break; + case EET_MOUSE_INPUT_EVENT: + + updateHoveredElement(core::position2d(event.MouseInput.X, event.MouseInput.Y)); + + if (Hovered != Focus) { + IGUIElement *focusCandidate = Hovered; + + // Only allow enabled elements to be focused (unless EFF_CAN_FOCUS_DISABLED is set) + if (Hovered && !Hovered->isEnabled() && !(FocusFlags & EFF_CAN_FOCUS_DISABLED)) + focusCandidate = NULL; // we still remove focus from the active element + + // Please don't merge this into a single if clause, it's easier to debug the way it is + if (FocusFlags & EFF_SET_ON_LMOUSE_DOWN && + event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { + setFocus(focusCandidate); + } else if (FocusFlags & EFF_SET_ON_RMOUSE_DOWN && + event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) { + setFocus(focusCandidate); + } else if (FocusFlags & EFF_SET_ON_MOUSE_OVER && + event.MouseInput.Event == EMIE_MOUSE_MOVED) { + setFocus(focusCandidate); + } + } + + // sending input to focus + if (Focus && Focus->OnEvent(event)) + return true; + + // focus could have died in last call + if (!Focus && Hovered) { + return Hovered->OnEvent(event); + } + + break; + case EET_KEY_INPUT_EVENT: { + if (Focus && Focus->OnEvent(event)) + return true; + + // For keys we handle the event before changing focus to give elements the chance for catching the TAB + // Send focus changing event + // CAREFUL when changing - there's an identical check in CGUIModalScreen::OnEvent + if (FocusFlags & EFF_SET_ON_TAB && + event.KeyInput.PressedDown && + event.KeyInput.Key == KEY_TAB) { + IGUIElement *next = getNextElement(event.KeyInput.Shift, event.KeyInput.Control); + if (next && next != Focus) { + if (setFocus(next)) + return true; + } + } + } break; + case EET_STRING_INPUT_EVENT: + if (Focus && Focus->OnEvent(event)) + return true; + break; + default: + break; + } // end switch + + return false; +} + +//! returns the current gui skin +IGUISkin *CGUIEnvironment::getSkin() const +{ + return CurrentSkin; +} + +//! Sets a new GUI Skin +void CGUIEnvironment::setSkin(IGUISkin *skin) +{ + if (CurrentSkin == skin) + return; + + if (CurrentSkin) + CurrentSkin->drop(); + + CurrentSkin = skin; + + if (CurrentSkin) + CurrentSkin->grab(); +} + +//! Creates a new GUI Skin based on a template. +/** \return Returns a pointer to the created skin. +If you no longer need the skin, you should call IGUISkin::drop(). +See IReferenceCounted::drop() for more information. */ +IGUISkin *CGUIEnvironment::createSkin(EGUI_SKIN_TYPE type) +{ + IGUISkin *skin = new CGUISkin(type, Driver); + + IGUIFont *builtinfont = getBuiltInFont(); + IGUIFontBitmap *bitfont = 0; + if (builtinfont && builtinfont->getType() == EGFT_BITMAP) + bitfont = (IGUIFontBitmap *)builtinfont; + + IGUISpriteBank *bank = 0; + skin->setFont(builtinfont); + + if (bitfont) + bank = bitfont->getSpriteBank(); + + skin->setSpriteBank(bank); + + return skin; +} + +//! adds a button. The returned pointer must not be dropped. +IGUIButton *CGUIEnvironment::addButton(const core::rect &rectangle, IGUIElement *parent, s32 id, const wchar_t *text, const wchar_t *tooltiptext) +{ + IGUIButton *button = new CGUIButton(this, parent ? parent : this, id, rectangle); + if (text) + button->setText(text); + + if (tooltiptext) + button->setToolTipText(tooltiptext); + + button->drop(); + return button; +} + +//! adds a scrollbar. The returned pointer must not be dropped. +IGUIScrollBar *CGUIEnvironment::addScrollBar(bool horizontal, const core::rect &rectangle, IGUIElement *parent, s32 id) +{ + IGUIScrollBar *bar = new CGUIScrollBar(horizontal, this, parent ? parent : this, id, rectangle); + bar->drop(); + return bar; +} + +//! Adds an image element. +IGUIImage *CGUIEnvironment::addImage(video::ITexture *image, core::position2d pos, + bool useAlphaChannel, IGUIElement *parent, s32 id, const wchar_t *text) +{ + core::dimension2d sz(0, 0); + if (image) + sz = core::dimension2d(image->getOriginalSize()); + + IGUIImage *img = new CGUIImage(this, parent ? parent : this, + id, core::rect(pos, sz)); + + if (text) + img->setText(text); + + if (useAlphaChannel) + img->setUseAlphaChannel(true); + + if (image) + img->setImage(image); + + img->drop(); + return img; +} + +//! adds an image. The returned pointer must not be dropped. +IGUIImage *CGUIEnvironment::addImage(const core::rect &rectangle, IGUIElement *parent, s32 id, const wchar_t *text, bool useAlphaChannel) +{ + IGUIImage *img = new CGUIImage(this, parent ? parent : this, + id, rectangle); + + if (text) + img->setText(text); + + if (useAlphaChannel) + img->setUseAlphaChannel(true); + + img->drop(); + return img; +} + +//! adds a checkbox +IGUICheckBox *CGUIEnvironment::addCheckBox(bool checked, const core::rect &rectangle, IGUIElement *parent, s32 id, const wchar_t *text) +{ + IGUICheckBox *b = new CGUICheckBox(checked, this, + parent ? parent : this, id, rectangle); + + if (text) + b->setText(text); + + b->drop(); + return b; +} + +//! adds a list box +IGUIListBox *CGUIEnvironment::addListBox(const core::rect &rectangle, + IGUIElement *parent, s32 id, bool drawBackground) +{ + IGUIListBox *b = new CGUIListBox(this, parent ? parent : this, id, rectangle, + true, drawBackground, false); + + if (CurrentSkin && CurrentSkin->getSpriteBank()) { + b->setSpriteBank(CurrentSkin->getSpriteBank()); + } else if (getBuiltInFont() && getBuiltInFont()->getType() == EGFT_BITMAP) { + b->setSpriteBank(((IGUIFontBitmap *)getBuiltInFont())->getSpriteBank()); + } + + b->drop(); + return b; +} + +//! adds a file open dialog. The returned pointer must not be dropped. +IGUIFileOpenDialog *CGUIEnvironment::addFileOpenDialog(const wchar_t *title, + bool modal, IGUIElement *parent, s32 id, + bool restoreCWD, io::path::char_type *startDir) +{ + parent = parent ? parent : this; + + if (modal) + return nullptr; + + IGUIFileOpenDialog *d = new CGUIFileOpenDialog(title, this, parent, id, + restoreCWD, startDir); + d->drop(); + + return d; +} + +//! adds a static text. The returned pointer must not be dropped. +IGUIStaticText *CGUIEnvironment::addStaticText(const wchar_t *text, + const core::rect &rectangle, + bool border, bool wordWrap, + IGUIElement *parent, s32 id, bool background) +{ + IGUIStaticText *d = new CGUIStaticText(text, border, this, + parent ? parent : this, id, rectangle, background); + + d->setWordWrap(wordWrap); + d->drop(); + + return d; +} + +//! Adds an edit box. The returned pointer must not be dropped. +IGUIEditBox *CGUIEnvironment::addEditBox(const wchar_t *text, + const core::rect &rectangle, bool border, + IGUIElement *parent, s32 id) +{ + IGUIEditBox *d = new CGUIEditBox(text, border, this, + parent ? parent : this, id, rectangle); + + d->drop(); + return d; +} + +//! Adds a tab control to the environment. +IGUITabControl *CGUIEnvironment::addTabControl(const core::rect &rectangle, + IGUIElement *parent, bool fillbackground, bool border, s32 id) +{ + IGUITabControl *t = new CGUITabControl(this, parent ? parent : this, + rectangle, fillbackground, border, id); + t->drop(); + return t; +} + +//! Adds tab to the environment. +IGUITab *CGUIEnvironment::addTab(const core::rect &rectangle, + IGUIElement *parent, s32 id) +{ + IGUITab *t = new CGUITab(this, parent ? parent : this, + rectangle, id); + t->drop(); + return t; +} + +//! Adds a combo box to the environment. +IGUIComboBox *CGUIEnvironment::addComboBox(const core::rect &rectangle, + IGUIElement *parent, s32 id) +{ + IGUIComboBox *t = new CGUIComboBox(this, parent ? parent : this, + id, rectangle); + t->drop(); + return t; +} + +//! returns the font +IGUIFont *CGUIEnvironment::getFont(const io::path &filename) +{ + // search existing font + + SFont f; + f.NamedPath.setPath(filename); + + s32 index = Fonts.binary_search(f); + if (index != -1) + return Fonts[index].Font; + + // font doesn't exist, attempt to load it + + // does the file exist? + + if (!FileSystem->existFile(filename)) { + os::Printer::log("Could not load font because the file does not exist", f.NamedPath.getPath(), ELL_ERROR); + return 0; + } + + IGUIFont *ifont = 0; +#if 0 + { + CGUIFont* font = new CGUIFont(this, filename); + ifont = (IGUIFont*)font; + + // load the font + io::path directory; + core::splitFilename(filename, &directory); + if (!font->load(xml, directory)) + { + font->drop(); + font = 0; + ifont = 0; + } + } +#endif + + if (!ifont) { + + CGUIFont *font = new CGUIFont(this, f.NamedPath.getPath()); + ifont = (IGUIFont *)font; + if (!font->load(f.NamedPath.getPath())) { + font->drop(); + return 0; + } + } + + // add to fonts. + + f.Font = ifont; + Fonts.push_back(f); + + return ifont; +} + +//! add an externally loaded font +IGUIFont *CGUIEnvironment::addFont(const io::path &name, IGUIFont *font) +{ + if (font) { + SFont f; + f.NamedPath.setPath(name); + s32 index = Fonts.binary_search(f); + if (index != -1) + return Fonts[index].Font; + f.Font = font; + Fonts.push_back(f); + font->grab(); + } + return font; +} + +//! remove loaded font +void CGUIEnvironment::removeFont(IGUIFont *font) +{ + if (!font) + return; + for (u32 i = 0; i < Fonts.size(); ++i) { + if (Fonts[i].Font == font) { + Fonts[i].Font->drop(); + Fonts.erase(i); + return; + } + } +} + +//! returns default font +IGUIFont *CGUIEnvironment::getBuiltInFont() const +{ + if (Fonts.empty()) + return 0; + + return Fonts[0].Font; +} + +IGUISpriteBank *CGUIEnvironment::getSpriteBank(const io::path &filename) +{ + // search for the file name + + SSpriteBank b; + b.NamedPath.setPath(filename); + + s32 index = Banks.binary_search(b); + if (index != -1) + return Banks[index].Bank; + + // we don't have this sprite bank, we should load it + if (!FileSystem->existFile(b.NamedPath.getPath())) { + if (filename != DefaultFontName) { + os::Printer::log("Could not load sprite bank because the file does not exist", b.NamedPath.getPath(), ELL_DEBUG); + } + return 0; + } + + // todo: load it! + + return 0; +} + +IGUISpriteBank *CGUIEnvironment::addEmptySpriteBank(const io::path &name) +{ + // no duplicate names allowed + + SSpriteBank b; + b.NamedPath.setPath(name); + + const s32 index = Banks.binary_search(b); + if (index != -1) + return 0; + + // create a new sprite bank + + b.Bank = new CGUISpriteBank(this); + Banks.push_back(b); + + return b.Bank; +} + +//! Creates the image list from the given texture. +IGUIImageList *CGUIEnvironment::createImageList(video::ITexture *texture, + core::dimension2d imageSize, bool useAlphaChannel) +{ + CGUIImageList *imageList = new CGUIImageList(Driver); + if (!imageList->createImageList(texture, imageSize, useAlphaChannel)) { + imageList->drop(); + return 0; + } + + return imageList; +} + +//! Returns the root gui element. +IGUIElement *CGUIEnvironment::getRootGUIElement() +{ + return this; +} + +//! Returns the next element in the tab group starting at the focused element +IGUIElement *CGUIEnvironment::getNextElement(bool reverse, bool group) +{ + // start the search at the root of the current tab group + IGUIElement *startPos = Focus ? Focus->getTabGroup() : 0; + s32 startOrder = -1; + + // if we're searching for a group + if (group && startPos) { + startOrder = startPos->getTabOrder(); + } else if (!group && Focus && !Focus->isTabGroup()) { + startOrder = Focus->getTabOrder(); + if (startOrder == -1) { + // this element is not part of the tab cycle, + // but its parent might be... + IGUIElement *el = Focus; + while (el && el->getParent() && startOrder == -1) { + el = el->getParent(); + startOrder = el->getTabOrder(); + } + } + } + + if (group || !startPos) + startPos = this; // start at the root + + // find the element + IGUIElement *closest = 0; + IGUIElement *first = 0; + startPos->getNextElement(startOrder, reverse, group, first, closest, false, (FocusFlags & EFF_CAN_FOCUS_DISABLED) != 0); + + if (closest) + return closest; // we found an element + else if (first) + return first; // go to the end or the start + else if (group) + return this; // no group found? root group + else + return 0; +} + +void CGUIEnvironment::setFocusBehavior(u32 flags) +{ + FocusFlags = flags; +} + +u32 CGUIEnvironment::getFocusBehavior() const +{ + return FocusFlags; +} + +//! creates an GUI Environment +IGUIEnvironment *createGUIEnvironment(io::IFileSystem *fs, + video::IVideoDriver *Driver, + IOSOperator *op) +{ + return new CGUIEnvironment(fs, Driver, op); +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIEnvironment.h b/irr/src/CGUIEnvironment.h new file mode 100644 index 000000000..b03c6f0d3 --- /dev/null +++ b/irr/src/CGUIEnvironment.h @@ -0,0 +1,226 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIEnvironment.h" +#include "IGUIElement.h" +#include "irrArray.h" +#include "IFileSystem.h" +#include "IOSOperator.h" + +namespace irr +{ + +namespace gui +{ + +class CGUIEnvironment : public IGUIEnvironment, public IGUIElement +{ +public: + //! constructor + CGUIEnvironment(io::IFileSystem *fs, video::IVideoDriver *driver, IOSOperator *op); + + //! destructor + virtual ~CGUIEnvironment(); + + //! draws all gui elements + void drawAll(bool useScreenSize) override; + + //! returns the current video driver + video::IVideoDriver *getVideoDriver() const override; + + //! returns pointer to the filesystem + io::IFileSystem *getFileSystem() const override; + + //! returns a pointer to the OS operator + IOSOperator *getOSOperator() const override; + + //! posts an input event to the environment + bool postEventFromUser(const SEvent &event) override; + + //! This sets a new event receiver for gui events. Usually you do not have to + //! use this method, it is used by the internal engine. + void setUserEventReceiver(IEventReceiver *evr) override; + + //! removes all elements from the environment + void clear() override; + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! returns the current gui skin + IGUISkin *getSkin() const override; + + //! Sets a new GUI Skin + void setSkin(IGUISkin *skin) override; + + //! Creates a new GUI Skin based on a template. + /** \return Returns a pointer to the created skin. + If you no longer need the skin, you should call IGUISkin::drop(). + See IReferenceCounted::drop() for more information. */ + IGUISkin *createSkin(EGUI_SKIN_TYPE type) override; + + //! Creates the image list from the given texture. + virtual IGUIImageList *createImageList(video::ITexture *texture, + core::dimension2d imageSize, bool useAlphaChannel) override; + + //! returns the font + IGUIFont *getFont(const io::path &filename) override; + + //! add an externally loaded font + IGUIFont *addFont(const io::path &name, IGUIFont *font) override; + + //! remove loaded font + void removeFont(IGUIFont *font) override; + + //! returns default font + IGUIFont *getBuiltInFont() const override; + + //! returns the sprite bank + IGUISpriteBank *getSpriteBank(const io::path &filename) override; + + //! returns the sprite bank + IGUISpriteBank *addEmptySpriteBank(const io::path &name) override; + + //! adds an button. The returned pointer must not be dropped. + IGUIButton *addButton(const core::rect &rectangle, IGUIElement *parent = 0, s32 id = -1, const wchar_t *text = 0, const wchar_t *tooltiptext = 0) override; + + //! adds a scrollbar. The returned pointer must not be dropped. + virtual IGUIScrollBar *addScrollBar(bool horizontal, const core::rect &rectangle, + IGUIElement *parent = 0, s32 id = -1) override; + + //! Adds an image element. + virtual IGUIImage *addImage(video::ITexture *image, core::position2d pos, + bool useAlphaChannel = true, IGUIElement *parent = 0, s32 id = -1, const wchar_t *text = 0) override; + + //! adds an image. The returned pointer must not be dropped. + virtual IGUIImage *addImage(const core::rect &rectangle, + IGUIElement *parent = 0, s32 id = -1, const wchar_t *text = 0, bool useAlphaChannel = true) override; + + //! adds a checkbox + virtual IGUICheckBox *addCheckBox(bool checked, const core::rect &rectangle, + IGUIElement *parent = 0, s32 id = -1, const wchar_t *text = 0) override; + + //! adds a list box + virtual IGUIListBox *addListBox(const core::rect &rectangle, + IGUIElement *parent = 0, s32 id = -1, bool drawBackground = false) override; + + //! Adds a file open dialog. + virtual IGUIFileOpenDialog *addFileOpenDialog(const wchar_t *title = 0, + bool modal = true, IGUIElement *parent = 0, s32 id = -1, + bool restoreCWD = false, io::path::char_type *startDir = 0) override; + + //! adds a static text. The returned pointer must not be dropped. + virtual IGUIStaticText *addStaticText(const wchar_t *text, const core::rect &rectangle, + bool border = false, bool wordWrap = true, IGUIElement *parent = 0, s32 id = -1, bool drawBackground = false) override; + + //! Adds an edit box. The returned pointer must not be dropped. + virtual IGUIEditBox *addEditBox(const wchar_t *text, const core::rect &rectangle, + bool border = false, IGUIElement *parent = 0, s32 id = -1) override; + + //! Adds a tab control to the environment. + virtual IGUITabControl *addTabControl(const core::rect &rectangle, + IGUIElement *parent = 0, bool fillbackground = false, bool border = true, s32 id = -1) override; + + //! Adds tab to the environment. + virtual IGUITab *addTab(const core::rect &rectangle, + IGUIElement *parent = 0, s32 id = -1) override; + + //! Adds a combo box to the environment. + virtual IGUIComboBox *addComboBox(const core::rect &rectangle, + IGUIElement *parent = 0, s32 id = -1) override; + + //! sets the focus to an element + bool setFocus(IGUIElement *element) override; + + //! removes the focus from an element + bool removeFocus(IGUIElement *element) override; + + //! Returns if the element has focus + bool hasFocus(const IGUIElement *element, bool checkSubElements = false) const override; + + //! Returns the element with the focus + IGUIElement *getFocus() const override; + + //! Returns the element last known to be under the mouse + IGUIElement *getHovered() const override; + + //! Returns the root gui element. + IGUIElement *getRootGUIElement() override; + + void OnPostRender(u32 time) override; + + //! Find the next element which would be selected when pressing the tab-key + IGUIElement *getNextElement(bool reverse = false, bool group = false) override; + + //! Set the way the gui will handle focus changes + void setFocusBehavior(u32 flags) override; + + //! Get the way the gui does handle focus changes + u32 getFocusBehavior() const override; + + //! Adds a IGUIElement to deletion queue. + void addToDeletionQueue(IGUIElement *element) override; + +private: + //! clears the deletion queue + void clearDeletionQueue(); + + void updateHoveredElement(core::position2d mousePos); + + void loadBuiltInFont(); + + struct SFont + { + io::SNamedPath NamedPath; + IGUIFont *Font; + + bool operator<(const SFont &other) const + { + return (NamedPath < other.NamedPath); + } + }; + + struct SSpriteBank + { + io::SNamedPath NamedPath; + IGUISpriteBank *Bank; + + bool operator<(const SSpriteBank &other) const + { + return (NamedPath < other.NamedPath); + } + }; + + struct SToolTip + { + IGUIStaticText *Element; + u32 LastTime; + u32 EnterTime; + u32 LaunchTime; + u32 RelaunchTime; + }; + + SToolTip ToolTip; + + core::array Fonts; + core::array Banks; + video::IVideoDriver *Driver; + IGUIElement *Hovered; + IGUIElement *HoveredNoSubelement; // subelements replaced by their parent, so you only have 'real' elements here + IGUIElement *Focus; + core::position2d LastHoveredMousePos; + IGUISkin *CurrentSkin; + io::IFileSystem *FileSystem; + IEventReceiver *UserReceiver; + IOSOperator *Operator; + u32 FocusFlags; + core::array DeletionQueue; + + static const io::path DefaultFontName; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIFileOpenDialog.cpp b/irr/src/CGUIFileOpenDialog.cpp new file mode 100644 index 000000000..1e669b255 --- /dev/null +++ b/irr/src/CGUIFileOpenDialog.cpp @@ -0,0 +1,372 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIFileOpenDialog.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "IGUIButton.h" +#include "IGUIStaticText.h" +#include "IGUIFont.h" +#include "IGUIFontBitmap.h" +#include "IFileList.h" +#include "os.h" + +namespace irr +{ +namespace gui +{ + +const s32 FOD_WIDTH = 350; +const s32 FOD_HEIGHT = 250; + +//! constructor +CGUIFileOpenDialog::CGUIFileOpenDialog(const wchar_t *title, + IGUIEnvironment *environment, IGUIElement *parent, s32 id, + bool restoreCWD, io::path::char_type *startDir) : + IGUIFileOpenDialog(environment, parent, id, + core::rect((parent->getAbsolutePosition().getWidth() - FOD_WIDTH) / 2, + (parent->getAbsolutePosition().getHeight() - FOD_HEIGHT) / 2, + (parent->getAbsolutePosition().getWidth() - FOD_WIDTH) / 2 + FOD_WIDTH, + (parent->getAbsolutePosition().getHeight() - FOD_HEIGHT) / 2 + FOD_HEIGHT)), + FileNameText(0), FileList(0), Dragging(false) +{ +#ifdef _DEBUG + IGUIElement::setDebugName("CGUIFileOpenDialog"); +#endif + + Text = title; + + FileSystem = Environment ? Environment->getFileSystem() : 0; + + if (FileSystem) { + FileSystem->grab(); + + if (restoreCWD) + RestoreDirectory = FileSystem->getWorkingDirectory(); + if (startDir) { + StartDirectory = startDir; + FileSystem->changeWorkingDirectoryTo(startDir); + } + } else + return; + + IGUISpriteBank *sprites = 0; + video::SColor color(255, 255, 255, 255); + IGUISkin *skin = Environment->getSkin(); + if (skin) { + sprites = skin->getSpriteBank(); + color = skin->getColor(EGDC_WINDOW_SYMBOL); + } + + const s32 buttonw = skin ? skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) : 2; + const s32 posx = RelativeRect.getWidth() - buttonw - 4; + + CloseButton = Environment->addButton(core::rect(posx, 3, posx + buttonw, 3 + buttonw), this, -1, + L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close"); + CloseButton->setSubElement(true); + CloseButton->setTabStop(false); + if (sprites && skin) { + CloseButton->setSpriteBank(sprites); + CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color); + CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color); + } + CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + CloseButton->grab(); + + OKButton = Environment->addButton( + core::rect(RelativeRect.getWidth() - 80, 30, RelativeRect.getWidth() - 10, 50), + this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK"); + OKButton->setSubElement(true); + OKButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + OKButton->grab(); + + CancelButton = Environment->addButton( + core::rect(RelativeRect.getWidth() - 80, 55, RelativeRect.getWidth() - 10, 75), + this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel"); + CancelButton->setSubElement(true); + CancelButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + CancelButton->grab(); + + FileBox = Environment->addListBox(core::rect(10, 55, RelativeRect.getWidth() - 90, 230), this, -1, true); + FileBox->setSubElement(true); + FileBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + FileBox->grab(); + + FileNameText = Environment->addEditBox(0, core::rect(10, 30, RelativeRect.getWidth() - 90, 50), true, this); + FileNameText->setSubElement(true); + FileNameText->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + FileNameText->grab(); + + setTabGroup(true); + + fillListBox(); +} + +//! destructor +CGUIFileOpenDialog::~CGUIFileOpenDialog() +{ + if (CloseButton) + CloseButton->drop(); + + if (OKButton) + OKButton->drop(); + + if (CancelButton) + CancelButton->drop(); + + if (FileBox) + FileBox->drop(); + + if (FileNameText) + FileNameText->drop(); + + if (FileSystem) { + // revert to original CWD if path was set in constructor + if (RestoreDirectory.size()) + FileSystem->changeWorkingDirectoryTo(RestoreDirectory); + FileSystem->drop(); + } + + if (FileList) + FileList->drop(); +} + +//! returns the filename of the selected file. Returns NULL, if no file was selected. +const wchar_t *CGUIFileOpenDialog::getFileName() const +{ + return FileNameW.c_str(); +} + +const io::path &CGUIFileOpenDialog::getFileNameP() const +{ + return FileName; +} + +//! Returns the directory of the selected file. Returns NULL, if no directory was selected. +const io::path &CGUIFileOpenDialog::getDirectoryName() const +{ + return FileDirectoryFlat; +} + +const wchar_t *CGUIFileOpenDialog::getDirectoryNameW() const +{ + return FileDirectoryFlatW.c_str(); +} + +void CGUIFileOpenDialog::setFileName(const irr::io::path &name) +{ + FileName = name; + pathToStringW(FileNameW, FileName); +} + +void CGUIFileOpenDialog::setDirectoryName(const irr::io::path &name) +{ + FileDirectory = name; + FileDirectoryFlat = name; + FileSystem->flattenFilename(FileDirectoryFlat); + pathToStringW(FileDirectoryFlatW, FileDirectoryFlat); +} + +//! called if an event happened. +bool CGUIFileOpenDialog::OnEvent(const SEvent &event) +{ + if (isEnabled()) { + switch (event.EventType) { + case EET_GUI_EVENT: + switch (event.GUIEvent.EventType) { + case EGET_ELEMENT_FOCUS_LOST: + Dragging = false; + break; + case EGET_BUTTON_CLICKED: + if (event.GUIEvent.Caller == CloseButton || + event.GUIEvent.Caller == CancelButton) { + sendCancelEvent(); + remove(); + return true; + } else if (event.GUIEvent.Caller == OKButton) { + if (FileDirectory != L"") { + sendSelectedEvent(EGET_DIRECTORY_SELECTED); + } + if (FileName != L"") { + sendSelectedEvent(EGET_FILE_SELECTED); + remove(); + return true; + } + } + break; + + case EGET_LISTBOX_CHANGED: { + s32 selected = FileBox->getSelected(); + if (FileList && FileSystem) { + if (FileList->isDirectory(selected)) { + setFileName(""); + setDirectoryName(FileList->getFullFileName(selected)); + } else { + setDirectoryName(""); + setFileName(FileList->getFullFileName(selected)); + } + return true; + } + } break; + + case EGET_LISTBOX_SELECTED_AGAIN: { + const s32 selected = FileBox->getSelected(); + if (FileList && FileSystem) { + if (FileList->isDirectory(selected)) { + setDirectoryName(FileList->getFullFileName(selected)); + FileSystem->changeWorkingDirectoryTo(FileDirectory); + fillListBox(); + setFileName(""); + } else { + setFileName(FileList->getFullFileName(selected)); + } + return true; + } + } break; + case EGET_EDITBOX_ENTER: + if (event.GUIEvent.Caller == FileNameText) { + io::path dir(FileNameText->getText()); + if (FileSystem->changeWorkingDirectoryTo(dir)) { + fillListBox(); + setFileName(""); + } + return true; + } + break; + default: + break; + } + break; + case EET_MOUSE_INPUT_EVENT: + switch (event.MouseInput.Event) { + case EMIE_MOUSE_WHEEL: + return FileBox->OnEvent(event); + case EMIE_LMOUSE_PRESSED_DOWN: + DragStart.X = event.MouseInput.X; + DragStart.Y = event.MouseInput.Y; + Dragging = true; + return true; + case EMIE_LMOUSE_LEFT_UP: + Dragging = false; + return true; + case EMIE_MOUSE_MOVED: + + if (!event.MouseInput.isLeftPressed()) + Dragging = false; + + if (Dragging) { + // gui window should not be dragged outside its parent + if (Parent) + if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X + 1 || + event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y + 1 || + event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X - 1 || + event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y - 1) + + return true; + + move(core::position2d(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y)); + DragStart.X = event.MouseInput.X; + DragStart.Y = event.MouseInput.Y; + return true; + } + break; + default: + break; + } + default: + break; + } + } + + return IGUIElement::OnEvent(event); +} + +//! draws the element and its children +void CGUIFileOpenDialog::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + + core::rect rect = AbsoluteRect; + + rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER), + rect, &AbsoluteClippingRect); + + if (Text.size()) { + rect.UpperLeftCorner.X += 2; + rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; + + IGUIFont *font = skin->getFont(EGDF_WINDOW); + if (font) + font->draw(Text.c_str(), rect, + skin->getColor(EGDC_ACTIVE_CAPTION), + false, true, &AbsoluteClippingRect); + } + + IGUIElement::draw(); +} + +void CGUIFileOpenDialog::pathToStringW(irr::core::stringw &result, const irr::io::path &p) +{ + core::multibyteToWString(result, p); +} + +//! fills the listbox with files. +void CGUIFileOpenDialog::fillListBox() +{ + IGUISkin *skin = Environment->getSkin(); + + if (!FileSystem || !FileBox || !skin) + return; + + if (FileList) + FileList->drop(); + + FileBox->clear(); + + FileList = FileSystem->createFileList(); + core::stringw s; + + if (FileList) { + for (u32 i = 0; i < FileList->getFileCount(); ++i) { + pathToStringW(s, FileList->getFileName(i)); + FileBox->addItem(s.c_str(), skin->getIcon(FileList->isDirectory(i) ? EGDI_DIRECTORY : EGDI_FILE)); + } + } + + if (FileNameText) { + setDirectoryName(FileSystem->getWorkingDirectory()); + pathToStringW(s, FileDirectory); + FileNameText->setText(s.c_str()); + } +} + +//! sends the event that the file has been selected. +void CGUIFileOpenDialog::sendSelectedEvent(EGUI_EVENT_TYPE type) +{ + SEvent event; + event.EventType = EET_GUI_EVENT; + event.GUIEvent.Caller = this; + event.GUIEvent.Element = 0; + event.GUIEvent.EventType = type; + Parent->OnEvent(event); +} + +//! sends the event that the file choose process has been cancelled +void CGUIFileOpenDialog::sendCancelEvent() +{ + SEvent event; + event.EventType = EET_GUI_EVENT; + event.GUIEvent.Caller = this; + event.GUIEvent.Element = 0; + event.GUIEvent.EventType = EGET_FILE_CHOOSE_DIALOG_CANCELLED; + Parent->OnEvent(event); +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIFileOpenDialog.h b/irr/src/CGUIFileOpenDialog.h new file mode 100644 index 000000000..133509233 --- /dev/null +++ b/irr/src/CGUIFileOpenDialog.h @@ -0,0 +1,84 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIFileOpenDialog.h" +#include "IGUIButton.h" +#include "IGUIListBox.h" +#include "IGUIEditBox.h" +#include "IFileSystem.h" + +namespace irr +{ +namespace gui +{ + +class CGUIFileOpenDialog : public IGUIFileOpenDialog +{ +public: + //! constructor + CGUIFileOpenDialog(const wchar_t *title, IGUIEnvironment *environment, + IGUIElement *parent, s32 id, bool restoreCWD = false, + io::path::char_type *startDir = 0); + + //! destructor + virtual ~CGUIFileOpenDialog(); + + //! returns the filename of the selected file. Returns NULL, if no file was selected. + const wchar_t *getFileName() const override; + + //! Returns the filename of the selected file. Is empty if no file was selected. + const io::path &getFileNameP() const override; + + //! Returns the directory of the selected file. Returns NULL, if no directory was selected. + const io::path &getDirectoryName() const override; + + //! Returns the directory of the selected file converted to wide characters. Returns NULL if no directory was selected. + const wchar_t *getDirectoryNameW() const override; + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + +protected: + void setFileName(const irr::io::path &name); + void setDirectoryName(const irr::io::path &name); + + //! Ensure filenames are converted correct depending on wide-char settings + void pathToStringW(irr::core::stringw &result, const irr::io::path &p); + + //! fills the listbox with files. + void fillListBox(); + + //! sends the event that the file has been selected. + void sendSelectedEvent(EGUI_EVENT_TYPE type); + + //! sends the event that the file choose process has been canceld + void sendCancelEvent(); + + core::position2d DragStart; + io::path FileName; + core::stringw FileNameW; + io::path FileDirectory; + io::path FileDirectoryFlat; + core::stringw FileDirectoryFlatW; + io::path RestoreDirectory; + io::path StartDirectory; + + IGUIButton *CloseButton; + IGUIButton *OKButton; + IGUIButton *CancelButton; + IGUIListBox *FileBox; + IGUIEditBox *FileNameText; + IGUIElement *EventParent; + io::IFileSystem *FileSystem; + io::IFileList *FileList; + bool Dragging; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIFont.cpp b/irr/src/CGUIFont.cpp new file mode 100644 index 000000000..4d85702f5 --- /dev/null +++ b/irr/src/CGUIFont.cpp @@ -0,0 +1,548 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIFont.h" + +#include "os.h" +#include "coreutil.h" +#include "IGUIEnvironment.h" +#include "IReadFile.h" +#include "IVideoDriver.h" +#include "IGUISpriteBank.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIFont::CGUIFont(IGUIEnvironment *env, const io::path &filename) : + Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0), + MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) +{ +#ifdef _DEBUG + setDebugName("CGUIFont"); +#endif + + if (Environment) { + // don't grab environment, to avoid circular references + Driver = Environment->getVideoDriver(); + + SpriteBank = Environment->getSpriteBank(filename); + if (!SpriteBank) // could be default-font which has no file + SpriteBank = Environment->addEmptySpriteBank(filename); + if (SpriteBank) + SpriteBank->grab(); + } + + if (Driver) + Driver->grab(); + + setInvisibleCharacters(L" "); +} + +//! destructor +CGUIFont::~CGUIFont() +{ + if (Driver) + Driver->drop(); + + if (SpriteBank) { + SpriteBank->drop(); + // TODO: spritebank still exists in gui-environment and should be removed here when it's + // reference-count is 1. Just can't do that from here at the moment. + // But spritebank would not be able to drop textures anyway because those are in texture-cache + // where they can't be removed unless materials start reference-couting 'em. + } +} + +#if 0 +//! loads a font file from xml +bool CGUIFont::load(io::IXMLReader* xml, const io::path& directory) +{ + if (!SpriteBank) + return false; + + SpriteBank->clear(); + + while (xml->read()) + { + if (io::EXN_ELEMENT == xml->getNodeType()) + { + if (core::stringw(L"Texture") == xml->getNodeName()) + { + // add a texture + core::stringc fn = xml->getAttributeValue(L"filename"); + u32 i = (u32)xml->getAttributeValueAsInt(L"index"); + core::stringw alpha = xml->getAttributeValue(L"hasAlpha"); + + while (i+1 > SpriteBank->getTextureCount()) + SpriteBank->addTexture(0); + + bool flags[3]; + pushTextureCreationFlags(flags); + + // load texture + io::path textureFullName = core::mergeFilename(directory, fn); + SpriteBank->setTexture(i, Driver->getTexture(textureFullName)); + + popTextureCreationFlags(flags); + + // couldn't load texture, abort. + if (!SpriteBank->getTexture(i)) + { + os::Printer::log("Unable to load all textures in the font, aborting", ELL_ERROR); + return false; + } + else + { + // colorkey texture rather than alpha channel? + if (alpha == core::stringw("false")) + Driver->makeColorKeyTexture(SpriteBank->getTexture(i), core::position2di(0,0)); + } + } + else if (core::stringw(L"c") == xml->getNodeName()) + { + // adding a character to this font + SFontArea a; + SGUISpriteFrame f; + SGUISprite s; + core::rect rectangle; + + a.underhang = xml->getAttributeValueAsInt(L"u"); + a.overhang = xml->getAttributeValueAsInt(L"o"); + a.spriteno = SpriteBank->getSprites().size(); + s32 texno = xml->getAttributeValueAsInt(L"i"); + + // parse rectangle + core::stringc rectstr = xml->getAttributeValue(L"r"); + wchar_t ch = xml->getAttributeValue(L"c")[0]; + + const c8 *c = rectstr.c_str(); + s32 val; + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.UpperLeftCorner.X = val; + while (*c == L' ' || *c == L',') c++; + + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.UpperLeftCorner.Y = val; + while (*c == L' ' || *c == L',') c++; + + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.LowerRightCorner.X = val; + while (*c == L' ' || *c == L',') c++; + + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.LowerRightCorner.Y = val; + + CharacterMap.emplace(ch, Areas.size()); + + // make frame + f.rectNumber = SpriteBank->getPositions().size(); + f.textureNumber = texno; + + // add frame to sprite + s.Frames.push_back(f); + s.frameTime = 0; + + // add rectangle to sprite bank + SpriteBank->getPositions().push_back(rectangle); + a.width = rectangle.getWidth(); + + // add sprite to sprite bank + SpriteBank->getSprites().push_back(s); + + // add character to font + Areas.push_back(a); + } + } + } + + // set bad character + WrongCharacter = getAreaFromCharacter(L' '); + + setMaxHeight(); + + return true; +} +#endif + +void CGUIFont::setMaxHeight() +{ + if (!SpriteBank) + return; + + MaxHeight = 0; + + core::array> &p = SpriteBank->getPositions(); + + for (u32 i = 0; i < p.size(); ++i) { + const s32 t = p[i].getHeight(); + if (t > MaxHeight) + MaxHeight = t; + } +} + +void CGUIFont::pushTextureCreationFlags(bool (&flags)[3]) +{ + flags[0] = Driver->getTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2); + flags[1] = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); + flags[2] = Driver->getTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY); + + Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, true); + Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); + Driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, true); +} + +void CGUIFont::popTextureCreationFlags(const bool (&flags)[3]) +{ + Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, flags[0]); + Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flags[1]); + Driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, flags[2]); +} + +//! loads a font file, native file needed, for texture parsing +bool CGUIFont::load(io::IReadFile *file) +{ + if (!Driver) + return false; + + return loadTexture(Driver->createImageFromFile(file), + file->getFileName()); +} + +//! loads a font file, native file needed, for texture parsing +bool CGUIFont::load(const io::path &filename) +{ + if (!Driver) + return false; + + return loadTexture(Driver->createImageFromFile(filename), + filename); +} + +//! load & prepare font from ITexture +bool CGUIFont::loadTexture(video::IImage *image, const io::path &name) +{ + if (!image || !SpriteBank) + return false; + + s32 lowerRightPositions = 0; + + video::IImage *tmpImage = image; + bool deleteTmpImage = false; + switch (image->getColorFormat()) { + case video::ECF_R5G6B5: + tmpImage = Driver->createImage(video::ECF_A1R5G5B5, image->getDimension()); + image->copyTo(tmpImage); + deleteTmpImage = true; + break; + case video::ECF_A1R5G5B5: + case video::ECF_A8R8G8B8: + break; + case video::ECF_R8G8B8: + tmpImage = Driver->createImage(video::ECF_A8R8G8B8, image->getDimension()); + image->copyTo(tmpImage); + deleteTmpImage = true; + break; + default: + os::Printer::log("Unknown texture format provided for CGUIFont::loadTexture", ELL_ERROR); + return false; + } + readPositions(tmpImage, lowerRightPositions); + + WrongCharacter = getAreaFromCharacter(L' '); + + // output warnings + if (!lowerRightPositions || !SpriteBank->getSprites().size()) + os::Printer::log("Either no upper or lower corner pixels in the font file. If this font was made using the new font tool, please load the XML file instead. If not, the font may be corrupted.", ELL_ERROR); + else if (lowerRightPositions != (s32)SpriteBank->getPositions().size()) + os::Printer::log("The amount of upper corner pixels and the lower corner pixels is not equal, font file may be corrupted.", ELL_ERROR); + + bool ret = (!SpriteBank->getSprites().empty() && lowerRightPositions); + + if (ret) { + bool flags[3]; + pushTextureCreationFlags(flags); + + SpriteBank->addTexture(Driver->addTexture(name, tmpImage)); + + popTextureCreationFlags(flags); + } + if (deleteTmpImage) + tmpImage->drop(); + image->drop(); + + setMaxHeight(); + + return ret; +} + +void CGUIFont::readPositions(video::IImage *image, s32 &lowerRightPositions) +{ + if (!SpriteBank) + return; + + const core::dimension2d size = image->getDimension(); + + video::SColor colorTopLeft = image->getPixel(0, 0); + colorTopLeft.setAlpha(255); + image->setPixel(0, 0, colorTopLeft); + video::SColor colorLowerRight = image->getPixel(1, 0); + video::SColor colorBackGround = image->getPixel(2, 0); + video::SColor colorBackGroundTransparent = 0; + + image->setPixel(1, 0, colorBackGround); + + // start parsing + + core::position2d pos(0, 0); + for (pos.Y = 0; pos.Y < (s32)size.Height; ++pos.Y) { + for (pos.X = 0; pos.X < (s32)size.Width; ++pos.X) { + const video::SColor c = image->getPixel(pos.X, pos.Y); + if (c == colorTopLeft) { + image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); + SpriteBank->getPositions().push_back(core::rect(pos, pos)); + } else if (c == colorLowerRight) { + // too many lower right points + if (SpriteBank->getPositions().size() <= (u32)lowerRightPositions) { + lowerRightPositions = 0; + return; + } + + image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); + SpriteBank->getPositions()[lowerRightPositions].LowerRightCorner = pos; + // add frame to sprite bank + SGUISpriteFrame f; + f.rectNumber = lowerRightPositions; + f.textureNumber = 0; + SGUISprite s; + s.Frames.push_back(f); + s.frameTime = 0; + SpriteBank->getSprites().push_back(s); + // add character to font + SFontArea a; + a.overhang = 0; + a.underhang = 0; + a.spriteno = lowerRightPositions; + a.width = SpriteBank->getPositions()[lowerRightPositions].getWidth(); + Areas.push_back(a); + // map letter to character + wchar_t ch = (wchar_t)(lowerRightPositions + 32); + CharacterMap[ch] = lowerRightPositions; + + ++lowerRightPositions; + } else if (c == colorBackGround) + image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); + } + } +} + +//! set an Pixel Offset on Drawing ( scale position on width ) +void CGUIFont::setKerningWidth(s32 kerning) +{ + GlobalKerningWidth = kerning; +} + +//! set an Pixel Offset on Drawing ( scale position on width ) +s32 CGUIFont::getKerningWidth(const wchar_t *thisLetter, const wchar_t *previousLetter) const +{ + s32 ret = GlobalKerningWidth; + + if (thisLetter) { + ret += Areas[getAreaFromCharacter(*thisLetter)].overhang; + + if (previousLetter) { + ret += Areas[getAreaFromCharacter(*previousLetter)].underhang; + } + } + + return ret; +} + +//! set an Pixel Offset on Drawing ( scale position on height ) +void CGUIFont::setKerningHeight(s32 kerning) +{ + GlobalKerningHeight = kerning; +} + +//! set an Pixel Offset on Drawing ( scale position on height ) +s32 CGUIFont::getKerningHeight() const +{ + return GlobalKerningHeight; +} + +//! returns the sprite number from a given character +u32 CGUIFont::getSpriteNoFromChar(const wchar_t *c) const +{ + return Areas[getAreaFromCharacter(*c)].spriteno; +} + +s32 CGUIFont::getAreaFromCharacter(const wchar_t c) const +{ + auto n = CharacterMap.find(c); + if (n != CharacterMap.end()) + return n->second; + else + return WrongCharacter; +} + +void CGUIFont::setInvisibleCharacters(const wchar_t *s) +{ + Invisible = s; +} + +//! returns the dimension of text +core::dimension2d CGUIFont::getDimension(const wchar_t *text) const +{ + core::dimension2d dim(0, 0); + core::dimension2d thisLine(0, MaxHeight); + + for (const wchar_t *p = text; *p; ++p) { + bool lineBreak = false; + if (*p == L'\r') { // Mac or Windows breaks + lineBreak = true; + if (p[1] == L'\n') // Windows breaks + ++p; + } else if (*p == L'\n') { // Unix breaks + lineBreak = true; + } + if (lineBreak) { + dim.Height += thisLine.Height; + if (dim.Width < thisLine.Width) + dim.Width = thisLine.Width; + thisLine.Width = 0; + continue; + } + + const SFontArea &area = Areas[getAreaFromCharacter(*p)]; + + thisLine.Width += area.underhang; + thisLine.Width += area.width + area.overhang + GlobalKerningWidth; + } + + dim.Height += thisLine.Height; + if (dim.Width < thisLine.Width) + dim.Width = thisLine.Width; + + return dim; +} + +//! draws some text and clips it to the specified rectangle if wanted +void CGUIFont::draw(const core::stringw &text, const core::rect &position, + video::SColor color, + bool hcenter, bool vcenter, const core::rect *clip) +{ + if (!Driver || !SpriteBank) + return; + + core::dimension2d textDimension; // NOTE: don't make this u32 or the >> later on can fail when the dimension width is < position width + core::position2d offset = position.UpperLeftCorner; + + if (hcenter || vcenter || clip) + textDimension = getDimension(text.c_str()); + + if (hcenter) + offset.X += (position.getWidth() - textDimension.Width) >> 1; + + if (vcenter) + offset.Y += (position.getHeight() - textDimension.Height) >> 1; + + if (clip) { + core::rect clippedRect(offset, textDimension); + clippedRect.clipAgainst(*clip); + if (!clippedRect.isValid()) + return; + } + + core::array indices(text.size()); + core::array offsets(text.size()); + + for (u32 i = 0; i < text.size(); i++) { + wchar_t c = text[i]; + + bool lineBreak = false; + if (c == L'\r') { // Mac or Windows breaks + lineBreak = true; + if (text[i + 1] == L'\n') // Windows breaks + c = text[++i]; + } else if (c == L'\n') { // Unix breaks + lineBreak = true; + } + + if (lineBreak) { + offset.Y += MaxHeight; + offset.X = position.UpperLeftCorner.X; + + if (hcenter) { + offset.X += (position.getWidth() - textDimension.Width) >> 1; + } + continue; + } + + SFontArea &area = Areas[getAreaFromCharacter(c)]; + + offset.X += area.underhang; + if (Invisible.findFirst(c) < 0) { + indices.push_back(area.spriteno); + offsets.push_back(offset); + } + + offset.X += area.width + area.overhang + GlobalKerningWidth; + } + + SpriteBank->draw2DSpriteBatch(indices, offsets, clip, color); +} + +//! Calculates the index of the character in the text which is on a specific position. +s32 CGUIFont::getCharacterFromPos(const wchar_t *text, s32 pixel_x) const +{ + s32 x = 0; + s32 idx = 0; + + while (text[idx]) { + const SFontArea &a = Areas[getAreaFromCharacter(text[idx])]; + + x += a.width + a.overhang + a.underhang + GlobalKerningWidth; + + if (x >= pixel_x) + return idx; + + ++idx; + } + + return -1; +} + +IGUISpriteBank *CGUIFont::getSpriteBank() const +{ + return SpriteBank; +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIFont.h b/irr/src/CGUIFont.h new file mode 100644 index 000000000..2f383a5f7 --- /dev/null +++ b/irr/src/CGUIFont.h @@ -0,0 +1,107 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIFontBitmap.h" +#include "irrString.h" +#include "IReadFile.h" +#include "irrArray.h" +#include + +namespace irr +{ + +namespace video +{ +class IVideoDriver; +class IImage; +} + +namespace gui +{ + +class IGUIEnvironment; + +class CGUIFont : public IGUIFontBitmap +{ +public: + //! constructor + CGUIFont(IGUIEnvironment *env, const io::path &filename); + + //! destructor + virtual ~CGUIFont(); + + //! loads a font from a texture file + bool load(const io::path &filename); + + //! loads a font from a texture file + bool load(io::IReadFile *file); + + //! draws an text and clips it to the specified rectangle if wanted + virtual void draw(const core::stringw &text, const core::rect &position, + video::SColor color, bool hcenter = false, + bool vcenter = false, const core::rect *clip = 0) override; + + //! returns the dimension of a text + core::dimension2d getDimension(const wchar_t *text) const override; + + //! Calculates the index of the character in the text which is on a specific position. + s32 getCharacterFromPos(const wchar_t *text, s32 pixel_x) const override; + + //! Returns the type of this font + EGUI_FONT_TYPE getType() const override { return EGFT_BITMAP; } + + //! set an Pixel Offset on Drawing ( scale position on width ) + void setKerningWidth(s32 kerning) override; + void setKerningHeight(s32 kerning) override; + + //! set an Pixel Offset on Drawing ( scale position on width ) + s32 getKerningWidth(const wchar_t *thisLetter = 0, const wchar_t *previousLetter = 0) const override; + s32 getKerningHeight() const override; + + //! gets the sprite bank + IGUISpriteBank *getSpriteBank() const override; + + //! returns the sprite number from a given character + u32 getSpriteNoFromChar(const wchar_t *c) const override; + + void setInvisibleCharacters(const wchar_t *s) override; + +private: + struct SFontArea + { + SFontArea() : + underhang(0), overhang(0), width(0), spriteno(0) {} + s32 underhang; + s32 overhang; + s32 width; + u32 spriteno; + }; + + //! load & prepare font from ITexture + bool loadTexture(video::IImage *image, const io::path &name); + + void readPositions(video::IImage *texture, s32 &lowerRightPositions); + + s32 getAreaFromCharacter(const wchar_t c) const; + void setMaxHeight(); + + void pushTextureCreationFlags(bool (&flags)[3]); + void popTextureCreationFlags(const bool (&flags)[3]); + + core::array Areas; + std::map CharacterMap; + video::IVideoDriver *Driver; + IGUISpriteBank *SpriteBank; + IGUIEnvironment *Environment; + u32 WrongCharacter; + s32 MaxHeight; + s32 GlobalKerningWidth, GlobalKerningHeight; + + core::stringw Invisible; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIImage.cpp b/irr/src/CGUIImage.cpp new file mode 100644 index 000000000..5f7bb8e26 --- /dev/null +++ b/irr/src/CGUIImage.cpp @@ -0,0 +1,164 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIImage.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIImage::CGUIImage(IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect rectangle) : + IGUIImage(environment, parent, id, rectangle), Texture(0), Color(255, 255, 255, 255), + UseAlphaChannel(false), ScaleImage(false), DrawBounds(0.f, 0.f, 1.f, 1.f), DrawBackground(true) +{ +#ifdef _DEBUG + setDebugName("CGUIImage"); +#endif +} + +//! destructor +CGUIImage::~CGUIImage() +{ + if (Texture) + Texture->drop(); +} + +//! sets an image +void CGUIImage::setImage(video::ITexture *image) +{ + if (image == Texture) + return; + + if (Texture) + Texture->drop(); + + Texture = image; + + if (Texture) + Texture->grab(); +} + +//! Gets the image texture +video::ITexture *CGUIImage::getImage() const +{ + return Texture; +} + +//! sets the color of the image +void CGUIImage::setColor(video::SColor color) +{ + Color = color; +} + +//! Gets the color of the image +video::SColor CGUIImage::getColor() const +{ + return Color; +} + +//! draws the element and its children +void CGUIImage::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + video::IVideoDriver *driver = Environment->getVideoDriver(); + + if (Texture) { + core::rect sourceRect(SourceRect); + if (sourceRect.getWidth() == 0 || sourceRect.getHeight() == 0) { + sourceRect = core::rect(core::dimension2di(Texture->getOriginalSize())); + } + + if (ScaleImage) { + const video::SColor Colors[] = {Color, Color, Color, Color}; + + core::rect clippingRect(AbsoluteClippingRect); + checkBounds(clippingRect); + + driver->draw2DImage(Texture, AbsoluteRect, sourceRect, + &clippingRect, Colors, UseAlphaChannel); + } else { + core::rect clippingRect(AbsoluteRect.UpperLeftCorner, sourceRect.getSize()); + checkBounds(clippingRect); + clippingRect.clipAgainst(AbsoluteClippingRect); + + driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner, sourceRect, + &clippingRect, Color, UseAlphaChannel); + } + } else if (DrawBackground) { + core::rect clippingRect(AbsoluteClippingRect); + checkBounds(clippingRect); + + skin->draw2DRectangle(this, skin->getColor(EGDC_3D_DARK_SHADOW), AbsoluteRect, &clippingRect); + } + + IGUIElement::draw(); +} + +//! sets if the image should use its alpha channel to draw itself +void CGUIImage::setUseAlphaChannel(bool use) +{ + UseAlphaChannel = use; +} + +//! sets if the image should use its alpha channel to draw itself +void CGUIImage::setScaleImage(bool scale) +{ + ScaleImage = scale; +} + +//! Returns true if the image is scaled to fit, false if not +bool CGUIImage::isImageScaled() const +{ + return ScaleImage; +} + +//! Returns true if the image is using the alpha channel, false if not +bool CGUIImage::isAlphaChannelUsed() const +{ + return UseAlphaChannel; +} + +//! Sets the source rectangle of the image. By default the full image is used. +void CGUIImage::setSourceRect(const core::rect &sourceRect) +{ + SourceRect = sourceRect; +} + +//! Returns the customized source rectangle of the image to be used. +core::rect CGUIImage::getSourceRect() const +{ + return SourceRect; +} + +//! Restrict target drawing-area. +void CGUIImage::setDrawBounds(const core::rect &drawBoundUVs) +{ + DrawBounds = drawBoundUVs; + DrawBounds.UpperLeftCorner.X = core::clamp(DrawBounds.UpperLeftCorner.X, 0.f, 1.f); + DrawBounds.UpperLeftCorner.Y = core::clamp(DrawBounds.UpperLeftCorner.Y, 0.f, 1.f); + DrawBounds.LowerRightCorner.X = core::clamp(DrawBounds.LowerRightCorner.X, 0.f, 1.f); + DrawBounds.LowerRightCorner.X = core::clamp(DrawBounds.LowerRightCorner.X, 0.f, 1.f); + if (DrawBounds.UpperLeftCorner.X > DrawBounds.LowerRightCorner.X) + DrawBounds.UpperLeftCorner.X = DrawBounds.LowerRightCorner.X; + if (DrawBounds.UpperLeftCorner.Y > DrawBounds.LowerRightCorner.Y) + DrawBounds.UpperLeftCorner.Y = DrawBounds.LowerRightCorner.Y; +} + +//! Get target drawing-area restrictions. +core::rect CGUIImage::getDrawBounds() const +{ + return DrawBounds; +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIImage.h b/irr/src/CGUIImage.h new file mode 100644 index 000000000..967ac40ea --- /dev/null +++ b/irr/src/CGUIImage.h @@ -0,0 +1,97 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIImage.h" + +namespace irr +{ +namespace gui +{ + +class CGUIImage : public IGUIImage +{ +public: + //! constructor + CGUIImage(IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect rectangle); + + //! destructor + virtual ~CGUIImage(); + + //! sets an image + void setImage(video::ITexture *image) override; + + //! Gets the image texture + video::ITexture *getImage() const override; + + //! sets the color of the image + void setColor(video::SColor color) override; + + //! sets if the image should scale to fit the element + void setScaleImage(bool scale) override; + + //! draws the element and its children + void draw() override; + + //! sets if the image should use its alpha channel to draw itself + void setUseAlphaChannel(bool use) override; + + //! Gets the color of the image + video::SColor getColor() const override; + + //! Returns true if the image is scaled to fit, false if not + bool isImageScaled() const override; + + //! Returns true if the image is using the alpha channel, false if not + bool isAlphaChannelUsed() const override; + + //! Sets the source rectangle of the image. By default the full image is used. + void setSourceRect(const core::rect &sourceRect) override; + + //! Returns the customized source rectangle of the image to be used. + core::rect getSourceRect() const override; + + //! Restrict drawing-area. + void setDrawBounds(const core::rect &drawBoundUVs) override; + + //! Get drawing-area restrictions. + core::rect getDrawBounds() const override; + + //! Sets whether to draw a background color (EGDC_3D_DARK_SHADOW) when no texture is set + void setDrawBackground(bool draw) override + { + DrawBackground = draw; + } + + //! Checks if a background is drawn when no texture is set + bool isDrawBackgroundEnabled() const override + { + return DrawBackground; + } + +protected: + void checkBounds(core::rect &rect) + { + f32 clipWidth = (f32)rect.getWidth(); + f32 clipHeight = (f32)rect.getHeight(); + + rect.UpperLeftCorner.X += core::round32(DrawBounds.UpperLeftCorner.X * clipWidth); + rect.UpperLeftCorner.Y += core::round32(DrawBounds.UpperLeftCorner.Y * clipHeight); + rect.LowerRightCorner.X -= core::round32((1.f - DrawBounds.LowerRightCorner.X) * clipWidth); + rect.LowerRightCorner.Y -= core::round32((1.f - DrawBounds.LowerRightCorner.Y) * clipHeight); + } + +private: + video::ITexture *Texture; + video::SColor Color; + bool UseAlphaChannel; + bool ScaleImage; + core::rect SourceRect; + core::rect DrawBounds; + bool DrawBackground; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIImageList.cpp b/irr/src/CGUIImageList.cpp new file mode 100644 index 000000000..3bd30d913 --- /dev/null +++ b/irr/src/CGUIImageList.cpp @@ -0,0 +1,84 @@ +// This file is part of the "Irrlicht Engine". +// written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de +// modified by Thomas Alten + +#include "CGUIImageList.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIImageList::CGUIImageList(video::IVideoDriver *driver) : + Driver(driver), + Texture(0), + ImageCount(0), + ImageSize(0, 0), + ImagesPerRow(0), + UseAlphaChannel(false) +{ +#ifdef _DEBUG + setDebugName("CGUIImageList"); +#endif + + if (Driver) { + Driver->grab(); + } +} + +//! destructor +CGUIImageList::~CGUIImageList() +{ + if (Driver) { + Driver->drop(); + } + + if (Texture) { + Texture->drop(); + } +} + +//! Creates the image list from texture. +bool CGUIImageList::createImageList(video::ITexture *texture, + core::dimension2d imageSize, + bool useAlphaChannel) +{ + if (!texture) { + return false; + } + + Texture = texture; + Texture->grab(); + + ImageSize = imageSize; + + ImagesPerRow = Texture->getSize().Width / ImageSize.Width; + ImageCount = ImagesPerRow * Texture->getSize().Height / ImageSize.Height; + + UseAlphaChannel = useAlphaChannel; + + return true; +} + +//! Draws an image and clips it to the specified rectangle if wanted +void CGUIImageList::draw(s32 index, const core::position2d &destPos, + const core::rect *clip /*= 0*/) +{ + core::rect sourceRect; + + if (!Driver || index < 0 || index >= ImageCount) { + return; + } + + sourceRect.UpperLeftCorner.X = (index % ImagesPerRow) * ImageSize.Width; + sourceRect.UpperLeftCorner.Y = (index / ImagesPerRow) * ImageSize.Height; + sourceRect.LowerRightCorner.X = sourceRect.UpperLeftCorner.X + ImageSize.Width; + sourceRect.LowerRightCorner.Y = sourceRect.UpperLeftCorner.Y + ImageSize.Height; + + Driver->draw2DImage(Texture, destPos, sourceRect, clip, + video::SColor(255, 255, 255, 255), UseAlphaChannel); +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIImageList.h b/irr/src/CGUIImageList.h new file mode 100644 index 000000000..afde14e0a --- /dev/null +++ b/irr/src/CGUIImageList.h @@ -0,0 +1,65 @@ +// This file is part of the "Irrlicht Engine". +// written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de + +#pragma once + +#include "IGUIImageList.h" +#include "IVideoDriver.h" + +namespace irr +{ +namespace gui +{ + +class CGUIImageList : public IGUIImageList +{ +public: + //! constructor + CGUIImageList(video::IVideoDriver *Driver); + + //! destructor + virtual ~CGUIImageList(); + + //! Creates the image list from texture. + //! \param texture: The texture to use + //! \param imageSize: Size of a single image + //! \param useAlphaChannel: true if the alpha channel from the texture should be used + //! \return + //! true if the image list was created + bool createImageList(video::ITexture *texture, + core::dimension2d imageSize, + bool useAlphaChannel); + + //! Draws an image and clips it to the specified rectangle if wanted + //! \param index: Index of the image + //! \param destPos: Position of the image to draw + //! \param clip: Optional pointer to a rectangle against which the text will be clipped. + //! If the pointer is null, no clipping will be done. + virtual void draw(s32 index, const core::position2d &destPos, + const core::rect *clip = 0) override; + + //! Returns the count of Images in the list. + //! \return Returns the count of Images in the list. + s32 getImageCount() const override + { + return ImageCount; + } + + //! Returns the size of the images in the list. + //! \return Returns the size of the images in the list. + core::dimension2d getImageSize() const override + { + return ImageSize; + } + +private: + video::IVideoDriver *Driver; + video::ITexture *Texture; + s32 ImageCount; + core::dimension2d ImageSize; + s32 ImagesPerRow; + bool UseAlphaChannel; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIListBox.cpp b/irr/src/CGUIListBox.cpp new file mode 100644 index 000000000..78cb96ecf --- /dev/null +++ b/irr/src/CGUIListBox.cpp @@ -0,0 +1,745 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIListBox.h" + +#include "CGUIListBox.h" +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "IGUIFont.h" +#include "IGUISpriteBank.h" +#include "CGUIScrollBar.h" +#include "os.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIListBox::CGUIListBox(IGUIEnvironment *environment, IGUIElement *parent, + s32 id, core::rect rectangle, bool clip, + bool drawBack, bool moveOverSelect) : + IGUIListBox(environment, parent, id, rectangle), + Selected(-1), + ItemHeight(0), ItemHeightOverride(0), + TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0), + ScrollBar(0), selectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack), + MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true) +{ +#ifdef _DEBUG + setDebugName("CGUIListBox"); +#endif + + IGUISkin *skin = Environment->getSkin(); + + ScrollBar = new CGUIScrollBar(false, Environment, this, -1, + core::recti(0, 0, 1, 1), + !clip); + ScrollBar->setSubElement(true); + ScrollBar->setTabStop(false); + ScrollBar->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + ScrollBar->setVisible(false); + ScrollBar->setPos(0); + + updateScrollBarSize(skin->getSize(EGDS_SCROLLBAR_SIZE)); + + setNotClipped(!clip); + + // this element can be tabbed to + setTabStop(true); + setTabOrder(-1); + + updateAbsolutePosition(); +} + +//! destructor +CGUIListBox::~CGUIListBox() +{ + if (ScrollBar) + ScrollBar->drop(); + + if (Font) + Font->drop(); + + if (IconBank) + IconBank->drop(); +} + +//! returns amount of list items +u32 CGUIListBox::getItemCount() const +{ + return Items.size(); +} + +//! returns string of a list item. the may be a value from 0 to itemCount-1 +const wchar_t *CGUIListBox::getListItem(u32 id) const +{ + if (id >= Items.size()) + return 0; + + return Items[id].Text.c_str(); +} + +//! Returns the icon of an item +s32 CGUIListBox::getIcon(u32 id) const +{ + if (id >= Items.size()) + return -1; + + return Items[id].Icon; +} + +//! adds a list item, returns id of item +u32 CGUIListBox::addItem(const wchar_t *text) +{ + return addItem(text, -1); +} + +//! adds a list item, returns id of item +void CGUIListBox::removeItem(u32 id) +{ + if (id >= Items.size()) + return; + + if ((u32)Selected == id) { + Selected = -1; + } else if ((u32)Selected > id) { + Selected -= 1; + selectTime = os::Timer::getTime(); + } + + Items.erase(id); + + recalculateItemHeight(); +} + +s32 CGUIListBox::getItemAt(s32 xpos, s32 ypos) const +{ + if (xpos < AbsoluteRect.UpperLeftCorner.X || xpos >= AbsoluteRect.LowerRightCorner.X || ypos < AbsoluteRect.UpperLeftCorner.Y || ypos >= AbsoluteRect.LowerRightCorner.Y) + return -1; + + if (ItemHeight == 0) + return -1; + + s32 item = ((ypos - AbsoluteRect.UpperLeftCorner.Y - 1) + ScrollBar->getPos()) / ItemHeight; + if (item < 0 || item >= (s32)Items.size()) + return -1; + + return item; +} + +//! clears the list +void CGUIListBox::clear() +{ + Items.clear(); + ItemsIconWidth = 0; + Selected = -1; + + ScrollBar->setPos(0); + + recalculateItemHeight(); +} + +void CGUIListBox::recalculateItemHeight() +{ + IGUISkin *skin = Environment->getSkin(); + + if (Font != skin->getFont()) { + if (Font) + Font->drop(); + + Font = skin->getFont(); + if (0 == ItemHeightOverride) + ItemHeight = 0; + + if (Font) { + if (0 == ItemHeightOverride) + ItemHeight = Font->getDimension(L"A").Height + 4; + + Font->grab(); + } + } + + TotalItemHeight = ItemHeight * Items.size(); + ScrollBar->setMax(core::max_(0, TotalItemHeight - AbsoluteRect.getHeight())); + s32 minItemHeight = ItemHeight > 0 ? ItemHeight : 1; + ScrollBar->setSmallStep(minItemHeight); + ScrollBar->setLargeStep(2 * minItemHeight); + + if (TotalItemHeight <= AbsoluteRect.getHeight()) + ScrollBar->setVisible(false); + else + ScrollBar->setVisible(true); +} + +//! returns id of selected item. returns -1 if no item is selected. +s32 CGUIListBox::getSelected() const +{ + return Selected; +} + +//! sets the selected item. Set this to -1 if no item should be selected +void CGUIListBox::setSelected(s32 id) +{ + if ((u32)id >= Items.size()) + Selected = -1; + else + Selected = id; + + selectTime = os::Timer::getTime(); + + recalculateScrollPos(); +} + +//! sets the selected item. Set this to -1 if no item should be selected +void CGUIListBox::setSelected(const wchar_t *item) +{ + s32 index = -1; + + if (item) { + for (index = 0; index < (s32)Items.size(); ++index) { + if (Items[index].Text == item) + break; + } + } + setSelected(index); +} + +//! called if an event happened. +bool CGUIListBox::OnEvent(const SEvent &event) +{ + if (isEnabled()) { + switch (event.EventType) { + case EET_KEY_INPUT_EVENT: + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_DOWN || + event.KeyInput.Key == KEY_UP || + event.KeyInput.Key == KEY_HOME || + event.KeyInput.Key == KEY_END || + event.KeyInput.Key == KEY_NEXT || + event.KeyInput.Key == KEY_PRIOR)) { + s32 oldSelected = Selected; + switch (event.KeyInput.Key) { + case KEY_DOWN: + Selected += 1; + break; + case KEY_UP: + Selected -= 1; + break; + case KEY_HOME: + Selected = 0; + break; + case KEY_END: + Selected = (s32)Items.size() - 1; + break; + case KEY_NEXT: + Selected += AbsoluteRect.getHeight() / ItemHeight; + break; + case KEY_PRIOR: + Selected -= AbsoluteRect.getHeight() / ItemHeight; + break; + default: + break; + } + if (Selected < 0) + Selected = 0; + if (Selected >= (s32)Items.size()) + Selected = Items.size() - 1; // will set Selected to -1 for empty listboxes which is correct + + recalculateScrollPos(); + + // post the news + + if (oldSelected != Selected && Parent && !Selecting && !MoveOverSelect) { + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = this; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = EGET_LISTBOX_CHANGED; + Parent->OnEvent(e); + } + + return true; + } else if (!event.KeyInput.PressedDown && (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) { + if (Parent) { + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = this; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = EGET_LISTBOX_SELECTED_AGAIN; + Parent->OnEvent(e); + } + return true; + } else if (event.KeyInput.Key == KEY_TAB) { + return false; + } else if (event.KeyInput.PressedDown && event.KeyInput.Char) { + // change selection based on text as it is typed. + u32 now = os::Timer::getTime(); + + if (now - LastKeyTime < 500) { + // add to key buffer if it isn't a key repeat + if (!(KeyBuffer.size() == 1 && KeyBuffer[0] == event.KeyInput.Char)) { + KeyBuffer += L" "; + KeyBuffer[KeyBuffer.size() - 1] = event.KeyInput.Char; + } + } else { + KeyBuffer = L" "; + KeyBuffer[0] = event.KeyInput.Char; + } + LastKeyTime = now; + + // find the selected item, starting at the current selection + s32 start = Selected; + // dont change selection if the key buffer matches the current item + if (Selected > -1 && KeyBuffer.size() > 1) { + if (Items[Selected].Text.size() >= KeyBuffer.size() && + KeyBuffer.equals_ignore_case(Items[Selected].Text.subString(0, KeyBuffer.size()))) + return true; + } + + s32 current; + for (current = start + 1; current < (s32)Items.size(); ++current) { + if (Items[current].Text.size() >= KeyBuffer.size()) { + if (KeyBuffer.equals_ignore_case(Items[current].Text.subString(0, KeyBuffer.size()))) { + if (Parent && Selected != current && !Selecting && !MoveOverSelect) { + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = this; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = EGET_LISTBOX_CHANGED; + Parent->OnEvent(e); + } + setSelected(current); + return true; + } + } + } + for (current = 0; current <= start; ++current) { + if (Items[current].Text.size() >= KeyBuffer.size()) { + if (KeyBuffer.equals_ignore_case(Items[current].Text.subString(0, KeyBuffer.size()))) { + if (Parent && Selected != current && !Selecting && !MoveOverSelect) { + Selected = current; + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = this; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = EGET_LISTBOX_CHANGED; + Parent->OnEvent(e); + } + setSelected(current); + return true; + } + } + } + + return true; + } + break; + + case EET_GUI_EVENT: + switch (event.GUIEvent.EventType) { + case gui::EGET_SCROLL_BAR_CHANGED: + if (event.GUIEvent.Caller == ScrollBar) + return true; + break; + case gui::EGET_ELEMENT_FOCUS_LOST: { + if (event.GUIEvent.Caller == this) + Selecting = false; + } + default: + break; + } + break; + + case EET_MOUSE_INPUT_EVENT: { + core::position2d p(event.MouseInput.X, event.MouseInput.Y); + + switch (event.MouseInput.Event) { + case EMIE_MOUSE_WHEEL: + ScrollBar->setPos(ScrollBar->getPos() + (event.MouseInput.Wheel < 0 ? -1 : 1) * -ItemHeight / 2); + return true; + + case EMIE_LMOUSE_PRESSED_DOWN: { + Selecting = true; + return true; + } + + case EMIE_LMOUSE_LEFT_UP: { + Selecting = false; + + if (isPointInside(p)) + selectNew(event.MouseInput.Y); + + return true; + } + + case EMIE_MOUSE_MOVED: + if (Selecting || MoveOverSelect) { + if (isPointInside(p)) { + selectNew(event.MouseInput.Y, true); + return true; + } + } + default: + break; + } + } break; + default: + break; + } + } + + return IGUIElement::OnEvent(event); +} + +void CGUIListBox::selectNew(s32 ypos, bool onlyHover) +{ + u32 now = os::Timer::getTime(); + s32 oldSelected = Selected; + + Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos); + if (Selected < 0 && !Items.empty()) + Selected = 0; + + recalculateScrollPos(); + + gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < selectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED; + selectTime = now; + // post the news + if (Parent && !onlyHover) { + SEvent event; + event.EventType = EET_GUI_EVENT; + event.GUIEvent.Caller = this; + event.GUIEvent.Element = 0; + event.GUIEvent.EventType = eventType; + Parent->OnEvent(event); + } +} + +//! Update the position and size of the listbox, and update the scrollbar +void CGUIListBox::updateAbsolutePosition() +{ + IGUIElement::updateAbsolutePosition(); + + recalculateItemHeight(); +} + +//! draws the element and its children +void CGUIListBox::draw() +{ + if (!IsVisible) + return; + + recalculateItemHeight(); // if the font changed + + IGUISkin *skin = Environment->getSkin(); + updateScrollBarSize(skin->getSize(EGDS_SCROLLBAR_SIZE)); + + core::rect *clipRect = 0; + + // draw background + core::rect frameRect(AbsoluteRect); + + // draw items + + core::rect clientClip(AbsoluteRect); + clientClip.UpperLeftCorner.Y += 1; + clientClip.UpperLeftCorner.X += 1; + if (ScrollBar->isVisible()) + clientClip.LowerRightCorner.X -= ScrollBar->getRelativePosition().getWidth(); + clientClip.LowerRightCorner.Y -= 1; + clientClip.clipAgainst(AbsoluteClippingRect); + + skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_HIGH_LIGHT), true, + DrawBack, frameRect, &AbsoluteClippingRect); + + if (clipRect) + clientClip.clipAgainst(*clipRect); + + frameRect = AbsoluteRect; + frameRect.UpperLeftCorner.X += 1; + if (ScrollBar->isVisible()) + frameRect.LowerRightCorner.X -= ScrollBar->getRelativePosition().getWidth(); + + frameRect.LowerRightCorner.Y = AbsoluteRect.UpperLeftCorner.Y + ItemHeight; + + frameRect.UpperLeftCorner.Y -= ScrollBar->getPos(); + frameRect.LowerRightCorner.Y -= ScrollBar->getPos(); + + bool hl = (HighlightWhenNotFocused || Environment->hasFocus(this) || Environment->hasFocus(ScrollBar)); + + for (s32 i = 0; i < (s32)Items.size(); ++i) { + if (frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y && + frameRect.UpperLeftCorner.Y <= AbsoluteRect.LowerRightCorner.Y) { + if (i == Selected && hl) + skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), frameRect, &clientClip); + + core::rect textRect = frameRect; + textRect.UpperLeftCorner.X += 3; + + if (Font) { + if (IconBank && (Items[i].Icon > -1)) { + core::position2di iconPos = textRect.UpperLeftCorner; + iconPos.Y += textRect.getHeight() / 2; + iconPos.X += ItemsIconWidth / 2; + + if (i == Selected && hl) { + IconBank->draw2DSprite((u32)Items[i].Icon, iconPos, &clientClip, + hasItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) ? getItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) : getItemDefaultColor(EGUI_LBC_ICON_HIGHLIGHT), + selectTime, os::Timer::getTime(), false, true); + } else { + IconBank->draw2DSprite((u32)Items[i].Icon, iconPos, &clientClip, + hasItemOverrideColor(i, EGUI_LBC_ICON) ? getItemOverrideColor(i, EGUI_LBC_ICON) : getItemDefaultColor(EGUI_LBC_ICON), + 0, (i == Selected) ? os::Timer::getTime() : 0, false, true); + } + } + + textRect.UpperLeftCorner.X += ItemsIconWidth + 3; + + if (i == Selected && hl) { + Font->draw(Items[i].Text.c_str(), textRect, + hasItemOverrideColor(i, EGUI_LBC_TEXT_HIGHLIGHT) ? getItemOverrideColor(i, EGUI_LBC_TEXT_HIGHLIGHT) : getItemDefaultColor(EGUI_LBC_TEXT_HIGHLIGHT), + false, true, &clientClip); + } else { + Font->draw(Items[i].Text.c_str(), textRect, + hasItemOverrideColor(i, EGUI_LBC_TEXT) ? getItemOverrideColor(i, EGUI_LBC_TEXT) : getItemDefaultColor(EGUI_LBC_TEXT), + false, true, &clientClip); + } + + textRect.UpperLeftCorner.X -= ItemsIconWidth + 3; + } + } + + frameRect.UpperLeftCorner.Y += ItemHeight; + frameRect.LowerRightCorner.Y += ItemHeight; + } + + IGUIElement::draw(); +} + +//! adds an list item with an icon +u32 CGUIListBox::addItem(const wchar_t *text, s32 icon) +{ + ListItem i; + i.Text = text; + i.Icon = icon; + + Items.push_back(i); + recalculateItemHeight(); + recalculateItemWidth(icon); + + return Items.size() - 1; +} + +void CGUIListBox::setSpriteBank(IGUISpriteBank *bank) +{ + if (bank == IconBank) + return; + if (IconBank) + IconBank->drop(); + + IconBank = bank; + if (IconBank) + IconBank->grab(); +} + +void CGUIListBox::recalculateScrollPos() +{ + if (!AutoScroll) + return; + + const s32 selPos = (getSelected() == -1 ? TotalItemHeight : getSelected() * ItemHeight) - ScrollBar->getPos(); + + if (selPos < 0) { + ScrollBar->setPos(ScrollBar->getPos() + selPos); + } else if (selPos > AbsoluteRect.getHeight() - ItemHeight) { + ScrollBar->setPos(ScrollBar->getPos() + selPos - AbsoluteRect.getHeight() + ItemHeight); + } +} + +void CGUIListBox::updateScrollBarSize(s32 size) +{ + if (size != ScrollBar->getRelativePosition().getWidth()) { + core::recti r(RelativeRect.getWidth() - size, 0, RelativeRect.getWidth(), RelativeRect.getHeight()); + ScrollBar->setRelativePosition(r); + } +} + +void CGUIListBox::setAutoScrollEnabled(bool scroll) +{ + AutoScroll = scroll; +} + +bool CGUIListBox::isAutoScrollEnabled() const +{ + return AutoScroll; +} + +bool CGUIListBox::getSerializationLabels(EGUI_LISTBOX_COLOR colorType, core::stringc &useColorLabel, core::stringc &colorLabel) const +{ + switch (colorType) { + case EGUI_LBC_TEXT: + useColorLabel = "UseColText"; + colorLabel = "ColText"; + break; + case EGUI_LBC_TEXT_HIGHLIGHT: + useColorLabel = "UseColTextHl"; + colorLabel = "ColTextHl"; + break; + case EGUI_LBC_ICON: + useColorLabel = "UseColIcon"; + colorLabel = "ColIcon"; + break; + case EGUI_LBC_ICON_HIGHLIGHT: + useColorLabel = "UseColIconHl"; + colorLabel = "ColIconHl"; + break; + default: + return false; + } + return true; +} + +void CGUIListBox::recalculateItemWidth(s32 icon) +{ + if (IconBank && icon > -1 && + IconBank->getSprites().size() > (u32)icon && + IconBank->getSprites()[(u32)icon].Frames.size()) { + u32 rno = IconBank->getSprites()[(u32)icon].Frames[0].rectNumber; + if (IconBank->getPositions().size() > rno) { + const s32 w = IconBank->getPositions()[rno].getWidth(); + if (w > ItemsIconWidth) + ItemsIconWidth = w; + } + } +} + +void CGUIListBox::setItem(u32 index, const wchar_t *text, s32 icon) +{ + if (index >= Items.size()) + return; + + Items[index].Text = text; + Items[index].Icon = icon; + + recalculateItemHeight(); + recalculateItemWidth(icon); +} + +//! Insert the item at the given index +//! Return the index on success or -1 on failure. +s32 CGUIListBox::insertItem(u32 index, const wchar_t *text, s32 icon) +{ + ListItem i; + i.Text = text; + i.Icon = icon; + + Items.insert(i, index); + recalculateItemHeight(); + recalculateItemWidth(icon); + + return index; +} + +void CGUIListBox::swapItems(u32 index1, u32 index2) +{ + if (index1 >= Items.size() || index2 >= Items.size()) + return; + + ListItem dummmy = Items[index1]; + Items[index1] = Items[index2]; + Items[index2] = dummmy; +} + +void CGUIListBox::setItemOverrideColor(u32 index, video::SColor color) +{ + for (u32 c = 0; c < EGUI_LBC_COUNT; ++c) { + Items[index].OverrideColors[c].Use = true; + Items[index].OverrideColors[c].Color = color; + } +} + +void CGUIListBox::setItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType, video::SColor color) +{ + if (index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT) + return; + + Items[index].OverrideColors[colorType].Use = true; + Items[index].OverrideColors[colorType].Color = color; +} + +void CGUIListBox::clearItemOverrideColor(u32 index) +{ + for (u32 c = 0; c < (u32)EGUI_LBC_COUNT; ++c) { + Items[index].OverrideColors[c].Use = false; + } +} + +void CGUIListBox::clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) +{ + if (index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT) + return; + + Items[index].OverrideColors[colorType].Use = false; +} + +bool CGUIListBox::hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const +{ + if (index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT) + return false; + + return Items[index].OverrideColors[colorType].Use; +} + +video::SColor CGUIListBox::getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const +{ + if ((u32)index >= Items.size() || colorType < 0 || colorType >= EGUI_LBC_COUNT) + return video::SColor(); + + return Items[index].OverrideColors[colorType].Color; +} + +video::SColor CGUIListBox::getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const +{ + IGUISkin *skin = Environment->getSkin(); + if (!skin) + return video::SColor(); + + switch (colorType) { + case EGUI_LBC_TEXT: + return skin->getColor(EGDC_BUTTON_TEXT); + case EGUI_LBC_TEXT_HIGHLIGHT: + return skin->getColor(EGDC_HIGH_LIGHT_TEXT); + case EGUI_LBC_ICON: + return skin->getColor(EGDC_ICON); + case EGUI_LBC_ICON_HIGHLIGHT: + return skin->getColor(EGDC_ICON_HIGH_LIGHT); + default: + return video::SColor(); + } +} + +//! set global itemHeight +void CGUIListBox::setItemHeight(s32 height) +{ + ItemHeight = height; + ItemHeightOverride = 1; +} + +//! Sets whether to draw the background +void CGUIListBox::setDrawBackground(bool draw) +{ + DrawBack = draw; +} + +//! Access the vertical scrollbar +IGUIScrollBar *CGUIListBox::getVerticalScrollBar() const +{ + return ScrollBar; +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIListBox.h b/irr/src/CGUIListBox.h new file mode 100644 index 000000000..ea1eaebd0 --- /dev/null +++ b/irr/src/CGUIListBox.h @@ -0,0 +1,173 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIListBox.h" +#include "irrArray.h" + +namespace irr +{ +namespace gui +{ + +class IGUIFont; +class IGUIScrollBar; + +class CGUIListBox : public IGUIListBox +{ +public: + //! constructor + CGUIListBox(IGUIEnvironment *environment, IGUIElement *parent, + s32 id, core::rect rectangle, bool clip = true, + bool drawBack = false, bool moveOverSelect = false); + + //! destructor + virtual ~CGUIListBox(); + + //! returns amount of list items + u32 getItemCount() const override; + + //! returns string of a list item. the id may be a value from 0 to itemCount-1 + const wchar_t *getListItem(u32 id) const override; + + //! adds an list item, returns id of item + u32 addItem(const wchar_t *text) override; + + //! clears the list + void clear() override; + + //! returns id of selected item. returns -1 if no item is selected. + s32 getSelected() const override; + + //! sets the selected item. Set this to -1 if no item should be selected + void setSelected(s32 id) override; + + //! sets the selected item. Set this to -1 if no item should be selected + void setSelected(const wchar_t *item) override; + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + + //! adds an list item with an icon + //! \param text Text of list entry + //! \param icon Sprite index of the Icon within the current sprite bank. Set it to -1 if you want no icon + //! \return + //! returns the id of the new created item + u32 addItem(const wchar_t *text, s32 icon) override; + + //! Returns the icon of an item + s32 getIcon(u32 id) const override; + + //! removes an item from the list + void removeItem(u32 id) override; + + //! get the the id of the item at the given absolute coordinates + s32 getItemAt(s32 xpos, s32 ypos) const override; + + //! Sets the sprite bank which should be used to draw list icons. This font is set to the sprite bank of + //! the built-in-font by default. A sprite can be displayed in front of every list item. + //! An icon is an index within the icon sprite bank. Several default icons are available in the + //! skin through getIcon + void setSpriteBank(IGUISpriteBank *bank) override; + + //! set whether the listbox should scroll to newly selected items + void setAutoScrollEnabled(bool scroll) override; + + //! returns true if automatic scrolling is enabled, false if not. + bool isAutoScrollEnabled() const override; + + //! Update the position and size of the listbox, and update the scrollbar + void updateAbsolutePosition() override; + + //! set all item colors at given index to color + void setItemOverrideColor(u32 index, video::SColor color) override; + + //! set all item colors of specified type at given index to color + void setItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType, video::SColor color) override; + + //! clear all item colors at index + void clearItemOverrideColor(u32 index) override; + + //! clear item color at index for given colortype + void clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) override; + + //! has the item at index its color overwritten? + bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override; + + //! return the overwrite color at given item index. + video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override; + + //! return the default color which is used for the given colorType + video::SColor getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const override; + + //! set the item at the given index + void setItem(u32 index, const wchar_t *text, s32 icon) override; + + //! Insert the item at the given index + //! Return the index on success or -1 on failure. + s32 insertItem(u32 index, const wchar_t *text, s32 icon) override; + + //! Swap the items at the given indices + void swapItems(u32 index1, u32 index2) override; + + //! set global itemHeight + void setItemHeight(s32 height) override; + + //! Sets whether to draw the background + void setDrawBackground(bool draw) override; + + //! Access the vertical scrollbar + IGUIScrollBar *getVerticalScrollBar() const override; + +private: + struct ListItem + { + core::stringw Text; + s32 Icon = -1; + + // A multicolor extension + struct ListItemOverrideColor + { + bool Use = false; + video::SColor Color; + }; + ListItemOverrideColor OverrideColors[EGUI_LBC_COUNT]{}; + }; + + void recalculateItemHeight(); + void selectNew(s32 ypos, bool onlyHover = false); + void recalculateScrollPos(); + void updateScrollBarSize(s32 size); + + // extracted that function to avoid copy&paste code + void recalculateItemWidth(s32 icon); + + // get labels used for serialization + bool getSerializationLabels(EGUI_LISTBOX_COLOR colorType, core::stringc &useColorLabel, core::stringc &colorLabel) const; + + core::array Items; + s32 Selected; + s32 ItemHeight; + s32 ItemHeightOverride; + s32 TotalItemHeight; + s32 ItemsIconWidth; + gui::IGUIFont *Font; + gui::IGUISpriteBank *IconBank; + gui::IGUIScrollBar *ScrollBar; + u32 selectTime; + u32 LastKeyTime; + core::stringw KeyBuffer; + bool Selecting; + bool DrawBack; + bool MoveOverSelect; + bool AutoScroll; + bool HighlightWhenNotFocused; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIScrollBar.cpp b/irr/src/CGUIScrollBar.cpp new file mode 100644 index 000000000..f9ebad09e --- /dev/null +++ b/irr/src/CGUIScrollBar.cpp @@ -0,0 +1,463 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIScrollBar.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "CGUIButton.h" +#include "IGUIFont.h" +#include "IGUIFontBitmap.h" +#include "os.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIScrollBar::CGUIScrollBar(bool horizontal, IGUIEnvironment *environment, + IGUIElement *parent, s32 id, + core::rect rectangle, bool noclip) : + IGUIScrollBar(environment, parent, id, rectangle), + UpButton(0), + DownButton(0), Dragging(false), Horizontal(horizontal), + DraggedBySlider(false), TrayClick(false), Pos(0), DrawPos(0), + DrawHeight(0), Min(0), Max(100), SmallStep(10), LargeStep(50), DesiredPos(0), + LastChange(0) +{ +#ifdef _DEBUG + setDebugName("CGUIScrollBar"); +#endif + + refreshControls(); + + setNotClipped(noclip); + + // this element can be tabbed to + setTabStop(true); + setTabOrder(-1); + + setPos(0); +} + +//! destructor +CGUIScrollBar::~CGUIScrollBar() +{ + if (UpButton) + UpButton->drop(); + + if (DownButton) + DownButton->drop(); +} + +//! called if an event happened. +bool CGUIScrollBar::OnEvent(const SEvent &event) +{ + if (isEnabled()) { + + switch (event.EventType) { + case EET_KEY_INPUT_EVENT: + if (event.KeyInput.PressedDown) { + const s32 oldPos = Pos; + bool absorb = true; + switch (event.KeyInput.Key) { + case KEY_LEFT: + case KEY_UP: + setPos(Pos - SmallStep); + break; + case KEY_RIGHT: + case KEY_DOWN: + setPos(Pos + SmallStep); + break; + case KEY_HOME: + setPos(Min); + break; + case KEY_PRIOR: + setPos(Pos - LargeStep); + break; + case KEY_END: + setPos(Max); + break; + case KEY_NEXT: + setPos(Pos + LargeStep); + break; + default: + absorb = false; + } + + if (Pos != oldPos) { + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED; + Parent->OnEvent(newEvent); + } + if (absorb) + return true; + } + break; + case EET_GUI_EVENT: + if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) { + if (event.GUIEvent.Caller == UpButton) + setPos(Pos - SmallStep); + else if (event.GUIEvent.Caller == DownButton) + setPos(Pos + SmallStep); + + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED; + Parent->OnEvent(newEvent); + + return true; + } else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { + if (event.GUIEvent.Caller == this) + Dragging = false; + } + break; + case EET_MOUSE_INPUT_EVENT: { + const core::position2di p(event.MouseInput.X, event.MouseInput.Y); + bool isInside = isPointInside(p); + switch (event.MouseInput.Event) { + case EMIE_MOUSE_WHEEL: + if (Environment->hasFocus(this)) { + // thanks to a bug report by REAPER + // thanks to tommi by tommi for another bugfix + // everybody needs a little thanking. hallo niko!;-) + setPos(getPos() + + ((event.MouseInput.Wheel < 0 ? -1 : 1) * SmallStep * (Horizontal ? 1 : -1))); + + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED; + Parent->OnEvent(newEvent); + return true; + } + break; + case EMIE_LMOUSE_PRESSED_DOWN: { + if (isInside) { + Dragging = true; + DraggedBySlider = SliderRect.isPointInside(p); + TrayClick = !DraggedBySlider; + DesiredPos = getPosFromMousePos(p); + return true; + } + break; + } + case EMIE_LMOUSE_LEFT_UP: + case EMIE_MOUSE_MOVED: { + if (!event.MouseInput.isLeftPressed()) + Dragging = false; + + if (!Dragging) { + if (event.MouseInput.Event == EMIE_MOUSE_MOVED) + break; + return isInside; + } + + if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) + Dragging = false; + + const s32 newPos = getPosFromMousePos(p); + const s32 oldPos = Pos; + + if (!DraggedBySlider) { + if (isInside) { + DraggedBySlider = SliderRect.isPointInside(p); + TrayClick = !DraggedBySlider; + } + + if (DraggedBySlider) { + setPos(newPos); + } else { + TrayClick = false; + if (event.MouseInput.Event == EMIE_MOUSE_MOVED) + return isInside; + } + } + + if (DraggedBySlider) { + setPos(newPos); + } else { + DesiredPos = newPos; + } + + if (Pos != oldPos && Parent) { + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED; + Parent->OnEvent(newEvent); + } + return isInside; + } break; + + default: + break; + } + } break; + default: + break; + } + } + + return IGUIElement::OnEvent(event); +} + +void CGUIScrollBar::OnPostRender(u32 timeMs) +{ + if (Dragging && !DraggedBySlider && TrayClick && timeMs > LastChange + 200) { + LastChange = timeMs; + + const s32 oldPos = Pos; + + if (DesiredPos >= Pos + LargeStep) + setPos(Pos + LargeStep); + else if (DesiredPos <= Pos - LargeStep) + setPos(Pos - LargeStep); + else if (DesiredPos >= Pos - LargeStep && DesiredPos <= Pos + LargeStep) + setPos(DesiredPos); + + if (Pos != oldPos && Parent) { + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED; + Parent->OnEvent(newEvent); + } + } +} + +//! draws the element and its children +void CGUIScrollBar::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + if (!skin) + return; + + video::SColor iconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL); + if (iconColor != CurrentIconColor) { + refreshControls(); + } + + SliderRect = AbsoluteRect; + + // draws the background + skin->draw2DRectangle(this, skin->getColor(EGDC_SCROLLBAR), SliderRect, &AbsoluteClippingRect); + + if (core::isnotzero(range())) { + // recalculate slider rectangle + if (Horizontal) { + SliderRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawPos + RelativeRect.getHeight() - DrawHeight / 2; + SliderRect.LowerRightCorner.X = SliderRect.UpperLeftCorner.X + DrawHeight; + } else { + SliderRect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawPos + RelativeRect.getWidth() - DrawHeight / 2; + SliderRect.LowerRightCorner.Y = SliderRect.UpperLeftCorner.Y + DrawHeight; + } + + skin->draw3DButtonPaneStandard(this, SliderRect, &AbsoluteClippingRect); + } + + // draw buttons + IGUIElement::draw(); +} + +void CGUIScrollBar::updateAbsolutePosition() +{ + IGUIElement::updateAbsolutePosition(); + // todo: properly resize + refreshControls(); + setPos(Pos); +} + +//! +s32 CGUIScrollBar::getPosFromMousePos(const core::position2di &pos) const +{ + f32 w, p; + if (Horizontal) { + w = RelativeRect.getWidth() - f32(RelativeRect.getHeight()) * 3.0f; + p = pos.X - AbsoluteRect.UpperLeftCorner.X - RelativeRect.getHeight() * 1.5f; + } else { + w = RelativeRect.getHeight() - f32(RelativeRect.getWidth()) * 3.0f; + p = pos.Y - AbsoluteRect.UpperLeftCorner.Y - RelativeRect.getWidth() * 1.5f; + } + return (s32)(p / w * range()) + Min; +} + +//! sets the position of the scrollbar +void CGUIScrollBar::setPos(s32 pos) +{ + Pos = core::s32_clamp(pos, Min, Max); + + if (core::isnotzero(range())) { + if (Horizontal) { + f32 f = (RelativeRect.getWidth() - ((f32)RelativeRect.getHeight() * 3.0f)) / range(); + DrawPos = (s32)(((Pos - Min) * f) + ((f32)RelativeRect.getHeight() * 0.5f)); + DrawHeight = RelativeRect.getHeight(); + } else { + f32 f = (RelativeRect.getHeight() - ((f32)RelativeRect.getWidth() * 3.0f)) / range(); + + DrawPos = (s32)(((Pos - Min) * f) + ((f32)RelativeRect.getWidth() * 0.5f)); + DrawHeight = RelativeRect.getWidth(); + } + } +} + +//! gets the small step value +s32 CGUIScrollBar::getSmallStep() const +{ + return SmallStep; +} + +//! sets the small step value +void CGUIScrollBar::setSmallStep(s32 step) +{ + if (step > 0) + SmallStep = step; + else + SmallStep = 10; +} + +//! gets the small step value +s32 CGUIScrollBar::getLargeStep() const +{ + return LargeStep; +} + +//! sets the small step value +void CGUIScrollBar::setLargeStep(s32 step) +{ + if (step > 0) + LargeStep = step; + else + LargeStep = 50; +} + +//! gets the maximum value of the scrollbar. +s32 CGUIScrollBar::getMax() const +{ + return Max; +} + +//! sets the maximum value of the scrollbar. +void CGUIScrollBar::setMax(s32 max) +{ + Max = max; + if (Min > Max) + Min = Max; + + bool enable = core::isnotzero(range()); + UpButton->setEnabled(enable); + DownButton->setEnabled(enable); + setPos(Pos); +} + +//! gets the minimum value of the scrollbar. +s32 CGUIScrollBar::getMin() const +{ + return Min; +} + +//! sets the minimum value of the scrollbar. +void CGUIScrollBar::setMin(s32 min) +{ + Min = min; + if (Max < Min) + Max = Min; + + bool enable = core::isnotzero(range()); + UpButton->setEnabled(enable); + DownButton->setEnabled(enable); + setPos(Pos); +} + +//! gets the current position of the scrollbar +s32 CGUIScrollBar::getPos() const +{ + return Pos; +} + +//! refreshes the position and text on child buttons +void CGUIScrollBar::refreshControls() +{ + CurrentIconColor = video::SColor(255, 255, 255, 255); + + IGUISkin *skin = Environment->getSkin(); + IGUISpriteBank *sprites = 0; + + if (skin) { + sprites = skin->getSpriteBank(); + CurrentIconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL); + } + + if (Horizontal) { + const s32 h = RelativeRect.getHeight(); + const s32 w = (h < RelativeRect.getWidth() / 2) ? h : RelativeRect.getWidth() / 2; + if (!UpButton) { + UpButton = new CGUIButton(Environment, this, -1, core::rect(0, 0, w, h), NoClip); + UpButton->setSubElement(true); + UpButton->setTabStop(false); + } + if (sprites) { + UpButton->setSpriteBank(sprites); + UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_LEFT), CurrentIconColor); + UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_LEFT), CurrentIconColor); + } + UpButton->setRelativePosition(core::rect(0, 0, w, h)); + UpButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + if (!DownButton) { + DownButton = new CGUIButton(Environment, this, -1, core::rect(RelativeRect.getWidth() - w, 0, RelativeRect.getWidth(), h), NoClip); + DownButton->setSubElement(true); + DownButton->setTabStop(false); + } + if (sprites) { + DownButton->setSpriteBank(sprites); + DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_RIGHT), CurrentIconColor); + DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_RIGHT), CurrentIconColor); + } + DownButton->setRelativePosition(core::rect(RelativeRect.getWidth() - w, 0, RelativeRect.getWidth(), h)); + DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + } else { + const s32 w = RelativeRect.getWidth(); + const s32 h = (w < RelativeRect.getHeight() / 2) ? w : RelativeRect.getHeight() / 2; + if (!UpButton) { + UpButton = new CGUIButton(Environment, this, -1, core::rect(0, 0, w, h), NoClip); + UpButton->setSubElement(true); + UpButton->setTabStop(false); + } + if (sprites) { + UpButton->setSpriteBank(sprites); + UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_UP), CurrentIconColor); + UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_UP), CurrentIconColor); + } + UpButton->setRelativePosition(core::rect(0, 0, w, h)); + UpButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + if (!DownButton) { + DownButton = new CGUIButton(Environment, this, -1, core::rect(0, RelativeRect.getHeight() - h, w, RelativeRect.getHeight()), NoClip); + DownButton->setSubElement(true); + DownButton->setTabStop(false); + } + if (sprites) { + DownButton->setSpriteBank(sprites); + DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), CurrentIconColor); + DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), CurrentIconColor); + } + DownButton->setRelativePosition(core::rect(0, RelativeRect.getHeight() - h, w, RelativeRect.getHeight())); + DownButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT); + } +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIScrollBar.h b/irr/src/CGUIScrollBar.h new file mode 100644 index 000000000..82c5c5c26 --- /dev/null +++ b/irr/src/CGUIScrollBar.h @@ -0,0 +1,95 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIScrollBar.h" +#include "IGUIButton.h" + +namespace irr +{ +namespace gui +{ + +class CGUIScrollBar : public IGUIScrollBar +{ +public: + //! constructor + CGUIScrollBar(bool horizontal, IGUIEnvironment *environment, + IGUIElement *parent, s32 id, core::rect rectangle, + bool noclip = false); + + //! destructor + virtual ~CGUIScrollBar(); + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + + void OnPostRender(u32 timeMs) override; + + //! gets the maximum value of the scrollbar. + s32 getMax() const override; + + //! sets the maximum value of the scrollbar. + void setMax(s32 max) override; + + //! gets the minimum value of the scrollbar. + s32 getMin() const override; + + //! sets the minimum value of the scrollbar. + void setMin(s32 min) override; + + //! gets the small step value + s32 getSmallStep() const override; + + //! sets the small step value + void setSmallStep(s32 step) override; + + //! gets the large step value + s32 getLargeStep() const override; + + //! sets the large step value + void setLargeStep(s32 step) override; + + //! gets the current position of the scrollbar + s32 getPos() const override; + + //! sets the position of the scrollbar + void setPos(s32 pos) override; + + //! updates the rectangle + void updateAbsolutePosition() override; + +private: + void refreshControls(); + s32 getPosFromMousePos(const core::position2di &p) const; + + IGUIButton *UpButton; + IGUIButton *DownButton; + + core::rect SliderRect; + + bool Dragging; + bool Horizontal; + bool DraggedBySlider; + bool TrayClick; + s32 Pos; + s32 DrawPos; + s32 DrawHeight; + s32 Min; + s32 Max; + s32 SmallStep; + s32 LargeStep; + s32 DesiredPos; + u32 LastChange; + video::SColor CurrentIconColor; + + f32 range() const { return (f32)(Max - Min); } +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUISkin.cpp b/irr/src/CGUISkin.cpp new file mode 100644 index 000000000..84ceaeabf --- /dev/null +++ b/irr/src/CGUISkin.cpp @@ -0,0 +1,891 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUISkin.h" + +#include "IGUIFont.h" +#include "IGUISpriteBank.h" +#include "IGUIElement.h" +#include "IVideoDriver.h" +#include "IAttributes.h" + +namespace irr +{ +namespace gui +{ + +CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver *driver) : + SpriteBank(0), Driver(driver), Type(type) +{ +#ifdef _DEBUG + setDebugName("CGUISkin"); +#endif + + if ((Type == EGST_WINDOWS_CLASSIC) || (Type == EGST_WINDOWS_METALLIC)) { + Colors[EGDC_3D_DARK_SHADOW] = video::SColor(101, 50, 50, 50); + Colors[EGDC_3D_SHADOW] = video::SColor(101, 130, 130, 130); + Colors[EGDC_3D_FACE] = video::SColor(101, 210, 210, 210); + Colors[EGDC_3D_HIGH_LIGHT] = video::SColor(101, 255, 255, 255); + Colors[EGDC_3D_LIGHT] = video::SColor(101, 210, 210, 210); + Colors[EGDC_ACTIVE_BORDER] = video::SColor(101, 16, 14, 115); + Colors[EGDC_ACTIVE_CAPTION] = video::SColor(255, 255, 255, 255); + Colors[EGDC_APP_WORKSPACE] = video::SColor(101, 100, 100, 100); + Colors[EGDC_BUTTON_TEXT] = video::SColor(240, 10, 10, 10); + Colors[EGDC_GRAY_TEXT] = video::SColor(240, 130, 130, 130); + Colors[EGDC_HIGH_LIGHT] = video::SColor(101, 8, 36, 107); + Colors[EGDC_HIGH_LIGHT_TEXT] = video::SColor(240, 255, 255, 255); + Colors[EGDC_INACTIVE_BORDER] = video::SColor(101, 165, 165, 165); + Colors[EGDC_INACTIVE_CAPTION] = video::SColor(255, 30, 30, 30); + Colors[EGDC_TOOLTIP] = video::SColor(200, 0, 0, 0); + Colors[EGDC_TOOLTIP_BACKGROUND] = video::SColor(200, 255, 255, 225); + Colors[EGDC_SCROLLBAR] = video::SColor(101, 230, 230, 230); + Colors[EGDC_WINDOW] = video::SColor(101, 255, 255, 255); + Colors[EGDC_WINDOW_SYMBOL] = video::SColor(200, 10, 10, 10); + Colors[EGDC_ICON] = video::SColor(200, 255, 255, 255); + Colors[EGDC_ICON_HIGH_LIGHT] = video::SColor(200, 8, 36, 107); + Colors[EGDC_GRAY_WINDOW_SYMBOL] = video::SColor(240, 100, 100, 100); + Colors[EGDC_EDITABLE] = video::SColor(255, 255, 255, 255); + Colors[EGDC_GRAY_EDITABLE] = video::SColor(255, 120, 120, 120); + Colors[EGDC_FOCUSED_EDITABLE] = video::SColor(255, 240, 240, 255); + + Sizes[EGDS_SCROLLBAR_SIZE] = 14; + Sizes[EGDS_MENU_HEIGHT] = 30; + Sizes[EGDS_WINDOW_BUTTON_WIDTH] = 15; + Sizes[EGDS_CHECK_BOX_WIDTH] = 18; + Sizes[EGDS_MESSAGE_BOX_WIDTH] = 500; + Sizes[EGDS_MESSAGE_BOX_HEIGHT] = 200; + Sizes[EGDS_BUTTON_WIDTH] = 80; + Sizes[EGDS_BUTTON_HEIGHT] = 30; + + Sizes[EGDS_TEXT_DISTANCE_X] = 2; + Sizes[EGDS_TEXT_DISTANCE_Y] = 0; + + Sizes[EGDS_TITLEBARTEXT_DISTANCE_X] = 2; + Sizes[EGDS_TITLEBARTEXT_DISTANCE_Y] = 0; + } else { + // 0x80a6a8af + Colors[EGDC_3D_DARK_SHADOW] = 0x60767982; + // Colors[EGDC_3D_FACE] = 0xc0c9ccd4; // tab background + Colors[EGDC_3D_FACE] = 0xc0cbd2d9; // tab background + Colors[EGDC_3D_SHADOW] = 0x50e4e8f1; // tab background, and left-top highlight + Colors[EGDC_3D_HIGH_LIGHT] = 0x40c7ccdc; + Colors[EGDC_3D_LIGHT] = 0x802e313a; + Colors[EGDC_ACTIVE_BORDER] = 0x80404040; // window title + Colors[EGDC_ACTIVE_CAPTION] = 0xffd0d0d0; + Colors[EGDC_APP_WORKSPACE] = 0xc0646464; // unused + Colors[EGDC_BUTTON_TEXT] = 0xd0161616; + Colors[EGDC_GRAY_TEXT] = 0x3c141414; + Colors[EGDC_HIGH_LIGHT] = 0x6c606060; + Colors[EGDC_HIGH_LIGHT_TEXT] = 0xd0e0e0e0; + Colors[EGDC_INACTIVE_BORDER] = 0xf0a5a5a5; + Colors[EGDC_INACTIVE_CAPTION] = 0xffd2d2d2; + Colors[EGDC_TOOLTIP] = 0xf00f2033; + Colors[EGDC_TOOLTIP_BACKGROUND] = 0xc0cbd2d9; + Colors[EGDC_SCROLLBAR] = 0xf0e0e0e0; + Colors[EGDC_WINDOW] = 0xf0f0f0f0; + Colors[EGDC_WINDOW_SYMBOL] = 0xd0161616; + Colors[EGDC_ICON] = 0xd0161616; + Colors[EGDC_ICON_HIGH_LIGHT] = 0xd0606060; + Colors[EGDC_GRAY_WINDOW_SYMBOL] = 0x3c101010; + Colors[EGDC_EDITABLE] = 0xf0ffffff; + Colors[EGDC_GRAY_EDITABLE] = 0xf0cccccc; + Colors[EGDC_FOCUSED_EDITABLE] = 0xf0fffff0; + + Sizes[EGDS_SCROLLBAR_SIZE] = 14; + Sizes[EGDS_MENU_HEIGHT] = 48; + Sizes[EGDS_WINDOW_BUTTON_WIDTH] = 15; + Sizes[EGDS_CHECK_BOX_WIDTH] = 18; + Sizes[EGDS_MESSAGE_BOX_WIDTH] = 500; + Sizes[EGDS_MESSAGE_BOX_HEIGHT] = 200; + Sizes[EGDS_BUTTON_WIDTH] = 80; + Sizes[EGDS_BUTTON_HEIGHT] = 30; + + Sizes[EGDS_TEXT_DISTANCE_X] = 3; + Sizes[EGDS_TEXT_DISTANCE_Y] = 2; + + Sizes[EGDS_TITLEBARTEXT_DISTANCE_X] = 3; + Sizes[EGDS_TITLEBARTEXT_DISTANCE_Y] = 2; + } + + Sizes[EGDS_MESSAGE_BOX_GAP_SPACE] = 15; + Sizes[EGDS_MESSAGE_BOX_MIN_TEXT_WIDTH] = 0; + Sizes[EGDS_MESSAGE_BOX_MAX_TEXT_WIDTH] = 500; + Sizes[EGDS_MESSAGE_BOX_MIN_TEXT_HEIGHT] = 0; + Sizes[EGDS_MESSAGE_BOX_MAX_TEXT_HEIGHT] = 99999; + + Sizes[EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X] = 1; + Sizes[EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y] = 1; + Sizes[EGDS_BUTTON_PRESSED_TEXT_OFFSET_X] = 0; + Sizes[EGDS_BUTTON_PRESSED_TEXT_OFFSET_Y] = 2; + Sizes[EGDS_BUTTON_PRESSED_SPRITE_OFFSET_X] = 0; + Sizes[EGDS_BUTTON_PRESSED_SPRITE_OFFSET_Y] = 0; + + Texts[EGDT_MSG_BOX_OK] = L"OK"; + Texts[EGDT_MSG_BOX_CANCEL] = L"Cancel"; + Texts[EGDT_MSG_BOX_YES] = L"Yes"; + Texts[EGDT_MSG_BOX_NO] = L"No"; + Texts[EGDT_WINDOW_CLOSE] = L"Close"; + Texts[EGDT_WINDOW_RESTORE] = L"Restore"; + Texts[EGDT_WINDOW_MINIMIZE] = L"Minimize"; + Texts[EGDT_WINDOW_MAXIMIZE] = L"Maximize"; + + Icons[EGDI_WINDOW_MAXIMIZE] = 225; + Icons[EGDI_WINDOW_RESTORE] = 226; + Icons[EGDI_WINDOW_CLOSE] = 227; + Icons[EGDI_WINDOW_MINIMIZE] = 228; + Icons[EGDI_CURSOR_UP] = 229; + Icons[EGDI_CURSOR_DOWN] = 230; + Icons[EGDI_CURSOR_LEFT] = 231; + Icons[EGDI_CURSOR_RIGHT] = 232; + Icons[EGDI_MENU_MORE] = 232; + Icons[EGDI_CHECK_BOX_CHECKED] = 233; + Icons[EGDI_DROP_DOWN] = 234; + Icons[EGDI_SMALL_CURSOR_UP] = 235; + Icons[EGDI_SMALL_CURSOR_DOWN] = 236; + Icons[EGDI_RADIO_BUTTON_CHECKED] = 237; + Icons[EGDI_MORE_LEFT] = 238; + Icons[EGDI_MORE_RIGHT] = 239; + Icons[EGDI_MORE_UP] = 240; + Icons[EGDI_MORE_DOWN] = 241; + Icons[EGDI_WINDOW_RESIZE] = 242; + Icons[EGDI_EXPAND] = 243; + Icons[EGDI_COLLAPSE] = 244; + + Icons[EGDI_FILE] = 245; + Icons[EGDI_DIRECTORY] = 246; + + for (u32 i = 0; i < EGDF_COUNT; ++i) + Fonts[i] = 0; + + UseGradient = (Type == EGST_WINDOWS_METALLIC) || (Type == EGST_BURNING_SKIN); +} + +//! destructor +CGUISkin::~CGUISkin() +{ + for (u32 i = 0; i < EGDF_COUNT; ++i) { + if (Fonts[i]) + Fonts[i]->drop(); + } + + if (SpriteBank) + SpriteBank->drop(); +} + +//! returns default color +video::SColor CGUISkin::getColor(EGUI_DEFAULT_COLOR color) const +{ + if ((u32)color < EGDC_COUNT) + return Colors[color]; + else + return video::SColor(); +} + +//! sets a default color +void CGUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor) +{ + if ((u32)which < EGDC_COUNT) + Colors[which] = newColor; +} + +//! returns size for the given size type +s32 CGUISkin::getSize(EGUI_DEFAULT_SIZE size) const +{ + if ((u32)size < EGDS_COUNT) + return Sizes[size]; + else + return 0; +} + +//! sets a default size +void CGUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size) +{ + if ((u32)which < EGDS_COUNT) + Sizes[which] = size; +} + +//! returns the default font +IGUIFont *CGUISkin::getFont(EGUI_DEFAULT_FONT which) const +{ + if (((u32)which < EGDF_COUNT) && Fonts[which]) + return Fonts[which]; + else + return Fonts[EGDF_DEFAULT]; +} + +//! sets a default font +void CGUISkin::setFont(IGUIFont *font, EGUI_DEFAULT_FONT which) +{ + if ((u32)which >= EGDF_COUNT) + return; + + if (font) { + font->grab(); + if (Fonts[which]) + Fonts[which]->drop(); + + Fonts[which] = font; + } +} + +//! gets the sprite bank stored +IGUISpriteBank *CGUISkin::getSpriteBank() const +{ + return SpriteBank; +} + +//! set a new sprite bank or remove one by passing 0 +void CGUISkin::setSpriteBank(IGUISpriteBank *bank) +{ + if (bank) + bank->grab(); + + if (SpriteBank) + SpriteBank->drop(); + + SpriteBank = bank; +} + +//! Returns a default icon +u32 CGUISkin::getIcon(EGUI_DEFAULT_ICON icon) const +{ + if ((u32)icon < EGDI_COUNT) + return Icons[icon]; + else + return 0; +} + +//! Sets a default icon +void CGUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index) +{ + if ((u32)icon < EGDI_COUNT) + Icons[icon] = index; +} + +//! Returns a default text. For example for Message box button captions: +//! "OK", "Cancel", "Yes", "No" and so on. +const wchar_t *CGUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const +{ + if ((u32)text < EGDT_COUNT) + return Texts[text].c_str(); + else + return Texts[0].c_str(); +} + +//! Sets a default text. For example for Message box button captions: +//! "OK", "Cancel", "Yes", "No" and so on. +void CGUISkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t *newText) +{ + if ((u32)which < EGDT_COUNT) + Texts[which] = newText; +} + +//! draws a standard 3d button pane +/** Used for drawing for example buttons in normal state. +It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and +EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. +\param rect: Defining area where to draw. +\param clip: Clip area. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. */ +void CGUISkin::draw3DButtonPaneStandard(IGUIElement *element, + const core::rect &r, + const core::rect *clip) +{ + if (!Driver) + return; + + core::rect rect = r; + + if (Type == EGST_BURNING_SKIN) { + rect.UpperLeftCorner.X -= 1; + rect.UpperLeftCorner.Y -= 1; + rect.LowerRightCorner.X += 1; + rect.LowerRightCorner.Y += 1; + draw3DSunkenPane(element, + getColor(EGDC_WINDOW).getInterpolated(0xFFFFFFFF, 0.9f), false, true, rect, clip); + return; + } + + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + + rect.LowerRightCorner.X -= 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); + + rect.LowerRightCorner.X -= 1; + rect.LowerRightCorner.Y -= 1; + + if (!UseGradient) { + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), rect, clip); + } else { + const video::SColor c1 = getColor(EGDC_3D_FACE); + const video::SColor c2 = c1.getInterpolated(getColor(EGDC_3D_DARK_SHADOW), 0.4f); + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} + +//! draws a pressed 3d button pane +/** Used for drawing for example buttons in pressed state. +It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and +EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. +\param rect: Defining area where to draw. +\param clip: Clip area. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. */ +void CGUISkin::draw3DButtonPanePressed(IGUIElement *element, + const core::rect &r, + const core::rect *clip) +{ + if (!Driver) + return; + + core::rect rect = r; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); + + rect.LowerRightCorner.X -= 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + + if (!UseGradient) { + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), rect, clip); + } else { + const video::SColor c1 = getColor(EGDC_3D_FACE); + const video::SColor c2 = c1.getInterpolated(getColor(EGDC_3D_DARK_SHADOW), 0.4f); + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} + +//! draws a sunken 3d pane +/** Used for drawing the background of edit, combo or check boxes. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param bgcolor: Background color. +\param flat: Specifies if the sunken pane should be flat or displayed as sunken +deep into the ground. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +void CGUISkin::draw3DSunkenPane(IGUIElement *element, video::SColor bgcolor, + bool flat, bool fillBackGround, + const core::rect &r, + const core::rect *clip) +{ + if (!Driver) + return; + + core::rect rect = r; + + if (fillBackGround) + Driver->draw2DRectangle(bgcolor, rect, clip); + + if (flat) { + // draw flat sunken pane + + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); // top + + ++rect.UpperLeftCorner.Y; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); // left + + rect = r; + ++rect.UpperLeftCorner.Y; + rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); // right + + rect = r; + ++rect.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + --rect.LowerRightCorner.X; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); // bottom + } else { + // draw deep sunken pane + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); // top + ++rect.UpperLeftCorner.X; + ++rect.UpperLeftCorner.Y; + --rect.LowerRightCorner.X; + ++rect.LowerRightCorner.Y; + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y + 1; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); // left + ++rect.UpperLeftCorner.X; + ++rect.UpperLeftCorner.Y; + ++rect.LowerRightCorner.X; + --rect.LowerRightCorner.Y; + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + + rect = r; + rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + ++rect.UpperLeftCorner.Y; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); // right + --rect.UpperLeftCorner.X; + ++rect.UpperLeftCorner.Y; + --rect.LowerRightCorner.X; + --rect.LowerRightCorner.Y; + Driver->draw2DRectangle(getColor(EGDC_3D_LIGHT), rect, clip); + + rect = r; + ++rect.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + --rect.LowerRightCorner.X; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); // bottom + ++rect.UpperLeftCorner.X; + --rect.UpperLeftCorner.Y; + --rect.LowerRightCorner.X; + --rect.LowerRightCorner.Y; + Driver->draw2DRectangle(getColor(EGDC_3D_LIGHT), rect, clip); + } +} + +//! draws a window background +// return where to draw title bar text. +core::rect CGUISkin::draw3DWindowBackground(IGUIElement *element, + bool drawTitleBar, video::SColor titleBarColor, + const core::rect &r, + const core::rect *clip, + core::rect *checkClientArea) +{ + if (!Driver) { + if (checkClientArea) { + *checkClientArea = r; + } + return r; + } + + core::rect rect = r; + + // top border + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + if (!checkClientArea) { + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); + } + + // left border + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + if (!checkClientArea) { + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); + } + + // right border dark outer line + rect.UpperLeftCorner.X = r.LowerRightCorner.X - 1; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + if (!checkClientArea) { + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + } + + // right border bright innner line + rect.UpperLeftCorner.X -= 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y += 1; + rect.LowerRightCorner.Y -= 1; + if (!checkClientArea) { + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); + } + + // bottom border dark outer line + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + if (!checkClientArea) { + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + } + + // bottom border bright inner line + rect.UpperLeftCorner.X += 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y -= 1; + rect.LowerRightCorner.Y -= 1; + if (!checkClientArea) { + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); + } + + // client area for background + rect = r; + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + rect.LowerRightCorner.X -= 2; + rect.LowerRightCorner.Y -= 2; + if (checkClientArea) { + *checkClientArea = rect; + } + + if (!checkClientArea) { + if (!UseGradient) { + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), rect, clip); + } else if (Type == EGST_BURNING_SKIN) { + const video::SColor c1 = getColor(EGDC_WINDOW).getInterpolated(0xFFFFFFFF, 0.9f); + const video::SColor c2 = getColor(EGDC_WINDOW).getInterpolated(0xFFFFFFFF, 0.8f); + + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } else { + const video::SColor c2 = getColor(EGDC_3D_SHADOW); + const video::SColor c1 = getColor(EGDC_3D_FACE); + Driver->draw2DRectangle(rect, c1, c1, c1, c2, clip); + } + } + + // title bar + rect = r; + rect.UpperLeftCorner.X += 2; + rect.UpperLeftCorner.Y += 2; + rect.LowerRightCorner.X -= 2; + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + getSize(EGDS_WINDOW_BUTTON_WIDTH) + 2; + + if (drawTitleBar) { + if (checkClientArea) { + (*checkClientArea).UpperLeftCorner.Y = rect.LowerRightCorner.Y; + } else { + // draw title bar + // if (!UseGradient) + // Driver->draw2DRectangle(titleBarColor, rect, clip); + // else + if (Type == EGST_BURNING_SKIN) { + const video::SColor c = titleBarColor.getInterpolated(video::SColor(titleBarColor.getAlpha(), 255, 255, 255), 0.8f); + Driver->draw2DRectangle(rect, titleBarColor, titleBarColor, c, c, clip); + } else { + const video::SColor c = titleBarColor.getInterpolated(video::SColor(titleBarColor.getAlpha(), 0, 0, 0), 0.2f); + Driver->draw2DRectangle(rect, titleBarColor, c, titleBarColor, c, clip); + } + } + } + + return rect; +} + +//! draws a standard 3d menu pane +/** Used for drawing for menus and context menus. +It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and +EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +void CGUISkin::draw3DMenuPane(IGUIElement *element, + const core::rect &r, const core::rect *clip) +{ + if (!Driver) + return; + + core::rect rect = r; + + if (Type == EGST_BURNING_SKIN) { + rect.UpperLeftCorner.Y -= 3; + draw3DButtonPaneStandard(element, rect, clip); + return; + } + + // in this skin, this is exactly what non pressed buttons look like, + // so we could simply call + // draw3DButtonPaneStandard(element, rect, clip); + // here. + // but if the skin is transparent, this doesn't look that nice. So + // We draw it a little bit better, with some more draw2DRectangle calls, + // but there aren't that much menus visible anyway. + + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); + + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), rect, clip); + + rect.UpperLeftCorner.X = r.LowerRightCorner.X - 1; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + + rect.UpperLeftCorner.X -= 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y += 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); + + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y -= 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); + + rect = r; + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + rect.LowerRightCorner.X -= 2; + rect.LowerRightCorner.Y -= 2; + + if (!UseGradient) + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), rect, clip); + else { + const video::SColor c1 = getColor(EGDC_3D_FACE); + const video::SColor c2 = getColor(EGDC_3D_SHADOW); + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} + +//! draws a standard 3d tool bar +/** Used for drawing for toolbars and menus. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +void CGUISkin::draw3DToolBar(IGUIElement *element, + const core::rect &r, + const core::rect *clip) +{ + if (!Driver) + return; + + core::rect rect = r; + + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), rect, clip); + + rect = r; + rect.LowerRightCorner.Y -= 1; + + if (!UseGradient) { + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), rect, clip); + } else if (Type == EGST_BURNING_SKIN) { + const video::SColor c1 = 0xF0000000 | getColor(EGDC_3D_FACE).color; + const video::SColor c2 = 0xF0000000 | getColor(EGDC_3D_SHADOW).color; + + rect.LowerRightCorner.Y += 1; + Driver->draw2DRectangle(rect, c1, c2, c1, c2, clip); + } else { + const video::SColor c1 = getColor(EGDC_3D_FACE); + const video::SColor c2 = getColor(EGDC_3D_SHADOW); + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} + +//! draws a tab button +/** Used for drawing for tab buttons on top of tabs. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param active: Specifies if the tab is currently active. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +void CGUISkin::draw3DTabButton(IGUIElement *element, bool active, + const core::rect &frameRect, const core::rect *clip, EGUI_ALIGNMENT alignment) +{ + if (!Driver) + return; + + core::rect tr = frameRect; + + if (alignment == EGUIA_UPPERLEFT) { + tr.LowerRightCorner.X -= 2; + tr.LowerRightCorner.Y = tr.UpperLeftCorner.Y + 1; + tr.UpperLeftCorner.X += 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), tr, clip); + + // draw left highlight + tr = frameRect; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + tr.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), tr, clip); + + // draw grey background + tr = frameRect; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y += 1; + tr.LowerRightCorner.X -= 2; + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), tr, clip); + + // draw right middle gray shadow + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X = tr.LowerRightCorner.X - 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), tr, clip); + + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), tr, clip); + } else { + tr.LowerRightCorner.X -= 2; + tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1; + tr.UpperLeftCorner.X += 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), tr, clip); + + // draw left highlight + tr = frameRect; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), tr, clip); + + // draw grey background + tr = frameRect; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y -= 1; + tr.LowerRightCorner.X -= 2; + tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), tr, clip); + + // draw right middle gray shadow + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X = tr.LowerRightCorner.X - 1; + // tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), tr, clip); + + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X += 1; + tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(getColor(EGDC_3D_DARK_SHADOW), tr, clip); + } +} + +//! draws a tab control body +/** \param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param border: Specifies if the border should be drawn. +\param background: Specifies if the background should be drawn. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +void CGUISkin::draw3DTabBody(IGUIElement *element, bool border, bool background, + const core::rect &rect, const core::rect *clip, s32 tabHeight, EGUI_ALIGNMENT alignment) +{ + if (!Driver) + return; + + core::rect tr = rect; + + if (tabHeight == -1) + tabHeight = getSize(gui::EGDS_BUTTON_HEIGHT); + + // draw border. + if (border) { + if (alignment == EGUIA_UPPERLEFT) { + // draw left hightlight + tr.UpperLeftCorner.Y += tabHeight + 2; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), tr, clip); + + // draw right shadow + tr.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), tr, clip); + + // draw lower shadow + tr = rect; + tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), tr, clip); + } else { + // draw left hightlight + tr.LowerRightCorner.Y -= tabHeight + 2; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), tr, clip); + + // draw right shadow + tr.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_SHADOW), tr, clip); + + // draw lower shadow + tr = rect; + tr.LowerRightCorner.Y = tr.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(getColor(EGDC_3D_HIGH_LIGHT), tr, clip); + } + } + + if (background) { + if (alignment == EGUIA_UPPERLEFT) { + tr = rect; + tr.UpperLeftCorner.Y += tabHeight + 2; + tr.LowerRightCorner.X -= 1; + tr.UpperLeftCorner.X += 1; + tr.LowerRightCorner.Y -= 1; + } else { + tr = rect; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y -= 1; + tr.LowerRightCorner.X -= 1; + tr.LowerRightCorner.Y -= tabHeight + 2; + // tr.UpperLeftCorner.X += 1; + } + + if (!UseGradient) + Driver->draw2DRectangle(getColor(EGDC_3D_FACE), tr, clip); + else { + video::SColor c1 = getColor(EGDC_3D_FACE); + video::SColor c2 = getColor(EGDC_3D_SHADOW); + Driver->draw2DRectangle(tr, c1, c1, c2, c2, clip); + } + } +} + +//! draws an icon, usually from the skin's sprite bank +/** \param parent: Pointer to the element which wishes to draw this icon. +This parameter is usually not used by IGUISkin, but can be used for example +by more complex implementations to find out how to draw the part exactly. +\param icon: Specifies the icon to be drawn. +\param position: The position to draw the icon +\param starttime: The time at the start of the animation +\param currenttime: The present time, used to calculate the frame number +\param loop: Whether the animation should loop or not +\param clip: Clip area. */ +void CGUISkin::drawIcon(IGUIElement *element, EGUI_DEFAULT_ICON icon, + const core::position2di position, + u32 starttime, u32 currenttime, + bool loop, const core::rect *clip) +{ + if (!SpriteBank) + return; + + bool gray = element && !element->isEnabled(); + SpriteBank->draw2DSprite(Icons[icon], position, clip, + Colors[gray ? EGDC_GRAY_WINDOW_SYMBOL : EGDC_WINDOW_SYMBOL], starttime, currenttime, loop, true); +} + +EGUI_SKIN_TYPE CGUISkin::getType() const +{ + return Type; +} + +//! draws a 2d rectangle. +void CGUISkin::draw2DRectangle(IGUIElement *element, + const video::SColor &color, const core::rect &pos, + const core::rect *clip) +{ + Driver->draw2DRectangle(color, pos, clip); +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUISkin.h b/irr/src/CGUISkin.h new file mode 100644 index 000000000..130e5fada --- /dev/null +++ b/irr/src/CGUISkin.h @@ -0,0 +1,226 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUISkin.h" +#include "irrString.h" + +namespace irr +{ +namespace video +{ +class IVideoDriver; +} +namespace gui +{ + +class CGUISkin : public IGUISkin +{ +public: + CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver *driver); + + //! destructor + virtual ~CGUISkin(); + + //! returns default color + video::SColor getColor(EGUI_DEFAULT_COLOR color) const override; + + //! sets a default color + void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor) override; + + //! returns size for the given size type + s32 getSize(EGUI_DEFAULT_SIZE size) const override; + + //! sets a default size + void setSize(EGUI_DEFAULT_SIZE which, s32 size) override; + + //! returns the default font + IGUIFont *getFont(EGUI_DEFAULT_FONT which = EGDF_DEFAULT) const override; + + //! sets a default font + void setFont(IGUIFont *font, EGUI_DEFAULT_FONT which = EGDF_DEFAULT) override; + + //! sets the sprite bank used for drawing icons + void setSpriteBank(IGUISpriteBank *bank) override; + + //! gets the sprite bank used for drawing icons + IGUISpriteBank *getSpriteBank() const override; + + //! Returns a default icon + /** Returns the sprite index within the sprite bank */ + u32 getIcon(EGUI_DEFAULT_ICON icon) const override; + + //! Sets a default icon + /** Sets the sprite index used for drawing icons like arrows, + close buttons and ticks in checkboxes + \param icon: Enum specifying which icon to change + \param index: The sprite index used to draw this icon */ + void setIcon(EGUI_DEFAULT_ICON icon, u32 index) override; + + //! Returns a default text. + /** For example for Message box button captions: + "OK", "Cancel", "Yes", "No" and so on. */ + const wchar_t *getDefaultText(EGUI_DEFAULT_TEXT text) const override; + + //! Sets a default text. + /** For example for Message box button captions: + "OK", "Cancel", "Yes", "No" and so on. */ + void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t *newText) override; + + //! draws a standard 3d button pane + /** Used for drawing for example buttons in normal state. + It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and + EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. + \param rect: Defining area where to draw. + \param clip: Clip area. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. */ + virtual void draw3DButtonPaneStandard(IGUIElement *element, + const core::rect &rect, + const core::rect *clip = 0) override; + + //! draws a pressed 3d button pane + /** Used for drawing for example buttons in pressed state. + It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and + EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. + \param rect: Defining area where to draw. + \param clip: Clip area. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. */ + virtual void draw3DButtonPanePressed(IGUIElement *element, + const core::rect &rect, + const core::rect *clip = 0) override; + + //! draws a sunken 3d pane + /** Used for drawing the background of edit, combo or check boxes. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param bgcolor: Background color. + \param flat: Specifies if the sunken pane should be flat or displayed as sunken + deep into the ground. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DSunkenPane(IGUIElement *element, + video::SColor bgcolor, bool flat, + bool fillBackGround, + const core::rect &rect, + const core::rect *clip = 0) override; + + //! draws a window background + /** Used for drawing the background of dialogs and windows. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param titleBarColor: Title color. + \param drawTitleBar: True to enable title drawing. + \param rect: Defining area where to draw. + \param clip: Clip area. + \param checkClientArea: When set to non-null the function will not draw anything, + but will instead return the clientArea which can be used for drawing by the calling window. + That is the area without borders and without titlebar. + \return Returns rect where it would be good to draw title bar text. This will + work even when checkClientArea is set to a non-null value.*/ + virtual core::rect draw3DWindowBackground(IGUIElement *element, + bool drawTitleBar, video::SColor titleBarColor, + const core::rect &rect, + const core::rect *clip, + core::rect *checkClientArea) override; + + //! draws a standard 3d menu pane + /** Used for drawing for menus and context menus. + It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and + EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DMenuPane(IGUIElement *element, + const core::rect &rect, + const core::rect *clip = 0) override; + + //! draws a standard 3d tool bar + /** Used for drawing for toolbars and menus. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DToolBar(IGUIElement *element, + const core::rect &rect, + const core::rect *clip = 0) override; + + //! draws a tab button + /** Used for drawing for tab buttons on top of tabs. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param active: Specifies if the tab is currently active. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DTabButton(IGUIElement *element, bool active, + const core::rect &rect, const core::rect *clip = 0, + EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT) override; + + //! draws a tab control body + /** \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param border: Specifies if the border should be drawn. + \param background: Specifies if the background should be drawn. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DTabBody(IGUIElement *element, bool border, bool background, + const core::rect &rect, const core::rect *clip = 0, s32 tabHeight = -1, + EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT) override; + + //! draws an icon, usually from the skin's sprite bank + /** \param element: Pointer to the element which wishes to draw this icon. + This parameter is usually not used by IGUISkin, but can be used for example + by more complex implementations to find out how to draw the part exactly. + \param icon: Specifies the icon to be drawn. + \param position: The position to draw the icon + \param starttime: The time at the start of the animation + \param currenttime: The present time, used to calculate the frame number + \param loop: Whether the animation should loop or not + \param clip: Clip area. */ + virtual void drawIcon(IGUIElement *element, EGUI_DEFAULT_ICON icon, + const core::position2di position, + u32 starttime = 0, u32 currenttime = 0, + bool loop = false, const core::rect *clip = 0) override; + + //! draws a 2d rectangle. + /** \param element: Pointer to the element which wishes to draw this icon. + This parameter is usually not used by IGUISkin, but can be used for example + by more complex implementations to find out how to draw the part exactly. + \param color: Color of the rectangle to draw. The alpha component specifies how + transparent the rectangle will be. + \param pos: Position of the rectangle. + \param clip: Pointer to rectangle against which the rectangle will be clipped. + If the pointer is null, no clipping will be performed. */ + virtual void draw2DRectangle(IGUIElement *element, const video::SColor &color, + const core::rect &pos, const core::rect *clip = 0) override; + + //! get the type of this skin + EGUI_SKIN_TYPE getType() const override; + +private: + video::SColor Colors[EGDC_COUNT]; + s32 Sizes[EGDS_COUNT]; + u32 Icons[EGDI_COUNT]; + IGUIFont *Fonts[EGDF_COUNT]; + IGUISpriteBank *SpriteBank; + core::stringw Texts[EGDT_COUNT]; + video::IVideoDriver *Driver; + bool UseGradient; + + EGUI_SKIN_TYPE Type; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUISpriteBank.cpp b/irr/src/CGUISpriteBank.cpp new file mode 100644 index 000000000..fe0c087b8 --- /dev/null +++ b/irr/src/CGUISpriteBank.cpp @@ -0,0 +1,246 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUISpriteBank.h" + +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "ITexture.h" + +namespace irr +{ +namespace gui +{ + +CGUISpriteBank::CGUISpriteBank(IGUIEnvironment *env) : + Environment(env), Driver(0) +{ +#ifdef _DEBUG + setDebugName("CGUISpriteBank"); +#endif + + if (Environment) { + Driver = Environment->getVideoDriver(); + if (Driver) + Driver->grab(); + } +} + +CGUISpriteBank::~CGUISpriteBank() +{ + clear(); + + // drop video driver + if (Driver) + Driver->drop(); +} + +core::array> &CGUISpriteBank::getPositions() +{ + return Rectangles; +} + +core::array &CGUISpriteBank::getSprites() +{ + return Sprites; +} + +u32 CGUISpriteBank::getTextureCount() const +{ + return Textures.size(); +} + +video::ITexture *CGUISpriteBank::getTexture(u32 index) const +{ + if (index < Textures.size()) + return Textures[index]; + else + return 0; +} + +void CGUISpriteBank::addTexture(video::ITexture *texture) +{ + if (texture) + texture->grab(); + + Textures.push_back(texture); +} + +void CGUISpriteBank::setTexture(u32 index, video::ITexture *texture) +{ + while (index >= Textures.size()) + Textures.push_back(0); + + if (texture) + texture->grab(); + + if (Textures[index]) + Textures[index]->drop(); + + Textures[index] = texture; +} + +//! clear everything +void CGUISpriteBank::clear() +{ + // drop textures + for (u32 i = 0; i < Textures.size(); ++i) { + if (Textures[i]) + Textures[i]->drop(); + } + Textures.clear(); + Sprites.clear(); + Rectangles.clear(); +} + +//! Add the texture and use it for a single non-animated sprite. +s32 CGUISpriteBank::addTextureAsSprite(video::ITexture *texture) +{ + if (!texture) + return -1; + + addTexture(texture); + u32 textureIndex = getTextureCount() - 1; + + u32 rectangleIndex = Rectangles.size(); + Rectangles.push_back(core::rect(0, 0, texture->getOriginalSize().Width, texture->getOriginalSize().Height)); + + SGUISprite sprite; + sprite.frameTime = 0; + + SGUISpriteFrame frame; + frame.textureNumber = textureIndex; + frame.rectNumber = rectangleIndex; + sprite.Frames.push_back(frame); + + Sprites.push_back(sprite); + + return Sprites.size() - 1; +} + +// get FrameNr for time. return true on exisiting frame +inline bool CGUISpriteBank::getFrameNr(u32 &frame, u32 index, u32 time, bool loop) const +{ + frame = 0; + if (index >= Sprites.size()) + return false; + + const SGUISprite &sprite = Sprites[index]; + const u32 frameSize = sprite.Frames.size(); + if (frameSize < 1) + return false; + + if (sprite.frameTime) { + u32 f = (time / sprite.frameTime); + if (loop) + frame = f % frameSize; + else + frame = (f >= frameSize) ? frameSize - 1 : f; + } + return true; +} + +//! draws a sprite in 2d with scale and color +void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di &pos, + const core::rect *clip, const video::SColor &color, + u32 starttime, u32 currenttime, bool loop, bool center) +{ + u32 frame = 0; + if (!getFrameNr(frame, index, currenttime - starttime, loop)) + return; + + const video::ITexture *tex = getTexture(Sprites[index].Frames[frame].textureNumber); + if (!tex) + return; + + const u32 rn = Sprites[index].Frames[frame].rectNumber; + if (rn >= Rectangles.size()) + return; + + const core::rect &r = Rectangles[rn]; + core::position2di p(pos); + if (center) { + p -= r.getSize() / 2; + } + Driver->draw2DImage(tex, p, r, clip, color, true); +} + +void CGUISpriteBank::draw2DSprite(u32 index, const core::rect &destRect, + const core::rect *clip, const video::SColor *const colors, + u32 timeTicks, bool loop) +{ + u32 frame = 0; + if (!getFrameNr(frame, index, timeTicks, loop)) + return; + + const video::ITexture *tex = getTexture(Sprites[index].Frames[frame].textureNumber); + if (!tex) + return; + + const u32 rn = Sprites[index].Frames[frame].rectNumber; + if (rn >= Rectangles.size()) + return; + + Driver->draw2DImage(tex, destRect, Rectangles[rn], clip, colors, true); +} + +void CGUISpriteBank::draw2DSpriteBatch(const core::array &indices, + const core::array &pos, + const core::rect *clip, + const video::SColor &color, + u32 starttime, u32 currenttime, + bool loop, bool center) +{ + const irr::u32 drawCount = core::min_(indices.size(), pos.size()); + + if (!getTextureCount()) + return; + core::array drawBatches(getTextureCount()); + for (u32 i = 0; i < Textures.size(); ++i) { + drawBatches.push_back(SDrawBatch()); + drawBatches[i].positions.reallocate(drawCount); + drawBatches[i].sourceRects.reallocate(drawCount); + } + + for (u32 i = 0; i < drawCount; ++i) { + const u32 index = indices[i]; + + // work out frame number + u32 frame = 0; + if (!getFrameNr(frame, index, currenttime - starttime, loop)) + return; + + const u32 texNum = Sprites[index].Frames[frame].textureNumber; + if (texNum >= drawBatches.size()) { + continue; + } + SDrawBatch ¤tBatch = drawBatches[texNum]; + + const u32 rn = Sprites[index].Frames[frame].rectNumber; + if (rn >= Rectangles.size()) + return; + + const core::rect &r = Rectangles[rn]; + + if (center) { + core::position2di p = pos[i]; + p -= r.getSize() / 2; + + currentBatch.positions.push_back(p); + currentBatch.sourceRects.push_back(r); + } else { + currentBatch.positions.push_back(pos[i]); + currentBatch.sourceRects.push_back(r); + } + } + + for (u32 i = 0; i < drawBatches.size(); i++) { + if (!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty()) + Driver->draw2DImageBatch(getTexture(i), drawBatches[i].positions, + drawBatches[i].sourceRects, clip, color, true); + } +} + +} // namespace gui +} // namespace irr diff --git a/irr/src/CGUISpriteBank.h b/irr/src/CGUISpriteBank.h new file mode 100644 index 000000000..f46ca8b15 --- /dev/null +++ b/irr/src/CGUISpriteBank.h @@ -0,0 +1,81 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUISpriteBank.h" + +namespace irr +{ + +namespace video +{ +class IVideoDriver; +class ITexture; +} + +namespace gui +{ + +class IGUIEnvironment; + +//! Sprite bank interface. +class CGUISpriteBank : public IGUISpriteBank +{ +public: + CGUISpriteBank(IGUIEnvironment *env); + virtual ~CGUISpriteBank(); + + core::array> &getPositions() override; + core::array &getSprites() override; + + u32 getTextureCount() const override; + video::ITexture *getTexture(u32 index) const override; + void addTexture(video::ITexture *texture) override; + void setTexture(u32 index, video::ITexture *texture) override; + + //! Add the texture and use it for a single non-animated sprite. + s32 addTextureAsSprite(video::ITexture *texture) override; + + //! clears sprites, rectangles and textures + void clear() override; + + //! Draws a sprite in 2d with position and color + virtual void draw2DSprite(u32 index, const core::position2di &pos, const core::rect *clip = 0, + const video::SColor &color = video::SColor(255, 255, 255, 255), + u32 starttime = 0, u32 currenttime = 0, bool loop = true, bool center = false) override; + + //! Draws a sprite in 2d with destination rectangle and colors + virtual void draw2DSprite(u32 index, const core::rect &destRect, + const core::rect *clip = 0, + const video::SColor *const colors = 0, + u32 timeTicks = 0, + bool loop = true) override; + + //! Draws a sprite batch in 2d using an array of positions and a color + virtual void draw2DSpriteBatch(const core::array &indices, const core::array &pos, + const core::rect *clip = 0, + const video::SColor &color = video::SColor(255, 255, 255, 255), + u32 starttime = 0, u32 currenttime = 0, + bool loop = true, bool center = false) override; + +protected: + bool getFrameNr(u32 &frameNr, u32 index, u32 time, bool loop) const; + + struct SDrawBatch + { + core::array positions; + core::array sourceRects; + u32 textureNumber; + }; + + core::array Sprites; + core::array> Rectangles; + core::array Textures; + IGUIEnvironment *Environment; + video::IVideoDriver *Driver; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIStaticText.cpp b/irr/src/CGUIStaticText.cpp new file mode 100644 index 000000000..035847583 --- /dev/null +++ b/irr/src/CGUIStaticText.cpp @@ -0,0 +1,511 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUIStaticText.h" + +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IGUIFont.h" +#include "IVideoDriver.h" +#include "rect.h" + +namespace irr +{ +namespace gui +{ + +//! constructor +CGUIStaticText::CGUIStaticText(const wchar_t *text, bool border, + IGUIEnvironment *environment, IGUIElement *parent, + s32 id, const core::rect &rectangle, + bool background) : + IGUIStaticText(environment, parent, id, rectangle), + HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_UPPERLEFT), + Border(border), OverrideColorEnabled(false), OverrideBGColorEnabled(false), WordWrap(false), Background(background), + RestrainTextInside(true), RightToLeft(false), + OverrideColor(video::SColor(101, 255, 255, 255)), BGColor(video::SColor(101, 210, 210, 210)), + OverrideFont(0), LastBreakFont(0) +{ +#ifdef _DEBUG + setDebugName("CGUIStaticText"); +#endif + + Text = text; + if (environment && environment->getSkin()) { + BGColor = environment->getSkin()->getColor(gui::EGDC_3D_FACE); + } +} + +//! destructor +CGUIStaticText::~CGUIStaticText() +{ + if (OverrideFont) + OverrideFont->drop(); +} + +//! draws the element and its children +void CGUIStaticText::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + if (!skin) + return; + video::IVideoDriver *driver = Environment->getVideoDriver(); + + core::rect frameRect(AbsoluteRect); + + // draw background + + if (Background) { + if (!OverrideBGColorEnabled) // skin-colors can change + BGColor = skin->getColor(gui::EGDC_3D_FACE); + + driver->draw2DRectangle(BGColor, frameRect, &AbsoluteClippingRect); + } + + // draw the border + + if (Border) { + skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect); + frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X); + } + + // draw the text + if (Text.size()) { + IGUIFont *font = getActiveFont(); + + if (font) { + if (!WordWrap) { + if (VAlign == EGUIA_LOWERRIGHT) { + frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - + font->getDimension(L"A").Height - font->getKerningHeight(); + } + if (HAlign == EGUIA_LOWERRIGHT) { + frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - + font->getDimension(Text.c_str()).Width; + } + + font->draw(Text.c_str(), frameRect, + getActiveColor(), + HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER, (RestrainTextInside ? &AbsoluteClippingRect : NULL)); + } else { + if (font != LastBreakFont) + breakText(); + + core::rect r = frameRect; + s32 height = font->getDimension(L"A").Height + font->getKerningHeight(); + s32 totalHeight = height * BrokenText.size(); + if (VAlign == EGUIA_CENTER) { + r.UpperLeftCorner.Y = r.getCenter().Y - (totalHeight / 2); + } else if (VAlign == EGUIA_LOWERRIGHT) { + r.UpperLeftCorner.Y = r.LowerRightCorner.Y - totalHeight; + } + + for (u32 i = 0; i < BrokenText.size(); ++i) { + if (HAlign == EGUIA_LOWERRIGHT) { + r.UpperLeftCorner.X = frameRect.LowerRightCorner.X - + font->getDimension(BrokenText[i].c_str()).Width; + } + + font->draw(BrokenText[i].c_str(), r, + getActiveColor(), + HAlign == EGUIA_CENTER, false, (RestrainTextInside ? &AbsoluteClippingRect : NULL)); + + r.LowerRightCorner.Y += height; + r.UpperLeftCorner.Y += height; + } + } + } + } + + IGUIElement::draw(); +} + +//! Sets another skin independent font. +void CGUIStaticText::setOverrideFont(IGUIFont *font) +{ + if (OverrideFont == font) + return; + + if (OverrideFont) + OverrideFont->drop(); + + OverrideFont = font; + + if (OverrideFont) + OverrideFont->grab(); + + breakText(); +} + +//! Gets the override font (if any) +IGUIFont *CGUIStaticText::getOverrideFont() const +{ + return OverrideFont; +} + +//! Get the font which is used right now for drawing +IGUIFont *CGUIStaticText::getActiveFont() const +{ + if (OverrideFont) + return OverrideFont; + IGUISkin *skin = Environment->getSkin(); + if (skin) + return skin->getFont(); + return 0; +} + +//! Sets another color for the text. +void CGUIStaticText::setOverrideColor(video::SColor color) +{ + OverrideColor = color; + OverrideColorEnabled = true; +} + +//! Sets another color for the text. +void CGUIStaticText::setBackgroundColor(video::SColor color) +{ + BGColor = color; + OverrideBGColorEnabled = true; + Background = true; +} + +//! Sets whether to draw the background +void CGUIStaticText::setDrawBackground(bool draw) +{ + Background = draw; +} + +//! Gets the background color +video::SColor CGUIStaticText::getBackgroundColor() const +{ + return BGColor; +} + +//! Checks if background drawing is enabled +bool CGUIStaticText::isDrawBackgroundEnabled() const +{ + return Background; +} + +//! Sets whether to draw the border +void CGUIStaticText::setDrawBorder(bool draw) +{ + Border = draw; +} + +//! Checks if border drawing is enabled +bool CGUIStaticText::isDrawBorderEnabled() const +{ + return Border; +} + +void CGUIStaticText::setTextRestrainedInside(bool restrainTextInside) +{ + RestrainTextInside = restrainTextInside; +} + +bool CGUIStaticText::isTextRestrainedInside() const +{ + return RestrainTextInside; +} + +void CGUIStaticText::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) +{ + HAlign = horizontal; + VAlign = vertical; +} + +video::SColor CGUIStaticText::getOverrideColor() const +{ + return OverrideColor; +} + +irr::video::SColor CGUIStaticText::getActiveColor() const +{ + if (OverrideColorEnabled) + return OverrideColor; + IGUISkin *skin = Environment->getSkin(); + if (skin) + return OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT); + return OverrideColor; +} + +//! Sets if the static text should use the override color or the +//! color in the gui skin. +void CGUIStaticText::enableOverrideColor(bool enable) +{ + OverrideColorEnabled = enable; +} + +bool CGUIStaticText::isOverrideColorEnabled() const +{ + return OverrideColorEnabled; +} + +//! Enables or disables word wrap for using the static text as +//! multiline text control. +void CGUIStaticText::setWordWrap(bool enable) +{ + WordWrap = enable; + breakText(); +} + +bool CGUIStaticText::isWordWrapEnabled() const +{ + return WordWrap; +} + +void CGUIStaticText::setRightToLeft(bool rtl) +{ + if (RightToLeft != rtl) { + RightToLeft = rtl; + breakText(); + } +} + +bool CGUIStaticText::isRightToLeft() const +{ + return RightToLeft; +} + +//! Breaks the single text line. +void CGUIStaticText::breakText() +{ + if (!WordWrap) + return; + + BrokenText.clear(); + + IGUISkin *skin = Environment->getSkin(); + IGUIFont *font = getActiveFont(); + if (!font) + return; + + LastBreakFont = font; + + core::stringw line; + core::stringw word; + core::stringw whitespace; + s32 size = Text.size(); + s32 length = 0; + s32 elWidth = RelativeRect.getWidth(); + if (Border) + elWidth -= 2 * skin->getSize(EGDS_TEXT_DISTANCE_X); + wchar_t c; + + // We have to deal with right-to-left and left-to-right differently + // However, most parts of the following code is the same, it's just + // some order and boundaries which change. + if (!RightToLeft) { + // regular (left-to-right) + for (s32 i = 0; i < size; ++i) { + c = Text[i]; + bool lineBreak = false; + + if (c == L'\r') { // Mac or Windows breaks + lineBreak = true; + if (Text[i + 1] == L'\n') { // Windows breaks + Text.erase(i + 1); + --size; + } + c = '\0'; + } else if (c == L'\n') { // Unix breaks + lineBreak = true; + c = '\0'; + } + + bool isWhitespace = (c == L' ' || c == 0); + if (!isWhitespace) { + // part of a word + word += c; + } + + if (isWhitespace || i == (size - 1)) { + if (word.size()) { + // here comes the next whitespace, look if + // we must break the last word to the next line. + const s32 whitelgth = font->getDimension(whitespace.c_str()).Width; + const s32 wordlgth = font->getDimension(word.c_str()).Width; + + if (wordlgth > elWidth) { + // This word is too long to fit in the available space, look for + // the Unicode Soft HYphen (SHY / 00AD) character for a place to + // break the word at + int where = word.findFirst(wchar_t(0x00AD)); + if (where != -1) { + core::stringw first = word.subString(0, where); + core::stringw second = word.subString(where, word.size() - where); + BrokenText.push_back(line + first + L"-"); + const s32 secondLength = font->getDimension(second.c_str()).Width; + + length = secondLength; + line = second; + } else { + // No soft hyphen found, so there's nothing more we can do + // break to next line + if (length) + BrokenText.push_back(line); + length = wordlgth; + line = word; + } + } else if (length && (length + wordlgth + whitelgth > elWidth)) { + // break to next line + BrokenText.push_back(line); + length = wordlgth; + line = word; + } else { + // add word to line + line += whitespace; + line += word; + length += whitelgth + wordlgth; + } + + word = L""; + whitespace = L""; + } + + if (isWhitespace) { + whitespace += c; + } + + // compute line break + if (lineBreak) { + line += whitespace; + line += word; + BrokenText.push_back(line); + line = L""; + word = L""; + whitespace = L""; + length = 0; + } + } + } + + line += whitespace; + line += word; + BrokenText.push_back(line); + } else { + // right-to-left + for (s32 i = size; i >= 0; --i) { + c = Text[i]; + bool lineBreak = false; + + if (c == L'\r') { // Mac or Windows breaks + lineBreak = true; + if ((i > 0) && Text[i - 1] == L'\n') { // Windows breaks + Text.erase(i - 1); + --size; + } + c = '\0'; + } else if (c == L'\n') { // Unix breaks + lineBreak = true; + c = '\0'; + } + + if (c == L' ' || c == 0 || i == 0) { + if (word.size()) { + // here comes the next whitespace, look if + // we must break the last word to the next line. + const s32 whitelgth = font->getDimension(whitespace.c_str()).Width; + const s32 wordlgth = font->getDimension(word.c_str()).Width; + + if (length && (length + wordlgth + whitelgth > elWidth)) { + // break to next line + BrokenText.push_back(line); + length = wordlgth; + line = word; + } else { + // add word to line + line = whitespace + line; + line = word + line; + length += whitelgth + wordlgth; + } + + word = L""; + whitespace = L""; + } + + if (c != 0) + whitespace = core::stringw(&c, 1) + whitespace; + + // compute line break + if (lineBreak) { + line = whitespace + line; + line = word + line; + BrokenText.push_back(line); + line = L""; + word = L""; + whitespace = L""; + length = 0; + } + } else { + // yippee this is a word.. + word = core::stringw(&c, 1) + word; + } + } + + line = whitespace + line; + line = word + line; + BrokenText.push_back(line); + } +} + +//! Sets the new caption of this element. +void CGUIStaticText::setText(const wchar_t *text) +{ + IGUIElement::setText(text); + breakText(); +} + +void CGUIStaticText::updateAbsolutePosition() +{ + IGUIElement::updateAbsolutePosition(); + breakText(); +} + +//! Returns the height of the text in pixels when it is drawn. +s32 CGUIStaticText::getTextHeight() const +{ + IGUIFont *font = getActiveFont(); + if (!font) + return 0; + + if (WordWrap) { + s32 height = font->getDimension(L"A").Height + font->getKerningHeight(); + return height * BrokenText.size(); + } else { + // TODO: Text can have multiple lines which are not in BrokenText + // This is likely not correct. But as I have no time for further + // investigation I just fix it for now by return the true height here. + return font->getDimension(Text.c_str()).Height; + } +} + +s32 CGUIStaticText::getTextWidth() const +{ + IGUIFont *font = getActiveFont(); + if (!font) + return 0; + + if (WordWrap) { + s32 widest = 0; + + for (u32 line = 0; line < BrokenText.size(); ++line) { + s32 width = font->getDimension(BrokenText[line].c_str()).Width; + + if (width > widest) + widest = width; + } + + return widest; + } else { + return font->getDimension(Text.c_str()).Width; + } +} + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUIStaticText.h b/irr/src/CGUIStaticText.h new file mode 100644 index 000000000..c127769f8 --- /dev/null +++ b/irr/src/CGUIStaticText.h @@ -0,0 +1,131 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUIStaticText.h" +#include "irrArray.h" + +namespace irr +{ +namespace gui +{ +class CGUIStaticText : public IGUIStaticText +{ +public: + //! constructor + CGUIStaticText(const wchar_t *text, bool border, IGUIEnvironment *environment, + IGUIElement *parent, s32 id, const core::rect &rectangle, + bool background = false); + + //! destructor + virtual ~CGUIStaticText(); + + //! draws the element and its children + void draw() override; + + //! Sets another skin independent font. + void setOverrideFont(IGUIFont *font = 0) override; + + //! Gets the override font (if any) + IGUIFont *getOverrideFont() const override; + + //! Get the font which is used right now for drawing + IGUIFont *getActiveFont() const override; + + //! Sets another color for the text. + void setOverrideColor(video::SColor color) override; + + //! Sets another color for the background. + void setBackgroundColor(video::SColor color) override; + + //! Sets whether to draw the background + void setDrawBackground(bool draw) override; + + //! Gets the background color + video::SColor getBackgroundColor() const override; + + //! Checks if background drawing is enabled + bool isDrawBackgroundEnabled() const override; + + //! Sets whether to draw the border + void setDrawBorder(bool draw) override; + + //! Checks if border drawing is enabled + bool isDrawBorderEnabled() const override; + + //! Sets alignment mode for text + void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override; + + //! Gets the override color + video::SColor getOverrideColor() const override; + + //! Gets the currently used text color + video::SColor getActiveColor() const override; + + //! Sets if the static text should use the override color or the + //! color in the gui skin. + void enableOverrideColor(bool enable) override; + + //! Checks if an override color is enabled + bool isOverrideColorEnabled() const override; + + //! Set whether the text in this label should be clipped if it goes outside bounds + void setTextRestrainedInside(bool restrainedInside) override; + + //! Checks if the text in this label should be clipped if it goes outside bounds + bool isTextRestrainedInside() const override; + + //! Enables or disables word wrap for using the static text as + //! multiline text control. + void setWordWrap(bool enable) override; + + //! Checks if word wrap is enabled + bool isWordWrapEnabled() const override; + + //! Sets the new caption of this element. + void setText(const wchar_t *text) override; + + //! Returns the height of the text in pixels when it is drawn. + s32 getTextHeight() const override; + + //! Returns the width of the current text, in the current font + s32 getTextWidth() const override; + + //! Updates the absolute position, splits text if word wrap is enabled + void updateAbsolutePosition() override; + + //! Set whether the string should be interpreted as right-to-left (RTL) text + /** \note This component does not implement the Unicode bidi standard, the + text of the component should be already RTL if you call this. The + main difference when RTL is enabled is that the linebreaks for multiline + elements are performed starting from the end. + */ + void setRightToLeft(bool rtl) override; + + //! Checks if the text should be interpreted as right-to-left text + bool isRightToLeft() const override; + +private: + //! Breaks the single text line. + void breakText(); + + EGUI_ALIGNMENT HAlign, VAlign; + bool Border; + bool OverrideColorEnabled; + bool OverrideBGColorEnabled; + bool WordWrap; + bool Background; + bool RestrainTextInside; + bool RightToLeft; + + video::SColor OverrideColor, BGColor; + gui::IGUIFont *OverrideFont; + gui::IGUIFont *LastBreakFont; // stored because: if skin changes, line break must be recalculated. + + core::array BrokenText; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CGUITabControl.cpp b/irr/src/CGUITabControl.cpp new file mode 100644 index 000000000..3e02773db --- /dev/null +++ b/irr/src/CGUITabControl.cpp @@ -0,0 +1,934 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CGUITabControl.h" + +#include "CGUIButton.h" +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IGUIFont.h" +#include "IVideoDriver.h" +#include "rect.h" +#include "os.h" + +namespace irr +{ +namespace gui +{ + +// ------------------------------------------------------------------ +// Tab +// ------------------------------------------------------------------ + +//! constructor +CGUITab::CGUITab(IGUIEnvironment *environment, + IGUIElement *parent, const core::rect &rectangle, + s32 id) : + IGUITab(environment, parent, id, rectangle), + BackColor(0, 0, 0, 0), OverrideTextColorEnabled(false), TextColor(255, 0, 0, 0), + DrawBackground(false) +{ +#ifdef _DEBUG + setDebugName("CGUITab"); +#endif + + const IGUISkin *const skin = environment->getSkin(); + if (skin) + TextColor = skin->getColor(EGDC_BUTTON_TEXT); +} + +//! draws the element and its children +void CGUITab::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + + if (skin && DrawBackground) + skin->draw2DRectangle(this, BackColor, AbsoluteRect, &AbsoluteClippingRect); + + IGUIElement::draw(); +} + +//! sets if the tab should draw its background +void CGUITab::setDrawBackground(bool draw) +{ + DrawBackground = draw; +} + +//! sets the color of the background, if it should be drawn. +void CGUITab::setBackgroundColor(video::SColor c) +{ + BackColor = c; +} + +//! sets the color of the text +void CGUITab::setTextColor(video::SColor c) +{ + OverrideTextColorEnabled = true; + TextColor = c; +} + +video::SColor CGUITab::getTextColor() const +{ + if (OverrideTextColorEnabled) + return TextColor; + else + return Environment->getSkin()->getColor(EGDC_BUTTON_TEXT); +} + +//! returns true if the tab is drawing its background, false if not +bool CGUITab::isDrawingBackground() const +{ + return DrawBackground; +} + +//! returns the color of the background +video::SColor CGUITab::getBackgroundColor() const +{ + return BackColor; +} + +// ------------------------------------------------------------------ +// Tabcontrol +// ------------------------------------------------------------------ + +//! constructor +CGUITabControl::CGUITabControl(IGUIEnvironment *environment, + IGUIElement *parent, const core::rect &rectangle, + bool fillbackground, bool border, s32 id) : + IGUITabControl(environment, parent, id, rectangle), + ActiveTabIndex(-1), + Border(border), FillBackground(fillbackground), ScrollControl(false), TabHeight(0), VerticalAlignment(EGUIA_UPPERLEFT), + UpButton(0), DownButton(0), TabMaxWidth(0), CurrentScrollTabIndex(0), TabExtraWidth(20) +{ +#ifdef _DEBUG + setDebugName("CGUITabControl"); +#endif + + IGUISkin *skin = Environment->getSkin(); + IGUISpriteBank *sprites = 0; + + TabHeight = 32; + + if (skin) { + sprites = skin->getSpriteBank(); + TabHeight = skin->getSize(gui::EGDS_BUTTON_HEIGHT) + 2; + } + + UpButton = Environment->addButton(core::rect(0, 0, 10, 10), this); + + if (UpButton) { + UpButton->setSpriteBank(sprites); + UpButton->setVisible(false); + UpButton->setSubElement(true); + UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + UpButton->setOverrideFont(Environment->getBuiltInFont()); + UpButton->grab(); + } + + DownButton = Environment->addButton(core::rect(0, 0, 10, 10), this); + + if (DownButton) { + DownButton->setSpriteBank(sprites); + DownButton->setVisible(false); + DownButton->setSubElement(true); + DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + DownButton->setOverrideFont(Environment->getBuiltInFont()); + DownButton->grab(); + } + + setTabVerticalAlignment(EGUIA_UPPERLEFT); + refreshSprites(); +} + +//! destructor +CGUITabControl::~CGUITabControl() +{ + for (u32 i = 0; i < Tabs.size(); ++i) { + if (Tabs[i]) + Tabs[i]->drop(); + } + + if (UpButton) + UpButton->drop(); + + if (DownButton) + DownButton->drop(); +} + +void CGUITabControl::refreshSprites() +{ + video::SColor color(255, 255, 255, 255); + IGUISkin *skin = Environment->getSkin(); + if (skin) { + color = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL); + + if (UpButton) { + UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_LEFT), color); + UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_LEFT), color); + } + + if (DownButton) { + DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_RIGHT), color); + DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_RIGHT), color); + } + } +} + +//! Adds a tab +IGUITab *CGUITabControl::addTab(const wchar_t *caption, s32 id) +{ + CGUITab *tab = new CGUITab(Environment, this, calcTabPos(), id); + + tab->setText(caption); + tab->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + tab->setVisible(false); + Tabs.push_back(tab); // no grab as new already creates a reference + + if (ActiveTabIndex == -1) { + ActiveTabIndex = Tabs.size() - 1; + tab->setVisible(true); + } + + recalculateScrollBar(); + + return tab; +} + +//! adds a tab which has been created elsewhere +s32 CGUITabControl::addTab(IGUITab *tab) +{ + return insertTab(Tabs.size(), tab, false); +} + +//! Insert the tab at the given index +IGUITab *CGUITabControl::insertTab(s32 idx, const wchar_t *caption, s32 id) +{ + if (idx < 0 || idx > (s32)Tabs.size()) // idx == Tabs.size() is indeed OK here as core::array can handle that + return NULL; + + CGUITab *tab = new CGUITab(Environment, this, calcTabPos(), id); + + tab->setText(caption); + tab->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); + tab->setVisible(false); + Tabs.insert(tab, (u32)idx); + + if (ActiveTabIndex == -1) { + ActiveTabIndex = (u32)idx; + tab->setVisible(true); + } else if (idx <= ActiveTabIndex) { + ++ActiveTabIndex; + setVisibleTab(ActiveTabIndex); + } + + recalculateScrollBar(); + + return tab; +} + +s32 CGUITabControl::insertTab(s32 idx, IGUITab *tab, bool serializationMode) +{ + if (!tab) + return -1; + if (idx > (s32)Tabs.size() && !serializationMode) // idx == Tabs.size() is indeed OK here as core::array can handle that + return -1; + // Not allowing to add same tab twice as it would make things complicated (serialization or setting active visible) + if (getTabIndex(tab) >= 0) + return -1; + + if (idx < 0) + idx = (s32)Tabs.size(); + + if (tab->getParent() != this) + this->addChildToEnd(tab); + + tab->setVisible(false); + + tab->grab(); + + if (serializationMode) { + while (idx >= (s32)Tabs.size()) { + Tabs.push_back(0); + } + Tabs[idx] = tab; + + if (idx == ActiveTabIndex) { // in serialization that can happen for any index + setVisibleTab(ActiveTabIndex); + tab->setVisible(true); + } + } else { + Tabs.insert(tab, (u32)idx); + + if (ActiveTabIndex == -1) { + ActiveTabIndex = idx; + setVisibleTab(ActiveTabIndex); + } else if (idx <= ActiveTabIndex) { + ++ActiveTabIndex; + setVisibleTab(ActiveTabIndex); + } + } + + recalculateScrollBar(); + + return idx; +} + +//! Removes a child. +void CGUITabControl::removeChild(IGUIElement *child) +{ + s32 idx = getTabIndex(child); + if (idx >= 0) + removeTabButNotChild(idx); + + // remove real element + IGUIElement::removeChild(child); + + recalculateScrollBar(); +} + +//! Removes a tab from the tabcontrol +void CGUITabControl::removeTab(s32 idx) +{ + if (idx < 0 || idx >= (s32)Tabs.size()) + return; + + removeChild(Tabs[(u32)idx]); +} + +void CGUITabControl::removeTabButNotChild(s32 idx) +{ + if (idx < 0 || idx >= (s32)Tabs.size()) + return; + + Tabs[(u32)idx]->drop(); + Tabs.erase((u32)idx); + + if (idx < ActiveTabIndex) { + --ActiveTabIndex; + setVisibleTab(ActiveTabIndex); + } else if (idx == ActiveTabIndex) { + if ((u32)idx == Tabs.size()) + --ActiveTabIndex; + setVisibleTab(ActiveTabIndex); + } +} + +//! Clears the tabcontrol removing all tabs +void CGUITabControl::clear() +{ + for (u32 i = 0; i < Tabs.size(); ++i) { + if (Tabs[i]) { + IGUIElement::removeChild(Tabs[i]); + Tabs[i]->drop(); + } + } + Tabs.clear(); + + recalculateScrollBar(); +} + +//! Returns amount of tabs in the tabcontrol +s32 CGUITabControl::getTabCount() const +{ + return Tabs.size(); +} + +//! Returns a tab based on zero based index +IGUITab *CGUITabControl::getTab(s32 idx) const +{ + if (idx < 0 || (u32)idx >= Tabs.size()) + return 0; + + return Tabs[idx]; +} + +//! called if an event happened. +bool CGUITabControl::OnEvent(const SEvent &event) +{ + if (isEnabled()) { + switch (event.EventType) { + case EET_GUI_EVENT: + switch (event.GUIEvent.EventType) { + case EGET_BUTTON_CLICKED: + if (event.GUIEvent.Caller == UpButton) { + scrollLeft(); + return true; + } else if (event.GUIEvent.Caller == DownButton) { + scrollRight(); + return true; + } + + break; + default: + break; + } + break; + case EET_MOUSE_INPUT_EVENT: + switch (event.MouseInput.Event) { + // case EMIE_LMOUSE_PRESSED_DOWN: + // // todo: dragging tabs around + // return true; + case EMIE_LMOUSE_LEFT_UP: { + s32 idx = getTabAt(event.MouseInput.X, event.MouseInput.Y); + if (idx >= 0) { + setActiveTab(idx); + return true; + } + break; + } + default: + break; + } + break; + default: + break; + } + } + + return IGUIElement::OnEvent(event); +} + +void CGUITabControl::scrollLeft() +{ + if (CurrentScrollTabIndex > 0) + --CurrentScrollTabIndex; + recalculateScrollBar(); +} + +void CGUITabControl::scrollRight() +{ + if (CurrentScrollTabIndex < (s32)(Tabs.size()) - 1) { + if (needScrollControl(CurrentScrollTabIndex, true)) + ++CurrentScrollTabIndex; + } + recalculateScrollBar(); +} + +s32 CGUITabControl::calcTabWidth(IGUIFont *font, const wchar_t *text) const +{ + if (!font) + return 0; + + s32 len = font->getDimension(text).Width + TabExtraWidth; + if (TabMaxWidth > 0 && len > TabMaxWidth) + len = TabMaxWidth; + + return len; +} + +bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl, s32 *pos_rightmost) +{ + if (startIndex < 0) + startIndex = 0; + + IGUISkin *skin = Environment->getSkin(); + if (!skin) + return false; + + IGUIFont *font = skin->getFont(); + + if (Tabs.empty()) + return false; + + if (!font) + return false; + + s32 pos = AbsoluteRect.UpperLeftCorner.X + 2; + const s32 pos_right = withScrollControl ? UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 : AbsoluteRect.LowerRightCorner.X; + + for (s32 i = startIndex; i < (s32)Tabs.size(); ++i) { + // get Text + const wchar_t *text = 0; + if (Tabs[i]) { + text = Tabs[i]->getText(); + + // get text length + s32 len = calcTabWidth(font, text); // always without withScrollControl here or len would be shortened + pos += len; + } + + if (pos > pos_right) + return true; + } + + if (pos_rightmost) + *pos_rightmost = pos; + return false; +} + +s32 CGUITabControl::calculateScrollIndexFromActive() +{ + if (!ScrollControl || Tabs.empty()) + return 0; + + IGUISkin *skin = Environment->getSkin(); + if (!skin) + return false; + + IGUIFont *font = skin->getFont(); + if (!font) + return false; + + const s32 pos_left = AbsoluteRect.UpperLeftCorner.X + 2; + const s32 pos_right = UpButton->getAbsolutePosition().UpperLeftCorner.X - 2; + + // Move from center to the left border left until it is reached + s32 pos_cl = (pos_left + pos_right) / 2; + s32 i = ActiveTabIndex; + for (; i > 0; --i) { + if (!Tabs[i]) + continue; + + s32 len = calcTabWidth(font, Tabs[i]->getText()); + if (i == ActiveTabIndex) + len /= 2; + if (pos_cl - len < pos_left) + break; + + pos_cl -= len; + } + if (i == 0) + return i; + + // Is scrolling to right still possible? + s32 pos_rr = 0; + if (needScrollControl(i, true, &pos_rr)) + return i; // Yes? -> OK + + // No? -> Decrease "i" more. Append tabs until scrolling becomes necessary + for (--i; i > 0; --i) { + if (!Tabs[i]) + continue; + + pos_rr += calcTabWidth(font, Tabs[i]->getText()); + if (pos_rr > pos_right) + break; + } + return i + 1; +} + +core::rect CGUITabControl::calcTabPos() +{ + core::rect r; + r.UpperLeftCorner.X = 0; + r.LowerRightCorner.X = AbsoluteRect.getWidth(); + if (Border) { + ++r.UpperLeftCorner.X; + --r.LowerRightCorner.X; + } + + if (VerticalAlignment == EGUIA_UPPERLEFT) { + r.UpperLeftCorner.Y = TabHeight + 2; + r.LowerRightCorner.Y = AbsoluteRect.getHeight() - 1; + if (Border) { + --r.LowerRightCorner.Y; + } + } else { + r.UpperLeftCorner.Y = 0; + r.LowerRightCorner.Y = AbsoluteRect.getHeight() - (TabHeight + 2); + if (Border) { + ++r.UpperLeftCorner.Y; + } + } + + return r; +} + +//! draws the element and its children +void CGUITabControl::draw() +{ + if (!IsVisible) + return; + + IGUISkin *skin = Environment->getSkin(); + if (!skin) + return; + + IGUIFont *font = skin->getFont(); + video::IVideoDriver *driver = Environment->getVideoDriver(); + + core::rect frameRect(AbsoluteRect); + + // some empty background as placeholder when there are no tabs + if (Tabs.empty()) + driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect); + + if (!font) + return; + + // tab button bar can be above or below the tabs + if (VerticalAlignment == EGUIA_UPPERLEFT) { + frameRect.UpperLeftCorner.Y += 2; + frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight; + } else { + frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight - 1; + frameRect.LowerRightCorner.Y -= 2; + } + + core::rect tr; + s32 pos = frameRect.UpperLeftCorner.X + 2; + + bool needLeftScroll = CurrentScrollTabIndex > 0; + bool needRightScroll = false; + + // left and right pos of the active tab + s32 left = 0; + s32 right = 0; + + // const wchar_t* activetext = 0; + IGUITab *activeTab = 0; + + // Draw all tab-buttons except the active one + for (u32 i = CurrentScrollTabIndex; i < Tabs.size() && !needRightScroll; ++i) { + // get Text + const wchar_t *text = 0; + if (Tabs[i]) + text = Tabs[i]->getText(); + + // get text length + s32 len = calcTabWidth(font, text); + if (ScrollControl) { + s32 space = UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 - pos; + if (space < len) { + needRightScroll = true; + len = space; + } + } + + frameRect.LowerRightCorner.X += len; + frameRect.UpperLeftCorner.X = pos; + frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len; + + pos += len; + + if ((s32)i == ActiveTabIndex) { + // for active button just remember values + left = frameRect.UpperLeftCorner.X; + right = frameRect.LowerRightCorner.X; + // activetext = text; + activeTab = Tabs[i]; + } else { + skin->draw3DTabButton(this, false, frameRect, &AbsoluteClippingRect, VerticalAlignment); + + // draw text + core::rect textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface + textClipRect.clipAgainst(AbsoluteClippingRect); + font->draw(text, frameRect, Tabs[i]->getTextColor(), + true, true, &textClipRect); + } + } + + // Draw active tab button + // Drawn later than other buttons because it draw over the buttons before/after it. + if (left != 0 && right != 0 && activeTab != 0) { + // draw upper highlight frame + if (VerticalAlignment == EGUIA_UPPERLEFT) { + frameRect.UpperLeftCorner.X = left - 2; + frameRect.LowerRightCorner.X = right + 2; + frameRect.UpperLeftCorner.Y -= 2; + + skin->draw3DTabButton(this, true, frameRect, &AbsoluteClippingRect, VerticalAlignment); + + // draw text + core::rect textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface + textClipRect.clipAgainst(AbsoluteClippingRect); + font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(), + true, true, &textClipRect); + + tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X; + tr.LowerRightCorner.X = left - 1; + tr.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - 1; + tr.LowerRightCorner.Y = frameRect.LowerRightCorner.Y; + driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect); + + tr.UpperLeftCorner.X = right; + tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X; + driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect); + } else { + frameRect.UpperLeftCorner.X = left - 2; + frameRect.LowerRightCorner.X = right + 2; + frameRect.LowerRightCorner.Y += 2; + + skin->draw3DTabButton(this, true, frameRect, &AbsoluteClippingRect, VerticalAlignment); + + // draw text + font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(), + true, true, &frameRect); + + tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X; + tr.LowerRightCorner.X = left - 1; + tr.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - 1; + tr.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y; + driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect); + + tr.UpperLeftCorner.X = right; + tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X; + driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect); + } + } else { + // No active tab + // Draw a line separating button bar from tab area + tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X; + tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X; + tr.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - 1; + tr.LowerRightCorner.Y = frameRect.LowerRightCorner.Y; + + if (VerticalAlignment == EGUIA_UPPERLEFT) { + driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect); + } else { + tr.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - 1; + tr.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y; + driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect); + } + } + + // drawing some border and background for the tab-area. + skin->draw3DTabBody(this, Border, FillBackground, AbsoluteRect, &AbsoluteClippingRect, TabHeight, VerticalAlignment); + + // enable scrollcontrols on need + if (UpButton) + UpButton->setEnabled(needLeftScroll); + if (DownButton) + DownButton->setEnabled(needRightScroll); + refreshSprites(); + + IGUIElement::draw(); +} + +//! Set the height of the tabs +void CGUITabControl::setTabHeight(s32 height) +{ + if (height < 0) + height = 0; + + TabHeight = height; + + recalculateScrollButtonPlacement(); + recalculateScrollBar(); +} + +//! Get the height of the tabs +s32 CGUITabControl::getTabHeight() const +{ + return TabHeight; +} + +//! set the maximal width of a tab. Per default width is 0 which means "no width restriction". +void CGUITabControl::setTabMaxWidth(s32 width) +{ + TabMaxWidth = width; +} + +//! get the maximal width of a tab +s32 CGUITabControl::getTabMaxWidth() const +{ + return TabMaxWidth; +} + +//! Set the extra width added to tabs on each side of the text +void CGUITabControl::setTabExtraWidth(s32 extraWidth) +{ + if (extraWidth < 0) + extraWidth = 0; + + TabExtraWidth = extraWidth; + + recalculateScrollBar(); +} + +//! Get the extra width added to tabs on each side of the text +s32 CGUITabControl::getTabExtraWidth() const +{ + return TabExtraWidth; +} + +void CGUITabControl::recalculateScrollBar() +{ + // Down: to right, Up: to left + if (!UpButton || !DownButton) + return; + + ScrollControl = needScrollControl() || CurrentScrollTabIndex > 0; + + if (ScrollControl) { + UpButton->setVisible(true); + DownButton->setVisible(true); + } else { + UpButton->setVisible(false); + DownButton->setVisible(false); + } + + bringToFront(UpButton); + bringToFront(DownButton); +} + +//! Set the alignment of the tabs +void CGUITabControl::setTabVerticalAlignment(EGUI_ALIGNMENT alignment) +{ + VerticalAlignment = alignment; + + recalculateScrollButtonPlacement(); + recalculateScrollBar(); + + core::rect r(calcTabPos()); + for (u32 i = 0; i < Tabs.size(); ++i) { + Tabs[i]->setRelativePosition(r); + } +} + +void CGUITabControl::recalculateScrollButtonPlacement() +{ + IGUISkin *skin = Environment->getSkin(); + s32 ButtonSize = 16; + s32 ButtonHeight = TabHeight - 2; + if (ButtonHeight < 0) + ButtonHeight = TabHeight; + if (skin) { + ButtonSize = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH); + if (ButtonSize > TabHeight) + ButtonSize = TabHeight; + } + + s32 ButtonX = RelativeRect.getWidth() - (s32)(2.5f * (f32)ButtonSize) - 1; + s32 ButtonY = 0; + + if (VerticalAlignment == EGUIA_UPPERLEFT) { + ButtonY = 2 + (TabHeight / 2) - (ButtonHeight / 2); + UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + } else { + ButtonY = RelativeRect.getHeight() - (TabHeight / 2) - (ButtonHeight / 2) - 2; + UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT); + DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT); + } + + UpButton->setRelativePosition(core::rect(ButtonX, ButtonY, ButtonX + ButtonSize, ButtonY + ButtonHeight)); + ButtonX += ButtonSize + 1; + DownButton->setRelativePosition(core::rect(ButtonX, ButtonY, ButtonX + ButtonSize, ButtonY + ButtonHeight)); +} + +//! Get the alignment of the tabs +EGUI_ALIGNMENT CGUITabControl::getTabVerticalAlignment() const +{ + return VerticalAlignment; +} + +s32 CGUITabControl::getTabAt(s32 xpos, s32 ypos) const +{ + core::position2di p(xpos, ypos); + IGUISkin *skin = Environment->getSkin(); + IGUIFont *font = skin->getFont(); + + core::rect frameRect(AbsoluteRect); + + if (VerticalAlignment == EGUIA_UPPERLEFT) { + frameRect.UpperLeftCorner.Y += 2; + frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight; + } else { + frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight; + } + + s32 pos = frameRect.UpperLeftCorner.X + 2; + + if (!frameRect.isPointInside(p)) + return -1; + + bool abort = false; + for (s32 i = CurrentScrollTabIndex; i < (s32)Tabs.size() && !abort; ++i) { + // get Text + const wchar_t *text = 0; + if (Tabs[i]) + text = Tabs[i]->getText(); + + // get text length + s32 len = calcTabWidth(font, text); + if (ScrollControl) { + // TODO: merge this with draw() ? + s32 space = UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 - pos; + if (space < len) { + abort = true; + len = space; + } + } + + frameRect.UpperLeftCorner.X = pos; + frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len; + + pos += len; + + if (frameRect.isPointInside(p)) { + return i; + } + } + return -1; +} + +//! Returns which tab is currently active +s32 CGUITabControl::getActiveTab() const +{ + return ActiveTabIndex; +} + +//! Brings a tab to front. +bool CGUITabControl::setActiveTab(s32 idx) +{ + if ((u32)idx >= Tabs.size()) + return false; + + bool changed = (ActiveTabIndex != idx); + + ActiveTabIndex = idx; + + setVisibleTab(ActiveTabIndex); + + if (changed && Parent) { + SEvent event; + event.EventType = EET_GUI_EVENT; + event.GUIEvent.Caller = this; + event.GUIEvent.Element = 0; + event.GUIEvent.EventType = EGET_TAB_CHANGED; + Parent->OnEvent(event); + } + + if (ScrollControl) { + CurrentScrollTabIndex = calculateScrollIndexFromActive(); + recalculateScrollBar(); + } + + return true; +} + +void CGUITabControl::setVisibleTab(s32 idx) +{ + for (u32 i = 0; i < Tabs.size(); ++i) + if (Tabs[i]) + Tabs[i]->setVisible((s32)i == idx); +} + +bool CGUITabControl::setActiveTab(IGUITab *tab) +{ + return setActiveTab(getTabIndex(tab)); +} + +s32 CGUITabControl::getTabIndex(const IGUIElement *tab) const +{ + for (u32 i = 0; i < Tabs.size(); ++i) + if (Tabs[i] == tab) + return (s32)i; + + return -1; +} + +//! Update the position of the element, decides scroll button status +void CGUITabControl::updateAbsolutePosition() +{ + IGUIElement::updateAbsolutePosition(); + recalculateScrollBar(); +} + +} // end namespace irr +} // end namespace gui diff --git a/irr/src/CGUITabControl.h b/irr/src/CGUITabControl.h new file mode 100644 index 000000000..5c167c2a3 --- /dev/null +++ b/irr/src/CGUITabControl.h @@ -0,0 +1,175 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IGUITabControl.h" +#include "irrArray.h" +#include "IGUISkin.h" + +namespace irr +{ +namespace gui +{ +class CGUITabControl; +class IGUIButton; + +// A tab, onto which other gui elements could be added. +class CGUITab : public IGUITab +{ +public: + //! constructor + CGUITab(IGUIEnvironment *environment, + IGUIElement *parent, const core::rect &rectangle, + s32 id); + + //! draws the element and its children + void draw() override; + + //! sets if the tab should draw its background + void setDrawBackground(bool draw = true) override; + + //! sets the color of the background, if it should be drawn. + void setBackgroundColor(video::SColor c) override; + + //! sets the color of the text + void setTextColor(video::SColor c) override; + + //! returns true if the tab is drawing its background, false if not + bool isDrawingBackground() const override; + + //! returns the color of the background + video::SColor getBackgroundColor() const override; + + video::SColor getTextColor() const override; + +private: + video::SColor BackColor; + bool OverrideTextColorEnabled; + video::SColor TextColor; + bool DrawBackground; +}; + +//! A standard tab control +class CGUITabControl : public IGUITabControl +{ +public: + //! destructor + CGUITabControl(IGUIEnvironment *environment, + IGUIElement *parent, const core::rect &rectangle, + bool fillbackground = true, bool border = true, s32 id = -1); + + //! destructor + virtual ~CGUITabControl(); + + //! Adds a tab + IGUITab *addTab(const wchar_t *caption, s32 id = -1) override; + + //! Adds an existing tab + s32 addTab(IGUITab *tab) override; + + //! Insert the tab at the given index + IGUITab *insertTab(s32 idx, const wchar_t *caption, s32 id = -1) override; + + //! Insert an existing tab + /** Note that it will also add the tab as a child of this TabControl. + \return Index of added tab (should be same as the one passed) or -1 for failure*/ + s32 insertTab(s32 idx, IGUITab *tab, bool serializationMode) override; + + //! Removes a tab from the tabcontrol + void removeTab(s32 idx) override; + + //! Clears the tabcontrol removing all tabs + void clear() override; + + //! Returns amount of tabs in the tabcontrol + s32 getTabCount() const override; + + //! Returns a tab based on zero based index + IGUITab *getTab(s32 idx) const override; + + //! Brings a tab to front. + bool setActiveTab(s32 idx) override; + + //! Brings a tab to front. + bool setActiveTab(IGUITab *tab) override; + + //! For given given tab find it's zero-based index (or -1 for not found) + s32 getTabIndex(const IGUIElement *tab) const override; + + //! Returns which tab is currently active + s32 getActiveTab() const override; + + //! get the the id of the tab at the given absolute coordinates + s32 getTabAt(s32 xpos, s32 ypos) const override; + + //! called if an event happened. + bool OnEvent(const SEvent &event) override; + + //! draws the element and its children + void draw() override; + + //! Removes a child. + void removeChild(IGUIElement *child) override; + + //! Set the height of the tabs + void setTabHeight(s32 height) override; + + //! Get the height of the tabs + s32 getTabHeight() const override; + + //! set the maximal width of a tab. Per default width is 0 which means "no width restriction". + void setTabMaxWidth(s32 width) override; + + //! get the maximal width of a tab + s32 getTabMaxWidth() const override; + + //! Set the alignment of the tabs + //! note: EGUIA_CENTER is not an option + void setTabVerticalAlignment(gui::EGUI_ALIGNMENT alignment) override; + + //! Get the alignment of the tabs + gui::EGUI_ALIGNMENT getTabVerticalAlignment() const override; + + //! Set the extra width added to tabs on each side of the text + void setTabExtraWidth(s32 extraWidth) override; + + //! Get the extra width added to tabs on each side of the text + s32 getTabExtraWidth() const override; + + //! Update the position of the element, decides scroll button status + void updateAbsolutePosition() override; + +private: + void scrollLeft(); + void scrollRight(); + //! Indicates whether the tabs overflow in X direction + bool needScrollControl(s32 startIndex = 0, bool withScrollControl = false, s32 *pos_rightmost = nullptr); + //! Left index calculation based on the selected tab + s32 calculateScrollIndexFromActive(); + s32 calcTabWidth(IGUIFont *font, const wchar_t *text) const; + core::rect calcTabPos(); + void setVisibleTab(s32 idx); + void removeTabButNotChild(s32 idx); + + void recalculateScrollButtonPlacement(); + void recalculateScrollBar(); + void refreshSprites(); + + core::array Tabs; + s32 ActiveTabIndex; + bool Border; + bool FillBackground; + bool ScrollControl; + s32 TabHeight; + gui::EGUI_ALIGNMENT VerticalAlignment; + IGUIButton *UpButton; + IGUIButton *DownButton; + s32 TabMaxWidth; + s32 CurrentScrollTabIndex; + s32 TabExtraWidth; +}; + +} // end namespace gui +} // end namespace irr diff --git a/irr/src/CImage.cpp b/irr/src/CImage.cpp new file mode 100644 index 000000000..209590174 --- /dev/null +++ b/irr/src/CImage.cpp @@ -0,0 +1,373 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImage.h" +#include "irrString.h" +#include "CColorConverter.h" +#include "CBlit.h" +#include "os.h" +#include "SoftwareDriver2_helper.h" + +namespace irr +{ +namespace video +{ + +//! Constructor from raw data +CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d &size, void *data, + bool ownForeignMemory, bool deleteMemory) : + IImage(format, size, deleteMemory) +{ + if (ownForeignMemory) { + Data = (u8 *)data; + } else { + const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height); + const u32 allocSize = align_next(dataSize, 16); + + // allocate as u32 to ensure enough alignment when casted + Data = reinterpret_cast(new u32[allocSize / 4]); + memcpy(Data, data, dataSize); + DeleteMemory = true; + } +} + +//! Constructor of empty image +CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d &size) : + IImage(format, size, true) +{ + const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height); + const u32 allocSize = align_next(dataSize, 16); + + Data = reinterpret_cast(new u32[allocSize / 4]); + DeleteMemory = true; +} + +//! sets a pixel +void CImage::setPixel(u32 x, u32 y, const SColor &color, bool blend) +{ + if (x >= Size.Width || y >= Size.Height) + return; + + switch (Format) { + case ECF_A1R5G5B5: { + u16 *dest = (u16 *)(Data + (y * Pitch) + (x << 1)); + *dest = video::A8R8G8B8toA1R5G5B5(color.color); + } break; + + case ECF_R5G6B5: { + u16 *dest = (u16 *)(Data + (y * Pitch) + (x << 1)); + *dest = video::A8R8G8B8toR5G6B5(color.color); + } break; + + case ECF_R8G8B8: { + u8 *dest = Data + (y * Pitch) + (x * 3); + dest[0] = (u8)color.getRed(); + dest[1] = (u8)color.getGreen(); + dest[2] = (u8)color.getBlue(); + } break; + + case ECF_A8R8G8B8: { + u32 *dest = (u32 *)(Data + (y * Pitch) + (x << 2)); + *dest = blend ? PixelBlend32(*dest, color.color) : color.color; + } break; + + case ECF_UNKNOWN: + os::Printer::log("IImage::setPixel unknown format.", ELL_WARNING); + return; + + default: + break; + } +} + +//! returns a pixel +SColor CImage::getPixel(u32 x, u32 y) const +{ + if (x >= Size.Width || y >= Size.Height) + return SColor(0); + + switch (Format) { + case ECF_A1R5G5B5: + return A1R5G5B5toA8R8G8B8(((u16 *)Data)[y * Size.Width + x]); + case ECF_R5G6B5: + return R5G6B5toA8R8G8B8(((u16 *)Data)[y * Size.Width + x]); + case ECF_A8R8G8B8: + return ((u32 *)Data)[y * Size.Width + x]; + case ECF_R8G8B8: { + u8 *p = Data + (y * 3) * Size.Width + (x * 3); + return SColor(255, p[0], p[1], p[2]); + } + + case ECF_UNKNOWN: + os::Printer::log("IImage::getPixel unknown format.", ELL_WARNING); + break; + + default: + break; + } + + return SColor(0); +} + +//! copies this surface into another at given position +void CImage::copyTo(IImage *target, const core::position2d &pos) +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::copyTo method doesn't work with compressed images.", ELL_WARNING); + return; + } + + if (!Blit(BLITTER_TEXTURE, target, 0, &pos, this, 0, 0) && target && pos.X == 0 && pos.Y == 0 && + CColorConverter::canConvertFormat(Format, target->getColorFormat())) { + // No fast blitting, but copyToScaling uses other color conversions and might work + irr::core::dimension2du dim(target->getDimension()); + copyToScaling(target->getData(), dim.Width, dim.Height, target->getColorFormat(), target->getPitch()); + } +} + +//! copies this surface partially into another at given position +void CImage::copyTo(IImage *target, const core::position2d &pos, const core::rect &sourceRect, const core::rect *clipRect) +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::copyTo method doesn't work with compressed images.", ELL_WARNING); + return; + } + + Blit(BLITTER_TEXTURE, target, clipRect, &pos, this, &sourceRect, 0); +} + +//! copies this surface into another, using the alpha mask, a cliprect and a color to add with +void CImage::copyToWithAlpha(IImage *target, const core::position2d &pos, const core::rect &sourceRect, const SColor &color, const core::rect *clipRect, bool combineAlpha) +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::copyToWithAlpha method doesn't work with compressed images.", ELL_WARNING); + return; + } + + eBlitter op = combineAlpha ? BLITTER_TEXTURE_COMBINE_ALPHA : color.color == 0xFFFFFFFF ? BLITTER_TEXTURE_ALPHA_BLEND + : BLITTER_TEXTURE_ALPHA_COLOR_BLEND; + Blit(op, target, clipRect, &pos, this, &sourceRect, color.color); +} + +//! copies this surface into another, if it has the exact same size and format. +bool CImage::copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format, u32 pitch) const +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::copyToNoScaling method doesn't work with compressed images.", ELL_WARNING); + return false; + } + + if (!target || !width || !height || !Size.Width || !Size.Height) + return false; + + const u32 bpp = getBitsPerPixelFromFormat(format) / 8; + if (0 == pitch) + pitch = width * bpp; + + if (!(Format == format && Size.Width == width && Size.Height == height)) + return false; + + if (pitch == Pitch) { + memcpy(target, Data, (size_t)height * pitch); + } else { + u8 *tgtpos = (u8 *)target; + u8 *srcpos = Data; + const u32 bwidth = width * bpp; + const u32 rest = pitch - bwidth; + for (u32 y = 0; y < height; ++y) { + // copy scanline + memcpy(tgtpos, srcpos, bwidth); + // clear pitch + memset(tgtpos + bwidth, 0, rest); + tgtpos += pitch; + srcpos += Pitch; + } + } + + return true; +} + +//! copies this surface into another, scaling it to the target image size +// note: this is very very slow. +void CImage::copyToScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format, u32 pitch) +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::copyToScaling method doesn't work with compressed images.", ELL_WARNING); + return; + } + + if (!target || !width || !height || !Size.Width || !Size.Height) + return; + + const u32 bpp = getBitsPerPixelFromFormat(format) / 8; + if (0 == pitch) + pitch = width * bpp; + + if (copyToNoScaling(target, width, height, format, pitch)) + return; + + // NOTE: Scaling is coded to keep the border pixels intact. + // Alternatively we could for example work with first pixel being taken at half step-size. + // Then we have one more step here and it would be: + // sourceXStep = (f32)(Size.Width-1) / (f32)(width); + // And sx would start at 0.5f + sourceXStep / 2.f; + // Similar for y. + // As scaling is done without any antialiasing it doesn't matter too much which outermost pixels we use and keeping + // border pixels intact is probably mostly better (with AA the other solution would be more correct). + // This is however unnecessary (and unexpected) for scaling to integer multiples, so don't do it there. + f32 sourceXStep, sourceYStep; + f32 sourceXStart = 0.f, sourceYStart = 0.f; + if (width % Size.Width == 0) + sourceXStep = (f32)(Size.Width) / (f32)(width); + else { + sourceXStep = width > 1 ? (f32)(Size.Width - 1) / (f32)(width - 1) : 0.f; + sourceXStart = 0.5f; // for rounding to nearest pixel + } + if (height % Size.Height == 0) + sourceYStep = (f32)(Size.Height) / (f32)(height); + else { + sourceYStep = height > 1 ? (f32)(Size.Height - 1) / (f32)(height - 1) : 0.f; + sourceYStart = 0.5f; // for rounding to nearest pixel + } + + s32 yval = 0, syval = 0; + f32 sy = sourceYStart; + for (u32 y = 0; y < height; ++y) { + f32 sx = sourceXStart; + for (u32 x = 0; x < width; ++x) { + CColorConverter::convert_viaFormat(Data + syval + ((s32)sx) * BytesPerPixel, Format, 1, ((u8 *)target) + yval + (x * bpp), format); + sx += sourceXStep; + } + sy += sourceYStep; + syval = (s32)(sy)*Pitch; + yval += pitch; + } +} + +//! copies this surface into another, scaling it to the target image size +// note: this is very very slow. +void CImage::copyToScaling(IImage *target) +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::copyToScaling method doesn't work with compressed images.", ELL_WARNING); + return; + } + + if (!target) + return; + + const core::dimension2d &targetSize = target->getDimension(); + + if (targetSize == Size) { + copyTo(target); + return; + } + + copyToScaling(target->getData(), targetSize.Width, targetSize.Height, target->getColorFormat()); +} + +//! copies this surface into another, scaling it to fit it. +void CImage::copyToScalingBoxFilter(IImage *target, s32 bias, bool blend) +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::copyToScalingBoxFilter method doesn't work with compressed images.", ELL_WARNING); + return; + } + + const core::dimension2d destSize = target->getDimension(); + + const f32 sourceXStep = (f32)Size.Width / (f32)destSize.Width; + const f32 sourceYStep = (f32)Size.Height / (f32)destSize.Height; + + s32 fx = core::ceil32(sourceXStep); + s32 fy = core::ceil32(sourceYStep); + f32 sx; + f32 sy; + + sy = 0.f; + for (u32 y = 0; y != destSize.Height; ++y) { + sx = 0.f; + for (u32 x = 0; x != destSize.Width; ++x) { + target->setPixel(x, y, + getPixelBox(core::floor32(sx), core::floor32(sy), fx, fy, bias), blend); + sx += sourceXStep; + } + sy += sourceYStep; + } +} + +//! fills the surface with given color +void CImage::fill(const SColor &color) +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::fill method doesn't work with compressed images.", ELL_WARNING); + return; + } + + u32 c; + + switch (Format) { + case ECF_A1R5G5B5: + c = color.toA1R5G5B5(); + c |= c << 16; + break; + case ECF_R5G6B5: + c = video::A8R8G8B8toR5G6B5(color.color); + c |= c << 16; + break; + case ECF_A8R8G8B8: + c = color.color; + break; + case ECF_R8G8B8: { + u8 rgb[3]; + CColorConverter::convert_A8R8G8B8toR8G8B8(&color, 1, rgb); + const u32 size = getImageDataSizeInBytes(); + for (u32 i = 0; i < size; i += 3) { + memcpy(Data + i, rgb, 3); + } + return; + } break; + default: + // TODO: Handle other formats + return; + } + memset32(Data, c, getImageDataSizeInBytes()); +} + +//! get a filtered pixel +inline SColor CImage::getPixelBox(s32 x, s32 y, s32 fx, s32 fy, s32 bias) const +{ + if (IImage::isCompressedFormat(Format)) { + os::Printer::log("IImage::getPixelBox method doesn't work with compressed images.", ELL_WARNING); + return SColor(0); + } + + SColor c; + s32 a = 0, r = 0, g = 0, b = 0; + + for (s32 dx = 0; dx != fx; ++dx) { + for (s32 dy = 0; dy != fy; ++dy) { + c = getPixel(core::s32_min(x + dx, Size.Width - 1), + core::s32_min(y + dy, Size.Height - 1)); + + a += c.getAlpha(); + r += c.getRed(); + g += c.getGreen(); + b += c.getBlue(); + } + } + + s32 sdiv = s32_log2_s32(fx * fy); + + a = core::s32_clamp((a >> sdiv) + bias, 0, 255); + r = core::s32_clamp((r >> sdiv) + bias, 0, 255); + g = core::s32_clamp((g >> sdiv) + bias, 0, 255); + b = core::s32_clamp((b >> sdiv) + bias, 0, 255); + + c.set(a, r, g, b); + return c; +} + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImage.h b/irr/src/CImage.h new file mode 100644 index 000000000..955f85705 --- /dev/null +++ b/irr/src/CImage.h @@ -0,0 +1,74 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IImage.h" +#include "rect.h" + +namespace irr +{ +namespace video +{ + +//! check sanity of image dimensions to prevent issues later, for use by CImageLoaders +inline bool checkImageDimensions(u32 width, u32 height) +{ + // 4 * 23000 * 23000 is just under S32_MAX + return width <= 23000 && height <= 23000; +} + +//! IImage implementation with a lot of special image operations for +//! 16 bit A1R5G5B5/32 Bit A8R8G8B8 images, which are used by the SoftwareDevice. +class CImage : public IImage +{ +public: + //! constructor from raw image data + /** \param useForeignMemory: If true, the image will use the data pointer + directly and own it from now on, which means it will also try to delete [] the + data when the image will be destructed. If false, the memory will by copied. */ + CImage(ECOLOR_FORMAT format, const core::dimension2d &size, void *data, + bool ownForeignMemory = true, bool deleteMemory = true); + + //! constructor for empty image + CImage(ECOLOR_FORMAT format, const core::dimension2d &size); + + //! returns a pixel + SColor getPixel(u32 x, u32 y) const override; + + //! sets a pixel + void setPixel(u32 x, u32 y, const SColor &color, bool blend = false) override; + + //! copies this surface into another, if it has the exact same size and format. + bool copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format, u32 pitch = 0) const override; + + //! copies this surface into another, scaling it to fit. + void copyToScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format, u32 pitch = 0) override; + + //! copies this surface into another, scaling it to fit. + void copyToScaling(IImage *target) override; + + //! copies this surface into another + void copyTo(IImage *target, const core::position2d &pos = core::position2d(0, 0)) override; + + //! copies this surface into another + void copyTo(IImage *target, const core::position2d &pos, const core::rect &sourceRect, const core::rect *clipRect = 0) override; + + //! copies this surface into another, using the alpha mask, an cliprect and a color to add with + virtual void copyToWithAlpha(IImage *target, const core::position2d &pos, + const core::rect &sourceRect, const SColor &color, + const core::rect *clipRect = 0, bool combineAlpha = false) override; + + //! copies this surface into another, scaling it to fit, applying a box filter + void copyToScalingBoxFilter(IImage *target, s32 bias = 0, bool blend = false) override; + + //! fills the surface with given color + void fill(const SColor &color) override; + +private: + inline SColor getPixelBox(s32 x, s32 y, s32 fx, s32 fy, s32 bias) const; +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageLoaderBMP.cpp b/irr/src/CImageLoaderBMP.cpp new file mode 100644 index 000000000..301edb2fe --- /dev/null +++ b/irr/src/CImageLoaderBMP.cpp @@ -0,0 +1,402 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImageLoaderBMP.h" + +#include "IReadFile.h" +#include "SColor.h" +#include "CColorConverter.h" +#include "CImage.h" +#include "os.h" +#include "irrString.h" + +namespace irr +{ +namespace video +{ + +//! constructor +CImageLoaderBMP::CImageLoaderBMP() +{ +#ifdef _DEBUG + setDebugName("CImageLoaderBMP"); +#endif +} + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".tga") +bool CImageLoaderBMP::isALoadableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "bmp"); +} + +//! returns true if the file maybe is able to be loaded by this class +bool CImageLoaderBMP::isALoadableFileFormat(io::IReadFile *file) const +{ + u16 headerID; + file->read(&headerID, sizeof(u16)); +#ifdef __BIG_ENDIAN__ + headerID = os::Byteswap::byteswap(headerID); +#endif + return headerID == 0x4d42; +} + +// UB-safe overflow check +static inline bool overflowCheck(const void *base, size_t offset, const void *end) +{ + auto baseI = reinterpret_cast(base), + endI = reinterpret_cast(end); + return baseI > endI || offset >= (endI - baseI); +} +// check whether &p[0] to &p[_off - 1] can be accessed +#define CHECKP(_off) \ + if ((_off) < 0 || overflowCheck(p, _off, pEnd)) \ + goto exit +// same for d +#define CHECKD(_off) \ + if ((_off) < 0 || overflowCheck(d, _off, destEnd)) \ + goto exit + +void CImageLoaderBMP::decompress8BitRLE(u8 *&bmpData, s32 size, s32 width, s32 height, s32 pitch) const +{ + u8 *p = bmpData; + const u8 *pEnd = bmpData + size; + u8 *newBmp = new u8[(width + pitch) * height]; + u8 *d = newBmp; + const u8 *destEnd = newBmp + (width + pitch) * height; + s32 line = 0; + + while (p < pEnd && d < destEnd) { + if (*p == 0) { + ++p; + CHECKP(1); + + switch (*p) { + case 0: // end of line + ++p; + ++line; + d = newBmp + (line * (width + pitch)); + break; + case 1: // end of bmp + goto exit; + case 2: + ++p; + CHECKP(2); + d += (u8)*p; + ++p; // delta + d += ((u8)*p) * (width + pitch); + ++p; + break; + default: { + // absolute mode + s32 count = (u8)*p; + ++p; + s32 readAdditional = ((2 - (count % 2)) % 2); + + CHECKP(count); + CHECKD(count); + for (s32 i = 0; i < count; ++i) { + *d = *p; + ++p; + ++d; + } + + CHECKP(readAdditional); + for (s32 i = 0; i < readAdditional; ++i) + ++p; + } + } + } else { + s32 count = (u8)*p; + ++p; + CHECKP(1); + u8 color = *p; + ++p; + CHECKD(count); + for (s32 i = 0; i < count; ++i) { + *d = color; + ++d; + } + } + } + +exit: + delete[] bmpData; + bmpData = newBmp; +} + +// how many bytes will be touched given the current state of decompress4BitRLE +static inline u32 shiftedCount(s32 count, s32 shift) +{ + _IRR_DEBUG_BREAK_IF(count < 0) + u32 ret = count / 2; + if (shift == 0 || count % 2 == 1) + ++ret; + return ret; +} + +void CImageLoaderBMP::decompress4BitRLE(u8 *&bmpData, s32 size, s32 width, s32 height, s32 pitch) const +{ + const s32 lineWidth = (width + 1) / 2 + pitch; + u8 *p = bmpData; + const u8 *pEnd = bmpData + size; + u8 *newBmp = new u8[lineWidth * height]; + u8 *d = newBmp; + const u8 *destEnd = newBmp + lineWidth * height; + s32 line = 0; + s32 shift = 4; + + while (p < pEnd && d < destEnd) { + if (*p == 0) { + ++p; + CHECKP(1); + + switch (*p) { + case 0: // end of line + ++p; + ++line; + d = newBmp + (line * lineWidth); + shift = 4; + break; + case 1: // end of bmp + goto exit; + case 2: { + ++p; + CHECKP(2); + s32 x = (u8)*p; + ++p; + s32 y = (u8)*p; + ++p; + d += x / 2 + y * lineWidth; + shift = x % 2 == 0 ? 4 : 0; + } break; + default: { + // absolute mode + s32 count = (u8)*p; + ++p; + s32 readAdditional = ((2 - ((count) % 2)) % 2); + s32 readShift = 4; + + CHECKP(shiftedCount(count, readShift)); + CHECKD(shiftedCount(count, shift)); + for (s32 i = 0; i < count; ++i) { + s32 color = (((u8)*p) >> readShift) & 0x0f; + readShift -= 4; + if (readShift < 0) { + ++*p; // <- bug? + readShift = 4; + } + + u8 mask = 0x0f << shift; + *d = (*d & (~mask)) | ((color << shift) & mask); + + shift -= 4; + if (shift < 0) { + shift = 4; + ++d; + } + } + + CHECKP(readAdditional); + for (s32 i = 0; i < readAdditional; ++i) + ++p; + } + } + } else { + s32 count = (u8)*p; + ++p; + CHECKP(1); + s32 color1 = (u8)*p; + color1 = color1 & 0x0f; + s32 color2 = (u8)*p; + color2 = (color2 >> 4) & 0x0f; + ++p; + + CHECKD(shiftedCount(count, shift)); + for (s32 i = 0; i < count; ++i) { + u8 mask = 0x0f << shift; + u8 toSet = (shift == 0 ? color1 : color2) << shift; + *d = (*d & (~mask)) | (toSet & mask); + + shift -= 4; + if (shift < 0) { + shift = 4; + ++d; + } + } + } + } + +exit: + delete[] bmpData; + bmpData = newBmp; +} + +#undef CHECKOFF +#undef CHECKP +#undef CHECKD + +//! creates a surface from the file +IImage *CImageLoaderBMP::loadImage(io::IReadFile *file) const +{ + SBMPHeader header; + + file->read(&header, sizeof(header)); + +#ifdef __BIG_ENDIAN__ + header.Id = os::Byteswap::byteswap(header.Id); + header.FileSize = os::Byteswap::byteswap(header.FileSize); + header.BitmapDataOffset = os::Byteswap::byteswap(header.BitmapDataOffset); + header.BitmapHeaderSize = os::Byteswap::byteswap(header.BitmapHeaderSize); + header.Width = os::Byteswap::byteswap(header.Width); + header.Height = os::Byteswap::byteswap(header.Height); + header.Planes = os::Byteswap::byteswap(header.Planes); + header.BPP = os::Byteswap::byteswap(header.BPP); + header.Compression = os::Byteswap::byteswap(header.Compression); + header.BitmapDataSize = os::Byteswap::byteswap(header.BitmapDataSize); + header.PixelPerMeterX = os::Byteswap::byteswap(header.PixelPerMeterX); + header.PixelPerMeterY = os::Byteswap::byteswap(header.PixelPerMeterY); + header.Colors = os::Byteswap::byteswap(header.Colors); + header.ImportantColors = os::Byteswap::byteswap(header.ImportantColors); +#endif + + s32 pitch = 0; + + //! return if the header is false + + if (header.Id != 0x4d42) + return 0; + + if (header.Compression > 2) { // we'll only handle RLE-Compression + os::Printer::log("Compression mode not supported.", ELL_ERROR); + return 0; + } + + if (header.BPP > 32 || !checkImageDimensions(header.Width, header.Height)) { + os::Printer::log("Rejecting BMP with unreasonable size or BPP.", ELL_ERROR); + return 0; + } + + // adjust bitmap data size to dword boundary + header.BitmapDataSize += (4 - (header.BitmapDataSize % 4)) % 4; + + // read palette + + long pos = file->getPos(); + constexpr s32 paletteAllocSize = 256; + s32 paletteSize = (header.BitmapDataOffset - pos) / 4; + paletteSize = core::clamp(paletteSize, 0, paletteAllocSize); + + s32 *paletteData = 0; + if (paletteSize) { + // always allocate an 8-bit palette to ensure enough space + paletteData = new s32[paletteAllocSize]; + memset(paletteData, 0, paletteAllocSize * sizeof(s32)); + file->read(paletteData, paletteSize * sizeof(s32)); +#ifdef __BIG_ENDIAN__ + for (s32 i = 0; i < paletteSize; ++i) + paletteData[i] = os::Byteswap::byteswap(paletteData[i]); +#endif + } + + // read image data + + if (!header.BitmapDataSize) { + // okay, lets guess the size + // some tools simply don't set it + header.BitmapDataSize = static_cast(file->getSize()) - header.BitmapDataOffset; + } + + file->seek(header.BitmapDataOffset); + + s32 widthInBytes; + { + f32 t = (header.Width) * (header.BPP / 8.0f); + widthInBytes = (s32)t; + t -= widthInBytes; + if (t != 0.0f) + ++widthInBytes; + } + + const s32 lineSize = widthInBytes + ((4 - (widthInBytes % 4))) % 4; + pitch = lineSize - widthInBytes; + + u8 *bmpData = new u8[header.BitmapDataSize]; + file->read(bmpData, header.BitmapDataSize); + + // decompress data if needed + switch (header.Compression) { + case 1: // 8 bit rle + decompress8BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch); + header.BitmapDataSize = (header.Width + pitch) * header.Height; + break; + case 2: // 4 bit rle + decompress4BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch); + header.BitmapDataSize = ((header.Width + 1) / 2 + pitch) * header.Height; + break; + } + + if (header.BitmapDataSize < lineSize * header.Height) { + os::Printer::log("Bitmap data is cut off.", ELL_ERROR); + + delete[] paletteData; + delete[] bmpData; + return 0; + } + + // create surface + core::dimension2d dim; + dim.Width = header.Width; + dim.Height = header.Height; + + IImage *image = 0; + switch (header.BPP) { + case 1: + image = new CImage(ECF_A1R5G5B5, dim); + if (image) + CColorConverter::convert1BitTo16Bit(bmpData, (s16 *)image->getData(), header.Width, header.Height, pitch, true); + break; + case 4: + image = new CImage(ECF_A1R5G5B5, dim); + if (image) + CColorConverter::convert4BitTo16Bit(bmpData, (s16 *)image->getData(), header.Width, header.Height, paletteData, pitch, true); + break; + case 8: + image = new CImage(ECF_A1R5G5B5, dim); + if (image) + CColorConverter::convert8BitTo16Bit(bmpData, (s16 *)image->getData(), header.Width, header.Height, paletteData, pitch, true); + break; + case 16: + image = new CImage(ECF_A1R5G5B5, dim); + if (image) + CColorConverter::convert16BitTo16Bit((s16 *)bmpData, (s16 *)image->getData(), header.Width, header.Height, pitch, true); + break; + case 24: + image = new CImage(ECF_R8G8B8, dim); + if (image) + CColorConverter::convert24BitTo24Bit(bmpData, (u8 *)image->getData(), header.Width, header.Height, pitch, true, true); + break; + case 32: // thx to Reinhard Ostermeier + image = new CImage(ECF_A8R8G8B8, dim); + if (image) + CColorConverter::convert32BitTo32Bit((s32 *)bmpData, (s32 *)image->getData(), header.Width, header.Height, pitch, true); + break; + }; + + // clean up + + delete[] paletteData; + delete[] bmpData; + + return image; +} + +//! creates a loader which is able to load windows bitmaps +IImageLoader *createImageLoaderBMP() +{ + return new CImageLoaderBMP; +} + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageLoaderBMP.h b/irr/src/CImageLoaderBMP.h new file mode 100644 index 000000000..e7ef8ed2b --- /dev/null +++ b/irr/src/CImageLoaderBMP.h @@ -0,0 +1,81 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IImageLoader.h" + +namespace irr +{ +namespace video +{ + +// byte-align structures +#include "irrpack.h" + +struct SBMPHeader +{ + u16 Id; // BM - Windows 3.1x, 95, NT, 98, 2000, ME, XP + // BA - OS/2 Bitmap Array + // CI - OS/2 Color Icon + // CP - OS/2 Color Pointer + // IC - OS/2 Icon + // PT - OS/2 Pointer + u32 FileSize; + u32 Reserved; + u32 BitmapDataOffset; + u32 BitmapHeaderSize; // should be 28h for windows bitmaps or + // 0Ch for OS/2 1.x or F0h for OS/2 2.x + u32 Width; + u32 Height; + u16 Planes; + u16 BPP; // 1: Monochrome bitmap + // 4: 16 color bitmap + // 8: 256 color bitmap + // 16: 16bit (high color) bitmap + // 24: 24bit (true color) bitmap + // 32: 32bit (true color) bitmap + + u32 Compression; // 0: none (Also identified by BI_RGB) + // 1: RLE 8-bit / pixel (Also identified by BI_RLE4) + // 2: RLE 4-bit / pixel (Also identified by BI_RLE8) + // 3: Bitfields (Also identified by BI_BITFIELDS) + + u32 BitmapDataSize; // Size of the bitmap data in bytes. This number must be rounded to the next 4 byte boundary. + u32 PixelPerMeterX; + u32 PixelPerMeterY; + u32 Colors; + u32 ImportantColors; +} PACK_STRUCT; + +// Default alignment +#include "irrunpack.h" + +/*! + Surface Loader for Windows bitmaps +*/ +class CImageLoaderBMP : public IImageLoader +{ +public: + //! constructor + CImageLoaderBMP(); + + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".tga") + bool isALoadableFileExtension(const io::path &filename) const override; + + //! returns true if the file maybe is able to be loaded by this class + bool isALoadableFileFormat(io::IReadFile *file) const override; + + //! creates a surface from the file + IImage *loadImage(io::IReadFile *file) const override; + +private: + void decompress8BitRLE(u8 *&BmpData, s32 size, s32 width, s32 height, s32 pitch) const; + + void decompress4BitRLE(u8 *&BmpData, s32 size, s32 width, s32 height, s32 pitch) const; +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageLoaderJPG.cpp b/irr/src/CImageLoaderJPG.cpp new file mode 100644 index 000000000..e64c458e7 --- /dev/null +++ b/irr/src/CImageLoaderJPG.cpp @@ -0,0 +1,263 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImageLoaderJPG.h" + +#include "IReadFile.h" +#include "CImage.h" +#include "os.h" +#include "irrString.h" + +namespace irr +{ +namespace video +{ + +//! constructor +CImageLoaderJPG::CImageLoaderJPG() +{ +#ifdef _DEBUG + setDebugName("CImageLoaderJPG"); +#endif +} + +//! destructor +CImageLoaderJPG::~CImageLoaderJPG() +{ +} + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".tga") +bool CImageLoaderJPG::isALoadableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "jpg", "jpeg"); +} + +// struct for handling jpeg errors +struct irr_jpeg_error_mgr +{ + // public jpeg error fields + struct jpeg_error_mgr pub; + + // for longjmp, to return to caller on a fatal error + jmp_buf setjmp_buffer; + + // for having access to the filename when printing the error messages + core::stringc *filename; +}; + +void CImageLoaderJPG::init_source(j_decompress_ptr cinfo) +{ + // DO NOTHING +} + +boolean CImageLoaderJPG::fill_input_buffer(j_decompress_ptr cinfo) +{ + // DO NOTHING + return TRUE; +} + +void CImageLoaderJPG::skip_input_data(j_decompress_ptr cinfo, long count) +{ + jpeg_source_mgr *src = cinfo->src; + if (count > 0) { + src->bytes_in_buffer -= count; + src->next_input_byte += count; + } +} + +void CImageLoaderJPG::term_source(j_decompress_ptr cinfo) +{ + // DO NOTHING +} + +void CImageLoaderJPG::error_exit(j_common_ptr cinfo) +{ + // unfortunately we need to use a goto rather than throwing an exception + // as gcc crashes under linux crashes when using throw from within + // extern c code + + // Always display the message + (*cinfo->err->output_message)(cinfo); + + // cinfo->err really points to a irr_error_mgr struct + irr_jpeg_error_mgr *myerr = (irr_jpeg_error_mgr *)cinfo->err; + + longjmp(myerr->setjmp_buffer, 1); +} + +void CImageLoaderJPG::output_message(j_common_ptr cinfo) +{ + // display the error message. + c8 temp1[JMSG_LENGTH_MAX]; + (*cinfo->err->format_message)(cinfo, temp1); + core::stringc errMsg("JPEG FATAL ERROR in "); + + irr_jpeg_error_mgr *myerr = (irr_jpeg_error_mgr *)cinfo->err; + errMsg += *myerr->filename; + os::Printer::log(errMsg.c_str(), temp1, ELL_ERROR); +} + +//! returns true if the file maybe is able to be loaded by this class +bool CImageLoaderJPG::isALoadableFileFormat(io::IReadFile *file) const +{ + if (!(file && file->seek(0))) + return false; + unsigned char header[3]; + size_t headerLen = file->read(header, sizeof(header)); + return headerLen >= 3 && !memcmp(header, "\xFF\xD8\xFF", 3); +} + +//! creates a surface from the file +IImage *CImageLoaderJPG::loadImage(io::IReadFile *file) const +{ + if (!file) + return 0; + + core::stringc filename = file->getFileName(); + + u8 **rowPtr = 0; + u8 *input = new u8[file->getSize()]; + file->read(input, file->getSize()); + + // allocate and initialize JPEG decompression object + struct jpeg_decompress_struct cinfo; + struct irr_jpeg_error_mgr jerr; + + // We have to set up the error handler first, in case the initialization + // step fails. (Unlikely, but it could happen if you are out of memory.) + // This routine fills in the contents of struct jerr, and returns jerr's + // address which we place into the link field in cinfo. + + cinfo.err = jpeg_std_error(&jerr.pub); + cinfo.err->error_exit = error_exit; + cinfo.err->output_message = output_message; + jerr.filename = &filename; + + // compatibility fudge: + // we need to use setjmp/longjmp for error handling as gcc-linux + // crashes when throwing within external c code + if (setjmp(jerr.setjmp_buffer)) { + // If we get here, the JPEG code has signaled an error. + // We need to clean up the JPEG object and return. + + jpeg_destroy_decompress(&cinfo); + + delete[] input; + delete[] rowPtr; + + // return null pointer + return 0; + } + + // Now we can initialize the JPEG decompression object. + jpeg_create_decompress(&cinfo); + + // specify data source + jpeg_source_mgr jsrc; + + // Set up data pointer + jsrc.bytes_in_buffer = file->getSize(); + jsrc.next_input_byte = (JOCTET *)input; + cinfo.src = &jsrc; + + jsrc.init_source = init_source; + jsrc.fill_input_buffer = fill_input_buffer; + jsrc.skip_input_data = skip_input_data; + jsrc.resync_to_restart = jpeg_resync_to_restart; + jsrc.term_source = term_source; + + // Decodes JPG input from whatever source + // Does everything AFTER jpeg_create_decompress + // and BEFORE jpeg_destroy_decompress + // Caller is responsible for arranging these + setting up cinfo + + // read file parameters with jpeg_read_header() + jpeg_read_header(&cinfo, TRUE); + + bool useCMYK = false; + if (cinfo.jpeg_color_space == JCS_CMYK) { + cinfo.out_color_space = JCS_CMYK; + cinfo.out_color_components = 4; + useCMYK = true; + } else { + cinfo.out_color_space = JCS_RGB; + cinfo.out_color_components = 3; + } + cinfo.output_gamma = 2.2; + cinfo.do_fancy_upsampling = FALSE; + + // reject unreasonable sizes + if (!checkImageDimensions(cinfo.image_width, cinfo.image_height)) + longjmp(jerr.setjmp_buffer, 1); + + // Start decompressor + jpeg_start_decompress(&cinfo); + + // Get image data + u32 rowspan = cinfo.image_width * cinfo.out_color_components; + u32 width = cinfo.image_width; + u32 height = cinfo.image_height; + + // Allocate memory for buffer + u8 *output = new u8[rowspan * height]; + + // Here we use the library's state variable cinfo.output_scanline as the + // loop counter, so that we don't have to keep track ourselves. + // Create array of row pointers for lib + rowPtr = new u8 *[height]; + + for (u32 i = 0; i < height; i++) + rowPtr[i] = &output[i * rowspan]; + + u32 rowsRead = 0; + + while (cinfo.output_scanline < cinfo.output_height) + rowsRead += jpeg_read_scanlines(&cinfo, &rowPtr[rowsRead], cinfo.output_height - rowsRead); + + delete[] rowPtr; + // Finish decompression + + jpeg_finish_decompress(&cinfo); + + // Release JPEG decompression object + // This is an important step since it will release a good deal of memory. + jpeg_destroy_decompress(&cinfo); + + // convert image + IImage *image = 0; + if (useCMYK) { + image = new CImage(ECF_R8G8B8, + core::dimension2d(width, height)); + const u32 size = 3 * width * height; + u8 *data = (u8 *)image->getData(); + if (data) { + for (u32 i = 0, j = 0; i < size; i += 3, j += 4) { + // Also works without K, but has more contrast with K multiplied in + // data[i+0] = output[j+2]; + // data[i+1] = output[j+1]; + // data[i+2] = output[j+0]; + data[i + 0] = (char)(output[j + 2] * (output[j + 3] / 255.f)); + data[i + 1] = (char)(output[j + 1] * (output[j + 3] / 255.f)); + data[i + 2] = (char)(output[j + 0] * (output[j + 3] / 255.f)); + } + } + delete[] output; + } else + image = new CImage(ECF_R8G8B8, + core::dimension2d(width, height), output); + + delete[] input; + + return image; +} + +//! creates a loader which is able to load jpeg images +IImageLoader *createImageLoaderJPG() +{ + return new CImageLoaderJPG(); +} + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageLoaderJPG.h b/irr/src/CImageLoaderJPG.h new file mode 100644 index 000000000..921a46a25 --- /dev/null +++ b/irr/src/CImageLoaderJPG.h @@ -0,0 +1,87 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IImageLoader.h" + +#include // required for jpeglib.h +#include // use system lib +#include + +namespace irr +{ +namespace video +{ + +//! Surface Loader for JPG images +class CImageLoaderJPG : public IImageLoader +{ +public: + //! constructor + CImageLoaderJPG(); + + //! destructor + virtual ~CImageLoaderJPG(); + + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".tga") + bool isALoadableFileExtension(const io::path &filename) const override; + + //! returns true if the file maybe is able to be loaded by this class + bool isALoadableFileFormat(io::IReadFile *file) const override; + + //! creates a surface from the file + IImage *loadImage(io::IReadFile *file) const override; + +private: + // several methods used via function pointers by jpeglib + + /* Receives control for a fatal error. Information sufficient to + generate the error message has been stored in cinfo->err; call + output_message to display it. Control must NOT return to the caller; + generally this routine will exit() or longjmp() somewhere. + Typically you would override this routine to get rid of the exit() + default behavior. Note that if you continue processing, you should + clean up the JPEG object with jpeg_abort() or jpeg_destroy(). + */ + static void error_exit(j_common_ptr cinfo); + + /* output error messages via Irrlicht logger. */ + static void output_message(j_common_ptr cinfo); + + /* Initialize source. This is called by jpeg_read_header() before any + data is actually read. Unlike init_destination(), it may leave + bytes_in_buffer set to 0 (in which case a fill_input_buffer() call + will occur immediately). */ + static void init_source(j_decompress_ptr cinfo); + + /* This is called whenever bytes_in_buffer has reached zero and more + data is wanted. In typical applications, it should read fresh data + into the buffer (ignoring the current state of next_input_byte and + bytes_in_buffer), reset the pointer & count to the start of the + buffer, and return TRUE indicating that the buffer has been reloaded. + It is not necessary to fill the buffer entirely, only to obtain at + least one more byte. bytes_in_buffer MUST be set to a positive value + if TRUE is returned. A FALSE return should only be used when I/O + suspension is desired (this mode is discussed in the next section). */ + static boolean fill_input_buffer(j_decompress_ptr cinfo); + + /* Skip num_bytes worth of data. The buffer pointer and count should + be advanced over num_bytes input bytes, refilling the buffer as + needed. This is used to skip over a potentially large amount of + uninteresting data (such as an APPn marker). In some applications + it may be possible to optimize away the reading of the skipped data, + but it's not clear that being smart is worth much trouble; large + skips are uncommon. bytes_in_buffer may be zero on return. + A zero or negative skip count should be treated as a no-op. */ + static void skip_input_data(j_decompress_ptr cinfo, long num_bytes); + + /* Terminate source --- called by jpeg_finish_decompress() after all + data has been read. Often a no-op. */ + static void term_source(j_decompress_ptr cinfo); +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageLoaderPNG.cpp b/irr/src/CImageLoaderPNG.cpp new file mode 100644 index 000000000..42cfc51d2 --- /dev/null +++ b/irr/src/CImageLoaderPNG.cpp @@ -0,0 +1,248 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImageLoaderPNG.h" + +#include // use system lib png + +#include "CImage.h" +#include "CReadFile.h" +#include "os.h" + +namespace irr +{ +namespace video +{ + +// PNG function for error handling +static void png_cpexcept_error(png_structp png_ptr, png_const_charp msg) +{ + os::Printer::log("PNG fatal error", msg, ELL_ERROR); + longjmp(png_jmpbuf(png_ptr), 1); +} + +// PNG function for warning handling +static void png_cpexcept_warn(png_structp png_ptr, png_const_charp msg) +{ + os::Printer::log("PNG warning", msg, ELL_WARNING); +} + +// PNG function for file reading +void PNGAPI user_read_data_fcn(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + // changed by zola { + io::IReadFile *file = (io::IReadFile *)png_get_io_ptr(png_ptr); + check = (png_size_t)file->read((void *)data, length); + // } + + if (check != length) + png_error(png_ptr, "Read Error"); +} + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".tga") +bool CImageLoaderPng::isALoadableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "png"); +} + +//! returns true if the file maybe is able to be loaded by this class +bool CImageLoaderPng::isALoadableFileFormat(io::IReadFile *file) const +{ + if (!file) + return false; + + png_byte buffer[8]; + // Read the first few bytes of the PNG file + if (file->read(buffer, 8) != 8) + return false; + + // Check if it really is a PNG file + return !png_sig_cmp(buffer, 0, 8); +} + +// load in the image data +IImage *CImageLoaderPng::loadImage(io::IReadFile *file) const +{ + if (!file) + return 0; + + // Used to point to image rows + u8 **RowPointers = 0; + + png_byte buffer[8]; + // Read the first few bytes of the PNG file + if (file->read(buffer, 8) != 8) { + os::Printer::log("LOAD PNG: can't read file (filesize < 8)", file->getFileName(), ELL_ERROR); + return 0; + } + + // Check if it really is a PNG file + if (png_sig_cmp(buffer, 0, 8)) { + os::Printer::log("LOAD PNG: not really a png (wrong signature)", file->getFileName(), ELL_ERROR); + return 0; + } + + // Allocate the png read struct + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + NULL, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warn); + if (!png_ptr) { + os::Printer::log("LOAD PNG: Internal PNG create read struct failure", file->getFileName(), ELL_ERROR); + return 0; + } + + // Allocate the png info struct + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + os::Printer::log("LOAD PNG: Internal PNG create info struct failure", file->getFileName(), ELL_ERROR); + png_destroy_read_struct(&png_ptr, NULL, NULL); + return 0; + } + + // for proper error handling + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + delete[] RowPointers; + return 0; + } + + // changed by zola so we don't need to have public FILE pointers + png_set_read_fn(png_ptr, file, user_read_data_fcn); + + png_set_sig_bytes(png_ptr, 8); // Tell png that we read the signature + + png_read_info(png_ptr, info_ptr); // Read the info section of the png file + + u32 Width; + u32 Height; + s32 BitDepth; + s32 ColorType; + { + // Use temporary variables to avoid passing cast pointers + png_uint_32 w, h; + // Extract info + png_get_IHDR(png_ptr, info_ptr, + &w, &h, + &BitDepth, &ColorType, NULL, NULL, NULL); + Width = w; + Height = h; + } + + if (!checkImageDimensions(Width, Height)) + png_cpexcept_error(png_ptr, "Unreasonable size"); + + // Convert palette color to true color + if (ColorType == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + // Convert low bit colors to 8 bit colors + if (BitDepth < 8) { + if (ColorType == PNG_COLOR_TYPE_GRAY || ColorType == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_expand_gray_1_2_4_to_8(png_ptr); + else + png_set_packing(png_ptr); + } + + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_tRNS_to_alpha(png_ptr); + + // Convert high bit colors to 8 bit colors + if (BitDepth == 16) + png_set_strip_16(png_ptr); + + // Convert gray color to true color + if (ColorType == PNG_COLOR_TYPE_GRAY || ColorType == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + + int intent; + const double screen_gamma = 2.2; + + if (png_get_sRGB(png_ptr, info_ptr, &intent)) + png_set_gamma(png_ptr, screen_gamma, 0.45455); + else { + double image_gamma; + if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)) + png_set_gamma(png_ptr, screen_gamma, image_gamma); + else + png_set_gamma(png_ptr, screen_gamma, 0.45455); + } + + // Update the changes in between, as we need to get the new color type + // for proper processing of the RGBA type + png_read_update_info(png_ptr, info_ptr); + { + // Use temporary variables to avoid passing cast pointers + png_uint_32 w, h; + // Extract info + png_get_IHDR(png_ptr, info_ptr, + &w, &h, + &BitDepth, &ColorType, NULL, NULL, NULL); + Width = w; + Height = h; + } + + // Convert RGBA to BGRA + if (ColorType == PNG_COLOR_TYPE_RGB_ALPHA) { +#ifdef __BIG_ENDIAN__ + png_set_swap_alpha(png_ptr); +#else + png_set_bgr(png_ptr); +#endif + } + + // Create the image structure to be filled by png data + video::IImage *image = 0; + if (ColorType == PNG_COLOR_TYPE_RGB_ALPHA) + image = new CImage(ECF_A8R8G8B8, core::dimension2d(Width, Height)); + else + image = new CImage(ECF_R8G8B8, core::dimension2d(Width, Height)); + if (!image) { + os::Printer::log("LOAD PNG: Internal PNG create image struct failure", file->getFileName(), ELL_ERROR); + png_destroy_read_struct(&png_ptr, NULL, NULL); + return 0; + } + + // Create array of pointers to rows in image data + RowPointers = new png_bytep[Height]; + if (!RowPointers) { + os::Printer::log("LOAD PNG: Internal PNG create row pointers failure", file->getFileName(), ELL_ERROR); + png_destroy_read_struct(&png_ptr, NULL, NULL); + delete image; + return 0; + } + + // Fill array of pointers to rows in image data + unsigned char *data = (unsigned char *)image->getData(); + for (u32 i = 0; i < Height; ++i) { + RowPointers[i] = data; + data += image->getPitch(); + } + + // for proper error handling + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + delete[] RowPointers; + delete image; + return 0; + } + + // Read data using the library function that handles all transformations including interlacing + png_read_image(png_ptr, RowPointers); + + png_read_end(png_ptr, NULL); + delete[] RowPointers; + png_destroy_read_struct(&png_ptr, &info_ptr, 0); // Clean up memory + + return image; +} + +IImageLoader *createImageLoaderPNG() +{ + return new CImageLoaderPng(); +} + +} // end namespace irr +} // end namespace video diff --git a/irr/src/CImageLoaderPNG.h b/irr/src/CImageLoaderPNG.h new file mode 100644 index 000000000..f878320ba --- /dev/null +++ b/irr/src/CImageLoaderPNG.h @@ -0,0 +1,34 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// this file was created by rt (www.tomkorp.com), based on ttk's png-reader +// i wanted to be able to read in PNG images with irrlicht :) +// why? lossless compression with 8-bit alpha channel! + +#pragma once + +#include "IImageLoader.h" + +namespace irr +{ +namespace video +{ + +//! Surface Loader for PNG files +class CImageLoaderPng : public IImageLoader +{ +public: + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".png") + bool isALoadableFileExtension(const io::path &filename) const override; + + //! returns true if the file maybe is able to be loaded by this class + bool isALoadableFileFormat(io::IReadFile *file) const override; + + //! creates a surface from the file + IImage *loadImage(io::IReadFile *file) const override; +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageLoaderTGA.cpp b/irr/src/CImageLoaderTGA.cpp new file mode 100644 index 000000000..5b7cc6143 --- /dev/null +++ b/irr/src/CImageLoaderTGA.cpp @@ -0,0 +1,246 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImageLoaderTGA.h" + +#include "IReadFile.h" +#include "os.h" +#include "CColorConverter.h" +#include "CImage.h" +#include "irrString.h" + +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) + +namespace irr +{ +namespace video +{ + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".tga") +bool CImageLoaderTGA::isALoadableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "tga"); +} + +//! loads a compressed tga. +u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader &header) const +{ + // This was written and sent in by Jon Pry, thank you very much! + // I only changed the formatting a little bit. + + const u32 bytesPerPixel = header.PixelDepth / 8; + const u32 imageSize = header.ImageHeight * header.ImageWidth * bytesPerPixel; + u8 *data = new u8[imageSize]; + u32 currentByte = 0; + + while (currentByte < imageSize) { + u8 chunkheader = 0; + file->read(&chunkheader, sizeof(u8)); // Read The Chunk's Header + + if (chunkheader < 128) { // If The Chunk Is A 'RAW' Chunk + chunkheader++; // Add 1 To The Value To Get Total Number Of Raw Pixels + + const u32 bytesToRead = bytesPerPixel * chunkheader; + if (currentByte + bytesToRead <= imageSize) { + file->read(&data[currentByte], bytesToRead); + currentByte += bytesToRead; + } else { + os::Printer::log("Compressed TGA file RAW chunk tries writing beyond buffer", file->getFileName(), ELL_WARNING); + break; + } + } else { + // thnx to neojzs for some fixes with this code + + // If It's An RLE Header + chunkheader -= 127; // Subtract 127 To Get Rid Of The ID Bit + + u32 dataOffset = currentByte; + if (dataOffset + bytesPerPixel < imageSize) { + file->read(&data[dataOffset], bytesPerPixel); + currentByte += bytesPerPixel; + } else { + os::Printer::log("Compressed TGA file RLE headertries writing beyond buffer", file->getFileName(), ELL_WARNING); + break; + } + + for (u32 counter = 1; counter < chunkheader; counter++) { + if (currentByte + bytesPerPixel <= imageSize) { + for (u32 elementCounter = 0; elementCounter < bytesPerPixel; elementCounter++) { + data[currentByte + elementCounter] = data[dataOffset + elementCounter]; + } + } + + currentByte += bytesPerPixel; + } + } + } + + return data; +} + +//! returns true if the file maybe is able to be loaded by this class +bool CImageLoaderTGA::isALoadableFileFormat(io::IReadFile *file) const +{ + if (!file) + return false; + + STGAFooter footer; + memset(&footer, 0, sizeof(STGAFooter)); + file->seek(file->getSize() - sizeof(STGAFooter)); + file->read(&footer, sizeof(STGAFooter)); + return (!strcmp(footer.Signature, "TRUEVISION-XFILE.")); // very old tgas are refused. +} + +//! creates a surface from the file +IImage *CImageLoaderTGA::loadImage(io::IReadFile *file) const +{ + STGAHeader header; + u32 *palette = 0; + + file->read(&header, sizeof(STGAHeader)); + +#ifdef __BIG_ENDIAN__ + header.ColorMapLength = os::Byteswap::byteswap(header.ColorMapLength); + header.ImageWidth = os::Byteswap::byteswap(header.ImageWidth); + header.ImageHeight = os::Byteswap::byteswap(header.ImageHeight); +#endif + + if (!checkImageDimensions(header.ImageWidth, header.ImageHeight)) { + os::Printer::log("Image dimensions too large in file", file->getFileName(), ELL_ERROR); + return 0; + } + + // skip image identification field + if (header.IdLength) + file->seek(header.IdLength, true); + + if (header.ColorMapType) { + // Create 32 bit palette + // `core::max_()` is not used here because it takes its inputs as references. Since `header` is packed, use the macro `MAX()` instead: + const irr::u16 paletteSize = MAX((u16)256u, header.ColorMapLength); // ColorMapLength can lie, but so far we only use palette for 8-bit, so ensure it has 256 entries + palette = new u32[paletteSize]; + + if (paletteSize > header.ColorMapLength) { + // To catch images using palette colors with invalid indices + const irr::u32 errorCol = irr::video::SColor(255, 255, 0, 205).color; // bright magenta + for (irr::u16 i = header.ColorMapLength; i < paletteSize; ++i) + palette[i] = errorCol; + } + + // read color map + u8 *colorMap = new u8[header.ColorMapEntrySize / 8 * header.ColorMapLength]; + file->read(colorMap, header.ColorMapEntrySize / 8 * header.ColorMapLength); + + // convert to 32-bit palette + switch (header.ColorMapEntrySize) { + case 16: + CColorConverter::convert_A1R5G5B5toA8R8G8B8(colorMap, header.ColorMapLength, palette); + break; + case 24: + CColorConverter::convert_B8G8R8toA8R8G8B8(colorMap, header.ColorMapLength, palette); + break; + case 32: + CColorConverter::convert_B8G8R8A8toA8R8G8B8(colorMap, header.ColorMapLength, palette); + break; + } + delete[] colorMap; + } + + // read image + + u8 *data = 0; + + if (header.ImageType == 1 || // Uncompressed, color-mapped images. + header.ImageType == 2 || // Uncompressed, RGB images + header.ImageType == 3 // Uncompressed, black and white images + ) { + const s32 imageSize = header.ImageHeight * header.ImageWidth * (header.PixelDepth / 8); + data = new u8[imageSize]; + file->read(data, imageSize); + } else if (header.ImageType == 10) { + // Runlength encoded RGB images + data = loadCompressedImage(file, header); + } else { + os::Printer::log("Unsupported TGA file type", file->getFileName(), ELL_ERROR); + delete[] palette; + return 0; + } + + IImage *image = 0; + + switch (header.PixelDepth) { + case 8: { + if (header.ImageType == 3) { // grey image + image = new CImage(ECF_R8G8B8, + core::dimension2d(header.ImageWidth, header.ImageHeight)); + if (image) + CColorConverter::convert8BitTo24Bit((u8 *)data, + (u8 *)image->getData(), + header.ImageWidth, header.ImageHeight, + 0, 0, (header.ImageDescriptor & 0x20) == 0); + } else { + switch (header.ColorMapEntrySize) { + case 16: + image = new CImage(ECF_A1R5G5B5, core::dimension2d(header.ImageWidth, header.ImageHeight)); + if (image) + CColorConverter::convert8BitTo16Bit((u8 *)data, + (s16 *)image->getData(), + header.ImageWidth, header.ImageHeight, + (s32 *)palette, 0, + (header.ImageDescriptor & 0x20) == 0); + break; + // Note: 24 bit with palette would need a 24 bit palette, too lazy doing that now (textures will prefer 32-bit later anyway) + default: + image = new CImage(ECF_A8R8G8B8, core::dimension2d(header.ImageWidth, header.ImageHeight)); + if (image) + CColorConverter::convert8BitTo32Bit((u8 *)data, + (u8 *)image->getData(), + header.ImageWidth, header.ImageHeight, + (u8 *)palette, 0, + (header.ImageDescriptor & 0x20) == 0); + break; + } + } + } break; + case 16: + image = new CImage(ECF_A1R5G5B5, + core::dimension2d(header.ImageWidth, header.ImageHeight)); + if (image) + CColorConverter::convert16BitTo16Bit((s16 *)data, + (s16 *)image->getData(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor & 0x20) == 0); + break; + case 24: + image = new CImage(ECF_R8G8B8, + core::dimension2d(header.ImageWidth, header.ImageHeight)); + if (image) + CColorConverter::convert24BitTo24Bit( + (u8 *)data, (u8 *)image->getData(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor & 0x20) == 0, true); + break; + case 32: + image = new CImage(ECF_A8R8G8B8, + core::dimension2d(header.ImageWidth, header.ImageHeight)); + if (image) + CColorConverter::convert32BitTo32Bit((s32 *)data, + (s32 *)image->getData(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor & 0x20) == 0); + break; + default: + os::Printer::log("Unsupported TGA format", file->getFileName(), ELL_ERROR); + break; + } + + delete[] data; + delete[] palette; + + return image; +} + +//! creates a loader which is able to load tgas +IImageLoader *createImageLoaderTGA() +{ + return new CImageLoaderTGA(); +} + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageLoaderTGA.h b/irr/src/CImageLoaderTGA.h new file mode 100644 index 000000000..18930da3d --- /dev/null +++ b/irr/src/CImageLoaderTGA.h @@ -0,0 +1,66 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IImageLoader.h" + +namespace irr +{ +namespace video +{ + +// byte-align structures +#include "irrpack.h" + +// these structs are also used in the TGA writer +struct STGAHeader +{ + u8 IdLength; + u8 ColorMapType; + u8 ImageType; + u8 FirstEntryIndex[2]; + u16 ColorMapLength; + u8 ColorMapEntrySize; + u8 XOrigin[2]; + u8 YOrigin[2]; + u16 ImageWidth; + u16 ImageHeight; + u8 PixelDepth; + u8 ImageDescriptor; +} PACK_STRUCT; + +struct STGAFooter +{ + u32 ExtensionOffset; + u32 DeveloperOffset; + c8 Signature[18]; +} PACK_STRUCT; + +// Default alignment +#include "irrunpack.h" + +/*! + Surface Loader for targa images +*/ +class CImageLoaderTGA : public IImageLoader +{ +public: + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".tga") + bool isALoadableFileExtension(const io::path &filename) const override; + + //! returns true if the file maybe is able to be loaded by this class + bool isALoadableFileFormat(io::IReadFile *file) const override; + + //! creates a surface from the file + IImage *loadImage(io::IReadFile *file) const override; + +private: + //! loads a compressed tga. Was written and sent in by Jon Pry, thank you very much! + u8 *loadCompressedImage(io::IReadFile *file, const STGAHeader &header) const; +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/CImageWriterJPG.cpp b/irr/src/CImageWriterJPG.cpp new file mode 100644 index 000000000..574e46041 --- /dev/null +++ b/irr/src/CImageWriterJPG.cpp @@ -0,0 +1,195 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImageWriterJPG.h" + +#include "CColorConverter.h" +#include "IWriteFile.h" +#include "CImage.h" +#include "irrString.h" +#include "os.h" + +#include // required for jpeglib.h +extern "C" { +#include +#include +} + +namespace irr +{ +namespace video +{ + +// The writer uses a 4k buffer and flushes to disk each time it's filled +#define OUTPUT_BUF_SIZE 4096 +typedef struct +{ + struct jpeg_destination_mgr pub; /* public fields */ + + io::IWriteFile *file; /* target file */ + JOCTET buffer[OUTPUT_BUF_SIZE]; /* image buffer */ +} mem_destination_mgr; + +typedef mem_destination_mgr *mem_dest_ptr; + +// init +static void jpeg_init_destination(j_compress_ptr cinfo) +{ + mem_dest_ptr dest = (mem_dest_ptr)cinfo->dest; + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; +} + +// flush to disk and reset buffer +static boolean jpeg_empty_output_buffer(j_compress_ptr cinfo) +{ + mem_dest_ptr dest = (mem_dest_ptr)cinfo->dest; + + // for now just exit upon file error + if (dest->file->write(dest->buffer, OUTPUT_BUF_SIZE) != OUTPUT_BUF_SIZE) + ERREXIT(cinfo, JERR_FILE_WRITE); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + + return TRUE; +} + +static void jpeg_term_destination(j_compress_ptr cinfo) +{ + mem_dest_ptr dest = (mem_dest_ptr)cinfo->dest; + const size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; + // for now just exit upon file error + if (dest->file->write(dest->buffer, datacount) != datacount) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + +// set up buffer data +static void jpeg_file_dest(j_compress_ptr cinfo, io::IWriteFile *file) +{ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr)cinfo, + JPOOL_PERMANENT, + sizeof(mem_destination_mgr)); + } + + mem_dest_ptr dest = (mem_dest_ptr)cinfo->dest; /* for casting */ + + /* Initialize method pointers */ + dest->pub.init_destination = jpeg_init_destination; + dest->pub.empty_output_buffer = jpeg_empty_output_buffer; + dest->pub.term_destination = jpeg_term_destination; + + /* Initialize private member */ + dest->file = file; +} + +/* write_JPEG_memory: store JPEG compressed image into memory. + */ +static bool writeJPEGFile(io::IWriteFile *file, IImage *image, u32 quality) +{ + void (*format)(const void *, s32, void *) = 0; + switch (image->getColorFormat()) { + case ECF_R8G8B8: + format = CColorConverter::convert_R8G8B8toR8G8B8; + break; + case ECF_A8R8G8B8: + format = CColorConverter::convert_A8R8G8B8toR8G8B8; + break; + case ECF_A1R5G5B5: + format = CColorConverter::convert_A1R5G5B5toB8G8R8; + break; + case ECF_R5G6B5: + format = CColorConverter::convert_R5G6B5toR8G8B8; + break; + default: + os::Printer::log("writeJPEGFile does not support image format", ColorFormatNames[image->getColorFormat()], ELL_WARNING); + break; + } + + // couldn't find a color converter + if (0 == format) + return false; + + const core::dimension2du dim = image->getDimension(); + + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + cinfo.err = jpeg_std_error(&jerr); + + jpeg_create_compress(&cinfo); + jpeg_file_dest(&cinfo, file); + cinfo.image_width = dim.Width; + cinfo.image_height = dim.Height; + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + + jpeg_set_defaults(&cinfo); + + if (0 == quality) + quality = 75; + + jpeg_set_quality(&cinfo, quality, TRUE); + jpeg_start_compress(&cinfo, TRUE); + + u8 *dest = new u8[dim.Width * 3]; + + if (dest) { + const u32 pitch = image->getPitch(); + JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ + row_pointer[0] = dest; + + u8 *src = (u8 *)image->getData(); + + while (cinfo.next_scanline < cinfo.image_height) { + // convert next line + format(src, dim.Width, dest); + src += pitch; + jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + + delete[] dest; + + /* Step 6: Finish compression */ + jpeg_finish_compress(&cinfo); + } + + /* Step 7: Destroy */ + jpeg_destroy_compress(&cinfo); + + return (dest != 0); +} + +} // namespace video +} // namespace irr + +namespace irr +{ +namespace video +{ + +IImageWriter *createImageWriterJPG() +{ + return new CImageWriterJPG; +} + +CImageWriterJPG::CImageWriterJPG() +{ +#ifdef _DEBUG + setDebugName("CImageWriterJPG"); +#endif +} + +bool CImageWriterJPG::isAWriteableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "jpg", "jpeg"); +} + +bool CImageWriterJPG::writeImage(io::IWriteFile *file, IImage *image, u32 quality) const +{ + return writeJPEGFile(file, image, quality); +} + +} // namespace video +} // namespace irr diff --git a/irr/src/CImageWriterJPG.h b/irr/src/CImageWriterJPG.h new file mode 100644 index 000000000..1d8dde53f --- /dev/null +++ b/irr/src/CImageWriterJPG.h @@ -0,0 +1,28 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IImageWriter.h" + +namespace irr +{ +namespace video +{ + +class CImageWriterJPG : public IImageWriter +{ +public: + //! constructor + CImageWriterJPG(); + + //! return true if this writer can write a file with the given extension + bool isAWriteableFileExtension(const io::path &filename) const override; + + //! write image to file + bool writeImage(io::IWriteFile *file, IImage *image, u32 param) const override; +}; + +} +} diff --git a/irr/src/CImageWriterPNG.cpp b/irr/src/CImageWriterPNG.cpp new file mode 100644 index 000000000..1c8a840ca --- /dev/null +++ b/irr/src/CImageWriterPNG.cpp @@ -0,0 +1,190 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImageWriterPNG.h" + +#include "CImageLoaderPNG.h" +#include "CColorConverter.h" +#include "IWriteFile.h" +#include "irrString.h" +#include "os.h" // for logging + +#include // use system lib png + +namespace irr +{ +namespace video +{ + +IImageWriter *createImageWriterPNG() +{ + return new CImageWriterPNG; +} + +// PNG function for error handling +static void png_cpexcept_error(png_structp png_ptr, png_const_charp msg) +{ + os::Printer::log("PNG fatal error", msg, ELL_ERROR); + longjmp(png_jmpbuf(png_ptr), 1); +} + +// PNG function for warning handling +static void png_cpexcept_warning(png_structp png_ptr, png_const_charp msg) +{ + os::Printer::log("PNG warning", msg, ELL_WARNING); +} + +// PNG function for file writing +void PNGAPI user_write_data_fcn(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + io::IWriteFile *file = (io::IWriteFile *)png_get_io_ptr(png_ptr); + check = (png_size_t)file->write((const void *)data, length); + + if (check != length) + png_error(png_ptr, "Write Error"); +} + +CImageWriterPNG::CImageWriterPNG() +{ +#ifdef _DEBUG + setDebugName("CImageWriterPNG"); +#endif +} + +bool CImageWriterPNG::isAWriteableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "png"); +} + +bool CImageWriterPNG::writeImage(io::IWriteFile *file, IImage *image, u32 param) const +{ + if (!file || !image) + return false; + + // Allocate the png write struct + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warning); + if (!png_ptr) { + os::Printer::log("PNGWriter: Internal PNG create write struct failure", file->getFileName(), ELL_ERROR); + return false; + } + + // Allocate the png info struct + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + os::Printer::log("PNGWriter: Internal PNG create info struct failure", file->getFileName(), ELL_ERROR); + png_destroy_write_struct(&png_ptr, NULL); + return false; + } + + // for proper error handling + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_write_struct(&png_ptr, &info_ptr); + return false; + } + + png_set_write_fn(png_ptr, file, user_write_data_fcn, NULL); + + // Set info + switch (image->getColorFormat()) { + case ECF_A8R8G8B8: + case ECF_A1R5G5B5: + png_set_IHDR(png_ptr, info_ptr, + image->getDimension().Width, image->getDimension().Height, + 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + break; + default: + png_set_IHDR(png_ptr, info_ptr, + image->getDimension().Width, image->getDimension().Height, + 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + } + + s32 lineWidth = image->getDimension().Width; + switch (image->getColorFormat()) { + case ECF_R8G8B8: + case ECF_R5G6B5: + lineWidth *= 3; + break; + case ECF_A8R8G8B8: + case ECF_A1R5G5B5: + lineWidth *= 4; + break; + // TODO: Error handling in case of unsupported color format + default: + break; + } + u8 *tmpImage = new u8[image->getDimension().Height * lineWidth]; + if (!tmpImage) { + os::Printer::log("PNGWriter: Internal PNG create image failure", file->getFileName(), ELL_ERROR); + png_destroy_write_struct(&png_ptr, &info_ptr); + return false; + } + + u8 *data = (u8 *)image->getData(); + switch (image->getColorFormat()) { + case ECF_R8G8B8: + CColorConverter::convert_R8G8B8toR8G8B8(data, image->getDimension().Height * image->getDimension().Width, tmpImage); + break; + case ECF_A8R8G8B8: + CColorConverter::convert_A8R8G8B8toA8R8G8B8(data, image->getDimension().Height * image->getDimension().Width, tmpImage); + break; + case ECF_R5G6B5: + CColorConverter::convert_R5G6B5toR8G8B8(data, image->getDimension().Height * image->getDimension().Width, tmpImage); + break; + case ECF_A1R5G5B5: + CColorConverter::convert_A1R5G5B5toA8R8G8B8(data, image->getDimension().Height * image->getDimension().Width, tmpImage); + break; + // TODO: Error handling in case of unsupported color format + default: + os::Printer::log("CImageWriterPNG does not support image format", ColorFormatNames[image->getColorFormat()], ELL_WARNING); + png_destroy_write_struct(&png_ptr, &info_ptr); + delete[] tmpImage; + return false; + } + + // Create array of pointers to rows in image data + + // Used to point to image rows + u8 **RowPointers = new png_bytep[image->getDimension().Height]; + if (!RowPointers) { + os::Printer::log("PNGWriter: Internal PNG create row pointers failure", file->getFileName(), ELL_ERROR); + png_destroy_write_struct(&png_ptr, &info_ptr); + delete[] tmpImage; + return false; + } + + data = tmpImage; + // Fill array of pointers to rows in image data + for (u32 i = 0; i < image->getDimension().Height; ++i) { + RowPointers[i] = data; + data += lineWidth; + } + // for proper error handling + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_write_struct(&png_ptr, &info_ptr); + delete[] RowPointers; + delete[] tmpImage; + return false; + } + + png_set_rows(png_ptr, info_ptr, RowPointers); + + if (image->getColorFormat() == ECF_A8R8G8B8 || image->getColorFormat() == ECF_A1R5G5B5) + png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR, NULL); + else { + png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); + } + + delete[] RowPointers; + delete[] tmpImage; + png_destroy_write_struct(&png_ptr, &info_ptr); + return true; +} + +} // namespace video +} // namespace irr diff --git a/irr/src/CImageWriterPNG.h b/irr/src/CImageWriterPNG.h new file mode 100644 index 000000000..b0f7348ee --- /dev/null +++ b/irr/src/CImageWriterPNG.h @@ -0,0 +1,28 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IImageWriter.h" + +namespace irr +{ +namespace video +{ + +class CImageWriterPNG : public IImageWriter +{ +public: + //! constructor + CImageWriterPNG(); + + //! return true if this writer can write a file with the given extension + bool isAWriteableFileExtension(const io::path &filename) const override; + + //! write image to file + bool writeImage(io::IWriteFile *file, IImage *image, u32 param) const override; +}; + +} // namespace video +} // namespace irr diff --git a/irr/src/CIrrDeviceLinux.cpp b/irr/src/CIrrDeviceLinux.cpp new file mode 100644 index 000000000..71eb0f260 --- /dev/null +++ b/irr/src/CIrrDeviceLinux.cpp @@ -0,0 +1,2244 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CIrrDeviceLinux.h" + +#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ + +#include +#include +#include +#include +#include +#include "IEventReceiver.h" +#include "ISceneManager.h" +#include "IGUIElement.h" +#include "IGUIEnvironment.h" +#include "os.h" +#include "CTimer.h" +#include "irrString.h" +#include "Keycodes.h" +#include "COSOperator.h" +#include "CColorConverter.h" +#include "SIrrCreationParameters.h" +#include "SExposedVideoData.h" +#include "IGUISpriteBank.h" +#include "IImageLoader.h" +#include "IFileSystem.h" +#include +#include + +#if defined(_IRR_LINUX_X11_XINPUT2_) +#include +#endif + +#if defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) +#include "CEGLManager.h" +#endif + +#if defined(_IRR_COMPILE_WITH_OPENGL_) +#include "CGLXManager.h" +#endif + +#ifdef _IRR_LINUX_XCURSOR_ +#include +#endif + +#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +#include +#include + +#ifdef __FreeBSD__ +#include +#else + +// linux/joystick.h includes linux/input.h, which #defines values for various KEY_FOO keys. +// These override the irr::KEY_FOO equivalents, which stops key handling from working. +// As a workaround, defining _INPUT_H stops linux/input.h from being included; it +// doesn't actually seem to be necessary except to pull in sys/ioctl.h. +#define _INPUT_H +#include // Would normally be included in linux/input.h +#include +#undef _INPUT_H +#endif + +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + +namespace irr +{ +namespace video +{ +#ifdef _IRR_COMPILE_WITH_OPENGL_ +IVideoDriver *createOpenGLDriver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#endif + +#ifdef _IRR_COMPILE_WITH_OGLES1_ +IVideoDriver *createOGLES1Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#endif + +#ifdef _IRR_COMPILE_WITH_OGLES2_ +IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#endif + +#ifdef _IRR_COMPILE_WITH_WEBGL1_ +IVideoDriver *createWebGL1Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#endif +} +} // end namespace irr + +namespace +{ +Atom X_ATOM_CLIPBOARD; +Atom X_ATOM_TARGETS; +Atom X_ATOM_UTF8_STRING; +Atom X_ATOM_UTF8_MIME_TYPE; +Atom X_ATOM_TEXT; +Atom X_ATOM_NETWM_MAXIMIZE_VERT; +Atom X_ATOM_NETWM_MAXIMIZE_HORZ; +Atom X_ATOM_NETWM_STATE; +Atom X_ATOM_NETWM_STATE_FULLSCREEN; + +Atom X_ATOM_WM_DELETE_WINDOW; + +#if defined(_IRR_LINUX_X11_XINPUT2_) +int XI_EXTENSIONS_OPCODE; +#endif +} + +namespace irr +{ +//! constructor +CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters ¶m) : + CIrrDeviceStub(param), +#ifdef _IRR_COMPILE_WITH_X11_ + XDisplay(0), VisualInfo(0), Screennr(0), XWindow(0), StdHints(0), + XInputMethod(0), XInputContext(0), + HasNetWM(false), +#endif +#if defined(_IRR_LINUX_X11_XINPUT2_) + currentTouchedCount(0), +#endif + Width(param.WindowSize.Width), Height(param.WindowSize.Height), + WindowHasFocus(false), WindowMinimized(false), WindowMaximized(param.WindowMaximized), + ExternalWindow(false), AutorepeatSupport(0) +{ +#ifdef _DEBUG + setDebugName("CIrrDeviceLinux"); +#endif + + // print version, distribution etc. + // thx to LynxLuna for pointing me to the uname function + core::stringc linuxversion; + struct utsname LinuxInfo; + uname(&LinuxInfo); + + linuxversion += LinuxInfo.sysname; + linuxversion += " "; + linuxversion += LinuxInfo.release; + linuxversion += " "; + linuxversion += LinuxInfo.version; + linuxversion += " "; + linuxversion += LinuxInfo.machine; + + Operator = new COSOperator(linuxversion, this); + os::Printer::log(linuxversion.c_str(), ELL_INFORMATION); + + // create keymap + createKeyMap(); + + // initialize X11 thread safety + // libX11 1.8+ has this on by default + // without it, multi-threaded GL drivers may crash + XInitThreads(); + + // create window + if (CreationParams.DriverType != video::EDT_NULL) { + // create the window, only if we do not use the null device + if (!createWindow()) + return; + if (param.WindowResizable < 2) + setResizable(param.WindowResizable == 1 ? true : false); +#ifdef _IRR_COMPILE_WITH_X11_ + createInputContext(); +#endif + } + + // create cursor control + CursorControl = new CCursorControl(this, CreationParams.DriverType == video::EDT_NULL); + + // create driver + createDriver(); + + if (!VideoDriver) + return; + + createGUIAndScene(); + + if (param.WindowMaximized) + maximizeWindow(); + + setupTopLevelXorgWindow(); +} + +//! destructor +CIrrDeviceLinux::~CIrrDeviceLinux() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (StdHints) + XFree(StdHints); + // Disable cursor (it is drop'ed in stub) + if (CursorControl) { + CursorControl->setVisible(false); + static_cast(CursorControl)->clearCursors(); + } + + // Must free OpenGL textures etc before destroying context, so can't wait for stub destructor + if (GUIEnvironment) { + GUIEnvironment->drop(); + GUIEnvironment = NULL; + } + if (SceneManager) { + SceneManager->drop(); + SceneManager = NULL; + } + if (VideoDriver) { + VideoDriver->drop(); + VideoDriver = NULL; + } + + destroyInputContext(); + + if (XDisplay) { + if (ContextManager) { + ContextManager->destroyContext(); + ContextManager->destroySurface(); + } + + if (!ExternalWindow) { + XDestroyWindow(XDisplay, XWindow); + XCloseDisplay(XDisplay); + } + } + if (VisualInfo) + XFree(VisualInfo); + +#endif // #ifdef _IRR_COMPILE_WITH_X11_ + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + for (u32 joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { + if (ActiveJoysticks[joystick].fd >= 0) { + close(ActiveJoysticks[joystick].fd); + } + } +#endif +} + +#if defined(_IRR_COMPILE_WITH_X11_) && defined(_DEBUG) +int IrrPrintXError(Display *display, XErrorEvent *event) +{ + char msg[256]; + char msg2[256]; + + snprintf_irr(msg, 256, "%d", event->request_code); + XGetErrorDatabaseText(display, "XRequest", msg, "unknown", msg2, 256); + XGetErrorText(display, event->error_code, msg, 256); + os::Printer::log("X Error", msg, ELL_WARNING); + os::Printer::log("From call ", msg2, ELL_WARNING); + return 0; +} +#endif + +bool CIrrDeviceLinux::switchToFullscreen() +{ + if (!CreationParams.Fullscreen) + return true; + + if (!HasNetWM) { + os::Printer::log("NetWM support is required to allow Irrlicht to switch " + "to fullscreen mode. Running in windowed mode instead.", + ELL_WARNING); + CreationParams.Fullscreen = false; + return false; + } + + XEvent ev = {0}; + + ev.type = ClientMessage; + ev.xclient.window = XWindow; + ev.xclient.message_type = X_ATOM_NETWM_STATE; + ev.xclient.format = 32; + ev.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD + ev.xclient.data.l[1] = X_ATOM_NETWM_STATE_FULLSCREEN; + + XSendEvent(XDisplay, DefaultRootWindow(XDisplay), false, + SubstructureNotifyMask | SubstructureRedirectMask, &ev); + + return true; +} + +void CIrrDeviceLinux::setupTopLevelXorgWindow() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType == video::EDT_NULL) + return; // no display and window + + os::Printer::log("Configuring X11-specific top level window properties", ELL_DEBUG); + + // Set application name and class hints. For now name and class are the same. + // Note: SDL uses the executable name here (i.e. "minetest"). + XClassHint *classhint = XAllocClassHint(); + classhint->res_name = const_cast("Minetest"); + classhint->res_class = const_cast("Minetest"); + + XSetClassHint(XDisplay, XWindow, classhint); + XFree(classhint); + + // FIXME: In the future WMNormalHints should be set ... e.g see the + // gtk/gdk code (gdk/x11/gdksurface-x11.c) for the setup_top_level + // method. But for now (as it would require some significant changes) + // leave the code as is. + + // The following is borrowed from the above gdk source for setting top + // level windows. The source indicates and the Xlib docs suggest that + // this will set the WM_CLIENT_MACHINE and WM_LOCAL_NAME. This will not + // set the WM_CLIENT_MACHINE to a Fully Qualified Domain Name (FQDN) which is + // required by the Extended Window Manager Hints (EWMH) spec when setting + // the _NET_WM_PID (see further down) but running Minetest in an env + // where the window manager is on another machine from Minetest (therefore + // making the PID useless) is not expected to be a problem. Further + // more, using gtk/gdk as the model it would seem that not using a FQDN is + // not an issue for modern Xorg window managers. + + os::Printer::log("Setting Xorg window manager Properties", ELL_DEBUG); + + XSetWMProperties(XDisplay, XWindow, NULL, NULL, NULL, 0, NULL, NULL, NULL); + + // Set the _NET_WM_PID window property according to the EWMH spec. _NET_WM_PID + // (in conjunction with WM_CLIENT_MACHINE) can be used by window managers to + // force a shutdown of an application if it doesn't respond to the destroy + // window message. + + os::Printer::log("Setting Xorg _NET_WM_PID extended window manager property", ELL_DEBUG); + + Atom NET_WM_PID = XInternAtom(XDisplay, "_NET_WM_PID", false); + + long pid = static_cast(getpid()); + + XChangeProperty(XDisplay, XWindow, NET_WM_PID, + XA_CARDINAL, 32, PropModeReplace, + reinterpret_cast(&pid), 1); + + // Set the WM_CLIENT_LEADER window property here. Minetest has only one + // window and that window will always be the leader. + + os::Printer::log("Setting Xorg WM_CLIENT_LEADER property", ELL_DEBUG); + + Atom WM_CLIENT_LEADER = XInternAtom(XDisplay, "WM_CLIENT_LEADER", false); + + XChangeProperty(XDisplay, XWindow, WM_CLIENT_LEADER, + XA_WINDOW, 32, PropModeReplace, + reinterpret_cast(&XWindow), 1); +#endif +} + +#if defined(_IRR_COMPILE_WITH_X11_) +void IrrPrintXGrabError(int grabResult, const c8 *grabCommand) +{ + if (grabResult == GrabSuccess) { + // os::Printer::log(grabCommand, "GrabSuccess", ELL_INFORMATION); + return; + } + + switch (grabResult) { + case AlreadyGrabbed: + os::Printer::log(grabCommand, "AlreadyGrabbed", ELL_WARNING); + break; + case GrabNotViewable: + os::Printer::log(grabCommand, "GrabNotViewable", ELL_WARNING); + break; + case GrabFrozen: + os::Printer::log(grabCommand, "GrabFrozen", ELL_WARNING); + break; + case GrabInvalidTime: + os::Printer::log(grabCommand, "GrabInvalidTime", ELL_WARNING); + break; + default: + os::Printer::log(grabCommand, "grab failed with unknown problem", ELL_WARNING); + break; + } +} +#endif + +bool CIrrDeviceLinux::createWindow() +{ +#ifdef _IRR_COMPILE_WITH_X11_ +#ifdef _DEBUG + os::Printer::log("Creating X window...", ELL_INFORMATION); + XSetErrorHandler(IrrPrintXError); +#endif + + XDisplay = XOpenDisplay(0); + if (!XDisplay) { + os::Printer::log("Error: Need running XServer to start Irrlicht Engine.", ELL_ERROR); + if (XDisplayName(0)[0]) + os::Printer::log("Could not open display", XDisplayName(0), ELL_ERROR); + else + os::Printer::log("Could not open display, set DISPLAY variable", ELL_ERROR); + return false; + } + + Screennr = DefaultScreen(XDisplay); + + initXAtoms(); + + // check netwm support + Atom WMCheck = XInternAtom(XDisplay, "_NET_SUPPORTING_WM_CHECK", True); + if (WMCheck != None) + HasNetWM = true; + +#if defined(_IRR_COMPILE_WITH_OPENGL_) + // don't use the XVisual with OpenGL, because it ignores all requested + // properties of the CreationParams + if (CreationParams.DriverType == video::EDT_OPENGL) { + video::SExposedVideoData data; + data.OpenGLLinux.X11Display = XDisplay; + ContextManager = new video::CGLXManager(CreationParams, data, Screennr); + VisualInfo = ((video::CGLXManager *)ContextManager)->getVisual(); + } +#endif + + if (!VisualInfo) { + // create visual with standard X methods + os::Printer::log("Using plain X visual"); + XVisualInfo visTempl; // Template to hold requested values + int visNumber; // Return value of available visuals + + visTempl.screen = Screennr; + // ARGB visuals should be avoided for usual applications + visTempl.depth = CreationParams.WithAlphaChannel ? 32 : 24; + while ((!VisualInfo) && (visTempl.depth >= 16)) { + VisualInfo = XGetVisualInfo(XDisplay, VisualScreenMask | VisualDepthMask, + &visTempl, &visNumber); + visTempl.depth -= 8; + } + } + + if (!VisualInfo) { + os::Printer::log("Fatal error, could not get visual.", ELL_ERROR); + XCloseDisplay(XDisplay); + XDisplay = 0; + return false; + } +#ifdef _DEBUG + else + os::Printer::log("Visual chosen", core::stringc(static_cast(VisualInfo->visualid)).c_str(), ELL_DEBUG); +#endif + + // create color map + Colormap colormap; + colormap = XCreateColormap(XDisplay, + RootWindow(XDisplay, VisualInfo->screen), + VisualInfo->visual, AllocNone); + + WndAttributes.colormap = colormap; + WndAttributes.border_pixel = 0; + WndAttributes.event_mask = StructureNotifyMask | FocusChangeMask | ExposureMask; + WndAttributes.event_mask |= PointerMotionMask | + ButtonPressMask | KeyPressMask | + ButtonReleaseMask | KeyReleaseMask; + + if (!CreationParams.WindowId) { + int x = 0; + int y = 0; + + if (!CreationParams.Fullscreen) { + if (CreationParams.WindowPosition.X > 0) + x = CreationParams.WindowPosition.X; + if (CreationParams.WindowPosition.Y > 0) + y = CreationParams.WindowPosition.Y; + } + + // create new Window + // Remove window manager decoration in fullscreen + XWindow = XCreateWindow(XDisplay, + RootWindow(XDisplay, VisualInfo->screen), + x, y, Width, Height, 0, VisualInfo->depth, + InputOutput, VisualInfo->visual, + CWBorderPixel | CWColormap | CWEventMask, + &WndAttributes); + + XMapRaised(XDisplay, XWindow); + CreationParams.WindowId = (void *)XWindow; + X_ATOM_WM_DELETE_WINDOW = XInternAtom(XDisplay, "WM_DELETE_WINDOW", True); + XSetWMProtocols(XDisplay, XWindow, &X_ATOM_WM_DELETE_WINDOW, 1); + + if (CreationParams.Fullscreen) { + // Don't try to set window position + } else if (CreationParams.WindowPosition.X >= 0 || CreationParams.WindowPosition.Y >= 0) { // default is -1, -1 + // Window managers are free to ignore positions above, so give it another shot + XMoveWindow(XDisplay, XWindow, x, y); + } + } else { + // attach external window + XWindow = (Window)CreationParams.WindowId; + { + // Note: This might be further improved by using a InputOnly window instead of InputOutput. + // I think then it should be possible to render into the given parent window instead of + // creating a child-window. + // Also... this does possibly leak. + Window child_window = XCreateWindow(XDisplay, + XWindow, + 0, 0, Width, Height, 0, VisualInfo->depth, + InputOutput, VisualInfo->visual, + CWBorderPixel | CWColormap | CWEventMask, + &WndAttributes); + + // do not forget to map new window + XMapWindow(XDisplay, child_window); + + // overwrite device window id + XWindow = child_window; + } + XWindowAttributes wa; + XGetWindowAttributes(XDisplay, XWindow, &wa); + CreationParams.WindowSize.Width = wa.width; + CreationParams.WindowSize.Height = wa.height; + CreationParams.Fullscreen = false; + ExternalWindow = true; + } + + switchToFullscreen(); + + WindowMinimized = false; + XkbSetDetectableAutoRepeat(XDisplay, True, &AutorepeatSupport); + + Window tmp; + u32 borderWidth; + int x, y; + unsigned int bits; + + XGetGeometry(XDisplay, XWindow, &tmp, &x, &y, &Width, &Height, &borderWidth, &bits); + CreationParams.Bits = bits; + CreationParams.WindowSize.Width = Width; + CreationParams.WindowSize.Height = Height; + + StdHints = XAllocSizeHints(); + long num; + XGetWMNormalHints(XDisplay, XWindow, StdHints, &num); + + initXInput2(); + +#endif // #ifdef _IRR_COMPILE_WITH_X11_ + return true; +} + +//! create the driver +void CIrrDeviceLinux::createDriver() +{ + switch (CreationParams.DriverType) { +#ifdef _IRR_COMPILE_WITH_X11_ + case video::EDT_OPENGL: +#ifdef _IRR_COMPILE_WITH_OPENGL_ + { + video::SExposedVideoData data; + data.OpenGLLinux.X11Window = XWindow; + data.OpenGLLinux.X11Display = XDisplay; + + ContextManager->initialize(CreationParams, data); + + VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); + } +#else + os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_OGLES1: +#ifdef _IRR_COMPILE_WITH_OGLES1_ + { + video::SExposedVideoData data; + data.OpenGLLinux.X11Window = XWindow; + data.OpenGLLinux.X11Display = XDisplay; + + ContextManager = new video::CEGLManager(); + ContextManager->initialize(CreationParams, data); + + VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager); + } +#else + os::Printer::log("No OpenGL-ES1 support compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_OGLES2: +#ifdef _IRR_COMPILE_WITH_OGLES2_ + { + video::SExposedVideoData data; + data.OpenGLLinux.X11Window = XWindow; + data.OpenGLLinux.X11Display = XDisplay; + + ContextManager = new video::CEGLManager(); + ContextManager->initialize(CreationParams, data); + + VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); + } +#else + os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_WEBGL1: +#ifdef _IRR_COMPILE_WITH_WEBGL1_ + { + video::SExposedVideoData data; + data.OpenGLLinux.X11Window = XWindow; + data.OpenGLLinux.X11Display = XDisplay; + + ContextManager = new video::CEGLManager(); + ContextManager->initialize(CreationParams, data); + + VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); + } +#else + os::Printer::log("No WebGL1 support compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_NULL: + VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); + break; + default: + os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); + break; +#else + case video::EDT_NULL: + VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); + break; + default: + os::Printer::log("No X11 support compiled in. Only Null driver available.", ELL_ERROR); + break; +#endif + } +} + +#ifdef _IRR_COMPILE_WITH_X11_ +bool CIrrDeviceLinux::createInputContext() +{ + // One one side it would be nicer to let users do that - on the other hand + // not setting the environment locale will not work when using i18n X11 functions. + // So users would have to call it always or their input is broken badly. + // We can restore immediately - so won't mess with anything in users apps. + core::stringc oldLocale(setlocale(LC_CTYPE, NULL)); + setlocale(LC_CTYPE, ""); // use environment locale + + if (!XSupportsLocale()) { + os::Printer::log("Locale not supported. Falling back to non-i18n input.", ELL_WARNING); + setlocale(LC_CTYPE, oldLocale.c_str()); + return false; + } + + // Load XMODIFIERS (e.g. for IMEs) + if (!XSetLocaleModifiers("")) { + setlocale(LC_CTYPE, oldLocale.c_str()); + os::Printer::log("XSetLocaleModifiers failed. Falling back to non-i18n input.", ELL_WARNING); + return false; + } + + XInputMethod = XOpenIM(XDisplay, NULL, NULL, NULL); + if (!XInputMethod) { + setlocale(LC_CTYPE, oldLocale.c_str()); + os::Printer::log("XOpenIM failed to create an input method. Falling back to non-i18n input.", ELL_WARNING); + return false; + } + + XIMStyles *im_supported_styles; + XGetIMValues(XInputMethod, XNQueryInputStyle, &im_supported_styles, (char *)NULL); + XIMStyle bestStyle = 0; + XIMStyle supportedStyle = XIMPreeditNothing | XIMStatusNothing; + for (int i = 0; i < im_supported_styles->count_styles; ++i) { + XIMStyle style = im_supported_styles->supported_styles[i]; + if ((style & supportedStyle) == style) /* if we can handle it */ + { + bestStyle = style; + break; + } + } + XFree(im_supported_styles); + + if (!bestStyle) { + XDestroyIC(XInputContext); + XInputContext = 0; + + os::Printer::log("XInputMethod has no input style we can use. Falling back to non-i18n input.", ELL_WARNING); + setlocale(LC_CTYPE, oldLocale.c_str()); + return false; + } + + XInputContext = XCreateIC(XInputMethod, + XNInputStyle, bestStyle, + XNClientWindow, XWindow, + (char *)NULL); + if (!XInputContext) { + os::Printer::log("XInputContext failed to create an input context. Falling back to non-i18n input.", ELL_WARNING); + setlocale(LC_CTYPE, oldLocale.c_str()); + return false; + } + XSetICFocus(XInputContext); + setlocale(LC_CTYPE, oldLocale.c_str()); + return true; +} + +void CIrrDeviceLinux::destroyInputContext() +{ + if (XInputContext) { + XUnsetICFocus(XInputContext); + XDestroyIC(XInputContext); + XInputContext = 0; + } + if (XInputMethod) { + XCloseIM(XInputMethod); + XInputMethod = 0; + } +} + +EKEY_CODE CIrrDeviceLinux::getKeyCode(XEvent &event) +{ + EKEY_CODE keyCode = (EKEY_CODE)0; + + SKeyMap mp; + mp.X11Key = XkbKeycodeToKeysym(XDisplay, event.xkey.keycode, 0, 0); + const s32 idx = KeyMap.binary_search(mp); + if (idx != -1) { + keyCode = (EKEY_CODE)KeyMap[idx].Win32Key; + } + if (keyCode == 0) { + keyCode = KEY_UNKNOWN; + if (!mp.X11Key) { + os::Printer::log("No such X11Key, event keycode", core::stringc(event.xkey.keycode).c_str(), ELL_INFORMATION); + } else if (idx == -1) { + os::Printer::log("EKEY_CODE not found, X11 keycode", core::stringc(mp.X11Key).c_str(), ELL_INFORMATION); + } else { + os::Printer::log("EKEY_CODE is 0, X11 keycode", core::stringc(mp.X11Key).c_str(), ELL_INFORMATION); + } + } + return keyCode; +} +#endif + +//! runs the device. Returns false if device wants to be deleted +bool CIrrDeviceLinux::run() +{ + os::Timer::tick(); + +#ifdef _IRR_COMPILE_WITH_X11_ + + if (CursorControl) + static_cast(CursorControl)->update(); + + if ((CreationParams.DriverType != video::EDT_NULL) && XDisplay) { + SEvent irrevent; + irrevent.MouseInput.ButtonStates = 0xffffffff; + + while (XPending(XDisplay) > 0 && !Close) { + XEvent event; + XNextEvent(XDisplay, &event); + if (XFilterEvent(&event, None)) + continue; + + switch (event.type) { + case ConfigureNotify: + // check for changed window size + if ((event.xconfigure.width != (int)Width) || + (event.xconfigure.height != (int)Height)) { + Width = event.xconfigure.width; + Height = event.xconfigure.height; + + if (VideoDriver) + VideoDriver->OnResize(core::dimension2d(Width, Height)); + } + break; + + case MapNotify: + WindowMinimized = false; + break; + + case UnmapNotify: + WindowMinimized = true; + break; + + case FocusIn: + WindowHasFocus = true; + break; + + case FocusOut: + WindowHasFocus = false; + break; + + case MotionNotify: + irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; + irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; + irrevent.MouseInput.X = event.xbutton.x; + irrevent.MouseInput.Y = event.xbutton.y; + irrevent.MouseInput.Control = (event.xkey.state & ControlMask) != 0; + irrevent.MouseInput.Shift = (event.xkey.state & ShiftMask) != 0; + + // mouse button states + irrevent.MouseInput.ButtonStates = (event.xbutton.state & Button1Mask) ? irr::EMBSM_LEFT : 0; + irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button3Mask) ? irr::EMBSM_RIGHT : 0; + irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button2Mask) ? irr::EMBSM_MIDDLE : 0; + + postEventFromUser(irrevent); + break; + + case ButtonPress: + case ButtonRelease: + + irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; + irrevent.MouseInput.X = event.xbutton.x; + irrevent.MouseInput.Y = event.xbutton.y; + irrevent.MouseInput.Control = (event.xkey.state & ControlMask) != 0; + irrevent.MouseInput.Shift = (event.xkey.state & ShiftMask) != 0; + + // mouse button states + // This sets the state which the buttons had _prior_ to the event. + // So unlike on Windows the button which just got changed has still the old state here. + // We handle that below by flipping the corresponding bit later. + irrevent.MouseInput.ButtonStates = (event.xbutton.state & Button1Mask) ? irr::EMBSM_LEFT : 0; + irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button3Mask) ? irr::EMBSM_RIGHT : 0; + irrevent.MouseInput.ButtonStates |= (event.xbutton.state & Button2Mask) ? irr::EMBSM_MIDDLE : 0; + + irrevent.MouseInput.Event = irr::EMIE_COUNT; + + switch (event.xbutton.button) { + case Button1: + irrevent.MouseInput.Event = + (event.type == ButtonPress) ? irr::EMIE_LMOUSE_PRESSED_DOWN : irr::EMIE_LMOUSE_LEFT_UP; + irrevent.MouseInput.ButtonStates ^= irr::EMBSM_LEFT; + break; + + case Button3: + irrevent.MouseInput.Event = + (event.type == ButtonPress) ? irr::EMIE_RMOUSE_PRESSED_DOWN : irr::EMIE_RMOUSE_LEFT_UP; + irrevent.MouseInput.ButtonStates ^= irr::EMBSM_RIGHT; + break; + + case Button2: + irrevent.MouseInput.Event = + (event.type == ButtonPress) ? irr::EMIE_MMOUSE_PRESSED_DOWN : irr::EMIE_MMOUSE_LEFT_UP; + irrevent.MouseInput.ButtonStates ^= irr::EMBSM_MIDDLE; + break; + + case Button4: + if (event.type == ButtonPress) { + irrevent.MouseInput.Event = EMIE_MOUSE_WHEEL; + irrevent.MouseInput.Wheel = 1.0f; + } + break; + + case Button5: + if (event.type == ButtonPress) { + irrevent.MouseInput.Event = EMIE_MOUSE_WHEEL; + irrevent.MouseInput.Wheel = -1.0f; + } + break; + } + + if (irrevent.MouseInput.Event != irr::EMIE_COUNT) { + postEventFromUser(irrevent); + + if (irrevent.MouseInput.Event >= EMIE_LMOUSE_PRESSED_DOWN && irrevent.MouseInput.Event <= EMIE_MMOUSE_PRESSED_DOWN) { + u32 clicks = checkSuccessiveClicks(irrevent.MouseInput.X, irrevent.MouseInput.Y, irrevent.MouseInput.Event); + if (clicks == 2) { + irrevent.MouseInput.Event = (EMOUSE_INPUT_EVENT)(EMIE_LMOUSE_DOUBLE_CLICK + irrevent.MouseInput.Event - EMIE_LMOUSE_PRESSED_DOWN); + postEventFromUser(irrevent); + } else if (clicks == 3) { + irrevent.MouseInput.Event = (EMOUSE_INPUT_EVENT)(EMIE_LMOUSE_TRIPLE_CLICK + irrevent.MouseInput.Event - EMIE_LMOUSE_PRESSED_DOWN); + postEventFromUser(irrevent); + } + } + } + break; + + case MappingNotify: + XRefreshKeyboardMapping(&event.xmapping); + break; + + case KeyRelease: + if (0 == AutorepeatSupport && (XPending(XDisplay) > 0)) { + // check for Autorepeat manually + // We'll do the same as Windows does: Only send KeyPressed + // So every KeyRelease is a real release + XEvent next_event; + XPeekEvent(event.xkey.display, &next_event); + if ((next_event.type == KeyPress) && + (next_event.xkey.keycode == event.xkey.keycode) && + (next_event.xkey.time - event.xkey.time) < 2) // usually same time, but on some systems a difference of 1 is possible + { + // Ignore the key release event + break; + } + } + + irrevent.EventType = irr::EET_KEY_INPUT_EVENT; + irrevent.KeyInput.PressedDown = false; + irrevent.KeyInput.Char = 0; // on release that's undefined + irrevent.KeyInput.Control = (event.xkey.state & ControlMask) != 0; + irrevent.KeyInput.Shift = (event.xkey.state & ShiftMask) != 0; + irrevent.KeyInput.Key = getKeyCode(event); + + postEventFromUser(irrevent); + break; + + case KeyPress: { + SKeyMap mp; + if (XInputContext) { + wchar_t buf[64] = {0}; + Status status; + int strLen = XwcLookupString(XInputContext, &event.xkey, buf, sizeof(buf) / sizeof(wchar_t) - 1, &mp.X11Key, &status); + if (status == XBufferOverflow) { + os::Printer::log("XwcLookupString needs a larger buffer", ELL_INFORMATION); + } + if (strLen > 0 && (status == XLookupChars || status == XLookupBoth)) { + if (strLen > 1) { + // Multiple characters: send string event + irrevent.EventType = irr::EET_STRING_INPUT_EVENT; + irrevent.StringInput.Str = new core::stringw(buf); + postEventFromUser(irrevent); + delete irrevent.StringInput.Str; + irrevent.StringInput.Str = NULL; + break; + } else { + irrevent.KeyInput.Char = buf[0]; + } + } else { +#if 0 // Most of those are fine - but useful to have the info when debugging Irrlicht itself. + if ( status == XLookupNone ) + os::Printer::log("XLookupNone", ELL_INFORMATION); + else if ( status == XLookupKeySym ) + // Getting this also when user did not set setlocale(LC_ALL, ""); and using an unknown locale + // XSupportsLocale doesn't seem to catch that unfortunately - any other ideas to catch it are welcome. + os::Printer::log("XLookupKeySym", ELL_INFORMATION); + else if ( status == XBufferOverflow ) + os::Printer::log("XBufferOverflow", ELL_INFORMATION); + else if ( strLen == 0 ) + os::Printer::log("no string", ELL_INFORMATION); +#endif + irrevent.KeyInput.Char = 0; + } + } else // Old version without InputContext. Does not support i18n, but good to have as fallback. + { + union + { + char buf[8]; + wchar_t wbuf[2]; + } tmp = {{0}}; + XLookupString(&event.xkey, tmp.buf, sizeof(tmp.buf), &mp.X11Key, NULL); + irrevent.KeyInput.Char = tmp.wbuf[0]; + } + + irrevent.EventType = irr::EET_KEY_INPUT_EVENT; + irrevent.KeyInput.PressedDown = true; + irrevent.KeyInput.Control = (event.xkey.state & ControlMask) != 0; + irrevent.KeyInput.Shift = (event.xkey.state & ShiftMask) != 0; + irrevent.KeyInput.Key = getKeyCode(event); + postEventFromUser(irrevent); + } break; + + case ClientMessage: { + if (static_cast(event.xclient.data.l[0]) == X_ATOM_WM_DELETE_WINDOW && X_ATOM_WM_DELETE_WINDOW != None) { + os::Printer::log("Quit message received.", ELL_INFORMATION); + Close = true; + } else { + // we assume it's a user message + irrevent.EventType = irr::EET_USER_EVENT; + irrevent.UserEvent.UserData1 = static_cast(event.xclient.data.l[0]); + irrevent.UserEvent.UserData2 = static_cast(event.xclient.data.l[1]); + postEventFromUser(irrevent); + } + } break; + + case SelectionRequest: { + XSelectionRequestEvent *req = &(event.xselectionrequest); + + auto send_response = [this, req](Atom property) { + XEvent response; + response.xselection.type = SelectionNotify; + response.xselection.display = req->display; + response.xselection.requestor = req->requestor; + response.xselection.selection = req->selection; + response.xselection.target = req->target; + response.xselection.property = property; + response.xselection.time = req->time; + XSendEvent(XDisplay, req->requestor, 0, 0, &response); + XFlush(XDisplay); + }; + auto send_response_refuse = [&send_response] { + send_response(None); + }; + + // sets the required property to data of type type and + // sends the according response + auto set_property_and_notify = [this, req, &send_response](Atom type, int format, const void *data, u32 data_size) { + XChangeProperty(XDisplay, + req->requestor, + req->property, + type, + format, + PropModeReplace, + (const unsigned char *)data, + data_size); + send_response(req->property); + }; + + if ((req->selection != X_ATOM_CLIPBOARD && + req->selection != XA_PRIMARY) || + req->owner != XWindow) { + // we are not the owner, refuse request + send_response_refuse(); + break; + } + const core::stringc &text_buffer = req->selection == X_ATOM_CLIPBOARD ? Clipboard : PrimarySelection; + + // for debugging: + //~ { + //~ char *target_name = XGetAtomName(XDisplay, req->target); + //~ fprintf(stderr, "CIrrDeviceLinux::run: target: %s (=%ld)\n", + //~ target_name, req->target); + //~ XFree(target_name); + //~ } + + if (req->property == None) { + // req is from obsolete client, use target as property name + // and X_ATOM_UTF8_STRING as type + // Note: this was not tested and might be incorrect + os::Printer::log("CIrrDeviceLinux::run: SelectionRequest from obsolete client", + ELL_WARNING); + XChangeProperty(XDisplay, + req->requestor, + req->target, X_ATOM_UTF8_STRING, + 8, // format = 8-bit + PropModeReplace, + (unsigned char *)text_buffer.c_str(), + text_buffer.size()); + send_response(req->target); + break; + } + + if (req->target == X_ATOM_TARGETS) { + Atom data[] = { + X_ATOM_TARGETS, + X_ATOM_TEXT, + X_ATOM_UTF8_STRING, + X_ATOM_UTF8_MIME_TYPE}; + set_property_and_notify( + XA_ATOM, + 32, // Atom is long, we need to set 32 for longs + &data, + sizeof(data) / sizeof(*data)); + + } else if (req->target == X_ATOM_TEXT || + req->target == X_ATOM_UTF8_STRING || + req->target == X_ATOM_UTF8_MIME_TYPE) { + set_property_and_notify( + X_ATOM_UTF8_STRING, + 8, + text_buffer.c_str(), + text_buffer.size()); + + } else { + // refuse the request + send_response_refuse(); + } + } break; + +#if defined(_IRR_LINUX_X11_XINPUT2_) + case GenericEvent: { + XGenericEventCookie *cookie = &event.xcookie; + if (XGetEventData(XDisplay, cookie) && cookie->extension == XI_EXTENSIONS_OPCODE && XI_EXTENSIONS_OPCODE && (cookie->evtype == XI_TouchUpdate || cookie->evtype == XI_TouchBegin || cookie->evtype == XI_TouchEnd)) { + XIDeviceEvent *de = (XIDeviceEvent *)cookie->data; + + irrevent.EventType = EET_TOUCH_INPUT_EVENT; + + irrevent.TouchInput.Event = cookie->evtype == XI_TouchUpdate ? ETIE_MOVED : (cookie->evtype == XI_TouchBegin ? ETIE_PRESSED_DOWN : ETIE_LEFT_UP); + + irrevent.TouchInput.ID = de->detail; + irrevent.TouchInput.X = de->event_x; + irrevent.TouchInput.Y = de->event_y; + + if (irrevent.TouchInput.Event == ETIE_PRESSED_DOWN) { + currentTouchedCount++; + } + irrevent.TouchInput.touchedCount = currentTouchedCount; + if (currentTouchedCount > 0 && irrevent.TouchInput.Event == ETIE_LEFT_UP) { + currentTouchedCount--; + } + + postEventFromUser(irrevent); + } + } break; +#endif + + default: + break; + } // end switch + + // Update IME information + if (XInputContext && GUIEnvironment) { + gui::IGUIElement *elem = GUIEnvironment->getFocus(); + if (elem && elem->acceptsIME()) { + core::rect r = elem->getAbsolutePosition(); + XPoint p; + p.x = (short)r.UpperLeftCorner.X; + p.y = (short)r.LowerRightCorner.Y; + XSetICFocus(XInputContext); + XVaNestedList l = XVaCreateNestedList(0, XNSpotLocation, &p, NULL); + XSetICValues(XInputContext, XNPreeditAttributes, l, NULL); + XFree(l); + } else { + XUnsetICFocus(XInputContext); + } + } + + } // end while + } +#endif //_IRR_COMPILE_WITH_X11_ + + if (!Close) + pollJoysticks(); + + return !Close; +} + +//! Pause the current process for the minimum time allowed only to allow other processes to execute +void CIrrDeviceLinux::yield() +{ + struct timespec ts = {0, 1}; + nanosleep(&ts, NULL); +} + +//! Pause execution and let other processes to run for a specified amount of time. +void CIrrDeviceLinux::sleep(u32 timeMs, bool pauseTimer = false) +{ + const bool wasStopped = Timer ? Timer->isStopped() : true; + + struct timespec ts; + ts.tv_sec = (time_t)(timeMs / 1000); + ts.tv_nsec = (long)(timeMs % 1000) * 1000000; + + if (pauseTimer && !wasStopped) + Timer->stop(); + + nanosleep(&ts, NULL); + + if (pauseTimer && !wasStopped) + Timer->start(); +} + +//! sets the caption of the window +void CIrrDeviceLinux::setWindowCaption(const wchar_t *text) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType == video::EDT_NULL) + return; + + XTextProperty txt; + if (Success == XwcTextListToTextProperty(XDisplay, const_cast(&text), + 1, XStdICCTextStyle, &txt)) { + XSetWMName(XDisplay, XWindow, &txt); + XSetWMIconName(XDisplay, XWindow, &txt); + XFree(txt.value); + } +#endif +} + +//! Sets the window icon. +bool CIrrDeviceLinux::setWindowIcon(const video::IImage *img) +{ + if (CreationParams.DriverType == video::EDT_NULL) + return false; // no display and window + + u32 height = img->getDimension().Height; + u32 width = img->getDimension().Width; + + size_t icon_buffer_len = 2 + height * width; + long *icon_buffer = new long[icon_buffer_len]; + + icon_buffer[0] = width; + icon_buffer[1] = height; + + for (u32 x = 0; x < width; x++) { + for (u32 y = 0; y < height; y++) { + video::SColor col = img->getPixel(x, y); + long pixel_val = 0; + pixel_val |= (u8)col.getAlpha() << 24; + pixel_val |= (u8)col.getRed() << 16; + pixel_val |= (u8)col.getGreen() << 8; + pixel_val |= (u8)col.getBlue(); + icon_buffer[2 + x + y * width] = pixel_val; + } + } + + if (XDisplay == NULL) { + os::Printer::log("Could not find x11 display for setting its icon.", ELL_ERROR); + delete[] icon_buffer; + return false; + } + + Atom net_wm_icon = XInternAtom(XDisplay, "_NET_WM_ICON", False); + Atom cardinal = XInternAtom(XDisplay, "CARDINAL", False); + XChangeProperty(XDisplay, XWindow, net_wm_icon, cardinal, 32, PropModeReplace, + (const unsigned char *)icon_buffer, icon_buffer_len); + + delete[] icon_buffer; + + return true; +} + +//! notifies the device that it should close itself +void CIrrDeviceLinux::closeDevice() +{ + Close = true; +} + +//! returns if window is active. if not, nothing need to be drawn +bool CIrrDeviceLinux::isWindowActive() const +{ + return (WindowHasFocus && !WindowMinimized); +} + +//! returns if window has focus. +bool CIrrDeviceLinux::isWindowFocused() const +{ + return WindowHasFocus; +} + +//! returns if window is minimized. +bool CIrrDeviceLinux::isWindowMinimized() const +{ + return WindowMinimized; +} + +//! returns last state from maximizeWindow() and restoreWindow() +bool CIrrDeviceLinux::isWindowMaximized() const +{ + return WindowMaximized; +} + +//! returns color format of the window. +video::ECOLOR_FORMAT CIrrDeviceLinux::getColorFormat() const +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (VisualInfo && (VisualInfo->depth != 16)) + return video::ECF_R8G8B8; + else +#endif + return video::ECF_R5G6B5; +} + +//! Sets if the window should be resizable in windowed mode. +void CIrrDeviceLinux::setResizable(bool resize) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType == video::EDT_NULL || CreationParams.Fullscreen) + return; + + if (!resize) { + // Must be heap memory because data size depends on X Server + XSizeHints *hints = XAllocSizeHints(); + hints->flags = PSize | PMinSize | PMaxSize; + hints->min_width = hints->max_width = hints->base_width = Width; + hints->min_height = hints->max_height = hints->base_height = Height; + XSetWMNormalHints(XDisplay, XWindow, hints); + XFree(hints); + } else { + XSetWMNormalHints(XDisplay, XWindow, StdHints); + } + XFlush(XDisplay); +#endif // #ifdef _IRR_COMPILE_WITH_X11_ +} + +//! Resize the render window. +void CIrrDeviceLinux::setWindowSize(const irr::core::dimension2d &size) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType == video::EDT_NULL || CreationParams.Fullscreen) + return; + + XWindowChanges values; + values.width = size.Width; + values.height = size.Height; + XConfigureWindow(XDisplay, XWindow, CWWidth | CWHeight, &values); + XFlush(XDisplay); +#endif // #ifdef _IRR_COMPILE_WITH_X11_ +} + +//! Minimize window +void CIrrDeviceLinux::minimizeWindow() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + XIconifyWindow(XDisplay, XWindow, Screennr); +#endif +} + +//! Maximize window +void CIrrDeviceLinux::maximizeWindow() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + // Maximize is not implemented in bare X, it's a WM construct. + if (HasNetWM) { + XEvent ev = {0}; + + ev.type = ClientMessage; + ev.xclient.window = XWindow; + ev.xclient.message_type = X_ATOM_NETWM_STATE; + ev.xclient.format = 32; + ev.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD + ev.xclient.data.l[1] = X_ATOM_NETWM_MAXIMIZE_VERT; + ev.xclient.data.l[2] = X_ATOM_NETWM_MAXIMIZE_HORZ; + + XSendEvent(XDisplay, DefaultRootWindow(XDisplay), false, + SubstructureNotifyMask | SubstructureRedirectMask, &ev); + } + + XMapWindow(XDisplay, XWindow); + + WindowMaximized = true; +#endif +} + +//! Restore original window size +void CIrrDeviceLinux::restoreWindow() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + // Maximize is not implemented in bare X, it's a WM construct. + if (HasNetWM) { + XEvent ev = {0}; + + ev.type = ClientMessage; + ev.xclient.window = XWindow; + ev.xclient.message_type = X_ATOM_NETWM_STATE; + ev.xclient.format = 32; + ev.xclient.data.l[0] = 0; // _NET_WM_STATE_REMOVE + ev.xclient.data.l[1] = X_ATOM_NETWM_MAXIMIZE_VERT; + ev.xclient.data.l[2] = X_ATOM_NETWM_MAXIMIZE_HORZ; + + XSendEvent(XDisplay, DefaultRootWindow(XDisplay), false, + SubstructureNotifyMask | SubstructureRedirectMask, &ev); + } + + XMapWindow(XDisplay, XWindow); + + WindowMaximized = false; +#endif +} + +core::position2di CIrrDeviceLinux::getWindowPosition() +{ + int wx = 0, wy = 0; +#ifdef _IRR_COMPILE_WITH_X11_ + Window child; + XTranslateCoordinates(XDisplay, XWindow, DefaultRootWindow(XDisplay), 0, 0, &wx, &wy, &child); +#endif + return core::position2di(wx, wy); +} + +void CIrrDeviceLinux::createKeyMap() +{ + // I don't know if this is the best method to create + // the lookuptable, but I'll leave it like that until + // I find a better version. + // Search for missing numbers in keysymdef.h + +#ifdef _IRR_COMPILE_WITH_X11_ + KeyMap.reallocate(190); + KeyMap.push_back(SKeyMap(XK_BackSpace, KEY_BACK)); + KeyMap.push_back(SKeyMap(XK_Tab, KEY_TAB)); + KeyMap.push_back(SKeyMap(XK_ISO_Left_Tab, KEY_TAB)); + KeyMap.push_back(SKeyMap(XK_Linefeed, 0)); // ??? + KeyMap.push_back(SKeyMap(XK_Clear, KEY_CLEAR)); + KeyMap.push_back(SKeyMap(XK_Return, KEY_RETURN)); + KeyMap.push_back(SKeyMap(XK_Pause, KEY_PAUSE)); + KeyMap.push_back(SKeyMap(XK_Scroll_Lock, KEY_SCROLL)); + KeyMap.push_back(SKeyMap(XK_Sys_Req, 0)); // ??? + KeyMap.push_back(SKeyMap(XK_Escape, KEY_ESCAPE)); + KeyMap.push_back(SKeyMap(XK_Insert, KEY_INSERT)); + KeyMap.push_back(SKeyMap(XK_Delete, KEY_DELETE)); + KeyMap.push_back(SKeyMap(XK_Home, KEY_HOME)); + KeyMap.push_back(SKeyMap(XK_Left, KEY_LEFT)); + KeyMap.push_back(SKeyMap(XK_Up, KEY_UP)); + KeyMap.push_back(SKeyMap(XK_Right, KEY_RIGHT)); + KeyMap.push_back(SKeyMap(XK_Down, KEY_DOWN)); + KeyMap.push_back(SKeyMap(XK_Prior, KEY_PRIOR)); + KeyMap.push_back(SKeyMap(XK_Page_Up, KEY_PRIOR)); + KeyMap.push_back(SKeyMap(XK_Next, KEY_NEXT)); + KeyMap.push_back(SKeyMap(XK_Page_Down, KEY_NEXT)); + KeyMap.push_back(SKeyMap(XK_End, KEY_END)); + KeyMap.push_back(SKeyMap(XK_Begin, KEY_NUMPAD5)); + KeyMap.push_back(SKeyMap(XK_Num_Lock, KEY_NUMLOCK)); + KeyMap.push_back(SKeyMap(XK_KP_Space, KEY_SPACE)); + KeyMap.push_back(SKeyMap(XK_KP_Tab, KEY_TAB)); + KeyMap.push_back(SKeyMap(XK_KP_Enter, KEY_RETURN)); + KeyMap.push_back(SKeyMap(XK_KP_F1, KEY_F1)); + KeyMap.push_back(SKeyMap(XK_KP_F2, KEY_F2)); + KeyMap.push_back(SKeyMap(XK_KP_F3, KEY_F3)); + KeyMap.push_back(SKeyMap(XK_KP_F4, KEY_F4)); + KeyMap.push_back(SKeyMap(XK_KP_Home, KEY_HOME)); + KeyMap.push_back(SKeyMap(XK_KP_Left, KEY_LEFT)); + KeyMap.push_back(SKeyMap(XK_KP_Up, KEY_UP)); + KeyMap.push_back(SKeyMap(XK_KP_Right, KEY_RIGHT)); + KeyMap.push_back(SKeyMap(XK_KP_Down, KEY_DOWN)); + KeyMap.push_back(SKeyMap(XK_Print, KEY_PRINT)); + KeyMap.push_back(SKeyMap(XK_KP_Prior, KEY_PRIOR)); + KeyMap.push_back(SKeyMap(XK_KP_Page_Up, KEY_PRIOR)); + KeyMap.push_back(SKeyMap(XK_KP_Next, KEY_NEXT)); + KeyMap.push_back(SKeyMap(XK_KP_Page_Down, KEY_NEXT)); + KeyMap.push_back(SKeyMap(XK_KP_End, KEY_END)); + KeyMap.push_back(SKeyMap(XK_KP_Begin, KEY_NUMPAD5)); + KeyMap.push_back(SKeyMap(XK_KP_Insert, KEY_INSERT)); + KeyMap.push_back(SKeyMap(XK_KP_Delete, KEY_DELETE)); + KeyMap.push_back(SKeyMap(XK_KP_Equal, 0)); // ??? + KeyMap.push_back(SKeyMap(XK_KP_Multiply, KEY_MULTIPLY)); + KeyMap.push_back(SKeyMap(XK_KP_Add, KEY_ADD)); + KeyMap.push_back(SKeyMap(XK_KP_Separator, KEY_SEPARATOR)); + KeyMap.push_back(SKeyMap(XK_KP_Subtract, KEY_SUBTRACT)); + KeyMap.push_back(SKeyMap(XK_KP_Decimal, KEY_DECIMAL)); + KeyMap.push_back(SKeyMap(XK_KP_Divide, KEY_DIVIDE)); + KeyMap.push_back(SKeyMap(XK_KP_0, KEY_NUMPAD0)); + KeyMap.push_back(SKeyMap(XK_KP_1, KEY_NUMPAD1)); + KeyMap.push_back(SKeyMap(XK_KP_2, KEY_NUMPAD2)); + KeyMap.push_back(SKeyMap(XK_KP_3, KEY_NUMPAD3)); + KeyMap.push_back(SKeyMap(XK_KP_4, KEY_NUMPAD4)); + KeyMap.push_back(SKeyMap(XK_KP_5, KEY_NUMPAD5)); + KeyMap.push_back(SKeyMap(XK_KP_6, KEY_NUMPAD6)); + KeyMap.push_back(SKeyMap(XK_KP_7, KEY_NUMPAD7)); + KeyMap.push_back(SKeyMap(XK_KP_8, KEY_NUMPAD8)); + KeyMap.push_back(SKeyMap(XK_KP_9, KEY_NUMPAD9)); + KeyMap.push_back(SKeyMap(XK_F1, KEY_F1)); + KeyMap.push_back(SKeyMap(XK_F2, KEY_F2)); + KeyMap.push_back(SKeyMap(XK_F3, KEY_F3)); + KeyMap.push_back(SKeyMap(XK_F4, KEY_F4)); + KeyMap.push_back(SKeyMap(XK_F5, KEY_F5)); + KeyMap.push_back(SKeyMap(XK_F6, KEY_F6)); + KeyMap.push_back(SKeyMap(XK_F7, KEY_F7)); + KeyMap.push_back(SKeyMap(XK_F8, KEY_F8)); + KeyMap.push_back(SKeyMap(XK_F9, KEY_F9)); + KeyMap.push_back(SKeyMap(XK_F10, KEY_F10)); + KeyMap.push_back(SKeyMap(XK_F11, KEY_F11)); + KeyMap.push_back(SKeyMap(XK_F12, KEY_F12)); + KeyMap.push_back(SKeyMap(XK_Shift_L, KEY_LSHIFT)); + KeyMap.push_back(SKeyMap(XK_Shift_R, KEY_RSHIFT)); + KeyMap.push_back(SKeyMap(XK_Control_L, KEY_LCONTROL)); + KeyMap.push_back(SKeyMap(XK_Control_R, KEY_RCONTROL)); + KeyMap.push_back(SKeyMap(XK_Caps_Lock, KEY_CAPITAL)); + KeyMap.push_back(SKeyMap(XK_Shift_Lock, KEY_CAPITAL)); + KeyMap.push_back(SKeyMap(XK_Meta_L, KEY_LWIN)); + KeyMap.push_back(SKeyMap(XK_Meta_R, KEY_RWIN)); + KeyMap.push_back(SKeyMap(XK_Alt_L, KEY_LMENU)); + KeyMap.push_back(SKeyMap(XK_Alt_R, KEY_RMENU)); + KeyMap.push_back(SKeyMap(XK_ISO_Level3_Shift, KEY_RMENU)); + KeyMap.push_back(SKeyMap(XK_Menu, KEY_MENU)); + KeyMap.push_back(SKeyMap(XK_space, KEY_SPACE)); + KeyMap.push_back(SKeyMap(XK_exclam, 0)); //? + KeyMap.push_back(SKeyMap(XK_quotedbl, 0)); //? + KeyMap.push_back(SKeyMap(XK_section, 0)); //? + KeyMap.push_back(SKeyMap(XK_numbersign, KEY_OEM_2)); + KeyMap.push_back(SKeyMap(XK_dollar, 0)); //? + KeyMap.push_back(SKeyMap(XK_percent, 0)); //? + KeyMap.push_back(SKeyMap(XK_ampersand, 0)); //? + KeyMap.push_back(SKeyMap(XK_apostrophe, KEY_OEM_7)); + KeyMap.push_back(SKeyMap(XK_parenleft, 0)); //? + KeyMap.push_back(SKeyMap(XK_parenright, 0)); //? + KeyMap.push_back(SKeyMap(XK_asterisk, 0)); //? + KeyMap.push_back(SKeyMap(XK_plus, KEY_PLUS)); //? + KeyMap.push_back(SKeyMap(XK_comma, KEY_COMMA)); //? + KeyMap.push_back(SKeyMap(XK_minus, KEY_MINUS)); //? + KeyMap.push_back(SKeyMap(XK_period, KEY_PERIOD)); //? + KeyMap.push_back(SKeyMap(XK_slash, KEY_OEM_2)); //? + KeyMap.push_back(SKeyMap(XK_0, KEY_KEY_0)); + KeyMap.push_back(SKeyMap(XK_1, KEY_KEY_1)); + KeyMap.push_back(SKeyMap(XK_2, KEY_KEY_2)); + KeyMap.push_back(SKeyMap(XK_3, KEY_KEY_3)); + KeyMap.push_back(SKeyMap(XK_4, KEY_KEY_4)); + KeyMap.push_back(SKeyMap(XK_5, KEY_KEY_5)); + KeyMap.push_back(SKeyMap(XK_6, KEY_KEY_6)); + KeyMap.push_back(SKeyMap(XK_7, KEY_KEY_7)); + KeyMap.push_back(SKeyMap(XK_8, KEY_KEY_8)); + KeyMap.push_back(SKeyMap(XK_9, KEY_KEY_9)); + KeyMap.push_back(SKeyMap(XK_colon, 0)); //? + KeyMap.push_back(SKeyMap(XK_semicolon, KEY_OEM_1)); + KeyMap.push_back(SKeyMap(XK_less, KEY_OEM_102)); + KeyMap.push_back(SKeyMap(XK_equal, KEY_PLUS)); + KeyMap.push_back(SKeyMap(XK_greater, 0)); //? + KeyMap.push_back(SKeyMap(XK_question, 0)); //? + KeyMap.push_back(SKeyMap(XK_at, KEY_KEY_2)); //? + KeyMap.push_back(SKeyMap(XK_mu, 0)); //? + KeyMap.push_back(SKeyMap(XK_EuroSign, 0)); //? + KeyMap.push_back(SKeyMap(XK_A, KEY_KEY_A)); + KeyMap.push_back(SKeyMap(XK_B, KEY_KEY_B)); + KeyMap.push_back(SKeyMap(XK_C, KEY_KEY_C)); + KeyMap.push_back(SKeyMap(XK_D, KEY_KEY_D)); + KeyMap.push_back(SKeyMap(XK_E, KEY_KEY_E)); + KeyMap.push_back(SKeyMap(XK_F, KEY_KEY_F)); + KeyMap.push_back(SKeyMap(XK_G, KEY_KEY_G)); + KeyMap.push_back(SKeyMap(XK_H, KEY_KEY_H)); + KeyMap.push_back(SKeyMap(XK_I, KEY_KEY_I)); + KeyMap.push_back(SKeyMap(XK_J, KEY_KEY_J)); + KeyMap.push_back(SKeyMap(XK_K, KEY_KEY_K)); + KeyMap.push_back(SKeyMap(XK_L, KEY_KEY_L)); + KeyMap.push_back(SKeyMap(XK_M, KEY_KEY_M)); + KeyMap.push_back(SKeyMap(XK_N, KEY_KEY_N)); + KeyMap.push_back(SKeyMap(XK_O, KEY_KEY_O)); + KeyMap.push_back(SKeyMap(XK_P, KEY_KEY_P)); + KeyMap.push_back(SKeyMap(XK_Q, KEY_KEY_Q)); + KeyMap.push_back(SKeyMap(XK_R, KEY_KEY_R)); + KeyMap.push_back(SKeyMap(XK_S, KEY_KEY_S)); + KeyMap.push_back(SKeyMap(XK_T, KEY_KEY_T)); + KeyMap.push_back(SKeyMap(XK_U, KEY_KEY_U)); + KeyMap.push_back(SKeyMap(XK_V, KEY_KEY_V)); + KeyMap.push_back(SKeyMap(XK_W, KEY_KEY_W)); + KeyMap.push_back(SKeyMap(XK_X, KEY_KEY_X)); + KeyMap.push_back(SKeyMap(XK_Y, KEY_KEY_Y)); + KeyMap.push_back(SKeyMap(XK_Z, KEY_KEY_Z)); + KeyMap.push_back(SKeyMap(XK_bracketleft, KEY_OEM_4)); + KeyMap.push_back(SKeyMap(XK_backslash, KEY_OEM_5)); + KeyMap.push_back(SKeyMap(XK_bracketright, KEY_OEM_6)); + KeyMap.push_back(SKeyMap(XK_asciicircum, KEY_OEM_5)); + KeyMap.push_back(SKeyMap(XK_dead_circumflex, KEY_OEM_5)); + KeyMap.push_back(SKeyMap(XK_degree, 0)); //? + KeyMap.push_back(SKeyMap(XK_underscore, KEY_MINUS)); //? + KeyMap.push_back(SKeyMap(XK_grave, KEY_OEM_3)); + KeyMap.push_back(SKeyMap(XK_dead_grave, KEY_OEM_3)); + KeyMap.push_back(SKeyMap(XK_acute, KEY_OEM_6)); + KeyMap.push_back(SKeyMap(XK_dead_acute, KEY_OEM_6)); + KeyMap.push_back(SKeyMap(XK_a, KEY_KEY_A)); + KeyMap.push_back(SKeyMap(XK_b, KEY_KEY_B)); + KeyMap.push_back(SKeyMap(XK_c, KEY_KEY_C)); + KeyMap.push_back(SKeyMap(XK_d, KEY_KEY_D)); + KeyMap.push_back(SKeyMap(XK_e, KEY_KEY_E)); + KeyMap.push_back(SKeyMap(XK_f, KEY_KEY_F)); + KeyMap.push_back(SKeyMap(XK_g, KEY_KEY_G)); + KeyMap.push_back(SKeyMap(XK_h, KEY_KEY_H)); + KeyMap.push_back(SKeyMap(XK_i, KEY_KEY_I)); + KeyMap.push_back(SKeyMap(XK_j, KEY_KEY_J)); + KeyMap.push_back(SKeyMap(XK_k, KEY_KEY_K)); + KeyMap.push_back(SKeyMap(XK_l, KEY_KEY_L)); + KeyMap.push_back(SKeyMap(XK_m, KEY_KEY_M)); + KeyMap.push_back(SKeyMap(XK_n, KEY_KEY_N)); + KeyMap.push_back(SKeyMap(XK_o, KEY_KEY_O)); + KeyMap.push_back(SKeyMap(XK_p, KEY_KEY_P)); + KeyMap.push_back(SKeyMap(XK_q, KEY_KEY_Q)); + KeyMap.push_back(SKeyMap(XK_r, KEY_KEY_R)); + KeyMap.push_back(SKeyMap(XK_s, KEY_KEY_S)); + KeyMap.push_back(SKeyMap(XK_t, KEY_KEY_T)); + KeyMap.push_back(SKeyMap(XK_u, KEY_KEY_U)); + KeyMap.push_back(SKeyMap(XK_v, KEY_KEY_V)); + KeyMap.push_back(SKeyMap(XK_w, KEY_KEY_W)); + KeyMap.push_back(SKeyMap(XK_x, KEY_KEY_X)); + KeyMap.push_back(SKeyMap(XK_y, KEY_KEY_Y)); + KeyMap.push_back(SKeyMap(XK_z, KEY_KEY_Z)); + KeyMap.push_back(SKeyMap(XK_ssharp, KEY_OEM_4)); + KeyMap.push_back(SKeyMap(XK_adiaeresis, KEY_OEM_7)); + KeyMap.push_back(SKeyMap(XK_odiaeresis, KEY_OEM_3)); + KeyMap.push_back(SKeyMap(XK_udiaeresis, KEY_OEM_1)); + KeyMap.push_back(SKeyMap(XK_Super_L, KEY_LWIN)); + KeyMap.push_back(SKeyMap(XK_Super_R, KEY_RWIN)); + + KeyMap.sort(); +#endif +} + +bool CIrrDeviceLinux::activateJoysticks(core::array &joystickInfo) +{ +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + + joystickInfo.clear(); + + u32 joystick; + for (joystick = 0; joystick < 32; ++joystick) { + // The joystick device could be here... + core::stringc devName = "/dev/js"; + devName += joystick; + + SJoystickInfo returnInfo; + JoystickInfo info; + + info.fd = open(devName.c_str(), O_RDONLY); + if (-1 == info.fd) { + // ...but Ubuntu and possibly other distros + // create the devices in /dev/input + devName = "/dev/input/js"; + devName += joystick; + info.fd = open(devName.c_str(), O_RDONLY); + if (-1 == info.fd) { + // and BSD here + devName = "/dev/joy"; + devName += joystick; + info.fd = open(devName.c_str(), O_RDONLY); + } + } + + if (-1 == info.fd) + continue; + +#ifdef __FreeBSD__ + info.axes = 2; + info.buttons = 2; +#else + ioctl(info.fd, JSIOCGAXES, &(info.axes)); + ioctl(info.fd, JSIOCGBUTTONS, &(info.buttons)); + fcntl(info.fd, F_SETFL, O_NONBLOCK); +#endif + + (void)memset(&info.persistentData, 0, sizeof(info.persistentData)); + info.persistentData.EventType = irr::EET_JOYSTICK_INPUT_EVENT; + info.persistentData.JoystickEvent.Joystick = ActiveJoysticks.size(); + + // There's no obvious way to determine which (if any) axes represent a POV + // hat, so we'll just set it to "not used" and forget about it. + info.persistentData.JoystickEvent.POV = 65535; + + ActiveJoysticks.push_back(info); + + returnInfo.Joystick = joystick; + returnInfo.PovHat = SJoystickInfo::POV_HAT_UNKNOWN; + returnInfo.Axes = info.axes; + returnInfo.Buttons = info.buttons; + +#ifndef __FreeBSD__ + char name[80]; + ioctl(info.fd, JSIOCGNAME(80), name); + returnInfo.Name = name; +#endif + + joystickInfo.push_back(returnInfo); + } + + for (joystick = 0; joystick < joystickInfo.size(); ++joystick) { + char logString[256]; + snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'", + joystick, joystickInfo[joystick].Axes, + joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); + os::Printer::log(logString, ELL_INFORMATION); + } + + return true; +#else + return false; +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +} + +void CIrrDeviceLinux::pollJoysticks() +{ +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + if (0 == ActiveJoysticks.size()) + return; + + for (u32 j = 0; j < ActiveJoysticks.size(); ++j) { + JoystickInfo &info = ActiveJoysticks[j]; + +#ifdef __FreeBSD__ + struct joystick js; + if (read(info.fd, &js, sizeof(js)) == sizeof(js)) { + info.persistentData.JoystickEvent.ButtonStates = js.b1 | (js.b2 << 1); /* should be a two-bit field */ + info.persistentData.JoystickEvent.Axis[0] = js.x; /* X axis */ + info.persistentData.JoystickEvent.Axis[1] = js.y; /* Y axis */ + } +#else + struct js_event event; + while (sizeof(event) == read(info.fd, &event, sizeof(event))) { + switch (event.type & ~JS_EVENT_INIT) { + case JS_EVENT_BUTTON: + if (event.value) + info.persistentData.JoystickEvent.ButtonStates |= (1 << event.number); + else + info.persistentData.JoystickEvent.ButtonStates &= ~(1 << event.number); + break; + + case JS_EVENT_AXIS: + if (event.number < SEvent::SJoystickEvent::NUMBER_OF_AXES) + info.persistentData.JoystickEvent.Axis[event.number] = event.value; + break; + + default: + break; + } + } +#endif + + // Send an irrlicht joystick event once per ::run() even if no new data were received. + (void)postEventFromUser(info.persistentData); + } +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +} + +#if defined(_IRR_COMPILE_WITH_X11_) +//! gets text from the clipboard +//! \return Returns 0 if no string is in there, otherwise utf-8 text. +const c8 *CIrrDeviceLinux::getTextFromSelection(Atom selection, core::stringc &text_buffer) const +{ + Window ownerWindow = XGetSelectionOwner(XDisplay, selection); + if (ownerWindow == XWindow) { + return text_buffer.c_str(); + } + + text_buffer = ""; + + if (ownerWindow == None) { + return text_buffer.c_str(); + } + + // delete the property to be set beforehand + XDeleteProperty(XDisplay, XWindow, XA_PRIMARY); + + XConvertSelection(XDisplay, selection, X_ATOM_UTF8_STRING, XA_PRIMARY, + XWindow, CurrentTime); + XFlush(XDisplay); + + // wait for event via a blocking call + XEvent event_ret; + std::pair args(XWindow, selection); + XIfEvent( + XDisplay, &event_ret, [](Display *_display, XEvent *event, XPointer arg) { + auto p = reinterpret_cast *>(arg); + return (Bool)(event->type == SelectionNotify && + event->xselection.requestor == p->first && + event->xselection.selection == p->second && + event->xselection.target == X_ATOM_UTF8_STRING); + }, + (XPointer)&args); + + _IRR_DEBUG_BREAK_IF(!(event_ret.type == SelectionNotify && + event_ret.xselection.requestor == XWindow && + event_ret.xselection.selection == selection && + event_ret.xselection.target == X_ATOM_UTF8_STRING)); + + Atom property_set = event_ret.xselection.property; + if (event_ret.xselection.property == None) { + // request failed => empty string + return text_buffer.c_str(); + } + + // check for data + Atom type; + int format; + unsigned long numItems, bytesLeft, dummy; + unsigned char *data = nullptr; + XGetWindowProperty(XDisplay, XWindow, + property_set, // property name + 0, // offset + 0, // length (we only check for data, so 0) + 0, // Delete 0==false + AnyPropertyType, // AnyPropertyType or property identifier + &type, // return type + &format, // return format + &numItems, // number items + &bytesLeft, // remaining bytes for partial reads + &data); // data + if (data) { + XFree(data); + data = nullptr; + } + + // for debugging: + //~ { + //~ char *type_name = XGetAtomName(XDisplay, type); + //~ fprintf(stderr, "CIrrDeviceLinux::getTextFromSelection: actual type: %s (=%ld)\n", + //~ type_name, type); + //~ XFree(type_name); + //~ } + + if (type != X_ATOM_UTF8_STRING && type != X_ATOM_UTF8_MIME_TYPE) { + os::Printer::log("CIrrDeviceLinux::getTextFromSelection: did not get utf-8 string", + ELL_WARNING); + return text_buffer.c_str(); + } + + if (bytesLeft > 0) { + // there is some data to get + int result = XGetWindowProperty(XDisplay, XWindow, property_set, 0, + bytesLeft, 0, AnyPropertyType, &type, &format, + &numItems, &dummy, &data); + if (result == Success) + text_buffer = (irr::c8 *)data; + XFree(data); + } + + // delete the property again, to inform the owner about the successful transfer + XDeleteProperty(XDisplay, XWindow, property_set); + + return text_buffer.c_str(); +} +#endif + +//! gets text from the clipboard +//! \return Returns 0 if no string is in there, otherwise utf-8 text. +const c8 *CIrrDeviceLinux::getTextFromClipboard() const +{ +#if defined(_IRR_COMPILE_WITH_X11_) + return getTextFromSelection(X_ATOM_CLIPBOARD, Clipboard); +#else + return nullptr; +#endif +} + +//! gets text from the primary selection +//! \return Returns 0 if no string is in there, otherwise utf-8 text. +const c8 *CIrrDeviceLinux::getTextFromPrimarySelection() const +{ +#if defined(_IRR_COMPILE_WITH_X11_) + return getTextFromSelection(XA_PRIMARY, PrimarySelection); +#else + return nullptr; +#endif +} + +#if defined(_IRR_COMPILE_WITH_X11_) +bool CIrrDeviceLinux::becomeSelectionOwner(Atom selection) const +{ + XSetSelectionOwner(XDisplay, selection, XWindow, CurrentTime); + XFlush(XDisplay); + Window owner = XGetSelectionOwner(XDisplay, selection); + return owner == XWindow; +} +#endif + +//! copies text to the clipboard +void CIrrDeviceLinux::copyToClipboard(const c8 *text) const +{ +#if defined(_IRR_COMPILE_WITH_X11_) + // Actually there is no clipboard on X but applications just say they own the clipboard and return text when asked. + // Which btw. also means that on X you lose clipboard content when closing applications. + Clipboard = text; + if (!becomeSelectionOwner(X_ATOM_CLIPBOARD)) { + os::Printer::log("CIrrDeviceLinux::copyToClipboard: failed to set owner", ELL_WARNING); + } +#endif +} + +//! copies text to the primary selection +void CIrrDeviceLinux::copyToPrimarySelection(const c8 *text) const +{ +#if defined(_IRR_COMPILE_WITH_X11_) + PrimarySelection = text; + if (!becomeSelectionOwner(XA_PRIMARY)) { + os::Printer::log("CIrrDeviceLinux::copyToPrimarySelection: failed to set owner", ELL_WARNING); + } +#endif +} + +#ifdef _IRR_COMPILE_WITH_X11_ +// return true if the passed event has the type passed in parameter arg +Bool PredicateIsEventType(Display *display, XEvent *event, XPointer arg) +{ + if (event && event->type == *(int *)arg) { + // os::Printer::log("remove event", core::stringc((int)arg).c_str(), ELL_INFORMATION); + return True; + } + return False; +} +#endif //_IRR_COMPILE_WITH_X11_ + +//! Remove all messages pending in the system message loop +void CIrrDeviceLinux::clearSystemMessages() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType != video::EDT_NULL) { + XEvent event; + int usrArg = ButtonPress; + while (XCheckIfEvent(XDisplay, &event, PredicateIsEventType, XPointer(&usrArg)) == True) { + } + usrArg = ButtonRelease; + while (XCheckIfEvent(XDisplay, &event, PredicateIsEventType, XPointer(&usrArg)) == True) { + } + usrArg = MotionNotify; + while (XCheckIfEvent(XDisplay, &event, PredicateIsEventType, XPointer(&usrArg)) == True) { + } + usrArg = KeyRelease; + while (XCheckIfEvent(XDisplay, &event, PredicateIsEventType, XPointer(&usrArg)) == True) { + } + usrArg = KeyPress; + while (XCheckIfEvent(XDisplay, &event, PredicateIsEventType, XPointer(&usrArg)) == True) { + } + } +#endif //_IRR_COMPILE_WITH_X11_ +} + +//! Get the display density in dots per inch. +float CIrrDeviceLinux::getDisplayDensity() const +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (XDisplay != NULL) { + /* try x direct */ + int dh = DisplayHeight(XDisplay, 0); + int dw = DisplayWidth(XDisplay, 0); + int dh_mm = DisplayHeightMM(XDisplay, 0); + int dw_mm = DisplayWidthMM(XDisplay, 0); + + if (dh_mm != 0 && dw_mm != 0) { + float dpi_height = floor(dh / (dh_mm * 0.039370) + 0.5); + float dpi_width = floor(dw / (dw_mm * 0.039370) + 0.5); + return std::max(dpi_height, dpi_width); + } + } +#endif //_IRR_COMPILE_WITH_X11_ + + return 0.0f; +} + +void CIrrDeviceLinux::initXAtoms() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + X_ATOM_CLIPBOARD = XInternAtom(XDisplay, "CLIPBOARD", False); + X_ATOM_TARGETS = XInternAtom(XDisplay, "TARGETS", False); + X_ATOM_UTF8_STRING = XInternAtom(XDisplay, "UTF8_STRING", False); + X_ATOM_UTF8_MIME_TYPE = XInternAtom(XDisplay, "text/plain;charset=utf-8", False); + X_ATOM_TEXT = XInternAtom(XDisplay, "TEXT", False); + X_ATOM_NETWM_MAXIMIZE_VERT = XInternAtom(XDisplay, "_NET_WM_STATE_MAXIMIZED_VERT", true); + X_ATOM_NETWM_MAXIMIZE_HORZ = XInternAtom(XDisplay, "_NET_WM_STATE_MAXIMIZED_HORZ", true); + X_ATOM_NETWM_STATE = XInternAtom(XDisplay, "_NET_WM_STATE", true); + X_ATOM_NETWM_STATE_FULLSCREEN = XInternAtom(XDisplay, "_NET_WM_STATE_FULLSCREEN", True); +#endif +} + +void CIrrDeviceLinux::initXInput2() +{ +#if defined(_IRR_LINUX_X11_XINPUT2_) + int ev = 0; + int err = 0; + if (!XQueryExtension(XDisplay, "XInputExtension", &XI_EXTENSIONS_OPCODE, &ev, &err)) { + os::Printer::log("X Input extension not available.", ELL_WARNING); + return; + } + + int major = 2; + int minor = 3; + int rc = XIQueryVersion(XDisplay, &major, &minor); + if (rc != Success) { + os::Printer::log("No XI2 support.", ELL_WARNING); + return; + } + + // So far we only use XInput2 for touch events. + // So we enable those and disable all other events for now. + XIEventMask eventMask; + unsigned char mask[XIMaskLen(XI_TouchEnd)]; + memset(mask, 0, sizeof(mask)); + eventMask.deviceid = XIAllMasterDevices; + eventMask.mask_len = sizeof(mask); + eventMask.mask = mask; + XISetMask(eventMask.mask, XI_TouchBegin); + XISetMask(eventMask.mask, XI_TouchUpdate); + XISetMask(eventMask.mask, XI_TouchEnd); + + XISelectEvents(XDisplay, XWindow, &eventMask, 1); +#endif +} + +#ifdef _IRR_COMPILE_WITH_X11_ + +Cursor CIrrDeviceLinux::TextureToMonochromeCursor(irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot) +{ + XImage *sourceImage = XCreateImage(XDisplay, VisualInfo->visual, + 1, // depth, + ZPixmap, // XYBitmap (depth=1), ZPixmap(depth=x) + 0, 0, sourceRect.getWidth(), sourceRect.getHeight(), + 32, // bitmap_pad, + 0 // bytes_per_line (0 means continuous in memory) + ); + sourceImage->data = new char[sourceImage->height * sourceImage->bytes_per_line]; + XImage *maskImage = XCreateImage(XDisplay, VisualInfo->visual, + 1, // depth, + ZPixmap, + 0, 0, sourceRect.getWidth(), sourceRect.getHeight(), + 32, // bitmap_pad, + 0 // bytes_per_line + ); + maskImage->data = new char[maskImage->height * maskImage->bytes_per_line]; + + // write texture into XImage + video::ECOLOR_FORMAT format = tex->getColorFormat(); + u32 bytesPerPixel = video::IImage::getBitsPerPixelFromFormat(format) / 8; + u32 bytesLeftGap = sourceRect.UpperLeftCorner.X * bytesPerPixel; + u32 bytesRightGap = tex->getPitch() - sourceRect.LowerRightCorner.X * bytesPerPixel; + const u8 *data = (const u8 *)tex->lock(video::ETLM_READ_ONLY, 0); + data += sourceRect.UpperLeftCorner.Y * tex->getPitch(); + for (s32 y = 0; y < sourceRect.getHeight(); ++y) { + data += bytesLeftGap; + for (s32 x = 0; x < sourceRect.getWidth(); ++x) { + video::SColor pixelCol; + pixelCol.setData((const void *)data, format); + data += bytesPerPixel; + + if (pixelCol.getAlpha() == 0) { // transparent + XPutPixel(maskImage, x, y, 0); + XPutPixel(sourceImage, x, y, 0); + } else // color + { + if (pixelCol.getAverage() >= 127) + XPutPixel(sourceImage, x, y, 1); + else + XPutPixel(sourceImage, x, y, 0); + XPutPixel(maskImage, x, y, 1); + } + } + data += bytesRightGap; + } + tex->unlock(); + + Pixmap sourcePixmap = XCreatePixmap(XDisplay, XWindow, sourceImage->width, sourceImage->height, sourceImage->depth); + Pixmap maskPixmap = XCreatePixmap(XDisplay, XWindow, maskImage->width, maskImage->height, maskImage->depth); + + XGCValues values; + values.foreground = 1; + values.background = 1; + GC gc = XCreateGC(XDisplay, sourcePixmap, GCForeground | GCBackground, &values); + + XPutImage(XDisplay, sourcePixmap, gc, sourceImage, 0, 0, 0, 0, sourceImage->width, sourceImage->height); + XPutImage(XDisplay, maskPixmap, gc, maskImage, 0, 0, 0, 0, maskImage->width, maskImage->height); + + XFreeGC(XDisplay, gc); + XDestroyImage(sourceImage); + XDestroyImage(maskImage); + + Cursor cursorResult = 0; + XColor foreground, background; + foreground.red = 65535; + foreground.green = 65535; + foreground.blue = 65535; + foreground.flags = DoRed | DoGreen | DoBlue; + background.red = 0; + background.green = 0; + background.blue = 0; + background.flags = DoRed | DoGreen | DoBlue; + + cursorResult = XCreatePixmapCursor(XDisplay, sourcePixmap, maskPixmap, &foreground, &background, hotspot.X, hotspot.Y); + + XFreePixmap(XDisplay, sourcePixmap); + XFreePixmap(XDisplay, maskPixmap); + + return cursorResult; +} + +#ifdef _IRR_LINUX_XCURSOR_ +Cursor CIrrDeviceLinux::TextureToARGBCursor(irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot) +{ + XcursorImage *image = XcursorImageCreate(sourceRect.getWidth(), sourceRect.getHeight()); + image->xhot = hotspot.X; + image->yhot = hotspot.Y; + + // write texture into XcursorImage + video::ECOLOR_FORMAT format = tex->getColorFormat(); + u32 bytesPerPixel = video::IImage::getBitsPerPixelFromFormat(format) / 8; + u32 bytesLeftGap = sourceRect.UpperLeftCorner.X * bytesPerPixel; + u32 bytesRightGap = tex->getPitch() - sourceRect.LowerRightCorner.X * bytesPerPixel; + XcursorPixel *target = image->pixels; + const u8 *data = (const u8 *)tex->lock(video::ETLM_READ_ONLY, 0); + data += sourceRect.UpperLeftCorner.Y * tex->getPitch(); + for (s32 y = 0; y < sourceRect.getHeight(); ++y) { + data += bytesLeftGap; + for (s32 x = 0; x < sourceRect.getWidth(); ++x) { + video::SColor pixelCol; + pixelCol.setData((const void *)data, format); + data += bytesPerPixel; + + *target = (XcursorPixel)pixelCol.color; + ++target; + } + data += bytesRightGap; + } + tex->unlock(); + + Cursor cursorResult = XcursorImageLoadCursor(XDisplay, image); + + XcursorImageDestroy(image); + + return cursorResult; +} +#endif // #ifdef _IRR_LINUX_XCURSOR_ + +Cursor CIrrDeviceLinux::TextureToCursor(irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot) +{ +#ifdef _IRR_LINUX_XCURSOR_ + return TextureToARGBCursor(tex, sourceRect, hotspot); +#else + return TextureToMonochromeCursor(tex, sourceRect, hotspot); +#endif +} +#endif // _IRR_COMPILE_WITH_X11_ + +CIrrDeviceLinux::CCursorControl::CCursorControl(CIrrDeviceLinux *dev, bool null) : + Device(dev) +#ifdef _IRR_COMPILE_WITH_X11_ + , + PlatformBehavior(gui::ECPB_NONE), LastQuery(0) +#ifdef _IRR_LINUX_X11_XINPUT2_ + , + DeviceId(0) +#endif +#endif + , + IsVisible(true), Null(null), UseReferenceRect(false), ActiveIcon(gui::ECI_NORMAL), ActiveIconStartTime(0) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (!Null) { +#ifdef _IRR_LINUX_X11_XINPUT2_ + // XIWarpPointer is entirely broken on multi-head setups (see also [1]), + // but behaves better in other cases so we can't just disable it outright. + // [1] https://developer.blender.org/rB165caafb99c6846e53d11c4e966990aaffc06cea + if (XScreenCount(Device->XDisplay) > 1) { + os::Printer::log("Detected classic multi-head setup, not using XIWarpPointer"); + } else { + XIGetClientPointer(Device->XDisplay, Device->XWindow, &DeviceId); + } +#endif + + XGCValues values; + unsigned long valuemask = 0; + + XColor fg, bg; + + // this code, for making the cursor invisible was sent in by + // Sirshane, thank your very much! + + Pixmap invisBitmap = XCreatePixmap(Device->XDisplay, Device->XWindow, 32, 32, 1); + Pixmap maskBitmap = XCreatePixmap(Device->XDisplay, Device->XWindow, 32, 32, 1); + Colormap screen_colormap = DefaultColormap(Device->XDisplay, DefaultScreen(Device->XDisplay)); + XAllocNamedColor(Device->XDisplay, screen_colormap, "black", &fg, &fg); + XAllocNamedColor(Device->XDisplay, screen_colormap, "white", &bg, &bg); + + GC gc = XCreateGC(Device->XDisplay, invisBitmap, valuemask, &values); + + XSetForeground(Device->XDisplay, gc, BlackPixel(Device->XDisplay, DefaultScreen(Device->XDisplay))); + XFillRectangle(Device->XDisplay, invisBitmap, gc, 0, 0, 32, 32); + XFillRectangle(Device->XDisplay, maskBitmap, gc, 0, 0, 32, 32); + + InvisCursor = XCreatePixmapCursor(Device->XDisplay, invisBitmap, maskBitmap, &fg, &bg, 1, 1); + XFreeGC(Device->XDisplay, gc); + XFreePixmap(Device->XDisplay, invisBitmap); + XFreePixmap(Device->XDisplay, maskBitmap); + + initCursors(); + } +#endif +} + +CIrrDeviceLinux::CCursorControl::~CCursorControl() +{ + // Do not clearCursors here as the display is already closed + // TODO (cutealien): dropping cursorcontrol earlier might work, not sure about reason why that's done in stub currently. +} + +#ifdef _IRR_COMPILE_WITH_X11_ +void CIrrDeviceLinux::CCursorControl::clearCursors() +{ + if (!Null) + XFreeCursor(Device->XDisplay, InvisCursor); + for (u32 i = 0; i < Cursors.size(); ++i) { + for (u32 f = 0; f < Cursors[i].Frames.size(); ++f) { + XFreeCursor(Device->XDisplay, Cursors[i].Frames[f].IconHW); + } + } +} + +void CIrrDeviceLinux::CCursorControl::initCursors() +{ + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_top_left_arrow))); // (or XC_arrow?) + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_crosshair))); + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_hand2))); // (or XC_hand1? ) + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_question_arrow))); + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_xterm))); + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_X_cursor))); // (or XC_pirate?) + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_watch))); // (or XC_clock?) + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_fleur))); + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_top_right_corner))); // NESW not available in X11 + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_top_left_corner))); // NWSE not available in X11 + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_sb_v_double_arrow))); + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_sb_h_double_arrow))); + Cursors.push_back(CursorX11(XCreateFontCursor(Device->XDisplay, XC_sb_up_arrow))); // (or XC_center_ptr?) +} + +void CIrrDeviceLinux::CCursorControl::update() +{ + if ((u32)ActiveIcon < Cursors.size() && !Cursors[ActiveIcon].Frames.empty() && Cursors[ActiveIcon].FrameTime) { + // update animated cursors. This could also be done by X11 in case someone wants to figure that out (this way was just easier to implement) + u32 now = Device->getTimer()->getRealTime(); + u32 frame = ((now - ActiveIconStartTime) / Cursors[ActiveIcon].FrameTime) % Cursors[ActiveIcon].Frames.size(); + XDefineCursor(Device->XDisplay, Device->XWindow, Cursors[ActiveIcon].Frames[frame].IconHW); + } +} +#endif + +//! Sets the active cursor icon +void CIrrDeviceLinux::CCursorControl::setActiveIcon(gui::ECURSOR_ICON iconId) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (iconId >= (s32)Cursors.size()) + return; + + if (Cursors[iconId].Frames.size()) + XDefineCursor(Device->XDisplay, Device->XWindow, Cursors[iconId].Frames[0].IconHW); + + ActiveIconStartTime = Device->getTimer()->getRealTime(); + ActiveIcon = iconId; +#endif +} + +//! Add a custom sprite as cursor icon. +gui::ECURSOR_ICON CIrrDeviceLinux::CCursorControl::addIcon(const gui::SCursorSprite &icon) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (icon.SpriteId >= 0) { + CursorX11 cX11; + cX11.FrameTime = icon.SpriteBank->getSprites()[icon.SpriteId].frameTime; + for (u32 i = 0; i < icon.SpriteBank->getSprites()[icon.SpriteId].Frames.size(); ++i) { + irr::u32 texId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].textureNumber; + irr::u32 rectId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].rectNumber; + irr::core::rect rectIcon = icon.SpriteBank->getPositions()[rectId]; + Cursor cursor = Device->TextureToCursor(icon.SpriteBank->getTexture(texId), rectIcon, icon.HotSpot); + cX11.Frames.push_back(CursorFrameX11(cursor)); + } + + Cursors.push_back(cX11); + + return (gui::ECURSOR_ICON)(Cursors.size() - 1); + } +#endif + return gui::ECI_NORMAL; +} + +//! replace the given cursor icon. +void CIrrDeviceLinux::CCursorControl::changeIcon(gui::ECURSOR_ICON iconId, const gui::SCursorSprite &icon) +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (iconId >= (s32)Cursors.size()) + return; + + for (u32 i = 0; i < Cursors[iconId].Frames.size(); ++i) + XFreeCursor(Device->XDisplay, Cursors[iconId].Frames[i].IconHW); + + if (icon.SpriteId >= 0) { + CursorX11 cX11; + cX11.FrameTime = icon.SpriteBank->getSprites()[icon.SpriteId].frameTime; + for (u32 i = 0; i < icon.SpriteBank->getSprites()[icon.SpriteId].Frames.size(); ++i) { + irr::u32 texId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].textureNumber; + irr::u32 rectId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].rectNumber; + irr::core::rect rectIcon = icon.SpriteBank->getPositions()[rectId]; + Cursor cursor = Device->TextureToCursor(icon.SpriteBank->getTexture(texId), rectIcon, icon.HotSpot); + cX11.Frames.push_back(CursorFrameX11(cursor)); + } + + Cursors[iconId] = cX11; + } +#endif +} + +irr::core::dimension2di CIrrDeviceLinux::CCursorControl::getSupportedIconSize() const +{ + // this returns the closest match that is smaller or same size, so we just pass a value which should be large enough for cursors + unsigned int width = 0, height = 0; +#ifdef _IRR_COMPILE_WITH_X11_ + XQueryBestCursor(Device->XDisplay, Device->XWindow, 64, 64, &width, &height); +#endif + return core::dimension2di(width, height); +} + +} // end namespace + +#endif // _IRR_COMPILE_WITH_X11_DEVICE_ diff --git a/irr/src/CIrrDeviceLinux.h b/irr/src/CIrrDeviceLinux.h new file mode 100644 index 000000000..4aac1cf6c --- /dev/null +++ b/irr/src/CIrrDeviceLinux.h @@ -0,0 +1,469 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ + +#include "CIrrDeviceStub.h" +#include "IrrlichtDevice.h" +#include "ICursorControl.h" +#include "os.h" + +#ifdef _IRR_COMPILE_WITH_X11_ + +#include +#include +#include +#include + +#ifdef _IRR_LINUX_X11_XINPUT2_ +#include +#endif + +#else +#define KeySym s32 +#endif + +namespace irr +{ + +class CIrrDeviceLinux : public CIrrDeviceStub +{ +public: + //! constructor + CIrrDeviceLinux(const SIrrlichtCreationParameters ¶m); + + //! destructor + virtual ~CIrrDeviceLinux(); + + //! runs the device. Returns false if device wants to be deleted + bool run() override; + + //! Cause the device to temporarily pause execution and let other processes to run + // This should bring down processor usage without major performance loss for Irrlicht + void yield() override; + + //! Pause execution and let other processes to run for a specified amount of time. + void sleep(u32 timeMs, bool pauseTimer) override; + + //! sets the caption of the window + void setWindowCaption(const wchar_t *text) override; + + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + + //! returns if window is active. if not, nothing need to be drawn + bool isWindowActive() const override; + + //! returns if window has focus. + bool isWindowFocused() const override; + + //! returns if window is minimized. + bool isWindowMinimized() const override; + + //! returns last state from maximizeWindow() and restoreWindow() + bool isWindowMaximized() const override; + + //! returns color format of the window. + video::ECOLOR_FORMAT getColorFormat() const override; + + //! notifies the device that it should close itself + void closeDevice() override; + + //! Sets if the window should be resizable in windowed mode. + void setResizable(bool resize = false) override; + + //! Resize the render window. + void setWindowSize(const irr::core::dimension2d &size) override; + + //! Minimizes the window. + void minimizeWindow() override; + + //! Maximizes the window. + void maximizeWindow() override; + + //! Restores the window size. + void restoreWindow() override; + + //! Get the position of this window on screen + core::position2di getWindowPosition() override; + + //! Activate any joysticks, and generate events for them. + bool activateJoysticks(core::array &joystickInfo) override; + + //! gets text from the clipboard + //! \return Returns 0 if no string is in there, otherwise utf-8 text. + virtual const c8 *getTextFromClipboard() const; + + //! gets text from the primary selection + //! \return Returns 0 if no string is in there, otherwise utf-8 text. + virtual const c8 *getTextFromPrimarySelection() const; + + //! copies text to the clipboard + //! This sets the clipboard selection and _not_ the primary selection. + //! @param text The text in utf-8 + virtual void copyToClipboard(const c8 *text) const; + + //! copies text to the primary selection + //! This sets the primary selection which you have on X on the middle mouse button. + //! @param text The text in utf-8 + virtual void copyToPrimarySelection(const c8 *text) const; + + //! Remove all messages pending in the system message loop + void clearSystemMessages() override; + + //! Get the device type + E_DEVICE_TYPE getType() const override + { + return EIDT_X11; + } + + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + +#ifdef _IRR_COMPILE_WITH_X11_ + // convert an Irrlicht texture to a X11 cursor + Cursor TextureToCursor(irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot); + Cursor TextureToMonochromeCursor(irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot); +#ifdef _IRR_LINUX_XCURSOR_ + Cursor TextureToARGBCursor(irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot); +#endif +#endif + +private: + //! create the driver + void createDriver(); + + bool createWindow(); + + void createKeyMap(); + + void pollJoysticks(); + + void initXAtoms(); + + void initXInput2(); + + bool switchToFullscreen(); + + void setupTopLevelXorgWindow(); + +#ifdef _IRR_COMPILE_WITH_X11_ + bool createInputContext(); + void destroyInputContext(); + EKEY_CODE getKeyCode(XEvent &event); + + const c8 *getTextFromSelection(Atom selection, core::stringc &text_buffer) const; + bool becomeSelectionOwner(Atom selection) const; +#endif + + //! Implementation of the linux cursor control + class CCursorControl : public gui::ICursorControl + { + public: + CCursorControl(CIrrDeviceLinux *dev, bool null); + + ~CCursorControl(); + + //! Changes the visible state of the mouse cursor. + void setVisible(bool visible) override + { + if (visible == IsVisible) + return; + IsVisible = visible; +#ifdef _IRR_COMPILE_WITH_X11_ + if (!Null) { + if (!IsVisible) + XDefineCursor(Device->XDisplay, Device->XWindow, InvisCursor); + else + XUndefineCursor(Device->XDisplay, Device->XWindow); + } +#endif + } + + //! Returns if the cursor is currently visible. + bool isVisible() const override + { + return IsVisible; + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(f32 x, f32 y) override + { + setPosition((s32)(x * Device->Width), (s32)(y * Device->Height)); + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(s32 x, s32 y) override + { +#ifdef _IRR_COMPILE_WITH_X11_ + + if (!Null) { + if (UseReferenceRect) { +// NOTE: XIWarpPointer works when X11 has set a coordinate transformation matrix for the mouse unlike XWarpPointer +// which runs into a bug mentioned here: https://gitlab.freedesktop.org/xorg/xserver/-/issues/600 +// So also workaround for Irrlicht bug #450 +#ifdef _IRR_LINUX_X11_XINPUT2_ + if (DeviceId != 0) { + XIWarpPointer(Device->XDisplay, + DeviceId, + None, + Device->XWindow, 0, 0, + Device->Width, + Device->Height, + ReferenceRect.UpperLeftCorner.X + x, + ReferenceRect.UpperLeftCorner.Y + y); + } else +#endif + { + XWarpPointer(Device->XDisplay, + None, + Device->XWindow, 0, 0, + Device->Width, + Device->Height, + ReferenceRect.UpperLeftCorner.X + x, + ReferenceRect.UpperLeftCorner.Y + y); + } + } else { +#ifdef _IRR_LINUX_X11_XINPUT2_ + if (DeviceId != 0) { + XIWarpPointer(Device->XDisplay, + DeviceId, + None, + Device->XWindow, 0, 0, + Device->Width, + Device->Height, x, y); + } else +#endif + { + XWarpPointer(Device->XDisplay, + None, + Device->XWindow, 0, 0, + Device->Width, + Device->Height, x, y); + } + } + XFlush(Device->XDisplay); + } +#endif + CursorPos.X = x; + CursorPos.Y = y; + } + + //! Returns the current position of the mouse cursor. + const core::position2d &getPosition(bool updateCursor) override + { + if (updateCursor) + updateCursorPos(); + return CursorPos; + } + + //! Returns the current position of the mouse cursor. + core::position2d getRelativePosition(bool updateCursor) override + { + if (updateCursor) + updateCursorPos(); + + if (!UseReferenceRect) { + return core::position2d(CursorPos.X / (f32)Device->Width, + CursorPos.Y / (f32)Device->Height); + } + + return core::position2d(CursorPos.X / (f32)ReferenceRect.getWidth(), + CursorPos.Y / (f32)ReferenceRect.getHeight()); + } + + void setReferenceRect(core::rect *rect = 0) override + { + if (rect) { + ReferenceRect = *rect; + UseReferenceRect = true; + + // prevent division through zero and uneven sizes + + if (!ReferenceRect.getHeight() || ReferenceRect.getHeight() % 2) + ReferenceRect.LowerRightCorner.Y += 1; + + if (!ReferenceRect.getWidth() || ReferenceRect.getWidth() % 2) + ReferenceRect.LowerRightCorner.X += 1; + } else + UseReferenceRect = false; + } + + //! Sets the active cursor icon + void setActiveIcon(gui::ECURSOR_ICON iconId) override; + + //! Gets the currently active icon + gui::ECURSOR_ICON getActiveIcon() const override + { + return ActiveIcon; + } + + //! Add a custom sprite as cursor icon. + gui::ECURSOR_ICON addIcon(const gui::SCursorSprite &icon) override; + + //! replace the given cursor icon. + void changeIcon(gui::ECURSOR_ICON iconId, const gui::SCursorSprite &icon) override; + + //! Return a system-specific size which is supported for cursors. Larger icons will fail, smaller icons might work. + core::dimension2di getSupportedIconSize() const override; + +#ifdef _IRR_COMPILE_WITH_X11_ + //! Set platform specific behavior flags. + void setPlatformBehavior(gui::ECURSOR_PLATFORM_BEHAVIOR behavior) override { PlatformBehavior = behavior; } + + //! Return platform specific behavior. + gui::ECURSOR_PLATFORM_BEHAVIOR getPlatformBehavior() const override { return PlatformBehavior; } + + void update(); + void clearCursors(); +#endif + private: + void updateCursorPos() + { +#ifdef _IRR_COMPILE_WITH_X11_ + if (Null) + return; + + if (PlatformBehavior & gui::ECPB_X11_CACHE_UPDATES && !os::Timer::isStopped()) { + u32 now = os::Timer::getTime(); + if (now <= LastQuery) + return; + LastQuery = now; + } + + Window tmp; + int itmp1, itmp2; + unsigned int maskreturn; + XQueryPointer(Device->XDisplay, Device->XWindow, + &tmp, &tmp, + &itmp1, &itmp2, + &CursorPos.X, &CursorPos.Y, &maskreturn); +#endif + } + + CIrrDeviceLinux *Device; + core::position2d CursorPos; + core::rect ReferenceRect; +#ifdef _IRR_COMPILE_WITH_X11_ + gui::ECURSOR_PLATFORM_BEHAVIOR PlatformBehavior; + u32 LastQuery; + Cursor InvisCursor; + +#ifdef _IRR_LINUX_X11_XINPUT2_ + int DeviceId; +#endif + + struct CursorFrameX11 + { + CursorFrameX11() : + IconHW(0) {} + CursorFrameX11(Cursor icon) : + IconHW(icon) {} + + Cursor IconHW; // hardware cursor + }; + + struct CursorX11 + { + CursorX11() {} + explicit CursorX11(Cursor iconHw, u32 frameTime = 0) : + FrameTime(frameTime) + { + Frames.push_back(CursorFrameX11(iconHw)); + } + core::array Frames; + u32 FrameTime; + }; + + core::array Cursors; + + void initCursors(); +#endif + bool IsVisible; + bool Null; + bool UseReferenceRect; + gui::ECURSOR_ICON ActiveIcon; + u32 ActiveIconStartTime; + }; + + friend class CCursorControl; + +#ifdef _IRR_COMPILE_WITH_X11_ + friend class COpenGLDriver; + + Display *XDisplay; + XVisualInfo *VisualInfo; + int Screennr; + Window XWindow; + XSetWindowAttributes WndAttributes; + XSizeHints *StdHints; + XIM XInputMethod; + XIC XInputContext; + bool HasNetWM; + // text is utf-8 + mutable core::stringc Clipboard; + mutable core::stringc PrimarySelection; +#endif +#if defined(_IRR_LINUX_X11_XINPUT2_) + int currentTouchedCount; +#endif + u32 Width, Height; + bool WindowHasFocus; + bool WindowMinimized; + bool WindowMaximized; + bool ExternalWindow; + int AutorepeatSupport; + + struct SKeyMap + { + SKeyMap() {} + SKeyMap(s32 x11, s32 win32) : + X11Key(x11), Win32Key(win32) + { + } + + KeySym X11Key; + s32 Win32Key; + + bool operator<(const SKeyMap &o) const + { + return X11Key < o.X11Key; + } + }; + + core::array KeyMap; + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + struct JoystickInfo + { + int fd; + int axes; + int buttons; + + SEvent persistentData; + + JoystickInfo() : + fd(-1), axes(0), buttons(0) {} + }; + core::array ActiveJoysticks; +#endif +}; + +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_X11_DEVICE_ diff --git a/irr/src/CIrrDeviceOSX.h b/irr/src/CIrrDeviceOSX.h new file mode 100644 index 000000000..f4f159aa2 --- /dev/null +++ b/irr/src/CIrrDeviceOSX.h @@ -0,0 +1,238 @@ +// Copyright (C) 2005-2006 Etienne Petitjean +// Copyright (C) 2007-2012 Christian Stehno +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ + +#include "CIrrDeviceStub.h" +#include "IrrlichtDevice.h" +#include "IGUIEnvironment.h" +#include "ICursorControl.h" + +#import +#import + +#include + +namespace irr +{ +class CIrrDeviceMacOSX; +} + +@interface CIrrDelegateOSX : NSObject + +- (id)initWithDevice:(irr::CIrrDeviceMacOSX *)device; +- (void)terminate:(id)sender; +- (BOOL)isQuit; + +@end + +namespace irr +{ +class CIrrDeviceMacOSX : public CIrrDeviceStub +{ +public: + //! constructor + CIrrDeviceMacOSX(const SIrrlichtCreationParameters ¶ms); + + //! destructor + virtual ~CIrrDeviceMacOSX(); + + //! runs the device. Returns false if device wants to be deleted + bool run() override; + + //! Cause the device to temporarily pause execution and let other processes to run + // This should bring down processor usage without major performance loss for Irrlicht + void yield() override; + + //! Pause execution and let other processes to run for a specified amount of time. + void sleep(u32 timeMs, bool pauseTimer) override; + + //! sets the caption of the window + void setWindowCaption(const wchar_t *text) override; + + //! returns if window is active. if not, nothing need to be drawn + bool isWindowActive() const override; + + //! Checks if the Irrlicht window has focus + bool isWindowFocused() const override; + + //! Checks if the Irrlicht window is minimized + bool isWindowMinimized() const override; + + //! notifies the device that it should close itself + void closeDevice() override; + + //! Sets if the window should be resizable in windowed mode. + void setResizable(bool resize) override; + + //! Returns true if the window is resizable, false if not + virtual bool isResizable() const; + + //! Minimizes the window if possible + void minimizeWindow() override; + + //! Maximizes the window if possible. + void maximizeWindow() override; + + //! Restore the window to normal size if possible. + void restoreWindow() override; + + //! Get the position of this window on screen + core::position2di getWindowPosition() override; + + //! Activate any joysticks, and generate events for them. + bool activateJoysticks(core::array &joystickInfo) override; + + //! Get the device type + E_DEVICE_TYPE getType() const override + { + return EIDT_OSX; + } + + void setMouseLocation(int x, int y); + void setResize(int width, int height); + void setCursorVisible(bool visible); + void setWindow(NSWindow *window); + +private: + //! create the driver + void createDriver(); + + //! Implementation of the macos x cursor control + class CCursorControl : public gui::ICursorControl + { + public: + CCursorControl(const core::dimension2d &wsize, CIrrDeviceMacOSX *device) : + WindowSize(wsize), InvWindowSize(0.0f, 0.0f), Device(device), IsVisible(true), UseReferenceRect(false) + { + CursorPos.X = CursorPos.Y = 0; + if (WindowSize.Width != 0) + InvWindowSize.Width = 1.0f / WindowSize.Width; + if (WindowSize.Height != 0) + InvWindowSize.Height = 1.0f / WindowSize.Height; + } + + //! Changes the visible state of the mouse cursor. + void setVisible(bool visible) override + { + IsVisible = visible; + Device->setCursorVisible(visible); + } + + //! Returns if the cursor is currently visible. + bool isVisible() const override + { + return IsVisible; + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(f32 x, f32 y) override + { + setPosition((s32)(x * WindowSize.Width), (s32)(y * WindowSize.Height)); + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + if (CursorPos.X != pos.X || CursorPos.Y != pos.Y) + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(s32 x, s32 y) override + { + if (UseReferenceRect) { + Device->setMouseLocation(ReferenceRect.UpperLeftCorner.X + x, ReferenceRect.UpperLeftCorner.Y + y); + } else { + Device->setMouseLocation(x, y); + } + } + + //! Returns the current position of the mouse cursor. + const core::position2d &getPosition(bool updateCursor) override + { + return CursorPos; + } + + //! Returns the current position of the mouse cursor. + core::position2d getRelativePosition(bool updateCursor) override + { + if (!UseReferenceRect) { + return core::position2d(CursorPos.X * InvWindowSize.Width, + CursorPos.Y * InvWindowSize.Height); + } + + return core::position2d(CursorPos.X / (f32)ReferenceRect.getWidth(), + CursorPos.Y / (f32)ReferenceRect.getHeight()); + } + + //! Sets an absolute reference rect for calculating the cursor position. + void setReferenceRect(core::rect *rect = 0) override + { + if (rect) { + ReferenceRect = *rect; + UseReferenceRect = true; + + // prevent division through zero and uneven sizes + + if (!ReferenceRect.getHeight() || ReferenceRect.getHeight() % 2) + ReferenceRect.LowerRightCorner.Y += 1; + + if (!ReferenceRect.getWidth() || ReferenceRect.getWidth() % 2) + ReferenceRect.LowerRightCorner.X += 1; + } else + UseReferenceRect = false; + } + + //! Updates the internal cursor position + void updateInternalCursorPosition(int x, int y) + { + CursorPos.X = x; + CursorPos.Y = y; + } + + private: + core::position2d CursorPos; + core::dimension2d WindowSize; + core::dimension2d InvWindowSize; + core::rect ReferenceRect; + CIrrDeviceMacOSX *Device; + bool IsVisible; + bool UseReferenceRect; + }; + + bool createWindow(); + void initKeycodes(); + void storeMouseLocation(); + void postMouseEvent(void *event, irr::SEvent &ievent); + void postKeyEvent(void *event, irr::SEvent &ievent, bool pressed); + void pollJoysticks(); + + NSWindow *Window; + CGDirectDisplayID Display; + std::map KeyCodes; + int DeviceWidth; + int DeviceHeight; + int ScreenWidth; + int ScreenHeight; + u32 MouseButtonStates; + bool IsFullscreen; + bool IsActive; + bool IsShiftDown; + bool IsControlDown; + bool IsResizable; +}; + +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_OSX_DEVICE_ diff --git a/irr/src/CIrrDeviceOSX.mm b/irr/src/CIrrDeviceOSX.mm new file mode 100644 index 000000000..8e4843441 --- /dev/null +++ b/irr/src/CIrrDeviceOSX.mm @@ -0,0 +1,1470 @@ +// Copyright (C) 2005-2006 Etienne Petitjean +// Copyright (C) 2007-2012 Christian Stehno +// Copyright (C) 2013-2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ + +#import +#import + +#include "CIrrDeviceOSX.h" + +#include "IEventReceiver.h" +#include "os.h" +#include "CTimer.h" +#include "irrString.h" +#include "Keycodes.h" +#include +#include +#include "COSOperator.h" +#include "CColorConverter.h" +#include "irrlicht.h" +#include + +#include +#include + +#include "CNSOGLManager.h" + +#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + +#include +#include +#include +#include +#include + +struct JoystickComponent +{ + IOHIDElementCookie cookie; // unique value which identifies element, will NOT change + long min; // reported min value possible + long max; // reported max value possible + + long minRead; // min read value + long maxRead; // max read value + + JoystickComponent() : + min(0), minRead(0), max(0), maxRead(0) + { + } +}; + +struct JoystickInfo +{ + irr::core::array axisComp; + irr::core::array buttonComp; + irr::core::array hatComp; + + int hats; + int axes; + int buttons; + int numActiveJoysticks; + + irr::SEvent persistentData; + + IOHIDDeviceInterface **interface; + bool removed; + char joystickName[256]; + long usage; // usage page from IOUSBHID Parser.h which defines general usage + long usagePage; // usage within above page from IOUSBHID Parser.h which defines specific usage + + JoystickInfo() : + hats(0), axes(0), buttons(0), interface(0), removed(false), usage(0), usagePage(0), numActiveJoysticks(0) + { + interface = NULL; + memset(joystickName, '\0', 256); + axisComp.clear(); + buttonComp.clear(); + hatComp.clear(); + + persistentData.EventType = irr::EET_JOYSTICK_INPUT_EVENT; + persistentData.JoystickEvent.POV = 65535; + persistentData.JoystickEvent.ButtonStates = 0; + } +}; +irr::core::array ActiveJoysticks; + +// helper functions for init joystick +static IOReturn closeJoystickDevice(JoystickInfo *joyInfo) +{ + IOReturn result = kIOReturnSuccess; + if (joyInfo && joyInfo->interface) { + /* close the interface */ + result = (*(joyInfo->interface))->close(joyInfo->interface); + if (kIOReturnNotOpen == result) { + /* do nothing as device was not opened, thus can't be closed */ + } else if (kIOReturnSuccess != result) + irr::os::Printer::log("IOHIDDeviceInterface failed to close", irr::ELL_ERROR); + /* release the interface */ + result = (*(joyInfo->interface))->Release(joyInfo->interface); + if (kIOReturnSuccess != result) + irr::os::Printer::log("IOHIDDeviceInterface failed to release", irr::ELL_ERROR); + joyInfo->interface = NULL; + } + return result; +} + +static void addComponentInfo(CFTypeRef refElement, JoystickComponent *pComponent, int numActiveJoysticks) +{ + long number; + CFTypeRef refType; + + refType = CFDictionaryGetValue((CFDictionaryRef)refElement, CFSTR(kIOHIDElementCookieKey)); + if (refType && CFNumberGetValue((CFNumberRef)refType, kCFNumberLongType, &number)) + pComponent->cookie = (IOHIDElementCookie)number; + refType = CFDictionaryGetValue((CFDictionaryRef)refElement, CFSTR(kIOHIDElementMinKey)); + if (refType && CFNumberGetValue((CFNumberRef)refType, kCFNumberLongType, &number)) + pComponent->minRead = pComponent->min = number; + refType = CFDictionaryGetValue((CFDictionaryRef)refElement, CFSTR(kIOHIDElementMaxKey)); + if (refType && CFNumberGetValue((CFNumberRef)refType, kCFNumberLongType, &number)) + pComponent->maxRead = pComponent->max = number; +} + +static void getJoystickComponentArrayHandler(const void *value, void *parameter); + +static void addJoystickComponent(CFTypeRef refElement, JoystickInfo *joyInfo) +{ + long elementType, usagePage, usage; + CFTypeRef refElementType = CFDictionaryGetValue((CFDictionaryRef)refElement, CFSTR(kIOHIDElementTypeKey)); + CFTypeRef refUsagePage = CFDictionaryGetValue((CFDictionaryRef)refElement, CFSTR(kIOHIDElementUsagePageKey)); + CFTypeRef refUsage = CFDictionaryGetValue((CFDictionaryRef)refElement, CFSTR(kIOHIDElementUsageKey)); + + if ((refElementType) && (CFNumberGetValue((CFNumberRef)refElementType, kCFNumberLongType, &elementType))) { + /* look at types of interest */ + if ((elementType == kIOHIDElementTypeInput_Misc) || (elementType == kIOHIDElementTypeInput_Button) || + (elementType == kIOHIDElementTypeInput_Axis)) { + if (refUsagePage && CFNumberGetValue((CFNumberRef)refUsagePage, kCFNumberLongType, &usagePage) && + refUsage && CFNumberGetValue((CFNumberRef)refUsage, kCFNumberLongType, &usage)) { + switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */ + { + case kHIDPage_GenericDesktop: { + switch (usage) /* look at usage to determine function */ + { + case kHIDUsage_GD_X: + case kHIDUsage_GD_Y: + case kHIDUsage_GD_Z: + case kHIDUsage_GD_Rx: + case kHIDUsage_GD_Ry: + case kHIDUsage_GD_Rz: + case kHIDUsage_GD_Slider: + case kHIDUsage_GD_Dial: + case kHIDUsage_GD_Wheel: { + joyInfo->axes++; + JoystickComponent newComponent; + addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks); + joyInfo->axisComp.push_back(newComponent); + } break; + case kHIDUsage_GD_Hatswitch: { + joyInfo->hats++; + JoystickComponent newComponent; + addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks); + joyInfo->hatComp.push_back(newComponent); + } break; + } + } break; + case kHIDPage_Button: { + joyInfo->buttons++; + JoystickComponent newComponent; + addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks); + joyInfo->buttonComp.push_back(newComponent); + } break; + default: + break; + } + } + } else if (kIOHIDElementTypeCollection == elementType) { + // get elements + CFTypeRef refElementTop = CFDictionaryGetValue((CFMutableDictionaryRef)refElement, CFSTR(kIOHIDElementKey)); + if (refElementTop) { + CFTypeID type = CFGetTypeID(refElementTop); + if (type == CFArrayGetTypeID()) { + CFRange range = {0, CFArrayGetCount((CFArrayRef)refElementTop)}; + CFArrayApplyFunction((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, joyInfo); + } + } + } + } +} + +static void getJoystickComponentArrayHandler(const void *value, void *parameter) +{ + if (CFGetTypeID(value) == CFDictionaryGetTypeID()) + addJoystickComponent((CFTypeRef)value, (JoystickInfo *)parameter); +} + +static void joystickTopLevelElementHandler(const void *value, void *parameter) +{ + CFTypeRef refCF = 0; + if (CFGetTypeID(value) != CFDictionaryGetTypeID()) + return; + refCF = CFDictionaryGetValue((CFDictionaryRef)value, CFSTR(kIOHIDElementUsagePageKey)); + if (!CFNumberGetValue((CFNumberRef)refCF, kCFNumberLongType, &((JoystickInfo *)parameter)->usagePage)) + irr::os::Printer::log("CFNumberGetValue error retrieving JoystickInfo->usagePage", irr::ELL_ERROR); + refCF = CFDictionaryGetValue((CFDictionaryRef)value, CFSTR(kIOHIDElementUsageKey)); + if (!CFNumberGetValue((CFNumberRef)refCF, kCFNumberLongType, &((JoystickInfo *)parameter)->usage)) + irr::os::Printer::log("CFNumberGetValue error retrieving JoystickInfo->usage", irr::ELL_ERROR); +} + +static void getJoystickDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties, JoystickInfo *joyInfo) +{ + CFMutableDictionaryRef usbProperties = 0; + io_registry_entry_t parent1, parent2; + + /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also + * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties + */ + if ((KERN_SUCCESS == IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1)) && + (KERN_SUCCESS == IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) && + (KERN_SUCCESS == IORegistryEntryCreateCFProperties(parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) { + if (usbProperties) { + CFTypeRef refCF = 0; + /* get device info + * try hid dictionary first, if fail then go to usb dictionary + */ + + /* get joystickName name */ + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); + if (!refCF) + refCF = CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); + if (refCF) { + if (!CFStringGetCString((CFStringRef)refCF, joyInfo->joystickName, 256, CFStringGetSystemEncoding())) + irr::os::Printer::log("CFStringGetCString error getting joyInfo->joystickName", irr::ELL_ERROR); + } + + /* get usage page and usage */ + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); + if (refCF) { + if (!CFNumberGetValue((CFNumberRef)refCF, kCFNumberLongType, &joyInfo->usagePage)) + irr::os::Printer::log("CFNumberGetValue error getting joyInfo->usagePage", irr::ELL_ERROR); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); + if (refCF) + if (!CFNumberGetValue((CFNumberRef)refCF, kCFNumberLongType, &joyInfo->usage)) + irr::os::Printer::log("CFNumberGetValue error getting joyInfo->usage", irr::ELL_ERROR); + } + + if (NULL == refCF) /* get top level element HID usage page or usage */ + { + /* use top level element instead */ + CFTypeRef refCFTopElement = 0; + refCFTopElement = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDElementKey)); + { + /* refCFTopElement points to an array of element dictionaries */ + CFRange range = {0, CFArrayGetCount((CFArrayRef)refCFTopElement)}; + CFArrayApplyFunction((CFArrayRef)refCFTopElement, range, joystickTopLevelElementHandler, joyInfo); + } + } + + CFRelease(usbProperties); + } else + irr::os::Printer::log("IORegistryEntryCreateCFProperties failed to create usbProperties", irr::ELL_ERROR); + + if (kIOReturnSuccess != IOObjectRelease(parent2)) + irr::os::Printer::log("IOObjectRelease failed to release parent2", irr::ELL_ERROR); + if (kIOReturnSuccess != IOObjectRelease(parent1)) + irr::os::Printer::log("IOObjectRelease failed to release parent1", irr::ELL_ERROR); + } +} + +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + +// Contents from Events.h from Carbon/HIToolbox but we need it with Cocoa too +// and for some reason no Cocoa equivalent of these constants seems provided. +// So I'm doing like everyone else and using copy-and-paste. + +/* + * Summary: + * Virtual keycodes + * + * Discussion: + * These constants are the virtual keycodes defined originally in + * Inside Mac Volume V, pg. V-191. They identify physical keys on a + * keyboard. Those constants with "ANSI" in the name are labeled + * according to the key position on an ANSI-standard US keyboard. + * For example, kVK_ANSI_A indicates the virtual keycode for the key + * with the letter 'A' in the US keyboard layout. Other keyboard + * layouts may have the 'A' key label on a different physical key; + * in this case, pressing 'A' will generate a different virtual + * keycode. + */ +enum +{ + kVK_ANSI_A = 0x00, + kVK_ANSI_S = 0x01, + kVK_ANSI_D = 0x02, + kVK_ANSI_F = 0x03, + kVK_ANSI_H = 0x04, + kVK_ANSI_G = 0x05, + kVK_ANSI_Z = 0x06, + kVK_ANSI_X = 0x07, + kVK_ANSI_C = 0x08, + kVK_ANSI_V = 0x09, + kVK_ANSI_B = 0x0B, + kVK_ANSI_Q = 0x0C, + kVK_ANSI_W = 0x0D, + kVK_ANSI_E = 0x0E, + kVK_ANSI_R = 0x0F, + kVK_ANSI_Y = 0x10, + kVK_ANSI_T = 0x11, + kVK_ANSI_1 = 0x12, + kVK_ANSI_2 = 0x13, + kVK_ANSI_3 = 0x14, + kVK_ANSI_4 = 0x15, + kVK_ANSI_6 = 0x16, + kVK_ANSI_5 = 0x17, + kVK_ANSI_Equal = 0x18, + kVK_ANSI_9 = 0x19, + kVK_ANSI_7 = 0x1A, + kVK_ANSI_Minus = 0x1B, + kVK_ANSI_8 = 0x1C, + kVK_ANSI_0 = 0x1D, + kVK_ANSI_RightBracket = 0x1E, + kVK_ANSI_O = 0x1F, + kVK_ANSI_U = 0x20, + kVK_ANSI_LeftBracket = 0x21, + kVK_ANSI_I = 0x22, + kVK_ANSI_P = 0x23, + kVK_ANSI_L = 0x25, + kVK_ANSI_J = 0x26, + kVK_ANSI_Quote = 0x27, + kVK_ANSI_K = 0x28, + kVK_ANSI_Semicolon = 0x29, + kVK_ANSI_Backslash = 0x2A, + kVK_ANSI_Comma = 0x2B, + kVK_ANSI_Slash = 0x2C, + kVK_ANSI_N = 0x2D, + kVK_ANSI_M = 0x2E, + kVK_ANSI_Period = 0x2F, + kVK_ANSI_Grave = 0x32, + kVK_ANSI_KeypadDecimal = 0x41, + kVK_ANSI_KeypadMultiply = 0x43, + kVK_ANSI_KeypadPlus = 0x45, + kVK_ANSI_KeypadClear = 0x47, + kVK_ANSI_KeypadDivide = 0x4B, + kVK_ANSI_KeypadEnter = 0x4C, + kVK_ANSI_KeypadMinus = 0x4E, + kVK_ANSI_KeypadEquals = 0x51, + kVK_ANSI_Keypad0 = 0x52, + kVK_ANSI_Keypad1 = 0x53, + kVK_ANSI_Keypad2 = 0x54, + kVK_ANSI_Keypad3 = 0x55, + kVK_ANSI_Keypad4 = 0x56, + kVK_ANSI_Keypad5 = 0x57, + kVK_ANSI_Keypad6 = 0x58, + kVK_ANSI_Keypad7 = 0x59, + kVK_ANSI_Keypad8 = 0x5B, + kVK_ANSI_Keypad9 = 0x5C +}; + +/* keycodes for keys that are independent of keyboard layout*/ +enum +{ + kVK_Return = 0x24, + kVK_Tab = 0x30, + kVK_Space = 0x31, + kVK_Delete = 0x33, + kVK_Escape = 0x35, + kVK_Command = 0x37, + kVK_Shift = 0x38, + kVK_CapsLock = 0x39, + kVK_Option = 0x3A, + kVK_Control = 0x3B, + kVK_RightShift = 0x3C, + kVK_RightOption = 0x3D, + kVK_RightControl = 0x3E, + kVK_Function = 0x3F, + kVK_F17 = 0x40, + kVK_VolumeUp = 0x48, + kVK_VolumeDown = 0x49, + kVK_Mute = 0x4A, + kVK_F18 = 0x4F, + kVK_F19 = 0x50, + kVK_F20 = 0x5A, + kVK_F5 = 0x60, + kVK_F6 = 0x61, + kVK_F7 = 0x62, + kVK_F3 = 0x63, + kVK_F8 = 0x64, + kVK_F9 = 0x65, + kVK_F11 = 0x67, + kVK_F13 = 0x69, + kVK_F16 = 0x6A, + kVK_F14 = 0x6B, + kVK_F10 = 0x6D, + kVK_F12 = 0x6F, + kVK_F15 = 0x71, + kVK_Help = 0x72, + kVK_Home = 0x73, + kVK_PageUp = 0x74, + kVK_ForwardDelete = 0x75, + kVK_F4 = 0x76, + kVK_End = 0x77, + kVK_F2 = 0x78, + kVK_PageDown = 0x79, + kVK_F1 = 0x7A, + kVK_LeftArrow = 0x7B, + kVK_RightArrow = 0x7C, + kVK_DownArrow = 0x7D, + kVK_UpArrow = 0x7E +}; + +//------------------------------------------------------------------------------------------ +Boolean GetDictionaryBoolean(CFDictionaryRef theDict, const void *key) +{ + // get a boolean from the dictionary + Boolean value = false; + CFBooleanRef boolRef; + boolRef = (CFBooleanRef)CFDictionaryGetValue(theDict, key); + if (boolRef != NULL) + value = CFBooleanGetValue(boolRef); + return value; +} +//------------------------------------------------------------------------------------------ +long GetDictionaryLong(CFDictionaryRef theDict, const void *key) +{ + // get a long from the dictionary + long value = 0; + CFNumberRef numRef; + numRef = (CFNumberRef)CFDictionaryGetValue(theDict, key); + if (numRef != NULL) + CFNumberGetValue(numRef, kCFNumberLongType, &value); + return value; +} + +namespace irr +{ +namespace video +{ +IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶m, io::IFileSystem *io, IContextManager *contextManager); +} +} // end namespace irr + +static bool firstLaunch = true; + +@implementation CIrrDelegateOSX { + irr::CIrrDeviceMacOSX *Device; + bool Quit; +} + +- (id)initWithDevice:(irr::CIrrDeviceMacOSX *)device +{ + self = [super init]; + + if (self) + Device = device; + + Quit = false; + + return (self); +} + +- (void)applicationDidFinishLaunching:(NSNotification *)notification +{ + Quit = false; +} + +- (void)orderFrontStandardAboutPanel:(id)sender +{ + [NSApp orderFrontStandardAboutPanel:sender]; +} + +- (void)unhideAllApplications:(id)sender +{ + [NSApp unhideAllApplications:sender]; +} + +- (void)hide:(id)sender +{ + [NSApp hide:sender]; +} + +- (void)hideOtherApplications:(id)sender +{ + [NSApp hideOtherApplications:sender]; +} + +- (void)terminate:(id)sender +{ + Quit = true; +} + +- (void)windowWillClose:(id)sender +{ + Device->setWindow(nil); + Quit = true; +} + +- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize +{ + if (Device->isResizable()) + return proposedFrameSize; + else + return [window frame].size; +} + +- (void)windowDidResize:(NSNotification *)aNotification +{ + NSWindow *window; + NSRect frame; + + window = [aNotification object]; + frame = [window frame]; + Device->setResize((int)frame.size.width, (int)frame.size.height); +} + +- (BOOL)isQuit +{ + return (Quit); +} + +@end + +namespace irr +{ +//! constructor +CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters ¶m) : + CIrrDeviceStub(param), Window(NULL), Display(NULL), + DeviceWidth(0), DeviceHeight(0), + ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0), + IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false) +{ + struct utsname name; + +#ifdef _DEBUG + setDebugName("CIrrDeviceMacOSX"); +#endif + + if (firstLaunch) { + firstLaunch = false; + + if (!CreationParams.WindowId) { + [[NSAutoreleasePool alloc] init]; + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; + [[NSApplication sharedApplication] setDelegate:[[[CIrrDelegateOSX alloc] initWithDevice:this] autorelease]]; + + // Create menu + + NSString *bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; + if (bundleName == nil) + bundleName = @"Irrlicht"; + + NSMenu *mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease]; + NSMenu *menu = [[[NSMenu alloc] initWithTitle:bundleName] autorelease]; + NSMenuItem *menuItem = [mainMenu addItemWithTitle:bundleName action:nil keyEquivalent:@""]; + [mainMenu setSubmenu:menu forItem:menuItem]; + menuItem = [menu addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; + [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; + + [NSApp setMainMenu:mainMenu]; + + [NSApp finishLaunching]; + } + + NSString *path = [[NSBundle mainBundle] bundlePath]; + if (path != nil) { + path = [path stringByAppendingString:@"/Contents/Resources"]; + chdir([path fileSystemRepresentation]); + [path release]; + } + } + + uname(&name); + Operator = new COSOperator(name.version); + os::Printer::log(name.version, ELL_INFORMATION); + + initKeycodes(); + + bool success = true; + + if (CreationParams.DriverType != video::EDT_NULL) + success = createWindow(); + + // in case of failure, one can check VideoDriver for initialization + if (!success) + return; + + setResizable(false); + CursorControl = new CCursorControl(CreationParams.WindowSize, this); + + createDriver(); + createGUIAndScene(); +} + +CIrrDeviceMacOSX::~CIrrDeviceMacOSX() +{ + [NSApp setPresentationOptions:(NSApplicationPresentationDefault)]; + closeDevice(); +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + for (u32 joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { + if (ActiveJoysticks[joystick].interface) + closeJoystickDevice(&ActiveJoysticks[joystick]); + } +#endif +} + +void CIrrDeviceMacOSX::closeDevice() +{ + if (Window != nil) { + [Window setIsVisible:FALSE]; + [Window setReleasedWhenClosed:TRUE]; + [Window release]; + Window = nil; + } + + IsFullscreen = false; + IsActive = false; +} + +bool CIrrDeviceMacOSX::createWindow() +{ + CGDisplayErr error; + bool result = false; + Display = CGMainDisplayID(); + + CGRect displayRect; + CGDisplayModeRef displaymode, olddisplaymode; + + ScreenWidth = (int)CGDisplayPixelsWide(Display); + ScreenHeight = (int)CGDisplayPixelsHigh(Display); + + const NSBackingStoreType type = (CreationParams.DriverType == video::EDT_OPENGL) ? NSBackingStoreBuffered : NSBackingStoreNonretained; + + // TODO: fullscreen + // if (!CreationParams.Fullscreen) + { + if (!CreationParams.WindowId) { // create another window when WindowId is null + int x = (CreationParams.WindowPosition.X > 0) ? CreationParams.WindowPosition.X : 0; + int y = (CreationParams.WindowPosition.Y > 0) ? CreationParams.WindowPosition.Y : 0; + + if (CreationParams.WindowPosition.Y > -1) { + int screenHeight = [[[NSScreen screens] objectAtIndex:0] frame].size.height; + y = screenHeight - y - CreationParams.WindowSize.Height; + } + + Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(x, y, CreationParams.WindowSize.Width, CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask + NSClosableWindowMask + NSResizableWindowMask backing:type defer:FALSE]; + + if (CreationParams.WindowPosition.X == -1 && CreationParams.WindowPosition.Y == -1) + [Window center]; + } + + DeviceWidth = CreationParams.WindowSize.Width; + DeviceHeight = CreationParams.WindowSize.Height; + + result = true; + } + + if (result) { + if (Window) { + [Window setDelegate:(CIrrDelegateOSX *)[NSApp delegate]]; + [Window setAcceptsMouseMovedEvents:TRUE]; + [Window setIsVisible:TRUE]; + [Window makeKeyAndOrderFront:nil]; + } + } + + return result; +} + +void CIrrDeviceMacOSX::setResize(int width, int height) +{ + // set new window size + DeviceWidth = width; + DeviceHeight = height; + +#if defined(_IRR_COMPILE_WITH_OPENGL_) + // update the size of the opengl rendering context + if (CreationParams.DriverType == video::EDT_OPENGL) { + NSOpenGLContext *Context = (NSOpenGLContext *)ContextManager->getContext().OpenGLOSX.Context; + + if (Context) + [Context update]; + } +#endif + + // resize the driver to the inner pane size + if (Window) { + NSRect driverFrame = [Window contentRectForFrameRect:[Window frame]]; + getVideoDriver()->OnResize(core::dimension2d((s32)driverFrame.size.width, (s32)driverFrame.size.height)); + DeviceWidth = (s32)driverFrame.size.width; + DeviceHeight = (s32)driverFrame.size.height; + } else + getVideoDriver()->OnResize(core::dimension2d((s32)width, (s32)height)); +} + +void CIrrDeviceMacOSX::createDriver() +{ + switch (CreationParams.DriverType) { + case video::EDT_OPENGL: +#ifdef _IRR_COMPILE_WITH_OPENGL_ + { + video::SExposedVideoData data; + data.OpenGLOSX.Window = Window; + ContextManager = new video::CNSOGLManager(); + ContextManager->initialize(CreationParams, data); + VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); + if (!VideoDriver) { + os::Printer::log("Could not create OpenGL driver.", ELL_ERROR); + } + + if (Window) { + [[Window contentView] setWantsBestResolutionOpenGLSurface:NO]; + [(NSOpenGLContext *)ContextManager->getContext().OpenGLOSX.Context setView:[Window contentView]]; + } else { + [(NSView *)CreationParams.WindowId setWantsBestResolutionOpenGLSurface:NO]; + [(NSOpenGLContext *)ContextManager->getContext().OpenGLOSX.Context setView:(NSView *)CreationParams.WindowId]; + } + } +#else + os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); +#endif + break; + + case video::EDT_OGLES1: + case video::EDT_OGLES2: + os::Printer::log("This driver is not available in OSX. Try OpenGL or Software renderer.", ELL_ERROR); + break; + + case video::EDT_NULL: + VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); + break; + + default: + os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); + break; + } +} + +bool CIrrDeviceMacOSX::run() +{ + NSAutoreleasePool *Pool = [[NSAutoreleasePool alloc] init]; + + NSEvent *event; + irr::SEvent ievent; + + os::Timer::tick(); + storeMouseLocation(); + + event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; + if (event != nil) { + bzero(&ievent, sizeof(ievent)); + + switch ([(NSEvent *)event type]) { + case NSKeyDown: + postKeyEvent(event, ievent, true); + break; + + case NSKeyUp: + postKeyEvent(event, ievent, false); + break; + + case NSFlagsChanged: + ievent.EventType = irr::EET_KEY_INPUT_EVENT; + ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0; + ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0; + + if (IsShiftDown != ievent.KeyInput.Shift) { + ievent.KeyInput.Char = irr::KEY_SHIFT; + ievent.KeyInput.Key = irr::KEY_SHIFT; + ievent.KeyInput.PressedDown = ievent.KeyInput.Shift; + + IsShiftDown = ievent.KeyInput.Shift; + + postEventFromUser(ievent); + } + + if (IsControlDown != ievent.KeyInput.Control) { + ievent.KeyInput.Char = irr::KEY_CONTROL; + ievent.KeyInput.Key = irr::KEY_CONTROL; + ievent.KeyInput.PressedDown = ievent.KeyInput.Control; + + IsControlDown = ievent.KeyInput.Control; + + postEventFromUser(ievent); + } + + [NSApp sendEvent:event]; + break; + + case NSLeftMouseDown: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + ievent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN; + MouseButtonStates |= irr::EMBSM_LEFT; + ievent.MouseInput.ButtonStates = MouseButtonStates; + postMouseEvent(event, ievent); + break; + + case NSLeftMouseUp: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + MouseButtonStates &= !irr::EMBSM_LEFT; + ievent.MouseInput.ButtonStates = MouseButtonStates; + ievent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP; + postMouseEvent(event, ievent); + break; + + case NSOtherMouseDown: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + ievent.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN; + MouseButtonStates |= irr::EMBSM_MIDDLE; + ievent.MouseInput.ButtonStates = MouseButtonStates; + postMouseEvent(event, ievent); + break; + + case NSOtherMouseUp: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + MouseButtonStates &= !irr::EMBSM_MIDDLE; + ievent.MouseInput.ButtonStates = MouseButtonStates; + ievent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP; + postMouseEvent(event, ievent); + break; + + case NSMouseMoved: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; + ievent.MouseInput.ButtonStates = MouseButtonStates; + postMouseEvent(event, ievent); + break; + + case NSRightMouseDown: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + ievent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN; + MouseButtonStates |= irr::EMBSM_RIGHT; + ievent.MouseInput.ButtonStates = MouseButtonStates; + postMouseEvent(event, ievent); + break; + + case NSRightMouseUp: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + ievent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP; + MouseButtonStates &= !irr::EMBSM_RIGHT; + ievent.MouseInput.ButtonStates = MouseButtonStates; + postMouseEvent(event, ievent); + break; + + case NSScrollWheel: + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + ievent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL; + ievent.MouseInput.Wheel = [(NSEvent *)event deltaY]; + if (ievent.MouseInput.Wheel < 1.0f) + ievent.MouseInput.Wheel *= 10.0f; + else + ievent.MouseInput.Wheel *= 5.0f; + postMouseEvent(event, ievent); + break; + + default: + [NSApp sendEvent:event]; + break; + } + } + + pollJoysticks(); + + [Pool release]; + + return (![[NSApp delegate] isQuit] && IsActive); +} + +//! Pause the current process for the minimum time allowed only to allow other processes to execute +void CIrrDeviceMacOSX::yield() +{ + struct timespec ts = {0, 0}; + nanosleep(&ts, NULL); +} + +//! Pause execution and let other processes to run for a specified amount of time. +void CIrrDeviceMacOSX::sleep(u32 timeMs, bool pauseTimer = false) +{ + bool wasStopped = Timer ? Timer->isStopped() : true; + + struct timespec ts; + ts.tv_sec = (time_t)(timeMs / 1000); + ts.tv_nsec = (long)(timeMs % 1000) * 1000000; + + if (pauseTimer && !wasStopped) + Timer->stop(); + + nanosleep(&ts, NULL); + + if (pauseTimer && !wasStopped) + Timer->start(); +} + +void CIrrDeviceMacOSX::setWindowCaption(const wchar_t *text) +{ + if (Window != NULL) { + if (text) { + size_t numBytes = wcslen(text) * sizeof(wchar_t); + +#ifdef __BIG_ENDIAN__ + NSStringEncoding encode = sizeof(wchar_t) == 4 ? NSUTF32BigEndianStringEncoding : NSUTF16BigEndianStringEncoding; +#else + NSStringEncoding encode = sizeof(wchar_t) == 4 ? NSUTF32LittleEndianStringEncoding : NSUTF16LittleEndianStringEncoding; +#endif + NSString *name = [[NSString alloc] initWithBytes:text length:numBytes encoding:encode]; + if (name) { + [Window setTitle:name]; + [name release]; + } + } else { + [Window setTitle:@""]; + } + } +} + +bool CIrrDeviceMacOSX::isWindowActive() const +{ + return (IsActive); +} + +bool CIrrDeviceMacOSX::isWindowFocused() const +{ + if (Window != NULL) + return [Window isKeyWindow]; + return false; +} + +bool CIrrDeviceMacOSX::isWindowMinimized() const +{ + if (Window != NULL) + return [Window isMiniaturized]; + return false; +} + +void CIrrDeviceMacOSX::postKeyEvent(void *event, irr::SEvent &ievent, bool pressed) +{ + NSString *str; + std::map::const_iterator iter; + unsigned int c, mkey, mchar; + const unsigned char *cStr; + BOOL skipCommand; + + str = [(NSEvent *)event characters]; + if ((str != nil) && ([str length] > 0)) { + mkey = mchar = 0; + skipCommand = false; + c = [str characterAtIndex:0]; + mchar = c; + + iter = KeyCodes.find([(NSEvent *)event keyCode]); + if (iter != KeyCodes.end()) + mkey = (*iter).second; + else if ((iter = KeyCodes.find(c)) != KeyCodes.end()) + mkey = (*iter).second; + else { + // workaround for period character + if (c == 0x2E) { + mkey = irr::KEY_PERIOD; + mchar = '.'; + } else { + cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding]; + if (cStr != NULL && strlen((char *)cStr) > 0) { + mchar = cStr[0]; + mkey = toupper(mchar); + if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask) { + if (mkey == 'C' || mkey == 'V' || mkey == 'X') { + mchar = 0; + skipCommand = true; + } + } + } + } + } + + ievent.EventType = irr::EET_KEY_INPUT_EVENT; + ievent.KeyInput.Key = (irr::EKEY_CODE)mkey; + ievent.KeyInput.PressedDown = pressed; + ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0; + ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0; + ievent.KeyInput.Char = mchar; + + if (skipCommand) + ievent.KeyInput.Control = true; + else if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask) + [NSApp sendEvent:(NSEvent *)event]; + + postEventFromUser(ievent); + } +} + +void CIrrDeviceMacOSX::postMouseEvent(void *event, irr::SEvent &ievent) +{ + bool post = true; + + if (Window != NULL) { + ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x; + ievent.MouseInput.Y = DeviceHeight - (int)[(NSEvent *)event locationInWindow].y; + + if (ievent.MouseInput.Y < 0) + post = false; + } else { + CGEventRef ourEvent = CGEventCreate(NULL); + CGPoint point = CGEventGetLocation(ourEvent); + CFRelease(ourEvent); + + ievent.MouseInput.X = (int)point.x; + ievent.MouseInput.Y = (int)point.y; + + if (ievent.MouseInput.Y < 0) + post = false; + } + + if (post) { + ievent.MouseInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0; + ievent.MouseInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0; + + postEventFromUser(ievent); + } + + [NSApp sendEvent:(NSEvent *)event]; +} + +void CIrrDeviceMacOSX::storeMouseLocation() +{ + int x, y; + + if (Window != NULL) { + NSPoint p; + p = [NSEvent mouseLocation]; + p = [Window convertScreenToBase:p]; + x = (int)p.x; + y = DeviceHeight - (int)p.y; + } else { + // Do we still need this? + CGEventRef ourEvent = CGEventCreate(NULL); + CGPoint point = CGEventGetLocation(ourEvent); + CFRelease(ourEvent); + + x = (int)point.x; + y = (int)point.y; + + const core::position2di &curr = ((CCursorControl *)CursorControl)->getPosition(true); + if (curr.X != x || curr.Y != y) { + irr::SEvent ievent; + ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; + ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; + ievent.MouseInput.X = x; + ievent.MouseInput.Y = y; + postEventFromUser(ievent); + } + } + + ((CCursorControl *)CursorControl)->updateInternalCursorPosition(x, y); +} + +void CIrrDeviceMacOSX::setMouseLocation(int x, int y) +{ + NSPoint p; + CGPoint c; + + if (Window != NULL) { + // Irrlicht window exists + p.x = (float)x; + p.y = (float)(DeviceHeight - y); + p = [Window convertBaseToScreen:p]; + p.y = ScreenHeight - p.y; + } else { + p.x = (float)x; + p.y = (float)y + (ScreenHeight - DeviceHeight); + } + + c.x = p.x; + c.y = p.y; + + CGWarpMouseCursorPosition(c); + CGAssociateMouseAndMouseCursorPosition(YES); +} + +void CIrrDeviceMacOSX::setCursorVisible(bool visible) +{ + if (visible) + CGDisplayShowCursor(CGMainDisplayID()); + else + CGDisplayHideCursor(CGMainDisplayID()); +} + +void CIrrDeviceMacOSX::setWindow(NSWindow *window) +{ + Window = window; +} + +void CIrrDeviceMacOSX::initKeycodes() +{ + KeyCodes[kVK_UpArrow] = irr::KEY_UP; + KeyCodes[kVK_DownArrow] = irr::KEY_DOWN; + KeyCodes[kVK_LeftArrow] = irr::KEY_LEFT; + KeyCodes[kVK_RightArrow] = irr::KEY_RIGHT; + KeyCodes[kVK_F1] = irr::KEY_F1; + KeyCodes[kVK_F2] = irr::KEY_F2; + KeyCodes[kVK_F3] = irr::KEY_F3; + KeyCodes[kVK_F4] = irr::KEY_F4; + KeyCodes[kVK_F5] = irr::KEY_F5; + KeyCodes[kVK_F6] = irr::KEY_F6; + KeyCodes[kVK_F7] = irr::KEY_F7; + KeyCodes[kVK_F8] = irr::KEY_F8; + KeyCodes[kVK_F9] = irr::KEY_F9; + KeyCodes[kVK_F10] = irr::KEY_F10; + KeyCodes[kVK_F11] = irr::KEY_F11; + KeyCodes[kVK_F12] = irr::KEY_F12; + KeyCodes[kVK_F13] = irr::KEY_F13; + KeyCodes[kVK_F14] = irr::KEY_F14; + KeyCodes[kVK_F15] = irr::KEY_F15; + KeyCodes[kVK_F16] = irr::KEY_F16; + KeyCodes[kVK_F17] = irr::KEY_F17; + KeyCodes[kVK_F18] = irr::KEY_F18; + KeyCodes[kVK_F19] = irr::KEY_F19; + KeyCodes[kVK_F20] = irr::KEY_F20; + KeyCodes[kVK_Home] = irr::KEY_HOME; + KeyCodes[kVK_End] = irr::KEY_END; + KeyCodes[NSInsertFunctionKey] = irr::KEY_INSERT; + KeyCodes[kVK_ForwardDelete] = irr::KEY_DELETE; + KeyCodes[kVK_Help] = irr::KEY_HELP; + KeyCodes[NSSelectFunctionKey] = irr::KEY_SELECT; + KeyCodes[NSPrintFunctionKey] = irr::KEY_PRINT; + KeyCodes[NSExecuteFunctionKey] = irr::KEY_EXECUT; + KeyCodes[NSPrintScreenFunctionKey] = irr::KEY_SNAPSHOT; + KeyCodes[NSPauseFunctionKey] = irr::KEY_PAUSE; + KeyCodes[NSScrollLockFunctionKey] = irr::KEY_SCROLL; + KeyCodes[kVK_Delete] = irr::KEY_BACK; + KeyCodes[kVK_Tab] = irr::KEY_TAB; + KeyCodes[kVK_Return] = irr::KEY_RETURN; + KeyCodes[kVK_Escape] = irr::KEY_ESCAPE; + KeyCodes[kVK_Control] = irr::KEY_CONTROL; + KeyCodes[kVK_RightControl] = irr::KEY_RCONTROL; + KeyCodes[kVK_Command] = irr::KEY_MENU; + KeyCodes[kVK_Shift] = irr::KEY_SHIFT; + KeyCodes[kVK_RightShift] = irr::KEY_RSHIFT; + KeyCodes[kVK_Space] = irr::KEY_SPACE; + + KeyCodes[kVK_ANSI_A] = irr::KEY_KEY_A; + KeyCodes[kVK_ANSI_B] = irr::KEY_KEY_B; + KeyCodes[kVK_ANSI_C] = irr::KEY_KEY_C; + KeyCodes[kVK_ANSI_D] = irr::KEY_KEY_D; + KeyCodes[kVK_ANSI_E] = irr::KEY_KEY_E; + KeyCodes[kVK_ANSI_F] = irr::KEY_KEY_F; + KeyCodes[kVK_ANSI_G] = irr::KEY_KEY_G; + KeyCodes[kVK_ANSI_H] = irr::KEY_KEY_H; + KeyCodes[kVK_ANSI_I] = irr::KEY_KEY_I; + KeyCodes[kVK_ANSI_J] = irr::KEY_KEY_J; + KeyCodes[kVK_ANSI_K] = irr::KEY_KEY_K; + KeyCodes[kVK_ANSI_L] = irr::KEY_KEY_L; + KeyCodes[kVK_ANSI_M] = irr::KEY_KEY_M; + KeyCodes[kVK_ANSI_N] = irr::KEY_KEY_N; + KeyCodes[kVK_ANSI_O] = irr::KEY_KEY_O; + KeyCodes[kVK_ANSI_P] = irr::KEY_KEY_P; + KeyCodes[kVK_ANSI_Q] = irr::KEY_KEY_Q; + KeyCodes[kVK_ANSI_R] = irr::KEY_KEY_R; + KeyCodes[kVK_ANSI_S] = irr::KEY_KEY_S; + KeyCodes[kVK_ANSI_T] = irr::KEY_KEY_T; + KeyCodes[kVK_ANSI_U] = irr::KEY_KEY_U; + KeyCodes[kVK_ANSI_V] = irr::KEY_KEY_V; + KeyCodes[kVK_ANSI_W] = irr::KEY_KEY_W; + KeyCodes[kVK_ANSI_X] = irr::KEY_KEY_X; + KeyCodes[kVK_ANSI_X] = irr::KEY_KEY_X; + KeyCodes[kVK_ANSI_Y] = irr::KEY_KEY_Y; + KeyCodes[kVK_ANSI_Z] = irr::KEY_KEY_Z; + + KeyCodes[kVK_ANSI_0] = irr::KEY_KEY_0; + KeyCodes[kVK_ANSI_1] = irr::KEY_KEY_1; + KeyCodes[kVK_ANSI_2] = irr::KEY_KEY_2; + KeyCodes[kVK_ANSI_3] = irr::KEY_KEY_3; + KeyCodes[kVK_ANSI_4] = irr::KEY_KEY_4; + KeyCodes[kVK_ANSI_5] = irr::KEY_KEY_5; + KeyCodes[kVK_ANSI_6] = irr::KEY_KEY_6; + KeyCodes[kVK_ANSI_7] = irr::KEY_KEY_7; + KeyCodes[kVK_ANSI_8] = irr::KEY_KEY_8; + KeyCodes[kVK_ANSI_9] = irr::KEY_KEY_9; + + KeyCodes[kVK_ANSI_Slash] = irr::KEY_DIVIDE; + KeyCodes[kVK_ANSI_Comma] = irr::KEY_COMMA; + KeyCodes[kVK_ANSI_Period] = irr::KEY_PERIOD; + KeyCodes[kVK_PageUp] = irr::KEY_PRIOR; + KeyCodes[kVK_PageDown] = irr::KEY_NEXT; + + KeyCodes[kVK_ANSI_Keypad0] = irr::KEY_NUMPAD0; + KeyCodes[kVK_ANSI_Keypad1] = irr::KEY_NUMPAD1; + KeyCodes[kVK_ANSI_Keypad2] = irr::KEY_NUMPAD2; + KeyCodes[kVK_ANSI_Keypad3] = irr::KEY_NUMPAD3; + KeyCodes[kVK_ANSI_Keypad4] = irr::KEY_NUMPAD4; + KeyCodes[kVK_ANSI_Keypad5] = irr::KEY_NUMPAD5; + KeyCodes[kVK_ANSI_Keypad6] = irr::KEY_NUMPAD6; + KeyCodes[kVK_ANSI_Keypad7] = irr::KEY_NUMPAD7; + KeyCodes[kVK_ANSI_Keypad8] = irr::KEY_NUMPAD8; + KeyCodes[kVK_ANSI_Keypad9] = irr::KEY_NUMPAD9; + + KeyCodes[kVK_ANSI_KeypadDecimal] = irr::KEY_DECIMAL; + KeyCodes[kVK_ANSI_KeypadMultiply] = irr::KEY_MULTIPLY; + KeyCodes[kVK_ANSI_KeypadPlus] = irr::KEY_PLUS; + KeyCodes[kVK_ANSI_KeypadClear] = irr::KEY_OEM_CLEAR; + KeyCodes[kVK_ANSI_KeypadDivide] = irr::KEY_DIVIDE; + KeyCodes[kVK_ANSI_KeypadEnter] = irr::KEY_RETURN; + KeyCodes[kVK_ANSI_KeypadMinus] = irr::KEY_SUBTRACT; + + KeyCodes[kVK_ANSI_LeftBracket] = irr::KEY_OEM_4; + KeyCodes[kVK_ANSI_Backslash] = irr::KEY_OEM_5; + KeyCodes[kVK_ANSI_RightBracket] = irr::KEY_OEM_6; +} + +//! Sets if the window should be resizable in windowed mode. +void CIrrDeviceMacOSX::setResizable(bool resize) +{ + IsResizable = resize; +#if 0 + if (resize) + [Window setStyleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask]; + else + [Window setStyleMask:NSTitledWindowMask|NSClosableWindowMask]; +#endif +} + +bool CIrrDeviceMacOSX::isResizable() const +{ + return IsResizable; +} + +void CIrrDeviceMacOSX::minimizeWindow() +{ + if (Window != NULL) + [Window miniaturize:[NSApp self]]; +} + +//! Maximizes the window if possible. +void CIrrDeviceMacOSX::maximizeWindow() +{ + // todo: implement +} + +//! get the window to normal size if possible. +void CIrrDeviceMacOSX::restoreWindow() +{ + [Window deminiaturize:[NSApp self]]; +} + +//! Get the position of this window on screen +core::position2di CIrrDeviceMacOSX::getWindowPosition() +{ + NSRect rect = [Window frame]; + int screenHeight = [[[NSScreen screens] objectAtIndex:0] frame].size.height; + return core::position2di(rect.origin.x, screenHeight - rect.origin.y - rect.size.height); +} + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) +static void joystickRemovalCallback(void *target, + IOReturn result, void *refcon, void *sender) +{ + JoystickInfo *joy = (JoystickInfo *)refcon; + joy->removed = 1; +} +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + +bool CIrrDeviceMacOSX::activateJoysticks(core::array &joystickInfo) +{ +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + ActiveJoysticks.clear(); + joystickInfo.clear(); + + io_object_t hidObject = 0; + io_iterator_t hidIterator = 0; + IOReturn result = kIOReturnSuccess; + mach_port_t masterPort = 0; + CFMutableDictionaryRef hidDictionaryRef = NULL; + + result = IOMasterPort(bootstrap_port, &masterPort); + if (kIOReturnSuccess != result) { + os::Printer::log("initialiseJoysticks IOMasterPort failed", ELL_ERROR); + return false; + } + + hidDictionaryRef = IOServiceMatching(kIOHIDDeviceKey); + if (!hidDictionaryRef) { + os::Printer::log("initialiseJoysticks IOServiceMatching failed", ELL_ERROR); + return false; + } + result = IOServiceGetMatchingServices(masterPort, hidDictionaryRef, &hidIterator); + + if (kIOReturnSuccess != result) { + os::Printer::log("initialiseJoysticks IOServiceGetMatchingServices failed", ELL_ERROR); + return false; + } + + // no joysticks just return + if (!hidIterator) + return false; + + u32 jindex = 0u; + while ((hidObject = IOIteratorNext(hidIterator))) { + JoystickInfo info; + + // get dictionary for HID properties + CFMutableDictionaryRef hidProperties = 0; + + kern_return_t kern_result = IORegistryEntryCreateCFProperties(hidObject, &hidProperties, kCFAllocatorDefault, kNilOptions); + if ((kern_result == KERN_SUCCESS) && hidProperties) { + HRESULT plugInResult = S_OK; + SInt32 score = 0; + IOCFPlugInInterface **ppPlugInInterface = NULL; + result = IOCreatePlugInInterfaceForService(hidObject, kIOHIDDeviceUserClientTypeID, + kIOCFPlugInInterfaceID, &ppPlugInInterface, &score); + if (kIOReturnSuccess == result) { + plugInResult = (*ppPlugInInterface)->QueryInterface(ppPlugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void **)&(info.interface)); + if (plugInResult != S_OK) + os::Printer::log("initialiseJoysticks query HID class device interface failed", ELL_ERROR); + (*ppPlugInInterface)->Release(ppPlugInInterface); + } else + continue; + + if (info.interface != NULL) { + result = (*(info.interface))->open(info.interface, 0); + if (result == kIOReturnSuccess) { + (*(info.interface))->setRemovalCallback(info.interface, joystickRemovalCallback, &info, &info); + getJoystickDeviceInfo(hidObject, hidProperties, &info); + + // get elements + CFTypeRef refElementTop = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDElementKey)); + if (refElementTop) { + CFTypeID type = CFGetTypeID(refElementTop); + if (type == CFArrayGetTypeID()) { + CFRange range = {0, CFArrayGetCount((CFArrayRef)refElementTop)}; + info.numActiveJoysticks = ActiveJoysticks.size(); + CFArrayApplyFunction((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, &info); + } + } + } else { + CFRelease(hidProperties); + os::Printer::log("initialiseJoysticks Open interface failed", ELL_ERROR); + continue; + } + + CFRelease(hidProperties); + + result = IOObjectRelease(hidObject); + + if ((info.usagePage != kHIDPage_GenericDesktop) || + ((info.usage != kHIDUsage_GD_Joystick && + info.usage != kHIDUsage_GD_GamePad && + info.usage != kHIDUsage_GD_MultiAxisController))) { + closeJoystickDevice(&info); + continue; + } + + for (u32 i = 0; i < 6; ++i) + info.persistentData.JoystickEvent.Axis[i] = 0; + + ActiveJoysticks.push_back(info); + + SJoystickInfo returnInfo; + returnInfo.Joystick = jindex; + returnInfo.Axes = info.axes; + // returnInfo.Hats = info.hats; + returnInfo.Buttons = info.buttons; + returnInfo.Name = info.joystickName; + returnInfo.PovHat = SJoystickInfo::POV_HAT_UNKNOWN; + ++jindex; + + // if (info.hatComp.size()) + // returnInfo.PovHat = SJoystickInfo::POV_HAT_PRESENT; + // else + // returnInfo.PovHat = SJoystickInfo::POV_HAT_ABSENT; + + joystickInfo.push_back(returnInfo); + } + + } else { + continue; + } + } + result = IOObjectRelease(hidIterator); + + return true; +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + + return false; +} + +void CIrrDeviceMacOSX::pollJoysticks() +{ +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + if (0 == ActiveJoysticks.size()) + return; + + u32 joystick; + for (joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { + if (ActiveJoysticks[joystick].removed) + continue; + + bool found = false; + ActiveJoysticks[joystick].persistentData.JoystickEvent.Joystick = joystick; + + if (ActiveJoysticks[joystick].interface) { + for (u32 n = 0; n < ActiveJoysticks[joystick].axisComp.size(); n++) { + IOReturn result = kIOReturnSuccess; + IOHIDEventStruct hidEvent; + hidEvent.value = 0; + result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].axisComp[n].cookie, &hidEvent); + if (kIOReturnSuccess == result) { + const f32 min = -32768.0f; + const f32 max = 32767.0f; + const f32 deviceScale = max - min; + const f32 readScale = (f32)ActiveJoysticks[joystick].axisComp[n].maxRead - (f32)ActiveJoysticks[joystick].axisComp[n].minRead; + + if (hidEvent.value < ActiveJoysticks[joystick].axisComp[n].minRead) + ActiveJoysticks[joystick].axisComp[n].minRead = hidEvent.value; + if (hidEvent.value > ActiveJoysticks[joystick].axisComp[n].maxRead) + ActiveJoysticks[joystick].axisComp[n].maxRead = hidEvent.value; + + if (readScale != 0.0f) + hidEvent.value = (int)(((f32)((f32)hidEvent.value - (f32)ActiveJoysticks[joystick].axisComp[n].minRead) * deviceScale / readScale) + min); + + if (ActiveJoysticks[joystick].persistentData.JoystickEvent.Axis[n] != (s16)hidEvent.value) + found = true; + ActiveJoysticks[joystick].persistentData.JoystickEvent.Axis[n] = (s16)hidEvent.value; + } + } // axis check + + for (u32 n = 0; n < ActiveJoysticks[joystick].buttonComp.size(); n++) { + IOReturn result = kIOReturnSuccess; + IOHIDEventStruct hidEvent; + hidEvent.value = 0; + result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].buttonComp[n].cookie, &hidEvent); + if (kIOReturnSuccess == result) { + if (hidEvent.value && !((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false)) + found = true; + else if (!hidEvent.value && ((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false)) + found = true; + + if (hidEvent.value) + ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates |= (1 << n); + else + ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates &= ~(1 << n); + } + } // button check + // still ToDo..will be done soon :) + /* + for (u32 n = 0; n < ActiveJoysticks[joystick].hatComp.size(); n++) + { + IOReturn result = kIOReturnSuccess; + IOHIDEventStruct hidEvent; + hidEvent.value = 0; + result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].hatComp[n].cookie, &hidEvent); + if (kIOReturnSuccess == result) + { + if (ActiveJoysticks[joystick].persistentData.JoystickEvent.POV != hidEvent.value) + found = true; + ActiveJoysticks[joystick].persistentData.JoystickEvent.POV = hidEvent.value; + } + }//hat check + */ + } + + if (found) + postEventFromUser(ActiveJoysticks[joystick].persistentData); + } +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +} + +} // end namespace + +#endif // _IRR_COMPILE_WITH_OSX_DEVICE_ diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp new file mode 100644 index 000000000..17dc033d4 --- /dev/null +++ b/irr/src/CIrrDeviceSDL.cpp @@ -0,0 +1,1264 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + +#include "CIrrDeviceSDL.h" +#include "IEventReceiver.h" +#include "IGUIElement.h" +#include "IGUIEnvironment.h" +#include "IImageLoader.h" +#include "IFileSystem.h" +#include "os.h" +#include "CTimer.h" +#include "irrString.h" +#include "Keycodes.h" +#include "COSOperator.h" +#include +#include +#include "SIrrCreationParameters.h" +#include + +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ +#include +#endif + +#include "CSDLManager.h" + +static int SDLDeviceInstances = 0; + +namespace irr +{ +namespace video +{ +#ifdef _IRR_COMPILE_WITH_OPENGL_ +IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#else +static IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ + os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); + return nullptr; +} +#endif + +#ifdef ENABLE_OPENGL3 +IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#else +static IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ + os::Printer::log("No OpenGL 3 support compiled in.", ELL_ERROR); + return nullptr; +} +#endif + +#ifdef _IRR_COMPILE_WITH_OGLES2_ +IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#else +static IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ + os::Printer::log("No OpenGL ES 2 support compiled in.", ELL_ERROR); + return nullptr; +} +#endif + +#ifdef _IRR_COMPILE_WITH_WEBGL1_ +IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#else +static IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ + os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR); + return nullptr; +} +#endif +} // end namespace video + +} // end namespace irr + +namespace irr +{ +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ +EM_BOOL CIrrDeviceSDL::MouseUpDownCallback(int eventType, const EmscriptenMouseEvent *event, void *userData) +{ + // We need this callback so far only because otherwise "emscripten_request_pointerlock" calls will + // fail as their request are infinitely deferred. + // Not exactly certain why, maybe SDL does catch those mouse-events otherwise and not pass them on. + return EM_FALSE; +} + +EM_BOOL CIrrDeviceSDL::MouseEnterCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) +{ + CIrrDeviceSDL *This = static_cast(userData); + + SEvent irrevent; + + irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; + irrevent.MouseInput.Event = irr::EMIE_MOUSE_ENTER_CANVAS; + This->MouseX = irrevent.MouseInput.X = mouseEvent->canvasX; + This->MouseY = irrevent.MouseInput.Y = mouseEvent->canvasY; + This->MouseXRel = mouseEvent->movementX; // should be 0 I guess? Or can it enter while pointer is locked()? + This->MouseYRel = mouseEvent->movementY; + irrevent.MouseInput.ButtonStates = This->MouseButtonStates; // TODO: not correct, but couldn't figure out the bitset of mouseEvent->buttons yet. + irrevent.MouseInput.Shift = mouseEvent->shiftKey; + irrevent.MouseInput.Control = mouseEvent->ctrlKey; + + This->postEventFromUser(irrevent); + + return EM_FALSE; +} + +EM_BOOL CIrrDeviceSDL::MouseLeaveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) +{ + CIrrDeviceSDL *This = static_cast(userData); + + SEvent irrevent; + + irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; + irrevent.MouseInput.Event = irr::EMIE_MOUSE_LEAVE_CANVAS; + This->MouseX = irrevent.MouseInput.X = mouseEvent->canvasX; + This->MouseY = irrevent.MouseInput.Y = mouseEvent->canvasY; + This->MouseXRel = mouseEvent->movementX; // should be 0 I guess? Or can it enter while pointer is locked()? + This->MouseYRel = mouseEvent->movementY; + irrevent.MouseInput.ButtonStates = This->MouseButtonStates; // TODO: not correct, but couldn't figure out the bitset of mouseEvent->buttons yet. + irrevent.MouseInput.Shift = mouseEvent->shiftKey; + irrevent.MouseInput.Control = mouseEvent->ctrlKey; + + This->postEventFromUser(irrevent); + + return EM_FALSE; +} +#endif + +bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key) +{ + switch (key) { + // keys which are known to have safe special character interpretation + // could need changes over time (removals and additions!) + case KEY_RETURN: + case KEY_PAUSE: + case KEY_ESCAPE: + case KEY_PRIOR: + case KEY_NEXT: + case KEY_HOME: + case KEY_END: + case KEY_LEFT: + case KEY_UP: + case KEY_RIGHT: + case KEY_DOWN: + case KEY_TAB: + case KEY_PRINT: + case KEY_SNAPSHOT: + case KEY_INSERT: + case KEY_BACK: + case KEY_DELETE: + case KEY_HELP: + case KEY_APPS: + case KEY_SLEEP: + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + case KEY_F11: + case KEY_F12: + case KEY_F13: + case KEY_F14: + case KEY_F15: + case KEY_F16: + case KEY_F17: + case KEY_F18: + case KEY_F19: + case KEY_F20: + case KEY_F21: + case KEY_F22: + case KEY_F23: + case KEY_F24: + case KEY_NUMLOCK: + case KEY_SCROLL: + case KEY_LCONTROL: + case KEY_RCONTROL: + return true; + + default: + return false; + } +} + +int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key) +{ + // special cases that always return a char regardless of how the SDL keycode + // looks + switch (key) { + case KEY_RETURN: + case KEY_ESCAPE: + return (int)key; + default: + break; + } + + // SDL in-place ORs values with no character representation with 1<<30 + // https://wiki.libsdl.org/SDL2/SDLKeycodeLookup + if (assumedChar & (1 << 30)) + return 0; + + switch (key) { + case KEY_PRIOR: + case KEY_NEXT: + case KEY_HOME: + case KEY_END: + case KEY_LEFT: + case KEY_UP: + case KEY_RIGHT: + case KEY_DOWN: + case KEY_NUMLOCK: + return 0; + default: + return assumedChar; + } +} + +void CIrrDeviceSDL::resetReceiveTextInputEvents() +{ + gui::IGUIElement *elem = GUIEnvironment->getFocus(); + if (elem && elem->acceptsIME()) { + // IBus seems to have an issue where dead keys and compose keys do not + // work (specifically, the individual characters in the sequence are + // sent as text input events instead of the result) when + // SDL_StartTextInput() is called on the same input box. + core::rect pos = elem->getAbsolutePosition(); + if (!SDL_IsTextInputActive() || lastElemPos != pos) { + lastElemPos = pos; + SDL_Rect rect; + rect.x = pos.UpperLeftCorner.X; + rect.y = pos.UpperLeftCorner.Y; + rect.w = pos.getWidth(); + rect.h = pos.getHeight(); + SDL_SetTextInputRect(&rect); + SDL_StartTextInput(); + } + } else { + SDL_StopTextInput(); + } +} + +//! constructor +CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters ¶m) : + CIrrDeviceStub(param), + Window((SDL_Window *)param.WindowId), SDL_Flags(0), + MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0), + Width(param.WindowSize.Width), Height(param.WindowSize.Height), + Resizable(param.WindowResizable == 1 ? true : false), CurrentTouchCount(0) +{ +#ifdef _DEBUG + setDebugName("CIrrDeviceSDL"); +#endif + + if (++SDLDeviceInstances == 1) { + u32 flags = SDL_INIT_TIMER | SDL_INIT_EVENTS; + if (CreationParams.DriverType != video::EDT_NULL) + flags |= SDL_INIT_VIDEO; +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + flags |= SDL_INIT_JOYSTICK; +#endif + if (SDL_Init(flags) < 0) { + os::Printer::log("Unable to initialize SDL", SDL_GetError(), ELL_ERROR); + Close = true; + } else { + os::Printer::log("SDL initialized", ELL_INFORMATION); + } + } + + // Minetest has its own code to synthesize mouse events from touch events, + // so we prevent SDL from doing it. + SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0"); + SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0"); + + // create keymap + createKeyMap(); + + // create window + if (CreationParams.DriverType != video::EDT_NULL) { + if (!createWindow()) { + Close = true; + return; + } + } + + SDL_VERSION(&Info.version); + +#ifndef _IRR_EMSCRIPTEN_PLATFORM_ + SDL_GetWindowWMInfo(Window, &Info); +#endif //_IRR_EMSCRIPTEN_PLATFORM_ + core::stringc sdlversion = "SDL Version "; + sdlversion += Info.version.major; + sdlversion += "."; + sdlversion += Info.version.minor; + sdlversion += "."; + sdlversion += Info.version.patch; + + Operator = new COSOperator(sdlversion); + if (SDLDeviceInstances == 1) { + os::Printer::log(sdlversion.c_str(), ELL_INFORMATION); + } + + // create cursor control + CursorControl = new CCursorControl(this); + + // create driver + createDriver(); + + if (VideoDriver) { + createGUIAndScene(); + VideoDriver->OnResize(core::dimension2d(Width, Height)); + } +} + +//! destructor +CIrrDeviceSDL::~CIrrDeviceSDL() +{ + if (--SDLDeviceInstances == 0) { +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + const u32 numJoysticks = Joysticks.size(); + for (u32 i = 0; i < numJoysticks; ++i) + SDL_JoystickClose(Joysticks[i]); +#endif + if (Window) { + SDL_GL_MakeCurrent(Window, NULL); + SDL_GL_DeleteContext(Context); + SDL_DestroyWindow(Window); + } + SDL_Quit(); + + os::Printer::log("Quit SDL", ELL_INFORMATION); + } +} + +void CIrrDeviceSDL::logAttributes() +{ + core::stringc sdl_attr("SDL attribs:"); + int value = 0; + if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value) == 0) + sdl_attr += core::stringc(" r:") + core::stringc(value); + if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value) == 0) + sdl_attr += core::stringc(" g:") + core::stringc(value); + if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value) == 0) + sdl_attr += core::stringc(" b:") + core::stringc(value); + if (SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &value) == 0) + sdl_attr += core::stringc(" a:") + core::stringc(value); + + if (SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value) == 0) + sdl_attr += core::stringc(" depth:") + core::stringc(value); + if (SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &value) == 0) + sdl_attr += core::stringc(" stencil:") + core::stringc(value); + if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value) == 0) + sdl_attr += core::stringc(" doublebuf:") + core::stringc(value); + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value) == 0) + sdl_attr += core::stringc(" aa:") + core::stringc(value); + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value) == 0) + sdl_attr += core::stringc(" aa-samples:") + core::stringc(value); + + os::Printer::log(sdl_attr.c_str()); +} + +bool CIrrDeviceSDL::createWindow() +{ + if (CreationParams.Fullscreen) { +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + SDL_Flags |= SDL_WINDOW_FULLSCREEN; +#else + SDL_Flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; +#endif + } + if (Resizable) + SDL_Flags |= SDL_WINDOW_RESIZABLE; + if (CreationParams.WindowMaximized) + SDL_Flags |= SDL_WINDOW_MAXIMIZED; + SDL_Flags |= SDL_WINDOW_OPENGL; + +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + if (Width != 0 || Height != 0) + emscripten_set_canvas_size(Width, Height); + else { + int w, h, fs; + emscripten_get_canvas_size(&w, &h, &fs); + Width = w; + Height = h; + } + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0); + + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, CreationParams.Doublebuffer ? 1 : 0); + + if (CreationParams.AntiAlias > 1) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias); + } else { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + } + + SDL_CreateWindowAndRenderer(0, 0, SDL_Flags, &Window, &Renderer); // 0,0 will use the canvas size + + logAttributes(); + + // "#canvas" is for the opengl context + emscripten_set_mousedown_callback("#canvas", (void *)this, true, MouseUpDownCallback); + emscripten_set_mouseup_callback("#canvas", (void *)this, true, MouseUpDownCallback); + emscripten_set_mouseenter_callback("#canvas", (void *)this, false, MouseEnterCallback); + emscripten_set_mouseleave_callback("#canvas", (void *)this, false, MouseLeaveCallback); + + return true; +#else // !_IRR_EMSCRIPTEN_PLATFORM_ + if (Close) + return false; + + switch (CreationParams.DriverType) { + case video::EDT_OPENGL: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + break; + case video::EDT_OPENGL3: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + break; + case video::EDT_OGLES1: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + break; + case video::EDT_OGLES2: + case video::EDT_WEBGL1: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + break; + default:; + } + +#ifdef _DEBUG + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG); +#endif + + if (CreationParams.Bits == 16) { + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0); + } else { + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0); + } + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, CreationParams.Doublebuffer); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0); + SDL_GL_SetAttribute(SDL_GL_STEREO, CreationParams.Stereobuffer); + if (CreationParams.AntiAlias > 1) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias); + } + if (!Window) + Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); + if (!Window) { + os::Printer::log("Could not create window...", SDL_GetError(), ELL_WARNING); + } + if (!Window && CreationParams.AntiAlias > 1) { + while (--CreationParams.AntiAlias > 1) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias); + Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); + if (Window) + break; + } + if (!Window) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); + if (Window) + os::Printer::log("AntiAliasing disabled due to lack of support!", ELL_WARNING); + } + } + + if (!Window && CreationParams.Doublebuffer) { + // Try single buffer + if (CreationParams.DriverType == video::EDT_OPENGL) + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); + } + if (!Window) { + os::Printer::log("Could not initialize display", SDL_GetError(), ELL_ERROR); + return false; + } + + Context = SDL_GL_CreateContext(Window); + if (!Context) { + os::Printer::log("Could not initialize context", SDL_GetError(), ELL_ERROR); + SDL_DestroyWindow(Window); + return false; + } + + return true; +#endif // !_IRR_EMSCRIPTEN_PLATFORM_ +} + +//! create the driver +void CIrrDeviceSDL::createDriver() +{ + if (CreationParams.DriverType == video::EDT_NULL) { + VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); + return; + } + + ContextManager = new video::CSDLManager(this); + switch (CreationParams.DriverType) { + case video::EDT_OPENGL: + VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); + break; + case video::EDT_OPENGL3: + VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); + break; + case video::EDT_OGLES2: + VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); + break; + case video::EDT_WEBGL1: + VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); + break; + default:; + } + if (!VideoDriver) + os::Printer::log("Could not create video driver", ELL_ERROR); +} + +//! runs the device. Returns false if device wants to be deleted +bool CIrrDeviceSDL::run() +{ + os::Timer::tick(); + + SEvent irrevent; + SDL_Event SDL_event; + + while (!Close && SDL_PollEvent(&SDL_event)) { + // os::Printer::log("event: ", core::stringc((int)SDL_event.type).c_str(), ELL_INFORMATION); // just for debugging + + switch (SDL_event.type) { + case SDL_MOUSEMOTION: { + SDL_Keymod keymod = SDL_GetModState(); + + irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; + irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; + MouseX = irrevent.MouseInput.X = SDL_event.motion.x; + MouseY = irrevent.MouseInput.Y = SDL_event.motion.y; + MouseXRel = SDL_event.motion.xrel; + MouseYRel = SDL_event.motion.yrel; + irrevent.MouseInput.ButtonStates = MouseButtonStates; + irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0; + irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0; + + postEventFromUser(irrevent); + break; + } + case SDL_MOUSEWHEEL: { + SDL_Keymod keymod = SDL_GetModState(); + + irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; + irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL; +#if SDL_VERSION_ATLEAST(2, 0, 18) + irrevent.MouseInput.Wheel = SDL_event.wheel.preciseY; +#else + irrevent.MouseInput.Wheel = SDL_event.wheel.y; +#endif + irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0; + irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0; + irrevent.MouseInput.X = MouseX; + irrevent.MouseInput.Y = MouseY; + + postEventFromUser(irrevent); + break; + } + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: { + SDL_Keymod keymod = SDL_GetModState(); + + irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; + irrevent.MouseInput.X = SDL_event.button.x; + irrevent.MouseInput.Y = SDL_event.button.y; + irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0; + irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0; + + irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; + +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + // Handle mouselocking in emscripten in Windowed mode. + // In fullscreen SDL will handle it. + // The behavior we want windowed is - when the canvas was clicked then + // we will lock the mouse-pointer if it should be invisible. + // For security reasons this will be delayed until the next mouse-up event. + // We do not pass on this event as we don't want the activation click to do anything. + if (SDL_event.type == SDL_MOUSEBUTTONDOWN && !isFullscreen()) { + EmscriptenPointerlockChangeEvent pointerlockStatus; // let's hope that test is not expensive ... + if (emscripten_get_pointerlock_status(&pointerlockStatus) == EMSCRIPTEN_RESULT_SUCCESS) { + if (CursorControl->isVisible() && pointerlockStatus.isActive) { + emscripten_exit_pointerlock(); + return !Close; + } else if (!CursorControl->isVisible() && !pointerlockStatus.isActive) { + emscripten_request_pointerlock(0, true); + return !Close; + } + } + } +#endif + + switch (SDL_event.button.button) { + case SDL_BUTTON_LEFT: + if (SDL_event.type == SDL_MOUSEBUTTONDOWN) { + irrevent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN; + MouseButtonStates |= irr::EMBSM_LEFT; + } else { + irrevent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP; + MouseButtonStates &= ~irr::EMBSM_LEFT; + } + break; + + case SDL_BUTTON_RIGHT: + if (SDL_event.type == SDL_MOUSEBUTTONDOWN) { + irrevent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN; + MouseButtonStates |= irr::EMBSM_RIGHT; + } else { + irrevent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP; + MouseButtonStates &= ~irr::EMBSM_RIGHT; + } + break; + + case SDL_BUTTON_MIDDLE: + if (SDL_event.type == SDL_MOUSEBUTTONDOWN) { + irrevent.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN; + MouseButtonStates |= irr::EMBSM_MIDDLE; + } else { + irrevent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP; + MouseButtonStates &= ~irr::EMBSM_MIDDLE; + } + break; + } + + irrevent.MouseInput.ButtonStates = MouseButtonStates; + + if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED) { + postEventFromUser(irrevent); + + if (irrevent.MouseInput.Event >= EMIE_LMOUSE_PRESSED_DOWN && irrevent.MouseInput.Event <= EMIE_MMOUSE_PRESSED_DOWN) { + u32 clicks = checkSuccessiveClicks(irrevent.MouseInput.X, irrevent.MouseInput.Y, irrevent.MouseInput.Event); + if (clicks == 2) { + irrevent.MouseInput.Event = (EMOUSE_INPUT_EVENT)(EMIE_LMOUSE_DOUBLE_CLICK + irrevent.MouseInput.Event - EMIE_LMOUSE_PRESSED_DOWN); + postEventFromUser(irrevent); + } else if (clicks == 3) { + irrevent.MouseInput.Event = (EMOUSE_INPUT_EVENT)(EMIE_LMOUSE_TRIPLE_CLICK + irrevent.MouseInput.Event - EMIE_LMOUSE_PRESSED_DOWN); + postEventFromUser(irrevent); + } + } + } + break; + } + + case SDL_TEXTINPUT: { + irrevent.EventType = irr::EET_STRING_INPUT_EVENT; + irrevent.StringInput.Str = new core::stringw(); + irr::core::utf8ToWString(*irrevent.StringInput.Str, SDL_event.text.text); + postEventFromUser(irrevent); + delete irrevent.StringInput.Str; + irrevent.StringInput.Str = NULL; + } break; + + case SDL_KEYDOWN: + case SDL_KEYUP: { + SKeyMap mp; + mp.SDLKey = SDL_event.key.keysym.sym; + s32 idx = KeyMap.binary_search(mp); + + EKEY_CODE key; + if (idx == -1) + key = (EKEY_CODE)0; + else + key = (EKEY_CODE)KeyMap[idx].Win32Key; + + if (key == (EKEY_CODE)0) + os::Printer::log("keycode not mapped", core::stringc(mp.SDLKey), ELL_DEBUG); + + // Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already + if (SDL_IsTextInputActive() && !keyIsKnownSpecial(key) && (SDL_event.key.keysym.mod & KMOD_CTRL) == 0) + break; + + irrevent.EventType = irr::EET_KEY_INPUT_EVENT; + irrevent.KeyInput.Key = key; + irrevent.KeyInput.PressedDown = (SDL_event.type == SDL_KEYDOWN); + irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0; + irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0; + irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key); + postEventFromUser(irrevent); + } break; + + case SDL_QUIT: + Close = true; + break; + + case SDL_WINDOWEVENT: + switch (SDL_event.window.event) { + case SDL_WINDOWEVENT_RESIZED: + if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height)) { + Width = SDL_event.window.data1; + Height = SDL_event.window.data2; + if (VideoDriver) + VideoDriver->OnResize(core::dimension2d(Width, Height)); + } + break; + } + + case SDL_USEREVENT: + irrevent.EventType = irr::EET_USER_EVENT; + irrevent.UserEvent.UserData1 = reinterpret_cast(SDL_event.user.data1); + irrevent.UserEvent.UserData2 = reinterpret_cast(SDL_event.user.data2); + + postEventFromUser(irrevent); + break; + + case SDL_FINGERDOWN: + irrevent.EventType = EET_TOUCH_INPUT_EVENT; + irrevent.TouchInput.Event = ETIE_PRESSED_DOWN; + irrevent.TouchInput.ID = SDL_event.tfinger.fingerId; + irrevent.TouchInput.X = SDL_event.tfinger.x * Width; + irrevent.TouchInput.Y = SDL_event.tfinger.y * Height; + CurrentTouchCount++; + irrevent.TouchInput.touchedCount = CurrentTouchCount; + + postEventFromUser(irrevent); + break; + + case SDL_FINGERMOTION: + irrevent.EventType = EET_TOUCH_INPUT_EVENT; + irrevent.TouchInput.Event = ETIE_MOVED; + irrevent.TouchInput.ID = SDL_event.tfinger.fingerId; + irrevent.TouchInput.X = SDL_event.tfinger.x * Width; + irrevent.TouchInput.Y = SDL_event.tfinger.y * Height; + irrevent.TouchInput.touchedCount = CurrentTouchCount; + + postEventFromUser(irrevent); + break; + + case SDL_FINGERUP: + irrevent.EventType = EET_TOUCH_INPUT_EVENT; + irrevent.TouchInput.Event = ETIE_LEFT_UP; + irrevent.TouchInput.ID = SDL_event.tfinger.fingerId; + irrevent.TouchInput.X = SDL_event.tfinger.x * Width; + irrevent.TouchInput.Y = SDL_event.tfinger.y * Height; + // To match Android behavior, still count the pointer that was + // just released. + irrevent.TouchInput.touchedCount = CurrentTouchCount; + if (CurrentTouchCount > 0) { + CurrentTouchCount--; + } + + postEventFromUser(irrevent); + break; + + default: + break; + } // end switch + resetReceiveTextInputEvents(); + } // end while + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + // TODO: Check if the multiple open/close calls are too expensive, then + // open/close in the constructor/destructor instead + + // update joystick states manually + SDL_JoystickUpdate(); + // we'll always send joystick input events... + SEvent joyevent; + joyevent.EventType = EET_JOYSTICK_INPUT_EVENT; + for (u32 i = 0; i < Joysticks.size(); ++i) { + SDL_Joystick *joystick = Joysticks[i]; + if (joystick) { + int j; + // query all buttons + const int numButtons = core::min_(SDL_JoystickNumButtons(joystick), 32); + joyevent.JoystickEvent.ButtonStates = 0; + for (j = 0; j < numButtons; ++j) + joyevent.JoystickEvent.ButtonStates |= (SDL_JoystickGetButton(joystick, j) << j); + + // query all axes, already in correct range + const int numAxes = core::min_(SDL_JoystickNumAxes(joystick), (int)SEvent::SJoystickEvent::NUMBER_OF_AXES); + joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_X] = 0; + joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Y] = 0; + joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Z] = 0; + joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_R] = 0; + joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_U] = 0; + joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_V] = 0; + for (j = 0; j < numAxes; ++j) + joyevent.JoystickEvent.Axis[j] = SDL_JoystickGetAxis(joystick, j); + + // we can only query one hat, SDL only supports 8 directions + if (SDL_JoystickNumHats(joystick) > 0) { + switch (SDL_JoystickGetHat(joystick, 0)) { + case SDL_HAT_UP: + joyevent.JoystickEvent.POV = 0; + break; + case SDL_HAT_RIGHTUP: + joyevent.JoystickEvent.POV = 4500; + break; + case SDL_HAT_RIGHT: + joyevent.JoystickEvent.POV = 9000; + break; + case SDL_HAT_RIGHTDOWN: + joyevent.JoystickEvent.POV = 13500; + break; + case SDL_HAT_DOWN: + joyevent.JoystickEvent.POV = 18000; + break; + case SDL_HAT_LEFTDOWN: + joyevent.JoystickEvent.POV = 22500; + break; + case SDL_HAT_LEFT: + joyevent.JoystickEvent.POV = 27000; + break; + case SDL_HAT_LEFTUP: + joyevent.JoystickEvent.POV = 31500; + break; + case SDL_HAT_CENTERED: + default: + joyevent.JoystickEvent.POV = 65535; + break; + } + } else { + joyevent.JoystickEvent.POV = 65535; + } + + // we map the number directly + joyevent.JoystickEvent.Joystick = static_cast(i); + // now post the event + postEventFromUser(joyevent); + // and close the joystick + } + } +#endif + return !Close; +} + +//! Activate any joysticks, and generate events for them. +bool CIrrDeviceSDL::activateJoysticks(core::array &joystickInfo) +{ +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + joystickInfo.clear(); + + // we can name up to 256 different joysticks + const int numJoysticks = core::min_(SDL_NumJoysticks(), 256); + Joysticks.reallocate(numJoysticks); + joystickInfo.reallocate(numJoysticks); + + int joystick = 0; + for (; joystick < numJoysticks; ++joystick) { + Joysticks.push_back(SDL_JoystickOpen(joystick)); + SJoystickInfo info; + + info.Joystick = joystick; + info.Axes = SDL_JoystickNumAxes(Joysticks[joystick]); + info.Buttons = SDL_JoystickNumButtons(Joysticks[joystick]); + info.Name = SDL_JoystickName(Joysticks[joystick]); + info.PovHat = (SDL_JoystickNumHats(Joysticks[joystick]) > 0) + ? SJoystickInfo::POV_HAT_PRESENT + : SJoystickInfo::POV_HAT_ABSENT; + + joystickInfo.push_back(info); + } + + for (joystick = 0; joystick < (int)joystickInfo.size(); ++joystick) { + char logString[256]; + snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'", + joystick, joystickInfo[joystick].Axes, + joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); + os::Printer::log(logString, ELL_INFORMATION); + } + + return true; + +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + + return false; +} + +//! Get the display density in dots per inch. +float CIrrDeviceSDL::getDisplayDensity() const +{ + if (!Window) + return 0.0f; + + int window_w; + int window_h; + SDL_GetWindowSize(Window, &window_w, &window_h); + + int drawable_w; + int drawable_h; + SDL_GL_GetDrawableSize(Window, &drawable_w, &drawable_h); + + // assume 96 dpi + float dpi_w = (float)drawable_w / (float)window_w * 96.0f; + float dpi_h = (float)drawable_h / (float)window_h * 96.0f; + + return std::max(dpi_w, dpi_h); +} + +void CIrrDeviceSDL::SwapWindow() +{ + SDL_GL_SwapWindow(Window); +} + +//! pause execution temporarily +void CIrrDeviceSDL::yield() +{ + SDL_Delay(0); +} + +//! pause execution for a specified time +void CIrrDeviceSDL::sleep(u32 timeMs, bool pauseTimer) +{ + const bool wasStopped = Timer ? Timer->isStopped() : true; + if (pauseTimer && !wasStopped) + Timer->stop(); + + SDL_Delay(timeMs); + + if (pauseTimer && !wasStopped) + Timer->start(); +} + +//! sets the caption of the window +void CIrrDeviceSDL::setWindowCaption(const wchar_t *text) +{ + core::stringc textc; + core::wStringToUTF8(textc, text); + SDL_SetWindowTitle(Window, textc.c_str()); +} + +//! Sets the window icon. +bool CIrrDeviceSDL::setWindowIcon(const video::IImage *img) +{ + if (!Window) + return false; + + u32 height = img->getDimension().Height; + u32 width = img->getDimension().Width; + + SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 32, + 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); + + if (!surface) { + os::Printer::log("Failed to create SDL suface", ELL_ERROR); + return false; + } + + SDL_LockSurface(surface); + bool succ = img->copyToNoScaling(surface->pixels, width, height, video::ECF_A8R8G8B8, surface->pitch); + SDL_UnlockSurface(surface); + + if (!succ) { + os::Printer::log("Could not copy icon image. Is the format not ECF_A8R8G8B8?", ELL_ERROR); + SDL_FreeSurface(surface); + return false; + } + + SDL_SetWindowIcon(Window, surface); + + SDL_FreeSurface(surface); + + return true; +} + +//! notifies the device that it should close itself +void CIrrDeviceSDL::closeDevice() +{ + Close = true; +} + +//! Sets if the window should be resizable in windowed mode. +void CIrrDeviceSDL::setResizable(bool resize) +{ +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + os::Printer::log("Resizable not available on the web.", ELL_WARNING); + return; +#else // !_IRR_EMSCRIPTEN_PLATFORM_ + if (resize != Resizable) { + if (resize) + SDL_Flags |= SDL_WINDOW_RESIZABLE; + else + SDL_Flags &= ~SDL_WINDOW_RESIZABLE; + + if (Window) { + SDL_SetWindowResizable(Window, (SDL_bool)resize); + } + Resizable = resize; + } +#endif // !_IRR_EMSCRIPTEN_PLATFORM_ +} + +//! Minimizes window if possible +void CIrrDeviceSDL::minimizeWindow() +{ + if (Window) + SDL_MinimizeWindow(Window); +} + +//! Maximize window +void CIrrDeviceSDL::maximizeWindow() +{ + if (Window) + SDL_MaximizeWindow(Window); +} + +//! Get the position of this window on screen +core::position2di CIrrDeviceSDL::getWindowPosition() +{ + return core::position2di(-1, -1); +} + +//! Restore original window size +void CIrrDeviceSDL::restoreWindow() +{ + if (Window) + SDL_RestoreWindow(Window); +} + +bool CIrrDeviceSDL::isWindowMaximized() const +{ + return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MAXIMIZED) != 0; +} + +bool CIrrDeviceSDL::isFullscreen() const +{ +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + return SDL_GetWindowFlags(0) == SDL_WINDOW_FULLSCREEN; +#else + + return CIrrDeviceStub::isFullscreen(); +#endif +} + +//! returns if window is active. if not, nothing need to be drawn +bool CIrrDeviceSDL::isWindowActive() const +{ +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + // Hidden test only does something in some browsers (when tab in background or window is minimized) + // In other browsers code automatically doesn't seem to be called anymore. + EmscriptenVisibilityChangeEvent emVisibility; + if (emscripten_get_visibility_status(&emVisibility) == EMSCRIPTEN_RESULT_SUCCESS) { + if (emVisibility.hidden) + return false; + } +#endif + const u32 windowFlags = SDL_GetWindowFlags(Window); + return windowFlags & SDL_WINDOW_SHOWN && windowFlags & SDL_WINDOW_INPUT_FOCUS; +} + +//! returns if window has focus. +bool CIrrDeviceSDL::isWindowFocused() const +{ + return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS) != 0; +} + +//! returns if window is minimized. +bool CIrrDeviceSDL::isWindowMinimized() const +{ + return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MINIMIZED) != 0; +} + +//! returns color format of the window. +video::ECOLOR_FORMAT CIrrDeviceSDL::getColorFormat() const +{ + if (Window) { + SDL_Surface *surface = SDL_GetWindowSurface(Window); + if (surface->format->BitsPerPixel == 16) { + if (surface->format->Amask != 0) + return video::ECF_A1R5G5B5; + else + return video::ECF_R5G6B5; + } else { + if (surface->format->Amask != 0) + return video::ECF_A8R8G8B8; + else + return video::ECF_R8G8B8; + } + } else + return CIrrDeviceStub::getColorFormat(); +} + +void CIrrDeviceSDL::createKeyMap() +{ + // I don't know if this is the best method to create + // the lookuptable, but I'll leave it like that until + // I find a better version. + + KeyMap.reallocate(105); + + // buttons missing + + KeyMap.push_back(SKeyMap(SDLK_BACKSPACE, KEY_BACK)); + KeyMap.push_back(SKeyMap(SDLK_TAB, KEY_TAB)); + KeyMap.push_back(SKeyMap(SDLK_CLEAR, KEY_CLEAR)); + KeyMap.push_back(SKeyMap(SDLK_RETURN, KEY_RETURN)); + + // combined modifiers missing + + KeyMap.push_back(SKeyMap(SDLK_PAUSE, KEY_PAUSE)); + KeyMap.push_back(SKeyMap(SDLK_CAPSLOCK, KEY_CAPITAL)); + + // asian letter keys missing + + KeyMap.push_back(SKeyMap(SDLK_ESCAPE, KEY_ESCAPE)); + + // asian letter keys missing + + KeyMap.push_back(SKeyMap(SDLK_SPACE, KEY_SPACE)); + KeyMap.push_back(SKeyMap(SDLK_PAGEUP, KEY_PRIOR)); + KeyMap.push_back(SKeyMap(SDLK_PAGEDOWN, KEY_NEXT)); + KeyMap.push_back(SKeyMap(SDLK_END, KEY_END)); + KeyMap.push_back(SKeyMap(SDLK_HOME, KEY_HOME)); + KeyMap.push_back(SKeyMap(SDLK_LEFT, KEY_LEFT)); + KeyMap.push_back(SKeyMap(SDLK_UP, KEY_UP)); + KeyMap.push_back(SKeyMap(SDLK_RIGHT, KEY_RIGHT)); + KeyMap.push_back(SKeyMap(SDLK_DOWN, KEY_DOWN)); + + // select missing + KeyMap.push_back(SKeyMap(SDLK_PRINTSCREEN, KEY_PRINT)); + // execute missing + KeyMap.push_back(SKeyMap(SDLK_PRINTSCREEN, KEY_SNAPSHOT)); + + KeyMap.push_back(SKeyMap(SDLK_INSERT, KEY_INSERT)); + KeyMap.push_back(SKeyMap(SDLK_DELETE, KEY_DELETE)); + KeyMap.push_back(SKeyMap(SDLK_HELP, KEY_HELP)); + + KeyMap.push_back(SKeyMap(SDLK_0, KEY_KEY_0)); + KeyMap.push_back(SKeyMap(SDLK_1, KEY_KEY_1)); + KeyMap.push_back(SKeyMap(SDLK_2, KEY_KEY_2)); + KeyMap.push_back(SKeyMap(SDLK_3, KEY_KEY_3)); + KeyMap.push_back(SKeyMap(SDLK_4, KEY_KEY_4)); + KeyMap.push_back(SKeyMap(SDLK_5, KEY_KEY_5)); + KeyMap.push_back(SKeyMap(SDLK_6, KEY_KEY_6)); + KeyMap.push_back(SKeyMap(SDLK_7, KEY_KEY_7)); + KeyMap.push_back(SKeyMap(SDLK_8, KEY_KEY_8)); + KeyMap.push_back(SKeyMap(SDLK_9, KEY_KEY_9)); + + KeyMap.push_back(SKeyMap(SDLK_a, KEY_KEY_A)); + KeyMap.push_back(SKeyMap(SDLK_b, KEY_KEY_B)); + KeyMap.push_back(SKeyMap(SDLK_c, KEY_KEY_C)); + KeyMap.push_back(SKeyMap(SDLK_d, KEY_KEY_D)); + KeyMap.push_back(SKeyMap(SDLK_e, KEY_KEY_E)); + KeyMap.push_back(SKeyMap(SDLK_f, KEY_KEY_F)); + KeyMap.push_back(SKeyMap(SDLK_g, KEY_KEY_G)); + KeyMap.push_back(SKeyMap(SDLK_h, KEY_KEY_H)); + KeyMap.push_back(SKeyMap(SDLK_i, KEY_KEY_I)); + KeyMap.push_back(SKeyMap(SDLK_j, KEY_KEY_J)); + KeyMap.push_back(SKeyMap(SDLK_k, KEY_KEY_K)); + KeyMap.push_back(SKeyMap(SDLK_l, KEY_KEY_L)); + KeyMap.push_back(SKeyMap(SDLK_m, KEY_KEY_M)); + KeyMap.push_back(SKeyMap(SDLK_n, KEY_KEY_N)); + KeyMap.push_back(SKeyMap(SDLK_o, KEY_KEY_O)); + KeyMap.push_back(SKeyMap(SDLK_p, KEY_KEY_P)); + KeyMap.push_back(SKeyMap(SDLK_q, KEY_KEY_Q)); + KeyMap.push_back(SKeyMap(SDLK_r, KEY_KEY_R)); + KeyMap.push_back(SKeyMap(SDLK_s, KEY_KEY_S)); + KeyMap.push_back(SKeyMap(SDLK_t, KEY_KEY_T)); + KeyMap.push_back(SKeyMap(SDLK_u, KEY_KEY_U)); + KeyMap.push_back(SKeyMap(SDLK_v, KEY_KEY_V)); + KeyMap.push_back(SKeyMap(SDLK_w, KEY_KEY_W)); + KeyMap.push_back(SKeyMap(SDLK_x, KEY_KEY_X)); + KeyMap.push_back(SKeyMap(SDLK_y, KEY_KEY_Y)); + KeyMap.push_back(SKeyMap(SDLK_z, KEY_KEY_Z)); + + KeyMap.push_back(SKeyMap(SDLK_LGUI, KEY_LWIN)); + KeyMap.push_back(SKeyMap(SDLK_RGUI, KEY_RWIN)); + // apps missing + KeyMap.push_back(SKeyMap(SDLK_POWER, KEY_SLEEP)); //?? + + KeyMap.push_back(SKeyMap(SDLK_KP_0, KEY_NUMPAD0)); + KeyMap.push_back(SKeyMap(SDLK_KP_1, KEY_NUMPAD1)); + KeyMap.push_back(SKeyMap(SDLK_KP_2, KEY_NUMPAD2)); + KeyMap.push_back(SKeyMap(SDLK_KP_3, KEY_NUMPAD3)); + KeyMap.push_back(SKeyMap(SDLK_KP_4, KEY_NUMPAD4)); + KeyMap.push_back(SKeyMap(SDLK_KP_5, KEY_NUMPAD5)); + KeyMap.push_back(SKeyMap(SDLK_KP_6, KEY_NUMPAD6)); + KeyMap.push_back(SKeyMap(SDLK_KP_7, KEY_NUMPAD7)); + KeyMap.push_back(SKeyMap(SDLK_KP_8, KEY_NUMPAD8)); + KeyMap.push_back(SKeyMap(SDLK_KP_9, KEY_NUMPAD9)); + KeyMap.push_back(SKeyMap(SDLK_KP_MULTIPLY, KEY_MULTIPLY)); + KeyMap.push_back(SKeyMap(SDLK_KP_PLUS, KEY_ADD)); + KeyMap.push_back(SKeyMap(SDLK_KP_ENTER, KEY_RETURN)); + KeyMap.push_back(SKeyMap(SDLK_KP_MINUS, KEY_SUBTRACT)); + KeyMap.push_back(SKeyMap(SDLK_KP_PERIOD, KEY_DECIMAL)); + KeyMap.push_back(SKeyMap(SDLK_KP_DIVIDE, KEY_DIVIDE)); + + KeyMap.push_back(SKeyMap(SDLK_F1, KEY_F1)); + KeyMap.push_back(SKeyMap(SDLK_F2, KEY_F2)); + KeyMap.push_back(SKeyMap(SDLK_F3, KEY_F3)); + KeyMap.push_back(SKeyMap(SDLK_F4, KEY_F4)); + KeyMap.push_back(SKeyMap(SDLK_F5, KEY_F5)); + KeyMap.push_back(SKeyMap(SDLK_F6, KEY_F6)); + KeyMap.push_back(SKeyMap(SDLK_F7, KEY_F7)); + KeyMap.push_back(SKeyMap(SDLK_F8, KEY_F8)); + KeyMap.push_back(SKeyMap(SDLK_F9, KEY_F9)); + KeyMap.push_back(SKeyMap(SDLK_F10, KEY_F10)); + KeyMap.push_back(SKeyMap(SDLK_F11, KEY_F11)); + KeyMap.push_back(SKeyMap(SDLK_F12, KEY_F12)); + KeyMap.push_back(SKeyMap(SDLK_F13, KEY_F13)); + KeyMap.push_back(SKeyMap(SDLK_F14, KEY_F14)); + KeyMap.push_back(SKeyMap(SDLK_F15, KEY_F15)); + // no higher F-keys + + KeyMap.push_back(SKeyMap(SDLK_NUMLOCKCLEAR, KEY_NUMLOCK)); + KeyMap.push_back(SKeyMap(SDLK_SCROLLLOCK, KEY_SCROLL)); + KeyMap.push_back(SKeyMap(SDLK_LSHIFT, KEY_LSHIFT)); + KeyMap.push_back(SKeyMap(SDLK_RSHIFT, KEY_RSHIFT)); + KeyMap.push_back(SKeyMap(SDLK_LCTRL, KEY_LCONTROL)); + KeyMap.push_back(SKeyMap(SDLK_RCTRL, KEY_RCONTROL)); + KeyMap.push_back(SKeyMap(SDLK_LALT, KEY_LMENU)); + KeyMap.push_back(SKeyMap(SDLK_RALT, KEY_RMENU)); + + KeyMap.push_back(SKeyMap(SDLK_PLUS, KEY_PLUS)); + KeyMap.push_back(SKeyMap(SDLK_COMMA, KEY_COMMA)); + KeyMap.push_back(SKeyMap(SDLK_MINUS, KEY_MINUS)); + KeyMap.push_back(SKeyMap(SDLK_PERIOD, KEY_PERIOD)); + + // some special keys missing + + KeyMap.sort(); +} + +void CIrrDeviceSDL::CCursorControl::initCursors() +{ + Cursors.reserve(gui::ECI_COUNT); + + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW)); // ECI_NORMAL + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR)); // ECI_CROSS + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND)); // ECI_HAND + Cursors.emplace_back(nullptr); // ECI_HELP + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM)); // ECI_IBEAM + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO)); // ECI_NO + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT)); // ECI_WAIT + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL)); // ECI_SIZEALL + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW)); // ECI_SIZENESW + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE)); // ECI_SIZENWSE + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS)); // ECI_SIZENS + Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE)); // ECI_SIZEWE + Cursors.emplace_back(nullptr); // ECI_UP +} + +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_SDL_DEVICE_ diff --git a/irr/src/CIrrDeviceSDL.h b/irr/src/CIrrDeviceSDL.h new file mode 100644 index 000000000..b1e2a7858 --- /dev/null +++ b/irr/src/CIrrDeviceSDL.h @@ -0,0 +1,326 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h +// This device code is based on the original SDL device implementation +// contributed by Shane Parker (sirshane). + +#pragma once + +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + +#include "IrrlichtDevice.h" +#include "CIrrDeviceStub.h" +#include "ICursorControl.h" + +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ +#include +#endif + +#include +// DirectFB is removed in SDL3, thou distribution as Alpine currently ships SDL2 +// with enabled DirectFB, but requiring another fix at a top of SDL2. +// We don't need DirectFB in Irrlicht/Minetest, so simply disable it here to prevent issues. +#undef SDL_VIDEO_DRIVER_DIRECTFB +#include + +#include + +namespace irr +{ + +class CIrrDeviceSDL : public CIrrDeviceStub +{ +public: + //! constructor + CIrrDeviceSDL(const SIrrlichtCreationParameters ¶m); + + //! destructor + virtual ~CIrrDeviceSDL(); + + //! runs the device. Returns false if device wants to be deleted + bool run() override; + + //! pause execution temporarily + void yield() override; + + //! pause execution for a specified time + void sleep(u32 timeMs, bool pauseTimer) override; + + //! sets the caption of the window + void setWindowCaption(const wchar_t *text) override; + + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + + //! returns if window is active. if not, nothing need to be drawn + bool isWindowActive() const override; + + //! returns if window has focus. + bool isWindowFocused() const override; + + //! returns if window is minimized. + bool isWindowMinimized() const override; + + //! returns color format of the window. + video::ECOLOR_FORMAT getColorFormat() const override; + + //! notifies the device that it should close itself + void closeDevice() override; + + //! Sets if the window should be resizable in windowed mode. + void setResizable(bool resize = false) override; + + //! Minimizes the window. + void minimizeWindow() override; + + //! Maximizes the window. + void maximizeWindow() override; + + //! Restores the window size. + void restoreWindow() override; + + //! Checks if the window is maximized. + bool isWindowMaximized() const override; + + //! Checks if the Irrlicht window is running in fullscreen mode + /** \return True if window is fullscreen. */ + bool isFullscreen() const override; + + //! Get the position of this window on screen + core::position2di getWindowPosition() override; + + //! Activate any joysticks, and generate events for them. + bool activateJoysticks(core::array &joystickInfo) override; + + //! Get the device type + E_DEVICE_TYPE getType() const override + { + return EIDT_SDL; + } + + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + + void SwapWindow(); + + //! Implementation of the linux cursor control + class CCursorControl : public gui::ICursorControl + { + public: + CCursorControl(CIrrDeviceSDL *dev) : + Device(dev), IsVisible(true) + { + initCursors(); + } + + //! Changes the visible state of the mouse cursor. + void setVisible(bool visible) override + { + IsVisible = visible; + if (visible) + SDL_ShowCursor(SDL_ENABLE); + else { + SDL_ShowCursor(SDL_DISABLE); + } + } + + //! Returns if the cursor is currently visible. + bool isVisible() const override + { + return IsVisible; + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(f32 x, f32 y) override + { + setPosition((s32)(x * Device->Width), (s32)(y * Device->Height)); + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(s32 x, s32 y) override + { + SDL_WarpMouseInWindow(Device->Window, x, y); + + if (SDL_GetRelativeMouseMode()) { + // There won't be an event for this warp (details on libsdl-org/SDL/issues/6034) + Device->MouseX = x; + Device->MouseY = y; + } + } + + //! Returns the current position of the mouse cursor. + const core::position2d &getPosition(bool updateCursor) override + { + if (updateCursor) + updateCursorPos(); + return CursorPos; + } + + //! Returns the current position of the mouse cursor. + core::position2d getRelativePosition(bool updateCursor) override + { + if (updateCursor) + updateCursorPos(); + return core::position2d(CursorPos.X / (f32)Device->Width, + CursorPos.Y / (f32)Device->Height); + } + + void setReferenceRect(core::rect *rect = 0) override + { + } + + virtual void setRelativeMode(bool relative) _IRR_OVERRIDE_ + { + // Only change it when necessary, as it flushes mouse motion when enabled + if (relative != SDL_GetRelativeMouseMode()) { + if (relative) + SDL_SetRelativeMouseMode(SDL_TRUE); + else + SDL_SetRelativeMouseMode(SDL_FALSE); + } + } + + void setActiveIcon(gui::ECURSOR_ICON iconId) override + { + ActiveIcon = iconId; + if (iconId > Cursors.size() || !Cursors[iconId]) { + iconId = gui::ECI_NORMAL; + if (iconId > Cursors.size() || !Cursors[iconId]) + return; + } + SDL_SetCursor(Cursors[iconId].get()); + } + + gui::ECURSOR_ICON getActiveIcon() const override + { + return ActiveIcon; + } + + private: + void updateCursorPos() + { +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + EmscriptenPointerlockChangeEvent pointerlockStatus; // let's hope that test is not expensive ... + if (emscripten_get_pointerlock_status(&pointerlockStatus) == EMSCRIPTEN_RESULT_SUCCESS) { + if (pointerlockStatus.isActive) { + CursorPos.X += Device->MouseXRel; + CursorPos.Y += Device->MouseYRel; + Device->MouseXRel = 0; + Device->MouseYRel = 0; + } else { + CursorPos.X = Device->MouseX; + CursorPos.Y = Device->MouseY; + } + } +#else + CursorPos.X = Device->MouseX; + CursorPos.Y = Device->MouseY; + + if (CursorPos.X < 0) + CursorPos.X = 0; + if (CursorPos.X > (s32)Device->Width) + CursorPos.X = Device->Width; + if (CursorPos.Y < 0) + CursorPos.Y = 0; + if (CursorPos.Y > (s32)Device->Height) + CursorPos.Y = Device->Height; +#endif + } + + void initCursors(); + + CIrrDeviceSDL *Device; + core::position2d CursorPos; + bool IsVisible; + + struct CursorDeleter + { + void operator()(SDL_Cursor *ptr) + { + if (ptr) + SDL_FreeCursor(ptr); + } + }; + std::vector> Cursors; + gui::ECURSOR_ICON ActiveIcon = gui::ECURSOR_ICON::ECI_NORMAL; + }; + +private: +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ + static EM_BOOL MouseUpDownCallback(int eventType, const EmscriptenMouseEvent *event, void *userData); + static EM_BOOL MouseEnterCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); + static EM_BOOL MouseLeaveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); + +#endif + // Check if a key is a known special character with no side effects on text boxes. + static bool keyIsKnownSpecial(EKEY_CODE key); + + // Return the Char that should be sent to Irrlicht for the given key (either the one passed in or 0). + static int findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key); + + // Check if a text box is in focus. Enable or disable SDL_TEXTINPUT events only if in focus. + void resetReceiveTextInputEvents(); + + //! create the driver + void createDriver(); + + bool createWindow(); + + void createKeyMap(); + + void logAttributes(); + SDL_GLContext Context; + SDL_Window *Window; + int SDL_Flags; +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + core::array Joysticks; +#endif + + s32 MouseX, MouseY; + s32 MouseXRel, MouseYRel; + u32 MouseButtonStates; + + u32 Width, Height; + + bool Resizable; + + core::rect lastElemPos; + + struct SKeyMap + { + SKeyMap() {} + SKeyMap(s32 x11, s32 win32) : + SDLKey(x11), Win32Key(win32) + { + } + + s32 SDLKey; + s32 Win32Key; + + bool operator<(const SKeyMap &o) const + { + return SDLKey < o.SDLKey; + } + }; + + core::array KeyMap; + SDL_SysWMinfo Info; + + s32 CurrentTouchCount; +}; + +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_SDL_DEVICE_ diff --git a/irr/src/CIrrDeviceStub.cpp b/irr/src/CIrrDeviceStub.cpp new file mode 100644 index 000000000..2292db191 --- /dev/null +++ b/irr/src/CIrrDeviceStub.cpp @@ -0,0 +1,376 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CIrrDeviceStub.h" +#include "ISceneManager.h" +#include "IEventReceiver.h" +#include "IFileSystem.h" +#include "IGUIElement.h" +#include "IGUIEnvironment.h" +#include "os.h" +#include "CTimer.h" +#include "CLogger.h" +#include "irrString.h" +#include "IrrCompileConfig.h" // for IRRLICHT_SDK_VERSION + +namespace irr +{ +//! constructor +CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters ¶ms) : + IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0), + Timer(0), CursorControl(0), UserReceiver(params.EventReceiver), + Logger(0), Operator(0), FileSystem(0), + InputReceivingSceneManager(0), ContextManager(0), + CreationParams(params), Close(false) +{ + Timer = new CTimer(); + if (os::Printer::Logger) { + os::Printer::Logger->grab(); + Logger = (CLogger *)os::Printer::Logger; + Logger->setReceiver(UserReceiver); + } else { + Logger = new CLogger(UserReceiver); + os::Printer::Logger = Logger; + } + Logger->setLogLevel(CreationParams.LoggingLevel); + + os::Printer::Logger = Logger; + + FileSystem = io::createFileSystem(); + + core::stringc s = "Irrlicht Engine version "; + s.append(getVersion()); + os::Printer::log(s.c_str(), ELL_INFORMATION); + + checkVersion(params.SDK_version_do_not_use); +} + +CIrrDeviceStub::~CIrrDeviceStub() +{ + if (GUIEnvironment) + GUIEnvironment->drop(); + + if (SceneManager) + SceneManager->drop(); + + if (VideoDriver) + VideoDriver->drop(); + + if (ContextManager) + ContextManager->drop(); + + if (FileSystem) + FileSystem->drop(); + + if (InputReceivingSceneManager) + InputReceivingSceneManager->drop(); + + if (CursorControl) + CursorControl->drop(); + + if (Operator) + Operator->drop(); + + CursorControl = 0; + + if (Timer) + Timer->drop(); + + if (Logger->drop()) + os::Printer::Logger = 0; +} + +void CIrrDeviceStub::createGUIAndScene() +{ + // create gui environment + GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator); + + // create Scene manager + SceneManager = scene::createSceneManager(VideoDriver, CursorControl); + + setEventReceiver(UserReceiver); +} + +//! returns the video driver +video::IVideoDriver *CIrrDeviceStub::getVideoDriver() +{ + return VideoDriver; +} + +//! return file system +io::IFileSystem *CIrrDeviceStub::getFileSystem() +{ + return FileSystem; +} + +//! returns the gui environment +gui::IGUIEnvironment *CIrrDeviceStub::getGUIEnvironment() +{ + return GUIEnvironment; +} + +//! returns the scene manager +scene::ISceneManager *CIrrDeviceStub::getSceneManager() +{ + return SceneManager; +} + +//! \return Returns a pointer to the ITimer object. With it the +//! current Time can be received. +ITimer *CIrrDeviceStub::getTimer() +{ + return Timer; +} + +//! Sets the window icon. +bool CIrrDeviceStub::setWindowIcon(const video::IImage *img) +{ + return false; +} + +//! Returns the version of the engine. +const char *CIrrDeviceStub::getVersion() const +{ + return IRRLICHT_SDK_VERSION; +} + +//! \return Returns a pointer to the mouse cursor control interface. +gui::ICursorControl *CIrrDeviceStub::getCursorControl() +{ + return CursorControl; +} + +//! return the context manager +video::IContextManager *CIrrDeviceStub::getContextManager() +{ + return ContextManager; +} + +//! checks version of sdk and prints warning if there might be a problem +bool CIrrDeviceStub::checkVersion(const char *version) +{ + if (strcmp(getVersion(), version)) { + core::stringc w; + w = "Warning: The library version of the Irrlicht Engine ("; + w += getVersion(); + w += ") does not match the version the application was compiled with ("; + w += version; + w += "). This may cause problems."; + os::Printer::log(w.c_str(), ELL_WARNING); + + return false; + } + + return true; +} + +//! Compares to the last call of this function to return double and triple clicks. +u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent) +{ + const s32 MAX_MOUSEMOVE = 3; + + irr::u32 clickTime = getTimer()->getRealTime(); + + if ((clickTime - MouseMultiClicks.LastClickTime) < MouseMultiClicks.DoubleClickTime && core::abs_(MouseMultiClicks.LastClick.X - mouseX) <= MAX_MOUSEMOVE && core::abs_(MouseMultiClicks.LastClick.Y - mouseY) <= MAX_MOUSEMOVE && MouseMultiClicks.CountSuccessiveClicks < 3 && MouseMultiClicks.LastMouseInputEvent == inputEvent) { + ++MouseMultiClicks.CountSuccessiveClicks; + } else { + MouseMultiClicks.CountSuccessiveClicks = 1; + } + + MouseMultiClicks.LastMouseInputEvent = inputEvent; + MouseMultiClicks.LastClickTime = clickTime; + MouseMultiClicks.LastClick.X = mouseX; + MouseMultiClicks.LastClick.Y = mouseY; + + return MouseMultiClicks.CountSuccessiveClicks; +} + +//! send the event to the right receiver +bool CIrrDeviceStub::postEventFromUser(const SEvent &event) +{ + bool absorbed = false; + + if (UserReceiver) + absorbed = UserReceiver->OnEvent(event); + + if (!absorbed && GUIEnvironment) + absorbed = GUIEnvironment->postEventFromUser(event); + + scene::ISceneManager *inputReceiver = InputReceivingSceneManager; + if (!inputReceiver) + inputReceiver = SceneManager; + + if (!absorbed && inputReceiver) + absorbed = inputReceiver->postEventFromUser(event); + + return absorbed; +} + +//! Sets a new event receiver to receive events +void CIrrDeviceStub::setEventReceiver(IEventReceiver *receiver) +{ + UserReceiver = receiver; + Logger->setReceiver(receiver); + if (GUIEnvironment) + GUIEnvironment->setUserEventReceiver(receiver); +} + +//! Returns poinhter to the current event receiver. Returns 0 if there is none. +IEventReceiver *CIrrDeviceStub::getEventReceiver() +{ + return UserReceiver; +} + +//! \return Returns a pointer to the logger. +ILogger *CIrrDeviceStub::getLogger() +{ + return Logger; +} + +//! Returns the operation system opertator object. +IOSOperator *CIrrDeviceStub::getOSOperator() +{ + return Operator; +} + +//! Sets the input receiving scene manager. +void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager *sceneManager) +{ + if (sceneManager) + sceneManager->grab(); + if (InputReceivingSceneManager) + InputReceivingSceneManager->drop(); + + InputReceivingSceneManager = sceneManager; +} + +//! Checks if the window is maximized. +bool CIrrDeviceStub::isWindowMaximized() const +{ + return false; +} + +//! Checks if the window is running in fullscreen mode +bool CIrrDeviceStub::isFullscreen() const +{ + return CreationParams.Fullscreen; +} + +//! returns color format +video::ECOLOR_FORMAT CIrrDeviceStub::getColorFormat() const +{ + return video::ECF_R5G6B5; +} + +//! No-op in this implementation +bool CIrrDeviceStub::activateJoysticks(core::array &joystickInfo) +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::activateAccelerometer(float updateInterval) +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::deactivateAccelerometer() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::isAccelerometerActive() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::isAccelerometerAvailable() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::activateGyroscope(float updateInterval) +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::deactivateGyroscope() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::isGyroscopeActive() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::isGyroscopeAvailable() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::activateDeviceMotion(float updateInterval) +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::deactivateDeviceMotion() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::isDeviceMotionActive() +{ + return false; +} + +//! No-op in this implementation +bool CIrrDeviceStub::isDeviceMotionAvailable() +{ + return false; +} + +//! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior. +void CIrrDeviceStub::setDoubleClickTime(u32 timeMs) +{ + MouseMultiClicks.DoubleClickTime = timeMs; +} + +//! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse. +u32 CIrrDeviceStub::getDoubleClickTime() const +{ + return MouseMultiClicks.DoubleClickTime; +} + +//! Remove all messages pending in the system message loop +void CIrrDeviceStub::clearSystemMessages() +{ +} + +//! Get the display density in dots per inch. +float CIrrDeviceStub::getDisplayDensity() const +{ + return 0.0f; +} + +//! Checks whether the input device should take input from the IME +bool CIrrDeviceStub::acceptsIME() +{ + if (!GUIEnvironment) + return false; + gui::IGUIElement *elem = GUIEnvironment->getFocus(); + return elem && elem->acceptsIME(); +} + +} // end namespace irr diff --git a/irr/src/CIrrDeviceStub.h b/irr/src/CIrrDeviceStub.h new file mode 100644 index 000000000..163e44f39 --- /dev/null +++ b/irr/src/CIrrDeviceStub.h @@ -0,0 +1,204 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IrrlichtDevice.h" +#include "SIrrCreationParameters.h" +#include "IContextManager.h" + +namespace irr +{ +// lots of prototypes: +class ILogger; +class CLogger; + +namespace gui +{ +class IGUIEnvironment; +IGUIEnvironment *createGUIEnvironment(io::IFileSystem *fs, + video::IVideoDriver *Driver, IOSOperator *op); +} + +namespace scene +{ +ISceneManager *createSceneManager(video::IVideoDriver *driver, gui::ICursorControl *cc); +} + +namespace io +{ +IFileSystem *createFileSystem(); +} + +namespace video +{ +IVideoDriver *createNullDriver(io::IFileSystem *io, const core::dimension2d &screenSize); +} + +//! Stub for an Irrlicht Device implementation +class CIrrDeviceStub : public IrrlichtDevice +{ +public: + //! constructor + CIrrDeviceStub(const SIrrlichtCreationParameters ¶m); + + //! destructor + virtual ~CIrrDeviceStub(); + + //! returns the video driver + video::IVideoDriver *getVideoDriver() override; + + //! return file system + io::IFileSystem *getFileSystem() override; + + //! returns the gui environment + gui::IGUIEnvironment *getGUIEnvironment() override; + + //! returns the scene manager + scene::ISceneManager *getSceneManager() override; + + //! \return Returns a pointer to the mouse cursor control interface. + gui::ICursorControl *getCursorControl() override; + + //! return the context manager + video::IContextManager *getContextManager() override; + + //! Returns a pointer to the ITimer object. With it the current Time can be received. + ITimer *getTimer() override; + + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + + //! Returns the version of the engine. + const char *getVersion() const override; + + //! send the event to the right receiver + bool postEventFromUser(const SEvent &event) override; + + //! Sets a new event receiver to receive events + void setEventReceiver(IEventReceiver *receiver) override; + + //! Returns pointer to the current event receiver. Returns 0 if there is none. + IEventReceiver *getEventReceiver() override; + + //! Sets the input receiving scene manager. + /** If set to null, the main scene manager (returned by GetSceneManager()) will receive the input */ + void setInputReceivingSceneManager(scene::ISceneManager *sceneManager) override; + + //! Returns a pointer to the logger. + ILogger *getLogger() override; + + //! Returns the operation system opertator object. + IOSOperator *getOSOperator() override; + + //! Checks if the window is maximized. + bool isWindowMaximized() const override; + + //! Checks if the window is running in fullscreen mode. + bool isFullscreen() const override; + + //! get color format of the current window + video::ECOLOR_FORMAT getColorFormat() const override; + + //! Activate any joysticks, and generate events for them. + bool activateJoysticks(core::array &joystickInfo) override; + + //! Activate accelerometer. + bool activateAccelerometer(float updateInterval = 0.016666f) override; + + //! Deactivate accelerometer. + bool deactivateAccelerometer() override; + + //! Is accelerometer active. + bool isAccelerometerActive() override; + + //! Is accelerometer available. + bool isAccelerometerAvailable() override; + + //! Activate gyroscope. + bool activateGyroscope(float updateInterval = 0.016666f) override; + + //! Deactivate gyroscope. + bool deactivateGyroscope() override; + + //! Is gyroscope active. + bool isGyroscopeActive() override; + + //! Is gyroscope available. + bool isGyroscopeAvailable() override; + + //! Activate device motion. + bool activateDeviceMotion(float updateInterval = 0.016666f) override; + + //! Deactivate device motion. + bool deactivateDeviceMotion() override; + + //! Is device motion active. + bool isDeviceMotionActive() override; + + //! Is device motion available. + bool isDeviceMotionAvailable() override; + + //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior. + //! When set to 0 no double- and tripleclicks will be generated. + void setDoubleClickTime(u32 timeMs) override; + + //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse. + u32 getDoubleClickTime() const override; + + //! Remove all messages pending in the system message loop + void clearSystemMessages() override; + + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + + //! Resize the render window. + void setWindowSize(const irr::core::dimension2d &size) override {} + +protected: + void createGUIAndScene(); + + //! checks version of SDK and prints warning if there might be a problem + bool checkVersion(const char *version); + + //! Compares to the last call of this function to return double and triple clicks. + /** Needed for win32 device event handling + \return Returns only 1,2 or 3. A 4th click will start with 1 again. + */ + virtual u32 checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent); + + //! Checks whether the input device should take input from the IME + bool acceptsIME(); + + video::IVideoDriver *VideoDriver; + gui::IGUIEnvironment *GUIEnvironment; + scene::ISceneManager *SceneManager; + ITimer *Timer; + gui::ICursorControl *CursorControl; + IEventReceiver *UserReceiver; + CLogger *Logger; + IOSOperator *Operator; + io::IFileSystem *FileSystem; + scene::ISceneManager *InputReceivingSceneManager; + + struct SMouseMultiClicks + { + SMouseMultiClicks() : + DoubleClickTime(500), CountSuccessiveClicks(0), LastClickTime(0), LastMouseInputEvent(EMIE_COUNT) + { + } + + u32 DoubleClickTime; + u32 CountSuccessiveClicks; + u32 LastClickTime; + core::position2di LastClick; + EMOUSE_INPUT_EVENT LastMouseInputEvent; + }; + SMouseMultiClicks MouseMultiClicks; + video::IContextManager *ContextManager; + SIrrlichtCreationParameters CreationParams; + bool Close; +}; + +} // end namespace irr diff --git a/irr/src/CIrrDeviceWin32.cpp b/irr/src/CIrrDeviceWin32.cpp new file mode 100644 index 000000000..c2876fcce --- /dev/null +++ b/irr/src/CIrrDeviceWin32.cpp @@ -0,0 +1,1474 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ + +#if defined(__STRICT_ANSI__) +#error Compiling with __STRICT_ANSI__ not supported. g++ does set this when compiling with -std=c++11 or -std=c++0x. Use instead -std=gnu++11 or -std=gnu++0x. Or use -U__STRICT_ANSI__ to disable strict ansi. +#endif + +#include "CIrrDeviceWin32.h" +#include "IEventReceiver.h" +#include "os.h" + +#include "CTimer.h" +#include "irrString.h" +#include "COSOperator.h" +#include "dimension2d.h" +#include "IGUISpriteBank.h" +#include +#include "SExposedVideoData.h" + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) +#include +#include +#ifdef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ +#define DIRECTINPUT_VERSION 0x0800 +#include +#endif +#endif + +#if defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) +#include "CEGLManager.h" +#endif + +#if defined(_IRR_COMPILE_WITH_OPENGL_) +#include "CWGLManager.h" +#endif + +namespace irr +{ +namespace video +{ +#ifdef _IRR_COMPILE_WITH_OPENGL_ +IVideoDriver *createOpenGLDriver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#endif + +#ifdef _IRR_COMPILE_WITH_OGLES1_ +IVideoDriver *createOGLES1Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#endif + +#ifdef _IRR_COMPILE_WITH_OGLES2_ +IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); +#endif +} +} // end namespace irr + +namespace irr +{ +struct SJoystickWin32Control +{ + CIrrDeviceWin32 *Device; + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) + IDirectInput8 *DirectInputDevice; +#endif +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) + struct JoystickInfo + { + u32 Index; +#ifdef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ + core::stringc Name; + GUID guid; + LPDIRECTINPUTDEVICE8 lpdijoy; + DIDEVCAPS devcaps; + u8 axisValid[8]; +#else + JOYCAPS Caps; +#endif + }; + core::array ActiveJoysticks; +#endif + + SJoystickWin32Control(CIrrDeviceWin32 *dev); + ~SJoystickWin32Control(); + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) + static BOOL CALLBACK EnumJoysticks(LPCDIDEVICEINSTANCE lpddi, LPVOID cp); + void directInputAddJoystick(LPCDIDEVICEINSTANCE lpddi); +#endif + + void pollJoysticks(); + bool activateJoysticks(core::array &joystickInfo); + irr::core::stringc findJoystickName(int index, const JOYCAPS &caps) const; +}; + +SJoystickWin32Control::SJoystickWin32Control(CIrrDeviceWin32 *dev) : + Device(dev) +{ +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) + DirectInputDevice = 0; + if (DI_OK != (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&DirectInputDevice, NULL))) { + os::Printer::log("Could not create DirectInput8 Object", ELL_WARNING); + return; + } +#endif +} + +SJoystickWin32Control::~SJoystickWin32Control() +{ +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) + for (u32 joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { + LPDIRECTINPUTDEVICE8 dev = ActiveJoysticks[joystick].lpdijoy; + if (dev) { + dev->Unacquire(); + dev->Release(); + } + } + + if (DirectInputDevice) + DirectInputDevice->Release(); +#endif +} + +#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) +BOOL CALLBACK SJoystickWin32Control::EnumJoysticks(LPCDIDEVICEINSTANCE lpddi, LPVOID cp) +{ + SJoystickWin32Control *p = (SJoystickWin32Control *)cp; + p->directInputAddJoystick(lpddi); + return DIENUM_CONTINUE; +} +void SJoystickWin32Control::directInputAddJoystick(LPCDIDEVICEINSTANCE lpddi) +{ + // Get the GUID of the joystuck + const GUID guid = lpddi->guidInstance; + + JoystickInfo activeJoystick; + activeJoystick.Index = ActiveJoysticks.size(); + activeJoystick.guid = guid; + activeJoystick.Name = lpddi->tszProductName; + if (FAILED(DirectInputDevice->CreateDevice(guid, &activeJoystick.lpdijoy, NULL))) { + os::Printer::log("Could not create DirectInput device", ELL_WARNING); + return; + } + + activeJoystick.devcaps.dwSize = sizeof(activeJoystick.devcaps); + if (FAILED(activeJoystick.lpdijoy->GetCapabilities(&activeJoystick.devcaps))) { + os::Printer::log("Could not create DirectInput device", ELL_WARNING); + return; + } + + if (FAILED(activeJoystick.lpdijoy->SetCooperativeLevel(Device->HWnd, DISCL_BACKGROUND | DISCL_EXCLUSIVE))) { + os::Printer::log("Could not set DirectInput device cooperative level", ELL_WARNING); + return; + } + + if (FAILED(activeJoystick.lpdijoy->SetDataFormat(&c_dfDIJoystick2))) { + os::Printer::log("Could not set DirectInput device data format", ELL_WARNING); + return; + } + + if (FAILED(activeJoystick.lpdijoy->Acquire())) { + os::Printer::log("Could not set DirectInput cooperative level", ELL_WARNING); + return; + } + + DIJOYSTATE2 info; + if (FAILED(activeJoystick.lpdijoy->GetDeviceState(sizeof(info), &info))) { + os::Printer::log("Could not read DirectInput device state", ELL_WARNING); + return; + } + + ZeroMemory(activeJoystick.axisValid, sizeof(activeJoystick.axisValid)); + activeJoystick.axisValid[0] = (info.lX != 0) ? 1 : 0; + activeJoystick.axisValid[1] = (info.lY != 0) ? 1 : 0; + activeJoystick.axisValid[2] = (info.lZ != 0) ? 1 : 0; + activeJoystick.axisValid[3] = (info.lRx != 0) ? 1 : 0; + activeJoystick.axisValid[4] = (info.lRy != 0) ? 1 : 0; + activeJoystick.axisValid[5] = (info.lRz != 0) ? 1 : 0; + + int caxis = 0; + for (u8 i = 0; i < 6; i++) { + if (activeJoystick.axisValid[i]) + caxis++; + } + + for (u8 i = 0; i < (activeJoystick.devcaps.dwAxes) - caxis; i++) { + if (i + caxis < 8) + activeJoystick.axisValid[i + caxis] = 1; + } + + ActiveJoysticks.push_back(activeJoystick); +} +#endif + +void SJoystickWin32Control::pollJoysticks() +{ +#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +#ifdef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ + if (0 == ActiveJoysticks.size()) + return; + + u32 joystick; + DIJOYSTATE2 info; + + for (joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { + // needs to be reset for each joystick + // request ALL values and POV as continuous if possible + + const DIDEVCAPS &caps = ActiveJoysticks[joystick].devcaps; + // if no POV is available don't ask for POV values + + if (!FAILED(ActiveJoysticks[joystick].lpdijoy->GetDeviceState(sizeof(info), &info))) { + SEvent event; + + event.EventType = irr::EET_JOYSTICK_INPUT_EVENT; + event.JoystickEvent.Joystick = (u8)joystick; + + event.JoystickEvent.POV = (u16)info.rgdwPOV[0]; + // set to undefined if no POV value was returned or the value + // is out of range + if ((caps.dwPOVs == 0) || (event.JoystickEvent.POV > 35900)) + event.JoystickEvent.POV = 65535; + + for (int axis = 0; axis < SEvent::SJoystickEvent::NUMBER_OF_AXES; ++axis) + event.JoystickEvent.Axis[axis] = 0; + + u16 dxAxis = 0; + u16 irrAxis = 0; + + while (dxAxis < 6 && irrAxis < caps.dwAxes) { + bool axisFound = 0; + s32 axisValue = 0; + + switch (dxAxis) { + case 0: + axisValue = info.lX; + break; + case 1: + axisValue = info.lY; + break; + case 2: + axisValue = info.lZ; + break; + case 3: + axisValue = info.lRx; + break; + case 4: + axisValue = info.lRy; + break; + case 5: + axisValue = info.lRz; + break; + case 6: + axisValue = info.rglSlider[0]; + break; + case 7: + axisValue = info.rglSlider[1]; + break; + default: + break; + } + + if (ActiveJoysticks[joystick].axisValid[dxAxis] > 0) + axisFound = 1; + + if (axisFound) { + s32 val = axisValue - 32768; + + if (val < -32767) + val = -32767; + if (val > 32767) + val = 32767; + event.JoystickEvent.Axis[irrAxis] = (s16)(val); + irrAxis++; + } + + dxAxis++; + } + + u32 buttons = 0; + BYTE *bytebuttons = info.rgbButtons; + for (u16 i = 0; i < 32; i++) { + if (bytebuttons[i] > 0) { + buttons |= (1 << i); + } + } + event.JoystickEvent.ButtonStates = buttons; + + (void)Device->postEventFromUser(event); + } + } +#else + if (0 == ActiveJoysticks.size()) + return; + + u32 joystick; + JOYINFOEX info; + + for (joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { + // needs to be reset for each joystick + // request ALL values and POV as continuous if possible + info.dwSize = sizeof(info); + info.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS; + const JOYCAPS &caps = ActiveJoysticks[joystick].Caps; + // if no POV is available don't ask for POV values + if (!(caps.wCaps & JOYCAPS_HASPOV)) + info.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS); + if (JOYERR_NOERROR == joyGetPosEx(ActiveJoysticks[joystick].Index, &info)) { + SEvent event; + + event.EventType = irr::EET_JOYSTICK_INPUT_EVENT; + event.JoystickEvent.Joystick = (u8)joystick; + + event.JoystickEvent.POV = (u16)info.dwPOV; + // set to undefined if no POV value was returned or the value + // is out of range + if (!(info.dwFlags & JOY_RETURNPOV) || (event.JoystickEvent.POV > 35900)) + event.JoystickEvent.POV = 65535; + + for (int axis = 0; axis < SEvent::SJoystickEvent::NUMBER_OF_AXES; ++axis) + event.JoystickEvent.Axis[axis] = 0; + + event.JoystickEvent.ButtonStates = info.dwButtons; + + switch (caps.wNumAxes) { + default: + case 6: + event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_V] = + (s16)((65535 * (info.dwVpos - caps.wVmin)) / (caps.wVmax - caps.wVmin) - 32768); + + case 5: + event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_U] = + (s16)((65535 * (info.dwUpos - caps.wUmin)) / (caps.wUmax - caps.wUmin) - 32768); + + case 4: + event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_R] = + (s16)((65535 * (info.dwRpos - caps.wRmin)) / (caps.wRmax - caps.wRmin) - 32768); + + case 3: + event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Z] = + (s16)((65535 * (info.dwZpos - caps.wZmin)) / (caps.wZmax - caps.wZmin) - 32768); + + case 2: + event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Y] = + (s16)((65535 * (info.dwYpos - caps.wYmin)) / (caps.wYmax - caps.wYmin) - 32768); + + case 1: + event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_X] = + (s16)((65535 * (info.dwXpos - caps.wXmin)) / (caps.wXmax - caps.wXmin) - 32768); + } + + (void)Device->postEventFromUser(event); + } + } +#endif +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +} + +/** This function is ported from SDL and released under zlib-license: + * Copyright (C) 1997-2014 Sam Lantinga */ +irr::core::stringc SJoystickWin32Control::findJoystickName(int index, const JOYCAPS &caps) const +{ +#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + + // As a default use the name given in the joystick structure. + // It is always the same name, independent of joystick. + irr::core::stringc result(caps.szPname); + + core::stringc key = core::stringc(REGSTR_PATH_JOYCONFIG) + "\\" + caps.szRegKey + "\\" + REGSTR_KEY_JOYCURR; + HKEY hTopKey = HKEY_LOCAL_MACHINE; + HKEY hKey; + long regresult = RegOpenKeyExA(hTopKey, key.c_str(), 0, KEY_READ, &hKey); + if (regresult != ERROR_SUCCESS) { + hTopKey = HKEY_CURRENT_USER; + regresult = RegOpenKeyExA(hTopKey, key.c_str(), 0, KEY_READ, &hKey); + } + if (regresult != ERROR_SUCCESS) + return result; + + /* find the registry key name for the joystick's properties */ + char regname[256]; + DWORD regsize = sizeof(regname); + core::stringc regvalue = core::stringc("Joystick") + core::stringc(index + 1) + REGSTR_VAL_JOYOEMNAME; + regresult = RegQueryValueExA(hKey, regvalue.c_str(), 0, 0, (LPBYTE)regname, ®size); + RegCloseKey(hKey); + if (regresult != ERROR_SUCCESS) + return result; + + /* open that registry key */ + core::stringc regkey = core::stringc(REGSTR_PATH_JOYOEM) + "\\" + regname; + regresult = RegOpenKeyExA(hTopKey, regkey.c_str(), 0, KEY_READ, &hKey); + if (regresult != ERROR_SUCCESS) + return result; + + /* find the size for the OEM name text */ + regsize = sizeof(regvalue); + regresult = RegQueryValueEx(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, + NULL, ®size); + if (regresult == ERROR_SUCCESS) { + char *name; + /* allocate enough memory for the OEM name text ... */ + name = new char[regsize]; + if (name) { + /* ... and read it from the registry */ + regresult = RegQueryValueEx(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, + (LPBYTE)name, ®size); + result = name; + } + delete[] name; + } + RegCloseKey(hKey); + + return result; +#endif + return ""; +} + +bool SJoystickWin32Control::activateJoysticks(core::array &joystickInfo) +{ +#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ + joystickInfo.clear(); + ActiveJoysticks.clear(); +#ifdef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ + if (!DirectInputDevice || (DirectInputDevice->EnumDevices(DI8DEVCLASS_GAMECTRL, SJoystickWin32Control::EnumJoysticks, this, DIEDFL_ATTACHEDONLY))) { + os::Printer::log("Could not enum DirectInput8 controllers", ELL_WARNING); + return false; + } + + for (u32 joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { + JoystickInfo &activeJoystick = ActiveJoysticks[joystick]; + SJoystickInfo info; + info.Axes = activeJoystick.devcaps.dwAxes; + info.Buttons = activeJoystick.devcaps.dwButtons; + info.Name = activeJoystick.Name; + info.PovHat = (activeJoystick.devcaps.dwPOVs != 0) + ? SJoystickInfo::POV_HAT_PRESENT + : SJoystickInfo::POV_HAT_ABSENT; + joystickInfo.push_back(info); + } + return true; +#else + const u32 numberOfJoysticks = ::joyGetNumDevs(); + JOYINFOEX info; + info.dwSize = sizeof(info); + info.dwFlags = JOY_RETURNALL; + + JoystickInfo activeJoystick; + SJoystickInfo returnInfo; + + joystickInfo.reallocate(numberOfJoysticks); + ActiveJoysticks.reallocate(numberOfJoysticks); + + u32 joystick = 0; + for (; joystick < numberOfJoysticks; ++joystick) { + if (JOYERR_NOERROR == joyGetPosEx(joystick, &info) && + JOYERR_NOERROR == joyGetDevCaps(joystick, + &activeJoystick.Caps, + sizeof(activeJoystick.Caps))) { + activeJoystick.Index = joystick; + ActiveJoysticks.push_back(activeJoystick); + + returnInfo.Joystick = (u8)joystick; + returnInfo.Axes = activeJoystick.Caps.wNumAxes; + returnInfo.Buttons = activeJoystick.Caps.wNumButtons; + returnInfo.Name = findJoystickName(joystick, activeJoystick.Caps); + returnInfo.PovHat = ((activeJoystick.Caps.wCaps & JOYCAPS_HASPOV) == JOYCAPS_HASPOV) + ? SJoystickInfo::POV_HAT_PRESENT + : SJoystickInfo::POV_HAT_ABSENT; + + joystickInfo.push_back(returnInfo); + } + } + + for (joystick = 0; joystick < joystickInfo.size(); ++joystick) { + char logString[256]; + snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'", + joystick, joystickInfo[joystick].Axes, + joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); + os::Printer::log(logString, ELL_INFORMATION); + } + + return true; +#endif +#else + return false; +#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ +} +} // end namespace irr + +namespace +{ +struct SEnvMapper +{ + HWND hWnd; + irr::CIrrDeviceWin32 *irrDev; +}; +// NOTE: This is global. We can have more than one Irrlicht Device at same time. +irr::core::array EnvMap; + +HKL KEYBOARD_INPUT_HKL = 0; +} + +irr::CIrrDeviceWin32 *getDeviceFromHWnd(HWND hWnd) +{ + const irr::u32 end = EnvMap.size(); + for (irr::u32 i = 0; i < end; ++i) { + const SEnvMapper &env = EnvMap[i]; + if (env.hWnd == hWnd) + return env.irrDev; + } + + return 0; +} + +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ +#ifndef WHEEL_DELTA +#define WHEEL_DELTA 120 +#endif + + irr::CIrrDeviceWin32 *dev = 0; + irr::SEvent event; + + static irr::s32 ClickCount = 0; + if (GetCapture() != hWnd && ClickCount > 0) + ClickCount = 0; + + struct messageMap + { + irr::s32 group; + UINT winMessage; + irr::s32 irrMessage; + }; + + static messageMap mouseMap[] = { + {0, WM_LBUTTONDOWN, irr::EMIE_LMOUSE_PRESSED_DOWN}, + {1, WM_LBUTTONUP, irr::EMIE_LMOUSE_LEFT_UP}, + {0, WM_RBUTTONDOWN, irr::EMIE_RMOUSE_PRESSED_DOWN}, + {1, WM_RBUTTONUP, irr::EMIE_RMOUSE_LEFT_UP}, + {0, WM_MBUTTONDOWN, irr::EMIE_MMOUSE_PRESSED_DOWN}, + {1, WM_MBUTTONUP, irr::EMIE_MMOUSE_LEFT_UP}, + {2, WM_MOUSEMOVE, irr::EMIE_MOUSE_MOVED}, + {3, WM_MOUSEWHEEL, irr::EMIE_MOUSE_WHEEL}, + {-1, 0, 0}, + }; + + // handle grouped events + messageMap *m = mouseMap; + while (m->group >= 0 && m->winMessage != message) + m += 1; + + if (m->group >= 0) { + if (m->group == 0) { // down + ClickCount++; + SetCapture(hWnd); + } else if (m->group == 1) { // up + ClickCount--; + if (ClickCount < 1) { + ClickCount = 0; + ReleaseCapture(); + } + } + + event.EventType = irr::EET_MOUSE_INPUT_EVENT; + event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT)m->irrMessage; + event.MouseInput.X = (short)LOWORD(lParam); + event.MouseInput.Y = (short)HIWORD(lParam); + event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); + event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); + // left and right mouse buttons + event.MouseInput.ButtonStates = wParam & (MK_LBUTTON | MK_RBUTTON); + // middle and extra buttons + if (wParam & MK_MBUTTON) + event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; + if (wParam & MK_XBUTTON1) + event.MouseInput.ButtonStates |= irr::EMBSM_EXTRA1; + if (wParam & MK_XBUTTON2) + event.MouseInput.ButtonStates |= irr::EMBSM_EXTRA2; + event.MouseInput.Wheel = 0.f; + + // wheel + if (m->group == 3) { + POINT p; // fixed by jox + p.x = 0; + p.y = 0; + ClientToScreen(hWnd, &p); + event.MouseInput.X -= p.x; + event.MouseInput.Y -= p.y; + event.MouseInput.Wheel = ((irr::f32)((short)HIWORD(wParam))) / (irr::f32)WHEEL_DELTA; + } + + dev = getDeviceFromHWnd(hWnd); + if (dev) { + dev->postEventFromUser(event); + + if (event.MouseInput.Event >= irr::EMIE_LMOUSE_PRESSED_DOWN && event.MouseInput.Event <= irr::EMIE_MMOUSE_PRESSED_DOWN) { + irr::u32 clicks = dev->checkSuccessiveClicks(event.MouseInput.X, event.MouseInput.Y, event.MouseInput.Event); + if (clicks == 2) { + event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT)(irr::EMIE_LMOUSE_DOUBLE_CLICK + event.MouseInput.Event - irr::EMIE_LMOUSE_PRESSED_DOWN); + dev->postEventFromUser(event); + } else if (clicks == 3) { + event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT)(irr::EMIE_LMOUSE_TRIPLE_CLICK + event.MouseInput.Event - irr::EMIE_LMOUSE_PRESSED_DOWN); + dev->postEventFromUser(event); + } + } + } + return 0; + } + + switch (message) { + case WM_PAINT: { + PAINTSTRUCT ps; + BeginPaint(hWnd, &ps); + EndPaint(hWnd, &ps); + } + return 0; + + case WM_ERASEBKGND: + return 0; + + case WM_SYSKEYDOWN: + case WM_SYSKEYUP: + case WM_KEYDOWN: + case WM_KEYUP: { + BYTE allKeys[256]; + + event.EventType = irr::EET_KEY_INPUT_EVENT; + event.KeyInput.Key = (irr::EKEY_CODE)wParam; + event.KeyInput.PressedDown = (message == WM_KEYDOWN || message == WM_SYSKEYDOWN); + + if (event.KeyInput.Key == irr::KEY_SHIFT) { + event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey(((lParam >> 16) & 255), MAPVK_VSC_TO_VK_EX); + } + if (event.KeyInput.Key == irr::KEY_CONTROL) { + event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey(((lParam >> 16) & 255), MAPVK_VSC_TO_VK_EX); + // some keyboards will just return LEFT for both - left and right keys. So also check extend bit. + if (lParam & 0x1000000) + event.KeyInput.Key = irr::KEY_RCONTROL; + } + if (event.KeyInput.Key == irr::KEY_MENU) { + event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey(((lParam >> 16) & 255), MAPVK_VSC_TO_VK_EX); + if (lParam & 0x1000000) + event.KeyInput.Key = irr::KEY_RMENU; + } + + GetKeyboardState(allKeys); + + event.KeyInput.Shift = ((allKeys[VK_SHIFT] & 0x80) != 0); + event.KeyInput.Control = ((allKeys[VK_CONTROL] & 0x80) != 0); + + // Handle unicode and deadkeys + WCHAR keyChars[2]; + UINT scanCode = HIWORD(lParam); + int conversionResult = ToUnicodeEx(static_cast(wParam), scanCode, allKeys, keyChars, 2, 0, KEYBOARD_INPUT_HKL); + if (conversionResult == 1) + event.KeyInput.Char = keyChars[0]; + else + event.KeyInput.Char = 0; + + // allow composing characters like '@' with Alt Gr on non-US keyboards + if ((allKeys[VK_MENU] & 0x80) != 0) + event.KeyInput.Control = 0; + + dev = getDeviceFromHWnd(hWnd); + if (dev) + dev->postEventFromUser(event); + + if (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP) + return DefWindowProcW(hWnd, message, wParam, lParam); + else + return 0; + } + + case WM_SIZE: { + // resize + dev = getDeviceFromHWnd(hWnd); + if (dev) + dev->OnResized(); + } + return 0; + + case WM_DESTROY: + PostQuitMessage(0); + return 0; + + case WM_SYSCOMMAND: + // prevent screensaver or monitor powersave mode from starting + if ((wParam & 0xFFF0) == SC_SCREENSAVE || + (wParam & 0xFFF0) == SC_MONITORPOWER || + (wParam & 0xFFF0) == SC_KEYMENU) + return 0; + + break; + + case WM_USER: + event.EventType = irr::EET_USER_EVENT; + event.UserEvent.UserData1 = static_cast(wParam); + event.UserEvent.UserData2 = static_cast(lParam); + dev = getDeviceFromHWnd(hWnd); + + if (dev) + dev->postEventFromUser(event); + + return 0; + + case WM_SETCURSOR: + // because Windows forgot about that in the meantime + dev = getDeviceFromHWnd(hWnd); + if (dev) { + dev->getCursorControl()->setActiveIcon(dev->getCursorControl()->getActiveIcon()); + dev->getCursorControl()->setVisible(dev->getCursorControl()->isVisible()); + } + break; + + case WM_INPUTLANGCHANGE: + // get the new codepage used for keyboard input + KEYBOARD_INPUT_HKL = GetKeyboardLayout(0); + return 0; + } + return DefWindowProcW(hWnd, message, wParam, lParam); +} + +namespace irr +{ + +//! constructor +CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters ¶ms) : + CIrrDeviceStub(params), HWnd(0), Resized(false), + ExternalWindow(false), Win32CursorControl(0), JoyControl(0), + WindowMaximized(params.WindowMaximized) +{ +#ifdef _DEBUG + setDebugName("CIrrDeviceWin32"); +#endif + + // get windows version and create OS operator + core::stringc winversion; + getWindowsVersion(winversion); + Operator = new COSOperator(winversion); + os::Printer::log(winversion.c_str(), ELL_INFORMATION); + + // get handle to exe file + HINSTANCE hInstance = GetModuleHandle(0); + + // create the window if we need to and we do not use the null device + if (!CreationParams.WindowId && CreationParams.DriverType != video::EDT_NULL) { + const wchar_t *ClassName = L"CIrrDeviceWin32"; + + // Register Class + WNDCLASSEXW wcex; + wcex.cbSize = sizeof(WNDCLASSEXW); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = NULL; + wcex.hCursor = 0; // LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszMenuName = 0; + wcex.lpszClassName = ClassName; + wcex.hIconSm = 0; + + RegisterClassExW(&wcex); + + // calculate client size + + RECT clientSize; + clientSize.top = 0; + clientSize.left = 0; + clientSize.right = CreationParams.WindowSize.Width; + clientSize.bottom = CreationParams.WindowSize.Height; + + DWORD style = getWindowStyle(CreationParams.Fullscreen, CreationParams.WindowResizable > 0 ? true : false); + AdjustWindowRect(&clientSize, style, FALSE); + + const s32 realWidth = clientSize.right - clientSize.left; + const s32 realHeight = clientSize.bottom - clientSize.top; + + s32 windowLeft = (CreationParams.WindowPosition.X == -1 ? (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2 : CreationParams.WindowPosition.X); + s32 windowTop = (CreationParams.WindowPosition.Y == -1 ? (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2 : CreationParams.WindowPosition.Y); + + if (windowLeft < 0) + windowLeft = 0; + if (windowTop < 0) + windowTop = 0; // make sure window menus are in screen on creation + + if (CreationParams.Fullscreen) { + windowLeft = 0; + windowTop = 0; + } + + // create window + HWnd = CreateWindowW(ClassName, L"", style, windowLeft, windowTop, + realWidth, realHeight, NULL, NULL, hInstance, NULL); + if (!HWnd) { + os::Printer::log("Window could not be created.", ELL_ERROR); + } + + CreationParams.WindowId = HWnd; + // CreationParams.WindowSize.Width = realWidth; + // CreationParams.WindowSize.Height = realHeight; + + ShowWindow(HWnd, SW_SHOWNORMAL); + UpdateWindow(HWnd); + + // fix ugly ATI driver bugs. Thanks to ariaci + MoveWindow(HWnd, windowLeft, windowTop, realWidth, realHeight, TRUE); + + // make sure everything gets updated to the real sizes + Resized = true; + } else if (CreationParams.WindowId) { + // attach external window + HWnd = static_cast(CreationParams.WindowId); + RECT r; + GetWindowRect(HWnd, &r); + CreationParams.WindowSize.Width = r.right - r.left; + CreationParams.WindowSize.Height = r.bottom - r.top; + CreationParams.Fullscreen = false; + ExternalWindow = true; + } + + // create cursor control + + Win32CursorControl = new CCursorControl(this, CreationParams.WindowSize, HWnd, CreationParams.Fullscreen); + CursorControl = Win32CursorControl; + JoyControl = new SJoystickWin32Control(this); + + // initialize doubleclicks with system values + MouseMultiClicks.DoubleClickTime = GetDoubleClickTime(); + + // create driver + + createDriver(); + + if (VideoDriver) + createGUIAndScene(); + + // register environment + + SEnvMapper em; + em.irrDev = this; + em.hWnd = HWnd; + EnvMap.push_back(em); + + // set this as active window + if (!ExternalWindow) { + SetActiveWindow(HWnd); + SetForegroundWindow(HWnd); + } + + KEYBOARD_INPUT_HKL = GetKeyboardLayout(0); + + // inform driver about the window size etc. + resizeIfNecessary(); + + if (params.WindowMaximized) + maximizeWindow(); +} + +//! destructor +CIrrDeviceWin32::~CIrrDeviceWin32() +{ + delete JoyControl; + + // unregister environment + for (u32 i = 0; i < EnvMap.size(); ++i) { + if (EnvMap[i].hWnd == HWnd) { + EnvMap.erase(i); + break; + } + } +} + +//! create the driver +void CIrrDeviceWin32::createDriver() +{ + switch (CreationParams.DriverType) { + case video::EDT_OPENGL: +#ifdef _IRR_COMPILE_WITH_OPENGL_ + switchToFullScreen(); + + ContextManager = new video::CWGLManager(); + ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd)); + + VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); + + if (!VideoDriver) + os::Printer::log("Could not create OpenGL driver.", ELL_ERROR); +#else + os::Printer::log("OpenGL driver was not compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_OGLES1: +#ifdef _IRR_COMPILE_WITH_OGLES1_ + switchToFullScreen(); + + ContextManager = new video::CEGLManager(); + ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd)); + + VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager); + + if (!VideoDriver) + os::Printer::log("Could not create OpenGL-ES1 driver.", ELL_ERROR); +#else + os::Printer::log("OpenGL-ES1 driver was not compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_OGLES2: +#ifdef _IRR_COMPILE_WITH_OGLES2_ + switchToFullScreen(); + + ContextManager = new video::CEGLManager(); + ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd)); + + VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); + + if (!VideoDriver) + os::Printer::log("Could not create OpenGL-ES2 driver.", ELL_ERROR); +#else + os::Printer::log("OpenGL-ES2 driver was not compiled in.", ELL_ERROR); +#endif + break; + case video::EDT_WEBGL1: + os::Printer::log("WebGL1 driver not supported on Win32 device.", ELL_ERROR); + break; + case video::EDT_NULL: + VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); + break; + default: + os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); + break; + } +} + +//! runs the device. Returns false if device wants to be deleted +bool CIrrDeviceWin32::run() +{ + os::Timer::tick(); + + static_cast(CursorControl)->update(); + + handleSystemMessages(); + + if (!Close) + resizeIfNecessary(); + + if (!Close && JoyControl) + JoyControl->pollJoysticks(); + + return !Close; +} + +//! Pause the current process for the minimum time allowed only to allow other processes to execute +void CIrrDeviceWin32::yield() +{ + Sleep(0); +} + +//! Pause execution and let other processes to run for a specified amount of time. +void CIrrDeviceWin32::sleep(u32 timeMs, bool pauseTimer) +{ + const bool wasStopped = Timer ? Timer->isStopped() : true; + if (pauseTimer && !wasStopped) + Timer->stop(); + + Sleep(timeMs); + + if (pauseTimer && !wasStopped) + Timer->start(); +} + +void CIrrDeviceWin32::resizeIfNecessary() +{ + if (!Resized || !getVideoDriver()) + return; + + RECT r; + GetClientRect(HWnd, &r); + + char tmp[255]; + + if (r.right < 2 || r.bottom < 2) { + snprintf_irr(tmp, sizeof(tmp), "Ignoring resize operation to (%ld %ld)", r.right, r.bottom); + os::Printer::log(tmp); + } else { + snprintf_irr(tmp, sizeof(tmp), "Resizing window (%ld %ld)", r.right, r.bottom); + os::Printer::log(tmp); + + getVideoDriver()->OnResize(irr::core::dimension2du((u32)r.right, (u32)r.bottom)); + getWin32CursorControl()->OnResize(getVideoDriver()->getScreenSize()); + } + + Resized = false; +} + +DWORD CIrrDeviceWin32::getWindowStyle(bool fullscreen, bool resizable) const +{ + if (fullscreen) + return WS_POPUP; + + if (resizable) + return WS_THICKFRAME | WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; + + return WS_BORDER | WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; +} + +//! sets the caption of the window +void CIrrDeviceWin32::setWindowCaption(const wchar_t *text) +{ + // We use SendMessage instead of SetText to ensure proper + // function even in cases where the HWND was created in a different thread + DWORD_PTR dwResult; + SendMessageTimeoutW(HWnd, WM_SETTEXT, 0, + reinterpret_cast(text), + SMTO_ABORTIFHUNG, 2000, &dwResult); +} + +//! Sets the window icon. +bool CIrrDeviceWin32::setWindowIcon(const video::IImage *img) +{ + // Ignore the img, instead load the ICON from resource file + // (This is minetest-specific!) + const HICON hicon = LoadIcon(GetModuleHandle(NULL), + MAKEINTRESOURCE(130) // The ID of the ICON defined in + // winresource.rc + ); + + if (hicon) { + SendMessage(HWnd, WM_SETICON, ICON_BIG, reinterpret_cast(hicon)); + SendMessage(HWnd, WM_SETICON, ICON_SMALL, + reinterpret_cast(hicon)); + return true; + } + return false; +} + +//! notifies the device that it should close itself +void CIrrDeviceWin32::closeDevice() +{ + if (!ExternalWindow) { + MSG msg; + PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); + PostQuitMessage(0); + PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); + DestroyWindow(HWnd); + const wchar_t *ClassName = L"CIrrDeviceWin32"; + HINSTANCE hInstance = GetModuleHandle(0); + UnregisterClassW(ClassName, hInstance); + } + Close = true; +} + +//! returns if window is active. if not, nothing needs to be drawn +bool CIrrDeviceWin32::isWindowActive() const +{ + return (GetActiveWindow() == HWnd); +} + +//! returns if window has focus +bool CIrrDeviceWin32::isWindowFocused() const +{ + bool ret = (GetFocus() == HWnd); + return ret; +} + +//! returns if window is minimized +bool CIrrDeviceWin32::isWindowMinimized() const +{ + WINDOWPLACEMENT plc; + plc.length = sizeof(WINDOWPLACEMENT); + bool ret = false; + if (GetWindowPlacement(HWnd, &plc)) + ret = plc.showCmd == SW_SHOWMINIMIZED; + return ret; +} + +//! returns last state from maximizeWindow() and restoreWindow() +bool CIrrDeviceWin32::isWindowMaximized() const +{ + return WindowMaximized; +} + +//! switches to fullscreen +bool CIrrDeviceWin32::switchToFullScreen() +{ + if (!CreationParams.Fullscreen) + return true; + + // No border, title bar, etc. is already set up through getWindowStyle() + // We only set the window size to match the monitor. + + MONITORINFO mi; + mi.cbSize = sizeof(mi); + if (GetMonitorInfo(MonitorFromWindow(HWnd, MONITOR_DEFAULTTOPRIMARY), &mi)) { + UINT flags = SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_FRAMECHANGED; + SetWindowPos(HWnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, + mi.rcMonitor.right - mi.rcMonitor.left, + mi.rcMonitor.bottom - mi.rcMonitor.top, flags); + } else { + CreationParams.Fullscreen = false; + } + + return CreationParams.Fullscreen; +} + +//! returns the win32 cursor control +CIrrDeviceWin32::CCursorControl *CIrrDeviceWin32::getWin32CursorControl() +{ + return Win32CursorControl; +} + +void CIrrDeviceWin32::getWindowsVersion(core::stringc &out) +{ + OSVERSIONINFO osvi; + + ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osvi); + + char tmp[255]; + snprintf(tmp, sizeof(tmp), "Microsoft Windows %lu.%lu %s", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.szCSDVersion); + out.append(tmp); +} + +//! Notifies the device, that it has been resized +void CIrrDeviceWin32::OnResized() +{ + Resized = true; +} + +//! Resize the render window. +void CIrrDeviceWin32::setWindowSize(const irr::core::dimension2d &size) +{ + if (ExternalWindow || !getVideoDriver() || CreationParams.Fullscreen) + return; + + // get size of the window for the give size of the client area + DWORD style = static_cast(GetWindowLongPtr(HWnd, GWL_STYLE)); + DWORD exStyle = static_cast(GetWindowLongPtr(HWnd, GWL_EXSTYLE)); + RECT clientSize; + clientSize.top = 0; + clientSize.left = 0; + clientSize.right = size.Width; + clientSize.bottom = size.Height; + AdjustWindowRectEx(&clientSize, style, false, exStyle); + const s32 realWidth = clientSize.right - clientSize.left; + const s32 realHeight = clientSize.bottom - clientSize.top; + + UINT flags = SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER; + SetWindowPos(HWnd, HWND_TOP, 0, 0, realWidth, realHeight, flags); +} + +//! Sets if the window should be resizable in windowed mode. +void CIrrDeviceWin32::setResizable(bool resize) +{ + if (ExternalWindow || !getVideoDriver() || CreationParams.Fullscreen) + return; + + LONG_PTR style = (LONG_PTR)getWindowStyle(false, resize); + if (!SetWindowLongPtr(HWnd, GWL_STYLE, style)) + os::Printer::log("Could not change window style."); + + RECT clientSize; + clientSize.top = 0; + clientSize.left = 0; + clientSize.right = getVideoDriver()->getScreenSize().Width; + clientSize.bottom = getVideoDriver()->getScreenSize().Height; + + AdjustWindowRect(&clientSize, static_cast(style), FALSE); + + const s32 realWidth = clientSize.right - clientSize.left; + const s32 realHeight = clientSize.bottom - clientSize.top; + + const s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2; + const s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2; + + SetWindowPos(HWnd, HWND_TOP, windowLeft, windowTop, realWidth, realHeight, + SWP_FRAMECHANGED | SWP_NOMOVE | SWP_SHOWWINDOW); + + static_cast(CursorControl)->updateBorderSize(CreationParams.Fullscreen, resize); +} + +//! Minimizes the window. +void CIrrDeviceWin32::minimizeWindow() +{ + WINDOWPLACEMENT wndpl; + wndpl.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(HWnd, &wndpl); + wndpl.showCmd = SW_SHOWMINNOACTIVE; + SetWindowPlacement(HWnd, &wndpl); +} + +//! Maximizes the window. +void CIrrDeviceWin32::maximizeWindow() +{ + WINDOWPLACEMENT wndpl; + wndpl.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(HWnd, &wndpl); + wndpl.showCmd = SW_SHOWMAXIMIZED; + SetWindowPlacement(HWnd, &wndpl); + + WindowMaximized = true; +} + +//! Restores the window to its original size. +void CIrrDeviceWin32::restoreWindow() +{ + WINDOWPLACEMENT wndpl; + wndpl.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(HWnd, &wndpl); + wndpl.showCmd = SW_SHOWNORMAL; + SetWindowPlacement(HWnd, &wndpl); + + WindowMaximized = false; +} + +core::position2di CIrrDeviceWin32::getWindowPosition() +{ + WINDOWPLACEMENT wndpl; + wndpl.length = sizeof(WINDOWPLACEMENT); + if (GetWindowPlacement(HWnd, &wndpl)) { + return core::position2di((int)wndpl.rcNormalPosition.left, + (int)wndpl.rcNormalPosition.top); + } else { + // No reason for this to happen + os::Printer::log("Failed to retrieve window location", ELL_ERROR); + return core::position2di(-1, -1); + } +} + +bool CIrrDeviceWin32::activateJoysticks(core::array &joystickInfo) +{ + if (JoyControl) + return JoyControl->activateJoysticks(joystickInfo); + else + return false; +} + +//! Process system events +void CIrrDeviceWin32::handleSystemMessages() +{ + MSG msg; + + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (ExternalWindow && msg.hwnd == HWnd) { + if (msg.hwnd == HWnd) { + WndProc(HWnd, msg.message, msg.wParam, msg.lParam); + } else { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } else { + // No message translation because we don't use WM_CHAR and it would conflict with our + // deadkey handling. + DispatchMessage(&msg); + } + + if (msg.message == WM_QUIT) + Close = true; + } +} + +//! Remove all messages pending in the system message loop +void CIrrDeviceWin32::clearSystemMessages() +{ + MSG msg; + while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)) { + } + while (PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE)) { + } +} + +//! Get the display density in dots per inch. +float CIrrDeviceWin32::getDisplayDensity() const +{ + HDC hdc = GetDC(HWnd); + float dpi = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(HWnd, hdc); + return dpi; +} + +// Convert an Irrlicht texture to a Windows cursor +// Based on http://www.codeguru.com/cpp/w-p/win32/cursors/article.php/c4529/ +HCURSOR CIrrDeviceWin32::TextureToCursor(HWND hwnd, irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot) +{ + // + // create the bitmaps needed for cursors from the texture + + HDC dc = GetDC(hwnd); + HDC andDc = CreateCompatibleDC(dc); + HDC xorDc = CreateCompatibleDC(dc); + HBITMAP andBitmap = CreateCompatibleBitmap(dc, sourceRect.getWidth(), sourceRect.getHeight()); + HBITMAP xorBitmap = CreateCompatibleBitmap(dc, sourceRect.getWidth(), sourceRect.getHeight()); + + HBITMAP oldAndBitmap = (HBITMAP)SelectObject(andDc, andBitmap); + HBITMAP oldXorBitmap = (HBITMAP)SelectObject(xorDc, xorBitmap); + + video::ECOLOR_FORMAT format = tex->getColorFormat(); + u32 bytesPerPixel = video::IImage::getBitsPerPixelFromFormat(format) / 8; + u32 bytesLeftGap = sourceRect.UpperLeftCorner.X * bytesPerPixel; + u32 bytesRightGap = tex->getPitch() - sourceRect.LowerRightCorner.X * bytesPerPixel; + const u8 *data = (const u8 *)tex->lock(video::ETLM_READ_ONLY, 0); + data += sourceRect.UpperLeftCorner.Y * tex->getPitch(); + for (s32 y = 0; y < sourceRect.getHeight(); ++y) { + data += bytesLeftGap; + for (s32 x = 0; x < sourceRect.getWidth(); ++x) { + video::SColor pixelCol; + pixelCol.setData((const void *)data, format); + data += bytesPerPixel; + + if (pixelCol.getAlpha() == 0) { // transparent + SetPixel(andDc, x, y, RGB(255, 255, 255)); + SetPixel(xorDc, x, y, RGB(0, 0, 0)); + } else // color + { + SetPixel(andDc, x, y, RGB(0, 0, 0)); + SetPixel(xorDc, x, y, RGB(pixelCol.getRed(), pixelCol.getGreen(), pixelCol.getBlue())); + } + } + data += bytesRightGap; + } + tex->unlock(); + + SelectObject(andDc, oldAndBitmap); + SelectObject(xorDc, oldXorBitmap); + + DeleteDC(xorDc); + DeleteDC(andDc); + + ReleaseDC(hwnd, dc); + + // create the cursor + + ICONINFO iconinfo; + iconinfo.fIcon = false; // type is cursor not icon + iconinfo.xHotspot = hotspot.X; + iconinfo.yHotspot = hotspot.Y; + iconinfo.hbmMask = andBitmap; + iconinfo.hbmColor = xorBitmap; + + HCURSOR cursor = CreateIconIndirect(&iconinfo); + + DeleteObject(andBitmap); + DeleteObject(xorBitmap); + + return cursor; +} + +CIrrDeviceWin32::CCursorControl::CCursorControl(CIrrDeviceWin32 *device, const core::dimension2d &wsize, HWND hwnd, bool fullscreen) : + Device(device), WindowSize(wsize), InvWindowSize(0.0f, 0.0f), + HWnd(hwnd), BorderX(0), BorderY(0), + UseReferenceRect(false), IsVisible(true), ActiveIcon(gui::ECI_NORMAL), ActiveIconStartTime(0) +{ + if (WindowSize.Width != 0) + InvWindowSize.Width = 1.0f / WindowSize.Width; + + if (WindowSize.Height != 0) + InvWindowSize.Height = 1.0f / WindowSize.Height; + + updateBorderSize(fullscreen, false); + initCursors(); +} + +CIrrDeviceWin32::CCursorControl::~CCursorControl() +{ + for (u32 i = 0; i < Cursors.size(); ++i) { + for (u32 f = 0; f < Cursors[i].Frames.size(); ++f) { + DestroyCursor(Cursors[i].Frames[f].IconHW); + } + } +} + +void CIrrDeviceWin32::CCursorControl::initCursors() +{ + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_ARROW))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_CROSS))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_HAND))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_HELP))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_IBEAM))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_NO))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_WAIT))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_SIZEALL))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_SIZENESW))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_SIZENWSE))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_SIZENS))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_SIZEWE))); + Cursors.push_back(CursorW32(LoadCursor(NULL, IDC_UPARROW))); +} + +void CIrrDeviceWin32::CCursorControl::update() +{ + if (!Cursors[ActiveIcon].Frames.empty() && Cursors[ActiveIcon].FrameTime) { + // update animated cursors. This could also be done by X11 in case someone wants to figure that out (this way was just easier to implement) + u32 now = Device->getTimer()->getRealTime(); + u32 frame = ((now - ActiveIconStartTime) / Cursors[ActiveIcon].FrameTime) % Cursors[ActiveIcon].Frames.size(); + SetCursor(Cursors[ActiveIcon].Frames[frame].IconHW); + } +} + +//! Sets the active cursor icon +void CIrrDeviceWin32::CCursorControl::setActiveIcon(gui::ECURSOR_ICON iconId) +{ + if (iconId >= (s32)Cursors.size()) + return; + + ActiveIcon = iconId; + ActiveIconStartTime = Device->getTimer()->getRealTime(); + if (Cursors[ActiveIcon].Frames.size()) + SetCursor(Cursors[ActiveIcon].Frames[0].IconHW); +} + +//! Add a custom sprite as cursor icon. +gui::ECURSOR_ICON CIrrDeviceWin32::CCursorControl::addIcon(const gui::SCursorSprite &icon) +{ + if (icon.SpriteId >= 0) { + CursorW32 cW32; + cW32.FrameTime = icon.SpriteBank->getSprites()[icon.SpriteId].frameTime; + + for (u32 i = 0; i < icon.SpriteBank->getSprites()[icon.SpriteId].Frames.size(); ++i) { + irr::u32 texId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].textureNumber; + irr::u32 rectId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].rectNumber; + irr::core::rect rectIcon = icon.SpriteBank->getPositions()[rectId]; + + HCURSOR hc = Device->TextureToCursor(HWnd, icon.SpriteBank->getTexture(texId), rectIcon, icon.HotSpot); + cW32.Frames.push_back(CursorFrameW32(hc)); + } + + Cursors.push_back(cW32); + return (gui::ECURSOR_ICON)(Cursors.size() - 1); + } + return gui::ECI_NORMAL; +} + +//! replace the given cursor icon. +void CIrrDeviceWin32::CCursorControl::changeIcon(gui::ECURSOR_ICON iconId, const gui::SCursorSprite &icon) +{ + if (iconId >= (s32)Cursors.size()) + return; + + for (u32 i = 0; i < Cursors[iconId].Frames.size(); ++i) + DestroyCursor(Cursors[iconId].Frames[i].IconHW); + + if (icon.SpriteId >= 0) { + CursorW32 cW32; + cW32.FrameTime = icon.SpriteBank->getSprites()[icon.SpriteId].frameTime; + for (u32 i = 0; i < icon.SpriteBank->getSprites()[icon.SpriteId].Frames.size(); ++i) { + irr::u32 texId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].textureNumber; + irr::u32 rectId = icon.SpriteBank->getSprites()[icon.SpriteId].Frames[i].rectNumber; + irr::core::rect rectIcon = icon.SpriteBank->getPositions()[rectId]; + + HCURSOR hc = Device->TextureToCursor(HWnd, icon.SpriteBank->getTexture(texId), rectIcon, icon.HotSpot); + cW32.Frames.push_back(CursorFrameW32(hc)); + } + + Cursors[iconId] = cW32; + } +} + +//! Return a system-specific size which is supported for cursors. Larger icons will fail, smaller icons might work. +core::dimension2di CIrrDeviceWin32::CCursorControl::getSupportedIconSize() const +{ + core::dimension2di result; + + result.Width = GetSystemMetrics(SM_CXCURSOR); + result.Height = GetSystemMetrics(SM_CYCURSOR); + + return result; +} + +} // end namespace + +#endif // _IRR_COMPILE_WITH_WINDOWS_DEVICE_ diff --git a/irr/src/CIrrDeviceWin32.h b/irr/src/CIrrDeviceWin32.h new file mode 100644 index 000000000..8a4c14276 --- /dev/null +++ b/irr/src/CIrrDeviceWin32.h @@ -0,0 +1,405 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ + +#include "CIrrDeviceStub.h" +#include "IrrlichtDevice.h" + +#define WIN32_LEAN_AND_MEAN +#include +#include // For JOYCAPS +#include +#if !defined(GET_X_LPARAM) +#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) +#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) +#endif + +namespace irr +{ +struct SJoystickWin32Control; + +class CIrrDeviceWin32 : public CIrrDeviceStub +{ + friend struct SJoystickWin32Control; + +public: + //! constructor + CIrrDeviceWin32(const SIrrlichtCreationParameters ¶ms); + + //! destructor + virtual ~CIrrDeviceWin32(); + + //! runs the device. Returns false if device wants to be deleted + bool run() override; + + //! Cause the device to temporarily pause execution and let other processes to run + // This should bring down processor usage without major performance loss for Irrlicht + void yield() override; + + //! Pause execution and let other processes to run for a specified amount of time. + void sleep(u32 timeMs, bool pauseTimer) override; + + //! sets the caption of the window + void setWindowCaption(const wchar_t *text) override; + + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + + //! returns if window is active. if not, nothing need to be drawn + bool isWindowActive() const override; + + //! returns if window has focus + bool isWindowFocused() const override; + + //! returns if window is minimized + bool isWindowMinimized() const override; + + //! returns last state from maximizeWindow() and restoreWindow() + bool isWindowMaximized() const override; + + //! notifies the device that it should close itself + void closeDevice() override; + + //! Notifies the device, that it has been resized + /** Must be publis as it is called from free function (event handler) */ + void OnResized(); + + //! Sets if the window should be resizable in windowed mode. + void setResizable(bool resize = false) override; + + //! Resize the render window. + void setWindowSize(const irr::core::dimension2d &size) override; + + //! Minimizes the window. + void minimizeWindow() override; + + //! Maximizes the window. + void maximizeWindow() override; + + //! Restores the window size. + void restoreWindow() override; + + //! Get the position of the window on screen + core::position2di getWindowPosition() override; + + //! Activate any joysticks, and generate events for them. + bool activateJoysticks(core::array &joystickInfo) override; + + //! Remove all messages pending in the system message loop + void clearSystemMessages() override; + + //! Get the device type + E_DEVICE_TYPE getType() const override + { + return EIDT_WIN32; + } + + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + + //! Compares to the last call of this function to return double and triple clicks. + //! \return Returns only 1,2 or 3. A 4th click will start with 1 again. + u32 checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent) override + { + // we just have to make it public + return CIrrDeviceStub::checkSuccessiveClicks(mouseX, mouseY, inputEvent); + } + + //! Switch to fullscreen + bool switchToFullScreen(); + + // convert an Irrlicht texture to a windows cursor + HCURSOR TextureToCursor(HWND hwnd, irr::video::ITexture *tex, const core::rect &sourceRect, const core::position2d &hotspot); + + //! Implementation of the win32 cursor control + class CCursorControl : public gui::ICursorControl + { + public: + CCursorControl(CIrrDeviceWin32 *device, const core::dimension2d &wsize, HWND hwnd, bool fullscreen); + ~CCursorControl(); + + //! Changes the visible state of the mouse cursor. + void setVisible(bool visible) override + { + CURSORINFO info; + info.cbSize = sizeof(CURSORINFO); + BOOL gotCursorInfo = GetCursorInfo(&info); + while (gotCursorInfo) { +#ifdef CURSOR_SUPPRESSED + // Since Windows 8 the cursor can be suppressed by a touch interface + if (visible && info.flags == CURSOR_SUPPRESSED) { + break; + } +#endif + if ((visible && info.flags == CURSOR_SHOWING) || // visible + (!visible && info.flags == 0)) // hidden + { + break; + } + // this only increases an internal + // display counter in windows, so it + // might have to be called some more + const int showResult = ShowCursor(visible); + // if result has correct sign we can + // stop here as well + if ((!visible && showResult < 0) || + (visible && showResult >= 0)) + break; + // yes, it really must be set each time + info.cbSize = sizeof(CURSORINFO); + gotCursorInfo = GetCursorInfo(&info); + +#ifdef CURSOR_SUPPRESSED + // Not sure if a cursor which we tried to hide still can be suppressed. + // I have no touch-display for testing this and MSDN doesn't describe it. + // But adding this check shouldn't hurt and might prevent an endless loop. + if (!visible && info.flags == CURSOR_SUPPRESSED) { + break; + } +#endif + } + IsVisible = visible; + } + + //! Returns if the cursor is currently visible. + bool isVisible() const override + { + return IsVisible; + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(f32 x, f32 y) override + { + if (!UseReferenceRect) + setPosition(core::round32(x * WindowSize.Width), core::round32(y * WindowSize.Height)); + else + setPosition(core::round32(x * ReferenceRect.getWidth()), core::round32(y * ReferenceRect.getHeight())); + } + + //! Sets the new position of the cursor. + void setPosition(const core::position2d &pos) override + { + setPosition(pos.X, pos.Y); + } + + //! Sets the new position of the cursor. + void setPosition(s32 x, s32 y) override + { + if (UseReferenceRect) { + SetCursorPos(ReferenceRect.UpperLeftCorner.X + x, + ReferenceRect.UpperLeftCorner.Y + y); + } else { + RECT rect; + if (GetWindowRect(HWnd, &rect)) + SetCursorPos(x + rect.left + BorderX, y + rect.top + BorderY); + } + + CursorPos.X = x; + CursorPos.Y = y; + } + + //! Returns the current position of the mouse cursor. + const core::position2d &getPosition(bool updateCursor) override + { + if (updateCursor) + updateInternalCursorPosition(); + return CursorPos; + } + + //! Returns the current position of the mouse cursor. + core::position2d getRelativePosition(bool updateCursor) override + { + if (updateCursor) + updateInternalCursorPosition(); + + if (!UseReferenceRect) { + return core::position2d(CursorPos.X * InvWindowSize.Width, + CursorPos.Y * InvWindowSize.Height); + } + + return core::position2d(CursorPos.X / (f32)ReferenceRect.getWidth(), + CursorPos.Y / (f32)ReferenceRect.getHeight()); + } + + //! Sets an absolute reference rect for calculating the cursor position. + void setReferenceRect(core::rect *rect = 0) override + { + if (rect) { + ReferenceRect = *rect; + UseReferenceRect = true; + + // prevent division through zero and uneven sizes + + if (!ReferenceRect.getHeight() || ReferenceRect.getHeight() % 2) + ReferenceRect.LowerRightCorner.Y += 1; + + if (!ReferenceRect.getWidth() || ReferenceRect.getWidth() % 2) + ReferenceRect.LowerRightCorner.X += 1; + } else + UseReferenceRect = false; + } + + /** Used to notify the cursor that the window was resized. */ + void OnResize(const core::dimension2d &size) + { + WindowSize = size; + if (size.Width != 0) + InvWindowSize.Width = 1.0f / size.Width; + else + InvWindowSize.Width = 0.f; + + if (size.Height != 0) + InvWindowSize.Height = 1.0f / size.Height; + else + InvWindowSize.Height = 0.f; + } + + /** Used to notify the cursor that the window resizable settings changed. */ + void updateBorderSize(bool fullscreen, bool resizable) + { + if (!fullscreen) { + s32 paddingBorder = 0; +#ifdef SM_CXPADDEDBORDER + paddingBorder = GetSystemMetrics(SM_CXPADDEDBORDER); +#endif + + if (resizable) { + BorderX = GetSystemMetrics(SM_CXSIZEFRAME) + paddingBorder; + BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYSIZEFRAME) + paddingBorder; + } else { + BorderX = GetSystemMetrics(SM_CXDLGFRAME) + paddingBorder; + BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYDLGFRAME) + paddingBorder; + } + } else { + BorderX = BorderY = 0; + } + } + + //! Sets the active cursor icon + void setActiveIcon(gui::ECURSOR_ICON iconId) override; + + //! Gets the currently active icon + gui::ECURSOR_ICON getActiveIcon() const override + { + return ActiveIcon; + } + + //! Add a custom sprite as cursor icon. + gui::ECURSOR_ICON addIcon(const gui::SCursorSprite &icon) override; + + //! replace the given cursor icon. + void changeIcon(gui::ECURSOR_ICON iconId, const gui::SCursorSprite &icon) override; + + //! Return a system-specific size which is supported for cursors. Larger icons will fail, smaller icons might work. + core::dimension2di getSupportedIconSize() const override; + + void update(); + + private: + //! Updates the internal cursor position + void updateInternalCursorPosition() + { + POINT p; + if (!GetCursorPos(&p)) { + DWORD xy = GetMessagePos(); + p.x = GET_X_LPARAM(xy); + p.y = GET_Y_LPARAM(xy); + } + + if (UseReferenceRect) { + CursorPos.X = p.x - ReferenceRect.UpperLeftCorner.X; + CursorPos.Y = p.y - ReferenceRect.UpperLeftCorner.Y; + } else { + RECT rect; + if (GetWindowRect(HWnd, &rect)) { + CursorPos.X = p.x - rect.left - BorderX; + CursorPos.Y = p.y - rect.top - BorderY; + } else { + // window seems not to be existent, so set cursor to + // a negative value + CursorPos.X = -1; + CursorPos.Y = -1; + } + } + } + + CIrrDeviceWin32 *Device; + core::position2d CursorPos; + core::dimension2d WindowSize; + core::dimension2d InvWindowSize; + HWND HWnd; + + s32 BorderX, BorderY; + core::rect ReferenceRect; + bool UseReferenceRect; + bool IsVisible; + + struct CursorFrameW32 + { + CursorFrameW32() : + IconHW(0) {} + CursorFrameW32(HCURSOR icon) : + IconHW(icon) {} + + HCURSOR IconHW; // hardware cursor + }; + + struct CursorW32 + { + CursorW32() {} + explicit CursorW32(HCURSOR iconHw, u32 frameTime = 0) : + FrameTime(frameTime) + { + Frames.push_back(CursorFrameW32(iconHw)); + } + core::array Frames; + u32 FrameTime; + }; + + core::array Cursors; + gui::ECURSOR_ICON ActiveIcon; + u32 ActiveIconStartTime; + + void initCursors(); + }; + + //! returns the win32 cursor control + CCursorControl *getWin32CursorControl(); + +private: + //! create the driver + void createDriver(); + + //! Process system events + void handleSystemMessages(); + + void getWindowsVersion(core::stringc &version); + + void resizeIfNecessary(); + + DWORD getWindowStyle(bool fullscreen, bool resizable) const; + + HWND HWnd; + + bool Resized; + bool ExternalWindow; + CCursorControl *Win32CursorControl; + + SJoystickWin32Control *JoyControl; + + bool WindowMaximized; +}; + +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_WINDOWS_DEVICE_ diff --git a/irr/src/CLimitReadFile.cpp b/irr/src/CLimitReadFile.cpp new file mode 100644 index 000000000..de9bf9ec3 --- /dev/null +++ b/irr/src/CLimitReadFile.cpp @@ -0,0 +1,115 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CLimitReadFile.h" +#include "irrMath.h" +#include "irrString.h" + +namespace irr +{ +namespace io +{ + +CLimitReadFile::CLimitReadFile(IReadFile *alreadyOpenedFile, long pos, + long areaSize, const io::path &name) : + Filename(name), + AreaStart(0), AreaEnd(0), Pos(0), + File(alreadyOpenedFile) +{ +#ifdef _DEBUG + setDebugName("CLimitReadFile"); +#endif + + if (File) { + File->grab(); + AreaStart = pos; + AreaEnd = AreaStart + areaSize; + } +} + +CLimitReadFile::~CLimitReadFile() +{ + if (File) + File->drop(); +} + +//! returns how much was read +size_t CLimitReadFile::read(void *buffer, size_t sizeToRead) +{ + if (0 == File) + return 0; + +#if 1 + long r = AreaStart + Pos; + long toRead = core::min_(AreaEnd, r + (long)sizeToRead) - core::max_(AreaStart, r); + if (toRead < 0) + return 0; + File->seek(r); + r = (long)File->read(buffer, toRead); + Pos += r; + return r; +#else + const long pos = File->getPos(); + + if (pos >= AreaEnd) + return 0; + + if (pos + (long)sizeToRead >= AreaEnd) + sizeToRead = AreaEnd - pos; + + return File->read(buffer, sizeToRead); +#endif +} + +//! changes position in file, returns true if successful +bool CLimitReadFile::seek(long finalPos, bool relativeMovement) +{ +#if 1 + Pos = core::s32_clamp(finalPos + (relativeMovement ? Pos : 0), 0, AreaEnd - AreaStart); + return true; +#else + const long pos = File->getPos(); + + if (relativeMovement) { + if (pos + finalPos > AreaEnd) + finalPos = AreaEnd - pos; + } else { + finalPos += AreaStart; + if (finalPos > AreaEnd) + return false; + } + + return File->seek(finalPos, relativeMovement); +#endif +} + +//! returns size of file +long CLimitReadFile::getSize() const +{ + return AreaEnd - AreaStart; +} + +//! returns where in the file we are. +long CLimitReadFile::getPos() const +{ +#if 1 + return Pos; +#else + return File->getPos() - AreaStart; +#endif +} + +//! returns name of file +const io::path &CLimitReadFile::getFileName() const +{ + return Filename; +} + +IReadFile *createLimitReadFile(const io::path &fileName, IReadFile *alreadyOpenedFile, long pos, long areaSize) +{ + return new CLimitReadFile(alreadyOpenedFile, pos, areaSize, fileName); +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CLimitReadFile.h b/irr/src/CLimitReadFile.h new file mode 100644 index 000000000..1594135e6 --- /dev/null +++ b/irr/src/CLimitReadFile.h @@ -0,0 +1,62 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IReadFile.h" +#include "irrString.h" + +namespace irr +{ +class CUnicodeConverter; + +namespace io +{ + +/*! this is a read file, which is limited to some boundaries, + so that it may only start from a certain file position + and may only read until a certain file position. + This can be useful, for example for reading uncompressed files + in an archive (zip, tar). +!*/ +class CLimitReadFile : public IReadFile +{ +public: + CLimitReadFile(IReadFile *alreadyOpenedFile, long pos, long areaSize, const io::path &name); + + virtual ~CLimitReadFile(); + + //! returns how much was read + size_t read(void *buffer, size_t sizeToRead) override; + + //! changes position in file, returns true if successful + //! if relativeMovement==true, the pos is changed relative to current pos, + //! otherwise from begin of file + bool seek(long finalPos, bool relativeMovement = false) override; + + //! returns size of file + long getSize() const override; + + //! returns where in the file we are. + long getPos() const override; + + //! returns name of file + const io::path &getFileName() const override; + + //! Get the type of the class implementing this interface + EREAD_FILE_TYPE getType() const override + { + return ERFT_LIMIT_READ_FILE; + } + +private: + io::path Filename; + long AreaStart; + long AreaEnd; + long Pos; + IReadFile *File; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CLogger.cpp b/irr/src/CLogger.cpp new file mode 100644 index 000000000..70d06b36a --- /dev/null +++ b/irr/src/CLogger.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CLogger.h" + +namespace irr +{ + +CLogger::CLogger(IEventReceiver *r) : + LogLevel(ELL_INFORMATION), Receiver(r) +{ +#ifdef _DEBUG + setDebugName("CLogger"); +#endif +} + +//! Returns the current set log level. +ELOG_LEVEL CLogger::getLogLevel() const +{ + return LogLevel; +} + +//! Sets a new log level. +void CLogger::setLogLevel(ELOG_LEVEL ll) +{ + LogLevel = ll; +} + +//! Prints out a text into the log +void CLogger::log(const c8 *text, ELOG_LEVEL ll) +{ + if (ll < LogLevel) + return; + + if (Receiver) { + SEvent event; + event.EventType = EET_LOG_TEXT_EVENT; + event.LogEvent.Text = text; + event.LogEvent.Level = ll; + if (Receiver->OnEvent(event)) + return; + } + + os::Printer::print(text); +} + +//! Prints out a text into the log +void CLogger::log(const c8 *text, const c8 *hint, ELOG_LEVEL ll) +{ + if (ll < LogLevel) + return; + + core::stringc s = text; + s += ": "; + s += hint; + log(s.c_str(), ll); +} + +//! Sets a new event receiver +void CLogger::setReceiver(IEventReceiver *r) +{ + Receiver = r; +} + +} // end namespace irr diff --git a/irr/src/CLogger.h b/irr/src/CLogger.h new file mode 100644 index 000000000..e9cfae8fc --- /dev/null +++ b/irr/src/CLogger.h @@ -0,0 +1,41 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "ILogger.h" +#include "os.h" +#include "irrString.h" +#include "IEventReceiver.h" + +namespace irr +{ + +//! Class for logging messages, warnings and errors to stdout +class CLogger : public ILogger +{ +public: + CLogger(IEventReceiver *r); + + //! Returns the current set log level. + ELOG_LEVEL getLogLevel() const override; + + //! Sets a new log level. void setLogLevel(ELOG_LEVEL ll) override; + void setLogLevel(ELOG_LEVEL ll) override; + + //! Prints out a text into the log + void log(const c8 *text, ELOG_LEVEL ll = ELL_INFORMATION) override; + + //! Prints out a text into the log + void log(const c8 *text, const c8 *hint, ELOG_LEVEL ll = ELL_INFORMATION) override; + + //! Sets a new event receiver + void setReceiver(IEventReceiver *r); + +private: + ELOG_LEVEL LogLevel; + IEventReceiver *Receiver; +}; + +} // end namespace diff --git a/irr/src/CMakeLists.txt b/irr/src/CMakeLists.txt new file mode 100644 index 000000000..46eaf9cca --- /dev/null +++ b/irr/src/CMakeLists.txt @@ -0,0 +1,580 @@ +if(NOT ANDROID AND NOT APPLE) + set(DEFAULT_SDL2 ON) +endif() + +option(BUILD_SHARED_LIBS "Build shared library" TRUE) +option(USE_SDL2 "Use the SDL2 backend" ${DEFAULT_SDL2}) + +# Compiler flags + +add_definitions(-DIRRLICHT_EXPORTS) +if(BUILD_SHARED_LIBS) + if(WIN32) + set(API_IMPORT "__declspec(dllimport)") + set(API_EXPORT "__declspec(dllexport)") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + set(API_EXPORT "__attribute__ ((visibility(\"default\")))") # only necessary if default visibility is set to hidden + endif() +else() + add_definitions(-D_IRR_STATIC_LIB_) +endif() +add_definitions("-DIRRLICHT_API=${API_EXPORT}") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-D_DEBUG) +endif() +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + +if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + set(CMAKE_CXX_FLAGS_RELEASE "-O3") + set(CMAKE_CXX_FLAGS_DEBUG "-g") + + add_compile_options(-Wall -pipe -fno-exceptions) + + # Enable SSE for floating point math on 32-bit x86 by default + # reasoning see minetest issue #11810 and https://gcc.gnu.org/wiki/FloatingPointMath + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + include(CheckCXXSourceCompiles) + check_cxx_source_compiles("#ifndef __i686__\n#error\n#endif\nint main(){}" IS_I686) + if(IS_I686) + message(STATUS "Detected Intel x86: using SSE instead of x87 FPU") + add_compile_options(-mfpmath=sse -msse) + endif() + endif() + +elseif(MSVC) + string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " msvcrt.lib") # ???? fuck off + + add_compile_options(/GR- /Zl) + + # Enable SSE for floating point math on 32-bit x86 by default + # reasoning see minetest issue #11810 and https://gcc.gnu.org/wiki/FloatingPointMath + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + add_compile_options(/arch:SSE) + endif() + + add_compile_options(/D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) +endif() + +# Sanity-check version + +include(CheckCXXSourceCompiles) +set(CMAKE_REQUIRED_INCLUDES ${PROJECT_SOURCE_DIR}/include) +unset(REVISION_SANITY_CHECK CACHE) +check_cxx_source_compiles("#include \n\ +#if IRRLICHT_VERSION_MT_REVISION != ${IRRLICHTMT_REVISION}\n\ +#error\n\ +#endif\n\ +int main() {}" REVISION_SANITY_CHECK) +if(NOT REVISION_SANITY_CHECK) + message(FATAL_ERROR "IrrlichtMt revision number mismatches between CMake and headers.") +endif() + +# Platform-independent configuration (hard-coded currently) +add_definitions( + -DIRR_ENABLE_BUILTIN_FONT +) + +# Platform-specific configuration + +if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") + set(SOLARIS TRUE) +endif() + +# Device + +if(WIN32) + add_definitions(-D_IRR_WINDOWS_ -D_IRR_WINDOWS_API_) + set(DEVICE "WINDOWS") +elseif(APPLE) + add_definitions(-D_IRR_OSX_PLATFORM_) + set(DEVICE "OSX") +elseif(ANDROID) + add_definitions(-D_IRR_ANDROID_PLATFORM_) + if(USE_SDL2) + message(FATAL_ERROR "SDL2 device is not (yet) supported on Android") + endif() + set(DEVICE "ANDROID") +elseif(EMSCRIPTEN) + add_definitions(-D_IRR_EMSCRIPTEN_PLATFORM_ -D_IRR_COMPILE_WITH_EGL_MANAGER_) + set(LINUX_PLATFORM TRUE) + set(DEVICE "SDL") +elseif(SOLARIS) + add_definitions(-D_IRR_SOLARIS_PLATFORM_ -D_IRR_POSIX_API_) + set(DEVICE "X11") +else() + add_definitions(-D_IRR_POSIX_API_) + set(LINUX_PLATFORM TRUE) + set(DEVICE "X11") +endif() + +if(LINUX_PLATFORM) + add_definitions(-D_IRR_LINUX_PLATFORM_) +endif() + +if(USE_SDL2) + set(DEVICE "SDL") +elseif(DEVICE STREQUAL "SDL") + message(FATAL_ERROR "SDL was used but not enabled?!") +endif() + +add_definitions("-D_IRR_COMPILE_WITH_${DEVICE}_DEVICE_") + +# X11 + +if(DEVICE STREQUAL "X11") + option(USE_X11 "Use X11" TRUE) +else() + set(USE_X11 FALSE) +endif() + +if(LINUX_PLATFORM AND USE_X11) + option(USE_XINPUT2 "Use XInput2" TRUE) + option(USE_XCURSOR "Use XCursor" FALSE) +else() + set(USE_XINPUT2 FALSE) + set(USE_XCURSOR FALSE) +endif() + +# Joystick + +if(NOT (BSD OR SOLARIS OR EMSCRIPTEN)) + add_definitions(-D_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) +endif() + +# OpenGL + +if(USE_SDL2) + option(ENABLE_OPENGL3 "Enable OpenGL 3+" TRUE) +else() + set(ENABLE_OPENGL3 FALSE) +endif() + +if(ANDROID OR EMSCRIPTEN) + set(ENABLE_OPENGL FALSE) +else() + option(ENABLE_OPENGL "Enable OpenGL" TRUE) +endif() + +if(EMSCRIPTEN OR APPLE) + set(ENABLE_GLES1 FALSE) +else() + if(ANDROID) + set(DEFAULT_GLES1 TRUE) + endif() + option(ENABLE_GLES1 "Enable OpenGL ES" ${DEFAULT_GLES1}) +endif() + +if(APPLE) + set(ENABLE_GLES2 FALSE) + set(ENABLE_WEBGL1 FALSE) +else() + if(ANDROID OR EMSCRIPTEN) + set(DEFAULT_GLES2 TRUE) + endif() + if(EMSCRIPTEN) + set(DEFAULT_WEBGL1 TRUE) + endif() + option(ENABLE_GLES2 "Enable OpenGL ES 2+" ${DEFAULT_GLES2}) + #option(ENABLE_WEBGL1 "Enable WebGL (requires GLES2)" ${DEFAULT_WEBGL1}) + set(ENABLE_WEBGL1 FALSE) # not working currently + if(ENABLE_WEBGL1) + set(ENABLE_GLES2 TRUE) + endif() +endif() + +if(ENABLE_OPENGL) + add_definitions(-D_IRR_COMPILE_WITH_OPENGL_) + set(OPENGL_DIRECT_LINK TRUE) # driver relies on this + if(DEVICE STREQUAL "WINDOWS") + add_definitions(-D_IRR_COMPILE_WITH_WGL_MANAGER_) + elseif(DEVICE STREQUAL "X11") + add_definitions(-D_IRR_COMPILE_WITH_GLX_MANAGER_) + elseif(DEVICE STREQUAL "OSX") + add_definitions(-D_IRR_COMPILE_WITH_NSOGL_MANAGER_) + endif() +endif() + +if(ENABLE_OPENGL3) + if (NOT USE_SDL2) + message(FATAL_ERROR "OpenGL 3 driver requires SDL2") + endif() +endif() + +if(ENABLE_GLES1) + if (USE_SDL2) + message(FATAL_ERROR "OpenGL ES 1 is not supported with SDL2") + endif() + add_definitions(-D_IRR_COMPILE_WITH_OGLES1_) + set(OPENGLES_DIRECT_LINK TRUE) + if(DEVICE MATCHES "^(WINDOWS|X11|ANDROID)$") + add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_) + endif() +endif() + +if(ENABLE_GLES2) + add_definitions(-D_IRR_COMPILE_WITH_OGLES2_) + if(DEVICE MATCHES "^(WINDOWS|X11|ANDROID)$" OR EMSCRIPTEN) + add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_) + endif() +endif() + +if(ENABLE_WEBGL1) + add_definitions(-D_IRR_COMPILE_WITH_WEBGL1_) +endif() + +# Misc + +include(TestBigEndian) +TEST_BIG_ENDIAN(BIG_ENDIAN) +if(BIG_ENDIAN) + add_definitions(-D__BIG_ENDIAN__) +endif() + +# Configuration report + +message(STATUS "Device: ${DEVICE}") +message(STATUS "OpenGL: ${ENABLE_OPENGL}") +message(STATUS "OpenGL 3: ${ENABLE_OPENGL3}") +message(STATUS "OpenGL ES: ${ENABLE_GLES1}") +if (ENABLE_GLES2) + message(STATUS "OpenGL ES 2: ON (unified)") +else() + message(STATUS "OpenGL ES 2: OFF") +endif() +#message(STATUS "WebGL: ${ENABLE_WEBGL1}") + +# Required libs + +find_package(ZLIB REQUIRED) +find_package(JPEG REQUIRED) +find_package(PNG REQUIRED) + + +if(ENABLE_GLES1) + # only tested on Android, probably works on Linux (is this needed anywhere else?) + find_library(OPENGLES_LIBRARY NAMES GLESv1_CM REQUIRED) + find_library(EGL_LIBRARY NAMES EGL REQUIRED) + + message(STATUS "Found OpenGLES: ${OPENGLES_LIBRARY}") +endif() +if(ENABLE_GLES2) + find_package(OpenGLES2 REQUIRED) +endif() +if(ENABLE_OPENGL OR ENABLE_OPENGL3) + find_package(OpenGL REQUIRED) +endif() +if(USE_SDL2) + find_package(SDL2 REQUIRED) + message(STATUS "Found SDL2: ${SDL2_LIBRARIES}") + + # unfortunately older SDL does not provide its version to cmake, so check header. + set(CMAKE_REQUIRED_INCLUDES ${SDL2_INCLUDE_DIRS}) + unset(CHECK_SDL_VERSION CACHE) + check_cxx_source_compiles("#include \n\ +#if !SDL_VERSION_ATLEAST(2, 0, 10)\n\ +#error\n\ +#endif\n\ +int main() {}" CHECK_SDL_VERSION) + if(NOT CHECK_SDL_VERSION) + message(FATAL_ERROR "SDL2 is too old, required is at least 2.0.10!") + endif() + + # ...no target either. + if(NOT TARGET SDL2::SDL2) + add_library(SDL2::SDL2 SHARED IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARIES}") + endif() +endif() + +# More special config + +if(ENABLE_OPENGL AND DEVICE STREQUAL "SDL") + # The legacy GL driver requires some symbols from GL 4.5 to compile, + # which SDL only provides since 2.26.0 (Nov 2022). + # We have a fallback in case this isn't satisfied so test for it. + set(CMAKE_REQUIRED_INCLUDES ${SDL2_INCLUDE_DIRS}) + unset(CHECK_GL_VERSION_4_5 CACHE) + check_cxx_source_compiles("#include \n\ +#ifndef GL_VERSION_4_5\n\ +#error\n\ +#endif\n\ +int main() {}" CHECK_GL_VERSION_4_5) + if(CHECK_GL_VERSION_4_5) + add_definitions(-DIRR_PREFER_SDL_GL_HEADER) + endif() +endif() + +# Platform-specific libs + +if(ANDROID) + enable_language(C) +elseif(APPLE) + find_library(COCOA_LIB Cocoa REQUIRED) + find_library(IOKIT_LIB IOKit REQUIRED) + + add_definitions(-DGL_SILENCE_DEPRECATION) +elseif(NOT USE_SDL2) + # Unix probably + find_package(X11 REQUIRED) + if(USE_XINPUT2 AND NOT X11_Xi_FOUND) + message(FATAL_ERROR "XInput not found") + endif() +endif() + +set(link_includes + "${PROJECT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}" + + "${ZLIB_INCLUDE_DIR}" + "${JPEG_INCLUDE_DIR}" + "${PNG_INCLUDE_DIR}" + "$<$:${SDL2_INCLUDE_DIRS}>" + + ${OPENGL_INCLUDE_DIR} + ${OPENGLES2_INCLUDE_DIR} + ${EGL_INCLUDE_DIR} + + "$<$:${ANDROID_NDK}/sources/android/native_app_glue>" + "$<$:${X11_INCLUDE_DIR}>" +) + +# Source files + +set(IRRMESHLOADER + CB3DMeshFileLoader.cpp + COBJMeshFileLoader.cpp + CXMeshFileLoader.cpp +) + +add_library(IRRMESHOBJ OBJECT + CSkinnedMesh.cpp + CBoneSceneNode.cpp + CMeshSceneNode.cpp + CAnimatedMeshSceneNode.cpp + ${IRRMESHLOADER} +) + +add_library(IRROBJ OBJECT + CBillboardSceneNode.cpp + CCameraSceneNode.cpp + CDummyTransformationSceneNode.cpp + CEmptySceneNode.cpp + CMeshManipulator.cpp + CSceneCollisionManager.cpp + CSceneManager.cpp + CMeshCache.cpp +) + +set(IRRDRVROBJ + CNullDriver.cpp + CGLXManager.cpp + CWGLManager.cpp + CEGLManager.cpp + CSDLManager.cpp + mt_opengl_loader.cpp +) + +# the two legacy drivers + +if(ENABLE_OPENGL) + set(IRRDRVROBJ + ${IRRDRVROBJ} + COpenGLCacheHandler.cpp + COpenGLDriver.cpp + COpenGLSLMaterialRenderer.cpp + COpenGLExtensionHandler.cpp + ) +endif() + +if(ENABLE_GLES1) + set(IRRDRVROBJ + ${IRRDRVROBJ} + COGLESDriver.cpp + COGLESExtensionHandler.cpp + ) +endif() + +# the unified drivers + +if(ENABLE_OPENGL3 OR ENABLE_GLES2) + set(IRRDRVROBJ + ${IRRDRVROBJ} + OpenGL/Driver.cpp + OpenGL/ExtensionHandler.cpp + OpenGL/FixedPipelineRenderer.cpp + OpenGL/MaterialRenderer.cpp + OpenGL/Renderer2D.cpp + ) +endif() + +if(ENABLE_OPENGL3) + set(IRRDRVROBJ + ${IRRDRVROBJ} + OpenGL3/Driver.cpp + ) +endif() + +if(ENABLE_GLES2) + set(IRRDRVROBJ + ${IRRDRVROBJ} + OpenGLES2/Driver.cpp + ) +endif() + +set(IRRIMAGEOBJ + CColorConverter.cpp + CImage.cpp + CImageLoaderBMP.cpp + CImageLoaderJPG.cpp + CImageLoaderPNG.cpp + CImageLoaderTGA.cpp + CImageWriterJPG.cpp + CImageWriterPNG.cpp +) + +add_library(IRRVIDEOOBJ OBJECT + CFPSCounter.cpp + ${IRRDRVROBJ} + ${IRRIMAGEOBJ} +) + +add_library(IRRIOOBJ OBJECT + CFileList.cpp + CFileSystem.cpp + CLimitReadFile.cpp + CMemoryFile.cpp + CReadFile.cpp + CWriteFile.cpp + CZipReader.cpp + CAttributes.cpp +) + +add_library(IRROTHEROBJ OBJECT + CIrrDeviceSDL.cpp + CIrrDeviceLinux.cpp + CIrrDeviceStub.cpp + CIrrDeviceWin32.cpp + CLogger.cpp + COSOperator.cpp + Irrlicht.cpp + os.cpp +) + +if(ENABLE_OPENGL3) + target_compile_definitions(IRROTHEROBJ PRIVATE ENABLE_OPENGL3) +endif() + +if(ANDROID) + target_sources(IRROTHEROBJ PRIVATE + Android/CIrrDeviceAndroid.cpp + Android/CAndroidAssetReader.cpp + Android/CAndroidAssetFileArchive.cpp + Android/CKeyEventWrapper.cpp + ) +elseif(APPLE) + # Build all IRROTHEROBJ sources as objc++, including the .cpp's + set_target_properties(IRROTHEROBJ PROPERTIES COMPILE_OPTIONS "-xobjective-c++") + target_sources(IRROTHEROBJ PRIVATE + CIrrDeviceOSX.mm + CNSOGLManager.mm + ) +endif() + +if(USE_X11) + target_compile_definitions(IRROTHEROBJ PRIVATE _IRR_COMPILE_WITH_X11_) +endif() + +if(USE_XINPUT2) + target_compile_definitions(IRROTHEROBJ PRIVATE _IRR_LINUX_X11_XINPUT2_) +endif() + +if(USE_XCURSOR) + target_compile_definitions(IRROTHEROBJ PRIVATE _IRR_LINUX_XCURSOR_) +endif() + +add_library(IRRGUIOBJ OBJECT + CGUIButton.cpp + CGUICheckBox.cpp + CGUIComboBox.cpp + CGUIEditBox.cpp + CGUIEnvironment.cpp + CGUIFileOpenDialog.cpp + CGUIFont.cpp + CGUIImage.cpp + CGUIListBox.cpp + CGUIScrollBar.cpp + CGUISkin.cpp + CGUIStaticText.cpp + CGUITabControl.cpp + CGUISpriteBank.cpp + CGUIImageList.cpp +) + +# Library + +add_library(IrrlichtMt) +foreach(object_lib + IRRMESHOBJ IRROBJ IRRVIDEOOBJ + IRRIOOBJ IRROTHEROBJ IRRGUIOBJ) + # Set include directories for object library compilation + target_include_directories(${object_lib} PRIVATE ${link_includes}) + # Add objects from object library to main library + target_sources(IrrlichtMt PRIVATE $) +endforeach() + +# Alias target provides add_submodule compatibility +add_library(IrrlichtMt::IrrlichtMt ALIAS IrrlichtMt) + +target_include_directories(IrrlichtMt + PUBLIC + "$" + "$" + "$" + PRIVATE + ${link_includes} +) + +# this needs to be here and not in a variable (like link_includes) due to issues +# with the generator expressions on at least CMake 3.22, but not 3.28 or later +target_link_libraries(IrrlichtMt PRIVATE + ${ZLIB_LIBRARY} + ${JPEG_LIBRARY} + ${PNG_LIBRARY} + "$<$:SDL2::SDL2>" + + "$<$:${OPENGL_LIBRARIES}>" + "$<$:${OPENGLES_LIBRARY}>" + ${EGL_LIBRARY} + + "$<$:-landroid -llog>" + ${COCOA_LIB} + ${IOKIT_LIB} + "$<$:gdi32>" + "$<$:winmm>" + "$<$:${X11_X11_LIB}>" + "$<$:${X11_Xi_LIB}>" +) + +if(WIN32) + target_compile_definitions(IrrlichtMt INTERFACE _IRR_WINDOWS_API_) # used in _IRR_DEBUG_BREAK_IF definition in a public header +endif() +target_compile_definitions(IrrlichtMt INTERFACE "IRRLICHT_API=${API_IMPORT}") +if(APPLE OR ANDROID OR EMSCRIPTEN) + target_compile_definitions(IrrlichtMt PUBLIC IRR_MOBILE_PATHS) +endif() + +set_target_properties(IrrlichtMt PROPERTIES + VERSION ${PROJECT_VERSION} +) + +if(WIN32) + set_target_properties(IrrlichtMt PROPERTIES PREFIX "") # for DLL name +endif() + +# Installation of library +install(TARGETS IrrlichtMt + EXPORT IrrlichtMt-export + DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) diff --git a/irr/src/CMemoryFile.cpp b/irr/src/CMemoryFile.cpp new file mode 100644 index 000000000..6d7906b91 --- /dev/null +++ b/irr/src/CMemoryFile.cpp @@ -0,0 +1,165 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CMemoryFile.h" +#include "irrString.h" + +namespace irr +{ +namespace io +{ + +CMemoryReadFile::CMemoryReadFile(const void *memory, long len, const io::path &fileName, bool d) : + Buffer(memory), Len(len), Pos(0), Filename(fileName), deleteMemoryWhenDropped(d) +{ +#ifdef _DEBUG + setDebugName("CMemoryReadFile"); +#endif +} + +CMemoryReadFile::~CMemoryReadFile() +{ + if (deleteMemoryWhenDropped) + delete[] (c8 *)Buffer; +} + +//! returns how much was read +size_t CMemoryReadFile::read(void *buffer, size_t sizeToRead) +{ + long amount = static_cast(sizeToRead); + if (Pos + amount > Len) + amount -= Pos + amount - Len; + + if (amount <= 0) + return 0; + + c8 *p = (c8 *)Buffer; + memcpy(buffer, p + Pos, amount); + + Pos += amount; + + return static_cast(amount); +} + +//! changes position in file, returns true if successful +//! if relativeMovement==true, the pos is changed relative to current pos, +//! otherwise from begin of file +bool CMemoryReadFile::seek(long finalPos, bool relativeMovement) +{ + if (relativeMovement) { + if (Pos + finalPos < 0 || Pos + finalPos > Len) + return false; + + Pos += finalPos; + } else { + if (finalPos < 0 || finalPos > Len) + return false; + + Pos = finalPos; + } + + return true; +} + +//! returns size of file +long CMemoryReadFile::getSize() const +{ + return Len; +} + +//! returns where in the file we are. +long CMemoryReadFile::getPos() const +{ + return Pos; +} + +//! returns name of file +const io::path &CMemoryReadFile::getFileName() const +{ + return Filename; +} + +CMemoryWriteFile::CMemoryWriteFile(void *memory, long len, const io::path &fileName, bool d) : + Buffer(memory), Len(len), Pos(0), Filename(fileName), deleteMemoryWhenDropped(d) +{ +#ifdef _DEBUG + setDebugName("CMemoryWriteFile"); +#endif +} + +CMemoryWriteFile::~CMemoryWriteFile() +{ + if (deleteMemoryWhenDropped) + delete[] (c8 *)Buffer; +} + +//! returns how much was written +size_t CMemoryWriteFile::write(const void *buffer, size_t sizeToWrite) +{ + long amount = (long)sizeToWrite; + if (Pos + amount > Len) + amount -= Pos + amount - Len; + + if (amount <= 0) + return 0; + + c8 *p = (c8 *)Buffer; + memcpy(p + Pos, buffer, amount); + + Pos += amount; + + return (size_t)amount; +} + +//! changes position in file, returns true if successful +//! if relativeMovement==true, the pos is changed relative to current pos, +//! otherwise from begin of file +bool CMemoryWriteFile::seek(long finalPos, bool relativeMovement) +{ + if (relativeMovement) { + if (Pos + finalPos < 0 || Pos + finalPos > Len) + return false; + + Pos += finalPos; + } else { + if (finalPos < 0 || finalPos > Len) + return false; + + Pos = finalPos; + } + + return true; +} + +//! returns where in the file we are. +long CMemoryWriteFile::getPos() const +{ + return Pos; +} + +//! returns name of file +const io::path &CMemoryWriteFile::getFileName() const +{ + return Filename; +} + +bool CMemoryWriteFile::flush() +{ + return true; // no buffering, so nothing to do +} + +IReadFile *createMemoryReadFile(const void *memory, long size, const io::path &fileName, bool deleteMemoryWhenDropped) +{ + CMemoryReadFile *file = new CMemoryReadFile(memory, size, fileName, deleteMemoryWhenDropped); + return file; +} + +IWriteFile *createMemoryWriteFile(void *memory, long size, const io::path &fileName, bool deleteMemoryWhenDropped) +{ + CMemoryWriteFile *file = new CMemoryWriteFile(memory, size, fileName, deleteMemoryWhenDropped); + return file; +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CMemoryFile.h b/irr/src/CMemoryFile.h new file mode 100644 index 000000000..3ce0e8460 --- /dev/null +++ b/irr/src/CMemoryFile.h @@ -0,0 +1,99 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IMemoryReadFile.h" +#include "IWriteFile.h" +#include "irrString.h" + +namespace irr +{ + +namespace io +{ + +/*! + Class for reading from memory. +*/ +class CMemoryReadFile : public IMemoryReadFile +{ +public: + //! Constructor + CMemoryReadFile(const void *memory, long len, const io::path &fileName, bool deleteMemoryWhenDropped); + + //! Destructor + virtual ~CMemoryReadFile(); + + //! returns how much was read + size_t read(void *buffer, size_t sizeToRead) override; + + //! changes position in file, returns true if successful + bool seek(long finalPos, bool relativeMovement = false) override; + + //! returns size of file + long getSize() const override; + + //! returns where in the file we are. + long getPos() const override; + + //! returns name of file + const io::path &getFileName() const override; + + //! Get the type of the class implementing this interface + EREAD_FILE_TYPE getType() const override + { + return ERFT_MEMORY_READ_FILE; + } + + //! Get direct access to internal buffer + const void *getBuffer() const override + { + return Buffer; + } + +private: + const void *Buffer; + long Len; + long Pos; + io::path Filename; + bool deleteMemoryWhenDropped; +}; + +/*! + Class for writing to memory. +*/ +class CMemoryWriteFile : public IWriteFile +{ +public: + //! Constructor + CMemoryWriteFile(void *memory, long len, const io::path &fileName, bool deleteMemoryWhenDropped); + + //! Destructor + virtual ~CMemoryWriteFile(); + + //! returns how much was written + size_t write(const void *buffer, size_t sizeToWrite) override; + + //! changes position in file, returns true if successful + bool seek(long finalPos, bool relativeMovement = false) override; + + //! returns where in the file we are. + long getPos() const override; + + //! returns name of file + const io::path &getFileName() const override; + + bool flush() override; + +private: + void *Buffer; + long Len; + long Pos; + io::path Filename; + bool deleteMemoryWhenDropped; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CMeshCache.cpp b/irr/src/CMeshCache.cpp new file mode 100644 index 000000000..4f7e1203c --- /dev/null +++ b/irr/src/CMeshCache.cpp @@ -0,0 +1,156 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CMeshCache.h" +#include "IAnimatedMesh.h" +#include "IMesh.h" + +namespace irr +{ +namespace scene +{ + +static const io::SNamedPath emptyNamedPath; + +CMeshCache::~CMeshCache() +{ + clear(); +} + +//! adds a mesh to the list +void CMeshCache::addMesh(const io::path &filename, IAnimatedMesh *mesh) +{ + mesh->grab(); + + MeshEntry e(filename); + e.Mesh = mesh; + + Meshes.push_back(e); +} + +//! Removes a mesh from the cache. +void CMeshCache::removeMesh(const IMesh *const mesh) +{ + if (!mesh) + return; + for (u32 i = 0; i < Meshes.size(); ++i) { + if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) { + Meshes[i].Mesh->drop(); + Meshes.erase(i); + return; + } + } +} + +//! Returns amount of loaded meshes +u32 CMeshCache::getMeshCount() const +{ + return Meshes.size(); +} + +//! Returns current number of the mesh +s32 CMeshCache::getMeshIndex(const IMesh *const mesh) const +{ + for (u32 i = 0; i < Meshes.size(); ++i) { + if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) + return (s32)i; + } + + return -1; +} + +//! Returns a mesh based on its index number +IAnimatedMesh *CMeshCache::getMeshByIndex(u32 number) +{ + if (number >= Meshes.size()) + return 0; + + return Meshes[number].Mesh; +} + +//! Returns a mesh based on its name. +IAnimatedMesh *CMeshCache::getMeshByName(const io::path &name) +{ + MeshEntry e(name); + s32 id = Meshes.binary_search(e); + return (id != -1) ? Meshes[id].Mesh : 0; +} + +//! Get the name of a loaded mesh, based on its index. +const io::SNamedPath &CMeshCache::getMeshName(u32 index) const +{ + if (index >= Meshes.size()) + return emptyNamedPath; + + return Meshes[index].NamedPath; +} + +//! Get the name of a loaded mesh, if there is any. +const io::SNamedPath &CMeshCache::getMeshName(const IMesh *const mesh) const +{ + if (!mesh) + return emptyNamedPath; + + for (u32 i = 0; i < Meshes.size(); ++i) { + if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) + return Meshes[i].NamedPath; + } + + return emptyNamedPath; +} + +//! Renames a loaded mesh. +bool CMeshCache::renameMesh(u32 index, const io::path &name) +{ + if (index >= Meshes.size()) + return false; + + Meshes[index].NamedPath.setPath(name); + Meshes.sort(); + return true; +} + +//! Renames a loaded mesh. +bool CMeshCache::renameMesh(const IMesh *const mesh, const io::path &name) +{ + for (u32 i = 0; i < Meshes.size(); ++i) { + if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) { + Meshes[i].NamedPath.setPath(name); + Meshes.sort(); + return true; + } + } + + return false; +} + +//! returns if a mesh already was loaded +bool CMeshCache::isMeshLoaded(const io::path &name) +{ + return getMeshByName(name) != 0; +} + +//! Clears the whole mesh cache, removing all meshes. +void CMeshCache::clear() +{ + for (u32 i = 0; i < Meshes.size(); ++i) + Meshes[i].Mesh->drop(); + + Meshes.clear(); +} + +//! Clears all meshes that are held in the mesh cache but not used anywhere else. +void CMeshCache::clearUnusedMeshes() +{ + for (u32 i = 0; i < Meshes.size(); ++i) { + if (Meshes[i].Mesh->getReferenceCount() == 1) { + Meshes[i].Mesh->drop(); + Meshes.erase(i); + --i; + } + } +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CMeshCache.h b/irr/src/CMeshCache.h new file mode 100644 index 000000000..1c2b52686 --- /dev/null +++ b/irr/src/CMeshCache.h @@ -0,0 +1,116 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IMeshCache.h" +#include "irrArray.h" + +namespace irr +{ + +namespace scene +{ +class CMeshCache : public IMeshCache +{ +public: + virtual ~CMeshCache(); + + //! Adds a mesh to the internal list of loaded meshes. + /** Usually, ISceneManager::getMesh() is called to load a mesh from file. + That method searches the list of loaded meshes if a mesh has already been loaded and + returns a pointer to if it is in that list and already in memory. Otherwise it loads + the mesh. With IMeshCache::addMesh(), it is possible to pretend that a mesh already + has been loaded. This method can be used for example by mesh loaders who need to + load more than one mesh with one call. They can add additional meshes with this + method to the scene manager. The COLLADA loader for example uses this method. + \param filename: Filename of the mesh. When called ISceneManager::getMesh() with this + parameter, the method will return the mesh parameter given with this method. + \param mesh: Pointer to a mesh which will now be referenced by this name. */ + void addMesh(const io::path &filename, IAnimatedMesh *mesh) override; + + //! Removes a mesh from the cache. + /** After loading a mesh with getMesh(), the mesh can be removed from the cache + using this method, freeing a lot of memory. */ + void removeMesh(const IMesh *const mesh) override; + + //! Returns amount of loaded meshes in the cache. + /** You can load new meshes into the cache using getMesh() and addMesh(). + If you ever need to access the internal mesh cache, you can do this using + removeMesh(), getMeshNumber(), getMeshByIndex() and getMeshFilename() */ + u32 getMeshCount() const override; + + //! Returns current index number of the mesh, and -1 if it is not in the cache. + s32 getMeshIndex(const IMesh *const mesh) const override; + + //! Returns a mesh based on its index number. + /** \param index: Index of the mesh, number between 0 and getMeshCount()-1. + Note that this number is only valid until a new mesh is loaded or removed * + \return Returns pointer to the mesh or 0 if there is none with this number. */ + IAnimatedMesh *getMeshByIndex(u32 index) override; + + //! Returns a mesh based on its name. + /** \param name Name of the mesh. Usually a filename. + \return Pointer to the mesh or 0 if there is none with this number. */ + IAnimatedMesh *getMeshByName(const io::path &name) override; + + //! Get the name of a loaded mesh, based on its index. + /** \param index: Index of the mesh, number between 0 and getMeshCount()-1. + \return The name if mesh was found and has a name, else the path is empty. */ + const io::SNamedPath &getMeshName(u32 index) const override; + + //! Get the name of a loaded mesh, if there is any. + /** \param mesh Pointer to mesh to query. + \return The name if mesh was found and has a name, else the path is empty. */ + const io::SNamedPath &getMeshName(const IMesh *const mesh) const override; + + //! Renames a loaded mesh. + /** Note that renaming meshes might change the ordering of the + meshes, and so the index of the meshes as returned by + getMeshIndex() or taken by some methods will change. + \param index The index of the mesh in the cache. + \param name New name for the mesh. + \return True if mesh was renamed. */ + bool renameMesh(u32 index, const io::path &name) override; + + //! Renames a loaded mesh. + /** Note that renaming meshes might change the ordering of the + meshes, and so the index of the meshes as returned by + getMeshIndex() or taken by some methods will change. + \param mesh Mesh to be renamed. + \param name New name for the mesh. + \return True if mesh was renamed. */ + bool renameMesh(const IMesh *const mesh, const io::path &name) override; + + //! returns if a mesh already was loaded + bool isMeshLoaded(const io::path &name) override; + + //! Clears the whole mesh cache, removing all meshes. + void clear() override; + + //! Clears all meshes that are held in the mesh cache but not used anywhere else. + void clearUnusedMeshes() override; + +protected: + struct MeshEntry + { + MeshEntry(const io::path &name) : + NamedPath(name) + { + } + io::SNamedPath NamedPath; + IAnimatedMesh *Mesh; + + bool operator<(const MeshEntry &other) const + { + return (NamedPath < other.NamedPath); + } + }; + + //! loaded meshes + core::array Meshes; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CMeshManipulator.cpp b/irr/src/CMeshManipulator.cpp new file mode 100644 index 000000000..3309fea3f --- /dev/null +++ b/irr/src/CMeshManipulator.cpp @@ -0,0 +1,218 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CMeshManipulator.h" +#include "ISkinnedMesh.h" +#include "SMesh.h" +#include "CMeshBuffer.h" +#include "SAnimatedMesh.h" +#include "os.h" + +namespace irr +{ +namespace scene +{ + +static inline core::vector3df getAngleWeight(const core::vector3df &v1, + const core::vector3df &v2, + const core::vector3df &v3) +{ + // Calculate this triangle's weight for each of its three vertices + // start by calculating the lengths of its sides + const f32 a = v2.getDistanceFromSQ(v3); + const f32 asqrt = sqrtf(a); + const f32 b = v1.getDistanceFromSQ(v3); + const f32 bsqrt = sqrtf(b); + const f32 c = v1.getDistanceFromSQ(v2); + const f32 csqrt = sqrtf(c); + + // use them to find the angle at each vertex + return core::vector3df( + acosf((b + c - a) / (2.f * bsqrt * csqrt)), + acosf((-b + c + a) / (2.f * asqrt * csqrt)), + acosf((b - c + a) / (2.f * bsqrt * asqrt))); +} + +namespace +{ +template +void recalculateNormalsT(IMeshBuffer *buffer, bool smooth, bool angleWeighted) +{ + const u32 vtxcnt = buffer->getVertexCount(); + const u32 idxcnt = buffer->getIndexCount(); + const T *idx = reinterpret_cast(buffer->getIndices()); + + if (!smooth) { + for (u32 i = 0; i < idxcnt; i += 3) { + const core::vector3df &v1 = buffer->getPosition(idx[i + 0]); + const core::vector3df &v2 = buffer->getPosition(idx[i + 1]); + const core::vector3df &v3 = buffer->getPosition(idx[i + 2]); + const core::vector3df normal = core::plane3d(v1, v2, v3).Normal; + buffer->getNormal(idx[i + 0]) = normal; + buffer->getNormal(idx[i + 1]) = normal; + buffer->getNormal(idx[i + 2]) = normal; + } + } else { + u32 i; + + for (i = 0; i != vtxcnt; ++i) + buffer->getNormal(i).set(0.f, 0.f, 0.f); + + for (i = 0; i < idxcnt; i += 3) { + const core::vector3df &v1 = buffer->getPosition(idx[i + 0]); + const core::vector3df &v2 = buffer->getPosition(idx[i + 1]); + const core::vector3df &v3 = buffer->getPosition(idx[i + 2]); + const core::vector3df normal = core::plane3d(v1, v2, v3).Normal; + + core::vector3df weight(1.f, 1.f, 1.f); + if (angleWeighted) + weight = irr::scene::getAngleWeight(v1, v2, v3); // writing irr::scene:: necessary for borland + + buffer->getNormal(idx[i + 0]) += weight.X * normal; + buffer->getNormal(idx[i + 1]) += weight.Y * normal; + buffer->getNormal(idx[i + 2]) += weight.Z * normal; + } + + for (i = 0; i != vtxcnt; ++i) + buffer->getNormal(i).normalize(); + } +} +} + +//! Recalculates all normals of the mesh buffer. +/** \param buffer: Mesh buffer on which the operation is performed. */ +void CMeshManipulator::recalculateNormals(IMeshBuffer *buffer, bool smooth, bool angleWeighted) const +{ + if (!buffer) + return; + + if (buffer->getIndexType() == video::EIT_16BIT) + recalculateNormalsT(buffer, smooth, angleWeighted); + else + recalculateNormalsT(buffer, smooth, angleWeighted); +} + +//! Recalculates all normals of the mesh. +//! \param mesh: Mesh on which the operation is performed. +void CMeshManipulator::recalculateNormals(scene::IMesh *mesh, bool smooth, bool angleWeighted) const +{ + if (!mesh) + return; + + if (mesh->getMeshType() == EAMT_SKINNED) { + ISkinnedMesh *smesh = (ISkinnedMesh *)mesh; + smesh->resetAnimation(); + } + + const u32 bcount = mesh->getMeshBufferCount(); + for (u32 b = 0; b < bcount; ++b) + recalculateNormals(mesh->getMeshBuffer(b), smooth, angleWeighted); + + if (mesh->getMeshType() == EAMT_SKINNED) { + ISkinnedMesh *smesh = (ISkinnedMesh *)mesh; + smesh->refreshJointCache(); + } +} + +//! Clones a static IMesh into a modifyable SMesh. +// not yet 32bit +SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const +{ + if (!mesh) + return 0; + + SMesh *clone = new SMesh(); + + const u32 meshBufferCount = mesh->getMeshBufferCount(); + + for (u32 b = 0; b < meshBufferCount; ++b) { + const IMeshBuffer *const mb = mesh->getMeshBuffer(b); + switch (mb->getVertexType()) { + case video::EVT_STANDARD: { + SMeshBuffer *buffer = new SMeshBuffer(); + buffer->Material = mb->getMaterial(); + const u32 vcount = mb->getVertexCount(); + buffer->Vertices.reallocate(vcount); + video::S3DVertex *vertices = (video::S3DVertex *)mb->getVertices(); + for (u32 i = 0; i < vcount; ++i) + buffer->Vertices.push_back(vertices[i]); + const u32 icount = mb->getIndexCount(); + buffer->Indices.reallocate(icount); + const u16 *indices = mb->getIndices(); + for (u32 i = 0; i < icount; ++i) + buffer->Indices.push_back(indices[i]); + clone->addMeshBuffer(buffer); + buffer->drop(); + } break; + case video::EVT_2TCOORDS: { + SMeshBufferLightMap *buffer = new SMeshBufferLightMap(); + buffer->Material = mb->getMaterial(); + const u32 vcount = mb->getVertexCount(); + buffer->Vertices.reallocate(vcount); + video::S3DVertex2TCoords *vertices = (video::S3DVertex2TCoords *)mb->getVertices(); + for (u32 i = 0; i < vcount; ++i) + buffer->Vertices.push_back(vertices[i]); + const u32 icount = mb->getIndexCount(); + buffer->Indices.reallocate(icount); + const u16 *indices = mb->getIndices(); + for (u32 i = 0; i < icount; ++i) + buffer->Indices.push_back(indices[i]); + clone->addMeshBuffer(buffer); + buffer->drop(); + } break; + case video::EVT_TANGENTS: { + SMeshBufferTangents *buffer = new SMeshBufferTangents(); + buffer->Material = mb->getMaterial(); + const u32 vcount = mb->getVertexCount(); + buffer->Vertices.reallocate(vcount); + video::S3DVertexTangents *vertices = (video::S3DVertexTangents *)mb->getVertices(); + for (u32 i = 0; i < vcount; ++i) + buffer->Vertices.push_back(vertices[i]); + const u32 icount = mb->getIndexCount(); + buffer->Indices.reallocate(icount); + const u16 *indices = mb->getIndices(); + for (u32 i = 0; i < icount; ++i) + buffer->Indices.push_back(indices[i]); + clone->addMeshBuffer(buffer); + buffer->drop(); + } break; + } // end switch + + } // end for all mesh buffers + + clone->BoundingBox = mesh->getBoundingBox(); + return clone; +} + +//! Returns amount of polygons in mesh. +s32 CMeshManipulator::getPolyCount(scene::IMesh *mesh) const +{ + if (!mesh) + return 0; + + s32 trianglecount = 0; + + for (u32 g = 0; g < mesh->getMeshBufferCount(); ++g) + trianglecount += mesh->getMeshBuffer(g)->getIndexCount() / 3; + + return trianglecount; +} + +//! Returns amount of polygons in mesh. +s32 CMeshManipulator::getPolyCount(scene::IAnimatedMesh *mesh) const +{ + if (mesh && mesh->getFrameCount() != 0) + return getPolyCount(mesh->getMesh(0)); + + return 0; +} + +//! create a new AnimatedMesh and adds the mesh to it +IAnimatedMesh *CMeshManipulator::createAnimatedMesh(scene::IMesh *mesh, scene::E_ANIMATED_MESH_TYPE type) const +{ + return new SAnimatedMesh(mesh, type); +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CMeshManipulator.h b/irr/src/CMeshManipulator.h new file mode 100644 index 000000000..0377d6a3a --- /dev/null +++ b/irr/src/CMeshManipulator.h @@ -0,0 +1,46 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IMeshManipulator.h" + +namespace irr +{ +namespace scene +{ + +//! An interface for easy manipulation of meshes. +/** Scale, set alpha value, flip surfaces, and so on. This exists for fixing +problems with wrong imported or exported meshes quickly after loading. It is +not intended for doing mesh modifications and/or animations during runtime. +*/ +class CMeshManipulator : public IMeshManipulator +{ +public: + //! Recalculates all normals of the mesh. + /** \param mesh: Mesh on which the operation is performed. + \param smooth: Whether to use smoothed normals. */ + void recalculateNormals(scene::IMesh *mesh, bool smooth = false, bool angleWeighted = false) const override; + + //! Recalculates all normals of the mesh buffer. + /** \param buffer: Mesh buffer on which the operation is performed. + \param smooth: Whether to use smoothed normals. */ + void recalculateNormals(IMeshBuffer *buffer, bool smooth = false, bool angleWeighted = false) const override; + + //! Clones a static IMesh into a modifiable SMesh. + SMesh *createMeshCopy(scene::IMesh *mesh) const override; + + //! Returns amount of polygons in mesh. + s32 getPolyCount(scene::IMesh *mesh) const override; + + //! Returns amount of polygons in mesh. + s32 getPolyCount(scene::IAnimatedMesh *mesh) const override; + + //! create a new AnimatedMesh and adds the mesh to it + IAnimatedMesh *createAnimatedMesh(scene::IMesh *mesh, scene::E_ANIMATED_MESH_TYPE type) const override; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CMeshSceneNode.cpp b/irr/src/CMeshSceneNode.cpp new file mode 100644 index 000000000..7ff6cad55 --- /dev/null +++ b/irr/src/CMeshSceneNode.cpp @@ -0,0 +1,262 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CMeshSceneNode.h" +#include "IVideoDriver.h" +#include "ISceneManager.h" +#include "S3DVertex.h" +#include "ICameraSceneNode.h" +#include "IMeshCache.h" +#include "IAnimatedMesh.h" +#include "IMaterialRenderer.h" +#include "IFileSystem.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CMeshSceneNode::CMeshSceneNode(IMesh *mesh, ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position, const core::vector3df &rotation, + const core::vector3df &scale) : + IMeshSceneNode(parent, mgr, id, position, rotation, scale), + Mesh(0), + PassCount(0), ReadOnlyMaterials(false) +{ +#ifdef _DEBUG + setDebugName("CMeshSceneNode"); +#endif + + setMesh(mesh); +} + +//! destructor +CMeshSceneNode::~CMeshSceneNode() +{ + if (Mesh) + Mesh->drop(); +} + +//! frame +void CMeshSceneNode::OnRegisterSceneNode() +{ + if (IsVisible && Mesh) { + // because this node supports rendering of mixed mode meshes consisting of + // transparent and solid material at the same time, we need to go through all + // materials, check of what type they are and register this node for the right + // render pass according to that. + + video::IVideoDriver *driver = SceneManager->getVideoDriver(); + + PassCount = 0; + int transparentCount = 0; + int solidCount = 0; + + // count transparent and solid materials in this scene node + const u32 numMaterials = ReadOnlyMaterials ? Mesh->getMeshBufferCount() : Materials.size(); + for (u32 i = 0; i < numMaterials; ++i) { + const video::SMaterial &material = ReadOnlyMaterials ? Mesh->getMeshBuffer(i)->getMaterial() : Materials[i]; + + if (driver->needsTransparentRenderPass(material)) + ++transparentCount; + else + ++solidCount; + + if (solidCount && transparentCount) + break; + } + + // register according to material types counted + + if (solidCount) + SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); + + if (transparentCount) + SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); + + ISceneNode::OnRegisterSceneNode(); + } +} + +//! renders the node. +void CMeshSceneNode::render() +{ + video::IVideoDriver *driver = SceneManager->getVideoDriver(); + + if (!Mesh || !driver) + return; + + const bool isTransparentPass = + SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT; + + ++PassCount; + + driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); + Box = Mesh->getBoundingBox(); + + for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i) { + scene::IMeshBuffer *mb = Mesh->getMeshBuffer(i); + if (mb) { + const video::SMaterial &material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i]; + + const bool transparent = driver->needsTransparentRenderPass(material); + + // only render transparent buffer if this is the transparent render pass + // and solid only in solid pass + if (transparent == isTransparentPass) { + driver->setMaterial(material); + driver->drawMeshBuffer(mb); + } + } + } + + // for debug purposes only: + if (DebugDataVisible && PassCount == 1) { + video::SMaterial m; + m.Lighting = false; + m.AntiAliasing = 0; + driver->setMaterial(m); + + if (DebugDataVisible & scene::EDS_BBOX) { + driver->draw3DBox(Box, video::SColor(255, 255, 255, 255)); + } + if (DebugDataVisible & scene::EDS_BBOX_BUFFERS) { + for (u32 g = 0; g < Mesh->getMeshBufferCount(); ++g) { + driver->draw3DBox( + Mesh->getMeshBuffer(g)->getBoundingBox(), + video::SColor(255, 190, 128, 128)); + } + } + + if (DebugDataVisible & scene::EDS_NORMALS) { + // draw normals + const f32 debugNormalLength = 1.f; + const video::SColor debugNormalColor = video::SColor(255, 34, 221, 221); + const u32 count = Mesh->getMeshBufferCount(); + + for (u32 i = 0; i != count; ++i) { + driver->drawMeshBufferNormals(Mesh->getMeshBuffer(i), debugNormalLength, debugNormalColor); + } + } + + // show mesh + if (DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY) { + m.Wireframe = true; + driver->setMaterial(m); + + for (u32 g = 0; g < Mesh->getMeshBufferCount(); ++g) { + driver->drawMeshBuffer(Mesh->getMeshBuffer(g)); + } + } + } +} + +//! Removes a child from this scene node. +//! Implemented here, to be able to remove the shadow properly, if there is one, +//! or to remove attached childs. +bool CMeshSceneNode::removeChild(ISceneNode *child) +{ + return ISceneNode::removeChild(child); +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CMeshSceneNode::getBoundingBox() const +{ + return Mesh ? Mesh->getBoundingBox() : Box; +} + +//! returns the material based on the zero based index i. To get the amount +//! of materials used by this scene node, use getMaterialCount(). +//! This function is needed for inserting the node into the scene hierarchy on a +//! optimal position for minimizing renderstate changes, but can also be used +//! to directly modify the material of a scene node. +video::SMaterial &CMeshSceneNode::getMaterial(u32 i) +{ + if (Mesh && ReadOnlyMaterials && i < Mesh->getMeshBufferCount()) { + ReadOnlyMaterial = Mesh->getMeshBuffer(i)->getMaterial(); + return ReadOnlyMaterial; + } + + if (i >= Materials.size()) + return ISceneNode::getMaterial(i); + + return Materials[i]; +} + +//! returns amount of materials used by this scene node. +u32 CMeshSceneNode::getMaterialCount() const +{ + if (Mesh && ReadOnlyMaterials) + return Mesh->getMeshBufferCount(); + + return Materials.size(); +} + +//! Sets a new mesh +void CMeshSceneNode::setMesh(IMesh *mesh) +{ + if (mesh) { + mesh->grab(); + if (Mesh) + Mesh->drop(); + + Mesh = mesh; + copyMaterials(); + } +} + +void CMeshSceneNode::copyMaterials() +{ + Materials.clear(); + + if (Mesh) { + video::SMaterial mat; + + for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i) { + IMeshBuffer *mb = Mesh->getMeshBuffer(i); + if (mb) + mat = mb->getMaterial(); + + Materials.push_back(mat); + } + } +} + +//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style. +/* In this way it is possible to change the materials a mesh causing all mesh scene nodes +referencing this mesh to change too. */ +void CMeshSceneNode::setReadOnlyMaterials(bool readonly) +{ + ReadOnlyMaterials = readonly; +} + +//! Returns if the scene node should not copy the materials of the mesh but use them in a read only style +bool CMeshSceneNode::isReadOnlyMaterials() const +{ + return ReadOnlyMaterials; +} + +//! Creates a clone of this scene node and its children. +ISceneNode *CMeshSceneNode::clone(ISceneNode *newParent, ISceneManager *newManager) +{ + if (!newParent) + newParent = Parent; + if (!newManager) + newManager = SceneManager; + + CMeshSceneNode *nb = new CMeshSceneNode(Mesh, newParent, + newManager, ID, RelativeTranslation, RelativeRotation, RelativeScale); + + nb->cloneMembers(this, newManager); + nb->ReadOnlyMaterials = ReadOnlyMaterials; + nb->Materials = Materials; + + if (newParent) + nb->drop(); + return nb; +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CMeshSceneNode.h b/irr/src/CMeshSceneNode.h new file mode 100644 index 000000000..a00928748 --- /dev/null +++ b/irr/src/CMeshSceneNode.h @@ -0,0 +1,85 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IMeshSceneNode.h" +#include "IMesh.h" + +namespace irr +{ +namespace scene +{ + +class CMeshSceneNode : public IMeshSceneNode +{ +public: + //! constructor + CMeshSceneNode(IMesh *mesh, ISceneNode *parent, ISceneManager *mgr, s32 id, + const core::vector3df &position = core::vector3df(0, 0, 0), + const core::vector3df &rotation = core::vector3df(0, 0, 0), + const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f)); + + //! destructor + virtual ~CMeshSceneNode(); + + //! frame + void OnRegisterSceneNode() override; + + //! renders the node. + void render() override; + + //! returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + //! returns the material based on the zero based index i. To get the amount + //! of materials used by this scene node, use getMaterialCount(). + //! This function is needed for inserting the node into the scene hierarchy on a + //! optimal position for minimizing renderstate changes, but can also be used + //! to directly modify the material of a scene node. + video::SMaterial &getMaterial(u32 i) override; + + //! returns amount of materials used by this scene node. + u32 getMaterialCount() const override; + + //! Returns type of the scene node + ESCENE_NODE_TYPE getType() const override { return ESNT_MESH; } + + //! Sets a new mesh + void setMesh(IMesh *mesh) override; + + //! Returns the current mesh + IMesh *getMesh(void) override { return Mesh; } + + //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style. + /* In this way it is possible to change the materials a mesh causing all mesh scene nodes + referencing this mesh to change too. */ + void setReadOnlyMaterials(bool readonly) override; + + //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style + bool isReadOnlyMaterials() const override; + + //! Creates a clone of this scene node and its children. + ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override; + + //! Removes a child from this scene node. + //! Implemented here, to be able to remove the shadow properly, if there is one, + //! or to remove attached child. + bool removeChild(ISceneNode *child) override; + +protected: + void copyMaterials(); + + core::array Materials; + core::aabbox3d Box; + video::SMaterial ReadOnlyMaterial; + + IMesh *Mesh; + + s32 PassCount; + bool ReadOnlyMaterials; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CNSOGLManager.h b/irr/src/CNSOGLManager.h new file mode 100644 index 000000000..cdbb221b3 --- /dev/null +++ b/irr/src/CNSOGLManager.h @@ -0,0 +1,70 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_NSOGL_MANAGER_ + +#include "SIrrCreationParameters.h" +#include "SExposedVideoData.h" +#include "IContextManager.h" +#include "SColor.h" + +#import + +namespace irr +{ +namespace video +{ +// NSOpenGL manager. +class CNSOGLManager : public IContextManager +{ +public: + //! Constructor. + CNSOGLManager(); + + //! Destructor + ~CNSOGLManager(); + + // Initialize + bool initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &data) override; + + // Terminate + void terminate() override; + + // Create surface. + bool generateSurface() override; + + // Destroy surface. + void destroySurface() override; + + // Create context. + bool generateContext() override; + + // Destroy EGL context. + void destroyContext() override; + + //! Get current context + const SExposedVideoData &getContext() const; + + //! Change render context, disable old and activate new defined by videoData + bool activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) override; + + // Get procedure address. + void *getProcAddress(const std::string &procName) override; + + // Swap buffers. + bool swapBuffers() override; + +private: + SIrrlichtCreationParameters Params; + SExposedVideoData PrimaryContext; + SExposedVideoData CurrentContext; + + NSOpenGLPixelFormat *PixelFormat; +}; +} +} + +#endif diff --git a/irr/src/CNSOGLManager.mm b/irr/src/CNSOGLManager.mm new file mode 100644 index 000000000..c1e543e53 --- /dev/null +++ b/irr/src/CNSOGLManager.mm @@ -0,0 +1,234 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "CNSOGLManager.h" + +#ifdef _IRR_COMPILE_WITH_NSOGL_MANAGER_ + +#include +#include "os.h" + +namespace irr +{ +namespace video +{ + +CNSOGLManager::CNSOGLManager() : + PrimaryContext(SExposedVideoData(0)), PixelFormat(nil) +{ +#ifdef _DEBUG + setDebugName("CNSOGLManager"); +#endif +} + +CNSOGLManager::~CNSOGLManager() +{ +} + +bool CNSOGLManager::initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &videodata) +{ + Params = params; + + return true; +} + +void CNSOGLManager::terminate() +{ +} + +bool CNSOGLManager::generateSurface() +{ + if (Params.DriverType == video::EDT_OPENGL) { + int alphaSize = Params.WithAlphaChannel ? 4 : 0; + int depthSize = Params.ZBufferBits; + + if (Params.WithAlphaChannel && Params.Bits == 32) + alphaSize = 8; + + NSOpenGLPixelFormatAttribute Attribs[] = { + NSOpenGLPFANoRecovery, + NSOpenGLPFAAccelerated, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFADepthSize, static_cast(depthSize), + NSOpenGLPFAColorSize, Params.Bits, + NSOpenGLPFAAlphaSize, static_cast(alphaSize), + NSOpenGLPFASampleBuffers, 1, + NSOpenGLPFASamples, Params.AntiAlias, + NSOpenGLPFAStencilSize, static_cast(Params.Stencilbuffer ? 1 : 0), + // NSOpenGLPFAFullScreen, + 0, + }; + + u32 Steps = 6; + + // Choose the best pixel format. + do { + switch (Steps) { + case 6: // decrease step. + --Steps; + break; + case 5: // samples + if (Attribs[12] > 2) + --Attribs[12]; + else { + Attribs[10] = 0; + Attribs[12] = 0; + --Steps; + } + break; + case 4: // alpha + if (Attribs[8]) { + Attribs[8] = 0; + + if (Params.AntiAlias) { + Attribs[10] = 1; + Attribs[12] = Params.AntiAlias; + Steps = 5; + } + } else + --Steps; + break; + case 3: // stencil + if (Attribs[14]) { + Attribs[14] = 0; + + if (Params.AntiAlias) { + Attribs[10] = 1; + Attribs[12] = Params.AntiAlias; + Steps = 5; + } + } else + --Steps; + break; + case 2: // depth size + if (Attribs[4] > 16) { + Attribs[4] = Attribs[4] - 8; + } else + --Steps; + break; + case 1: // buffer size + if (Attribs[6] > 16) { + Attribs[6] = Attribs[6] - 8; + } else + --Steps; + break; + default: + os::Printer::log("Could not get pixel format."); + return false; + } + + PixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:Attribs]; + } while (PixelFormat == nil); + + if (Params.AntiAlias && !Attribs[10]) + os::Printer::log("No multisampling."); + + if (Params.WithAlphaChannel && !Attribs[8]) + os::Printer::log("No alpha."); + + if (Params.Stencilbuffer && !Attribs[14]) + os::Printer::log("No stencil buffer."); + + if (Params.ZBufferBits > Attribs[4]) + os::Printer::log("No full depth buffer."); + + if (Params.Bits > Attribs[6]) + os::Printer::log("No full color buffer."); + } + + return true; +} + +void CNSOGLManager::destroySurface() +{ + [PixelFormat release]; + PixelFormat = nil; +} + +bool CNSOGLManager::generateContext() +{ + NSOpenGLContext *Context = [[NSOpenGLContext alloc] initWithFormat:PixelFormat shareContext:nil]; + + GLint Vsync = Params.Vsync ? 1 : 0; + [Context setValues:&Vsync forParameter:NSOpenGLCPSwapInterval]; + + if (Context == nil) { + os::Printer::log("Could not create OpenGL context.", ELL_ERROR); + return false; + } + + // set exposed data + CurrentContext.OpenGLOSX.Context = Context; + + if (!PrimaryContext.OpenGLOSX.Context) + PrimaryContext.OpenGLOSX.Context = CurrentContext.OpenGLOSX.Context; + + return true; +} + +const SExposedVideoData &CNSOGLManager::getContext() const +{ + return CurrentContext; +} + +bool CNSOGLManager::activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) +{ + // TODO: handle restorePrimaryOnZero + if (videoData.OpenGLOSX.Context) { + if ((NSOpenGLContext *)videoData.OpenGLOSX.Context != [NSOpenGLContext currentContext]) { + [(NSOpenGLContext *)videoData.OpenGLOSX.Context makeCurrentContext]; + + CurrentContext = videoData; + } + } + // set back to main context + else { + if ((NSOpenGLContext *)PrimaryContext.OpenGLOSX.Context != [NSOpenGLContext currentContext]) { + [(NSOpenGLContext *)PrimaryContext.OpenGLOSX.Context makeCurrentContext]; + + CurrentContext = PrimaryContext; + } + } + + return true; +} + +void CNSOGLManager::destroyContext() +{ + if (CurrentContext.OpenGLOSX.Context) { + if (PrimaryContext.OpenGLOSX.Context == CurrentContext.OpenGLOSX.Context) + PrimaryContext.OpenGLOSX.Context = nil; + + [(NSOpenGLContext *)CurrentContext.OpenGLOSX.Context makeCurrentContext]; + [(NSOpenGLContext *)CurrentContext.OpenGLOSX.Context clearDrawable]; + [(NSOpenGLContext *)CurrentContext.OpenGLOSX.Context release]; + [NSOpenGLContext clearCurrentContext]; + + CurrentContext.OpenGLOSX.Context = nil; + } +} + +// It appears that there is no separate GL proc address getter on OSX. +// https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_entrypts/opengl_entrypts.html +void *CNSOGLManager::getProcAddress(const std::string &procName) +{ + NSSymbol symbol = NULL; + // Allocate a buffer for the name, an underscore prefix, and a cstring terminator. + std::string mangledName = "_" + procName; + if (NSIsSymbolNameDefined(mangledName.c_str())) + symbol = NSLookupAndBindSymbol(mangledName.c_str()); + return symbol ? NSAddressOfSymbol(symbol) : NULL; +} + +bool CNSOGLManager::swapBuffers() +{ + [(NSOpenGLContext *)CurrentContext.OpenGLOSX.Context flushBuffer]; + + return true; +} + +} +} + +#endif diff --git a/irr/src/CNullDriver.cpp b/irr/src/CNullDriver.cpp new file mode 100644 index 000000000..347569e6a --- /dev/null +++ b/irr/src/CNullDriver.cpp @@ -0,0 +1,1775 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CNullDriver.h" +#include "os.h" +#include "CImage.h" +#include "CAttributes.h" +#include "IReadFile.h" +#include "IWriteFile.h" +#include "IImageLoader.h" +#include "IImageWriter.h" +#include "IMaterialRenderer.h" +#include "IAnimatedMeshSceneNode.h" +#include "CMeshManipulator.h" +#include "CColorConverter.h" +#include "IReferenceCounted.h" +#include "IRenderTarget.h" + +namespace irr +{ +namespace video +{ + +//! creates a loader which is able to load windows bitmaps +IImageLoader *createImageLoaderBMP(); + +//! creates a loader which is able to load jpeg images +IImageLoader *createImageLoaderJPG(); + +//! creates a loader which is able to load targa images +IImageLoader *createImageLoaderTGA(); + +//! creates a loader which is able to load png images +IImageLoader *createImageLoaderPNG(); + +//! creates a writer which is able to save jpg images +IImageWriter *createImageWriterJPG(); + +//! creates a writer which is able to save png images +IImageWriter *createImageWriterPNG(); + +namespace +{ +//! no-op material renderer +class CDummyMaterialRenderer : public IMaterialRenderer +{ +public: + CDummyMaterialRenderer() {} +}; +} + +//! constructor +CNullDriver::CNullDriver(io::IFileSystem *io, const core::dimension2d &screenSize) : + SharedRenderTarget(0), CurrentRenderTarget(0), CurrentRenderTargetSize(0, 0), FileSystem(io), MeshManipulator(0), + ViewPort(0, 0, 0, 0), ScreenSize(screenSize), PrimitivesDrawn(0), MinVertexCountForVBO(500), + TextureCreationFlags(0), OverrideMaterial2DEnabled(false), AllowZWriteOnTransparent(false) +{ +#ifdef _DEBUG + setDebugName("CNullDriver"); +#endif + + DriverAttributes = new io::CAttributes(); + DriverAttributes->addInt("MaxTextures", MATERIAL_MAX_TEXTURES); + DriverAttributes->addInt("MaxSupportedTextures", MATERIAL_MAX_TEXTURES); + DriverAttributes->addInt("MaxAnisotropy", 1); + // DriverAttributes->addInt("MaxUserClipPlanes", 0); + // DriverAttributes->addInt("MaxAuxBuffers", 0); + DriverAttributes->addInt("MaxMultipleRenderTargets", 1); + DriverAttributes->addInt("MaxIndices", -1); + DriverAttributes->addInt("MaxTextureSize", -1); + // DriverAttributes->addInt("MaxGeometryVerticesOut", 0); + // DriverAttributes->addFloat("MaxTextureLODBias", 0.f); + DriverAttributes->addInt("Version", 1); + // DriverAttributes->addInt("ShaderLanguageVersion", 0); + // DriverAttributes->addInt("AntiAlias", 0); + + setFog(); + + setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true); + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true); + setTextureCreationFlag(ETCF_AUTO_GENERATE_MIP_MAPS, true); + setTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY, true); + + ViewPort = core::rect(core::position2d(0, 0), core::dimension2di(screenSize)); + + // create manipulator + MeshManipulator = new scene::CMeshManipulator(); + + if (FileSystem) + FileSystem->grab(); + + // create surface loaders and writers + SurfaceLoader.push_back(video::createImageLoaderTGA()); + SurfaceLoader.push_back(video::createImageLoaderPNG()); + SurfaceLoader.push_back(video::createImageLoaderJPG()); + SurfaceLoader.push_back(video::createImageLoaderBMP()); + + SurfaceWriter.push_back(video::createImageWriterJPG()); + SurfaceWriter.push_back(video::createImageWriterPNG()); + + // set ExposedData to 0 + memset((void *)&ExposedData, 0, sizeof(ExposedData)); + for (u32 i = 0; i < video::EVDF_COUNT; ++i) + FeatureEnabled[i] = true; + + InitMaterial2D.AntiAliasing = video::EAAM_OFF; + InitMaterial2D.Lighting = false; + InitMaterial2D.ZWriteEnable = video::EZW_OFF; + InitMaterial2D.ZBuffer = video::ECFN_DISABLED; + InitMaterial2D.UseMipMaps = false; + InitMaterial2D.forEachTexture([](auto &tex) { + // Using ETMINF_LINEAR_MIPMAP_NEAREST (bilinear) for 2D graphics looks + // much better and doesn't have any downsides (e.g. regarding pixel art). + tex.MinFilter = video::ETMINF_LINEAR_MIPMAP_NEAREST; + tex.MagFilter = video::ETMAGF_NEAREST; + tex.TextureWrapU = video::ETC_REPEAT; + tex.TextureWrapV = video::ETC_REPEAT; + tex.TextureWrapW = video::ETC_REPEAT; + }); + OverrideMaterial2D = InitMaterial2D; +} + +//! destructor +CNullDriver::~CNullDriver() +{ + if (DriverAttributes) + DriverAttributes->drop(); + + if (FileSystem) + FileSystem->drop(); + + if (MeshManipulator) + MeshManipulator->drop(); + + removeAllRenderTargets(); + + deleteAllTextures(); + + u32 i; + for (i = 0; i < SurfaceLoader.size(); ++i) + SurfaceLoader[i]->drop(); + + for (i = 0; i < SurfaceWriter.size(); ++i) + SurfaceWriter[i]->drop(); + + // delete material renderers + deleteMaterialRenders(); + + // delete hardware mesh buffers + removeAllHardwareBuffers(); +} + +//! Adds an external surface loader to the engine. +void CNullDriver::addExternalImageLoader(IImageLoader *loader) +{ + if (!loader) + return; + + loader->grab(); + SurfaceLoader.push_back(loader); +} + +//! Adds an external surface writer to the engine. +void CNullDriver::addExternalImageWriter(IImageWriter *writer) +{ + if (!writer) + return; + + writer->grab(); + SurfaceWriter.push_back(writer); +} + +//! Retrieve the number of image loaders +u32 CNullDriver::getImageLoaderCount() const +{ + return SurfaceLoader.size(); +} + +//! Retrieve the given image loader +IImageLoader *CNullDriver::getImageLoader(u32 n) +{ + if (n < SurfaceLoader.size()) + return SurfaceLoader[n]; + return 0; +} + +//! Retrieve the number of image writers +u32 CNullDriver::getImageWriterCount() const +{ + return SurfaceWriter.size(); +} + +//! Retrieve the given image writer +IImageWriter *CNullDriver::getImageWriter(u32 n) +{ + if (n < SurfaceWriter.size()) + return SurfaceWriter[n]; + return 0; +} + +//! deletes all textures +void CNullDriver::deleteAllTextures() +{ + // we need to remove previously set textures which might otherwise be kept in the + // last set material member. Could be optimized to reduce state changes. + setMaterial(SMaterial()); + + // reset render targets. + + for (u32 i = 0; i < RenderTargets.size(); ++i) + RenderTargets[i]->setTexture(0, 0); + + // remove textures. + + for (u32 i = 0; i < Textures.size(); ++i) + Textures[i].Surface->drop(); + + Textures.clear(); + + SharedDepthTextures.clear(); +} + +bool CNullDriver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData &videoData, core::rect *sourceRect) +{ + PrimitivesDrawn = 0; + return true; +} + +bool CNullDriver::endScene() +{ + FPSCounter.registerFrame(os::Timer::getRealTime(), PrimitivesDrawn); + updateAllHardwareBuffers(); + updateAllOcclusionQueries(); + return true; +} + +//! Disable a feature of the driver. +void CNullDriver::disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag) +{ + FeatureEnabled[feature] = !flag; +} + +//! queries the features of the driver, returns true if feature is available +bool CNullDriver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const +{ + return false; +} + +//! Get attributes of the actual video driver +const io::IAttributes &CNullDriver::getDriverAttributes() const +{ + return *DriverAttributes; +} + +//! sets transformation +void CNullDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) +{ +} + +//! Returns the transformation set by setTransform +const core::matrix4 &CNullDriver::getTransform(E_TRANSFORMATION_STATE state) const +{ + return TransformationMatrix; +} + +//! sets a material +void CNullDriver::setMaterial(const SMaterial &material) +{ +} + +//! Removes a texture from the texture cache and deletes it, freeing lot of +//! memory. +void CNullDriver::removeTexture(ITexture *texture) +{ + if (!texture) + return; + SSurface s; + s.Surface = texture; + + s32 last; + s32 first = Textures.binary_search_multi(s, last); + if (first == -1) + return; + for (u32 i = first; i <= (u32)last; i++) { + if (Textures[i].Surface == texture) { + texture->drop(); + Textures.erase(i); + return; + } + } +} + +//! Removes all texture from the texture cache and deletes them, freeing lot of +//! memory. +void CNullDriver::removeAllTextures() +{ + setMaterial(SMaterial()); + deleteAllTextures(); +} + +//! Returns amount of textures currently loaded +u32 CNullDriver::getTextureCount() const +{ + return Textures.size(); +} + +ITexture *CNullDriver::addTexture(const core::dimension2d &size, const io::path &name, ECOLOR_FORMAT format) +{ + if (0 == name.size()) { + os::Printer::log("Could not create ITexture, texture needs to have a non-empty name.", ELL_WARNING); + return 0; + } + + IImage *image = new CImage(format, size); + ITexture *t = 0; + + if (checkImage(image)) { + t = createDeviceDependentTexture(name, image); + } + + image->drop(); + + if (t) { + addTexture(t); + t->drop(); + } + + return t; +} + +ITexture *CNullDriver::addTexture(const io::path &name, IImage *image) +{ + if (0 == name.size()) { + os::Printer::log("Could not create ITexture, texture needs to have a non-empty name.", ELL_WARNING); + return 0; + } + + if (!image) + return 0; + + ITexture *t = 0; + + if (checkImage(image)) { + t = createDeviceDependentTexture(name, image); + } + + if (t) { + addTexture(t); + t->drop(); + } + + return t; +} + +ITexture *CNullDriver::addTextureCubemap(const io::path &name, IImage *imagePosX, IImage *imageNegX, IImage *imagePosY, + IImage *imageNegY, IImage *imagePosZ, IImage *imageNegZ) +{ + if (0 == name.size() || !imagePosX || !imageNegX || !imagePosY || !imageNegY || !imagePosZ || !imageNegZ) + return 0; + + ITexture *t = 0; + + core::array imageArray(6); + imageArray.push_back(imagePosX); + imageArray.push_back(imageNegX); + imageArray.push_back(imagePosY); + imageArray.push_back(imageNegY); + imageArray.push_back(imagePosZ); + imageArray.push_back(imageNegZ); + + if (checkImage(imageArray)) { + t = createDeviceDependentTextureCubemap(name, imageArray); + } + + if (t) { + addTexture(t); + t->drop(); + } + + return t; +} + +ITexture *CNullDriver::addTextureCubemap(const irr::u32 sideLen, const io::path &name, ECOLOR_FORMAT format) +{ + if (0 == sideLen) + return 0; + + if (0 == name.size()) { + os::Printer::log("Could not create ITexture, texture needs to have a non-empty name.", ELL_WARNING); + return 0; + } + + core::array imageArray(6); + for (int i = 0; i < 6; ++i) + imageArray.push_back(new CImage(format, core::dimension2du(sideLen, sideLen))); + + ITexture *t = 0; + if (checkImage(imageArray)) { + t = createDeviceDependentTextureCubemap(name, imageArray); + + if (t) { + addTexture(t); + t->drop(); + } + } + + for (int i = 0; i < 6; ++i) + imageArray[i]->drop(); + + return t; +} + +//! loads a Texture +ITexture *CNullDriver::getTexture(const io::path &filename) +{ + // Identify textures by their absolute filenames if possible. + const io::path absolutePath = FileSystem->getAbsolutePath(filename); + + ITexture *texture = findTexture(absolutePath); + if (texture) { + texture->updateSource(ETS_FROM_CACHE); + return texture; + } + + // Then try the raw filename, which might be in an Archive + texture = findTexture(filename); + if (texture) { + texture->updateSource(ETS_FROM_CACHE); + return texture; + } + + // Now try to open the file using the complete path. + io::IReadFile *file = FileSystem->createAndOpenFile(absolutePath); + + if (!file) { + // Try to open it using the raw filename. + file = FileSystem->createAndOpenFile(filename); + } + + if (file) { + // Re-check name for actual archive names + texture = findTexture(file->getFileName()); + if (texture) { + texture->updateSource(ETS_FROM_CACHE); + file->drop(); + return texture; + } + + texture = loadTextureFromFile(file); + file->drop(); + + if (texture) { + texture->updateSource(ETS_FROM_FILE); + addTexture(texture); + texture->drop(); // drop it because we created it, one grab too much + } else + os::Printer::log("Could not load texture", filename, ELL_ERROR); + return texture; + } else { + os::Printer::log("Could not open file of texture", filename, ELL_WARNING); + return 0; + } +} + +//! loads a Texture +ITexture *CNullDriver::getTexture(io::IReadFile *file) +{ + ITexture *texture = 0; + + if (file) { + texture = findTexture(file->getFileName()); + + if (texture) { + texture->updateSource(ETS_FROM_CACHE); + return texture; + } + + texture = loadTextureFromFile(file); + + if (texture) { + texture->updateSource(ETS_FROM_FILE); + addTexture(texture); + texture->drop(); // drop it because we created it, one grab too much + } + + if (!texture) + os::Printer::log("Could not load texture", file->getFileName(), ELL_WARNING); + } + + return texture; +} + +//! opens the file and loads it into the surface +video::ITexture *CNullDriver::loadTextureFromFile(io::IReadFile *file, const io::path &hashName) +{ + ITexture *texture = nullptr; + + IImage *image = createImageFromFile(file); + if (!image) + return nullptr; + + if (checkImage(image)) { + texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), image); + if (texture) + os::Printer::log("Loaded texture", file->getFileName(), ELL_DEBUG); + } + + image->drop(); + + return texture; +} + +//! adds a surface, not loaded or created by the Irrlicht Engine +void CNullDriver::addTexture(video::ITexture *texture) +{ + if (texture) { + SSurface s; + s.Surface = texture; + texture->grab(); + + Textures.push_back(s); + + // the new texture is now at the end of the texture list. when searching for + // the next new texture, the texture array will be sorted and the index of this texture + // will be changed. + } +} + +//! looks if the image is already loaded +video::ITexture *CNullDriver::findTexture(const io::path &filename) +{ + SSurface s; + SDummyTexture dummy(filename, ETT_2D); + s.Surface = &dummy; + + s32 index = Textures.binary_search(s); + if (index != -1) + return Textures[index].Surface; + + return 0; +} + +ITexture *CNullDriver::createDeviceDependentTexture(const io::path &name, IImage *image) +{ + SDummyTexture *dummy = new SDummyTexture(name, ETT_2D); + dummy->setSize(image->getDimension()); + return dummy; +} + +ITexture *CNullDriver::createDeviceDependentTextureCubemap(const io::path &name, const core::array &image) +{ + return new SDummyTexture(name, ETT_CUBEMAP); +} + +bool CNullDriver::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +{ + return false; +} + +bool CNullDriver::setRenderTarget(ITexture *texture, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +{ + if (texture) { + // create render target if require. + if (!SharedRenderTarget) + SharedRenderTarget = addRenderTarget(); + + ITexture *depthTexture = 0; + + // try to find available depth texture with require size. + for (u32 i = 0; i < SharedDepthTextures.size(); ++i) { + if (SharedDepthTextures[i]->getSize() == texture->getSize()) { + depthTexture = SharedDepthTextures[i]; + + break; + } + } + + // create depth texture if require. + if (!depthTexture) { + depthTexture = addRenderTargetTexture(texture->getSize(), "IRR_DEPTH_STENCIL", video::ECF_D24S8); + SharedDepthTextures.push_back(depthTexture); + } + + SharedRenderTarget->setTexture(texture, depthTexture); + + return setRenderTargetEx(SharedRenderTarget, clearFlag, clearColor, clearDepth, clearStencil); + } else { + return setRenderTargetEx(0, clearFlag, clearColor, clearDepth, clearStencil); + } +} + +//! sets a viewport +void CNullDriver::setViewPort(const core::rect &area) +{ +} + +//! gets the area of the current viewport +const core::rect &CNullDriver::getViewPort() const +{ + return ViewPort; +} + +//! draws a vertex primitive list +void CNullDriver::drawVertexPrimitiveList(const void *vertices, u32 vertexCount, const void *indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) +{ + if ((iType == EIT_16BIT) && (vertexCount > 65536)) + os::Printer::log("Too many vertices for 16bit index type, render artifacts may occur."); + PrimitivesDrawn += primitiveCount; +} + +//! draws a vertex primitive list in 2d +void CNullDriver::draw2DVertexPrimitiveList(const void *vertices, u32 vertexCount, const void *indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) +{ + if ((iType == EIT_16BIT) && (vertexCount > 65536)) + os::Printer::log("Too many vertices for 16bit index type, render artifacts may occur."); + PrimitivesDrawn += primitiveCount; +} + +//! Draws a 3d line. +void CNullDriver::draw3DLine(const core::vector3df &start, + const core::vector3df &end, SColor color) +{ +} + +//! Draws a 3d axis aligned box. +void CNullDriver::draw3DBox(const core::aabbox3d &box, SColor color) +{ + core::vector3df edges[8]; + box.getEdges(edges); + + // TODO: optimize into one big drawIndexPrimitive call. + + draw3DLine(edges[5], edges[1], color); + draw3DLine(edges[1], edges[3], color); + draw3DLine(edges[3], edges[7], color); + draw3DLine(edges[7], edges[5], color); + draw3DLine(edges[0], edges[2], color); + draw3DLine(edges[2], edges[6], color); + draw3DLine(edges[6], edges[4], color); + draw3DLine(edges[4], edges[0], color); + draw3DLine(edges[1], edges[0], color); + draw3DLine(edges[3], edges[2], color); + draw3DLine(edges[7], edges[6], color); + draw3DLine(edges[5], edges[4], color); +} + +//! draws an 2d image +void CNullDriver::draw2DImage(const video::ITexture *texture, const core::position2d &destPos, bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + draw2DImage(texture, destPos, core::rect(core::position2d(0, 0), core::dimension2di(texture->getOriginalSize())), + 0, + SColor(255, 255, 255, 255), + useAlphaChannelOfTexture); +} + +//! draws a set of 2d images, using a color and the alpha channel of the +//! texture if desired. +void CNullDriver::draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect, + SColor color, + bool useAlphaChannelOfTexture) +{ + const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); + + for (u32 i = 0; i < drawCount; ++i) { + draw2DImage(texture, positions[i], sourceRects[i], + clipRect, color, useAlphaChannelOfTexture); + } +} + +//! Draws a part of the texture into the rectangle. +void CNullDriver::draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect, + const video::SColor *const colors, bool useAlphaChannelOfTexture) +{ + if (destRect.isValid()) + draw2DImage(texture, core::position2d(destRect.UpperLeftCorner), + sourceRect, clipRect, colors ? colors[0] : video::SColor(0xffffffff), + useAlphaChannelOfTexture); +} + +//! Draws a 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted. +void CNullDriver::draw2DImage(const video::ITexture *texture, const core::position2d &destPos, + const core::rect &sourceRect, + const core::rect *clipRect, SColor color, + bool useAlphaChannelOfTexture) +{ +} + +//! Draw a 2d rectangle +void CNullDriver::draw2DRectangle(SColor color, const core::rect &pos, const core::rect *clip) +{ + draw2DRectangle(pos, color, color, color, color, clip); +} + +//! Draws a 2d rectangle with a gradient. +void CNullDriver::draw2DRectangle(const core::rect &pos, + SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip) +{ +} + +//! Draws a 2d line. +void CNullDriver::draw2DLine(const core::position2d &start, + const core::position2d &end, SColor color) +{ +} + +//! returns color format +ECOLOR_FORMAT CNullDriver::getColorFormat() const +{ + return ECF_R5G6B5; +} + +//! returns screen size +const core::dimension2d &CNullDriver::getScreenSize() const +{ + return ScreenSize; +} + +//! get current render target +IRenderTarget *CNullDriver::getCurrentRenderTarget() const +{ + return CurrentRenderTarget; +} + +const core::dimension2d &CNullDriver::getCurrentRenderTargetSize() const +{ + if (CurrentRenderTargetSize.Width == 0) + return ScreenSize; + else + return CurrentRenderTargetSize; +} + +// returns current frames per second value +s32 CNullDriver::getFPS() const +{ + return FPSCounter.getFPS(); +} + +//! returns amount of primitives (mostly triangles) were drawn in the last frame. +//! very useful method for statistics. +u32 CNullDriver::getPrimitiveCountDrawn(u32 param) const +{ + return (0 == param) ? FPSCounter.getPrimitive() : (1 == param) ? FPSCounter.getPrimitiveAverage() + : FPSCounter.getPrimitiveTotal(); +} + +//! Sets the dynamic ambient light color. The default color is +//! (0,0,0,0) which means it is dark. +//! \param color: New color of the ambient light. +void CNullDriver::setAmbientLight(const SColorf &color) +{ + AmbientLight = color; +} + +const SColorf &CNullDriver::getAmbientLight() const +{ + return AmbientLight; +} + +//! \return Returns the name of the video driver. Example: In case of the DIRECT3D8 +//! driver, it would return "Direct3D8". + +const char *CNullDriver::getName() const +{ + return "Irrlicht NullDevice"; +} + +//! Creates a boolean alpha channel of the texture based of an color key. +void CNullDriver::makeColorKeyTexture(video::ITexture *texture, + video::SColor color) const +{ + if (!texture) + return; + + if (texture->getColorFormat() != ECF_A1R5G5B5 && + texture->getColorFormat() != ECF_A8R8G8B8) { + os::Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR); + return; + } + + if (texture->getColorFormat() == ECF_A1R5G5B5) { + u16 *p = (u16 *)texture->lock(); + + if (!p) { + os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR); + return; + } + + const core::dimension2d dim = texture->getSize(); + const u32 pitch = texture->getPitch() / 2; + + // color with alpha disabled (i.e. fully transparent) + const u16 refZeroAlpha = (0x7fff & color.toA1R5G5B5()); + + const u32 pixels = pitch * dim.Height; + + for (u32 pixel = 0; pixel < pixels; ++pixel) { + // If the color matches the reference color, ignoring alphas, + // set the alpha to zero. + if (((*p) & 0x7fff) == refZeroAlpha) + (*p) = refZeroAlpha; + + ++p; + } + + texture->unlock(); + } else { + u32 *p = (u32 *)texture->lock(); + + if (!p) { + os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR); + return; + } + + core::dimension2d dim = texture->getSize(); + u32 pitch = texture->getPitch() / 4; + + // color with alpha disabled (fully transparent) + const u32 refZeroAlpha = 0x00ffffff & color.color; + + const u32 pixels = pitch * dim.Height; + for (u32 pixel = 0; pixel < pixels; ++pixel) { + // If the color matches the reference color, ignoring alphas, + // set the alpha to zero. + if (((*p) & 0x00ffffff) == refZeroAlpha) + (*p) = refZeroAlpha; + + ++p; + } + + texture->unlock(); + } + texture->regenerateMipMapLevels(); +} + +//! Creates an boolean alpha channel of the texture based of an color key position. +void CNullDriver::makeColorKeyTexture(video::ITexture *texture, + core::position2d colorKeyPixelPos) const +{ + if (!texture) + return; + + if (texture->getColorFormat() != ECF_A1R5G5B5 && + texture->getColorFormat() != ECF_A8R8G8B8) { + os::Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR); + return; + } + + SColor colorKey; + + if (texture->getColorFormat() == ECF_A1R5G5B5) { + u16 *p = (u16 *)texture->lock(ETLM_READ_ONLY); + + if (!p) { + os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR); + return; + } + + u32 pitch = texture->getPitch() / 2; + + const u16 key16Bit = 0x7fff & p[colorKeyPixelPos.Y * pitch + colorKeyPixelPos.X]; + + colorKey = video::A1R5G5B5toA8R8G8B8(key16Bit); + } else { + u32 *p = (u32 *)texture->lock(ETLM_READ_ONLY); + + if (!p) { + os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR); + return; + } + + u32 pitch = texture->getPitch() / 4; + colorKey = 0x00ffffff & p[colorKeyPixelPos.Y * pitch + colorKeyPixelPos.X]; + } + + texture->unlock(); + makeColorKeyTexture(texture, colorKey); +} + +//! Returns the maximum amount of primitives (mostly vertices) which +//! the device is able to render with one drawIndexedTriangleList +//! call. +u32 CNullDriver::getMaximalPrimitiveCount() const +{ + return 0xFFFFFFFF; +} + +//! checks triangle count and print warning if wrong +bool CNullDriver::checkPrimitiveCount(u32 prmCount) const +{ + const u32 m = getMaximalPrimitiveCount(); + + if (prmCount > m) { + char tmp[128]; + snprintf_irr(tmp, sizeof(tmp), "Could not draw triangles, too many primitives(%u), maximum is %u.", prmCount, m); + os::Printer::log(tmp, ELL_ERROR); + return false; + } + + return true; +} + +bool CNullDriver::checkImage(IImage *image) const +{ + return true; +} + +bool CNullDriver::checkImage(const core::array &image) const +{ + if (!image.size()) + return false; + + ECOLOR_FORMAT lastFormat = image[0]->getColorFormat(); + core::dimension2d lastSize = image[0]->getDimension(); + + for (u32 i = 0; i < image.size(); ++i) { + ECOLOR_FORMAT format = image[i]->getColorFormat(); + core::dimension2d size = image[i]->getDimension(); + + if (!checkImage(image[i])) + return false; + + if (format != lastFormat || size != lastSize) + return false; + } + return true; +} + +//! Enables or disables a texture creation flag. +void CNullDriver::setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled) +{ + if (enabled && ((flag == ETCF_ALWAYS_16_BIT) || (flag == ETCF_ALWAYS_32_BIT) || (flag == ETCF_OPTIMIZED_FOR_QUALITY) || (flag == ETCF_OPTIMIZED_FOR_SPEED))) { + // disable other formats + setTextureCreationFlag(ETCF_ALWAYS_16_BIT, false); + setTextureCreationFlag(ETCF_ALWAYS_32_BIT, false); + setTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY, false); + setTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED, false); + } + + // set flag + TextureCreationFlags = (TextureCreationFlags & (~flag)) | + ((((u32)!enabled) - 1) & flag); +} + +//! Returns if a texture creation flag is enabled or disabled. +bool CNullDriver::getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const +{ + return (TextureCreationFlags & flag) != 0; +} + +IImage *CNullDriver::createImageFromFile(const io::path &filename) +{ + if (!filename.size()) + return nullptr; + + io::IReadFile *file = FileSystem->createAndOpenFile(filename); + if (!file) { + os::Printer::log("Could not open file of image", filename, ELL_WARNING); + return nullptr; + } + + IImage *image = createImageFromFile(file); + file->drop(); + return image; +} + +IImage *CNullDriver::createImageFromFile(io::IReadFile *file) +{ + if (!file) + return nullptr; + + // try to load file based on file extension + for (int i = SurfaceLoader.size() - 1; i >= 0; --i) { + if (!SurfaceLoader[i]->isALoadableFileExtension(file->getFileName())) + continue; + + file->seek(0); // reset file position which might have changed due to previous loadImage calls + if (IImage *image = SurfaceLoader[i]->loadImage(file)) + return image; + } + + // try to load file based on what is in it + for (int i = SurfaceLoader.size() - 1; i >= 0; --i) { + if (SurfaceLoader[i]->isALoadableFileExtension(file->getFileName())) + continue; // extension was tried above already + file->seek(0); // dito + if (!SurfaceLoader[i]->isALoadableFileFormat(file)) + continue; + + file->seek(0); + if (IImage *image = SurfaceLoader[i]->loadImage(file)) + return image; + } + + return nullptr; +} + +//! Writes the provided image to disk file +bool CNullDriver::writeImageToFile(IImage *image, const io::path &filename, u32 param) +{ + io::IWriteFile *file = FileSystem->createAndWriteFile(filename); + if (!file) + return false; + + bool result = writeImageToFile(image, file, param); + file->drop(); + + return result; +} + +//! Writes the provided image to a file. +bool CNullDriver::writeImageToFile(IImage *image, io::IWriteFile *file, u32 param) +{ + if (!file) + return false; + + for (s32 i = SurfaceWriter.size() - 1; i >= 0; --i) { + if (SurfaceWriter[i]->isAWriteableFileExtension(file->getFileName())) { + bool written = SurfaceWriter[i]->writeImage(file, image, param); + if (written) + return true; + } + } + return false; // failed to write +} + +//! Creates a software image from a byte array. +IImage *CNullDriver::createImageFromData(ECOLOR_FORMAT format, + const core::dimension2d &size, void *data, bool ownForeignMemory, + bool deleteMemory) +{ + return new CImage(format, size, data, ownForeignMemory, deleteMemory); +} + +//! Creates an empty software image. +IImage *CNullDriver::createImage(ECOLOR_FORMAT format, const core::dimension2d &size) +{ + return new CImage(format, size); +} + +//! Creates a software image from part of a texture. +IImage *CNullDriver::createImage(ITexture *texture, const core::position2d &pos, const core::dimension2d &size) +{ + if ((pos == core::position2di(0, 0)) && (size == texture->getSize())) { + void *data = texture->lock(ETLM_READ_ONLY); + if (!data) + return 0; + IImage *image = new CImage(texture->getColorFormat(), size, data, false, false); + texture->unlock(); + return image; + } else { + // make sure to avoid buffer overruns + // make the vector a separate variable for g++ 3.x + const core::vector2d leftUpper(core::clamp(static_cast(pos.X), 0u, texture->getSize().Width), + core::clamp(static_cast(pos.Y), 0u, texture->getSize().Height)); + const core::rect clamped(leftUpper, + core::dimension2du(core::clamp(static_cast(size.Width), 0u, texture->getSize().Width), + core::clamp(static_cast(size.Height), 0u, texture->getSize().Height))); + if (!clamped.isValid()) + return 0; + u8 *src = static_cast(texture->lock(ETLM_READ_ONLY)); + if (!src) + return 0; + IImage *image = new CImage(texture->getColorFormat(), clamped.getSize()); + u8 *dst = static_cast(image->getData()); + src += clamped.UpperLeftCorner.Y * texture->getPitch() + image->getBytesPerPixel() * clamped.UpperLeftCorner.X; + for (u32 i = 0; i < clamped.getHeight(); ++i) { + video::CColorConverter::convert_viaFormat(src, texture->getColorFormat(), clamped.getWidth(), dst, image->getColorFormat()); + src += texture->getPitch(); + dst += image->getPitch(); + } + texture->unlock(); + return image; + } +} + +//! Sets the fog mode. +void CNullDriver::setFog(SColor color, E_FOG_TYPE fogType, f32 start, f32 end, + f32 density, bool pixelFog, bool rangeFog) +{ + FogColor = color; + FogType = fogType; + FogStart = start; + FogEnd = end; + FogDensity = density; + PixelFog = pixelFog; + RangeFog = rangeFog; +} + +//! Gets the fog mode. +void CNullDriver::getFog(SColor &color, E_FOG_TYPE &fogType, f32 &start, f32 &end, + f32 &density, bool &pixelFog, bool &rangeFog) +{ + color = FogColor; + fogType = FogType; + start = FogStart; + end = FogEnd; + density = FogDensity; + pixelFog = PixelFog; + rangeFog = RangeFog; +} + +//! Draws a mesh buffer +void CNullDriver::drawMeshBuffer(const scene::IMeshBuffer *mb) +{ + if (!mb) + return; + + // IVertexBuffer and IIndexBuffer later + SHWBufferLink *HWBuffer = getBufferLink(mb); + + if (HWBuffer) + drawHardwareBuffer(HWBuffer); + else + drawVertexPrimitiveList(mb->getVertices(), mb->getVertexCount(), mb->getIndices(), mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType()); +} + +//! Draws the normals of a mesh buffer +void CNullDriver::drawMeshBufferNormals(const scene::IMeshBuffer *mb, f32 length, SColor color) +{ + const u32 count = mb->getVertexCount(); + const bool normalize = mb->getMaterial().NormalizeNormals; + + for (u32 i = 0; i < count; ++i) { + core::vector3df normalizedNormal = mb->getNormal(i); + if (normalize) + normalizedNormal.normalize(); + + const core::vector3df &pos = mb->getPosition(i); + draw3DLine(pos, pos + (normalizedNormal * length), color); + } +} + +CNullDriver::SHWBufferLink *CNullDriver::getBufferLink(const scene::IMeshBuffer *mb) +{ + if (!mb || !isHardwareBufferRecommend(mb)) + return 0; + + // search for hardware links + SHWBufferLink *HWBuffer = reinterpret_cast(mb->getHWBuffer()); + if (HWBuffer) + return HWBuffer; + + return createHardwareBuffer(mb); // no hardware links, and mesh wants one, create it +} + +//! Update all hardware buffers, remove unused ones +void CNullDriver::updateAllHardwareBuffers() +{ + auto it = HWBufferList.begin(); + while (it != HWBufferList.end()) { + SHWBufferLink *Link = *it; + ++it; + + if (!Link->MeshBuffer || Link->MeshBuffer->getReferenceCount() == 1) + deleteHardwareBuffer(Link); + } +} + +void CNullDriver::deleteHardwareBuffer(SHWBufferLink *HWBuffer) +{ + if (!HWBuffer) + return; + HWBufferList.erase(HWBuffer->listPosition); + delete HWBuffer; +} + +//! Remove hardware buffer +void CNullDriver::removeHardwareBuffer(const scene::IMeshBuffer *mb) +{ + if (!mb) + return; + SHWBufferLink *HWBuffer = reinterpret_cast(mb->getHWBuffer()); + if (HWBuffer) + deleteHardwareBuffer(HWBuffer); +} + +//! Remove all hardware buffers +void CNullDriver::removeAllHardwareBuffers() +{ + while (!HWBufferList.empty()) + deleteHardwareBuffer(HWBufferList.front()); +} + +bool CNullDriver::isHardwareBufferRecommend(const scene::IMeshBuffer *mb) +{ + if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER)) + return false; + + if (mb->getVertexCount() < MinVertexCountForVBO) + return false; + + return true; +} + +//! Create occlusion query. +/** Use node for identification and mesh for occlusion test. */ +void CNullDriver::addOcclusionQuery(scene::ISceneNode *node, const scene::IMesh *mesh) +{ + if (!node) + return; + if (!mesh) { + if ((node->getType() != scene::ESNT_MESH) && (node->getType() != scene::ESNT_ANIMATED_MESH)) + return; + else if (node->getType() == scene::ESNT_MESH) + mesh = static_cast(node)->getMesh(); + else + mesh = static_cast(node)->getMesh()->getMesh(0); + if (!mesh) + return; + } + + // search for query + s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if (index != -1) { + if (OcclusionQueries[index].Mesh != mesh) { + OcclusionQueries[index].Mesh->drop(); + OcclusionQueries[index].Mesh = mesh; + mesh->grab(); + } + } else { + OcclusionQueries.push_back(SOccQuery(node, mesh)); + node->setAutomaticCulling(node->getAutomaticCulling() | scene::EAC_OCC_QUERY); + } +} + +//! Remove occlusion query. +void CNullDriver::removeOcclusionQuery(scene::ISceneNode *node) +{ + // search for query + s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if (index != -1) { + node->setAutomaticCulling(node->getAutomaticCulling() & ~scene::EAC_OCC_QUERY); + OcclusionQueries.erase(index); + } +} + +//! Remove all occlusion queries. +void CNullDriver::removeAllOcclusionQueries() +{ + for (s32 i = OcclusionQueries.size() - 1; i >= 0; --i) { + removeOcclusionQuery(OcclusionQueries[i].Node); + } +} + +//! Run occlusion query. Draws mesh stored in query. +/** If the mesh shall be rendered visible, use +flag to enable the proper material setting. */ +void CNullDriver::runOcclusionQuery(scene::ISceneNode *node, bool visible) +{ + if (!node) + return; + s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if (index == -1) + return; + OcclusionQueries[index].Run = 0; + if (!visible) { + SMaterial mat; + mat.Lighting = false; + mat.AntiAliasing = 0; + mat.ColorMask = ECP_NONE; + mat.GouraudShading = false; + mat.ZWriteEnable = EZW_OFF; + setMaterial(mat); + } + setTransform(video::ETS_WORLD, node->getAbsoluteTransformation()); + const scene::IMesh *mesh = OcclusionQueries[index].Mesh; + for (u32 i = 0; i < mesh->getMeshBufferCount(); ++i) { + if (visible) + setMaterial(mesh->getMeshBuffer(i)->getMaterial()); + drawMeshBuffer(mesh->getMeshBuffer(i)); + } +} + +//! Run all occlusion queries. Draws all meshes stored in queries. +/** If the meshes shall not be rendered visible, use +overrideMaterial to disable the color and depth buffer. */ +void CNullDriver::runAllOcclusionQueries(bool visible) +{ + for (u32 i = 0; i < OcclusionQueries.size(); ++i) + runOcclusionQuery(OcclusionQueries[i].Node, visible); +} + +//! Update occlusion query. Retrieves results from GPU. +/** If the query shall not block, set the flag to false. +Update might not occur in this case, though */ +void CNullDriver::updateOcclusionQuery(scene::ISceneNode *node, bool block) +{ +} + +//! Update all occlusion queries. Retrieves results from GPU. +/** If the query shall not block, set the flag to false. +Update might not occur in this case, though */ +void CNullDriver::updateAllOcclusionQueries(bool block) +{ + for (u32 i = 0; i < OcclusionQueries.size(); ++i) { + if (OcclusionQueries[i].Run == u32(~0)) + continue; + updateOcclusionQuery(OcclusionQueries[i].Node, block); + ++OcclusionQueries[i].Run; + if (OcclusionQueries[i].Run > 1000) + removeOcclusionQuery(OcclusionQueries[i].Node); + } +} + +//! Return query result. +/** Return value is the number of visible pixels/fragments. +The value is a safe approximation, i.e. can be larger then the +actual value of pixels. */ +u32 CNullDriver::getOcclusionQueryResult(scene::ISceneNode *node) const +{ + return ~0; +} + +//! Create render target. +IRenderTarget *CNullDriver::addRenderTarget() +{ + return 0; +} + +//! Remove render target. +void CNullDriver::removeRenderTarget(IRenderTarget *renderTarget) +{ + if (!renderTarget) + return; + + for (u32 i = 0; i < RenderTargets.size(); ++i) { + if (RenderTargets[i] == renderTarget) { + RenderTargets[i]->drop(); + RenderTargets.erase(i); + + return; + } + } +} + +//! Remove all render targets. +void CNullDriver::removeAllRenderTargets() +{ + for (u32 i = 0; i < RenderTargets.size(); ++i) + RenderTargets[i]->drop(); + + RenderTargets.clear(); + + SharedRenderTarget = 0; +} + +//! Only used by the internal engine. Used to notify the driver that +//! the window was resized. +void CNullDriver::OnResize(const core::dimension2d &size) +{ + if (ViewPort.getWidth() == (s32)ScreenSize.Width && + ViewPort.getHeight() == (s32)ScreenSize.Height) + ViewPort = core::rect(core::position2d(0, 0), + core::dimension2di(size)); + + ScreenSize = size; +} + +// adds a material renderer and drops it afterwards. To be used for internal creation +s32 CNullDriver::addAndDropMaterialRenderer(IMaterialRenderer *m) +{ + s32 i = addMaterialRenderer(m); + + if (m) + m->drop(); + + return i; +} + +//! Adds a new material renderer to the video device. +s32 CNullDriver::addMaterialRenderer(IMaterialRenderer *renderer, const char *name) +{ + if (!renderer) + return -1; + + SMaterialRenderer r; + r.Renderer = renderer; + r.Name = name; + + if (name == 0 && MaterialRenderers.size() < numBuiltInMaterials) { + // set name of built in renderer so that we don't have to implement name + // setting in all available renderers. + r.Name = sBuiltInMaterialTypeNames[MaterialRenderers.size()]; + } + + MaterialRenderers.push_back(r); + renderer->grab(); + + return MaterialRenderers.size() - 1; +} + +//! Sets the name of a material renderer. +void CNullDriver::setMaterialRendererName(u32 idx, const char *name) +{ + if (idx < numBuiltInMaterials || idx >= MaterialRenderers.size()) + return; + + MaterialRenderers[idx].Name = name; +} + +void CNullDriver::swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames) +{ + if (idx1 < MaterialRenderers.size() && idx2 < MaterialRenderers.size()) { + irr::core::swap(MaterialRenderers[idx1].Renderer, MaterialRenderers[idx2].Renderer); + if (swapNames) + irr::core::swap(MaterialRenderers[idx1].Name, MaterialRenderers[idx2].Name); + } +} + +//! Returns driver and operating system specific data about the IVideoDriver. +const SExposedVideoData &CNullDriver::getExposedVideoData() +{ + return ExposedData; +} + +//! Returns type of video driver +E_DRIVER_TYPE CNullDriver::getDriverType() const +{ + return EDT_NULL; +} + +//! deletes all material renderers +void CNullDriver::deleteMaterialRenders() +{ + // delete material renderers + for (u32 i = 0; i < MaterialRenderers.size(); ++i) + if (MaterialRenderers[i].Renderer) + MaterialRenderers[i].Renderer->drop(); + + MaterialRenderers.clear(); +} + +//! Returns pointer to material renderer or null +IMaterialRenderer *CNullDriver::getMaterialRenderer(u32 idx) const +{ + if (idx < MaterialRenderers.size()) + return MaterialRenderers[idx].Renderer; + else + return 0; +} + +//! Returns amount of currently available material renderers. +u32 CNullDriver::getMaterialRendererCount() const +{ + return MaterialRenderers.size(); +} + +//! Returns name of the material renderer +const char *CNullDriver::getMaterialRendererName(u32 idx) const +{ + if (idx < MaterialRenderers.size()) + return MaterialRenderers[idx].Name.c_str(); + + return 0; +} + +//! Returns pointer to the IGPUProgrammingServices interface. +IGPUProgrammingServices *CNullDriver::getGPUProgrammingServices() +{ + return this; +} + +//! Adds a new material renderer to the VideoDriver, based on a high level shading language. +s32 CNullDriver::addHighLevelShaderMaterial( + const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + const c8 *pixelShaderProgram, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + const c8 *geometryShaderProgram, + const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, + scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) +{ + os::Printer::log("High level shader materials not available (yet) in this driver, sorry"); + return -1; +} + +s32 CNullDriver::addHighLevelShaderMaterialFromFiles( + const io::path &vertexShaderProgramFileName, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + const io::path &pixelShaderProgramFileName, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + const io::path &geometryShaderProgramFileName, + const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, + scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) +{ + io::IReadFile *vsfile = 0; + io::IReadFile *psfile = 0; + io::IReadFile *gsfile = 0; + + if (vertexShaderProgramFileName.size()) { + vsfile = FileSystem->createAndOpenFile(vertexShaderProgramFileName); + if (!vsfile) { + os::Printer::log("Could not open vertex shader program file", + vertexShaderProgramFileName, ELL_WARNING); + } + } + + if (pixelShaderProgramFileName.size()) { + psfile = FileSystem->createAndOpenFile(pixelShaderProgramFileName); + if (!psfile) { + os::Printer::log("Could not open pixel shader program file", + pixelShaderProgramFileName, ELL_WARNING); + } + } + + if (geometryShaderProgramFileName.size()) { + gsfile = FileSystem->createAndOpenFile(geometryShaderProgramFileName); + if (!gsfile) { + os::Printer::log("Could not open geometry shader program file", + geometryShaderProgramFileName, ELL_WARNING); + } + } + + s32 result = addHighLevelShaderMaterialFromFiles( + vsfile, vertexShaderEntryPointName, vsCompileTarget, + psfile, pixelShaderEntryPointName, psCompileTarget, + gsfile, geometryShaderEntryPointName, gsCompileTarget, + inType, outType, verticesOut, + callback, baseMaterial, userData); + + if (psfile) + psfile->drop(); + + if (vsfile) + vsfile->drop(); + + if (gsfile) + gsfile->drop(); + + return result; +} + +s32 CNullDriver::addHighLevelShaderMaterialFromFiles( + io::IReadFile *vertexShaderProgram, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + io::IReadFile *pixelShaderProgram, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + io::IReadFile *geometryShaderProgram, + const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, + scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) +{ + c8 *vs = 0; + c8 *ps = 0; + c8 *gs = 0; + + if (vertexShaderProgram) { + const long size = vertexShaderProgram->getSize(); + if (size) { + vs = new c8[size + 1]; + vertexShaderProgram->read(vs, size); + vs[size] = 0; + } + } + + if (pixelShaderProgram) { + const long size = pixelShaderProgram->getSize(); + if (size) { + // if both handles are the same we must reset the file + if (pixelShaderProgram == vertexShaderProgram) + pixelShaderProgram->seek(0); + ps = new c8[size + 1]; + pixelShaderProgram->read(ps, size); + ps[size] = 0; + } + } + + if (geometryShaderProgram) { + const long size = geometryShaderProgram->getSize(); + if (size) { + // if both handles are the same we must reset the file + if ((geometryShaderProgram == vertexShaderProgram) || + (geometryShaderProgram == pixelShaderProgram)) + geometryShaderProgram->seek(0); + gs = new c8[size + 1]; + geometryShaderProgram->read(gs, size); + gs[size] = 0; + } + } + + s32 result = this->addHighLevelShaderMaterial( + vs, vertexShaderEntryPointName, vsCompileTarget, + ps, pixelShaderEntryPointName, psCompileTarget, + gs, geometryShaderEntryPointName, gsCompileTarget, + inType, outType, verticesOut, + callback, baseMaterial, userData); + + delete[] vs; + delete[] ps; + delete[] gs; + + return result; +} + +void CNullDriver::deleteShaderMaterial(s32 material) +{ + const u32 idx = (u32)material; + if (idx < numBuiltInMaterials || idx >= MaterialRenderers.size()) + return; + + // if this is the last material we can drop it without consequence + if (idx == MaterialRenderers.size() - 1) { + if (MaterialRenderers[idx].Renderer) + MaterialRenderers[idx].Renderer->drop(); + MaterialRenderers.erase(idx); + return; + } + // otherwise replace with a dummy renderer, we have to preserve the IDs + auto &ref = MaterialRenderers[idx]; + if (ref.Renderer) + ref.Renderer->drop(); + ref.Renderer = new CDummyMaterialRenderer(); + ref.Name.clear(); +} + +//! Creates a render target texture. +ITexture *CNullDriver::addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format) +{ + return 0; +} + +ITexture *CNullDriver::addRenderTargetTextureCubemap(const irr::u32 sideLen, + const io::path &name, const ECOLOR_FORMAT format) +{ + return 0; +} + +void CNullDriver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) +{ +} + +//! Returns a pointer to the mesh manipulator. +scene::IMeshManipulator *CNullDriver::getMeshManipulator() +{ + return MeshManipulator; +} + +//! Returns an image created from the last rendered frame. +IImage *CNullDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target) +{ + return 0; +} + +// prints renderer version +void CNullDriver::printVersion() +{ + core::stringc namePrint = "Using renderer: "; + namePrint += getName(); + os::Printer::log(namePrint.c_str(), ELL_INFORMATION); +} + +//! creates a video driver +IVideoDriver *createNullDriver(io::IFileSystem *io, const core::dimension2d &screenSize) +{ + CNullDriver *nullDriver = new CNullDriver(io, screenSize); + + // create empty material renderers + for (u32 i = 0; sBuiltInMaterialTypeNames[i]; ++i) { + IMaterialRenderer *imr = new IMaterialRenderer(); + nullDriver->addMaterialRenderer(imr); + imr->drop(); + } + + return nullDriver; +} + +//! Set/unset a clipping plane. +//! There are at least 6 clipping planes available for the user to set at will. +//! \param index: The plane index. Must be between 0 and MaxUserClipPlanes. +//! \param plane: The plane itself. +//! \param enable: If true, enable the clipping plane else disable it. +bool CNullDriver::setClipPlane(u32 index, const core::plane3df &plane, bool enable) +{ + return false; +} + +//! Enable/disable a clipping plane. +void CNullDriver::enableClipPlane(u32 index, bool enable) +{ + // not necessary +} + +void CNullDriver::setMinHardwareBufferVertexCount(u32 count) +{ + MinVertexCountForVBO = count; +} + +SOverrideMaterial &CNullDriver::getOverrideMaterial() +{ + return OverrideMaterial; +} + +//! Get the 2d override material for altering its values +SMaterial &CNullDriver::getMaterial2D() +{ + return OverrideMaterial2D; +} + +//! Enable the 2d override material +void CNullDriver::enableMaterial2D(bool enable) +{ + OverrideMaterial2DEnabled = enable; +} + +core::dimension2du CNullDriver::getMaxTextureSize() const +{ + return core::dimension2du(0x10000, 0x10000); // maybe large enough +} + +bool CNullDriver::needsTransparentRenderPass(const irr::video::SMaterial &material) const +{ + // TODO: I suspect it would be nice if the material had an enum for further control. + // Especially it probably makes sense to allow disabling transparent render pass as soon as material.ZWriteEnable is on. + // But then we might want an enum for the renderpass in material instead of just a transparency flag in material - and that's more work. + // Or we could at least set return false when material.ZWriteEnable is EZW_ON? Still considering that... + // Be careful - this function is deeply connected to getWriteZBuffer as transparent render passes are usually about rendering with + // zwrite disabled and getWriteZBuffer calls this function. + + video::IMaterialRenderer *rnd = getMaterialRenderer(material.MaterialType); + // TODO: I suspect IMaterialRenderer::isTransparent also often could use SMaterial as parameter + // We could for example then get rid of IsTransparent function in SMaterial and move that to the software material renderer. + if (rnd && rnd->isTransparent()) + return true; + + return false; +} + +//! Color conversion convenience function +/** Convert an image (as array of pixels) from source to destination +array, thereby converting the color format. The pixel size is +determined by the color formats. +\param sP Pointer to source +\param sF Color format of source +\param sN Number of pixels to convert, both array must be large enough +\param dP Pointer to destination +\param dF Color format of destination +*/ +void CNullDriver::convertColor(const void *sP, ECOLOR_FORMAT sF, s32 sN, + void *dP, ECOLOR_FORMAT dF) const +{ + video::CColorConverter::convert_viaFormat(sP, sF, sN, dP, dF); +} + +} // end namespace +} // end namespace diff --git a/irr/src/CNullDriver.h b/irr/src/CNullDriver.h new file mode 100644 index 000000000..d47212c0f --- /dev/null +++ b/irr/src/CNullDriver.h @@ -0,0 +1,742 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IVideoDriver.h" +#include "IFileSystem.h" +#include "IGPUProgrammingServices.h" +#include "irrArray.h" +#include "irrString.h" +#include "IAttributes.h" +#include "IMesh.h" +#include "IMeshBuffer.h" +#include "IMeshSceneNode.h" +#include "CFPSCounter.h" +#include "S3DVertex.h" +#include "SVertexIndex.h" +#include "SExposedVideoData.h" +#include + +namespace irr +{ +namespace io +{ +class IWriteFile; +class IReadFile; +} // end namespace io +namespace video +{ +class IImageLoader; +class IImageWriter; + +class CNullDriver : public IVideoDriver, public IGPUProgrammingServices +{ +public: + //! constructor + CNullDriver(io::IFileSystem *io, const core::dimension2d &screenSize); + + //! destructor + virtual ~CNullDriver(); + + virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0, + const SExposedVideoData &videoData = SExposedVideoData(), core::rect *sourceRect = 0) override; + + bool endScene() override; + + //! Disable a feature of the driver. + void disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag = true) override; + + //! queries the features of the driver, returns true if feature is available + bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override; + + //! Get attributes of the actual video driver + const io::IAttributes &getDriverAttributes() const override; + + //! sets transformation + void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) override; + + //! Retrieve the number of image loaders + u32 getImageLoaderCount() const override; + + //! Retrieve the given image loader + IImageLoader *getImageLoader(u32 n) override; + + //! Retrieve the number of image writers + u32 getImageWriterCount() const override; + + //! Retrieve the given image writer + IImageWriter *getImageWriter(u32 n) override; + + //! sets a material + void setMaterial(const SMaterial &material) override; + + //! loads a Texture + ITexture *getTexture(const io::path &filename) override; + + //! loads a Texture + ITexture *getTexture(io::IReadFile *file) override; + + //! Returns amount of textures currently loaded + u32 getTextureCount() const override; + + ITexture *addTexture(const core::dimension2d &size, const io::path &name, ECOLOR_FORMAT format = ECF_A8R8G8B8) override; + + ITexture *addTexture(const io::path &name, IImage *image) override; + + virtual ITexture *addTextureCubemap(const io::path &name, IImage *imagePosX, IImage *imageNegX, IImage *imagePosY, + IImage *imageNegY, IImage *imagePosZ, IImage *imageNegZ) override; + + ITexture *addTextureCubemap(const irr::u32 sideLen, const io::path &name, ECOLOR_FORMAT format = ECF_A8R8G8B8) override; + + virtual bool setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), + f32 clearDepth = 1.f, u8 clearStencil = 0) override; + + virtual bool setRenderTarget(ITexture *texture, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), + f32 clearDepth = 1.f, u8 clearStencil = 0) override; + + //! sets a viewport + void setViewPort(const core::rect &area) override; + + //! gets the area of the current viewport + const core::rect &getViewPort() const override; + + //! draws a vertex primitive list + virtual void drawVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType = EVT_STANDARD, scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES, + E_INDEX_TYPE iType = EIT_16BIT) override; + + //! draws a vertex primitive list in 2d + virtual void draw2DVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType = EVT_STANDARD, scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES, + E_INDEX_TYPE iType = EIT_16BIT) override; + + //! Draws a 3d line. + virtual void draw3DLine(const core::vector3df &start, + const core::vector3df &end, SColor color = SColor(255, 255, 255, 255)) override; + + //! Draws a 3d axis aligned box. + virtual void draw3DBox(const core::aabbox3d &box, + SColor color = SColor(255, 255, 255, 255)) override; + + //! draws an 2d image + void draw2DImage(const video::ITexture *texture, const core::position2d &destPos, bool useAlphaChannelOfTexture) override; + + //! Draws a set of 2d images, using a color and the alpha channel of the texture. + /** All drawings are clipped against clipRect (if != 0). + The subtextures are defined by the array of sourceRects and are + positioned using the array of positions. + \param texture Texture to be drawn. + \param pos Array of upper left 2d destinations where the images + will be drawn. + \param sourceRects Source rectangles of the image. + \param clipRect Pointer to rectangle on the screen where the + images are clipped to. + If this pointer is 0 then the image is not clipped. + \param color Color with which the image is drawn. + Note that the alpha component is used. If alpha is other than + 255, the image will be transparent. + \param useAlphaChannelOfTexture: If true, the alpha channel of + the texture is used to draw the image. */ + virtual void draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect = 0, + SColor color = SColor(255, 255, 255, 255), + bool useAlphaChannelOfTexture = false) override; + + //! Draws a 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted. + virtual void draw2DImage(const video::ITexture *texture, const core::position2d &destPos, + const core::rect &sourceRect, const core::rect *clipRect = 0, + SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override; + + //! Draws a part of the texture into the rectangle. + virtual void draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect = 0, + const video::SColor *const colors = 0, bool useAlphaChannelOfTexture = false) override; + + //! Draws a 2d rectangle + void draw2DRectangle(SColor color, const core::rect &pos, const core::rect *clip = 0) override; + + //! Draws a 2d rectangle with a gradient. + virtual void draw2DRectangle(const core::rect &pos, + SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip = 0) override; + + //! Draws a 2d line. + virtual void draw2DLine(const core::position2d &start, + const core::position2d &end, + SColor color = SColor(255, 255, 255, 255)) override; + + virtual void setFog(SColor color = SColor(0, 255, 255, 255), + E_FOG_TYPE fogType = EFT_FOG_LINEAR, + f32 start = 50.0f, f32 end = 100.0f, f32 density = 0.01f, + bool pixelFog = false, bool rangeFog = false) override; + + virtual void getFog(SColor &color, E_FOG_TYPE &fogType, + f32 &start, f32 &end, f32 &density, + bool &pixelFog, bool &rangeFog) override; + + //! get color format of the current color buffer + ECOLOR_FORMAT getColorFormat() const override; + + //! get screen size + const core::dimension2d &getScreenSize() const override; + + //! get current render target + IRenderTarget *getCurrentRenderTarget() const; + + //! get render target size + const core::dimension2d &getCurrentRenderTargetSize() const override; + + // get current frames per second value + s32 getFPS() const override; + + //! returns amount of primitives (mostly triangles) were drawn in the last frame. + //! very useful method for statistics. + u32 getPrimitiveCountDrawn(u32 param = 0) const override; + + //! \return Returns the name of the video driver. Example: In case of the DIRECT3D8 + //! driver, it would return "Direct3D8.1". + const char *getName() const override; + + //! Sets the dynamic ambient light color. The default color is + //! (0,0,0,0) which means it is dark. + //! \param color: New color of the ambient light. + void setAmbientLight(const SColorf &color) override; + + //! Get the global ambient light currently used by the driver + const SColorf &getAmbientLight() const override; + + //! Adds an external image loader to the engine. + void addExternalImageLoader(IImageLoader *loader) override; + + //! Adds an external image writer to the engine. + void addExternalImageWriter(IImageWriter *writer) override; + + //! Removes a texture from the texture cache and deletes it, freeing lot of + //! memory. + void removeTexture(ITexture *texture) override; + + //! Removes all texture from the texture cache and deletes them, freeing lot of + //! memory. + void removeAllTextures() override; + + //! Creates a render target texture. + virtual ITexture *addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override; + + //! Creates a render target texture for a cubemap + ITexture *addRenderTargetTextureCubemap(const irr::u32 sideLen, + const io::path &name, const ECOLOR_FORMAT format) override; + + //! Creates an 1bit alpha channel of the texture based of an color key. + void makeColorKeyTexture(video::ITexture *texture, video::SColor color) const override; + + //! Creates an 1bit alpha channel of the texture based of an color key position. + virtual void makeColorKeyTexture(video::ITexture *texture, + core::position2d colorKeyPixelPos) const override; + + //! Returns the maximum amount of primitives (mostly vertices) which + //! the device is able to render with one drawIndexedTriangleList + //! call. + u32 getMaximalPrimitiveCount() const override; + + //! Enables or disables a texture creation flag. + void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled) override; + + //! Returns if a texture creation flag is enabled or disabled. + bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const override; + + IImage *createImageFromFile(const io::path &filename) override; + + IImage *createImageFromFile(io::IReadFile *file) override; + + //! Creates a software image from a byte array. + /** \param useForeignMemory: If true, the image will use the data pointer + directly and own it from now on, which means it will also try to delete [] the + data when the image will be destructed. If false, the memory will by copied. */ + virtual IImage *createImageFromData(ECOLOR_FORMAT format, + const core::dimension2d &size, void *data, bool ownForeignMemory = false, + bool deleteMemory = true) override; + + //! Creates an empty software image. + IImage *createImage(ECOLOR_FORMAT format, const core::dimension2d &size) override; + + //! Creates a software image from part of a texture. + virtual IImage *createImage(ITexture *texture, + const core::position2d &pos, + const core::dimension2d &size) override; + + //! Draws a mesh buffer + void drawMeshBuffer(const scene::IMeshBuffer *mb) override; + + //! Draws the normals of a mesh buffer + virtual void drawMeshBufferNormals(const scene::IMeshBuffer *mb, f32 length = 10.f, + SColor color = 0xffffffff) override; + + //! Check if the driver supports creating textures with the given color format + bool queryTextureFormat(ECOLOR_FORMAT format) const override + { + return false; + } + +protected: + struct SHWBufferLink + { + SHWBufferLink(const scene::IMeshBuffer *_MeshBuffer) : + MeshBuffer(_MeshBuffer), + ChangedID_Vertex(0), ChangedID_Index(0), + Mapped_Vertex(scene::EHM_NEVER), Mapped_Index(scene::EHM_NEVER) + { + if (MeshBuffer) { + MeshBuffer->grab(); + MeshBuffer->setHWBuffer(reinterpret_cast(this)); + } + } + + virtual ~SHWBufferLink() + { + if (MeshBuffer) { + MeshBuffer->setHWBuffer(NULL); + MeshBuffer->drop(); + } + } + + const scene::IMeshBuffer *MeshBuffer; + u32 ChangedID_Vertex; + u32 ChangedID_Index; + scene::E_HARDWARE_MAPPING Mapped_Vertex; + scene::E_HARDWARE_MAPPING Mapped_Index; + std::list::iterator listPosition; + }; + + //! Gets hardware buffer link from a meshbuffer (may create or update buffer) + virtual SHWBufferLink *getBufferLink(const scene::IMeshBuffer *mb); + + //! updates hardware buffer if needed (only some drivers can) + virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer) { return false; } + + //! Draw hardware buffer (only some drivers can) + virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer) {} + + //! Delete hardware buffer + virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer); + + //! Create hardware buffer from mesh (only some drivers can) + virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer *mb) { return 0; } + +public: + //! Remove hardware buffer + void removeHardwareBuffer(const scene::IMeshBuffer *mb) override; + + //! Remove all hardware buffers + void removeAllHardwareBuffers() override; + + //! Update all hardware buffers, remove unused ones + virtual void updateAllHardwareBuffers(); + + //! is vbo recommended on this mesh? + virtual bool isHardwareBufferRecommend(const scene::IMeshBuffer *mb); + + //! Create occlusion query. + /** Use node for identification and mesh for occlusion test. */ + virtual void addOcclusionQuery(scene::ISceneNode *node, + const scene::IMesh *mesh = 0) override; + + //! Remove occlusion query. + void removeOcclusionQuery(scene::ISceneNode *node) override; + + //! Remove all occlusion queries. + void removeAllOcclusionQueries() override; + + //! Run occlusion query. Draws mesh stored in query. + /** If the mesh shall not be rendered visible, use + overrideMaterial to disable the color and depth buffer. */ + void runOcclusionQuery(scene::ISceneNode *node, bool visible = false) override; + + //! Run all occlusion queries. Draws all meshes stored in queries. + /** If the meshes shall not be rendered visible, use + overrideMaterial to disable the color and depth buffer. */ + void runAllOcclusionQueries(bool visible = false) override; + + //! Update occlusion query. Retrieves results from GPU. + /** If the query shall not block, set the flag to false. + Update might not occur in this case, though */ + void updateOcclusionQuery(scene::ISceneNode *node, bool block = true) override; + + //! Update all occlusion queries. Retrieves results from GPU. + /** If the query shall not block, set the flag to false. + Update might not occur in this case, though */ + void updateAllOcclusionQueries(bool block = true) override; + + //! Return query result. + /** Return value is the number of visible pixels/fragments. + The value is a safe approximation, i.e. can be larger than the + actual value of pixels. */ + u32 getOcclusionQueryResult(scene::ISceneNode *node) const override; + + //! Create render target. + IRenderTarget *addRenderTarget() override; + + //! Remove render target. + void removeRenderTarget(IRenderTarget *renderTarget) override; + + //! Remove all render targets. + void removeAllRenderTargets() override; + + //! Only used by the engine internally. + /** Used to notify the driver that the window was resized. */ + void OnResize(const core::dimension2d &size) override; + + //! Adds a new material renderer to the video device. + virtual s32 addMaterialRenderer(IMaterialRenderer *renderer, + const char *name = 0) override; + + //! Returns driver and operating system specific data about the IVideoDriver. + const SExposedVideoData &getExposedVideoData() override; + + //! Returns type of video driver + E_DRIVER_TYPE getDriverType() const override; + + //! Returns the transformation set by setTransform + const core::matrix4 &getTransform(E_TRANSFORMATION_STATE state) const override; + + //! Returns pointer to the IGPUProgrammingServices interface. + IGPUProgrammingServices *getGPUProgrammingServices() override; + + //! Returns pointer to material renderer or null + IMaterialRenderer *getMaterialRenderer(u32 idx) const override; + + //! Returns amount of currently available material renderers. + u32 getMaterialRendererCount() const override; + + //! Returns name of the material renderer + const char *getMaterialRendererName(u32 idx) const override; + + //! Adds a new material renderer to the VideoDriver, based on a high level shading language. + virtual s32 addHighLevelShaderMaterial( + const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName = 0, + E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1, + const c8 *pixelShaderProgram = 0, + const c8 *pixelShaderEntryPointName = 0, + E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1, + const c8 *geometryShaderProgram = 0, + const c8 *geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, + s32 userData = 0) override; + + virtual s32 addHighLevelShaderMaterialFromFiles( + const io::path &vertexShaderProgramFile, + const c8 *vertexShaderEntryPointName = "main", + E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1, + const io::path &pixelShaderProgramFile = "", + const c8 *pixelShaderEntryPointName = "main", + E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1, + const io::path &geometryShaderProgramFileName = "", + const c8 *geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, + s32 userData = 0) override; + + virtual s32 addHighLevelShaderMaterialFromFiles( + io::IReadFile *vertexShaderProgram, + const c8 *vertexShaderEntryPointName = "main", + E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1, + io::IReadFile *pixelShaderProgram = 0, + const c8 *pixelShaderEntryPointName = "main", + E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1, + io::IReadFile *geometryShaderProgram = 0, + const c8 *geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, + s32 userData = 0) override; + + virtual void deleteShaderMaterial(s32 material) override; + + //! Returns a pointer to the mesh manipulator. + scene::IMeshManipulator *getMeshManipulator() override; + + void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) override; + + //! Returns an image created from the last rendered frame. + IImage *createScreenShot(video::ECOLOR_FORMAT format = video::ECF_UNKNOWN, video::E_RENDER_TARGET target = video::ERT_FRAME_BUFFER) override; + + //! Writes the provided image to disk file + bool writeImageToFile(IImage *image, const io::path &filename, u32 param = 0) override; + + //! Writes the provided image to a file. + bool writeImageToFile(IImage *image, io::IWriteFile *file, u32 param = 0) override; + + //! Sets the name of a material renderer. + void setMaterialRendererName(u32 idx, const char *name) override; + + //! Swap the material renderers used for certain id's + void swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames) override; + + //! looks if the image is already loaded + video::ITexture *findTexture(const io::path &filename) override; + + //! Set/unset a clipping plane. + //! There are at least 6 clipping planes available for the user to set at will. + //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes. + //! \param plane: The plane itself. + //! \param enable: If true, enable the clipping plane else disable it. + bool setClipPlane(u32 index, const core::plane3df &plane, bool enable = false) override; + + //! Enable/disable a clipping plane. + //! There are at least 6 clipping planes available for the user to set at will. + //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes. + //! \param enable: If true, enable the clipping plane else disable it. + void enableClipPlane(u32 index, bool enable) override; + + //! Returns the graphics card vendor name. + core::stringc getVendorInfo() override { return "Not available on this driver."; } + + //! Set the minimum number of vertices for which a hw buffer will be created + /** \param count Number of vertices to set as minimum. */ + void setMinHardwareBufferVertexCount(u32 count) override; + + //! Get the global Material, which might override local materials. + /** Depending on the enable flags, values from this Material + are used to override those of local materials of some + meshbuffer being rendered. */ + SOverrideMaterial &getOverrideMaterial() override; + + //! Get the 2d override material for altering its values + SMaterial &getMaterial2D() override; + + //! Enable the 2d override material + void enableMaterial2D(bool enable = true) override; + + //! Only used by the engine internally. + void setAllowZWriteOnTransparent(bool flag) override + { + AllowZWriteOnTransparent = flag; + } + + //! Returns the maximum texture size supported. + core::dimension2du getMaxTextureSize() const override; + + //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass + bool needsTransparentRenderPass(const irr::video::SMaterial &material) const override; + + //! Color conversion convenience function + /** Convert an image (as array of pixels) from source to destination + array, thereby converting the color format. The pixel size is + determined by the color formats. + \param sP Pointer to source + \param sF Color format of source + \param sN Number of pixels to convert, both array must be large enough + \param dP Pointer to destination + \param dF Color format of destination + */ + virtual void convertColor(const void *sP, ECOLOR_FORMAT sF, s32 sN, + void *dP, ECOLOR_FORMAT dF) const override; + + bool checkDriverReset() override { return false; } + +protected: + //! deletes all textures + void deleteAllTextures(); + + //! opens the file and loads it into the surface + ITexture *loadTextureFromFile(io::IReadFile *file, const io::path &hashName = ""); + + //! adds a surface, not loaded or created by the Irrlicht Engine + void addTexture(ITexture *surface); + + virtual ITexture *createDeviceDependentTexture(const io::path &name, IImage *image); + + virtual ITexture *createDeviceDependentTextureCubemap(const io::path &name, const core::array &image); + + //! checks triangle count and print warning if wrong + bool checkPrimitiveCount(u32 prmcnt) const; + + bool checkImage(IImage *image) const; + + bool checkImage(const core::array &image) const; + + // adds a material renderer and drops it afterwards. To be used for internal creation + s32 addAndDropMaterialRenderer(IMaterialRenderer *m); + + //! deletes all material renderers + void deleteMaterialRenders(); + + // prints renderer version + void printVersion(); + + inline bool getWriteZBuffer(const SMaterial &material) const + { + switch (material.ZWriteEnable) { + case video::EZW_OFF: + return false; + case video::EZW_AUTO: + return AllowZWriteOnTransparent || !needsTransparentRenderPass(material); + case video::EZW_ON: + return true; + } + return true; // never should get here, but some compilers don't know and complain + } + + struct SSurface + { + video::ITexture *Surface; + + bool operator<(const SSurface &other) const + { + return Surface->getName() < other.Surface->getName(); + } + }; + + struct SMaterialRenderer + { + core::stringc Name; + IMaterialRenderer *Renderer; + }; + + struct SDummyTexture : public ITexture + { + SDummyTexture(const io::path &name, E_TEXTURE_TYPE type) : + ITexture(name, type){}; + + void setSize(const core::dimension2d &size) { Size = OriginalSize = size; } + + void *lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel = 0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) override { return 0; } + void unlock() override {} + void regenerateMipMapLevels(void *data = 0, u32 layer = 0) override {} + }; + core::array Textures; + + struct SOccQuery + { + SOccQuery(scene::ISceneNode *node, const scene::IMesh *mesh = 0) : + Node(node), Mesh(mesh), PID(0), Result(0xffffffff), Run(0xffffffff) + { + if (Node) + Node->grab(); + if (Mesh) + Mesh->grab(); + } + + SOccQuery(const SOccQuery &other) : + Node(other.Node), Mesh(other.Mesh), PID(other.PID), Result(other.Result), Run(other.Run) + { + if (Node) + Node->grab(); + if (Mesh) + Mesh->grab(); + } + + ~SOccQuery() + { + if (Node) + Node->drop(); + if (Mesh) + Mesh->drop(); + } + + SOccQuery &operator=(const SOccQuery &other) + { + Node = other.Node; + Mesh = other.Mesh; + PID = other.PID; + Result = other.Result; + Run = other.Run; + if (Node) + Node->grab(); + if (Mesh) + Mesh->grab(); + return *this; + } + + bool operator==(const SOccQuery &other) const + { + return other.Node == Node; + } + + scene::ISceneNode *Node; + const scene::IMesh *Mesh; + union + { + void *PID; + unsigned int UID; + }; + u32 Result; + u32 Run; + }; + core::array OcclusionQueries; + + core::array RenderTargets; + + // Shared objects used with simplified IVideoDriver::setRenderTarget method with ITexture* param. + IRenderTarget *SharedRenderTarget; + core::array SharedDepthTextures; + + IRenderTarget *CurrentRenderTarget; + core::dimension2d CurrentRenderTargetSize; + + core::array SurfaceLoader; + core::array SurfaceWriter; + core::array MaterialRenderers; + + std::list HWBufferList; + + io::IFileSystem *FileSystem; + + //! mesh manipulator + scene::IMeshManipulator *MeshManipulator; + + core::rect ViewPort; + core::dimension2d ScreenSize; + core::matrix4 TransformationMatrix; + + CFPSCounter FPSCounter; + + u32 PrimitivesDrawn; + u32 MinVertexCountForVBO; + + u32 TextureCreationFlags; + + f32 FogStart; + f32 FogEnd; + f32 FogDensity; + SColor FogColor; + SExposedVideoData ExposedData; + + io::IAttributes *DriverAttributes; + + SOverrideMaterial OverrideMaterial; + SMaterial OverrideMaterial2D; + SMaterial InitMaterial2D; + bool OverrideMaterial2DEnabled; + + E_FOG_TYPE FogType; + bool PixelFog; + bool RangeFog; + bool AllowZWriteOnTransparent; + + bool FeatureEnabled[video::EVDF_COUNT]; + + SColorf AmbientLight; +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/COBJMeshFileLoader.cpp b/irr/src/COBJMeshFileLoader.cpp new file mode 100644 index 000000000..4c5a5328d --- /dev/null +++ b/irr/src/COBJMeshFileLoader.cpp @@ -0,0 +1,549 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "COBJMeshFileLoader.h" +#include "IMeshManipulator.h" +#include "IVideoDriver.h" +#include "SMesh.h" +#include "SMeshBuffer.h" +#include "SAnimatedMesh.h" +#include "IReadFile.h" +#include "IAttributes.h" +#include "fast_atof.h" +#include "coreutil.h" +#include "os.h" + +namespace irr +{ +namespace scene +{ + +#ifdef _DEBUG +#define _IRR_DEBUG_OBJ_LOADER_ +#endif + +//! Constructor +COBJMeshFileLoader::COBJMeshFileLoader(scene::ISceneManager *smgr) : + SceneManager(smgr) +{ +#ifdef _DEBUG + setDebugName("COBJMeshFileLoader"); +#endif +} + +//! destructor +COBJMeshFileLoader::~COBJMeshFileLoader() +{ +} + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".bsp") +bool COBJMeshFileLoader::isALoadableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "obj"); +} + +//! creates/loads an animated mesh from the file. +//! \return Pointer to the created mesh. Returns 0 if loading failed. +//! If you no longer need the mesh, you should call IAnimatedMesh::drop(). +//! See IReferenceCounted::drop() for more information. +IAnimatedMesh *COBJMeshFileLoader::createMesh(io::IReadFile *file) +{ + if (!file) + return 0; + + const long filesize = file->getSize(); + if (!filesize) + return 0; + + const u32 WORD_BUFFER_LENGTH = 512; + + core::array vertexBuffer(1000); + core::array normalsBuffer(1000); + core::array textureCoordBuffer(1000); + + SObjMtl *currMtl = new SObjMtl(); + Materials.push_back(currMtl); + u32 smoothingGroup = 0; + + const io::path fullName = file->getFileName(); + + c8 *buf = new c8[filesize + 1]; // plus null-terminator + memset(buf, 0, filesize + 1); + file->read((void *)buf, filesize); + const c8 *const bufEnd = buf + filesize; + + // Process obj information + const c8 *bufPtr = buf; + core::stringc grpName, mtlName; + bool mtlChanged = false; + bool useGroups = !SceneManager->getParameters()->getAttributeAsBool(OBJ_LOADER_IGNORE_GROUPS); + bool useMaterials = !SceneManager->getParameters()->getAttributeAsBool(OBJ_LOADER_IGNORE_MATERIAL_FILES); + [[maybe_unused]] irr::u32 lineNr = 1; // only counts non-empty lines, still useful in debugging to locate errors + core::array faceCorners; + faceCorners.reallocate(32); // should be large enough + const core::stringc TAG_OFF = "off"; + irr::u32 degeneratedFaces = 0; + + while (bufPtr != bufEnd) { + switch (bufPtr[0]) { + case 'm': // mtllib (material) + { + if (useMaterials) { + c8 name[WORD_BUFFER_LENGTH]; + bufPtr = goAndCopyNextWord(name, bufPtr, WORD_BUFFER_LENGTH, bufEnd); +#ifdef _IRR_DEBUG_OBJ_LOADER_ + os::Printer::log("Ignoring material file", name); +#endif + } + } break; + + case 'v': // v, vn, vt + switch (bufPtr[1]) { + case ' ': // vertex + { + core::vector3df vec; + bufPtr = readVec3(bufPtr, vec, bufEnd); + vertexBuffer.push_back(vec); + } break; + + case 'n': // normal + { + core::vector3df vec; + bufPtr = readVec3(bufPtr, vec, bufEnd); + normalsBuffer.push_back(vec); + } break; + + case 't': // texcoord + { + core::vector2df vec; + bufPtr = readUV(bufPtr, vec, bufEnd); + textureCoordBuffer.push_back(vec); + } break; + } + break; + + case 'g': // group name + { + c8 grp[WORD_BUFFER_LENGTH]; + bufPtr = goAndCopyNextWord(grp, bufPtr, WORD_BUFFER_LENGTH, bufEnd); +#ifdef _IRR_DEBUG_OBJ_LOADER_ + os::Printer::log("Loaded group start", grp, ELL_DEBUG); +#endif + if (useGroups) { + if (0 != grp[0]) + grpName = grp; + else + grpName = "default"; + } + mtlChanged = true; + } break; + + case 's': // smoothing can be a group or off (equiv. to 0) + { + c8 smooth[WORD_BUFFER_LENGTH]; + bufPtr = goAndCopyNextWord(smooth, bufPtr, WORD_BUFFER_LENGTH, bufEnd); +#ifdef _IRR_DEBUG_OBJ_LOADER_ + os::Printer::log("Loaded smoothing group start", smooth, ELL_DEBUG); +#endif + if (TAG_OFF == smooth) + smoothingGroup = 0; + else + smoothingGroup = core::strtoul10(smooth); + + (void)smoothingGroup; // disable unused variable warnings + } break; + + case 'u': // usemtl + // get name of material + { + c8 matName[WORD_BUFFER_LENGTH]; + bufPtr = goAndCopyNextWord(matName, bufPtr, WORD_BUFFER_LENGTH, bufEnd); +#ifdef _IRR_DEBUG_OBJ_LOADER_ + os::Printer::log("Loaded material start", matName, ELL_DEBUG); +#endif + mtlName = matName; + mtlChanged = true; + } + break; + + case 'f': // face + { + c8 vertexWord[WORD_BUFFER_LENGTH]; // for retrieving vertex data + video::S3DVertex v; + // Assign vertex color from currently active material's diffuse color + if (mtlChanged) { + // retrieve the material + SObjMtl *useMtl = findMtl(mtlName, grpName); + // only change material if we found it + if (useMtl) + currMtl = useMtl; + mtlChanged = false; + } + if (currMtl) + v.Color = currMtl->Meshbuffer->Material.DiffuseColor; + + // get all vertices data in this face (current line of obj file) + const core::stringc wordBuffer = copyLine(bufPtr, bufEnd); + const c8 *linePtr = wordBuffer.c_str(); + const c8 *const endPtr = linePtr + wordBuffer.size(); + + faceCorners.set_used(0); // fast clear + + // read in all vertices + linePtr = goNextWord(linePtr, endPtr); + while (0 != linePtr[0]) { + // Array to communicate with retrieveVertexIndices() + // sends the buffer sizes and gets the actual indices + // if index not set returns -1 + s32 Idx[3]; + Idx[0] = Idx[1] = Idx[2] = -1; + + // read in next vertex's data + u32 wlength = copyWord(vertexWord, linePtr, WORD_BUFFER_LENGTH, endPtr); + // this function will also convert obj's 1-based index to c++'s 0-based index + retrieveVertexIndices(vertexWord, Idx, vertexWord + wlength + 1, vertexBuffer.size(), textureCoordBuffer.size(), normalsBuffer.size()); + if (Idx[0] >= 0 && Idx[0] < (irr::s32)vertexBuffer.size()) + v.Pos = vertexBuffer[Idx[0]]; + else { + os::Printer::log("Invalid vertex index in this line", wordBuffer.c_str(), ELL_ERROR); + delete[] buf; + cleanUp(); + return 0; + } + if (Idx[1] >= 0 && Idx[1] < (irr::s32)textureCoordBuffer.size()) + v.TCoords = textureCoordBuffer[Idx[1]]; + else + v.TCoords.set(0.0f, 0.0f); + if (Idx[2] >= 0 && Idx[2] < (irr::s32)normalsBuffer.size()) + v.Normal = normalsBuffer[Idx[2]]; + else { + v.Normal.set(0.0f, 0.0f, 0.0f); + currMtl->RecalculateNormals = true; + } + + int vertLocation; + auto n = currMtl->VertMap.find(v); + if (n != currMtl->VertMap.end()) { + vertLocation = n->second; + } else { + currMtl->Meshbuffer->Vertices.push_back(v); + vertLocation = currMtl->Meshbuffer->Vertices.size() - 1; + currMtl->VertMap.emplace(v, vertLocation); + } + + faceCorners.push_back(vertLocation); + + // go to next vertex + linePtr = goNextWord(linePtr, endPtr); + } + + if (faceCorners.size() < 3) { + os::Printer::log("Too few vertices in this line", wordBuffer.c_str(), ELL_ERROR); + delete[] buf; + cleanUp(); + return 0; + } + + // triangulate the face + const int c = faceCorners[0]; + for (u32 i = 1; i < faceCorners.size() - 1; ++i) { + // Add a triangle + const int a = faceCorners[i + 1]; + const int b = faceCorners[i]; + if (a != b && a != c && b != c) { // ignore degenerated faces. We can get them when we merge vertices above in the VertMap. + currMtl->Meshbuffer->Indices.push_back(a); + currMtl->Meshbuffer->Indices.push_back(b); + currMtl->Meshbuffer->Indices.push_back(c); + } else { + ++degeneratedFaces; + } + } + } break; + + case '#': // comment + default: + break; + } // end switch(bufPtr[0]) + // eat up rest of line + bufPtr = goNextLine(bufPtr, bufEnd); + ++lineNr; + } // end while(bufPtr && (bufPtr-buf 0) { + irr::core::stringc log(degeneratedFaces); + log += " degenerated faces removed in "; + log += irr::core::stringc(fullName); + os::Printer::log(log.c_str(), ELL_INFORMATION); + } + + SMesh *mesh = new SMesh(); + + // Combine all the groups (meshbuffers) into the mesh + for (u32 m = 0; m < Materials.size(); ++m) { + if (Materials[m]->Meshbuffer->getIndexCount() > 0) { + Materials[m]->Meshbuffer->recalculateBoundingBox(); + if (Materials[m]->RecalculateNormals) + SceneManager->getMeshManipulator()->recalculateNormals(Materials[m]->Meshbuffer); + mesh->addMeshBuffer(Materials[m]->Meshbuffer); + } + } + + // Create the Animated mesh if there's anything in the mesh + SAnimatedMesh *animMesh = 0; + if (0 != mesh->getMeshBufferCount()) { + mesh->recalculateBoundingBox(); + animMesh = new SAnimatedMesh(); + animMesh->Type = EAMT_OBJ; + animMesh->addMesh(mesh); + animMesh->recalculateBoundingBox(); + } + + // Clean up the allocate obj file contents + delete[] buf; + // more cleaning up + cleanUp(); + mesh->drop(); + + return animMesh; +} + +//! Read RGB color +const c8 *COBJMeshFileLoader::readColor(const c8 *bufPtr, video::SColor &color, const c8 *const bufEnd) +{ + const u32 COLOR_BUFFER_LENGTH = 16; + c8 colStr[COLOR_BUFFER_LENGTH]; + + bufPtr = goAndCopyNextWord(colStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd); + color.setRed((u32)core::round32(core::fast_atof(colStr) * 255.f)); + bufPtr = goAndCopyNextWord(colStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd); + color.setGreen((u32)core::round32(core::fast_atof(colStr) * 255.f)); + bufPtr = goAndCopyNextWord(colStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd); + color.setBlue((u32)core::round32(core::fast_atof(colStr) * 255.f)); + return bufPtr; +} + +//! Read 3d vector of floats +const c8 *COBJMeshFileLoader::readVec3(const c8 *bufPtr, core::vector3df &vec, const c8 *const bufEnd) +{ + const u32 WORD_BUFFER_LENGTH = 256; + c8 wordBuffer[WORD_BUFFER_LENGTH]; + + bufPtr = goAndCopyNextWord(wordBuffer, bufPtr, WORD_BUFFER_LENGTH, bufEnd); + vec.X = -core::fast_atof(wordBuffer); // change handedness + bufPtr = goAndCopyNextWord(wordBuffer, bufPtr, WORD_BUFFER_LENGTH, bufEnd); + vec.Y = core::fast_atof(wordBuffer); + bufPtr = goAndCopyNextWord(wordBuffer, bufPtr, WORD_BUFFER_LENGTH, bufEnd); + vec.Z = core::fast_atof(wordBuffer); + return bufPtr; +} + +//! Read 2d vector of floats +const c8 *COBJMeshFileLoader::readUV(const c8 *bufPtr, core::vector2df &vec, const c8 *const bufEnd) +{ + const u32 WORD_BUFFER_LENGTH = 256; + c8 wordBuffer[WORD_BUFFER_LENGTH]; + + bufPtr = goAndCopyNextWord(wordBuffer, bufPtr, WORD_BUFFER_LENGTH, bufEnd); + vec.X = core::fast_atof(wordBuffer); + bufPtr = goAndCopyNextWord(wordBuffer, bufPtr, WORD_BUFFER_LENGTH, bufEnd); + vec.Y = 1 - core::fast_atof(wordBuffer); // change handedness + return bufPtr; +} + +//! Read boolean value represented as 'on' or 'off' +const c8 *COBJMeshFileLoader::readBool(const c8 *bufPtr, bool &tf, const c8 *const bufEnd) +{ + const u32 BUFFER_LENGTH = 8; + c8 tfStr[BUFFER_LENGTH]; + + bufPtr = goAndCopyNextWord(tfStr, bufPtr, BUFFER_LENGTH, bufEnd); + tf = strcmp(tfStr, "off") != 0; + return bufPtr; +} + +COBJMeshFileLoader::SObjMtl *COBJMeshFileLoader::findMtl(const core::stringc &mtlName, const core::stringc &grpName) +{ + COBJMeshFileLoader::SObjMtl *defMaterial = 0; + // search existing Materials for best match + // exact match does return immediately, only name match means a new group + for (u32 i = 0; i < Materials.size(); ++i) { + if (Materials[i]->Name == mtlName) { + if (Materials[i]->Group == grpName) + return Materials[i]; + else + defMaterial = Materials[i]; + } + } + // we found a partial match + if (defMaterial) { + Materials.push_back(new SObjMtl(*defMaterial)); + Materials.getLast()->Group = grpName; + return Materials.getLast(); + } + // we found a new group for a non-existent material + else if (grpName.size()) { + Materials.push_back(new SObjMtl(*Materials[0])); + Materials.getLast()->Group = grpName; + return Materials.getLast(); + } + return 0; +} + +//! skip space characters and stop on first non-space +const c8 *COBJMeshFileLoader::goFirstWord(const c8 *buf, const c8 *const bufEnd, bool acrossNewlines) +{ + // skip space characters + if (acrossNewlines) + while ((buf != bufEnd) && core::isspace(*buf)) + ++buf; + else + while ((buf != bufEnd) && core::isspace(*buf) && (*buf != '\n')) + ++buf; + + return buf; +} + +//! skip current word and stop at beginning of next one +const c8 *COBJMeshFileLoader::goNextWord(const c8 *buf, const c8 *const bufEnd, bool acrossNewlines) +{ + // skip current word + while ((buf != bufEnd) && !core::isspace(*buf)) + ++buf; + + return goFirstWord(buf, bufEnd, acrossNewlines); +} + +//! Read until line break is reached and stop at the next non-space character +const c8 *COBJMeshFileLoader::goNextLine(const c8 *buf, const c8 *const bufEnd) +{ + // look for newline characters + while (buf != bufEnd) { + // found it, so leave + if (*buf == '\n' || *buf == '\r') + break; + ++buf; + } + return goFirstWord(buf, bufEnd); +} + +u32 COBJMeshFileLoader::copyWord(c8 *outBuf, const c8 *const inBuf, u32 outBufLength, const c8 *const bufEnd) +{ + if (!outBufLength) + return 0; + if (!inBuf) { + *outBuf = 0; + return 0; + } + + u32 i = 0; + while (inBuf[i]) { + if (core::isspace(inBuf[i]) || &(inBuf[i]) == bufEnd) + break; + ++i; + } + + u32 length = core::min_(i, outBufLength - 1); + for (u32 j = 0; j < length; ++j) + outBuf[j] = inBuf[j]; + + outBuf[length] = 0; + return length; +} + +core::stringc COBJMeshFileLoader::copyLine(const c8 *inBuf, const c8 *bufEnd) +{ + if (!inBuf) + return core::stringc(); + + const c8 *ptr = inBuf; + while (ptr < bufEnd) { + if (*ptr == '\n' || *ptr == '\r') + break; + ++ptr; + } + // we must avoid the +1 in case the array is used up + return core::stringc(inBuf, (u32)(ptr - inBuf + ((ptr < bufEnd) ? 1 : 0))); +} + +const c8 *COBJMeshFileLoader::goAndCopyNextWord(c8 *outBuf, const c8 *inBuf, u32 outBufLength, const c8 *bufEnd) +{ + inBuf = goNextWord(inBuf, bufEnd, false); + copyWord(outBuf, inBuf, outBufLength, bufEnd); + return inBuf; +} + +bool COBJMeshFileLoader::retrieveVertexIndices(c8 *vertexData, s32 *idx, const c8 *bufEnd, u32 vbsize, u32 vtsize, u32 vnsize) +{ + const u32 BUFFER_LENGTH = 16; + c8 word[BUFFER_LENGTH]; + const c8 *p = goFirstWord(vertexData, bufEnd); + u32 idxType = 0; // 0 = posIdx, 1 = texcoordIdx, 2 = normalIdx + + u32 i = 0; + while (p != bufEnd) { + if (i >= BUFFER_LENGTH) { + return false; + } + if ((core::isdigit(*p)) || (*p == '-')) { + // build up the number + word[i++] = *p; + } else if (*p == '/' || *p == ' ' || *p == '\0') { + // number is completed. Convert and store it + word[i] = '\0'; + // if no number was found index will become 0 and later on -1 by decrement + idx[idxType] = core::strtol10(word); + if (idx[idxType] < 0) { + switch (idxType) { + case 0: + idx[idxType] += vbsize; + break; + case 1: + idx[idxType] += vtsize; + break; + case 2: + idx[idxType] += vnsize; + break; + } + } else + idx[idxType] -= 1; + + // reset the word + word[0] = '\0'; + i = 0; + + // go to the next kind of index type + if (*p == '/') { + if (++idxType > 2) { + // error checking, shouldn't reach here unless file is wrong + idxType = 0; + } + } else { + // set all missing values to disable (=-1) + while (++idxType < 3) + idx[idxType] = -1; + ++p; + break; // while + } + } + + // go to the next char + ++p; + } + + return true; +} + +void COBJMeshFileLoader::cleanUp() +{ + for (u32 i = 0; i < Materials.size(); ++i) { + Materials[i]->Meshbuffer->drop(); + delete Materials[i]; + } + + Materials.clear(); +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/COBJMeshFileLoader.h b/irr/src/COBJMeshFileLoader.h new file mode 100644 index 000000000..63e768e4f --- /dev/null +++ b/irr/src/COBJMeshFileLoader.h @@ -0,0 +1,109 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include +#include "IMeshLoader.h" +#include "ISceneManager.h" +#include "irrString.h" +#include "SMeshBuffer.h" + +namespace irr +{ +namespace scene +{ + +//! Meshloader capable of loading obj meshes. +class COBJMeshFileLoader : public IMeshLoader +{ +public: + //! Constructor + COBJMeshFileLoader(scene::ISceneManager *smgr); + + //! destructor + virtual ~COBJMeshFileLoader(); + + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".obj") + bool isALoadableFileExtension(const io::path &filename) const override; + + //! creates/loads an animated mesh from the file. + //! \return Pointer to the created mesh. Returns 0 if loading failed. + //! If you no longer need the mesh, you should call IAnimatedMesh::drop(). + //! See IReferenceCounted::drop() for more information. + IAnimatedMesh *createMesh(io::IReadFile *file) override; + +private: + struct SObjMtl + { + SObjMtl() : + Meshbuffer(0), Bumpiness(1.0f), Illumination(0), + RecalculateNormals(false) + { + Meshbuffer = new SMeshBuffer(); + Meshbuffer->Material.Shininess = 0.0f; + Meshbuffer->Material.AmbientColor = video::SColorf(0.2f, 0.2f, 0.2f, 1.0f).toSColor(); + Meshbuffer->Material.DiffuseColor = video::SColorf(0.8f, 0.8f, 0.8f, 1.0f).toSColor(); + Meshbuffer->Material.SpecularColor = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f).toSColor(); + } + + SObjMtl(const SObjMtl &o) : + Name(o.Name), Group(o.Group), + Bumpiness(o.Bumpiness), Illumination(o.Illumination), + RecalculateNormals(false) + { + Meshbuffer = new SMeshBuffer(); + Meshbuffer->Material = o.Meshbuffer->Material; + } + + std::map VertMap; + scene::SMeshBuffer *Meshbuffer; + core::stringc Name; + core::stringc Group; + f32 Bumpiness; + c8 Illumination; + bool RecalculateNormals; + }; + + // returns a pointer to the first printable character available in the buffer + const c8 *goFirstWord(const c8 *buf, const c8 *const bufEnd, bool acrossNewlines = true); + // returns a pointer to the first printable character after the first non-printable + const c8 *goNextWord(const c8 *buf, const c8 *const bufEnd, bool acrossNewlines = true); + // returns a pointer to the next printable character after the first line break + const c8 *goNextLine(const c8 *buf, const c8 *const bufEnd); + // copies the current word from the inBuf to the outBuf + u32 copyWord(c8 *outBuf, const c8 *inBuf, u32 outBufLength, const c8 *const pBufEnd); + // copies the current line from the inBuf to the outBuf + core::stringc copyLine(const c8 *inBuf, const c8 *const bufEnd); + + // combination of goNextWord followed by copyWord + const c8 *goAndCopyNextWord(c8 *outBuf, const c8 *inBuf, u32 outBufLength, const c8 *const pBufEnd); + + //! Find and return the material with the given name + SObjMtl *findMtl(const core::stringc &mtlName, const core::stringc &grpName); + + //! Read RGB color + const c8 *readColor(const c8 *bufPtr, video::SColor &color, const c8 *const pBufEnd); + //! Read 3d vector of floats + const c8 *readVec3(const c8 *bufPtr, core::vector3df &vec, const c8 *const pBufEnd); + //! Read 2d vector of floats + const c8 *readUV(const c8 *bufPtr, core::vector2df &vec, const c8 *const pBufEnd); + //! Read boolean value represented as 'on' or 'off' + const c8 *readBool(const c8 *bufPtr, bool &tf, const c8 *const bufEnd); + + // reads and convert to integer the vertex indices in a line of obj file's face statement + // -1 for the index if it doesn't exist + // indices are changed to 0-based index instead of 1-based from the obj file + bool retrieveVertexIndices(c8 *vertexData, s32 *idx, const c8 *bufEnd, u32 vbsize, u32 vtsize, u32 vnsize); + + void cleanUp(); + + scene::ISceneManager *SceneManager; + + core::array Materials; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/COGLESCommon.h b/irr/src/COGLESCommon.h new file mode 100644 index 000000000..24c96d14a --- /dev/null +++ b/irr/src/COGLESCommon.h @@ -0,0 +1,119 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OGLES1_ + +#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_) +#include +#include +#elif defined(_IRR_OGLES1_USE_KHRONOS_API_HEADERS_) +#include +#include +typedef char GLchar; +#else // or only when defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) ? +#include +#include +#include +#endif + +#ifndef GL_BGRA +#define GL_BGRA 0x80E1; +#endif + +// Blending definitions. + +#if defined(GL_OES_blend_subtract) +#define GL_FUNC_ADD GL_FUNC_ADD_OES +#else +#define GL_FUNC_ADD 0 +#endif + +// FBO definitions. + +#ifdef GL_OES_framebuffer_object +#define GL_NONE 0 // iOS has missing definition of GL_NONE_OES +#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES +#define GL_DEPTH_COMPONENT16 GL_DEPTH_COMPONENT16_OES +#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES +#define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES +#define GL_STENCIL_ATTACHMENT GL_STENCIL_ATTACHMENT_OES +#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 1 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 2 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES +#define GL_FRAMEBUFFER_UNSUPPORTED GL_FRAMEBUFFER_UNSUPPORTED_OES +#else +#define GL_NONE 0 +#define GL_FRAMEBUFFER 0 +#define GL_DEPTH_COMPONENT16 0 +#define GL_COLOR_ATTACHMENT0 0 +#define GL_DEPTH_ATTACHMENT 0 +#define GL_STENCIL_ATTACHMENT 0 +#define GL_FRAMEBUFFER_COMPLETE 0 +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 1 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 2 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 3 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS 4 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 5 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 6 +#define GL_FRAMEBUFFER_UNSUPPORTED 7 +#endif + +#define GL_DEPTH_COMPONENT 0x1902 + +// Texture definitions. + +#ifdef GL_OES_texture_cube_map +#define GL_TEXTURE_CUBE_MAP GL_TEXTURE_CUBE_MAP_OES +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES +#else +#define GL_TEXTURE_CUBE_MAP 0 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0 +#endif + +// to check if this header is in the current compile unit (different GL implementation used different "GLCommon" headers in Irrlicht +#define IRR_COMPILE_GLES_COMMON + +namespace irr +{ +namespace video +{ + +// Forward declarations. + +class COpenGLCoreFeature; + +template +class COpenGLCoreTexture; + +template +class COpenGLCoreRenderTarget; + +template +class COpenGLCoreCacheHandler; + +class COGLES1Driver; +typedef COpenGLCoreTexture COGLES1Texture; +typedef COpenGLCoreRenderTarget COGLES1RenderTarget; +typedef COpenGLCoreCacheHandler COGLES1CacheHandler; + +} +} + +#endif diff --git a/irr/src/COGLESCoreExtensionHandler.h b/irr/src/COGLESCoreExtensionHandler.h new file mode 100644 index 000000000..4c691aaf9 --- /dev/null +++ b/irr/src/COGLESCoreExtensionHandler.h @@ -0,0 +1,189 @@ +// Copyright (C) 2017 Michael Zeilfelder +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +// Can be included from different ES versions +// (this is also the reason why this file is header-only as correct OGL ES headers have to be included first) + +#include "irrMath.h" +#include "COpenGLCoreFeature.h" + +namespace irr +{ +namespace video +{ + +class COGLESCoreExtensionHandler +{ +public: + // Enums used internally to check for ES extensions quickly. + // We buffer all extensions on start once in an array. + // All OpenGL ES versions share the same extensions (WebGL adds it's own extensions on top of ES2) + enum EOGLESFeatures + { + // If you update this enum also update the corresponding OGLESFeatureStrings string-array + IRR_GL_APPLE_texture_2D_limited_npot, + IRR_GL_APPLE_texture_format_BGRA8888, + IRR_GL_EXT_blend_minmax, + IRR_GL_EXT_read_format_bgra, + IRR_GL_EXT_texture_filter_anisotropic, + IRR_GL_EXT_texture_format_BGRA8888, + IRR_GL_EXT_texture_lod_bias, + IRR_GL_EXT_texture_rg, + IRR_GL_IMG_read_format, + IRR_GL_IMG_texture_format_BGRA8888, + IRR_GL_IMG_user_clip_plane, + IRR_GL_OES_blend_func_separate, + IRR_GL_OES_blend_subtract, + IRR_GL_OES_depth_texture, + IRR_GL_OES_depth24, + IRR_GL_OES_depth32, + IRR_GL_OES_element_index_uint, + IRR_GL_OES_framebuffer_object, + IRR_GL_OES_packed_depth_stencil, + IRR_GL_OES_point_size_array, + IRR_GL_OES_point_sprite, + IRR_GL_OES_read_format, + IRR_GL_OES_stencil_wrap, + IRR_GL_OES_texture_float, + IRR_GL_OES_texture_half_float, + IRR_GL_OES_texture_mirrored_repeat, + IRR_GL_OES_texture_npot, + + IRR_OGLES_Feature_Count + }; + + COGLESCoreExtensionHandler() : + Version(0), MaxAnisotropy(1), MaxIndices(0xffff), + MaxTextureSize(1), MaxTextureLODBias(0.f), StencilBuffer(false) + { + for (u32 i = 0; i < IRR_OGLES_Feature_Count; ++i) + FeatureAvailable[i] = false; + + DimAliasedLine[0] = 1.f; + DimAliasedLine[1] = 1.f; + DimAliasedPoint[0] = 1.f; + DimAliasedPoint[1] = 1.f; + } + + virtual ~COGLESCoreExtensionHandler() {} + + const COpenGLCoreFeature &getFeature() const + { + return Feature; + } + + void dump() const + { + for (u32 i = 0; i < IRR_OGLES_Feature_Count; ++i) + os::Printer::log(getFeatureString(i), FeatureAvailable[i] ? " true" : " false"); + } + + bool queryGLESFeature(EOGLESFeatures feature) const + { + return FeatureAvailable[feature]; + } + +protected: + const char *getFeatureString(size_t index) const + { + // One for each EOGLESFeatures + static const char *const OGLESFeatureStrings[IRR_OGLES_Feature_Count] = { + "GL_APPLE_texture_2D_limited_npot", + "GL_APPLE_texture_format_BGRA8888", + "GL_EXT_blend_minmax", + "GL_EXT_read_format_bgra", + "GL_EXT_texture_filter_anisotropic", + "GL_EXT_texture_format_BGRA8888", + "GL_EXT_texture_lod_bias", + "GL_EXT_texture_rg", + "GL_IMG_read_format", + "GL_IMG_texture_format_BGRA8888", + "GL_IMG_user_clip_plane", + "GL_OES_blend_func_separate", + "GL_OES_blend_subtract", + "GL_OES_depth_texture", + "GL_OES_depth24", + "GL_OES_depth32", + "GL_OES_element_index_uint", + "GL_OES_framebuffer_object", + "GL_OES_packed_depth_stencil", + "GL_OES_point_size_array", + "GL_OES_point_sprite", + "GL_OES_read_format", + "GL_OES_stencil_wrap", + "GL_OES_texture_float", + "GL_OES_texture_half_float", + "GL_OES_texture_mirrored_repeat", + "GL_OES_texture_npot", + }; + + return OGLESFeatureStrings[index]; + } + + void getGLVersion() + { + Version = 0; + s32 multiplier = 100; + + core::stringc version(glGetString(GL_VERSION)); + + for (u32 i = 0; i < version.size(); ++i) { + if (version[i] >= '0' && version[i] <= '9') { + if (multiplier > 1) { + Version += static_cast(core::floor32(atof(&(version[i]))) * multiplier); + multiplier /= 10; + } else { + break; + } + } + } + } + + void getGLExtensions() + { + core::stringc extensions = glGetString(GL_EXTENSIONS); + os::Printer::log(extensions.c_str()); + + const u32 size = extensions.size() + 1; + c8 *str = new c8[size]; + strncpy(str, extensions.c_str(), extensions.size()); + str[extensions.size()] = ' '; + c8 *p = str; + + for (u32 i = 0; i < size; ++i) { + if (str[i] == ' ') { + str[i] = 0; + if (*p) + for (size_t j = 0; j < IRR_OGLES_Feature_Count; ++j) { + if (!strcmp(getFeatureString(j), p)) { + FeatureAvailable[j] = true; + break; + } + } + + p = p + strlen(p) + 1; + } + } + + delete[] str; + } + + COpenGLCoreFeature Feature; + + u16 Version; + u8 MaxAnisotropy; + u32 MaxIndices; + u32 MaxTextureSize; + f32 MaxTextureLODBias; + //! Minimal and maximal supported thickness for lines without smoothing + float DimAliasedLine[2]; + //! Minimal and maximal supported thickness for points without smoothing + float DimAliasedPoint[2]; + bool StencilBuffer; + bool FeatureAvailable[IRR_OGLES_Feature_Count]; +}; +} +} diff --git a/irr/src/COGLESDriver.cpp b/irr/src/COGLESDriver.cpp new file mode 100644 index 000000000..2cd8430f2 --- /dev/null +++ b/irr/src/COGLESDriver.cpp @@ -0,0 +1,2403 @@ +// Copyright (C) 2002-2008 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "COGLESDriver.h" +#include +#include "CNullDriver.h" +#include "IContextManager.h" + +#ifdef _IRR_COMPILE_WITH_OGLES1_ + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreRenderTarget.h" +#include "COpenGLCoreCacheHandler.h" + +#include "COGLESMaterialRenderer.h" + +#include "EVertexAttributes.h" +#include "CImage.h" +#include "os.h" + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ +#include "android_native_app_glue.h" +#endif + +namespace irr +{ +namespace video +{ + +COGLES1Driver::COGLES1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) : + CNullDriver(io, params.WindowSize), COGLES1ExtensionHandler(), CacheHandler(0), CurrentRenderMode(ERM_NONE), + ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(params.AntiAlias), + ColorFormat(ECF_R8G8B8), Params(params), ContextManager(contextManager) +{ +#ifdef _DEBUG + setDebugName("COGLESDriver"); +#endif + + core::dimension2d windowSize(0, 0); + + if (!ContextManager) + return; + + ContextManager->grab(); + ContextManager->generateSurface(); + ContextManager->generateContext(); + ExposedData = ContextManager->getContext(); + ContextManager->activateContext(ExposedData, false); + + windowSize = params.WindowSize; + + genericDriverInit(windowSize, params.Stencilbuffer); +} + +COGLES1Driver::~COGLES1Driver() +{ + deleteMaterialRenders(); + + CacheHandler->getTextureCache().clear(); + + removeAllRenderTargets(); + deleteAllTextures(); + removeAllOcclusionQueries(); + removeAllHardwareBuffers(); + + delete CacheHandler; + + if (ContextManager) { + ContextManager->destroyContext(); + ContextManager->destroySurface(); + ContextManager->terminate(); + ContextManager->drop(); + } +} + +// ----------------------------------------------------------------------- +// METHODS +// ----------------------------------------------------------------------- + +bool COGLES1Driver::genericDriverInit(const core::dimension2d &screenSize, bool stencilBuffer) +{ + Name = glGetString(GL_VERSION); + printVersion(); + + // print renderer information + VendorName = glGetString(GL_VENDOR); + os::Printer::log(VendorName.c_str(), ELL_INFORMATION); + + // load extensions + initExtensions(); + + // reset cache handler + delete CacheHandler; + CacheHandler = new COGLES1CacheHandler(this); + + StencilBuffer = stencilBuffer; + + DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits); + DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits); + DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy); + DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices); + DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize); + DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias); + DriverAttributes->setAttribute("Version", Version); + DriverAttributes->setAttribute("AntiAlias", AntiAlias); + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + UserClipPlane.reallocate(MaxUserClipPlanes); + UserClipPlaneEnabled.resize(MaxUserClipPlanes); + + for (s32 i = 0; i < MaxUserClipPlanes; ++i) { + UserClipPlane.push_back(core::plane3df()); + UserClipPlaneEnabled[i] = false; + } + + for (s32 i = 0; i < ETS_COUNT; ++i) + setTransform(static_cast(i), core::IdentityMatrix); + + setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); + glClearDepthf(1.0f); + + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); + glDepthFunc(GL_LEQUAL); + glFrontFace(GL_CW); + glAlphaFunc(GL_GREATER, 0.f); + + // create material renderers + createMaterialRenderers(); + + // set the renderstates + setRenderStates3DMode(); + + // set fog mode + setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog); + + // create matrix for flipping textures + TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f)); + + // We need to reset once more at the beginning of the first rendering. + // This fixes problems with intermediate changes to the material during texture load. + ResetRenderStates = true; + + testGLError(__LINE__); + + return true; +} + +void COGLES1Driver::createMaterialRenderers() +{ + addAndDropMaterialRenderer(new COGLES1MaterialRenderer_SOLID(this)); + addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(this)); + addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(this)); + addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(this)); + addAndDropMaterialRenderer(new COGLES1MaterialRenderer_ONETEXTURE_BLEND(this)); +} + +bool COGLES1Driver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData &videoData, core::rect *sourceRect) +{ + CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect); + + if (ContextManager) + ContextManager->activateContext(videoData, true); + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; +} + +bool COGLES1Driver::endScene() +{ + CNullDriver::endScene(); + + glFlush(); + + if (ContextManager) + return ContextManager->swapBuffers(); + + return false; +} + +//! Returns the transformation set by setTransform +const core::matrix4 &COGLES1Driver::getTransform(E_TRANSFORMATION_STATE state) const +{ + return Matrices[state]; +} + +//! sets transformation +void COGLES1Driver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) +{ + Matrices[state] = mat; + Transformation3DChanged = true; + + switch (state) { + case ETS_VIEW: + case ETS_WORLD: { + // OGLES1 only has a model matrix, view and world is not existent. so lets fake these two. + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer()); + // we have to update the clip planes to the latest view matrix + for (u32 i = 0; i < MaxUserClipPlanes; ++i) + if (UserClipPlaneEnabled[i]) + uploadClipPlane(i); + } break; + case ETS_PROJECTION: { + GLfloat glmat[16]; + getGLMatrix(glmat, mat); + // flip z to compensate OGLES1s right-hand coordinate system + glmat[12] *= -1.0f; + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(glmat); + } break; + default: + break; + } +} + +bool COGLES1Driver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) +{ + if (!HWBuffer) + return false; + + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + const void *vertices = mb->getVertices(); + const u32 vertexCount = mb->getVertexCount(); + const E_VERTEX_TYPE vType = mb->getVertexType(); + const u32 vertexSize = getVertexPitchFromType(vType); + + // buffer vertex data, and convert colours... + core::array buffer(vertexSize * vertexCount); + buffer.set_used(vertexSize * vertexCount); + memcpy(buffer.pointer(), vertices, vertexSize * vertexCount); + + // in order to convert the colors into opengl format (RGBA) + switch (vType) { + case EVT_STANDARD: { + S3DVertex *pb = reinterpret_cast(buffer.pointer()); + const S3DVertex *po = static_cast(vertices); + for (u32 i = 0; i < vertexCount; i++) { + po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color.color)); + } + } break; + case EVT_2TCOORDS: { + S3DVertex2TCoords *pb = reinterpret_cast(buffer.pointer()); + const S3DVertex2TCoords *po = static_cast(vertices); + for (u32 i = 0; i < vertexCount; i++) { + po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color.color)); + } + } break; + case EVT_TANGENTS: { + S3DVertexTangents *pb = reinterpret_cast(buffer.pointer()); + const S3DVertexTangents *po = static_cast(vertices); + for (u32 i = 0; i < vertexCount; i++) { + po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color.color)); + } + } break; + default: { + return false; + } + } + + // get or create buffer + bool newBuffer = false; + if (!HWBuffer->vbo_verticesID) { + glGenBuffers(1, &HWBuffer->vbo_verticesID); + if (!HWBuffer->vbo_verticesID) + return false; + newBuffer = true; + } else if (HWBuffer->vbo_verticesSize < vertexCount * vertexSize) { + newBuffer = true; + } + + glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + + // copy data to graphics card + if (!newBuffer) + glBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, buffer.const_pointer()); + else { + HWBuffer->vbo_verticesSize = vertexCount * vertexSize; + + if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC) + glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_STATIC_DRAW); + else + glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_DYNAMIC_DRAW); + } + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); +} + +bool COGLES1Driver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) +{ + if (!HWBuffer) + return false; + + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + + const void *indices = mb->getIndices(); + u32 indexCount = mb->getIndexCount(); + + GLenum indexSize; + switch (mb->getIndexType()) { + case (EIT_16BIT): { + indexSize = sizeof(u16); + break; + } + case (EIT_32BIT): { + indexSize = sizeof(u32); + break; + } + default: { + return false; + } + } + + // get or create buffer + bool newBuffer = false; + if (!HWBuffer->vbo_indicesID) { + glGenBuffers(1, &HWBuffer->vbo_indicesID); + if (!HWBuffer->vbo_indicesID) + return false; + newBuffer = true; + } else if (HWBuffer->vbo_indicesSize < indexCount * indexSize) { + newBuffer = true; + } + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + + // copy data to graphics card + if (!newBuffer) + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices); + else { + HWBuffer->vbo_indicesSize = indexCount * indexSize; + + if (HWBuffer->Mapped_Index == scene::EHM_STATIC) + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW); + else + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_DYNAMIC_DRAW); + } + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); +} + +//! updates hardware buffer if needed +bool COGLES1Driver::updateHardwareBuffer(SHWBufferLink *HWBuffer) +{ + if (!HWBuffer) + return false; + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { + if (HWBuffer->ChangedID_Vertex != HWBuffer->MeshBuffer->getChangedID_Vertex() || !static_cast(HWBuffer)->vbo_verticesID) { + + HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); + + if (!updateVertexHardwareBuffer(static_cast(HWBuffer))) + return false; + } + } + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { + if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index() || !((SHWBufferLink_opengl *)HWBuffer)->vbo_indicesID) { + + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + + if (!updateIndexHardwareBuffer(static_cast(HWBuffer))) + return false; + } + } + + return true; +} + +//! Create hardware buffer from meshbuffer +COGLES1Driver::SHWBufferLink *COGLES1Driver::createHardwareBuffer(const scene::IMeshBuffer *mb) +{ + if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER)) + return 0; + + SHWBufferLink_opengl *HWBuffer = new SHWBufferLink_opengl(mb); + + // add to map + HWBuffer->listPosition = HWBufferList.insert(HWBufferList.end(), HWBuffer); + + HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + HWBuffer->Mapped_Vertex = mb->getHardwareMappingHint_Vertex(); + HWBuffer->Mapped_Index = mb->getHardwareMappingHint_Index(); + HWBuffer->vbo_verticesID = 0; + HWBuffer->vbo_indicesID = 0; + HWBuffer->vbo_verticesSize = 0; + HWBuffer->vbo_indicesSize = 0; + + if (!updateHardwareBuffer(HWBuffer)) { + deleteHardwareBuffer(HWBuffer); + return 0; + } + + return HWBuffer; +} + +void COGLES1Driver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) +{ + if (!_HWBuffer) + return; + + SHWBufferLink_opengl *HWBuffer = static_cast(_HWBuffer); + if (HWBuffer->vbo_verticesID) { + glDeleteBuffers(1, &HWBuffer->vbo_verticesID); + HWBuffer->vbo_verticesID = 0; + } + if (HWBuffer->vbo_indicesID) { + glDeleteBuffers(1, &HWBuffer->vbo_indicesID); + HWBuffer->vbo_indicesID = 0; + } + + CNullDriver::deleteHardwareBuffer(_HWBuffer); +} + +//! Draw hardware buffer +void COGLES1Driver::drawHardwareBuffer(SHWBufferLink *_HWBuffer) +{ + if (!_HWBuffer) + return; + + SHWBufferLink_opengl *HWBuffer = static_cast(_HWBuffer); + + updateHardwareBuffer(HWBuffer); // check if update is needed + + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + const void *vertices = mb->getVertices(); + const void *indexList = mb->getIndices(); + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { + glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + vertices = 0; + } + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + indexList = 0; + } + + drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, + mb->getPrimitiveCount(), mb->getVertexType(), + mb->getPrimitiveType(), mb->getIndexType()); + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) + glBindBuffer(GL_ARRAY_BUFFER, 0); + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} + +IRenderTarget *COGLES1Driver::addRenderTarget() +{ + COGLES1RenderTarget *renderTarget = new COGLES1RenderTarget(this); + RenderTargets.push_back(renderTarget); + + return renderTarget; +} + +// small helper function to create vertex buffer object adress offsets +static inline u8 *buffer_offset(const long offset) +{ + return ((u8 *)0 + offset); +} + +//! draws a vertex primitive list +void COGLES1Driver::drawVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) +{ + if (!checkPrimitiveCount(primitiveCount)) + return; + + setRenderStates3DMode(); + + drawVertexPrimitiveList2d3d(vertices, vertexCount, (const u16 *)indexList, primitiveCount, vType, pType, iType); +} + +void COGLES1Driver::drawVertexPrimitiveList2d3d(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType, bool threed) +{ + if (!primitiveCount || !vertexCount) + return; + + if (!threed && !checkPrimitiveCount(primitiveCount)) + return; + + CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); + + if (vertices) { + // convert colors to gl color format. + vertexCount *= 4; // reused as color component count + ColorBuffer.set_used(vertexCount); + u32 i; + + switch (vType) { + case EVT_STANDARD: { + const S3DVertex *p = static_cast(vertices); + for (i = 0; i < vertexCount; i += 4) { + p->Color.toOpenGLColor(&ColorBuffer[i]); + ++p; + } + } break; + case EVT_2TCOORDS: { + const S3DVertex2TCoords *p = static_cast(vertices); + for (i = 0; i < vertexCount; i += 4) { + p->Color.toOpenGLColor(&ColorBuffer[i]); + ++p; + } + } break; + case EVT_TANGENTS: { + const S3DVertexTangents *p = static_cast(vertices); + for (i = 0; i < vertexCount; i += 4) { + p->Color.toOpenGLColor(&ColorBuffer[i]); + ++p; + } + } break; + } + } + + // draw everything + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + if ((pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES)) + glEnableClientState(GL_TEXTURE_COORD_ARRAY); +#ifdef GL_OES_point_size_array + else if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_size_array] && (Material.Thickness == 0.0f)) + glEnableClientState(GL_POINT_SIZE_ARRAY_OES); +#endif + if (threed && (pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES)) + glEnableClientState(GL_NORMAL_ARRAY); + + if (vertices) + glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + + switch (vType) { + case EVT_STANDARD: + if (vertices) { + if (threed) + glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + } else { + glNormalPointer(GL_FLOAT, sizeof(S3DVertex), buffer_offset(12)); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0); + } + + if (Feature.MaxTextureUnits > 0 && CacheHandler->getTextureCache().get(1)) { + glClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + else + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); + } + break; + case EVT_2TCOORDS: + if (vertices) { + if (threed) + glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords); + glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Pos); + } else { + glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12)); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28)); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0)); + } + + if (Feature.MaxTextureUnits > 0) { + glClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords2); + else + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36)); + } + break; + case EVT_TANGENTS: + if (vertices) { + if (threed) + glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].TCoords); + glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Pos); + } else { + glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(12)); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28)); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0)); + } + + if (Feature.MaxTextureUnits > 0) { + glClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Tangent); + else + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(36)); + + glClientActiveTexture(GL_TEXTURE0 + 2); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Binormal); + else + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(48)); + } + break; + } + + GLenum indexSize = 0; + + switch (iType) { + case (EIT_16BIT): { + indexSize = GL_UNSIGNED_SHORT; + break; + } + case (EIT_32BIT): { +#ifdef GL_OES_element_index_uint +#ifndef GL_UNSIGNED_INT +#define GL_UNSIGNED_INT 0x1405 +#endif + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_element_index_uint]) + indexSize = GL_UNSIGNED_INT; + else +#endif + indexSize = GL_UNSIGNED_SHORT; + break; + } + } + + switch (pType) { + case scene::EPT_POINTS: + case scene::EPT_POINT_SPRITES: { +#ifdef GL_OES_point_sprite + if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_sprite]) + glEnable(GL_POINT_SPRITE_OES); +#endif + // if ==0 we use the point size array + if (Material.Thickness != 0.f) { + float quadratic[] = {0.0f, 0.0f, 10.01f}; + glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, quadratic); + float maxParticleSize = 1.0f; + glGetFloatv(GL_POINT_SIZE_MAX, &maxParticleSize); + // maxParticleSize=maxParticleSize 0) { + if (vType == EVT_TANGENTS) { + glClientActiveTexture(GL_TEXTURE0 + 2); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + if ((vType != EVT_STANDARD) || CacheHandler->getTextureCache().get(1)) { + glClientActiveTexture(GL_TEXTURE0 + 1); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + glClientActiveTexture(GL_TEXTURE0); + } + +#ifdef GL_OES_point_size_array + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_size_array] && (Material.Thickness == 0.0f)) + glDisableClientState(GL_POINT_SIZE_ARRAY_OES); +#endif + + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); +} + +//! draws a 2d image, using a color and the alpha channel of the texture +void COGLES1Driver::draw2DImage(const video::ITexture *texture, + const core::position2d &pos, + const core::rect &sourceRect, + const core::rect *clipRect, SColor color, + bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + if (!sourceRect.isValid()) + return; + + core::position2d targetPos(pos); + core::position2d sourcePos(sourceRect.UpperLeftCorner); + core::dimension2d sourceSize(sourceRect.getSize()); + if (clipRect) { + if (targetPos.X < clipRect->UpperLeftCorner.X) { + sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X; + if (sourceSize.Width <= 0) + return; + + sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X; + targetPos.X = clipRect->UpperLeftCorner.X; + } + + if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X) { + sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X; + if (sourceSize.Width <= 0) + return; + } + + if (targetPos.Y < clipRect->UpperLeftCorner.Y) { + sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y; + if (sourceSize.Height <= 0) + return; + + sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y; + targetPos.Y = clipRect->UpperLeftCorner.Y; + } + + if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y) { + sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y; + if (sourceSize.Height <= 0) + return; + } + } + + // clip these coordinates + + if (targetPos.X < 0) { + sourceSize.Width += targetPos.X; + if (sourceSize.Width <= 0) + return; + + sourcePos.X -= targetPos.X; + targetPos.X = 0; + } + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width) { + sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width; + if (sourceSize.Width <= 0) + return; + } + + if (targetPos.Y < 0) { + sourceSize.Height += targetPos.Y; + if (sourceSize.Height <= 0) + return; + + sourcePos.Y -= targetPos.Y; + targetPos.Y = 0; + } + + if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height) { + sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height; + if (sourceSize.Height <= 0) + return; + } + + // ok, we've clipped everything. + // now draw it. + + // texcoords need to be flipped horizontally for RTTs + const bool isRTT = texture->isRenderTarget(); + const core::dimension2d &ss = texture->getOriginalSize(); + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + const core::rect tcoords( + sourcePos.X * invW, + (isRTT ? (sourcePos.Y + sourceSize.Height) : sourcePos.Y) * invH, + (sourcePos.X + sourceSize.Width) * invW, + (isRTT ? sourcePos.Y : (sourcePos.Y + sourceSize.Height)) * invH); + + const core::rect poss(targetPos, sourceSize); + + if (!CacheHandler->getTextureCache().set(0, texture)) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + vertices[1] = S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + vertices[2] = S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + vertices[3] = S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); +} + +//! The same, but with a four element array of colors, one for each vertex +void COGLES1Driver::draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect, + const video::SColor *const colors, bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + // texcoords need to be flipped horizontally for RTTs + const bool isRTT = texture->isRenderTarget(); + const core::dimension2du &ss = texture->getOriginalSize(); + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + const core::rect tcoords( + sourceRect.UpperLeftCorner.X * invW, + (isRTT ? sourceRect.LowerRightCorner.Y : sourceRect.UpperLeftCorner.Y) * invH, + sourceRect.LowerRightCorner.X * invW, + (isRTT ? sourceRect.UpperLeftCorner.Y : sourceRect.LowerRightCorner.Y) * invH); + + const video::SColor temp[4] = { + 0xFFFFFFFF, + 0xFFFFFFFF, + 0xFFFFFFFF, + 0xFFFFFFFF, + }; + + const video::SColor *const useColor = colors ? colors : temp; + + if (!CacheHandler->getTextureCache().set(0, texture)) + return; + + setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 || + useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255, + true, useAlphaChannelOfTexture); + + if (clipRect) { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex((f32)destRect.UpperLeftCorner.X, (f32)destRect.UpperLeftCorner.Y, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + vertices[1] = S3DVertex((f32)destRect.LowerRightCorner.X, (f32)destRect.UpperLeftCorner.Y, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + vertices[2] = S3DVertex((f32)destRect.LowerRightCorner.X, (f32)destRect.LowerRightCorner.Y, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + vertices[3] = S3DVertex((f32)destRect.UpperLeftCorner.X, (f32)destRect.LowerRightCorner.Y, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); + + if (clipRect) + glDisable(GL_SCISSOR_TEST); +} + +void COGLES1Driver::draw2DImage(const video::ITexture *texture, u32 layer, bool flip) +{ + if (!texture || !CacheHandler->getTextureCache().set(0, texture)) + return; + + setRenderStates2DMode(false, true, true); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + Transformation3DChanged = true; + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + + vertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); + vertices[1].Pos = core::vector3df(1.f, 1.f, 0.f); + vertices[2].Pos = core::vector3df(1.f, -1.f, 0.f); + vertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f); + + f32 modificator = (flip) ? 1.f : 0.f; + + vertices[0].TCoords = core::vector2df(0.f, 0.f + modificator); + vertices[1].TCoords = core::vector2df(1.f, 0.f + modificator); + vertices[2].TCoords = core::vector2df(1.f, 1.f - modificator); + vertices[3].TCoords = core::vector2df(0.f, 1.f - modificator); + + vertices[0].Color = 0xFFFFFFFF; + vertices[1].Color = 0xFFFFFFFF; + vertices[2].Color = 0xFFFFFFFF; + vertices[3].Color = 0xFFFFFFFF; + + drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); +} + +//! draws a set of 2d images, using a color and the alpha channel of the texture if desired. +void COGLES1Driver::draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect, + SColor color, + bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + const u32 drawCount = core::min_(positions.size(), sourceRects.size()); + if (!drawCount) + return; + + const core::dimension2d &ss = texture->getOriginalSize(); + if (!ss.Width || !ss.Height) + return; + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + if (!CacheHandler->getTextureCache().set(0, texture)) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + core::array vertices; + core::array quadIndices; + vertices.reallocate(drawCount * 4); + quadIndices.reallocate(drawCount * 6); + + for (u32 i = 0; i < drawCount; ++i) { + if (!sourceRects[i].isValid()) + continue; + + core::position2d targetPos(positions[i]); + core::position2d sourcePos(sourceRects[i].UpperLeftCorner); + // This needs to be signed as it may go negative. + core::dimension2d sourceSize(sourceRects[i].getSize()); + if (clipRect) { + if (targetPos.X < clipRect->UpperLeftCorner.X) { + sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X; + if (sourceSize.Width <= 0) + continue; + + sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X; + targetPos.X = clipRect->UpperLeftCorner.X; + } + + if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X) { + sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X; + if (sourceSize.Width <= 0) + continue; + } + + if (targetPos.Y < clipRect->UpperLeftCorner.Y) { + sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y; + if (sourceSize.Height <= 0) + continue; + + sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y; + targetPos.Y = clipRect->UpperLeftCorner.Y; + } + + if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y) { + sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y; + if (sourceSize.Height <= 0) + continue; + } + } + + // clip these coordinates + + if (targetPos.X < 0) { + sourceSize.Width += targetPos.X; + if (sourceSize.Width <= 0) + continue; + + sourcePos.X -= targetPos.X; + targetPos.X = 0; + } + + if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width) { + sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width; + if (sourceSize.Width <= 0) + continue; + } + + if (targetPos.Y < 0) { + sourceSize.Height += targetPos.Y; + if (sourceSize.Height <= 0) + continue; + + sourcePos.Y -= targetPos.Y; + targetPos.Y = 0; + } + + if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height) { + sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height; + if (sourceSize.Height <= 0) + continue; + } + + // ok, we've clipped everything. + + const core::rect tcoords( + sourcePos.X * invW, + sourcePos.Y * invH, + (sourcePos.X + sourceSize.Width) * invW, + (sourcePos.Y + sourceSize.Height) * invH); + + const core::rect poss(targetPos, sourceSize); + + const u32 vstart = vertices.size(); + + vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); + vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); + vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); + vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); + + quadIndices.push_back(vstart); + quadIndices.push_back(vstart + 1); + quadIndices.push_back(vstart + 2); + quadIndices.push_back(vstart); + quadIndices.push_back(vstart + 2); + quadIndices.push_back(vstart + 3); + } + if (vertices.size()) + drawVertexPrimitiveList2d3d(vertices.pointer(), vertices.size(), + quadIndices.pointer(), vertices.size() / 2, + video::EVT_STANDARD, scene::EPT_TRIANGLES, + EIT_16BIT, false); +} + +//! draw a 2d rectangle +void COGLES1Driver::draw2DRectangle(SColor color, const core::rect &position, + const core::rect *clip) +{ + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, color, 0, 0); + vertices[2] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, color, 0, 0); + vertices[3] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, color, 0, 0); + drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); +} + +//! draw an 2d rectangle +void COGLES1Driver::draw2DRectangle(const core::rect &position, + SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip) +{ + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + setRenderStates2DMode(colorLeftUp.getAlpha() < 255 || + colorRightUp.getAlpha() < 255 || + colorLeftDown.getAlpha() < 255 || + colorRightDown.getAlpha() < 255, + false, false); + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, colorLeftUp, 0, 0); + vertices[1] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, colorRightUp, 0, 0); + vertices[2] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, colorRightDown, 0, 0); + vertices[3] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, colorLeftDown, 0, 0); + drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); +} + +//! Draws a 2d line. +void COGLES1Driver::draw2DLine(const core::position2d &start, + const core::position2d &end, + SColor color) +{ + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + u16 indices[] = {0, 1}; + S3DVertex vertices[2]; + vertices[0] = S3DVertex((f32)start.X, (f32)start.Y, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex((f32)end.X, (f32)end.Y, 0, 0, 0, 1, color, 1, 1); + drawVertexPrimitiveList2d3d(vertices, 2, indices, 1, video::EVT_STANDARD, scene::EPT_LINES, EIT_16BIT, false); +} + +//! creates a matrix in supplied GLfloat array to pass to OGLES1 +inline void COGLES1Driver::getGLMatrix(GLfloat gl_matrix[16], const core::matrix4 &m) +{ + memcpy(gl_matrix, m.pointer(), 16 * sizeof(f32)); +} + +//! creates a opengltexturematrix from a D3D style texture matrix +inline void COGLES1Driver::getGLTextureMatrix(GLfloat *o, const core::matrix4 &m) +{ + o[0] = m[0]; + o[1] = m[1]; + o[2] = 0.f; + o[3] = 0.f; + + o[4] = m[4]; + o[5] = m[5]; + o[6] = 0.f; + o[7] = 0.f; + + o[8] = 0.f; + o[9] = 0.f; + o[10] = 1.f; + o[11] = 0.f; + + o[12] = m[8]; + o[13] = m[9]; + o[14] = 0.f; + o[15] = 1.f; +} + +ITexture *COGLES1Driver::createDeviceDependentTexture(const io::path &name, IImage *image) +{ + core::array imageArray(1); + imageArray.push_back(image); + + COGLES1Texture *texture = new COGLES1Texture(name, imageArray, ETT_2D, this); + + return texture; +} + +ITexture *COGLES1Driver::createDeviceDependentTextureCubemap(const io::path &name, const core::array &image) +{ + COGLES1Texture *texture = new COGLES1Texture(name, image, ETT_CUBEMAP, this); + + return texture; +} + +//! Sets a material. All 3d drawing functions draw geometry now using this material. +void COGLES1Driver::setMaterial(const SMaterial &material) +{ + Material = material; + OverrideMaterial.apply(Material); + + for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) + setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); +} + +//! prints error if an error happened. +bool COGLES1Driver::testGLError(int code) +{ +#ifdef _DEBUG + GLenum g = glGetError(); + switch (g) { + case GL_NO_ERROR: + return false; + case GL_INVALID_ENUM: + os::Printer::log("GL_INVALID_ENUM", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_INVALID_VALUE: + os::Printer::log("GL_INVALID_VALUE", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_INVALID_OPERATION: + os::Printer::log("GL_INVALID_OPERATION", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_STACK_OVERFLOW: + os::Printer::log("GL_STACK_OVERFLOW", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_STACK_UNDERFLOW: + os::Printer::log("GL_STACK_UNDERFLOW", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_OUT_OF_MEMORY: + os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); + break; + }; + // _IRR_DEBUG_BREAK_IF(true); + return true; +#else + return false; +#endif +} + +//! sets the needed renderstates +void COGLES1Driver::setRenderStates3DMode() +{ + if (CurrentRenderMode != ERM_3D) { + // Reset Texture Stages + CacheHandler->setBlend(false); + glDisable(GL_ALPHA_TEST); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + // switch back the matrices + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer()); + + GLfloat glmat[16]; + getGLMatrix(glmat, Matrices[ETS_PROJECTION]); + glmat[12] *= -1.0f; + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(glmat); + + ResetRenderStates = true; + } + + if (ResetRenderStates || LastMaterial != Material) { + // unset old material + + if (LastMaterial.MaterialType != Material.MaterialType && + static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + + // set new material. + if (static_cast(Material.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial( + Material, LastMaterial, ResetRenderStates, this); + + LastMaterial = Material; + CacheHandler->correctCacheMaterial(LastMaterial); + ResetRenderStates = false; + } + + if (static_cast(Material.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, video::EVT_STANDARD); + + CurrentRenderMode = ERM_3D; +} + +GLint COGLES1Driver::getTextureWrapMode(u8 clamp) const +{ + switch (clamp) { + case ETC_CLAMP: + // return GL_CLAMP; not supported in ogl-es + return GL_CLAMP_TO_EDGE; + break; + case ETC_CLAMP_TO_EDGE: + return GL_CLAMP_TO_EDGE; + break; + case ETC_CLAMP_TO_BORDER: + // return GL_CLAMP_TO_BORDER; not supported in ogl-es + return GL_CLAMP_TO_EDGE; + break; + case ETC_MIRROR: +#ifdef GL_OES_texture_mirrored_repeat + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_texture_mirrored_repeat]) + return GL_MIRRORED_REPEAT_OES; + else +#endif + return GL_REPEAT; + break; + // the next three are not yet supported at all + case ETC_MIRROR_CLAMP: + case ETC_MIRROR_CLAMP_TO_EDGE: + case ETC_MIRROR_CLAMP_TO_BORDER: +#ifdef GL_OES_texture_mirrored_repeat + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_texture_mirrored_repeat]) + return GL_MIRRORED_REPEAT_OES; + else +#endif + return GL_CLAMP_TO_EDGE; + break; + case ETC_REPEAT: + default: + return GL_REPEAT; + break; + } +} + +//! Can be called by an IMaterialRenderer to make its work easier. +void COGLES1Driver::setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, + bool resetAllRenderStates) +{ + if (resetAllRenderStates || + lastmaterial.ColorMaterial != material.ColorMaterial) { + // we only have diffuse_and_ambient in ogl-es + if (material.ColorMaterial == ECM_DIFFUSE_AND_AMBIENT) + glEnable(GL_COLOR_MATERIAL); + else + glDisable(GL_COLOR_MATERIAL); + } + + if (resetAllRenderStates || + lastmaterial.AmbientColor != material.AmbientColor || + lastmaterial.DiffuseColor != material.DiffuseColor || + lastmaterial.EmissiveColor != material.EmissiveColor || + lastmaterial.ColorMaterial != material.ColorMaterial) { + GLfloat color[4]; + + const f32 inv = 1.0f / 255.0f; + + if ((material.ColorMaterial != video::ECM_AMBIENT) && + (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) { + color[0] = material.AmbientColor.getRed() * inv; + color[1] = material.AmbientColor.getGreen() * inv; + color[2] = material.AmbientColor.getBlue() * inv; + color[3] = material.AmbientColor.getAlpha() * inv; + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); + } + + if ((material.ColorMaterial != video::ECM_DIFFUSE) && + (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) { + color[0] = material.DiffuseColor.getRed() * inv; + color[1] = material.DiffuseColor.getGreen() * inv; + color[2] = material.DiffuseColor.getBlue() * inv; + color[3] = material.DiffuseColor.getAlpha() * inv; + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); + } + + if (material.ColorMaterial != video::ECM_EMISSIVE) { + color[0] = material.EmissiveColor.getRed() * inv; + color[1] = material.EmissiveColor.getGreen() * inv; + color[2] = material.EmissiveColor.getBlue() * inv; + color[3] = material.EmissiveColor.getAlpha() * inv; + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); + } + } + + if (resetAllRenderStates || + lastmaterial.SpecularColor != material.SpecularColor || + lastmaterial.Shininess != material.Shininess) { + GLfloat color[] = {0.f, 0.f, 0.f, 1.f}; + const f32 inv = 1.0f / 255.0f; + + // disable Specular colors if no shininess is set + if ((material.Shininess != 0.0f) && + (material.ColorMaterial != video::ECM_SPECULAR)) { +#ifdef GL_EXT_separate_specular_color + if (FeatureAvailable[IRR_EXT_separate_specular_color]) + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); +#endif + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess); + color[0] = material.SpecularColor.getRed() * inv; + color[1] = material.SpecularColor.getGreen() * inv; + color[2] = material.SpecularColor.getBlue() * inv; + color[3] = material.SpecularColor.getAlpha() * inv; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); + } +#ifdef GL_EXT_separate_specular_color + else if (FeatureAvailable[IRR_EXT_separate_specular_color]) + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); +#endif + } + + // TODO ogl-es + // fillmode + // if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud)) + // glPolygonMode(GL_FRONT_AND_BACK, material.Wireframe ? GL_LINE : material.PointCloud? GL_POINT : GL_FILL); + + // shademode + if (resetAllRenderStates || (lastmaterial.GouraudShading != material.GouraudShading)) { + if (material.GouraudShading) + glShadeModel(GL_SMOOTH); + else + glShadeModel(GL_FLAT); + } + + // lighting + if (resetAllRenderStates || (lastmaterial.Lighting != material.Lighting)) { + if (material.Lighting) + glEnable(GL_LIGHTING); + else + glDisable(GL_LIGHTING); + } + + // zbuffer + if (resetAllRenderStates || lastmaterial.ZBuffer != material.ZBuffer) { + switch (material.ZBuffer) { + case ECFN_DISABLED: + glDisable(GL_DEPTH_TEST); + break; + case ECFN_LESSEQUAL: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + break; + case ECFN_EQUAL: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_EQUAL); + break; + case ECFN_LESS: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + break; + case ECFN_NOTEQUAL: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_NOTEQUAL); + break; + case ECFN_GREATEREQUAL: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_GEQUAL); + break; + case ECFN_GREATER: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_GREATER); + break; + case ECFN_ALWAYS: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + break; + case ECFN_NEVER: + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_NEVER); + break; + } + } + + // zwrite + if (getWriteZBuffer(material)) { + glDepthMask(GL_TRUE); + } else { + glDepthMask(GL_FALSE); + } + + // back face culling + if (resetAllRenderStates || (lastmaterial.FrontfaceCulling != material.FrontfaceCulling) || (lastmaterial.BackfaceCulling != material.BackfaceCulling)) { + if ((material.FrontfaceCulling) && (material.BackfaceCulling)) { + glCullFace(GL_FRONT_AND_BACK); + glEnable(GL_CULL_FACE); + } else if (material.BackfaceCulling) { + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + } else if (material.FrontfaceCulling) { + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); + } else + glDisable(GL_CULL_FACE); + } + + // fog + if (resetAllRenderStates || lastmaterial.FogEnable != material.FogEnable) { + if (material.FogEnable) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + } + + // normalization + if (resetAllRenderStates || lastmaterial.NormalizeNormals != material.NormalizeNormals) { + if (material.NormalizeNormals) + glEnable(GL_NORMALIZE); + else + glDisable(GL_NORMALIZE); + } + + // Color Mask + if (resetAllRenderStates || lastmaterial.ColorMask != material.ColorMask) { + glColorMask( + (material.ColorMask & ECP_RED) ? GL_TRUE : GL_FALSE, + (material.ColorMask & ECP_GREEN) ? GL_TRUE : GL_FALSE, + (material.ColorMask & ECP_BLUE) ? GL_TRUE : GL_FALSE, + (material.ColorMask & ECP_ALPHA) ? GL_TRUE : GL_FALSE); + } + + // Blend Equation + if (material.BlendOperation == EBO_NONE) + CacheHandler->setBlend(false); + else { + CacheHandler->setBlend(true); + + if (queryFeature(EVDF_BLEND_OPERATIONS)) { + switch (material.BlendOperation) { + case EBO_ADD: +#if defined(GL_OES_blend_subtract) + CacheHandler->setBlendEquation(GL_FUNC_ADD_OES); +#endif + break; + case EBO_SUBTRACT: +#if defined(GL_OES_blend_subtract) + CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT_OES); +#endif + break; + case EBO_REVSUBTRACT: +#if defined(GL_OES_blend_subtract) + CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT_OES); +#endif + break; + default: + break; + } + } + } + + // Blend Factor + if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF? + && material.MaterialType != EMT_ONETEXTURE_BLEND) { + E_BLEND_FACTOR srcRGBFact = EBF_ZERO; + E_BLEND_FACTOR dstRGBFact = EBF_ZERO; + E_BLEND_FACTOR srcAlphaFact = EBF_ZERO; + E_BLEND_FACTOR dstAlphaFact = EBF_ZERO; + E_MODULATE_FUNC modulo = EMFN_MODULATE_1X; + u32 alphaSource = 0; + + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, material.BlendFactor); + + if (queryFeature(EVDF_BLEND_SEPARATE)) { + CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact), + getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact)); + } else { + CacheHandler->setBlendFunc(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact)); + } + } + + // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver. + + // thickness + if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) { + if (AntiAlias) { + // glPointSize(core::clamp(static_cast(material.Thickness), DimSmoothedPoint[0], DimSmoothedPoint[1])); + // we don't use point smoothing + glPointSize(core::clamp(static_cast(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1])); + } else { + glPointSize(core::clamp(static_cast(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1])); + glLineWidth(core::clamp(static_cast(material.Thickness), DimAliasedLine[0], DimAliasedLine[1])); + } + } + + // Anti aliasing + if (resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing) { + if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) + glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) + glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + + if ((AntiAlias >= 2) && (material.AntiAliasing & (EAAM_SIMPLE | EAAM_QUALITY))) + glEnable(GL_MULTISAMPLE); + else + glDisable(GL_MULTISAMPLE); + } + + // Texture parameters + setTextureRenderStates(material, resetAllRenderStates); +} + +//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. +void COGLES1Driver::setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates) +{ + // Set textures to TU/TIU and apply filters to them + + for (s32 i = Feature.MaxTextureUnits - 1; i >= 0; --i) { + CacheHandler->getTextureCache().set(i, material.TextureLayers[i].Texture); + + const COGLES1Texture *tmpTexture = CacheHandler->getTextureCache().get(i); + + if (!tmpTexture) + continue; + + GLenum tmpTextureType = tmpTexture->getOpenGLTextureType(); + + CacheHandler->setActiveTexture(GL_TEXTURE0 + i); + + { + const bool isRTT = tmpTexture->isRenderTarget(); + + glMatrixMode(GL_TEXTURE); + + if (!isRTT && Matrices[ETS_TEXTURE_0 + i].isIdentity()) + glLoadIdentity(); + else { + GLfloat glmat[16]; + if (isRTT) + getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i] * TextureFlipMatrix); + else + getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i]); + glLoadMatrixf(glmat); + } + } + + COGLES1Texture::SStatesCache &statesCache = tmpTexture->getStatesCache(); + + if (resetAllRenderstates) + statesCache.IsCached = false; + +#if defined(GL_EXT_texture_lod_bias) + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_lod_bias]) { + if (material.TextureLayers[i].LODBias) { + const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp); + } else + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f); + } +#endif + + if (!statesCache.IsCached || material.TextureLayers[i].MagFilter != statesCache.MagFilter) { + E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter; + glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER, + magFilter == ETMAGF_NEAREST ? GL_NEAREST : (assert(magFilter == ETMAGF_LINEAR), GL_LINEAR)); + + statesCache.MagFilter = magFilter; + } + + if (material.UseMipMaps && tmpTexture->hasMipMaps()) { + if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter || + !statesCache.MipMapStatus) { + E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; + glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST : minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST + : minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR + : (assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR)); + + statesCache.MinFilter = minFilter; + statesCache.MipMapStatus = true; + } + } else { + if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter || + statesCache.MipMapStatus) { + E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; + glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + (minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST : (assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR)); + + statesCache.MinFilter = minFilter; + statesCache.MipMapStatus = false; + } + } + +#ifdef GL_EXT_texture_filter_anisotropic + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_filter_anisotropic] && + (!statesCache.IsCached || material.TextureLayers[i].AnisotropicFilter != statesCache.AnisotropicFilter)) { + glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, + material.TextureLayers[i].AnisotropicFilter > 1 ? core::min_(MaxAnisotropy, material.TextureLayers[i].AnisotropicFilter) : 1); + + statesCache.AnisotropicFilter = material.TextureLayers[i].AnisotropicFilter; + } +#endif + + if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapU != statesCache.WrapU) { + glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayers[i].TextureWrapU)); + statesCache.WrapU = material.TextureLayers[i].TextureWrapU; + } + + if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapV != statesCache.WrapV) { + glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayers[i].TextureWrapV)); + statesCache.WrapV = material.TextureLayers[i].TextureWrapV; + } + + statesCache.IsCached = true; + } + + // be sure to leave in texture stage 0 + CacheHandler->setActiveTexture(GL_TEXTURE0); +} + +//! sets the needed renderstates +void COGLES1Driver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) +{ + if (CurrentRenderMode != ERM_2D || Transformation3DChanged) { + // unset last 3d material + if (CurrentRenderMode == ERM_3D) { + if (static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + } + if (Transformation3DChanged) { + glMatrixMode(GL_PROJECTION); + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + core::matrix4 m(core::matrix4::EM4CONST_NOTHING); + m.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0f, 1.0f); + m.setTranslation(core::vector3df(-1, 1, 0)); + glLoadMatrixf(m.pointer()); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + Transformation3DChanged = false; + } + } + + Material = (OverrideMaterial2DEnabled) ? OverrideMaterial2D : InitMaterial2D; + Material.Lighting = false; + Material.TextureLayers[0].Texture = (texture) ? const_cast(CacheHandler->getTextureCache().get(0)) : 0; + setTransform(ETS_TEXTURE_0, core::IdentityMatrix); + + setBasicRenderStates(Material, LastMaterial, false); + + LastMaterial = Material; + CacheHandler->correctCacheMaterial(LastMaterial); + + // no alphaChannel without texture + alphaChannel &= texture; + + if (alphaChannel || alpha) { + CacheHandler->setBlend(true); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + CacheHandler->setBlendEquation(GL_FUNC_ADD); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.f); + } else { + CacheHandler->setBlend(false); + glDisable(GL_ALPHA_TEST); + } + + if (texture) { + // Due to the transformation change, the previous line would call a reset each frame + // but we can safely reset the variable as it was false before + Transformation3DChanged = false; + + if (alphaChannel) { + // if alpha and alpha texture just modulate, otherwise use only the alpha channel + if (alpha) { + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } else { + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); + // rgb always modulates + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); + } + } else { + if (alpha) { + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR); + // rgb always modulates + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); + } else { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + } + } + + CurrentRenderMode = ERM_2D; +} + +//! \return Returns the name of the video driver. +const char *COGLES1Driver::getName() const +{ + return Name.c_str(); +} + +//! Sets the dynamic ambient light color. +void COGLES1Driver::setAmbientLight(const SColorf &color) +{ + CNullDriver::setAmbientLight(color); + GLfloat data[4] = {color.r, color.g, color.b, color.a}; + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data); +} + +// this code was sent in by Oliver Klems, thank you +void COGLES1Driver::setViewPort(const core::rect &area) +{ + core::rect vp = area; + core::rect rendert(0, 0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height); + vp.clipAgainst(rendert); + + if (vp.getHeight() > 0 && vp.getWidth() > 0) + CacheHandler->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight()); + + ViewPort = vp; +} + +void COGLES1Driver::setViewPortRaw(u32 width, u32 height) +{ + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); +} + +//! Sets the fog mode. +void COGLES1Driver::setFog(SColor c, E_FOG_TYPE fogType, f32 start, + f32 end, f32 density, bool pixelFog, bool rangeFog) +{ + CNullDriver::setFog(c, fogType, start, end, density, pixelFog, rangeFog); + + glFogf(GL_FOG_MODE, GLfloat((fogType == EFT_FOG_LINEAR) ? GL_LINEAR : (fogType == EFT_FOG_EXP) ? GL_EXP + : GL_EXP2)); + +#ifdef GL_EXT_fog_coord + if (FeatureAvailable[IRR_EXT_fog_coord]) + glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH); +#endif + + if (fogType == EFT_FOG_LINEAR) { + glFogf(GL_FOG_START, start); + glFogf(GL_FOG_END, end); + } else + glFogf(GL_FOG_DENSITY, density); + + if (pixelFog) + glHint(GL_FOG_HINT, GL_NICEST); + else + glHint(GL_FOG_HINT, GL_FASTEST); + + SColorf color(c); + GLfloat data[4] = {color.r, color.g, color.b, color.a}; + glFogfv(GL_FOG_COLOR, data); +} + +//! Draws a 3d line. +void COGLES1Driver::draw3DLine(const core::vector3df &start, + const core::vector3df &end, SColor color) +{ + setRenderStates3DMode(); + + u16 indices[] = {0, 1}; + S3DVertex vertices[2]; + vertices[0] = S3DVertex(start.X, start.Y, start.Z, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(end.X, end.Y, end.Z, 0, 0, 1, color, 0, 0); + drawVertexPrimitiveList2d3d(vertices, 2, indices, 1, video::EVT_STANDARD, scene::EPT_LINES); +} + +//! Only used by the internal engine. Used to notify the driver that +//! the window was resized. +void COGLES1Driver::OnResize(const core::dimension2d &size) +{ + CNullDriver::OnResize(size); + CacheHandler->setViewport(0, 0, size.Width, size.Height); + Transformation3DChanged = true; +} + +//! Returns type of video driver +E_DRIVER_TYPE COGLES1Driver::getDriverType() const +{ + return EDT_OGLES1; +} + +//! returns color format +ECOLOR_FORMAT COGLES1Driver::getColorFormat() const +{ + return ColorFormat; +} + +//! Get a vertex shader constant index. +s32 COGLES1Driver::getVertexShaderConstantID(const c8 *name) +{ + return getPixelShaderConstantID(name); +} + +//! Get a pixel shader constant index. +s32 COGLES1Driver::getPixelShaderConstantID(const c8 *name) +{ + os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->getPixelShaderConstantID()."); + return -1; +} + +//! Sets a constant for the vertex shader based on an index. +bool COGLES1Driver::setVertexShaderConstant(s32 index, const f32 *floats, int count) +{ + // pass this along, as in GLSL the same routine is used for both vertex and fragment shaders + return setPixelShaderConstant(index, floats, count); +} + +//! Int interface for the above. +bool COGLES1Driver::setVertexShaderConstant(s32 index, const s32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COGLES1Driver::setVertexShaderConstant(s32 index, const u32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +//! Sets a constant for the pixel shader based on an index. +bool COGLES1Driver::setPixelShaderConstant(s32 index, const f32 *floats, int count) +{ + os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant()."); + return false; +} + +//! Int interface for the above. +bool COGLES1Driver::setPixelShaderConstant(s32 index, const s32 *ints, int count) +{ + os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant()."); + return false; +} + +bool COGLES1Driver::setPixelShaderConstant(s32 index, const u32 *ints, int count) +{ + os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant()."); + return false; +} + +//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. +s32 COGLES1Driver::addHighLevelShaderMaterial( + const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + const c8 *pixelShaderProgram, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + const c8 *geometryShaderProgram, + const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, + scene::E_PRIMITIVE_TYPE inType, + scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) +{ + os::Printer::log("No shader support."); + return -1; +} + +//! Returns a pointer to the IVideoDriver interface. (Implementation for +//! IMaterialRendererServices) +IVideoDriver *COGLES1Driver::getVideoDriver() +{ + return this; +} + +//! Returns pointer to the IGPUProgrammingServices interface. +IGPUProgrammingServices *COGLES1Driver::getGPUProgrammingServices() +{ + return this; +} + +ITexture *COGLES1Driver::addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format) +{ + // disable mip-mapping + bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); + + bool supportForFBO = (Feature.ColorAttachment > 0); + + core::dimension2du destSize(size); + + if (!supportForFBO) { + destSize = core::dimension2d(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height)); + destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false); + } + + COGLES1Texture *renderTargetTexture = new COGLES1Texture(name, destSize, ETT_2D, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + // restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; +} + +ITexture *COGLES1Driver::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path &name, const ECOLOR_FORMAT format) +{ + // disable mip-mapping + bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); + + bool supportForFBO = (Feature.ColorAttachment > 0); + + const core::dimension2d size(sideLen, sideLen); + core::dimension2du destSize(size); + + if (!supportForFBO) { + destSize = core::dimension2d(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height)); + destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false); + } + + COGLES1Texture *renderTargetTexture = new COGLES1Texture(name, destSize, ETT_CUBEMAP, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + // restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; +} + +//! Returns the maximum amount of primitives +u32 COGLES1Driver::getMaximalPrimitiveCount() const +{ + return 65535; +} + +bool COGLES1Driver::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +{ + if (target && target->getDriverType() != EDT_OGLES1) { + os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL driver.", ELL_ERROR); + return false; + } + + bool supportForFBO = (Feature.ColorAttachment > 0); + + core::dimension2d destRenderTargetSize(0, 0); + + if (target) { + COGLES1RenderTarget *renderTarget = static_cast(target); + + if (supportForFBO) { + CacheHandler->setFBO(renderTarget->getBufferID()); + renderTarget->update(); + } + + destRenderTargetSize = renderTarget->getSize(); + + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); + } else { + if (supportForFBO) + CacheHandler->setFBO(0); + else { + COGLES1RenderTarget *prevRenderTarget = static_cast(CurrentRenderTarget); + COGLES1Texture *renderTargetTexture = static_cast(prevRenderTarget->getTexture()); + + if (renderTargetTexture) { + const COGLES1Texture *prevTexture = CacheHandler->getTextureCache().get(0); + + CacheHandler->getTextureCache().set(0, renderTargetTexture); + + const core::dimension2d size = renderTargetTexture->getSize(); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.Width, size.Height); + + CacheHandler->getTextureCache().set(0, prevTexture); + } + } + + destRenderTargetSize = core::dimension2d(0, 0); + + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); + } + + if (CurrentRenderTargetSize != destRenderTargetSize) { + CurrentRenderTargetSize = destRenderTargetSize; + + Transformation3DChanged = true; + } + + CurrentRenderTarget = target; + + if (!supportForFBO) { + clearFlag |= ECBF_COLOR; + clearFlag |= ECBF_DEPTH; + } + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; +} + +void COGLES1Driver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) +{ + GLbitfield mask = 0; + + if (flag & ECBF_COLOR) { + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + const f32 inv = 1.0f / 255.0f; + glClearColor(color.getRed() * inv, color.getGreen() * inv, + color.getBlue() * inv, color.getAlpha() * inv); + + mask |= GL_COLOR_BUFFER_BIT; + } + + if (flag & ECBF_DEPTH) { + glDepthMask(GL_TRUE); + glClearDepthf(depth); + mask |= GL_DEPTH_BUFFER_BIT; + } + + if (flag & ECBF_STENCIL) { + glClearStencil(stencil); + mask |= GL_STENCIL_BUFFER_BIT; + } + + if (mask) + glClear(mask); +} + +//! Returns an image created from the last rendered frame. +// We want to read the front buffer to get the latest render finished. +// This is not possible under ogl-es, though, so one has to call this method +// outside of the render loop only. +IImage *COGLES1Driver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target) +{ + if (target == video::ERT_MULTI_RENDER_TEXTURES || target == video::ERT_RENDER_TEXTURE || target == video::ERT_STEREO_BOTH_BUFFERS) + return 0; + GLint internalformat = GL_RGBA; + GLint type = GL_UNSIGNED_BYTE; + if (false && (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_IMG_read_format] || FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_read_format] || FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_read_format_bgra])) { +#ifdef GL_IMPLEMENTATION_COLOR_READ_TYPE_OES + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &internalformat); + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &type); +#endif + // there are formats we don't support ATM + if (GL_UNSIGNED_SHORT_4_4_4_4 == type) + type = GL_UNSIGNED_SHORT_5_5_5_1; +#ifdef GL_EXT_read_format_bgra + else if (GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT == type) + type = GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT; +#endif + } + + IImage *newImage = 0; + if ((GL_RGBA == internalformat) +#ifdef GL_EXT_read_format_bgra + || (GL_BGRA_EXT == internalformat) +#endif + ) { + if (GL_UNSIGNED_BYTE == type) + newImage = new CImage(ECF_A8R8G8B8, ScreenSize); + else + newImage = new CImage(ECF_A1R5G5B5, ScreenSize); + } else { + if (GL_UNSIGNED_BYTE == type) + newImage = new CImage(ECF_R8G8B8, ScreenSize); + else + newImage = new CImage(ECF_R5G6B5, ScreenSize); + } + + u8 *pixels = static_cast(newImage->getData()); + if (!pixels) { + newImage->drop(); + return 0; + } + + glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); + + // opengl images are horizontally flipped, so we have to fix that here. + const s32 pitch = newImage->getPitch(); + u8 *p2 = pixels + (ScreenSize.Height - 1) * pitch; + u8 *tmpBuffer = new u8[pitch]; + for (u32 i = 0; i < ScreenSize.Height; i += 2) { + memcpy(tmpBuffer, pixels, pitch); + memcpy(pixels, p2, pitch); + memcpy(p2, tmpBuffer, pitch); + pixels += pitch; + p2 -= pitch; + } + delete[] tmpBuffer; + + if (testGLError(__LINE__)) { + newImage->drop(); + return 0; + } + + return newImage; +} + +void COGLES1Driver::removeTexture(ITexture *texture) +{ + CacheHandler->getTextureCache().remove(texture); + CNullDriver::removeTexture(texture); +} + +//! Set/unset a clipping plane. +bool COGLES1Driver::setClipPlane(u32 index, const core::plane3df &plane, bool enable) +{ + if (index >= MaxUserClipPlanes) + return false; + + UserClipPlane[index] = plane; + enableClipPlane(index, enable); + return true; +} + +void COGLES1Driver::uploadClipPlane(u32 index) +{ + // opengl needs an array of doubles for the plane equation + float clip_plane[4]; + clip_plane[0] = UserClipPlane[index].Normal.X; + clip_plane[1] = UserClipPlane[index].Normal.Y; + clip_plane[2] = UserClipPlane[index].Normal.Z; + clip_plane[3] = UserClipPlane[index].D; + glClipPlanef(GL_CLIP_PLANE0 + index, clip_plane); +} + +//! Enable/disable a clipping plane. +void COGLES1Driver::enableClipPlane(u32 index, bool enable) +{ + if (index >= MaxUserClipPlanes) + return; + if (enable) { + if (!UserClipPlaneEnabled[index]) { + uploadClipPlane(index); + glEnable(GL_CLIP_PLANE0 + index); + } + } else + glDisable(GL_CLIP_PLANE0 + index); + + UserClipPlaneEnabled[index] = enable; +} + +core::dimension2du COGLES1Driver::getMaxTextureSize() const +{ + return core::dimension2du(MaxTextureSize, MaxTextureSize); +} + +GLenum COGLES1Driver::getGLBlend(E_BLEND_FACTOR factor) const +{ + static GLenum const blendTable[] = { + GL_ZERO, + GL_ONE, + GL_DST_COLOR, + GL_ONE_MINUS_DST_COLOR, + GL_SRC_COLOR, + GL_ONE_MINUS_SRC_COLOR, + GL_SRC_ALPHA, + GL_ONE_MINUS_SRC_ALPHA, + GL_DST_ALPHA, + GL_ONE_MINUS_DST_ALPHA, + GL_SRC_ALPHA_SATURATE, + }; + + return blendTable[factor]; +} + +GLenum COGLES1Driver::getZBufferBits() const +{ + GLenum bits = 0; + + switch (Params.ZBufferBits) { + case 24: +#if defined(GL_OES_depth24) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth24)) + bits = GL_DEPTH_COMPONENT24_OES; + else +#endif + bits = GL_DEPTH_COMPONENT16; + break; + case 32: +#if defined(GL_OES_depth32) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32)) + bits = GL_DEPTH_COMPONENT32_OES; + else +#endif + bits = GL_DEPTH_COMPONENT16; + break; + default: + bits = GL_DEPTH_COMPONENT16; + break; + } + + return bits; +} + +bool COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, + GLenum &pixelType, void (**converter)(const void *, s32, void *)) const +{ + bool supported = false; + internalFormat = GL_RGBA; + pixelFormat = GL_RGBA; + pixelType = GL_UNSIGNED_BYTE; + *converter = 0; + + switch (format) { + case ECF_A1R5G5B5: + supported = true; + internalFormat = GL_RGBA; + pixelFormat = GL_RGBA; + pixelType = GL_UNSIGNED_SHORT_5_5_5_1; + *converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1; + break; + case ECF_R5G6B5: + supported = true; + internalFormat = GL_RGB; + pixelFormat = GL_RGB; + pixelType = GL_UNSIGNED_SHORT_5_6_5; + break; + case ECF_R8G8B8: + supported = true; + internalFormat = GL_RGB; + pixelFormat = GL_RGB; + pixelType = GL_UNSIGNED_BYTE; + break; + case ECF_A8R8G8B8: + supported = true; + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_IMG_texture_format_BGRA8888) || + queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_format_BGRA8888) || + queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_APPLE_texture_format_BGRA8888)) { + internalFormat = GL_BGRA; + pixelFormat = GL_BGRA; + } else { + internalFormat = GL_RGBA; + pixelFormat = GL_RGBA; + *converter = CColorConverter::convert_A8R8G8B8toA8B8G8R8; + } + pixelType = GL_UNSIGNED_BYTE; + break; + case ECF_D16: + supported = true; + internalFormat = GL_DEPTH_COMPONENT16; + pixelFormat = GL_DEPTH_COMPONENT; + pixelType = GL_UNSIGNED_SHORT; + break; + case ECF_D32: +#if defined(GL_OES_depth32) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32)) { + supported = true; + internalFormat = GL_DEPTH_COMPONENT32_OES; + pixelFormat = GL_DEPTH_COMPONENT; + pixelType = GL_UNSIGNED_INT; + } +#endif + break; + case ECF_D24S8: +#ifdef GL_OES_packed_depth_stencil + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_packed_depth_stencil)) { + supported = true; + internalFormat = GL_DEPTH24_STENCIL8_OES; + pixelFormat = GL_DEPTH_STENCIL_OES; + pixelType = GL_UNSIGNED_INT_24_8_OES; + } +#endif + break; + case ECF_R8: + break; + case ECF_R8G8: + break; + case ECF_R16: + break; + case ECF_R16G16: + break; + case ECF_R16F: + break; + case ECF_G16R16F: + break; + case ECF_A16B16G16R16F: + break; + case ECF_R32F: + break; + case ECF_G32R32F: + break; + case ECF_A32B32G32R32F: + break; + default: + break; + } + +#ifdef _IRR_IOS_PLATFORM_ + if (internalFormat == GL_BGRA) + internalFormat = GL_RGBA; +#endif + + return supported; +} + +bool COGLES1Driver::queryTextureFormat(ECOLOR_FORMAT format) const +{ + GLint dummyInternalFormat; + GLenum dummyPixelFormat; + GLenum dummyPixelType; + void (*dummyConverter)(const void *, s32, void *); + return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter); +} + +bool COGLES1Driver::needsTransparentRenderPass(const irr::video::SMaterial &material) const +{ + return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); +} + +COGLES1CacheHandler *COGLES1Driver::getCacheHandler() const +{ + return CacheHandler; +} + +} // end namespace +} // end namespace + +#endif // _IRR_COMPILE_WITH_OGLES1_ + +namespace irr +{ +namespace video +{ + +#ifndef _IRR_COMPILE_WITH_OGLES1_ +class IVideoDriver; +class IContextManager; +#endif + +IVideoDriver *createOGLES1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ +#ifdef _IRR_COMPILE_WITH_OGLES1_ + return new COGLES1Driver(params, io, contextManager); +#else + return 0; +#endif // _IRR_COMPILE_WITH_OGLES1_ +} + +} // end namespace +} // end namespace diff --git a/irr/src/COGLESDriver.h b/irr/src/COGLESDriver.h new file mode 100644 index 000000000..82b4a1793 --- /dev/null +++ b/irr/src/COGLESDriver.h @@ -0,0 +1,325 @@ +// Copyright (C) 2002-20014 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "SIrrCreationParameters.h" + +#ifdef _IRR_COMPILE_WITH_OGLES1_ + +#include "CNullDriver.h" +#include "IMaterialRendererServices.h" +#include "EDriverFeatures.h" +#include "fast_atof.h" +#include "COGLESExtensionHandler.h" +#include "IContextManager.h" + +namespace irr +{ +namespace video +{ + +class COGLES1Driver : public CNullDriver, public IMaterialRendererServices, public COGLES1ExtensionHandler +{ + friend class COpenGLCoreTexture; + +public: + //! constructor + COGLES1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + + //! destructor + virtual ~COGLES1Driver(); + + virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0, + const SExposedVideoData &videoData = SExposedVideoData(), core::rect *sourceRect = 0) override; + + bool endScene() override; + + //! sets transformation + void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) override; + + struct SHWBufferLink_opengl : public SHWBufferLink + { + SHWBufferLink_opengl(const scene::IMeshBuffer *_MeshBuffer) : + SHWBufferLink(_MeshBuffer), vbo_verticesID(0), vbo_indicesID(0) {} + + GLuint vbo_verticesID; // tmp + GLuint vbo_indicesID; // tmp + + GLuint vbo_verticesSize; // tmp + GLuint vbo_indicesSize; // tmp + }; + + bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + + //! updates hardware buffer if needed + bool updateHardwareBuffer(SHWBufferLink *HWBuffer) override; + + //! Create hardware buffer from mesh + SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer *mb) override; + + //! Delete hardware buffer (only some drivers can) + void deleteHardwareBuffer(SHWBufferLink *HWBuffer) override; + + //! Draw hardware buffer + void drawHardwareBuffer(SHWBufferLink *HWBuffer) override; + + IRenderTarget *addRenderTarget() override; + + //! draws a vertex primitive list + virtual void drawVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override; + + void drawVertexPrimitiveList2d3d(const void *vertices, u32 vertexCount, const void *indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType = EIT_16BIT, bool threed = true); + + //! queries the features of the driver, returns true if feature is available + bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override + { + // return FeatureEnabled[feature] && COGLES1ExtensionHandler::queryFeature(feature); + return COGLES1ExtensionHandler::queryFeature(feature); + } + + //! Sets a material. + void setMaterial(const SMaterial &material) override; + + virtual void draw2DImage(const video::ITexture *texture, const core::position2d &destPos, + const core::rect &sourceRect, const core::rect *clipRect = 0, + SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override; + + virtual void draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect = 0, + const video::SColor *const colors = 0, bool useAlphaChannelOfTexture = false) override; + + virtual void draw2DImage(const video::ITexture *texture, u32 layer, bool flip); + + //! draws a set of 2d images, using a color and the alpha channel of the texture if desired. + virtual void draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect = 0, + SColor color = SColor(255, 255, 255, 255), + bool useAlphaChannelOfTexture = false) override; + + //! draw an 2d rectangle + virtual void draw2DRectangle(SColor color, const core::rect &pos, + const core::rect *clip = 0) override; + + //! Draws an 2d rectangle with a gradient. + virtual void draw2DRectangle(const core::rect &pos, + SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip = 0) override; + + //! Draws a 2d line. + virtual void draw2DLine(const core::position2d &start, + const core::position2d &end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! Draws a 3d line. + virtual void draw3DLine(const core::vector3df &start, + const core::vector3df &end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! Returns the name of the video driver. + const char *getName() const override; + + //! Sets the dynamic ambient light color. + void setAmbientLight(const SColorf &color) override; + + //! sets a viewport + void setViewPort(const core::rect &area) override; + + //! Sets the fog mode. + virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start, + f32 end, f32 density, bool pixelFog, bool rangeFog) override; + + //! Only used internally by the engine + void OnResize(const core::dimension2d &size) override; + + //! Returns type of video driver + E_DRIVER_TYPE getDriverType() const override; + + //! get color format of the current color buffer + ECOLOR_FORMAT getColorFormat() const override; + + //! Returns the transformation set by setTransform + const core::matrix4 &getTransform(E_TRANSFORMATION_STATE state) const override; + + //! Can be called by an IMaterialRenderer to make its work easier. + virtual void setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, + bool resetAllRenderstates) override; + + //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. + virtual void setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates); + + //! Get a vertex shader constant index. + s32 getVertexShaderConstantID(const c8 *name) override; + + //! Get a pixel shader constant index. + s32 getPixelShaderConstantID(const c8 *name) override; + + //! Sets a constant for the vertex shader based on an index. + bool setVertexShaderConstant(s32 index, const f32 *floats, int count) override; + + //! Int interface for the above. + bool setVertexShaderConstant(s32 index, const s32 *ints, int count) override; + + //! Uint interface for the above. + bool setVertexShaderConstant(s32 index, const u32 *ints, int count) override; + + //! Sets a constant for the pixel shader based on an index. + bool setPixelShaderConstant(s32 index, const f32 *floats, int count) override; + + //! Int interface for the above. + bool setPixelShaderConstant(s32 index, const s32 *ints, int count) override; + + //! Uint interface for the above. + bool setPixelShaderConstant(s32 index, const u32 *ints, int count) override; + + //! Adds a new material renderer to the VideoDriver + virtual s32 addHighLevelShaderMaterial(const c8 *vertexShaderProgram, const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, const c8 *pixelShaderProgram, const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, const c8 *geometryShaderProgram, const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, IShaderConstantSetCallBack *callback, E_MATERIAL_TYPE baseMaterial, + s32 userData) override; + + //! Returns pointer to the IGPUProgrammingServices interface. + IGPUProgrammingServices *getGPUProgrammingServices() override; + + //! Returns a pointer to the IVideoDriver interface. + IVideoDriver *getVideoDriver() override; + + //! Returns the maximum amount of primitives + u32 getMaximalPrimitiveCount() const override; + + virtual ITexture *addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override; + + //! Creates a render target texture for a cubemap + ITexture *addRenderTargetTextureCubemap(const irr::u32 sideLen, + const io::path &name, const ECOLOR_FORMAT format) override; + + virtual bool setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), + f32 clearDepth = 1.f, u8 clearStencil = 0) override; + + void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) override; + + //! Returns an image created from the last rendered frame. + IImage *createScreenShot(video::ECOLOR_FORMAT format = video::ECF_UNKNOWN, video::E_RENDER_TARGET target = video::ERT_FRAME_BUFFER) override; + + //! checks if an OpenGL error has happened and prints it (+ some internal code which is usually the line number) + bool testGLError(int code = 0); + + //! Set/unset a clipping plane. + bool setClipPlane(u32 index, const core::plane3df &plane, bool enable = false) override; + + //! Enable/disable a clipping plane. + void enableClipPlane(u32 index, bool enable) override; + + //! Returns the graphics card vendor name. + core::stringc getVendorInfo() override + { + return VendorName; + } + + //! Get the maximal texture size for this driver + core::dimension2du getMaxTextureSize() const override; + + void removeTexture(ITexture *texture) override; + + //! Check if the driver supports creating textures with the given color format + bool queryTextureFormat(ECOLOR_FORMAT format) const override; + + //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass + bool needsTransparentRenderPass(const irr::video::SMaterial &material) const override; + + //! Convert E_BLEND_FACTOR to OpenGL equivalent + GLenum getGLBlend(E_BLEND_FACTOR factor) const; + + //! Get ZBuffer bits. + GLenum getZBufferBits() const; + + bool getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, + GLenum &pixelType, void (**converter)(const void *, s32, void *)) const; + + COGLES1CacheHandler *getCacheHandler() const; + +private: + void uploadClipPlane(u32 index); + + //! inits the opengl-es driver + bool genericDriverInit(const core::dimension2d &screenSize, bool stencilBuffer); + + ITexture *createDeviceDependentTexture(const io::path &name, IImage *image) override; + + ITexture *createDeviceDependentTextureCubemap(const io::path &name, const core::array &image) override; + + //! creates a transposed matrix in supplied GLfloat array to pass to OGLES1 + inline void getGLMatrix(GLfloat gl_matrix[16], const core::matrix4 &m); + inline void getGLTextureMatrix(GLfloat gl_matrix[16], const core::matrix4 &m); + + //! Set GL pipeline to desired texture wrap modes of the material + void setWrapMode(const SMaterial &material); + + //! Get OpenGL wrap enum from Irrlicht enum + GLint getTextureWrapMode(u8 clamp) const; + + //! sets the needed renderstates + void setRenderStates3DMode(); + + //! sets the needed renderstates + void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel); + + void createMaterialRenderers(); + + //! Assign a hardware light to the specified requested light, if any + //! free hardware lights exist. + //! \param[in] lightIndex: the index of the requesting light + void assignHardwareLight(u32 lightIndex); + + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + + COGLES1CacheHandler *CacheHandler; + + core::stringc Name; + core::matrix4 Matrices[ETS_COUNT]; + core::array ColorBuffer; + + //! enumeration for rendering modes such as 2d and 3d for minimizing the switching of renderStates. + enum E_RENDER_MODE + { + ERM_NONE = 0, // no render state has been set yet. + ERM_2D, // 2d drawing rendermode + ERM_3D // 3d rendering mode + }; + + E_RENDER_MODE CurrentRenderMode; + //! bool to make all renderstates reset if set to true. + bool ResetRenderStates; + bool Transformation3DChanged; + u8 AntiAlias; + + SMaterial Material, LastMaterial; + core::array UserClipPlane; + std::vector UserClipPlaneEnabled; + + core::stringc VendorName; + + core::matrix4 TextureFlipMatrix; + + //! Color buffer format + ECOLOR_FORMAT ColorFormat; + + SIrrlichtCreationParameters Params; + + IContextManager *ContextManager; +}; + +} // end namespace video +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_OGLES1_ diff --git a/irr/src/COGLESExtensionHandler.cpp b/irr/src/COGLESExtensionHandler.cpp new file mode 100644 index 000000000..ba2c0c9bf --- /dev/null +++ b/irr/src/COGLESExtensionHandler.cpp @@ -0,0 +1,94 @@ +// Copyright (C) 2008 Christian Stehno +// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt +// 2017 modified by Michael Zeilfelder (unifying extension handlers) +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "COGLESExtensionHandler.h" + +#ifdef _IRR_COMPILE_WITH_OGLES1_ + +#include "irrString.h" +#include "SMaterial.h" +#include "fast_atof.h" + +#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) +#include +#else +#include +#endif + +namespace irr +{ +namespace video +{ + +COGLES1ExtensionHandler::COGLES1ExtensionHandler() : + COGLESCoreExtensionHandler(), + MaxUserClipPlanes(0), MaxLights(0), pGlBlendEquationOES(0), pGlBlendFuncSeparateOES(0), + pGlBindFramebufferOES(0), pGlDeleteFramebuffersOES(0), + pGlGenFramebuffersOES(0), pGlCheckFramebufferStatusOES(0), + pGlFramebufferTexture2DOES(0), pGlGenerateMipmapOES(0) +{ +} + +void COGLES1ExtensionHandler::initExtensions() +{ + getGLVersion(); + + if (Version >= 100) + os::Printer::log("OpenGL ES driver version is 1.1.", ELL_INFORMATION); + else + os::Printer::log("OpenGL ES driver version is 1.0.", ELL_WARNING); + + getGLExtensions(); + + GLint val = 0; + + if (Version > 100 || FeatureAvailable[IRR_GL_IMG_user_clip_plane]) { + glGetIntegerv(GL_MAX_CLIP_PLANES, &val); + MaxUserClipPlanes = static_cast(val); + } + + glGetIntegerv(GL_MAX_LIGHTS, &val); + MaxLights = static_cast(val); + + glGetIntegerv(GL_MAX_TEXTURE_UNITS, &val); + Feature.MaxTextureUnits = static_cast(val); + +#ifdef GL_EXT_texture_filter_anisotropic + if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) { + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val); + MaxAnisotropy = static_cast(val); + } +#endif +#ifdef GL_MAX_ELEMENTS_INDICES + glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val); + MaxIndices = val; +#endif + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val); + MaxTextureSize = static_cast(val); +#ifdef GL_EXT_texture_lod_bias + if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias]) + glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias); +#endif + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); + + Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast(MATERIAL_MAX_TEXTURES)); + Feature.ColorAttachment = 1; + + pGlBlendEquationOES = (PFNGLBLENDEQUATIONOESPROC)eglGetProcAddress("glBlendEquationOES"); + pGlBlendFuncSeparateOES = (PFNGLBLENDFUNCSEPARATEOESPROC)eglGetProcAddress("glBlendFuncSeparateOES"); + pGlBindFramebufferOES = (PFNGLBINDFRAMEBUFFEROESPROC)eglGetProcAddress("glBindFramebufferOES"); + pGlDeleteFramebuffersOES = (PFNGLDELETEFRAMEBUFFERSOESPROC)eglGetProcAddress("glDeleteFramebuffersOES"); + pGlGenFramebuffersOES = (PFNGLGENFRAMEBUFFERSOESPROC)eglGetProcAddress("glGenFramebuffersOES"); + pGlCheckFramebufferStatusOES = (PFNGLCHECKFRAMEBUFFERSTATUSOESPROC)eglGetProcAddress("glCheckFramebufferStatusOES"); + pGlFramebufferTexture2DOES = (PFNGLFRAMEBUFFERTEXTURE2DOESPROC)eglGetProcAddress("glFramebufferTexture2DOES"); + pGlGenerateMipmapOES = (PFNGLGENERATEMIPMAPOESPROC)eglGetProcAddress("glGenerateMipmapOES"); +} + +} // end namespace video +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_OGLES2_ diff --git a/irr/src/COGLESExtensionHandler.h b/irr/src/COGLESExtensionHandler.h new file mode 100644 index 000000000..d9e1ac4bc --- /dev/null +++ b/irr/src/COGLESExtensionHandler.h @@ -0,0 +1,190 @@ +// Copyright (C) 2008 Christian Stehno +// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OGLES1_ + +#include "EDriverFeatures.h" +#include "irrTypes.h" +#include "os.h" + +#include "COGLESCommon.h" + +#include "COGLESCoreExtensionHandler.h" + +namespace irr +{ +namespace video +{ + +class COGLES1ExtensionHandler : public COGLESCoreExtensionHandler +{ +public: + COGLES1ExtensionHandler(); + + void initExtensions(); + + bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const + { + switch (feature) { + case EVDF_RENDER_TO_TARGET: + case EVDF_HARDWARE_TL: + case EVDF_MULTITEXTURE: + case EVDF_BILINEAR_FILTER: + case EVDF_MIP_MAP: + case EVDF_TEXTURE_NSQUARE: + case EVDF_STENCIL_BUFFER: + case EVDF_ALPHA_TO_COVERAGE: + case EVDF_COLOR_MASK: + case EVDF_POLYGON_OFFSET: + case EVDF_TEXTURE_MATRIX: + return true; + case EVDF_TEXTURE_NPOT: + return FeatureAvailable[IRR_GL_APPLE_texture_2D_limited_npot] || FeatureAvailable[IRR_GL_OES_texture_npot]; + case EVDF_MIP_MAP_AUTO_UPDATE: + return Version > 100; + case EVDF_BLEND_OPERATIONS: + return FeatureAvailable[IRR_GL_OES_blend_subtract]; + case EVDF_BLEND_SEPARATE: + return FeatureAvailable[IRR_GL_OES_blend_func_separate]; + case EVDF_FRAMEBUFFER_OBJECT: + return FeatureAvailable[IRR_GL_OES_framebuffer_object]; + case EVDF_VERTEX_BUFFER_OBJECT: + return Version > 100; + default: + return true; + }; + } + + inline void irrGlActiveTexture(GLenum texture) + { + glActiveTexture(texture); + } + + inline void irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, + GLsizei imageSize, const void *data) + { + glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); + } + + inline void irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, + GLenum format, GLsizei imageSize, const void *data) + { + glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); + } + + inline void irrGlUseProgram(GLuint prog) + { + } + + inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer) + { + if (pGlBindFramebufferOES) + pGlBindFramebufferOES(target, framebuffer); + } + + inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) + { + if (pGlDeleteFramebuffersOES) + pGlDeleteFramebuffersOES(n, framebuffers); + } + + inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) + { + if (pGlGenFramebuffersOES) + pGlGenFramebuffersOES(n, framebuffers); + } + + inline GLenum irrGlCheckFramebufferStatus(GLenum target) + { + if (pGlCheckFramebufferStatusOES) + return pGlCheckFramebufferStatusOES(target); + else + return 0; + } + + inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) + { + if (pGlFramebufferTexture2DOES) + pGlFramebufferTexture2DOES(target, attachment, textarget, texture, level); + } + + inline void irrGlGenerateMipmap(GLenum target) + { + if (pGlGenerateMipmapOES) + pGlGenerateMipmapOES(target); + } + + inline void irrGlActiveStencilFace(GLenum face) + { + } + + inline void irrGlDrawBuffer(GLenum mode) + { + } + + inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) + { + } + + inline void irrGlBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) + { + if (pGlBlendFuncSeparateOES) + pGlBlendFuncSeparateOES(srcRGB, dstRGB, srcAlpha, dstAlpha); + } + + inline void irrGlBlendEquation(GLenum mode) + { + if (pGlBlendEquationOES) + pGlBlendEquationOES(mode); + } + + inline void irrGlEnableIndexed(GLenum target, GLuint index) + { + } + + inline void irrGlDisableIndexed(GLenum target, GLuint index) + { + } + + inline void irrGlColorMaskIndexed(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a) + { + } + + inline void irrGlBlendFuncIndexed(GLuint buf, GLenum src, GLenum dst) + { + } + + inline void irrGlBlendFuncSeparateIndexed(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) + { + } + + inline void irrGlBlendEquationIndexed(GLuint buf, GLenum mode) + { + } + + inline void irrGlBlendEquationSeparateIndexed(GLuint buf, GLenum modeRGB, GLenum modeAlpha) + { + } + +protected: + u8 MaxUserClipPlanes; + u8 MaxLights; + + PFNGLBLENDEQUATIONOESPROC pGlBlendEquationOES; + PFNGLBLENDFUNCSEPARATEOESPROC pGlBlendFuncSeparateOES; + PFNGLBINDFRAMEBUFFEROESPROC pGlBindFramebufferOES; + PFNGLDELETEFRAMEBUFFERSOESPROC pGlDeleteFramebuffersOES; + PFNGLGENFRAMEBUFFERSOESPROC pGlGenFramebuffersOES; + PFNGLCHECKFRAMEBUFFERSTATUSOESPROC pGlCheckFramebufferStatusOES; + PFNGLFRAMEBUFFERTEXTURE2DOESPROC pGlFramebufferTexture2DOES; + PFNGLGENERATEMIPMAPOESPROC pGlGenerateMipmapOES; +}; + +} +} + +#endif diff --git a/irr/src/COGLESMaterialRenderer.h b/irr/src/COGLESMaterialRenderer.h new file mode 100644 index 000000000..69d1b81ff --- /dev/null +++ b/irr/src/COGLESMaterialRenderer.h @@ -0,0 +1,286 @@ +// Copyright (C) 2002-2008 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OGLES1_ + +#include "COGLESDriver.h" +#include "IMaterialRenderer.h" + +namespace irr +{ +namespace video +{ + +//! Base class for all internal OGLES1 material renderers +class COGLES1MaterialRenderer : public IMaterialRenderer +{ +public: + //! Constructor + COGLES1MaterialRenderer(video::COGLES1Driver *driver) : + Driver(driver) + { + } + +protected: + video::COGLES1Driver *Driver; +}; + +//! Solid material renderer +class COGLES1MaterialRenderer_SOLID : public COGLES1MaterialRenderer +{ +public: + COGLES1MaterialRenderer_SOLID(video::COGLES1Driver *d) : + COGLES1MaterialRenderer(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) + { + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + if (resetAllRenderstates || (material.MaterialType != lastMaterial.MaterialType)) { + // thanks to Murphy, the following line removed some + // bugs with several OGLES1 implementations. + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + } +}; + +//! Generic Texture Blend +class COGLES1MaterialRenderer_ONETEXTURE_BLEND : public COGLES1MaterialRenderer +{ +public: + COGLES1MaterialRenderer_ONETEXTURE_BLEND(video::COGLES1Driver *d) : + COGLES1MaterialRenderer(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) + { + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + // if (material.MaterialType != lastMaterial.MaterialType || + // material.MaterialTypeParam != lastMaterial.MaterialTypeParam || + // resetAllRenderstates) + { + E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + Driver->getCacheHandler()->setBlend(true); + + if (Driver->queryFeature(EVDF_BLEND_SEPARATE)) { + Driver->getCacheHandler()->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), + Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); + } else { + Driver->getCacheHandler()->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact)); + } + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS); + + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, (f32)modulate); + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.f); + + if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || + textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) { + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); + + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); + } + } + } + + virtual void OnUnsetMaterial() + { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.f); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS); + + Driver->getCacheHandler()->setBlend(false); + glDisable(GL_ALPHA_TEST); + } + + //! Returns if the material is transparent. + /** Is not always transparent, but mostly. */ + virtual bool isTransparent() const + { + return true; + } + +private: + u32 getGLBlend(E_BLEND_FACTOR factor) const + { + u32 r = 0; + switch (factor) { + case EBF_ZERO: + r = GL_ZERO; + break; + case EBF_ONE: + r = GL_ONE; + break; + case EBF_DST_COLOR: + r = GL_DST_COLOR; + break; + case EBF_ONE_MINUS_DST_COLOR: + r = GL_ONE_MINUS_DST_COLOR; + break; + case EBF_SRC_COLOR: + r = GL_SRC_COLOR; + break; + case EBF_ONE_MINUS_SRC_COLOR: + r = GL_ONE_MINUS_SRC_COLOR; + break; + case EBF_SRC_ALPHA: + r = GL_SRC_ALPHA; + break; + case EBF_ONE_MINUS_SRC_ALPHA: + r = GL_ONE_MINUS_SRC_ALPHA; + break; + case EBF_DST_ALPHA: + r = GL_DST_ALPHA; + break; + case EBF_ONE_MINUS_DST_ALPHA: + r = GL_ONE_MINUS_DST_ALPHA; + break; + case EBF_SRC_ALPHA_SATURATE: + r = GL_SRC_ALPHA_SATURATE; + break; + } + return r; + } +}; + +//! Transparent vertex alpha material renderer +class COGLES1MaterialRenderer_TRANSPARENT_VERTEX_ALPHA : public COGLES1MaterialRenderer +{ +public: + COGLES1MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(video::COGLES1Driver *d) : + COGLES1MaterialRenderer(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) + { + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + Driver->getCacheHandler()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + Driver->getCacheHandler()->setBlend(true); + + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE); + } + } + + virtual void OnUnsetMaterial() + { + // default values + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS); + + Driver->getCacheHandler()->setBlend(false); + } + + //! Returns if the material is transparent. + virtual bool isTransparent() const + { + return true; + } +}; + +//! Transparent alpha channel material renderer +class COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public COGLES1MaterialRenderer +{ +public: + COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(video::COGLES1Driver *d) : + COGLES1MaterialRenderer(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) + { + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + Driver->getCacheHandler()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + Driver->getCacheHandler()->setBlend(true); + + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates || material.MaterialTypeParam != lastMaterial.MaterialTypeParam) { + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); + + glEnable(GL_ALPHA_TEST); + + glAlphaFunc(GL_GREATER, material.MaterialTypeParam); + } + } + + virtual void OnUnsetMaterial() + { + glDisable(GL_ALPHA_TEST); + Driver->getCacheHandler()->setBlend(false); + } + + //! Returns if the material is transparent. + virtual bool isTransparent() const + { + return true; + } +}; + +//! Transparent alpha channel material renderer +class COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF : public COGLES1MaterialRenderer +{ +public: + COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(video::COGLES1Driver *d) : + COGLES1MaterialRenderer(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) + { + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.5f); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + } + + virtual void OnUnsetMaterial() + { + glDisable(GL_ALPHA_TEST); + } + + //! Returns if the material is transparent. + virtual bool isTransparent() const + { + return false; // this material is not really transparent because it does no blending. + } +}; + +} // end namespace video +} // end namespace irr + +#endif diff --git a/irr/src/COSOperator.cpp b/irr/src/COSOperator.cpp new file mode 100644 index 000000000..b26463799 --- /dev/null +++ b/irr/src/COSOperator.cpp @@ -0,0 +1,268 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "COSOperator.h" + +#ifdef _IRR_WINDOWS_API_ +#include +#else +#include +#include +#ifndef _IRR_ANDROID_PLATFORM_ +#include +#ifdef _IRR_OSX_PLATFORM_ +#include +#endif +#endif +#endif + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#include +#include +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) +#include "CIrrDeviceLinux.h" +#endif +#if defined(_IRR_COMPILE_WITH_OSX_DEVICE_) +#import +#endif + +#include "fast_atof.h" + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +static const bool sdl_supports_primary_selection = [] { +#if SDL_VERSION_ATLEAST(2, 25, 0) + SDL_version linked_version; + SDL_GetVersion(&linked_version); + return (linked_version.major == 2 && linked_version.minor >= 25) || linked_version.major > 2; +#else + return false; +#endif +}(); +#endif + +namespace irr +{ + +#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) +// constructor linux +COSOperator::COSOperator(const core::stringc &osVersion, CIrrDeviceLinux *device) : + OperatingSystem(osVersion), IrrDeviceLinux(device) +{ +} +#endif + +// constructor +COSOperator::COSOperator(const core::stringc &osVersion) : + OperatingSystem(osVersion) +{ +#ifdef _DEBUG + setDebugName("COSOperator"); +#endif +} + +COSOperator::~COSOperator() +{ +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + SDL_free(ClipboardSelectionText); + SDL_free(PrimarySelectionText); +#endif +} + +//! returns the current operating system version as string. +const core::stringc &COSOperator::getOperatingSystemVersion() const +{ + return OperatingSystem; +} + +//! copies text to the clipboard +void COSOperator::copyToClipboard(const c8 *text) const +{ + if (strlen(text) == 0) + return; + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + SDL_SetClipboardText(text); + +#elif defined(_IRR_WINDOWS_API_) + if (!OpenClipboard(NULL) || text == 0) + return; + + EmptyClipboard(); + + core::stringw tempbuffer; + core::utf8ToWString(tempbuffer, text); + const u32 size = (tempbuffer.size() + 1) * sizeof(wchar_t); + + HGLOBAL clipbuffer; + void *buffer; + + clipbuffer = GlobalAlloc(GMEM_MOVEABLE, size); + buffer = GlobalLock(clipbuffer); + + memcpy(buffer, tempbuffer.c_str(), size); + + GlobalUnlock(clipbuffer); + SetClipboardData(CF_UNICODETEXT, clipbuffer); + CloseClipboard(); + +#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) + NSString *str = nil; + NSPasteboard *board = nil; + + if ((text != NULL) && (strlen(text) > 0)) { + str = [NSString stringWithCString:text encoding:NSUTF8StringEncoding]; + board = [NSPasteboard generalPasteboard]; + [board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp]; + [board setString:str forType:NSStringPboardType]; + } + +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if (IrrDeviceLinux) + IrrDeviceLinux->copyToClipboard(text); +#endif +} + +//! copies text to the primary selection +void COSOperator::copyToPrimarySelection(const c8 *text) const +{ + if (strlen(text) == 0) + return; + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#if SDL_VERSION_ATLEAST(2, 25, 0) + if (sdl_supports_primary_selection) + SDL_SetPrimarySelectionText(text); +#endif + +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if (IrrDeviceLinux) + IrrDeviceLinux->copyToPrimarySelection(text); +#endif +} + +//! gets text from the clipboard +const c8 *COSOperator::getTextFromClipboard() const +{ +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + SDL_free(ClipboardSelectionText); + ClipboardSelectionText = SDL_GetClipboardText(); + return ClipboardSelectionText; + +#elif defined(_IRR_WINDOWS_API_) + if (!OpenClipboard(NULL)) + return 0; + + HANDLE hData = GetClipboardData(CF_UNICODETEXT); + if (hData == NULL) // Probably not in Unicode text format + return 0; + + wchar_t *buffer = (wchar_t *)GlobalLock(hData); + + core::wStringToUTF8(ClipboardBuf, buffer); + + GlobalUnlock(hData); + CloseClipboard(); + + return ClipboardBuf.c_str(); + +#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) + NSString *str = nil; + NSPasteboard *board = nil; + char *result = 0; + + board = [NSPasteboard generalPasteboard]; + str = [board stringForType:NSStringPboardType]; + + if (str != nil) + result = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding]; + + return (result); + +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if (IrrDeviceLinux) + return IrrDeviceLinux->getTextFromClipboard(); + return 0; + +#else + + return 0; +#endif +} + +//! gets text from the primary selection +const c8 *COSOperator::getTextFromPrimarySelection() const +{ +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#if SDL_VERSION_ATLEAST(2, 25, 0) + if (sdl_supports_primary_selection) { + SDL_free(PrimarySelectionText); + PrimarySelectionText = SDL_GetPrimarySelectionText(); + return PrimarySelectionText; + } +#endif + return 0; + +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if (IrrDeviceLinux) + return IrrDeviceLinux->getTextFromPrimarySelection(); + return 0; + +#else + + return 0; +#endif +} + +bool COSOperator::getSystemMemory(u32 *Total, u32 *Avail) const +{ +#if defined(_IRR_WINDOWS_API_) + + MEMORYSTATUSEX MemoryStatusEx; + MemoryStatusEx.dwLength = sizeof(MEMORYSTATUSEX); + + // cannot fail + GlobalMemoryStatusEx(&MemoryStatusEx); + + if (Total) + *Total = (u32)(MemoryStatusEx.ullTotalPhys >> 10); + if (Avail) + *Avail = (u32)(MemoryStatusEx.ullAvailPhys >> 10); + return true; + +#elif defined(_IRR_POSIX_API_) && defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES) + long ps = sysconf(_SC_PAGESIZE); + long pp = sysconf(_SC_PHYS_PAGES); + long ap = sysconf(_SC_AVPHYS_PAGES); + + if (ps == -1 || (Total && pp == -1) || (Avail && ap == -1)) + return false; + + if (Total) + *Total = (u32)((pp >> 10) * ps); + if (Avail) + *Avail = (u32)((ap >> 10) * ps); + return true; +#elif defined(_IRR_OSX_PLATFORM_) + int mib[2]; + int64_t physical_memory; + size_t length; + + // Get the Physical memory size + mib[0] = CTL_HW; + mib[1] = HW_MEMSIZE; + length = sizeof(int64_t); + sysctl(mib, 2, &physical_memory, &length, NULL, 0); + + if (Total) + *Total = (u32)(physical_memory >> 10); + if (Avail) + *Avail = (u32)(physical_memory >> 10); // we don't know better + return true; +#else + // TODO: implement for others + return false; +#endif +} + +} // end namespace diff --git a/irr/src/COSOperator.h b/irr/src/COSOperator.h new file mode 100644 index 000000000..c1059bffc --- /dev/null +++ b/irr/src/COSOperator.h @@ -0,0 +1,74 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IOSOperator.h" + +namespace irr +{ + +class CIrrDeviceLinux; + +//! The OSOperator provides OS-specific methods and information. +class COSOperator : public IOSOperator +{ +public: + // constructor +#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) + COSOperator(const core::stringc &osversion, CIrrDeviceLinux *device); +#endif + COSOperator(const core::stringc &osversion); + + ~COSOperator(); + + COSOperator(const COSOperator &) = delete; + COSOperator &operator=(const COSOperator &) = delete; + + //! Get the current OS version as string. + const core::stringc &getOperatingSystemVersion() const override; + + //! Copies text to the clipboard + //! \param text: text in utf-8 + void copyToClipboard(const c8 *text) const override; + + //! Copies text to the primary selection + //! This is a no-op on some platforms. + //! \param text: text in utf-8 + void copyToPrimarySelection(const c8 *text) const override; + + //! Get text from the clipboard + //! \return Returns 0 if no string is in there, otherwise an utf-8 string. + const c8 *getTextFromClipboard() const override; + + //! Get text from the primary selection + //! This is a no-op on some platforms. + //! \return Returns 0 if no string is in there, otherwise an utf-8 string. + const c8 *getTextFromPrimarySelection() const override; + + //! Get the total and available system RAM + /** \param totalBytes: will contain the total system memory in Kilobytes (1024 B) + \param availableBytes: will contain the available memory in Kilobytes (1024 B) + \return True if successful, false if not */ + bool getSystemMemory(u32 *Total, u32 *Avail) const override; + +private: + core::stringc OperatingSystem; + +#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) + CIrrDeviceLinux *IrrDeviceLinux; +#endif + +#ifdef _IRR_WINDOWS_API_ + mutable core::stringc ClipboardBuf; +#endif + +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + // These need to be freed with SDL_free + mutable char *ClipboardSelectionText = nullptr; + mutable char *PrimarySelectionText = nullptr; +#endif +}; + +} // end namespace diff --git a/irr/src/COpenGLCacheHandler.cpp b/irr/src/COpenGLCacheHandler.cpp new file mode 100644 index 000000000..577967c56 --- /dev/null +++ b/irr/src/COpenGLCacheHandler.cpp @@ -0,0 +1,123 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "COpenGLCacheHandler.h" + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "COpenGLDriver.h" + +namespace irr +{ +namespace video +{ + +/* COpenGLCacheHandler */ + +COpenGLCacheHandler::COpenGLCacheHandler(COpenGLDriver *driver) : + COpenGLCoreCacheHandler(driver), AlphaMode(GL_ALWAYS), AlphaRef(0.f), AlphaTest(false), + MatrixMode(GL_MODELVIEW), ClientActiveTexture(GL_TEXTURE0), ClientStateVertex(false), + ClientStateNormal(false), ClientStateColor(false), ClientStateTexCoord0(false) +{ + // Initial OpenGL values from specification. + + glAlphaFunc(AlphaMode, AlphaRef); + glDisable(GL_ALPHA_TEST); + + glMatrixMode(MatrixMode); + + Driver->irrGlClientActiveTexture(ClientActiveTexture); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); +} + +COpenGLCacheHandler::~COpenGLCacheHandler() +{ +} + +void COpenGLCacheHandler::setAlphaFunc(GLenum mode, GLclampf ref) +{ + if (AlphaMode != mode || AlphaRef != ref) { + glAlphaFunc(mode, ref); + + AlphaMode = mode; + AlphaRef = ref; + } +} + +void COpenGLCacheHandler::setAlphaTest(bool enable) +{ + if (AlphaTest != enable) { + if (enable) + glEnable(GL_ALPHA_TEST); + else + glDisable(GL_ALPHA_TEST); + AlphaTest = enable; + } +} + +void COpenGLCacheHandler::setClientState(bool vertex, bool normal, bool color, bool texCoord0) +{ + if (ClientStateVertex != vertex) { + if (vertex) + glEnableClientState(GL_VERTEX_ARRAY); + else + glDisableClientState(GL_VERTEX_ARRAY); + + ClientStateVertex = vertex; + } + + if (ClientStateNormal != normal) { + if (normal) + glEnableClientState(GL_NORMAL_ARRAY); + else + glDisableClientState(GL_NORMAL_ARRAY); + + ClientStateNormal = normal; + } + + if (ClientStateColor != color) { + if (color) + glEnableClientState(GL_COLOR_ARRAY); + else + glDisableClientState(GL_COLOR_ARRAY); + + ClientStateColor = color; + } + + if (ClientStateTexCoord0 != texCoord0) { + setClientActiveTexture(GL_TEXTURE0_ARB); + + if (texCoord0) + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + else + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + ClientStateTexCoord0 = texCoord0; + } +} + +void COpenGLCacheHandler::setMatrixMode(GLenum mode) +{ + if (MatrixMode != mode) { + glMatrixMode(mode); + MatrixMode = mode; + } +} + +void COpenGLCacheHandler::setClientActiveTexture(GLenum texture) +{ + if (ClientActiveTexture != texture) { + Driver->irrGlClientActiveTexture(texture); + ClientActiveTexture = texture; + } +} + +} // end namespace +} // end namespace + +#endif // _IRR_COMPILE_WITH_OPENGL_ diff --git a/irr/src/COpenGLCacheHandler.h b/irr/src/COpenGLCacheHandler.h new file mode 100644 index 000000000..968e452d7 --- /dev/null +++ b/irr/src/COpenGLCacheHandler.h @@ -0,0 +1,62 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "COpenGLCommon.h" + +#include "COpenGLCoreFeature.h" +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreCacheHandler.h" + +namespace irr +{ +namespace video +{ + +class COpenGLCacheHandler : public COpenGLCoreCacheHandler +{ +public: + COpenGLCacheHandler(COpenGLDriver *driver); + virtual ~COpenGLCacheHandler(); + + // Alpha calls. + + void setAlphaFunc(GLenum mode, GLclampf ref); + + void setAlphaTest(bool enable); + + // Client state calls. + + void setClientState(bool vertex, bool normal, bool color, bool texCoord0); + + // Matrix calls. + + void setMatrixMode(GLenum mode); + + // Texture calls. + + void setClientActiveTexture(GLenum texture); + +protected: + GLenum AlphaMode; + GLclampf AlphaRef; + bool AlphaTest; + + GLenum MatrixMode; + + GLenum ClientActiveTexture; + + bool ClientStateVertex; + bool ClientStateNormal; + bool ClientStateColor; + bool ClientStateTexCoord0; +}; + +} // end namespace video +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_OPENGL_ diff --git a/irr/src/COpenGLCommon.h b/irr/src/COpenGLCommon.h new file mode 100644 index 000000000..3b43b35a4 --- /dev/null +++ b/irr/src/COpenGLCommon.h @@ -0,0 +1,48 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && defined(IRR_PREFER_SDL_GL_HEADER) +#include +#include +#else +#include "vendor/gl.h" +#endif + +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT + +// To check if this header is in the current compile unit (different GL driver implementations use different "GLCommon" headers in Irrlicht) +#define IRR_COMPILE_GL_COMMON + +namespace irr +{ +namespace video +{ + +// Forward declarations. + +class COpenGLCoreFeature; + +template +class COpenGLCoreTexture; + +template +class COpenGLCoreRenderTarget; + +template +class COpenGLCoreCacheHandler; + +class COpenGLDriver; +typedef COpenGLCoreTexture COpenGLTexture; +typedef COpenGLCoreRenderTarget COpenGLRenderTarget; +class COpenGLCacheHandler; + +} +} + +#endif diff --git a/irr/src/COpenGLCoreCacheHandler.h b/irr/src/COpenGLCoreCacheHandler.h new file mode 100644 index 000000000..ae3661313 --- /dev/null +++ b/irr/src/COpenGLCoreCacheHandler.h @@ -0,0 +1,595 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "SMaterial.h" +#include "ITexture.h" + +#include "mt_opengl.h" + +namespace irr +{ +namespace video +{ + +enum ESetTextureActive +{ + EST_ACTIVE_ALWAYS, // texture unit always active after set call + EST_ACTIVE_ON_CHANGE // texture unit only active after call when texture changed in cache +}; + +template +class COpenGLCoreCacheHandler +{ + class STextureCache + { + public: + STextureCache(COpenGLCoreCacheHandler &cacheHandler, E_DRIVER_TYPE driverType, u32 textureCount) : + CacheHandler(cacheHandler), DriverType(driverType), TextureCount(textureCount) + { + for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) { + Texture[i] = 0; + } + } + + ~STextureCache() + { + clear(); + } + + const TOpenGLTexture *operator[](int index) const + { + if (static_cast(index) < MATERIAL_MAX_TEXTURES) + return Texture[static_cast(index)]; + + return 0; + } + + const TOpenGLTexture *get(u32 index) const + { + if (index < MATERIAL_MAX_TEXTURES) + return Texture[index]; + + return 0; + } + + bool set(u32 index, const ITexture *texture, ESetTextureActive esa = EST_ACTIVE_ALWAYS) + { + bool status = false; + + E_DRIVER_TYPE type = DriverType; + + if (index < MATERIAL_MAX_TEXTURES && index < TextureCount) { + if (esa == EST_ACTIVE_ALWAYS) + CacheHandler.setActiveTexture(GL_TEXTURE0 + index); + + const TOpenGLTexture *prevTexture = Texture[index]; + + if (texture != prevTexture) { + if (esa == EST_ACTIVE_ON_CHANGE) + CacheHandler.setActiveTexture(GL_TEXTURE0 + index); + + if (texture) { + type = texture->getDriverType(); + + if (type == DriverType) { + texture->grab(); + + const TOpenGLTexture *curTexture = static_cast(texture); + const GLenum curTextureType = curTexture->getOpenGLTextureType(); + const GLenum prevTextureType = (prevTexture) ? prevTexture->getOpenGLTextureType() : curTextureType; + + if (curTextureType != prevTextureType) { + GL.BindTexture(prevTextureType, 0); + +#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) + GL.Disable(prevTextureType); + GL.Enable(curTextureType); +#endif + } +#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) + else if (!prevTexture) + GL.Enable(curTextureType); +#endif + + GL.BindTexture(curTextureType, static_cast(texture)->getOpenGLTextureName()); + } else { + texture = 0; + + os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR); + os::Printer::log("Texture type", irr::core::stringc((int)type), ELL_ERROR); + os::Printer::log("Driver (or cache handler) type", irr::core::stringc((int)DriverType), ELL_ERROR); + } + } + + if (!texture && prevTexture) { + const GLenum prevTextureType = prevTexture->getOpenGLTextureType(); + + GL.BindTexture(prevTextureType, 0); + +#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) + GL.Disable(prevTextureType); +#endif + } + + Texture[index] = static_cast(texture); + + if (prevTexture) + prevTexture->drop(); + } + + status = true; + } + + return (status && type == DriverType); + } + + void remove(ITexture *texture) + { + if (!texture) + return; + + for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) { + if (Texture[i] == texture) { + Texture[i] = 0; + + texture->drop(); + } + } + } + + void clear() + { + for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) { + if (Texture[i]) { + const TOpenGLTexture *prevTexture = Texture[i]; + + Texture[i] = 0; + + prevTexture->drop(); + } + } + } + + private: + COpenGLCoreCacheHandler &CacheHandler; + + E_DRIVER_TYPE DriverType; + + const TOpenGLTexture *Texture[MATERIAL_MAX_TEXTURES]; + u32 TextureCount; + }; + +public: + COpenGLCoreCacheHandler(TOpenGLDriver *driver) : + Driver(driver), +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4355) // Warning: "'this' : used in base member initializer list. ". It's OK, we don't use the reference in STextureCache constructor. +#endif + TextureCache(STextureCache(*this, driver->getDriverType(), driver->getFeature().MaxTextureUnits)), +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + FrameBufferCount(0), BlendEquation(0), BlendSourceRGB(0), + BlendDestinationRGB(0), BlendSourceAlpha(0), BlendDestinationAlpha(0), Blend(0), BlendEquationInvalid(false), BlendFuncInvalid(false), BlendInvalid(false), + ColorMask(0), ColorMaskInvalid(false), CullFaceMode(GL_BACK), CullFace(false), DepthFunc(GL_LESS), DepthMask(true), DepthTest(false), FrameBufferID(0), + ProgramID(0), ActiveTexture(GL_TEXTURE0), ViewportX(0), ViewportY(0) + { + const COpenGLCoreFeature &feature = Driver->getFeature(); + + FrameBufferCount = core::max_(static_cast(1), static_cast(feature.MultipleRenderTarget)); + + BlendEquation = new GLenum[FrameBufferCount]; + BlendSourceRGB = new GLenum[FrameBufferCount]; + BlendDestinationRGB = new GLenum[FrameBufferCount]; + BlendSourceAlpha = new GLenum[FrameBufferCount]; + BlendDestinationAlpha = new GLenum[FrameBufferCount]; + Blend = new bool[FrameBufferCount]; + ColorMask = new u8[FrameBufferCount]; + + // Initial OpenGL values from specification. + + if (feature.BlendOperation) { + Driver->irrGlBlendEquation(GL_FUNC_ADD); + } + + for (u32 i = 0; i < FrameBufferCount; ++i) { + BlendEquation[i] = GL_FUNC_ADD; + + BlendSourceRGB[i] = GL_ONE; + BlendDestinationRGB[i] = GL_ZERO; + BlendSourceAlpha[i] = GL_ONE; + BlendDestinationAlpha[i] = GL_ZERO; + + Blend[i] = false; + ColorMask[i] = ECP_ALL; + } + + GL.BlendFunc(GL_ONE, GL_ZERO); + GL.Disable(GL_BLEND); + + GL.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + GL.CullFace(CullFaceMode); + GL.Disable(GL_CULL_FACE); + + GL.DepthFunc(DepthFunc); + GL.DepthMask(GL_TRUE); + GL.Disable(GL_DEPTH_TEST); + + Driver->irrGlActiveTexture(ActiveTexture); + +#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) + GL.Disable(GL_TEXTURE_2D); +#endif + + const core::dimension2d ScreenSize = Driver->getScreenSize(); + ViewportWidth = ScreenSize.Width; + ViewportHeight = ScreenSize.Height; + GL.Viewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight); + } + + virtual ~COpenGLCoreCacheHandler() + { + delete[] BlendEquation; + delete[] BlendSourceRGB; + delete[] BlendDestinationRGB; + delete[] BlendSourceAlpha; + delete[] BlendDestinationAlpha; + delete[] Blend; + + delete[] ColorMask; + } + + E_DRIVER_TYPE getDriverType() const + { + return Driver->getDriverType(); + } + + STextureCache &getTextureCache() + { + return TextureCache; + } + + // Blending calls. + + void setBlendEquation(GLenum mode) + { + if (BlendEquation[0] != mode || BlendEquationInvalid) { + Driver->irrGlBlendEquation(mode); + + for (GLuint i = 0; i < FrameBufferCount; ++i) + BlendEquation[i] = mode; + + BlendEquationInvalid = false; + } + } + + void setBlendEquationIndexed(GLuint index, GLenum mode) + { + if (index < FrameBufferCount && BlendEquation[index] != mode) { + Driver->irrGlBlendEquationIndexed(index, mode); + + BlendEquation[index] = mode; + BlendEquationInvalid = true; + } + } + + void setBlendFunc(GLenum source, GLenum destination) + { + if (BlendSourceRGB[0] != source || BlendDestinationRGB[0] != destination || + BlendSourceAlpha[0] != source || BlendDestinationAlpha[0] != destination || + BlendFuncInvalid) { + GL.BlendFunc(source, destination); + + for (GLuint i = 0; i < FrameBufferCount; ++i) { + BlendSourceRGB[i] = source; + BlendDestinationRGB[i] = destination; + BlendSourceAlpha[i] = source; + BlendDestinationAlpha[i] = destination; + } + + BlendFuncInvalid = false; + } + } + + void setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha) + { + if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha) { + if (BlendSourceRGB[0] != sourceRGB || BlendDestinationRGB[0] != destinationRGB || + BlendSourceAlpha[0] != sourceAlpha || BlendDestinationAlpha[0] != destinationAlpha || + BlendFuncInvalid) { + Driver->irrGlBlendFuncSeparate(sourceRGB, destinationRGB, sourceAlpha, destinationAlpha); + + for (GLuint i = 0; i < FrameBufferCount; ++i) { + BlendSourceRGB[i] = sourceRGB; + BlendDestinationRGB[i] = destinationRGB; + BlendSourceAlpha[i] = sourceAlpha; + BlendDestinationAlpha[i] = destinationAlpha; + } + + BlendFuncInvalid = false; + } + } else { + setBlendFunc(sourceRGB, destinationRGB); + } + } + + void setBlendFuncIndexed(GLuint index, GLenum source, GLenum destination) + { + if (index < FrameBufferCount && (BlendSourceRGB[index] != source || BlendDestinationRGB[index] != destination || + BlendSourceAlpha[index] != source || BlendDestinationAlpha[index] != destination)) { + Driver->irrGlBlendFuncIndexed(index, source, destination); + + BlendSourceRGB[index] = source; + BlendDestinationRGB[index] = destination; + BlendSourceAlpha[index] = source; + BlendDestinationAlpha[index] = destination; + BlendFuncInvalid = true; + } + } + + void setBlendFuncSeparateIndexed(GLuint index, GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha) + { + if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha) { + if (index < FrameBufferCount && (BlendSourceRGB[index] != sourceRGB || BlendDestinationRGB[index] != destinationRGB || + BlendSourceAlpha[index] != sourceAlpha || BlendDestinationAlpha[index] != destinationAlpha)) { + Driver->irrGlBlendFuncSeparateIndexed(index, sourceRGB, destinationRGB, sourceAlpha, destinationAlpha); + + BlendSourceRGB[index] = sourceRGB; + BlendDestinationRGB[index] = destinationRGB; + BlendSourceAlpha[index] = sourceAlpha; + BlendDestinationAlpha[index] = destinationAlpha; + BlendFuncInvalid = true; + } + } else { + setBlendFuncIndexed(index, sourceRGB, destinationRGB); + } + } + + void setBlend(bool enable) + { + if (Blend[0] != enable || BlendInvalid) { + if (enable) + GL.Enable(GL_BLEND); + else + GL.Disable(GL_BLEND); + + for (GLuint i = 0; i < FrameBufferCount; ++i) + Blend[i] = enable; + + BlendInvalid = false; + } + } + + void setBlendIndexed(GLuint index, bool enable) + { + if (index < FrameBufferCount && Blend[index] != enable) { + if (enable) + Driver->irrGlEnableIndexed(GL_BLEND, index); + else + Driver->irrGlDisableIndexed(GL_BLEND, index); + + Blend[index] = enable; + BlendInvalid = true; + } + } + + // Color Mask. + + void getColorMask(u8 &mask) + { + mask = ColorMask[0]; + } + + void setColorMask(u8 mask) + { + if (ColorMask[0] != mask || ColorMaskInvalid) { + GL.ColorMask((mask & ECP_RED) ? GL_TRUE : GL_FALSE, (mask & ECP_GREEN) ? GL_TRUE : GL_FALSE, (mask & ECP_BLUE) ? GL_TRUE : GL_FALSE, (mask & ECP_ALPHA) ? GL_TRUE : GL_FALSE); + + for (GLuint i = 0; i < FrameBufferCount; ++i) + ColorMask[i] = mask; + + ColorMaskInvalid = false; + } + } + + void setColorMaskIndexed(GLuint index, u8 mask) + { + if (index < FrameBufferCount && ColorMask[index] != mask) { + Driver->irrGlColorMaskIndexed(index, (mask & ECP_RED) ? GL_TRUE : GL_FALSE, (mask & ECP_GREEN) ? GL_TRUE : GL_FALSE, (mask & ECP_BLUE) ? GL_TRUE : GL_FALSE, (mask & ECP_ALPHA) ? GL_TRUE : GL_FALSE); + + ColorMask[index] = mask; + ColorMaskInvalid = true; + } + } + + // Cull face calls. + + void setCullFaceFunc(GLenum mode) + { + if (CullFaceMode != mode) { + GL.CullFace(mode); + CullFaceMode = mode; + } + } + + void setCullFace(bool enable) + { + if (CullFace != enable) { + if (enable) + GL.Enable(GL_CULL_FACE); + else + GL.Disable(GL_CULL_FACE); + + CullFace = enable; + } + } + + // Depth calls. + + void setDepthFunc(GLenum mode) + { + if (DepthFunc != mode) { + GL.DepthFunc(mode); + DepthFunc = mode; + } + } + + void getDepthMask(bool &depth) + { + depth = DepthMask; + } + + void setDepthMask(bool enable) + { + if (DepthMask != enable) { + if (enable) + GL.DepthMask(GL_TRUE); + else + GL.DepthMask(GL_FALSE); + + DepthMask = enable; + } + } + + void getDepthTest(bool &enable) + { + enable = DepthTest; + } + + void setDepthTest(bool enable) + { + if (DepthTest != enable) { + if (enable) + GL.Enable(GL_DEPTH_TEST); + else + GL.Disable(GL_DEPTH_TEST); + + DepthTest = enable; + } + } + + // FBO calls. + + void getFBO(GLuint &frameBufferID) const + { + frameBufferID = FrameBufferID; + } + + void setFBO(GLuint frameBufferID) + { + if (FrameBufferID != frameBufferID) { + Driver->irrGlBindFramebuffer(GL_FRAMEBUFFER, frameBufferID); + FrameBufferID = frameBufferID; + } + } + + // Shaders calls. + + void getProgram(GLuint &programID) const + { + programID = ProgramID; + } + + void setProgram(GLuint programID) + { + if (ProgramID != programID) { + Driver->irrGlUseProgram(programID); + ProgramID = programID; + } + } + + // Texture calls. + + void getActiveTexture(GLenum &texture) const + { + texture = ActiveTexture; + } + + void setActiveTexture(GLenum texture) + { + if (ActiveTexture != texture) { + Driver->irrGlActiveTexture(texture); + ActiveTexture = texture; + } + } + + // Viewport calls. + + void getViewport(GLint &viewportX, GLint &viewportY, GLsizei &viewportWidth, GLsizei &viewportHeight) const + { + viewportX = ViewportX; + viewportY = ViewportY; + viewportWidth = ViewportWidth; + viewportHeight = ViewportHeight; + } + + void setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight) + { + if (ViewportX != viewportX || ViewportY != viewportY || ViewportWidth != viewportWidth || ViewportHeight != viewportHeight) { + GL.Viewport(viewportX, viewportY, viewportWidth, viewportHeight); + ViewportX = viewportX; + ViewportY = viewportY; + ViewportWidth = viewportWidth; + ViewportHeight = viewportHeight; + } + } + + //! Compare material to current cache and update it when there are differences + // Some material renderers do change the cache beyond the original material settings + // This corrects the material to represent the current cache state again. + void correctCacheMaterial(irr::video::SMaterial &material) + { + // Fix textures which got removed + for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) { + if (material.TextureLayers[i].Texture && !TextureCache[i]) { + material.TextureLayers[i].Texture = 0; + } + } + } + +protected: + TOpenGLDriver *Driver; + + STextureCache TextureCache; + + GLuint FrameBufferCount; + + GLenum *BlendEquation; + GLenum *BlendSourceRGB; + GLenum *BlendDestinationRGB; + GLenum *BlendSourceAlpha; + GLenum *BlendDestinationAlpha; + bool *Blend; + bool BlendEquationInvalid; + bool BlendFuncInvalid; + bool BlendInvalid; + + u8 *ColorMask; + bool ColorMaskInvalid; + + GLenum CullFaceMode; + bool CullFace; + + GLenum DepthFunc; + bool DepthMask; + bool DepthTest; + + GLuint FrameBufferID; + + GLuint ProgramID; + + GLenum ActiveTexture; + + GLint ViewportX; + GLint ViewportY; + GLsizei ViewportWidth; + GLsizei ViewportHeight; +}; + +} +} diff --git a/irr/src/COpenGLCoreFeature.h b/irr/src/COpenGLCoreFeature.h new file mode 100644 index 000000000..dc3d40e04 --- /dev/null +++ b/irr/src/COpenGLCoreFeature.h @@ -0,0 +1,34 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" + +namespace irr +{ +namespace video +{ + +class COpenGLCoreFeature +{ +public: + COpenGLCoreFeature() : + BlendOperation(false), ColorAttachment(0), MultipleRenderTarget(0), MaxTextureUnits(1) + { + } + + virtual ~COpenGLCoreFeature() + { + } + + bool BlendOperation; + + u8 ColorAttachment; + u8 MultipleRenderTarget; + u8 MaxTextureUnits; +}; + +} +} diff --git a/irr/src/COpenGLCoreRenderTarget.h b/irr/src/COpenGLCoreRenderTarget.h new file mode 100644 index 000000000..105cdd702 --- /dev/null +++ b/irr/src/COpenGLCoreRenderTarget.h @@ -0,0 +1,353 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IRenderTarget.h" + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_FORMATS +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT +#endif + +namespace irr +{ +namespace video +{ + +template +class COpenGLCoreRenderTarget : public IRenderTarget +{ +public: + COpenGLCoreRenderTarget(TOpenGLDriver *driver) : + AssignedDepth(false), AssignedStencil(false), RequestTextureUpdate(false), RequestDepthStencilUpdate(false), + BufferID(0), ColorAttachment(0), MultipleRenderTarget(0), Driver(driver) + { +#ifdef _DEBUG + setDebugName("COpenGLCoreRenderTarget"); +#endif + + DriverType = Driver->getDriverType(); + + Size = Driver->getScreenSize(); + + ColorAttachment = Driver->getFeature().ColorAttachment; + MultipleRenderTarget = Driver->getFeature().MultipleRenderTarget; + + if (ColorAttachment > 0) + Driver->irrGlGenFramebuffers(1, &BufferID); + + AssignedTextures.set_used(static_cast(ColorAttachment)); + + for (u32 i = 0; i < AssignedTextures.size(); ++i) + AssignedTextures[i] = GL_NONE; + } + + virtual ~COpenGLCoreRenderTarget() + { + if (ColorAttachment > 0 && BufferID != 0) + Driver->irrGlDeleteFramebuffers(1, &BufferID); + + for (u32 i = 0; i < Textures.size(); ++i) { + if (Textures[i]) + Textures[i]->drop(); + } + + if (DepthStencil) + DepthStencil->drop(); + } + + void setTextures(ITexture *const *textures, u32 numTextures, ITexture *depthStencil, const E_CUBE_SURFACE *cubeSurfaces, u32 numCubeSurfaces) override + { + bool needSizeUpdate = false; + + // Set color attachments. + if (!Textures.equals(textures, numTextures) || !CubeSurfaces.equals(cubeSurfaces, numCubeSurfaces)) { + needSizeUpdate = true; + + core::array prevTextures(Textures); + + if (numTextures > static_cast(ColorAttachment)) { + core::stringc message = "This GPU supports up to "; + message += static_cast(ColorAttachment); + message += " textures per render target."; + + os::Printer::log(message.c_str(), ELL_WARNING); + } + + Textures.set_used(core::min_(numTextures, static_cast(ColorAttachment))); + + for (u32 i = 0; i < Textures.size(); ++i) { + TOpenGLTexture *currentTexture = (textures[i] && textures[i]->getDriverType() == DriverType) ? static_cast(textures[i]) : 0; + + GLuint textureID = 0; + + if (currentTexture) { + textureID = currentTexture->getOpenGLTextureName(); + } + + if (textureID != 0) { + Textures[i] = textures[i]; + Textures[i]->grab(); + } else { + Textures[i] = 0; + } + } + + for (u32 i = 0; i < prevTextures.size(); ++i) { + if (prevTextures[i]) + prevTextures[i]->drop(); + } + + RequestTextureUpdate = true; + } + + if (!CubeSurfaces.equals(cubeSurfaces, numCubeSurfaces)) { + CubeSurfaces.set_data(cubeSurfaces, numCubeSurfaces); + RequestTextureUpdate = true; + } + + // Set depth and stencil attachments. + if (DepthStencil != depthStencil) { + if (DepthStencil) { + DepthStencil->drop(); + DepthStencil = 0; + } + + needSizeUpdate = true; + TOpenGLTexture *currentTexture = (depthStencil && depthStencil->getDriverType() == DriverType) ? static_cast(depthStencil) : 0; + + if (currentTexture) { + if (currentTexture->getType() == ETT_2D) { + GLuint textureID = currentTexture->getOpenGLTextureName(); + + const ECOLOR_FORMAT textureFormat = (textureID != 0) ? depthStencil->getColorFormat() : ECF_UNKNOWN; + if (IImage::isDepthFormat(textureFormat)) { + DepthStencil = depthStencil; + DepthStencil->grab(); + } else { + os::Printer::log("Ignoring depth/stencil texture without depth color format.", ELL_WARNING); + } + } else { + os::Printer::log("This driver doesn't support depth/stencil to cubemaps.", ELL_WARNING); + } + } + + RequestDepthStencilUpdate = true; + } + + if (needSizeUpdate) { + // Set size required for a viewport. + + ITexture *firstTexture = getTexture(); + + if (firstTexture) + Size = firstTexture->getSize(); + else { + if (DepthStencil) + Size = DepthStencil->getSize(); + else + Size = Driver->getScreenSize(); + } + } + } + + void update() + { + if (RequestTextureUpdate || RequestDepthStencilUpdate) { + // Set color attachments. + + if (RequestTextureUpdate) { + // Set new color textures. + + const u32 textureSize = core::min_(Textures.size(), AssignedTextures.size()); + + for (u32 i = 0; i < textureSize; ++i) { + TOpenGLTexture *currentTexture = static_cast(Textures[i]); + GLuint textureID = currentTexture ? currentTexture->getOpenGLTextureName() : 0; + + if (textureID != 0) { + AssignedTextures[i] = GL_COLOR_ATTACHMENT0 + i; + GLenum textarget = currentTexture->getType() == ETT_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int)CubeSurfaces[i]; + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], textarget, textureID, 0); +#ifdef _DEBUG + Driver->testGLError(__LINE__); +#endif + } else if (AssignedTextures[i] != GL_NONE) { + AssignedTextures[i] = GL_NONE; + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], GL_TEXTURE_2D, 0, 0); + + os::Printer::log("Error: Could not set render target.", ELL_ERROR); + } + } + + // Reset other render target channels. + + for (u32 i = textureSize; i < AssignedTextures.size(); ++i) { + if (AssignedTextures[i] != GL_NONE) { + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], GL_TEXTURE_2D, 0, 0); + AssignedTextures[i] = GL_NONE; + } + } + + RequestTextureUpdate = false; + } + + // Set depth and stencil attachments. + + if (RequestDepthStencilUpdate) { + const ECOLOR_FORMAT textureFormat = (DepthStencil) ? DepthStencil->getColorFormat() : ECF_UNKNOWN; + + if (IImage::isDepthFormat(textureFormat)) { + GLuint textureID = static_cast(DepthStencil)->getOpenGLTextureName(); + +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ // The WEBGL_depth_texture extension does not allow attaching stencil+depth separate. + if (textureFormat == ECF_D24S8) { + GLenum attachment = 0x821A; // GL_DEPTH_STENCIL_ATTACHMENT + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, textureID, 0); + AssignedStencil = true; + } else { + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureID, 0); + AssignedStencil = false; + } +#else + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureID, 0); + + if (textureFormat == ECF_D24S8) { + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textureID, 0); + + AssignedStencil = true; + } else { + if (AssignedStencil) + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + + AssignedStencil = false; + } +#endif + AssignedDepth = true; + } else { + if (AssignedDepth) + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + + if (AssignedStencil) + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + + AssignedDepth = false; + AssignedStencil = false; + } +#ifdef _DEBUG + Driver->testGLError(__LINE__); +#endif + + RequestDepthStencilUpdate = false; + } + + // Configure drawing operation. + + if (ColorAttachment > 0 && BufferID != 0) { + const u32 textureSize = Textures.size(); + + if (textureSize == 0) + Driver->irrGlDrawBuffer(GL_NONE); + else if (textureSize == 1 || MultipleRenderTarget == 0) + Driver->irrGlDrawBuffer(GL_COLOR_ATTACHMENT0); + else { + const u32 bufferCount = core::min_(MultipleRenderTarget, core::min_(textureSize, AssignedTextures.size())); + + Driver->irrGlDrawBuffers(bufferCount, AssignedTextures.pointer()); + } + +#ifdef _DEBUG + Driver->testGLError(__LINE__); +#endif + } + +#ifdef _DEBUG + checkFBO(Driver); +#endif + } + } + + GLuint getBufferID() const + { + return BufferID; + } + + const core::dimension2d &getSize() const + { + return Size; + } + + ITexture *getTexture() const + { + for (u32 i = 0; i < Textures.size(); ++i) { + if (Textures[i]) + return Textures[i]; + } + + return 0; + } + +protected: + bool checkFBO(TOpenGLDriver *driver) + { + if (ColorAttachment == 0) + return true; + + GLenum status = driver->irrGlCheckFramebufferStatus(GL_FRAMEBUFFER); + + switch (status) { + case GL_FRAMEBUFFER_COMPLETE: + return true; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + os::Printer::log("FBO has invalid read buffer", ELL_ERROR); + break; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + os::Printer::log("FBO has invalid draw buffer", ELL_ERROR); + break; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR); + break; + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS: + os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR); + break; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: + os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR); + break; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + os::Printer::log("FBO missing an image attachment", ELL_ERROR); + break; + case GL_FRAMEBUFFER_UNSUPPORTED: + os::Printer::log("FBO format unsupported", ELL_ERROR); + break; + default: + os::Printer::log("FBO error", ELL_ERROR); + break; + } + + return false; + } + + core::array AssignedTextures; + bool AssignedDepth; + bool AssignedStencil; + + bool RequestTextureUpdate; + bool RequestDepthStencilUpdate; + + GLuint BufferID; + + core::dimension2d Size; + + u32 ColorAttachment; + u32 MultipleRenderTarget; + + TOpenGLDriver *Driver; +}; + +} +} diff --git a/irr/src/COpenGLCoreTexture.h b/irr/src/COpenGLCoreTexture.h new file mode 100644 index 000000000..45bf2f0be --- /dev/null +++ b/irr/src/COpenGLCoreTexture.h @@ -0,0 +1,608 @@ +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrArray.h" +#include "SMaterialLayer.h" +#include "ITexture.h" +#include "EDriverFeatures.h" +#include "os.h" +#include "CImage.h" +#include "CColorConverter.h" + +#include "mt_opengl.h" + +namespace irr +{ +namespace video +{ + +template +class COpenGLCoreTexture : public ITexture +{ +public: + struct SStatesCache + { + SStatesCache() : + WrapU(ETC_REPEAT), WrapV(ETC_REPEAT), WrapW(ETC_REPEAT), + LODBias(0), AnisotropicFilter(0), MinFilter(video::ETMINF_NEAREST_MIPMAP_NEAREST), + MagFilter(video::ETMAGF_NEAREST), MipMapStatus(false), IsCached(false) + { + } + + u8 WrapU; + u8 WrapV; + u8 WrapW; + s8 LODBias; + u8 AnisotropicFilter; + video::E_TEXTURE_MIN_FILTER MinFilter; + video::E_TEXTURE_MAG_FILTER MagFilter; + bool MipMapStatus; + bool IsCached; + }; + + COpenGLCoreTexture(const io::path &name, const core::array &images, E_TEXTURE_TYPE type, TOpenGLDriver *driver) : + ITexture(name, type), Driver(driver), TextureType(GL_TEXTURE_2D), + TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), + KeepImage(false), MipLevelStored(0), LegacyAutoGenerateMipMaps(false) + { + _IRR_DEBUG_BREAK_IF(images.size() == 0) + + DriverType = Driver->getDriverType(); + TextureType = TextureTypeIrrToGL(Type); + HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); + KeepImage = Driver->getTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY); + + getImageValues(images[0]); + if (!InternalFormat) + return; + + const core::array *tmpImages = &images; + + if (KeepImage || OriginalSize != Size || OriginalColorFormat != ColorFormat) { + Images.set_used(images.size()); + + for (u32 i = 0; i < images.size(); ++i) { + Images[i] = Driver->createImage(ColorFormat, Size); + + if (images[i]->getDimension() == Size) + images[i]->copyTo(Images[i]); + else + images[i]->copyToScaling(Images[i]); + + if (images[i]->getMipMapsData()) { + if (OriginalSize == Size && OriginalColorFormat == ColorFormat) { + Images[i]->setMipMapsData(images[i]->getMipMapsData(), false); + } else { + // TODO: handle at least mipmap with changing color format + os::Printer::log("COpenGLCoreTexture: Can't handle format changes for mipmap data. Mipmap data dropped", ELL_WARNING); + } + } + } + + tmpImages = &Images; + } + + GL.GenTextures(1, &TextureName); + + const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0); + Driver->getCacheHandler()->getTextureCache().set(0, this); + + GL.TexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + +#ifdef GL_GENERATE_MIPMAP_HINT + if (HasMipMaps) { + if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) + GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); + else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY)) + GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + else + GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); + } +#endif + + for (u32 i = 0; i < (*tmpImages).size(); ++i) + uploadTexture(true, i, 0, (*tmpImages)[i]->getData()); + + if (HasMipMaps && !LegacyAutoGenerateMipMaps) { + // Create mipmaps (either from image mipmaps or generate them) + for (u32 i = 0; i < (*tmpImages).size(); ++i) { + void *mipmapsData = (*tmpImages)[i]->getMipMapsData(); + regenerateMipMapLevels(mipmapsData, i); + } + } + + if (!KeepImage) { + for (u32 i = 0; i < Images.size(); ++i) + Images[i]->drop(); + + Images.clear(); + } + + Driver->getCacheHandler()->getTextureCache().set(0, prevTexture); + + Driver->testGLError(__LINE__); + } + + COpenGLCoreTexture(const io::path &name, const core::dimension2d &size, E_TEXTURE_TYPE type, ECOLOR_FORMAT format, TOpenGLDriver *driver) : + ITexture(name, type), + Driver(driver), TextureType(GL_TEXTURE_2D), + TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), KeepImage(false), + MipLevelStored(0), LegacyAutoGenerateMipMaps(false) + { + DriverType = Driver->getDriverType(); + TextureType = TextureTypeIrrToGL(Type); + HasMipMaps = false; + IsRenderTarget = true; + + OriginalColorFormat = format; + + if (ECF_UNKNOWN == OriginalColorFormat) + ColorFormat = getBestColorFormat(Driver->getColorFormat()); + else + ColorFormat = OriginalColorFormat; + + OriginalSize = size; + Size = OriginalSize; + + Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8; + + if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) { + os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR); + return; + } + + GL.GenTextures(1, &TextureName); + + const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0); + Driver->getCacheHandler()->getTextureCache().set(0, this); + + GL.TexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + +#if defined(GL_VERSION_1_2) + GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); +#endif + + StatesCache.WrapU = ETC_CLAMP_TO_EDGE; + StatesCache.WrapV = ETC_CLAMP_TO_EDGE; + StatesCache.WrapW = ETC_CLAMP_TO_EDGE; + + switch (Type) { + case ETT_2D: + GL.TexImage2D(GL_TEXTURE_2D, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + break; + case ETT_CUBEMAP: + GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + break; + } + + Driver->getCacheHandler()->getTextureCache().set(0, prevTexture); + if (Driver->testGLError(__LINE__)) { + char msg[256]; + snprintf_irr(msg, 256, "COpenGLCoreTexture: InternalFormat:0x%04x PixelFormat:0x%04x", (int)InternalFormat, (int)PixelFormat); + os::Printer::log(msg, ELL_ERROR); + } + } + + virtual ~COpenGLCoreTexture() + { + if (TextureName) + GL.DeleteTextures(1, &TextureName); + + if (LockImage) + LockImage->drop(); + + for (u32 i = 0; i < Images.size(); ++i) + Images[i]->drop(); + } + + void *lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel = 0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) override + { + if (LockImage) + return getLockImageData(MipLevelStored); + + if (IImage::isCompressedFormat(ColorFormat)) + return 0; + + LockReadOnly |= (mode == ETLM_READ_ONLY); + LockLayer = layer; + MipLevelStored = mipmapLevel; + + if (KeepImage) { + _IRR_DEBUG_BREAK_IF(LockLayer > Images.size()) + + if (mipmapLevel == 0 || (Images[LockLayer] && Images[LockLayer]->getMipMapsData(mipmapLevel))) { + LockImage = Images[LockLayer]; + LockImage->grab(); + } + } + + if (!LockImage) { + core::dimension2d lockImageSize(IImage::getMipMapsSize(Size, MipLevelStored)); + + // note: we save mipmap data also in the image because IImage doesn't allow saving single mipmap levels to the mipmap data + LockImage = Driver->createImage(ColorFormat, lockImageSize); + + if (LockImage && mode != ETLM_WRITE_ONLY) { + bool passed = true; + +#ifdef IRR_COMPILE_GL_COMMON + IImage *tmpImage = LockImage; // not sure yet if the size required by glGetTexImage is always correct, if not we might have to allocate a different tmpImage and convert colors later on. + + Driver->getCacheHandler()->getTextureCache().set(0, this); + Driver->testGLError(__LINE__); + + GLenum tmpTextureType = TextureType; + + if (tmpTextureType == GL_TEXTURE_CUBE_MAP) { + _IRR_DEBUG_BREAK_IF(layer > 5) + + tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; + } + + GL.GetTexImage(tmpTextureType, MipLevelStored, PixelFormat, PixelType, tmpImage->getData()); + Driver->testGLError(__LINE__); + + if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT) { + const s32 pitch = tmpImage->getPitch(); + + u8 *srcA = static_cast(tmpImage->getData()); + u8 *srcB = srcA + (tmpImage->getDimension().Height - 1) * pitch; + + u8 *tmpBuffer = new u8[pitch]; + + for (u32 i = 0; i < tmpImage->getDimension().Height; i += 2) { + memcpy(tmpBuffer, srcA, pitch); + memcpy(srcA, srcB, pitch); + memcpy(srcB, tmpBuffer, pitch); + srcA += pitch; + srcB -= pitch; + } + + delete[] tmpBuffer; + } +#elif (defined(IRR_COMPILE_GLES2_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) + // TODO: on ES2 we can likely also work with glCopyTexImage2D instead of rendering which should be faster. + COpenGLCoreTexture *tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ETT_2D, ColorFormat, Driver); + + GLuint tmpFBO = 0; + Driver->irrGlGenFramebuffers(1, &tmpFBO); + + GLint prevViewportX = 0; + GLint prevViewportY = 0; + GLsizei prevViewportWidth = 0; + GLsizei prevViewportHeight = 0; + Driver->getCacheHandler()->getViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight); + Driver->getCacheHandler()->setViewport(0, 0, Size.Width, Size.Height); + + GLuint prevFBO = 0; + Driver->getCacheHandler()->getFBO(prevFBO); + Driver->getCacheHandler()->setFBO(tmpFBO); + + Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmpTexture->getOpenGLTextureName(), 0); + + GL.Clear(GL_COLOR_BUFFER_BIT); + + Driver->draw2DImage(this, layer, true); + + IImage *tmpImage = Driver->createImage(ECF_A8R8G8B8, Size); + GL.ReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData()); + + Driver->getCacheHandler()->setFBO(prevFBO); + Driver->getCacheHandler()->setViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight); + + Driver->irrGlDeleteFramebuffers(1, &tmpFBO); + delete tmpTexture; + + void *src = tmpImage->getData(); + void *dest = LockImage->getData(); + + switch (ColorFormat) { + case ECF_A1R5G5B5: + CColorConverter::convert_A8R8G8B8toA1B5G5R5(src, tmpImage->getDimension().getArea(), dest); + break; + case ECF_R5G6B5: + CColorConverter::convert_A8R8G8B8toR5G6B5(src, tmpImage->getDimension().getArea(), dest); + break; + case ECF_R8G8B8: + CColorConverter::convert_A8R8G8B8toB8G8R8(src, tmpImage->getDimension().getArea(), dest); + break; + case ECF_A8R8G8B8: + CColorConverter::convert_A8R8G8B8toA8B8G8R8(src, tmpImage->getDimension().getArea(), dest); + break; + default: + passed = false; + break; + } + tmpImage->drop(); +#endif + + if (!passed) { + LockImage->drop(); + LockImage = 0; + } + } + + Driver->testGLError(__LINE__); + } + + return (LockImage) ? getLockImageData(MipLevelStored) : 0; + } + + void unlock() override + { + if (!LockImage) + return; + + if (!LockReadOnly) { + const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0); + Driver->getCacheHandler()->getTextureCache().set(0, this); + + uploadTexture(false, LockLayer, MipLevelStored, getLockImageData(MipLevelStored)); + + Driver->getCacheHandler()->getTextureCache().set(0, prevTexture); + } + + LockImage->drop(); + + LockReadOnly = false; + LockImage = 0; + LockLayer = 0; + } + + void regenerateMipMapLevels(void *data = 0, u32 layer = 0) override + { + if (!HasMipMaps || LegacyAutoGenerateMipMaps || (Size.Width <= 1 && Size.Height <= 1)) + return; + + const COpenGLCoreTexture *prevTexture = Driver->getCacheHandler()->getTextureCache().get(0); + Driver->getCacheHandler()->getTextureCache().set(0, this); + + if (data) { + u32 width = Size.Width; + u32 height = Size.Height; + u8 *tmpData = static_cast(data); + u32 dataSize = 0; + u32 level = 0; + + do { + if (width > 1) + width >>= 1; + + if (height > 1) + height >>= 1; + + dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height); + ++level; + + uploadTexture(true, layer, level, tmpData); + + tmpData += dataSize; + } while (width != 1 || height != 1); + } else { + Driver->irrGlGenerateMipmap(TextureType); + } + + Driver->getCacheHandler()->getTextureCache().set(0, prevTexture); + } + + GLenum getOpenGLTextureType() const + { + return TextureType; + } + + GLuint getOpenGLTextureName() const + { + return TextureName; + } + + SStatesCache &getStatesCache() const + { + return StatesCache; + } + +protected: + void *getLockImageData(irr::u32 miplevel) const + { + if (KeepImage && MipLevelStored > 0 && LockImage->getMipMapsData(MipLevelStored)) { + return LockImage->getMipMapsData(MipLevelStored); + } + return LockImage->getData(); + } + + ECOLOR_FORMAT getBestColorFormat(ECOLOR_FORMAT format) + { + // We only try for to adapt "simple" formats + ECOLOR_FORMAT destFormat = (format <= ECF_A8R8G8B8) ? ECF_A8R8G8B8 : format; + + switch (format) { + case ECF_A1R5G5B5: + if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT)) + destFormat = ECF_A1R5G5B5; + break; + case ECF_R5G6B5: + if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT)) + destFormat = ECF_R5G6B5; + break; + case ECF_A8R8G8B8: + if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) || + Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) + destFormat = ECF_A1R5G5B5; + break; + case ECF_R8G8B8: + // Note: Using ECF_A8R8G8B8 even when ETCF_ALWAYS_32_BIT is not set as 24 bit textures fail with too many cards + if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) || Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) + destFormat = ECF_A1R5G5B5; + default: + break; + } + + if (Driver->getTextureCreationFlag(ETCF_NO_ALPHA_CHANNEL)) { + switch (destFormat) { + case ECF_A1R5G5B5: + destFormat = ECF_R5G6B5; + break; + case ECF_A8R8G8B8: + destFormat = ECF_R8G8B8; + break; + default: + break; + } + } + + return destFormat; + } + + void getImageValues(const IImage *image) + { + OriginalColorFormat = image->getColorFormat(); + ColorFormat = getBestColorFormat(OriginalColorFormat); + + if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) { + os::Printer::log("getImageValues: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR); + InternalFormat = 0; + return; + } + + if (IImage::isCompressedFormat(image->getColorFormat())) { + KeepImage = false; + } + + OriginalSize = image->getDimension(); + Size = OriginalSize; + + if (Size.Width == 0 || Size.Height == 0) { + os::Printer::log("Invalid size of image for texture.", ELL_ERROR); + return; + } + + const f32 ratio = (f32)Size.Width / (f32)Size.Height; + + if ((Size.Width > Driver->MaxTextureSize) && (ratio >= 1.f)) { + Size.Width = Driver->MaxTextureSize; + Size.Height = (u32)(Driver->MaxTextureSize / ratio); + } else if (Size.Height > Driver->MaxTextureSize) { + Size.Height = Driver->MaxTextureSize; + Size.Width = (u32)(Driver->MaxTextureSize * ratio); + } + + bool needSquare = (!Driver->queryFeature(EVDF_TEXTURE_NSQUARE) || Type == ETT_CUBEMAP); + + Size = Size.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT), needSquare, true, Driver->MaxTextureSize); + + Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8; + } + + void uploadTexture(bool initTexture, u32 layer, u32 level, void *data) + { + if (!data) + return; + + u32 width = Size.Width >> level; + u32 height = Size.Height >> level; + if (width < 1) + width = 1; + if (height < 1) + height = 1; + + GLenum tmpTextureType = TextureType; + + if (tmpTextureType == GL_TEXTURE_CUBE_MAP) { + _IRR_DEBUG_BREAK_IF(layer > 5) + + tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; + } + + if (!IImage::isCompressedFormat(ColorFormat)) { + CImage *tmpImage = 0; + void *tmpData = data; + + if (Converter) { + const core::dimension2d tmpImageSize(width, height); + + tmpImage = new CImage(ColorFormat, tmpImageSize); + tmpData = tmpImage->getData(); + + Converter(data, tmpImageSize.getArea(), tmpData); + } + + switch (TextureType) { + case GL_TEXTURE_2D: + case GL_TEXTURE_CUBE_MAP: + if (initTexture) + GL.TexImage2D(tmpTextureType, level, InternalFormat, width, height, 0, PixelFormat, PixelType, tmpData); + else + GL.TexSubImage2D(tmpTextureType, level, 0, 0, width, height, PixelFormat, PixelType, tmpData); + Driver->testGLError(__LINE__); + break; + default: + break; + } + + delete tmpImage; + } else { + u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height); + + switch (TextureType) { + case GL_TEXTURE_2D: + case GL_TEXTURE_CUBE_MAP: + if (initTexture) + Driver->irrGlCompressedTexImage2D(tmpTextureType, level, InternalFormat, width, height, 0, dataSize, data); + else + Driver->irrGlCompressedTexSubImage2D(tmpTextureType, level, 0, 0, width, height, PixelFormat, dataSize, data); + Driver->testGLError(__LINE__); + break; + default: + break; + } + } + } + + GLenum TextureTypeIrrToGL(E_TEXTURE_TYPE type) const + { + switch (type) { + case ETT_2D: + return GL_TEXTURE_2D; + case ETT_CUBEMAP: + return GL_TEXTURE_CUBE_MAP; + } + + os::Printer::log("COpenGLCoreTexture::TextureTypeIrrToGL unknown texture type", ELL_WARNING); + return GL_TEXTURE_2D; + } + + TOpenGLDriver *Driver; + + GLenum TextureType; + GLuint TextureName; + GLint InternalFormat; + GLenum PixelFormat; + GLenum PixelType; + void (*Converter)(const void *, s32, void *); + + bool LockReadOnly; + IImage *LockImage; + u32 LockLayer; + + bool KeepImage; + core::array Images; + + u8 MipLevelStored; + bool LegacyAutoGenerateMipMaps; + + mutable SStatesCache StatesCache; +}; + +} +} diff --git a/irr/src/COpenGLDriver.cpp b/irr/src/COpenGLDriver.cpp new file mode 100644 index 000000000..ef560e331 --- /dev/null +++ b/irr/src/COpenGLDriver.cpp @@ -0,0 +1,3414 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "COpenGLDriver.h" +#include +#include "CNullDriver.h" +#include "IContextManager.h" + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "os.h" + +#include "COpenGLCacheHandler.h" +#include "COpenGLMaterialRenderer.h" +#include "COpenGLSLMaterialRenderer.h" + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreRenderTarget.h" + +#include "mt_opengl.h" + +namespace irr +{ +namespace video +{ + +// Statics variables +const u16 COpenGLDriver::Quad2DIndices[4] = {0, 1, 2, 3}; + +COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) : + CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), + Transformation3DChanged(true), AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE), Params(params), + ContextManager(contextManager) +{ +#ifdef _DEBUG + setDebugName("COpenGLDriver"); +#endif +} + +bool COpenGLDriver::initDriver() +{ + ContextManager->generateSurface(); + ContextManager->generateContext(); + ExposedData = ContextManager->getContext(); + ContextManager->activateContext(ExposedData, false); + GL.LoadAllProcedures(ContextManager); + + genericDriverInit(); + +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) + extGlSwapInterval(Params.Vsync ? 1 : 0); +#endif + + return true; +} + +//! destructor +COpenGLDriver::~COpenGLDriver() +{ + deleteMaterialRenders(); + + CacheHandler->getTextureCache().clear(); + // I get a blue screen on my laptop, when I do not delete the + // textures manually before releasing the dc. Oh how I love this. + removeAllRenderTargets(); + deleteAllTextures(); + removeAllOcclusionQueries(); + removeAllHardwareBuffers(); + + delete CacheHandler; + + if (ContextManager) { + ContextManager->destroyContext(); + ContextManager->destroySurface(); + ContextManager->terminate(); + ContextManager->drop(); + } +} + +// ----------------------------------------------------------------------- +// METHODS +// ----------------------------------------------------------------------- + +bool COpenGLDriver::genericDriverInit() +{ + if (ContextManager) + ContextManager->grab(); + + Name = "OpenGL "; + Name.append(glGetString(GL_VERSION)); + s32 pos = Name.findNext(' ', 7); + if (pos != -1) + Name = Name.subString(0, pos); + printVersion(); + + // print renderer information + const GLubyte *renderer = glGetString(GL_RENDERER); + const GLubyte *vendor = glGetString(GL_VENDOR); + if (renderer && vendor) { + os::Printer::log(reinterpret_cast(renderer), reinterpret_cast(vendor), ELL_INFORMATION); + VendorName = reinterpret_cast(vendor); + } + + u32 i; + + // load extensions + initExtensions(ContextManager, Params.Stencilbuffer); + + // reset cache handler + delete CacheHandler; + CacheHandler = new COpenGLCacheHandler(this); + + if (queryFeature(EVDF_ARB_GLSL)) { + char buf[32]; + const u32 maj = ShaderLanguageVersion / 100; + snprintf_irr(buf, 32, "%u.%u", maj, ShaderLanguageVersion - maj * 100); + os::Printer::log("GLSL version", buf, ELL_INFORMATION); + } else + os::Printer::log("GLSL not available.", ELL_INFORMATION); + DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits); + DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits); + DriverAttributes->setAttribute("MaxLights", MaxLights); + DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy); + DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes); + DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers); + DriverAttributes->setAttribute("MaxMultipleRenderTargets", (s32)Feature.MultipleRenderTarget); + DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices); + DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize); + DriverAttributes->setAttribute("MaxGeometryVerticesOut", (s32)MaxGeometryVerticesOut); + DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias); + DriverAttributes->setAttribute("Version", Version); + DriverAttributes->setAttribute("ShaderLanguageVersion", ShaderLanguageVersion); + DriverAttributes->setAttribute("AntiAlias", AntiAlias); + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + UserClipPlanes.reallocate(MaxUserClipPlanes); + for (i = 0; i < MaxUserClipPlanes; ++i) + UserClipPlanes.push_back(SUserClipPlane()); + + for (i = 0; i < ETS_COUNT; ++i) + setTransform(static_cast(i), core::IdentityMatrix); + + setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); +#ifdef GL_EXT_separate_specular_color + if (FeatureAvailable[IRR_EXT_separate_specular_color]) + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); +#endif + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); + + // This is a fast replacement for NORMALIZE_NORMALS + // if ((Version>101) || FeatureAvailable[IRR_EXT_rescale_normal]) + // glEnable(GL_RESCALE_NORMAL_EXT); + + glClearDepth(1.0); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glFrontFace(GL_CW); + // adjust flat coloring scheme to DirectX version +#if defined(GL_ARB_provoking_vertex) || defined(GL_EXT_provoking_vertex) + extGlProvokingVertex(GL_FIRST_VERTEX_CONVENTION_EXT); +#endif + + // Create built-in 2D quad for 2D rendering (both quads and lines). + Quad2DVertices[0] = S3DVertex(core::vector3df(-1.0f, 1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(0.0f, 1.0f)); + Quad2DVertices[1] = S3DVertex(core::vector3df(1.0f, 1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(1.0f, 1.0f)); + Quad2DVertices[2] = S3DVertex(core::vector3df(1.0f, -1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(1.0f, 0.0f)); + Quad2DVertices[3] = S3DVertex(core::vector3df(-1.0f, -1.0f, 0.0f), core::vector3df(0.0f, 0.0f, 0.0f), SColor(255, 255, 255, 255), core::vector2df(0.0f, 0.0f)); + + // create material renderers + createMaterialRenderers(); + + // set the renderstates + setRenderStates3DMode(); + + // set fog mode + setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog); + + // create matrix for flipping textures + TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f)); + + // We need to reset once more at the beginning of the first rendering. + // This fixes problems with intermediate changes to the material during texture load. + ResetRenderStates = true; + + return true; +} + +void COpenGLDriver::createMaterialRenderers() +{ + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_SOLID(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_ONETEXTURE_BLEND(this)); +} + +bool COpenGLDriver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData &videoData, core::rect *sourceRect) +{ + CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect); + + if (ContextManager) + ContextManager->activateContext(videoData, true); + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; +} + +bool COpenGLDriver::endScene() +{ + CNullDriver::endScene(); + + glFlush(); + + bool status = false; + + if (ContextManager) + status = ContextManager->swapBuffers(); + + // todo: console device present + + return status; +} + +//! Returns the transformation set by setTransform +const core::matrix4 &COpenGLDriver::getTransform(E_TRANSFORMATION_STATE state) const +{ + return Matrices[state]; +} + +//! sets transformation +void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) +{ + Matrices[state] = mat; + Transformation3DChanged = true; + + switch (state) { + case ETS_VIEW: + case ETS_WORLD: { + // OpenGL only has a model matrix, view and world is not existent. so lets fake these two. + CacheHandler->setMatrixMode(GL_MODELVIEW); + + // first load the viewing transformation for user clip planes + glLoadMatrixf((Matrices[ETS_VIEW]).pointer()); + + // we have to update the clip planes to the latest view matrix + for (u32 i = 0; i < MaxUserClipPlanes; ++i) + if (UserClipPlanes[i].Enabled) + uploadClipPlane(i); + + // now the real model-view matrix + glMultMatrixf(Matrices[ETS_WORLD].pointer()); + } break; + case ETS_PROJECTION: { + CacheHandler->setMatrixMode(GL_PROJECTION); + glLoadMatrixf(mat.pointer()); + } break; + default: + break; + } +} + +bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) +{ + if (!HWBuffer) + return false; + + if (!FeatureAvailable[IRR_ARB_vertex_buffer_object]) + return false; + +#if defined(GL_ARB_vertex_buffer_object) + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + const void *vertices = mb->getVertices(); + const u32 vertexCount = mb->getVertexCount(); + const E_VERTEX_TYPE vType = mb->getVertexType(); + const u32 vertexSize = getVertexPitchFromType(vType); + + const c8 *vbuf = static_cast(vertices); + core::array buffer; + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) { + // buffer vertex data, and convert colors... + buffer.set_used(vertexSize * vertexCount); + memcpy(buffer.pointer(), vertices, vertexSize * vertexCount); + vbuf = buffer.const_pointer(); + + // in order to convert the colors into opengl format (RGBA) + switch (vType) { + case EVT_STANDARD: { + S3DVertex *pb = reinterpret_cast(buffer.pointer()); + const S3DVertex *po = static_cast(vertices); + for (u32 i = 0; i < vertexCount; i++) { + po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color)); + } + } break; + case EVT_2TCOORDS: { + S3DVertex2TCoords *pb = reinterpret_cast(buffer.pointer()); + const S3DVertex2TCoords *po = static_cast(vertices); + for (u32 i = 0; i < vertexCount; i++) { + po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color)); + } + } break; + case EVT_TANGENTS: { + S3DVertexTangents *pb = reinterpret_cast(buffer.pointer()); + const S3DVertexTangents *po = static_cast(vertices); + for (u32 i = 0; i < vertexCount; i++) { + po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color)); + } + } break; + default: { + return false; + } + } + } + + // get or create buffer + bool newBuffer = false; + if (!HWBuffer->vbo_verticesID) { + extGlGenBuffers(1, &HWBuffer->vbo_verticesID); + if (!HWBuffer->vbo_verticesID) + return false; + newBuffer = true; + } else if (HWBuffer->vbo_verticesSize < vertexCount * vertexSize) { + newBuffer = true; + } + + extGlBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + + // copy data to graphics card + if (!newBuffer) + extGlBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, vbuf); + else { + HWBuffer->vbo_verticesSize = vertexCount * vertexSize; + + if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC) + extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_STATIC_DRAW); + else if (HWBuffer->Mapped_Vertex == scene::EHM_DYNAMIC) + extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_DYNAMIC_DRAW); + else // scene::EHM_STREAM + extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_STREAM_DRAW); + } + + extGlBindBuffer(GL_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); +#else + return false; +#endif +} + +bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) +{ + if (!HWBuffer) + return false; + + if (!FeatureAvailable[IRR_ARB_vertex_buffer_object]) + return false; + +#if defined(GL_ARB_vertex_buffer_object) + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + + const void *indices = mb->getIndices(); + u32 indexCount = mb->getIndexCount(); + + GLenum indexSize; + switch (mb->getIndexType()) { + case EIT_16BIT: { + indexSize = sizeof(u16); + break; + } + case EIT_32BIT: { + indexSize = sizeof(u32); + break; + } + default: { + return false; + } + } + + // get or create buffer + bool newBuffer = false; + if (!HWBuffer->vbo_indicesID) { + extGlGenBuffers(1, &HWBuffer->vbo_indicesID); + if (!HWBuffer->vbo_indicesID) + return false; + newBuffer = true; + } else if (HWBuffer->vbo_indicesSize < indexCount * indexSize) { + newBuffer = true; + } + + extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + + // copy data to graphics card + if (!newBuffer) + extGlBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices); + else { + HWBuffer->vbo_indicesSize = indexCount * indexSize; + + if (HWBuffer->Mapped_Index == scene::EHM_STATIC) + extGlBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW); + else if (HWBuffer->Mapped_Index == scene::EHM_DYNAMIC) + extGlBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_DYNAMIC_DRAW); + else // scene::EHM_STREAM + extGlBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STREAM_DRAW); + } + + extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); +#else + return false; +#endif +} + +//! updates hardware buffer if needed +bool COpenGLDriver::updateHardwareBuffer(SHWBufferLink *HWBuffer) +{ + if (!HWBuffer) + return false; + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { + if (HWBuffer->ChangedID_Vertex != HWBuffer->MeshBuffer->getChangedID_Vertex() || !((SHWBufferLink_opengl *)HWBuffer)->vbo_verticesID) { + + HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); + + if (!updateVertexHardwareBuffer((SHWBufferLink_opengl *)HWBuffer)) + return false; + } + } + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { + if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index() || !((SHWBufferLink_opengl *)HWBuffer)->vbo_indicesID) { + + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + + if (!updateIndexHardwareBuffer((SHWBufferLink_opengl *)HWBuffer)) + return false; + } + } + + return true; +} + +//! Create hardware buffer from meshbuffer +COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::IMeshBuffer *mb) +{ +#if defined(GL_ARB_vertex_buffer_object) + if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER)) + return 0; + + SHWBufferLink_opengl *HWBuffer = new SHWBufferLink_opengl(mb); + + // add to map + HWBuffer->listPosition = HWBufferList.insert(HWBufferList.end(), HWBuffer); + + HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + HWBuffer->Mapped_Vertex = mb->getHardwareMappingHint_Vertex(); + HWBuffer->Mapped_Index = mb->getHardwareMappingHint_Index(); + HWBuffer->vbo_verticesID = 0; + HWBuffer->vbo_indicesID = 0; + HWBuffer->vbo_verticesSize = 0; + HWBuffer->vbo_indicesSize = 0; + + if (!updateHardwareBuffer(HWBuffer)) { + deleteHardwareBuffer(HWBuffer); + return 0; + } + + return HWBuffer; +#else + return 0; +#endif +} + +void COpenGLDriver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) +{ + if (!_HWBuffer) + return; + +#if defined(GL_ARB_vertex_buffer_object) + SHWBufferLink_opengl *HWBuffer = (SHWBufferLink_opengl *)_HWBuffer; + if (HWBuffer->vbo_verticesID) { + extGlDeleteBuffers(1, &HWBuffer->vbo_verticesID); + HWBuffer->vbo_verticesID = 0; + } + if (HWBuffer->vbo_indicesID) { + extGlDeleteBuffers(1, &HWBuffer->vbo_indicesID); + HWBuffer->vbo_indicesID = 0; + } +#endif + + CNullDriver::deleteHardwareBuffer(_HWBuffer); +} + +//! Draw hardware buffer +void COpenGLDriver::drawHardwareBuffer(SHWBufferLink *_HWBuffer) +{ + if (!_HWBuffer) + return; + + updateHardwareBuffer(_HWBuffer); // check if update is needed + +#if defined(GL_ARB_vertex_buffer_object) + SHWBufferLink_opengl *HWBuffer = (SHWBufferLink_opengl *)_HWBuffer; + + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + const void *vertices = mb->getVertices(); + const void *indexList = mb->getIndices(); + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { + extGlBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + vertices = 0; + } + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { + extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + indexList = 0; + } + + drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType()); + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) + extGlBindBuffer(GL_ARRAY_BUFFER, 0); + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) + extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +#endif +} + +//! Create occlusion query. +/** Use node for identification and mesh for occlusion test. */ +void COpenGLDriver::addOcclusionQuery(scene::ISceneNode *node, + const scene::IMesh *mesh) +{ + if (!queryFeature(EVDF_OCCLUSION_QUERY)) + return; + + CNullDriver::addOcclusionQuery(node, mesh); + const s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if ((index != -1) && (OcclusionQueries[index].UID == 0)) + extGlGenQueries(1, reinterpret_cast(&OcclusionQueries[index].UID)); +} + +//! Remove occlusion query. +void COpenGLDriver::removeOcclusionQuery(scene::ISceneNode *node) +{ + const s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if (index != -1) { + if (OcclusionQueries[index].UID != 0) + extGlDeleteQueries(1, reinterpret_cast(&OcclusionQueries[index].UID)); + CNullDriver::removeOcclusionQuery(node); + } +} + +//! Run occlusion query. Draws mesh stored in query. +/** If the mesh shall not be rendered visible, use +overrideMaterial to disable the color and depth buffer. */ +void COpenGLDriver::runOcclusionQuery(scene::ISceneNode *node, bool visible) +{ + if (!node) + return; + + const s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if (index != -1) { + if (OcclusionQueries[index].UID) + extGlBeginQuery( +#ifdef GL_ARB_occlusion_query + GL_SAMPLES_PASSED_ARB, +#else + 0, +#endif + OcclusionQueries[index].UID); + CNullDriver::runOcclusionQuery(node, visible); + if (OcclusionQueries[index].UID) + extGlEndQuery( +#ifdef GL_ARB_occlusion_query + GL_SAMPLES_PASSED_ARB); +#else + 0); +#endif + testGLError(__LINE__); + } +} + +//! Update occlusion query. Retrieves results from GPU. +/** If the query shall not block, set the flag to false. +Update might not occur in this case, though */ +void COpenGLDriver::updateOcclusionQuery(scene::ISceneNode *node, bool block) +{ + const s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if (index != -1) { + // not yet started + if (OcclusionQueries[index].Run == u32(~0)) + return; + GLint available = block ? GL_TRUE : GL_FALSE; + if (!block) { + extGlGetQueryObjectiv(OcclusionQueries[index].UID, +#ifdef GL_ARB_occlusion_query + GL_QUERY_RESULT_AVAILABLE_ARB, +#elif defined(GL_NV_occlusion_query) + GL_PIXEL_COUNT_AVAILABLE_NV, +#else + 0, +#endif + &available); + testGLError(__LINE__); + } + if (available == GL_TRUE) { + extGlGetQueryObjectiv(OcclusionQueries[index].UID, +#ifdef GL_ARB_occlusion_query + GL_QUERY_RESULT_ARB, +#elif defined(GL_NV_occlusion_query) + GL_PIXEL_COUNT_NV, +#else + 0, +#endif + &available); + if (queryFeature(EVDF_OCCLUSION_QUERY)) + OcclusionQueries[index].Result = available; + } + testGLError(__LINE__); + } +} + +//! Return query result. +/** Return value is the number of visible pixels/fragments. +The value is a safe approximation, i.e. can be larger than the +actual value of pixels. */ +u32 COpenGLDriver::getOcclusionQueryResult(scene::ISceneNode *node) const +{ + const s32 index = OcclusionQueries.linear_search(SOccQuery(node)); + if (index != -1) + return OcclusionQueries[index].Result; + else + return ~0; +} + +//! Create render target. +IRenderTarget *COpenGLDriver::addRenderTarget() +{ + COpenGLRenderTarget *renderTarget = new COpenGLRenderTarget(this); + RenderTargets.push_back(renderTarget); + + return renderTarget; +} + +// small helper function to create vertex buffer object address offsets +static inline const GLvoid *buffer_offset(const size_t offset) +{ + return (const GLvoid *)offset; +} + +//! draws a vertex primitive list +void COpenGLDriver::drawVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) +{ + if (!primitiveCount || !vertexCount) + return; + + if (!checkPrimitiveCount(primitiveCount)) + return; + + CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); + + if (vertices && !FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(vertices, vertexCount, vType); + + // draw everything + setRenderStates3DMode(); + + if ((pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES)) + CacheHandler->setClientState(true, true, true, true); + else + CacheHandler->setClientState(true, false, true, false); + +// due to missing defines in OSX headers, we have to be more specific with this check +// #if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra) +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (vertices) { + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) { + switch (vType) { + case EVT_STANDARD: + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + break; + case EVT_2TCOORDS: + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Color); + break; + case EVT_TANGENTS: + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Color); + break; + } + } else { + // avoid passing broken pointer to OpenGL + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + } + + switch (vType) { + case EVT_STANDARD: + if (vertices) { + glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + } else { + glNormalPointer(GL_FLOAT, sizeof(S3DVertex), buffer_offset(12)); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0); + } + + if (Feature.MaxTextureUnits > 0 && CacheHandler->getTextureCache()[1]) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + else + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); + } + break; + case EVT_2TCOORDS: + if (vertices) { + glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Pos); + } else { + glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12)); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28)); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0)); + } + + if (Feature.MaxTextureUnits > 0) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords2); + else + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36)); + } + break; + case EVT_TANGENTS: + if (vertices) { + glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].TCoords); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Pos); + } else { + glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(12)); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28)); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0)); + } + + if (Feature.MaxTextureUnits > 0) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Tangent); + else + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(36)); + + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 2); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Binormal); + else + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(48)); + } + break; + } + + renderArray(indexList, primitiveCount, pType, iType); + + if (Feature.MaxTextureUnits > 0) { + if (vType == EVT_TANGENTS) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 2); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + if ((vType != EVT_STANDARD) || CacheHandler->getTextureCache()[1]) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + CacheHandler->setClientActiveTexture(GL_TEXTURE0); + } +} + +void COpenGLDriver::getColorBuffer(const void *vertices, u32 vertexCount, E_VERTEX_TYPE vType) +{ + // convert colors to gl color format. + vertexCount *= 4; // reused as color component count + ColorBuffer.set_used(vertexCount); + u32 i; + + switch (vType) { + case EVT_STANDARD: { + const S3DVertex *p = static_cast(vertices); + for (i = 0; i < vertexCount; i += 4) { + p->Color.toOpenGLColor(&ColorBuffer[i]); + ++p; + } + } break; + case EVT_2TCOORDS: { + const S3DVertex2TCoords *p = static_cast(vertices); + for (i = 0; i < vertexCount; i += 4) { + p->Color.toOpenGLColor(&ColorBuffer[i]); + ++p; + } + } break; + case EVT_TANGENTS: { + const S3DVertexTangents *p = static_cast(vertices); + for (i = 0; i < vertexCount; i += 4) { + p->Color.toOpenGLColor(&ColorBuffer[i]); + ++p; + } + } break; + } +} + +void COpenGLDriver::renderArray(const void *indexList, u32 primitiveCount, + scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) +{ + GLenum indexSize = 0; + + switch (iType) { + case EIT_16BIT: { + indexSize = GL_UNSIGNED_SHORT; + break; + } + case EIT_32BIT: { + indexSize = GL_UNSIGNED_INT; + break; + } + } + + switch (pType) { + case scene::EPT_POINTS: + case scene::EPT_POINT_SPRITES: { +#ifdef GL_ARB_point_sprite + if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[IRR_ARB_point_sprite]) + glEnable(GL_POINT_SPRITE_ARB); +#endif + + // prepare size and attenuation (where supported) + GLfloat particleSize = Material.Thickness; + // if (AntiAlias) + // particleSize=core::clamp(particleSize, DimSmoothedPoint[0], DimSmoothedPoint[1]); + // else + particleSize = core::clamp(particleSize, DimAliasedPoint[0], DimAliasedPoint[1]); +#if defined(GL_VERSION_1_4) || defined(GL_ARB_point_parameters) || defined(GL_EXT_point_parameters) || defined(GL_SGIS_point_parameters) + const float att[] = {1.0f, 1.0f, 0.0f}; +#if defined(GL_VERSION_1_4) + extGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, att); + // extGlPointParameterf(GL_POINT_SIZE_MIN,1.f); + extGlPointParameterf(GL_POINT_SIZE_MAX, particleSize); + extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 1.0f); +#elif defined(GL_ARB_point_parameters) + extGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att); + // extGlPointParameterf(GL_POINT_SIZE_MIN_ARB,1.f); + extGlPointParameterf(GL_POINT_SIZE_MAX_ARB, particleSize); + extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1.0f); +#elif defined(GL_EXT_point_parameters) + extGlPointParameterfv(GL_DISTANCE_ATTENUATION_EXT, att); + // extGlPointParameterf(GL_POINT_SIZE_MIN_EXT,1.f); + extGlPointParameterf(GL_POINT_SIZE_MAX_EXT, particleSize); + extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 1.0f); +#elif defined(GL_SGIS_point_parameters) + extGlPointParameterfv(GL_DISTANCE_ATTENUATION_SGIS, att); + // extGlPointParameterf(GL_POINT_SIZE_MIN_SGIS,1.f); + extGlPointParameterf(GL_POINT_SIZE_MAX_SGIS, particleSize); + extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_SGIS, 1.0f); +#endif +#endif + glPointSize(particleSize); + +#ifdef GL_ARB_point_sprite + if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[IRR_ARB_point_sprite]) { + CacheHandler->setActiveTexture(GL_TEXTURE0_ARB); + glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE, GL_TRUE); + } +#endif + glDrawArrays(GL_POINTS, 0, primitiveCount); +#ifdef GL_ARB_point_sprite + if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[IRR_ARB_point_sprite]) { + glDisable(GL_POINT_SPRITE_ARB); + + CacheHandler->setActiveTexture(GL_TEXTURE0_ARB); + glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE, GL_FALSE); + } +#endif + } break; + case scene::EPT_LINE_STRIP: + glDrawElements(GL_LINE_STRIP, primitiveCount + 1, indexSize, indexList); + break; + case scene::EPT_LINE_LOOP: + glDrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList); + break; + case scene::EPT_LINES: + glDrawElements(GL_LINES, primitiveCount * 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_STRIP: + glDrawElements(GL_TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_FAN: + glDrawElements(GL_TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLES: + glDrawElements(GL_TRIANGLES, primitiveCount * 3, indexSize, indexList); + break; + } +} + +//! draws a vertex primitive list in 2d +void COpenGLDriver::draw2DVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) +{ + if (!primitiveCount || !vertexCount) + return; + + if (!checkPrimitiveCount(primitiveCount)) + return; + + CNullDriver::draw2DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); + + if (vertices && !FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(vertices, vertexCount, vType); + + // draw everything + CacheHandler->getTextureCache().set(0, Material.getTexture(0)); + if (Material.MaterialType == EMT_ONETEXTURE_BLEND) { + E_BLEND_FACTOR srcFact; + E_BLEND_FACTOR dstFact; + E_MODULATE_FUNC modulo; + u32 alphaSource; + unpack_textureBlendFunc(srcFact, dstFact, modulo, alphaSource, Material.MaterialTypeParam); + setRenderStates2DMode(alphaSource & video::EAS_VERTEX_COLOR, (Material.getTexture(0) != 0), (alphaSource & video::EAS_TEXTURE) != 0); + } else + setRenderStates2DMode(Material.MaterialType == EMT_TRANSPARENT_VERTEX_ALPHA, (Material.getTexture(0) != 0), Material.MaterialType == EMT_TRANSPARENT_ALPHA_CHANNEL); + + if ((pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES)) + CacheHandler->setClientState(true, false, true, true); + else + CacheHandler->setClientState(true, false, true, false); + +// due to missing defines in OSX headers, we have to be more specific with this check +// #if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra) +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (vertices) { + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) { + switch (vType) { + case EVT_STANDARD: + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + break; + case EVT_2TCOORDS: + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Color); + break; + case EVT_TANGENTS: + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Color); + break; + } + } else { + // avoid passing broken pointer to OpenGL + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + } + + switch (vType) { + case EVT_STANDARD: + if (vertices) { + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + } else { + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), 0); + } + + if (Feature.MaxTextureUnits > 0 && CacheHandler->getTextureCache()[1]) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + else + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); + } + break; + case EVT_2TCOORDS: + if (vertices) { + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Pos); + } else { + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28)); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0)); + } + + if (Feature.MaxTextureUnits > 0) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (vertices) + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords2); + else + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36)); + } + break; + case EVT_TANGENTS: + if (vertices) { + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].TCoords); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Pos); + } else { + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24)); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28)); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0)); + } + + break; + } + + renderArray(indexList, primitiveCount, pType, iType); + + if (Feature.MaxTextureUnits > 0) { + if ((vType != EVT_STANDARD) || CacheHandler->getTextureCache()[1]) { + CacheHandler->setClientActiveTexture(GL_TEXTURE0 + 1); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + CacheHandler->setClientActiveTexture(GL_TEXTURE0); + } +} + +void COpenGLDriver::draw2DImage(const video::ITexture *texture, const core::position2d &destPos, + const core::rect &sourceRect, const core::rect *clipRect, SColor color, + bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + if (!sourceRect.isValid()) + return; + + // clip these coordinates + core::rect targetRect(destPos, sourceRect.getSize()); + if (clipRect) { + targetRect.clipAgainst(*clipRect); + if (targetRect.getWidth() < 0 || targetRect.getHeight() < 0) + return; + } + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + targetRect.clipAgainst(core::rect(0, 0, (s32)renderTargetSize.Width, (s32)renderTargetSize.Height)); + if (targetRect.getWidth() < 0 || targetRect.getHeight() < 0) + return; + + // ok, we've clipped everything. + // now draw it. + const core::dimension2d sourceSize(targetRect.getSize()); + const core::position2d sourcePos(sourceRect.UpperLeftCorner + (targetRect.UpperLeftCorner - destPos)); + + const core::dimension2d &ss = texture->getOriginalSize(); + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + const core::rect tcoords( + sourcePos.X * invW, + sourcePos.Y * invH, + (sourcePos.X + sourceSize.Width) * invW, + (sourcePos.Y + sourceSize.Height) * invH); + + disableTextures(1); + if (!CacheHandler->getTextureCache().set(0, texture)) + return; + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + Quad2DVertices[0].Color = color; + Quad2DVertices[1].Color = color; + Quad2DVertices[2].Color = color; + Quad2DVertices[3].Color = color; + + Quad2DVertices[0].Pos = core::vector3df((f32)targetRect.UpperLeftCorner.X, (f32)targetRect.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[1].Pos = core::vector3df((f32)targetRect.LowerRightCorner.X, (f32)targetRect.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[2].Pos = core::vector3df((f32)targetRect.LowerRightCorner.X, (f32)targetRect.LowerRightCorner.Y, 0.0f); + Quad2DVertices[3].Pos = core::vector3df((f32)targetRect.UpperLeftCorner.X, (f32)targetRect.LowerRightCorner.Y, 0.0f); + + Quad2DVertices[0].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + Quad2DVertices[1].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + Quad2DVertices[2].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + Quad2DVertices[3].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(Quad2DVertices, 4, EVT_STANDARD); + + CacheHandler->setClientState(true, false, true, true); + + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].TCoords); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Pos); + +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Color); + else { + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices); +} + +void COpenGLDriver::draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect, + const video::SColor *const colors, bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + const core::dimension2d &ss = texture->getOriginalSize(); + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + const core::rect tcoords( + sourceRect.UpperLeftCorner.X * invW, + sourceRect.UpperLeftCorner.Y * invH, + sourceRect.LowerRightCorner.X * invW, + sourceRect.LowerRightCorner.Y * invH); + + const video::SColor temp[4] = { + 0xFFFFFFFF, + 0xFFFFFFFF, + 0xFFFFFFFF, + 0xFFFFFFFF, + }; + + const video::SColor *const useColor = colors ? colors : temp; + + disableTextures(1); + if (!CacheHandler->getTextureCache().set(0, texture)) + return; + setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 || + useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255, + true, useAlphaChannelOfTexture); + + if (clipRect) { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + Quad2DVertices[0].Color = useColor[0]; + Quad2DVertices[1].Color = useColor[3]; + Quad2DVertices[2].Color = useColor[2]; + Quad2DVertices[3].Color = useColor[1]; + + Quad2DVertices[0].Pos = core::vector3df((f32)destRect.UpperLeftCorner.X, (f32)destRect.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[1].Pos = core::vector3df((f32)destRect.LowerRightCorner.X, (f32)destRect.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[2].Pos = core::vector3df((f32)destRect.LowerRightCorner.X, (f32)destRect.LowerRightCorner.Y, 0.0f); + Quad2DVertices[3].Pos = core::vector3df((f32)destRect.UpperLeftCorner.X, (f32)destRect.LowerRightCorner.Y, 0.0f); + + Quad2DVertices[0].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + Quad2DVertices[1].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + Quad2DVertices[2].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + Quad2DVertices[3].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(Quad2DVertices, 4, EVT_STANDARD); + + CacheHandler->setClientState(true, false, true, true); + + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].TCoords); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Pos); + +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Color); + else { + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices); + + if (clipRect) + glDisable(GL_SCISSOR_TEST); +} + +void COpenGLDriver::draw2DImage(const video::ITexture *texture, u32 layer, bool flip) +{ + if (!texture || !CacheHandler->getTextureCache().set(0, texture)) + return; + + disableTextures(1); + + setRenderStates2DMode(false, true, true); + + CacheHandler->setMatrixMode(GL_PROJECTION); + glLoadIdentity(); + CacheHandler->setMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + Transformation3DChanged = true; + + CacheHandler->setClientState(true, false, false, true); + + const core::vector3df positionData[4] = { + core::vector3df(-1.f, 1.f, 0.f), + core::vector3df(1.f, 1.f, 0.f), + core::vector3df(1.f, -1.f, 0.f), + core::vector3df(-1.f, -1.f, 0.f)}; + + glVertexPointer(2, GL_FLOAT, sizeof(core::vector3df), positionData); + + if (texture && texture->getType() == ETT_CUBEMAP) { + const core::vector3df texcoordCubeData[6][4] = { + + // GL_TEXTURE_CUBE_MAP_POSITIVE_X + { + core::vector3df(1.f, 1.f, 1.f), + core::vector3df(1.f, 1.f, -1.f), + core::vector3df(1.f, -1.f, -1.f), + core::vector3df(1.f, -1.f, 1.f)}, + + // GL_TEXTURE_CUBE_MAP_NEGATIVE_X + { + core::vector3df(-1.f, 1.f, -1.f), + core::vector3df(-1.f, 1.f, 1.f), + core::vector3df(-1.f, -1.f, 1.f), + core::vector3df(-1.f, -1.f, -1.f)}, + + // GL_TEXTURE_CUBE_MAP_POSITIVE_Y + { + core::vector3df(-1.f, 1.f, -1.f), + core::vector3df(1.f, 1.f, -1.f), + core::vector3df(1.f, 1.f, 1.f), + core::vector3df(-1.f, 1.f, 1.f)}, + + // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y + { + core::vector3df(-1.f, -1.f, 1.f), + core::vector3df(-1.f, -1.f, -1.f), + core::vector3df(1.f, -1.f, -1.f), + core::vector3df(1.f, -1.f, 1.f)}, + + // GL_TEXTURE_CUBE_MAP_POSITIVE_Z + { + core::vector3df(-1.f, 1.f, 1.f), + core::vector3df(-1.f, -1.f, 1.f), + core::vector3df(1.f, -1.f, 1.f), + core::vector3df(1.f, 1.f, 1.f)}, + + // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + { + core::vector3df(1.f, 1.f, -1.f), + core::vector3df(-1.f, 1.f, -1.f), + core::vector3df(-1.f, -1.f, -1.f), + core::vector3df(1.f, -1.f, -1.f)}}; + + const core::vector3df texcoordData[4] = { + texcoordCubeData[layer][(flip) ? 3 : 0], + texcoordCubeData[layer][(flip) ? 2 : 1], + texcoordCubeData[layer][(flip) ? 1 : 2], + texcoordCubeData[layer][(flip) ? 0 : 3]}; + + glTexCoordPointer(3, GL_FLOAT, sizeof(core::vector3df), texcoordData); + } else { + f32 modificator = (flip) ? 1.f : 0.f; + + core::vector2df texcoordData[4] = { + core::vector2df(0.f, 0.f + modificator), + core::vector2df(1.f, 0.f + modificator), + core::vector2df(1.f, 1.f - modificator), + core::vector2df(0.f, 1.f - modificator)}; + + glTexCoordPointer(2, GL_FLOAT, sizeof(core::vector2df), texcoordData); + } + + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices); +} + +//! draws a set of 2d images, using a color and the alpha channel of the +//! texture if desired. +void COpenGLDriver::draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect, + SColor color, + bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + const u32 drawCount = core::min_(positions.size(), sourceRects.size()); + + const core::dimension2d &ss = texture->getOriginalSize(); + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + disableTextures(1); + if (!CacheHandler->getTextureCache().set(0, texture)) + return; + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + Quad2DVertices[0].Color = color; + Quad2DVertices[1].Color = color; + Quad2DVertices[2].Color = color; + Quad2DVertices[3].Color = color; + + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(Quad2DVertices, 4, EVT_STANDARD); + + CacheHandler->setClientState(true, false, true, true); + + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].TCoords); + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Pos); + +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Color); + else { + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + + for (u32 i = 0; i < drawCount; ++i) { + if (!sourceRects[i].isValid()) + continue; + + core::position2d targetPos(positions[i]); + core::position2d sourcePos(sourceRects[i].UpperLeftCorner); + // This needs to be signed as it may go negative. + core::dimension2d sourceSize(sourceRects[i].getSize()); + if (clipRect) { + if (targetPos.X < clipRect->UpperLeftCorner.X) { + sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X; + if (sourceSize.Width <= 0) + continue; + + sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X; + targetPos.X = clipRect->UpperLeftCorner.X; + } + + if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X) { + sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X; + if (sourceSize.Width <= 0) + continue; + } + + if (targetPos.Y < clipRect->UpperLeftCorner.Y) { + sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y; + if (sourceSize.Height <= 0) + continue; + + sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y; + targetPos.Y = clipRect->UpperLeftCorner.Y; + } + + if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y) { + sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y; + if (sourceSize.Height <= 0) + continue; + } + } + + // clip these coordinates + + if (targetPos.X < 0) { + sourceSize.Width += targetPos.X; + if (sourceSize.Width <= 0) + continue; + + sourcePos.X -= targetPos.X; + targetPos.X = 0; + } + + if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width) { + sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width; + if (sourceSize.Width <= 0) + continue; + } + + if (targetPos.Y < 0) { + sourceSize.Height += targetPos.Y; + if (sourceSize.Height <= 0) + continue; + + sourcePos.Y -= targetPos.Y; + targetPos.Y = 0; + } + + if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height) { + sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height; + if (sourceSize.Height <= 0) + continue; + } + + // ok, we've clipped everything. + // now draw it. + + const core::rect tcoords( + sourcePos.X * invW, + sourcePos.Y * invH, + (sourcePos.X + sourceSize.Width) * invW, + (sourcePos.Y + sourceSize.Height) * invH); + + const core::rect poss(targetPos, sourceSize); + + Quad2DVertices[0].Pos = core::vector3df((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[1].Pos = core::vector3df((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[2].Pos = core::vector3df((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0.0f); + Quad2DVertices[3].Pos = core::vector3df((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0.0f); + + Quad2DVertices[0].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + Quad2DVertices[1].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + Quad2DVertices[2].TCoords = core::vector2df(tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + Quad2DVertices[3].TCoords = core::vector2df(tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices); + } +} + +//! draw a 2d rectangle +void COpenGLDriver::draw2DRectangle(SColor color, const core::rect &position, + const core::rect *clip) +{ + disableTextures(); + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + glColor4ub(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + glRectf(GLfloat(pos.UpperLeftCorner.X), GLfloat(pos.UpperLeftCorner.Y), + GLfloat(pos.LowerRightCorner.X), GLfloat(pos.LowerRightCorner.Y)); +} + +//! draw an 2d rectangle +void COpenGLDriver::draw2DRectangle(const core::rect &position, + SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip) +{ + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + disableTextures(); + + setRenderStates2DMode(colorLeftUp.getAlpha() < 255 || + colorRightUp.getAlpha() < 255 || + colorLeftDown.getAlpha() < 255 || + colorRightDown.getAlpha() < 255, + false, false); + + Quad2DVertices[0].Color = colorLeftUp; + Quad2DVertices[1].Color = colorRightUp; + Quad2DVertices[2].Color = colorRightDown; + Quad2DVertices[3].Color = colorLeftDown; + + Quad2DVertices[0].Pos = core::vector3df((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[1].Pos = core::vector3df((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0.0f); + Quad2DVertices[2].Pos = core::vector3df((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0.0f); + Quad2DVertices[3].Pos = core::vector3df((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0.0f); + + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(Quad2DVertices, 4, EVT_STANDARD); + + CacheHandler->setClientState(true, false, true, false); + + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Pos); + +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Color); + else { + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices); +} + +//! Draws a 2d line. +void COpenGLDriver::draw2DLine(const core::position2d &start, + const core::position2d &end, SColor color) +{ + { + disableTextures(); + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + Quad2DVertices[0].Color = color; + Quad2DVertices[1].Color = color; + + Quad2DVertices[0].Pos = core::vector3df((f32)start.X, (f32)start.Y, 0.0f); + Quad2DVertices[1].Pos = core::vector3df((f32)end.X, (f32)end.Y, 0.0f); + + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(Quad2DVertices, 2, EVT_STANDARD); + + CacheHandler->setClientState(true, false, true, false); + + glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Pos); + +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Color); + else { + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + + glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, Quad2DIndices); + + // Draw sometimes non-drawn first & last pixel (search for "diamond exit rule") + // HACK this messes with alpha blending + glDrawArrays(GL_POINTS, 0, 1); + glDrawArrays(GL_POINTS, 1, 1); + } +} + +//! disables all textures beginning with the optional fromStage parameter. Otherwise all texture stages are disabled. +//! Returns whether disabling was successful or not. +bool COpenGLDriver::disableTextures(u32 fromStage) +{ + bool result = true; + for (u32 i = fromStage; i < Feature.MaxTextureUnits; ++i) { + result &= CacheHandler->getTextureCache().set(i, 0, EST_ACTIVE_ON_CHANGE); + } + return result; +} + +//! creates a matrix in supplied GLfloat array to pass to OpenGL +inline void COpenGLDriver::getGLMatrix(GLfloat gl_matrix[16], const core::matrix4 &m) +{ + memcpy(gl_matrix, m.pointer(), 16 * sizeof(f32)); +} + +//! creates a opengltexturematrix from a D3D style texture matrix +inline void COpenGLDriver::getGLTextureMatrix(GLfloat *o, const core::matrix4 &m) +{ + o[0] = m[0]; + o[1] = m[1]; + o[2] = 0.f; + o[3] = 0.f; + + o[4] = m[4]; + o[5] = m[5]; + o[6] = 0.f; + o[7] = 0.f; + + o[8] = 0.f; + o[9] = 0.f; + o[10] = 1.f; + o[11] = 0.f; + + o[12] = m[8]; + o[13] = m[9]; + o[14] = 0.f; + o[15] = 1.f; +} + +ITexture *COpenGLDriver::createDeviceDependentTexture(const io::path &name, IImage *image) +{ + core::array imageArray(1); + imageArray.push_back(image); + + COpenGLTexture *texture = new COpenGLTexture(name, imageArray, ETT_2D, this); + + return texture; +} + +ITexture *COpenGLDriver::createDeviceDependentTextureCubemap(const io::path &name, const core::array &image) +{ + COpenGLTexture *texture = new COpenGLTexture(name, image, ETT_CUBEMAP, this); + + return texture; +} + +void COpenGLDriver::disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag) +{ + CNullDriver::disableFeature(feature, flag); + + if (feature == EVDF_TEXTURE_CUBEMAP_SEAMLESS) { + if (queryFeature(feature)) + glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + else if (COpenGLExtensionHandler::queryFeature(feature)) + glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + } +} + +//! Sets a material. All 3d drawing functions draw geometry now using this material. +void COpenGLDriver::setMaterial(const SMaterial &material) +{ + Material = material; + OverrideMaterial.apply(Material); + + for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) { + const ITexture *texture = Material.getTexture(i); + CacheHandler->getTextureCache().set(i, texture, EST_ACTIVE_ON_CHANGE); + if (texture) { + setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); + } + } +} + +//! prints error if an error happened. +bool COpenGLDriver::testGLError(int code) +{ +#ifdef _DEBUG + GLenum g = glGetError(); + switch (g) { + case GL_NO_ERROR: + return false; + case GL_INVALID_ENUM: + os::Printer::log("GL_INVALID_ENUM", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_INVALID_VALUE: + os::Printer::log("GL_INVALID_VALUE", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_INVALID_OPERATION: + os::Printer::log("GL_INVALID_OPERATION", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_STACK_OVERFLOW: + os::Printer::log("GL_STACK_OVERFLOW", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_STACK_UNDERFLOW: + os::Printer::log("GL_STACK_UNDERFLOW", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_OUT_OF_MEMORY: + os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_TABLE_TOO_LARGE: + os::Printer::log("GL_TABLE_TOO_LARGE", core::stringc(code).c_str(), ELL_ERROR); + break; +#if defined(GL_EXT_framebuffer_object) + case GL_INVALID_FRAMEBUFFER_OPERATION_EXT: + os::Printer::log("GL_INVALID_FRAMEBUFFER_OPERATION", core::stringc(code).c_str(), ELL_ERROR); + break; +#endif + }; + // _IRR_DEBUG_BREAK_IF(true); + return true; +#else + return false; +#endif +} + +//! sets the needed renderstates +void COpenGLDriver::setRenderStates3DMode() +{ + if (CurrentRenderMode != ERM_3D) { + // Reset Texture Stages + CacheHandler->setBlend(false); + CacheHandler->setAlphaTest(false); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + CacheHandler->setActiveTexture(GL_TEXTURE0_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + // switch back the matrices + CacheHandler->setMatrixMode(GL_MODELVIEW); + glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer()); + + CacheHandler->setMatrixMode(GL_PROJECTION); + glLoadMatrixf(Matrices[ETS_PROJECTION].pointer()); + + ResetRenderStates = true; +#ifdef GL_EXT_clip_volume_hint + if (FeatureAvailable[IRR_EXT_clip_volume_hint]) + glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_NICEST); +#endif + } + + if (ResetRenderStates || LastMaterial != Material) { + // unset old material + + if (LastMaterial.MaterialType != Material.MaterialType && + static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + + // set new material. + if (static_cast(Material.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial( + Material, LastMaterial, ResetRenderStates, this); + + LastMaterial = Material; + CacheHandler->correctCacheMaterial(LastMaterial); + ResetRenderStates = false; + } + + if (static_cast(Material.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, video::EVT_STANDARD); + + CurrentRenderMode = ERM_3D; +} + +//! Get native wrap mode value +GLint COpenGLDriver::getTextureWrapMode(const u8 clamp) +{ + GLint mode = GL_REPEAT; + switch (clamp) { + case ETC_REPEAT: + mode = GL_REPEAT; + break; + case ETC_CLAMP: + mode = GL_CLAMP; + break; + case ETC_CLAMP_TO_EDGE: +#ifdef GL_VERSION_1_2 + if (Version > 101) + mode = GL_CLAMP_TO_EDGE; + else +#endif +#ifdef GL_SGIS_texture_edge_clamp + if (FeatureAvailable[IRR_SGIS_texture_edge_clamp]) + mode = GL_CLAMP_TO_EDGE_SGIS; + else +#endif + // fallback + mode = GL_CLAMP; + break; + case ETC_CLAMP_TO_BORDER: +#ifdef GL_VERSION_1_3 + if (Version > 102) + mode = GL_CLAMP_TO_BORDER; + else +#endif +#ifdef GL_ARB_texture_border_clamp + if (FeatureAvailable[IRR_ARB_texture_border_clamp]) + mode = GL_CLAMP_TO_BORDER_ARB; + else +#endif +#ifdef GL_SGIS_texture_border_clamp + if (FeatureAvailable[IRR_SGIS_texture_border_clamp]) + mode = GL_CLAMP_TO_BORDER_SGIS; + else +#endif + // fallback + mode = GL_CLAMP; + break; + case ETC_MIRROR: +#ifdef GL_VERSION_1_4 + if (Version > 103) + mode = GL_MIRRORED_REPEAT; + else +#endif +#ifdef GL_ARB_texture_border_clamp + if (FeatureAvailable[IRR_ARB_texture_mirrored_repeat]) + mode = GL_MIRRORED_REPEAT_ARB; + else +#endif +#ifdef GL_IBM_texture_mirrored_repeat + if (FeatureAvailable[IRR_IBM_texture_mirrored_repeat]) + mode = GL_MIRRORED_REPEAT_IBM; + else +#endif + mode = GL_REPEAT; + break; + case ETC_MIRROR_CLAMP: +#ifdef GL_EXT_texture_mirror_clamp + if (FeatureAvailable[IRR_EXT_texture_mirror_clamp]) + mode = GL_MIRROR_CLAMP_EXT; + else +#endif +#if defined(GL_ATI_texture_mirror_once) + if (FeatureAvailable[IRR_ATI_texture_mirror_once]) + mode = GL_MIRROR_CLAMP_ATI; + else +#endif + mode = GL_CLAMP; + break; + case ETC_MIRROR_CLAMP_TO_EDGE: +#ifdef GL_EXT_texture_mirror_clamp + if (FeatureAvailable[IRR_EXT_texture_mirror_clamp]) + mode = GL_MIRROR_CLAMP_TO_EDGE_EXT; + else +#endif +#if defined(GL_ATI_texture_mirror_once) + if (FeatureAvailable[IRR_ATI_texture_mirror_once]) + mode = GL_MIRROR_CLAMP_TO_EDGE_ATI; + else +#endif + mode = GL_CLAMP; + break; + case ETC_MIRROR_CLAMP_TO_BORDER: +#ifdef GL_EXT_texture_mirror_clamp + if (FeatureAvailable[IRR_EXT_texture_mirror_clamp]) + mode = GL_MIRROR_CLAMP_TO_BORDER_EXT; + else +#endif + mode = GL_CLAMP; + break; + } + return mode; +} + +//! Can be called by an IMaterialRenderer to make its work easier. +void COpenGLDriver::setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, + bool resetAllRenderStates) +{ + // Fixed pipeline isn't important for shader based materials + + E_OPENGL_FIXED_PIPELINE_STATE tempState = FixedPipelineState; + + if (resetAllRenderStates || tempState == EOFPS_ENABLE || tempState == EOFPS_DISABLE_TO_ENABLE) { + // material colors + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || + lastmaterial.ColorMaterial != material.ColorMaterial) { + switch (material.ColorMaterial) { + case ECM_NONE: + glDisable(GL_COLOR_MATERIAL); + break; + case ECM_DIFFUSE: + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + break; + case ECM_AMBIENT: + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); + break; + case ECM_EMISSIVE: + glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION); + break; + case ECM_SPECULAR: + glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); + break; + case ECM_DIFFUSE_AND_AMBIENT: + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + break; + } + if (material.ColorMaterial != ECM_NONE) + glEnable(GL_COLOR_MATERIAL); + } + + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || + lastmaterial.AmbientColor != material.AmbientColor || + lastmaterial.DiffuseColor != material.DiffuseColor || + lastmaterial.EmissiveColor != material.EmissiveColor || + lastmaterial.ColorMaterial != material.ColorMaterial) { + GLfloat color[4]; + + const f32 inv = 1.0f / 255.0f; + + if ((material.ColorMaterial != video::ECM_AMBIENT) && + (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) { + color[0] = material.AmbientColor.getRed() * inv; + color[1] = material.AmbientColor.getGreen() * inv; + color[2] = material.AmbientColor.getBlue() * inv; + color[3] = material.AmbientColor.getAlpha() * inv; + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); + } + + if ((material.ColorMaterial != video::ECM_DIFFUSE) && + (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) { + color[0] = material.DiffuseColor.getRed() * inv; + color[1] = material.DiffuseColor.getGreen() * inv; + color[2] = material.DiffuseColor.getBlue() * inv; + color[3] = material.DiffuseColor.getAlpha() * inv; + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); + } + + if (material.ColorMaterial != video::ECM_EMISSIVE) { + color[0] = material.EmissiveColor.getRed() * inv; + color[1] = material.EmissiveColor.getGreen() * inv; + color[2] = material.EmissiveColor.getBlue() * inv; + color[3] = material.EmissiveColor.getAlpha() * inv; + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); + } + } + + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || + lastmaterial.SpecularColor != material.SpecularColor || + lastmaterial.Shininess != material.Shininess || + lastmaterial.ColorMaterial != material.ColorMaterial) { + GLfloat color[4] = {0.f, 0.f, 0.f, 1.f}; + const f32 inv = 1.0f / 255.0f; + + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess); + // disable Specular colors if no shininess is set + if ((material.Shininess != 0.0f) && + (material.ColorMaterial != video::ECM_SPECULAR)) { +#ifdef GL_EXT_separate_specular_color + if (FeatureAvailable[IRR_EXT_separate_specular_color]) + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); +#endif + color[0] = material.SpecularColor.getRed() * inv; + color[1] = material.SpecularColor.getGreen() * inv; + color[2] = material.SpecularColor.getBlue() * inv; + color[3] = material.SpecularColor.getAlpha() * inv; + } +#ifdef GL_EXT_separate_specular_color + else if (FeatureAvailable[IRR_EXT_separate_specular_color]) + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); +#endif + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); + } + + // shademode + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || + lastmaterial.GouraudShading != material.GouraudShading) { + if (material.GouraudShading) + glShadeModel(GL_SMOOTH); + else + glShadeModel(GL_FLAT); + } + + // lighting + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || + lastmaterial.Lighting != material.Lighting) { + if (material.Lighting) + glEnable(GL_LIGHTING); + else + glDisable(GL_LIGHTING); + } + + // fog + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || + lastmaterial.FogEnable != material.FogEnable) { + if (material.FogEnable) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + } + + // normalization + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || + lastmaterial.NormalizeNormals != material.NormalizeNormals) { + if (material.NormalizeNormals) + glEnable(GL_NORMALIZE); + else + glDisable(GL_NORMALIZE); + } + + // Set fixed pipeline as active. + tempState = EOFPS_ENABLE; + } else if (tempState == EOFPS_ENABLE_TO_DISABLE) { + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_LIGHTING); + glDisable(GL_FOG); + glDisable(GL_NORMALIZE); + + // Set programmable pipeline as active. + tempState = EOFPS_DISABLE; + } + + // tempState == EOFPS_DISABLE - driver doesn't calls functions related to fixed pipeline. + + // fillmode - fixed pipeline call, but it emulate GL_LINES behaviour in rendering, so it stay here. + if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud)) + glPolygonMode(GL_FRONT_AND_BACK, material.Wireframe ? GL_LINE : material.PointCloud ? GL_POINT + : GL_FILL); + + // ZBuffer + switch (material.ZBuffer) { + case ECFN_DISABLED: + CacheHandler->setDepthTest(false); + break; + case ECFN_LESSEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LEQUAL); + break; + case ECFN_EQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_EQUAL); + break; + case ECFN_LESS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LESS); + break; + case ECFN_NOTEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NOTEQUAL); + break; + case ECFN_GREATEREQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GEQUAL); + break; + case ECFN_GREATER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GREATER); + break; + case ECFN_ALWAYS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_ALWAYS); + break; + case ECFN_NEVER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NEVER); + break; + default: + break; + } + + // ZWrite + if (getWriteZBuffer(material)) { + CacheHandler->setDepthMask(true); + } else { + CacheHandler->setDepthMask(false); + } + + // Back face culling + if ((material.FrontfaceCulling) && (material.BackfaceCulling)) { + CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK); + CacheHandler->setCullFace(true); + } else if (material.BackfaceCulling) { + CacheHandler->setCullFaceFunc(GL_BACK); + CacheHandler->setCullFace(true); + } else if (material.FrontfaceCulling) { + CacheHandler->setCullFaceFunc(GL_FRONT); + CacheHandler->setCullFace(true); + } else { + CacheHandler->setCullFace(false); + } + + // Color Mask + CacheHandler->setColorMask(material.ColorMask); + + // Blend Equation + if (material.BlendOperation == EBO_NONE) + CacheHandler->setBlend(false); + else { + CacheHandler->setBlend(true); + +#if defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op) || defined(GL_VERSION_1_4) + if (queryFeature(EVDF_BLEND_OPERATIONS)) { + switch (material.BlendOperation) { + case EBO_SUBTRACT: +#if defined(GL_VERSION_1_4) + CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT); +#elif defined(GL_EXT_blend_subtract) + CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT_EXT); +#endif + break; + case EBO_REVSUBTRACT: +#if defined(GL_VERSION_1_4) + CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT); +#elif defined(GL_EXT_blend_subtract) + CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT_EXT); +#endif + break; + case EBO_MIN: +#if defined(GL_VERSION_1_4) + CacheHandler->setBlendEquation(GL_MIN); +#elif defined(GL_EXT_blend_minmax) + CacheHandler->setBlendEquation(GL_MIN_EXT); +#endif + break; + case EBO_MAX: +#if defined(GL_VERSION_1_4) + CacheHandler->setBlendEquation(GL_MAX); +#elif defined(GL_EXT_blend_minmax) + CacheHandler->setBlendEquation(GL_MAX_EXT); +#endif + break; + case EBO_MIN_FACTOR: +#if defined(GL_AMD_blend_minmax_factor) + if (FeatureAvailable[IRR_AMD_blend_minmax_factor]) + CacheHandler->setBlendEquation(GL_FACTOR_MIN_AMD); +#endif + // fallback in case of missing extension +#if defined(GL_VERSION_1_4) +#if defined(GL_AMD_blend_minmax_factor) + else +#endif + CacheHandler->setBlendEquation(GL_MIN); +#endif + break; + case EBO_MAX_FACTOR: +#if defined(GL_AMD_blend_minmax_factor) + if (FeatureAvailable[IRR_AMD_blend_minmax_factor]) + CacheHandler->setBlendEquation(GL_FACTOR_MAX_AMD); +#endif + // fallback in case of missing extension +#if defined(GL_VERSION_1_4) +#if defined(GL_AMD_blend_minmax_factor) + else +#endif + CacheHandler->setBlendEquation(GL_MAX); +#endif + break; + case EBO_MIN_ALPHA: +#if defined(GL_SGIX_blend_alpha_minmax) + if (FeatureAvailable[IRR_SGIX_blend_alpha_minmax]) + CacheHandler->setBlendEquation(GL_ALPHA_MIN_SGIX); + // fallback in case of missing extension + else if (FeatureAvailable[IRR_EXT_blend_minmax]) + CacheHandler->setBlendEquation(GL_MIN_EXT); +#endif + break; + case EBO_MAX_ALPHA: +#if defined(GL_SGIX_blend_alpha_minmax) + if (FeatureAvailable[IRR_SGIX_blend_alpha_minmax]) + CacheHandler->setBlendEquation(GL_ALPHA_MAX_SGIX); + // fallback in case of missing extension + else if (FeatureAvailable[IRR_EXT_blend_minmax]) + CacheHandler->setBlendEquation(GL_MAX_EXT); +#endif + break; + default: +#if defined(GL_VERSION_1_4) + CacheHandler->setBlendEquation(GL_FUNC_ADD); +#elif defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op) + CacheHandler->setBlendEquation(GL_FUNC_ADD_EXT); +#endif + break; + } + } +#endif + } + + // Blend Factor + if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF? + && material.MaterialType != EMT_ONETEXTURE_BLEND) { + E_BLEND_FACTOR srcRGBFact = EBF_ZERO; + E_BLEND_FACTOR dstRGBFact = EBF_ZERO; + E_BLEND_FACTOR srcAlphaFact = EBF_ZERO; + E_BLEND_FACTOR dstAlphaFact = EBF_ZERO; + E_MODULATE_FUNC modulo = EMFN_MODULATE_1X; + u32 alphaSource = 0; + + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, material.BlendFactor); + + if (queryFeature(EVDF_BLEND_SEPARATE)) { + CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact), + getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact)); + } else { + CacheHandler->setBlendFunc(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact)); + } + } + + // Polygon Offset + if (queryFeature(EVDF_POLYGON_OFFSET) && (resetAllRenderStates || + lastmaterial.PolygonOffsetSlopeScale != material.PolygonOffsetSlopeScale || + lastmaterial.PolygonOffsetDepthBias != material.PolygonOffsetDepthBias)) { + glDisable(lastmaterial.Wireframe ? GL_POLYGON_OFFSET_LINE : lastmaterial.PointCloud ? GL_POLYGON_OFFSET_POINT + : GL_POLYGON_OFFSET_FILL); + if (material.PolygonOffsetSlopeScale || material.PolygonOffsetDepthBias) { + glEnable(material.Wireframe ? GL_POLYGON_OFFSET_LINE : material.PointCloud ? GL_POLYGON_OFFSET_POINT + : GL_POLYGON_OFFSET_FILL); + + glPolygonOffset(material.PolygonOffsetSlopeScale, material.PolygonOffsetDepthBias); + } else { + glPolygonOffset(0.0f, 0.f); + } + } + + // thickness + if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) { + if (AntiAlias) { + // glPointSize(core::clamp(static_cast(material.Thickness), DimSmoothedPoint[0], DimSmoothedPoint[1])); + // we don't use point smoothing + glPointSize(core::clamp(static_cast(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1])); + glLineWidth(core::clamp(static_cast(material.Thickness), DimSmoothedLine[0], DimSmoothedLine[1])); + } else { + glPointSize(core::clamp(static_cast(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1])); + glLineWidth(core::clamp(static_cast(material.Thickness), DimAliasedLine[0], DimAliasedLine[1])); + } + } + + // Anti aliasing + if ((resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing) && FeatureAvailable[IRR_ARB_multisample]) { + if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) + glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); + else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) + glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); + + if ((AntiAlias >= 2) && (material.AntiAliasing & (EAAM_SIMPLE | EAAM_QUALITY))) { + glEnable(GL_MULTISAMPLE_ARB); +#ifdef GL_NV_multisample_filter_hint + if (FeatureAvailable[IRR_NV_multisample_filter_hint]) { + if ((material.AntiAliasing & EAAM_QUALITY) == EAAM_QUALITY) + glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); + else + glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_FASTEST); + } +#endif + } else + glDisable(GL_MULTISAMPLE_ARB); + } + + // Texture parameters + setTextureRenderStates(material, resetAllRenderStates); + + // set current fixed pipeline state + FixedPipelineState = tempState; +} + +//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. +void COpenGLDriver::setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates) +{ + // Set textures to TU/TIU and apply filters to them + + for (s32 i = Feature.MaxTextureUnits - 1; i >= 0; --i) { + bool fixedPipeline = false; + + if (FixedPipelineState == EOFPS_ENABLE || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE) + fixedPipeline = true; + + const COpenGLTexture *tmpTexture = CacheHandler->getTextureCache().get(i); + + if (tmpTexture) { + CacheHandler->setActiveTexture(GL_TEXTURE0 + i); + + // Minetest uses the first texture matrix even with the programmable pipeline + if (fixedPipeline || i == 0) { + const bool isRTT = tmpTexture->isRenderTarget(); + + CacheHandler->setMatrixMode(GL_TEXTURE); + + if (!isRTT && Matrices[ETS_TEXTURE_0 + i].isIdentity()) + glLoadIdentity(); + else { + GLfloat glmat[16]; + if (isRTT) + getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i] * TextureFlipMatrix); + else + getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i]); + glLoadMatrixf(glmat); + } + } + + const GLenum tmpType = tmpTexture->getOpenGLTextureType(); + + COpenGLTexture::SStatesCache &statesCache = tmpTexture->getStatesCache(); + + if (resetAllRenderstates) + statesCache.IsCached = false; + +#ifdef GL_VERSION_2_1 + if (Version >= 201) { + if (!statesCache.IsCached || material.TextureLayers[i].LODBias != statesCache.LODBias) { + if (material.TextureLayers[i].LODBias) { + const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias); + glTexParameterf(tmpType, GL_TEXTURE_LOD_BIAS, tmp); + } else + glTexParameterf(tmpType, GL_TEXTURE_LOD_BIAS, 0.f); + + statesCache.LODBias = material.TextureLayers[i].LODBias; + } + } else if (FeatureAvailable[IRR_EXT_texture_lod_bias]) { + if (material.TextureLayers[i].LODBias) { + const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp); + } else + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f); + } +#elif defined(GL_EXT_texture_lod_bias) + if (FeatureAvailable[IRR_EXT_texture_lod_bias]) { + if (material.TextureLayers[i].LODBias) { + const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp); + } else + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f); + } +#endif + + if (!statesCache.IsCached || material.TextureLayers[i].MagFilter != statesCache.MagFilter) { + E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter; + glTexParameteri(tmpType, GL_TEXTURE_MAG_FILTER, + magFilter == ETMAGF_NEAREST ? GL_NEAREST : (assert(magFilter == ETMAGF_LINEAR), GL_LINEAR)); + + statesCache.MagFilter = magFilter; + } + + if (material.UseMipMaps && tmpTexture->hasMipMaps()) { + if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter || + !statesCache.MipMapStatus) { + E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; + glTexParameteri(tmpType, GL_TEXTURE_MIN_FILTER, + minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST : minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST + : minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR + : (assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR)); + + statesCache.MinFilter = minFilter; + statesCache.MipMapStatus = true; + } + } else { + if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter || + statesCache.MipMapStatus) { + E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; + glTexParameteri(tmpType, GL_TEXTURE_MIN_FILTER, + (minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST : (assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR)); + + statesCache.MinFilter = minFilter; + statesCache.MipMapStatus = false; + } + } + +#ifdef GL_EXT_texture_filter_anisotropic + if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic] && + (!statesCache.IsCached || material.TextureLayers[i].AnisotropicFilter != statesCache.AnisotropicFilter)) { + glTexParameteri(tmpType, GL_TEXTURE_MAX_ANISOTROPY_EXT, + material.TextureLayers[i].AnisotropicFilter > 1 ? core::min_(MaxAnisotropy, material.TextureLayers[i].AnisotropicFilter) : 1); + + statesCache.AnisotropicFilter = material.TextureLayers[i].AnisotropicFilter; + } +#endif + + if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapU != statesCache.WrapU) { + glTexParameteri(tmpType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayers[i].TextureWrapU)); + statesCache.WrapU = material.TextureLayers[i].TextureWrapU; + } + + if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapV != statesCache.WrapV) { + glTexParameteri(tmpType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayers[i].TextureWrapV)); + statesCache.WrapV = material.TextureLayers[i].TextureWrapV; + } + + if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapW != statesCache.WrapW) { + glTexParameteri(tmpType, GL_TEXTURE_WRAP_R, getTextureWrapMode(material.TextureLayers[i].TextureWrapW)); + statesCache.WrapW = material.TextureLayers[i].TextureWrapW; + } + + statesCache.IsCached = true; + } + } +} + +//! Enable the 2d override material +void COpenGLDriver::enableMaterial2D(bool enable) +{ + if (!enable) + CurrentRenderMode = ERM_NONE; + CNullDriver::enableMaterial2D(enable); +} + +//! sets the needed renderstates +void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) +{ + // 2d methods uses fixed pipeline + if (FixedPipelineState == COpenGLDriver::EOFPS_DISABLE) + FixedPipelineState = COpenGLDriver::EOFPS_DISABLE_TO_ENABLE; + else + FixedPipelineState = COpenGLDriver::EOFPS_ENABLE; + + bool resetAllRenderStates = false; + + if (CurrentRenderMode != ERM_2D || Transformation3DChanged) { + // unset last 3d material + if (CurrentRenderMode == ERM_3D) { + if (static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + } + + if (Transformation3DChanged) { + CacheHandler->setMatrixMode(GL_PROJECTION); + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + core::matrix4 m(core::matrix4::EM4CONST_NOTHING); + m.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0f, 1.0f); + m.setTranslation(core::vector3df(-1, 1, 0)); + glLoadMatrixf(m.pointer()); + + CacheHandler->setMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.375f, 0.375f, 0.0f); + + Transformation3DChanged = false; + } + + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + CacheHandler->setBlendEquation(GL_FUNC_ADD); + +#ifdef GL_EXT_clip_volume_hint + if (FeatureAvailable[IRR_EXT_clip_volume_hint]) + glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_FASTEST); +#endif + + resetAllRenderStates = true; + } + + SMaterial currentMaterial = (!OverrideMaterial2DEnabled) ? InitMaterial2D : OverrideMaterial2D; + currentMaterial.Lighting = false; + + if (texture) { + setTransform(ETS_TEXTURE_0, core::IdentityMatrix); + + // Due to the transformation change, the previous line would call a reset each frame + // but we can safely reset the variable as it was false before + Transformation3DChanged = false; + } else { + CacheHandler->getTextureCache().set(0, 0); + } + + setBasicRenderStates(currentMaterial, LastMaterial, resetAllRenderStates); + + LastMaterial = currentMaterial; + CacheHandler->correctCacheMaterial(LastMaterial); + + // no alphaChannel without texture + alphaChannel &= texture; + + if (alphaChannel || alpha) { + CacheHandler->setBlend(true); + CacheHandler->setAlphaTest(true); + CacheHandler->setAlphaFunc(GL_GREATER, 0.f); + } else { + CacheHandler->setBlend(false); + CacheHandler->setAlphaTest(false); + } + + if (texture) { + CacheHandler->setActiveTexture(GL_TEXTURE0_ARB); + + if (alphaChannel) { + // if alpha and alpha texture just modulate, otherwise use only the alpha channel + if (alpha) { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } else { +#if defined(GL_ARB_texture_env_combine) || defined(GL_EXT_texture_env_combine) + if (FeatureAvailable[IRR_ARB_texture_env_combine] || FeatureAvailable[IRR_EXT_texture_env_combine]) { +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); + // rgb always modulates + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE); + // rgb always modulates + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT); +#endif + } else +#endif + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + } else { + if (alpha) { +#if defined(GL_ARB_texture_env_combine) || defined(GL_EXT_texture_env_combine) + if (FeatureAvailable[IRR_ARB_texture_env_combine] || FeatureAvailable[IRR_EXT_texture_env_combine]) { +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB); + // rgb always modulates + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT); + // rgb always modulates + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT); +#endif + } else +#endif + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } else { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + } + } + + CurrentRenderMode = ERM_2D; +} + +//! \return Returns the name of the video driver. +const char *COpenGLDriver::getName() const +{ + return Name.c_str(); +} + +//! Sets the dynamic ambient light color. The default color is +//! (0,0,0,0) which means it is dark. +//! \param color: New color of the ambient light. +void COpenGLDriver::setAmbientLight(const SColorf &color) +{ + CNullDriver::setAmbientLight(color); + GLfloat data[4] = {color.r, color.g, color.b, color.a}; + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data); +} + +// this code was sent in by Oliver Klems, thank you! (I modified the glViewport +// method just a bit. +void COpenGLDriver::setViewPort(const core::rect &area) +{ + core::rect vp = area; + core::rect rendert(0, 0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height); + vp.clipAgainst(rendert); + + if (vp.getHeight() > 0 && vp.getWidth() > 0) + CacheHandler->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight()); + + ViewPort = vp; +} + +void COpenGLDriver::setViewPortRaw(u32 width, u32 height) +{ + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); +} + +//! Sets the fog mode. +void COpenGLDriver::setFog(SColor c, E_FOG_TYPE fogType, f32 start, + f32 end, f32 density, bool pixelFog, bool rangeFog) +{ + CNullDriver::setFog(c, fogType, start, end, density, pixelFog, rangeFog); + + glFogf(GL_FOG_MODE, GLfloat((fogType == EFT_FOG_LINEAR) ? GL_LINEAR : (fogType == EFT_FOG_EXP) ? GL_EXP + : GL_EXP2)); + +#ifdef GL_EXT_fog_coord + if (FeatureAvailable[IRR_EXT_fog_coord]) + glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH); +#endif +#ifdef GL_NV_fog_distance + if (FeatureAvailable[IRR_NV_fog_distance]) { + if (rangeFog) + glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV); + else + glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV); + } +#endif + + if (fogType == EFT_FOG_LINEAR) { + glFogf(GL_FOG_START, start); + glFogf(GL_FOG_END, end); + } else + glFogf(GL_FOG_DENSITY, density); + + if (pixelFog) + glHint(GL_FOG_HINT, GL_NICEST); + else + glHint(GL_FOG_HINT, GL_FASTEST); + + SColorf color(c); + GLfloat data[4] = {color.r, color.g, color.b, color.a}; + glFogfv(GL_FOG_COLOR, data); +} + +//! Draws a 3d box. +void COpenGLDriver::draw3DBox(const core::aabbox3d &box, SColor color) +{ + core::vector3df edges[8]; + box.getEdges(edges); + + setRenderStates3DMode(); + + video::S3DVertex v[24]; + + for (u32 i = 0; i < 24; i++) + v[i].Color = color; + + v[0].Pos = edges[5]; + v[1].Pos = edges[1]; + v[2].Pos = edges[1]; + v[3].Pos = edges[3]; + v[4].Pos = edges[3]; + v[5].Pos = edges[7]; + v[6].Pos = edges[7]; + v[7].Pos = edges[5]; + v[8].Pos = edges[0]; + v[9].Pos = edges[2]; + v[10].Pos = edges[2]; + v[11].Pos = edges[6]; + v[12].Pos = edges[6]; + v[13].Pos = edges[4]; + v[14].Pos = edges[4]; + v[15].Pos = edges[0]; + v[16].Pos = edges[1]; + v[17].Pos = edges[0]; + v[18].Pos = edges[3]; + v[19].Pos = edges[2]; + v[20].Pos = edges[7]; + v[21].Pos = edges[6]; + v[22].Pos = edges[5]; + v[23].Pos = edges[4]; + + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(v, 24, EVT_STANDARD); + + CacheHandler->setClientState(true, false, true, false); + + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast(v))[0].Pos); + +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(v))[0].Color); + else { + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + + glDrawArrays(GL_LINES, 0, 24); +} + +//! Draws a 3d line. +void COpenGLDriver::draw3DLine(const core::vector3df &start, + const core::vector3df &end, SColor color) +{ + setRenderStates3DMode(); + + Quad2DVertices[0].Color = color; + Quad2DVertices[1].Color = color; + + Quad2DVertices[0].Pos = core::vector3df((f32)start.X, (f32)start.Y, (f32)start.Z); + Quad2DVertices[1].Pos = core::vector3df((f32)end.X, (f32)end.Y, (f32)end.Z); + + if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra]) + getColorBuffer(Quad2DVertices, 2, EVT_STANDARD); + + CacheHandler->setClientState(true, false, true, false); + + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Pos); + +#ifdef GL_BGRA + const GLint colorSize = (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) ? GL_BGRA : 4; +#else + const GLint colorSize = 4; +#endif + if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) + glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast(Quad2DVertices))[0].Color); + else { + _IRR_DEBUG_BREAK_IF(ColorBuffer.size() == 0); + glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + } + + glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, Quad2DIndices); +} + +//! Removes a texture from the texture cache and deletes it, freeing lot of memory. +void COpenGLDriver::removeTexture(ITexture *texture) +{ + CacheHandler->getTextureCache().remove(texture); + CNullDriver::removeTexture(texture); +} + +//! Check if the driver supports creating textures with the given color format +bool COpenGLDriver::queryTextureFormat(ECOLOR_FORMAT format) const +{ + GLint dummyInternalFormat; + GLenum dummyPixelFormat; + GLenum dummyPixelType; + void (*dummyConverter)(const void *, s32, void *); + return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter); +} + +bool COpenGLDriver::needsTransparentRenderPass(const irr::video::SMaterial &material) const +{ + return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); +} + +//! Only used by the internal engine. Used to notify the driver that +//! the window was resized. +void COpenGLDriver::OnResize(const core::dimension2d &size) +{ + CNullDriver::OnResize(size); + CacheHandler->setViewport(0, 0, size.Width, size.Height); + Transformation3DChanged = true; +} + +//! Returns type of video driver +E_DRIVER_TYPE COpenGLDriver::getDriverType() const +{ + return EDT_OPENGL; +} + +//! returns color format +ECOLOR_FORMAT COpenGLDriver::getColorFormat() const +{ + return ColorFormat; +} + +//! Get a vertex shader constant index. +s32 COpenGLDriver::getVertexShaderConstantID(const c8 *name) +{ + return getPixelShaderConstantID(name); +} + +//! Get a pixel shader constant index. +s32 COpenGLDriver::getPixelShaderConstantID(const c8 *name) +{ + os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID()."); + return -1; +} + +//! Sets a constant for the vertex shader based on an index. +bool COpenGLDriver::setVertexShaderConstant(s32 index, const f32 *floats, int count) +{ + // pass this along, as in GLSL the same routine is used for both vertex and fragment shaders + return setPixelShaderConstant(index, floats, count); +} + +//! Int interface for the above. +bool COpenGLDriver::setVertexShaderConstant(s32 index, const s32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +//! Uint interface for the above. +bool COpenGLDriver::setVertexShaderConstant(s32 index, const u32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +//! Sets a constant for the pixel shader based on an index. +bool COpenGLDriver::setPixelShaderConstant(s32 index, const f32 *floats, int count) +{ + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; +} + +//! Int interface for the above. +bool COpenGLDriver::setPixelShaderConstant(s32 index, const s32 *ints, int count) +{ + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; +} + +bool COpenGLDriver::setPixelShaderConstant(s32 index, const u32 *ints, int count) +{ + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; +} + +//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. +s32 COpenGLDriver::addHighLevelShaderMaterial( + const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + const c8 *pixelShaderProgram, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + const c8 *geometryShaderProgram, + const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, + scene::E_PRIMITIVE_TYPE inType, + scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) +{ + s32 nr = -1; + + COpenGLSLMaterialRenderer *r = new COpenGLSLMaterialRenderer( + this, nr, + vertexShaderProgram, vertexShaderEntryPointName, vsCompileTarget, + pixelShaderProgram, pixelShaderEntryPointName, psCompileTarget, + geometryShaderProgram, geometryShaderEntryPointName, gsCompileTarget, + inType, outType, verticesOut, + callback, baseMaterial, userData); + + r->drop(); + + return nr; +} + +//! Returns a pointer to the IVideoDriver interface. (Implementation for +//! IMaterialRendererServices) +IVideoDriver *COpenGLDriver::getVideoDriver() +{ + return this; +} + +ITexture *COpenGLDriver::addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format) +{ + if (IImage::isCompressedFormat(format)) + return 0; + + // disable mip-mapping + bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); + + bool supportForFBO = (Feature.ColorAttachment > 0); + + core::dimension2du destSize(size); + + if (!supportForFBO) { + destSize = core::dimension2d(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height)); + destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false); + } + + COpenGLTexture *renderTargetTexture = new COpenGLTexture(name, destSize, ETT_2D, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + // restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; +} + +//! Creates a render target texture for a cubemap +ITexture *COpenGLDriver::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path &name, const ECOLOR_FORMAT format) +{ + if (IImage::isCompressedFormat(format)) + return 0; + + // disable mip-mapping + bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); + + bool supportForFBO = (Feature.ColorAttachment > 0); + + const core::dimension2d size(sideLen, sideLen); + core::dimension2du destSize(size); + + if (!supportForFBO) { + destSize = core::dimension2d(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height)); + destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false); + } + + COpenGLTexture *renderTargetTexture = new COpenGLTexture(name, destSize, ETT_CUBEMAP, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + // restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; +} + +//! Returns the maximum amount of primitives (mostly vertices) which +//! the device is able to render with one drawIndexedTriangleList +//! call. +u32 COpenGLDriver::getMaximalPrimitiveCount() const +{ + return 0x7fffffff; +} + +bool COpenGLDriver::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +{ + if (target && target->getDriverType() != EDT_OPENGL) { + os::Printer::log("Fatal Error: Tried to set a render target not owned by this driver.", ELL_ERROR); + return false; + } + + bool supportForFBO = (Feature.ColorAttachment > 0); + + core::dimension2d destRenderTargetSize(0, 0); + + if (target) { + COpenGLRenderTarget *renderTarget = static_cast(target); + + if (supportForFBO) { + CacheHandler->setFBO(renderTarget->getBufferID()); + renderTarget->update(); + } + + destRenderTargetSize = renderTarget->getSize(); + + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); + } else { + if (supportForFBO) + CacheHandler->setFBO(0); + else { + COpenGLRenderTarget *prevRenderTarget = static_cast(CurrentRenderTarget); + COpenGLTexture *renderTargetTexture = static_cast(prevRenderTarget->getTexture()); + + if (renderTargetTexture) { + const COpenGLTexture *prevTexture = CacheHandler->getTextureCache()[0]; + + CacheHandler->getTextureCache().set(0, renderTargetTexture); + + const core::dimension2d size = renderTargetTexture->getSize(); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.Width, size.Height); + + CacheHandler->getTextureCache().set(0, prevTexture); + } + } + + destRenderTargetSize = core::dimension2d(0, 0); + + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); + } + + if (CurrentRenderTargetSize != destRenderTargetSize) { + CurrentRenderTargetSize = destRenderTargetSize; + + Transformation3DChanged = true; + } + + CurrentRenderTarget = target; + + if (!supportForFBO) { + clearFlag |= ECBF_COLOR; + clearFlag |= ECBF_DEPTH; + } + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; +} + +void COpenGLDriver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) +{ + GLbitfield mask = 0; + u8 colorMask = 0; + bool depthMask = false; + + CacheHandler->getColorMask(colorMask); + CacheHandler->getDepthMask(depthMask); + + if (flag & ECBF_COLOR) { + CacheHandler->setColorMask(ECP_ALL); + + const f32 inv = 1.0f / 255.0f; + glClearColor(color.getRed() * inv, color.getGreen() * inv, + color.getBlue() * inv, color.getAlpha() * inv); + + mask |= GL_COLOR_BUFFER_BIT; + } + + if (flag & ECBF_DEPTH) { + CacheHandler->setDepthMask(true); + glClearDepth(depth); + mask |= GL_DEPTH_BUFFER_BIT; + } + + if (flag & ECBF_STENCIL) { + glClearStencil(stencil); + mask |= GL_STENCIL_BUFFER_BIT; + } + + if (mask) + glClear(mask); + + CacheHandler->setColorMask(colorMask); + CacheHandler->setDepthMask(depthMask); +} + +//! Returns an image created from the last rendered frame. +IImage *COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target) +{ + if (target != video::ERT_FRAME_BUFFER) + return 0; + + if (format == video::ECF_UNKNOWN) + format = getColorFormat(); + + // TODO: Maybe we could support more formats (floating point and some of those beyond ECF_R8), didn't really try yet + if (IImage::isCompressedFormat(format) || IImage::isDepthFormat(format) || IImage::isFloatingPointFormat(format) || format >= ECF_R8) + return 0; + + // allows to read pixels in top-to-bottom order +#ifdef GL_MESA_pack_invert + if (FeatureAvailable[IRR_MESA_pack_invert]) + glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE); +#endif + + GLenum fmt; + GLenum type; + + switch (format) { + case ECF_A1R5G5B5: + fmt = GL_BGRA; + type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + break; + case ECF_R5G6B5: + fmt = GL_RGB; + type = GL_UNSIGNED_SHORT_5_6_5; + break; + case ECF_R8G8B8: + fmt = GL_RGB; + type = GL_UNSIGNED_BYTE; + break; + case ECF_A8R8G8B8: + fmt = GL_BGRA; + if (Version > 101) + type = GL_UNSIGNED_INT_8_8_8_8_REV; + else + type = GL_UNSIGNED_BYTE; + break; + default: + fmt = GL_BGRA; + type = GL_UNSIGNED_BYTE; + break; + } + IImage *newImage = createImage(format, ScreenSize); + + u8 *pixels = 0; + if (newImage) + pixels = static_cast(newImage->getData()); + if (pixels) { + glReadBuffer(GL_FRONT); + glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, fmt, type, pixels); + testGLError(__LINE__); + glReadBuffer(GL_BACK); + } + +#ifdef GL_MESA_pack_invert + if (FeatureAvailable[IRR_MESA_pack_invert]) + glPixelStorei(GL_PACK_INVERT_MESA, GL_FALSE); + else +#endif + if (pixels && newImage) { + // opengl images are horizontally flipped, so we have to fix that here. + const s32 pitch = newImage->getPitch(); + u8 *p2 = pixels + (ScreenSize.Height - 1) * pitch; + u8 *tmpBuffer = new u8[pitch]; + for (u32 i = 0; i < ScreenSize.Height; i += 2) { + memcpy(tmpBuffer, pixels, pitch); + // for (u32 j=0; jdrop(); + return 0; + } + } + return newImage; +} + +//! Set/unset a clipping plane. +bool COpenGLDriver::setClipPlane(u32 index, const core::plane3df &plane, bool enable) +{ + if (index >= MaxUserClipPlanes) + return false; + + UserClipPlanes[index].Plane = plane; + enableClipPlane(index, enable); + return true; +} + +void COpenGLDriver::uploadClipPlane(u32 index) +{ + // opengl needs an array of doubles for the plane equation + GLdouble clip_plane[4]; + clip_plane[0] = UserClipPlanes[index].Plane.Normal.X; + clip_plane[1] = UserClipPlanes[index].Plane.Normal.Y; + clip_plane[2] = UserClipPlanes[index].Plane.Normal.Z; + clip_plane[3] = UserClipPlanes[index].Plane.D; + glClipPlane(GL_CLIP_PLANE0 + index, clip_plane); +} + +//! Enable/disable a clipping plane. +void COpenGLDriver::enableClipPlane(u32 index, bool enable) +{ + if (index >= MaxUserClipPlanes) + return; + if (enable) { + if (!UserClipPlanes[index].Enabled) { + uploadClipPlane(index); + glEnable(GL_CLIP_PLANE0 + index); + } + } else + glDisable(GL_CLIP_PLANE0 + index); + + UserClipPlanes[index].Enabled = enable; +} + +core::dimension2du COpenGLDriver::getMaxTextureSize() const +{ + return core::dimension2du(MaxTextureSize, MaxTextureSize); +} + +//! Convert E_PRIMITIVE_TYPE to OpenGL equivalent +GLenum COpenGLDriver::primitiveTypeToGL(scene::E_PRIMITIVE_TYPE type) const +{ + switch (type) { + case scene::EPT_POINTS: + return GL_POINTS; + case scene::EPT_LINE_STRIP: + return GL_LINE_STRIP; + case scene::EPT_LINE_LOOP: + return GL_LINE_LOOP; + case scene::EPT_LINES: + return GL_LINES; + case scene::EPT_TRIANGLE_STRIP: + return GL_TRIANGLE_STRIP; + case scene::EPT_TRIANGLE_FAN: + return GL_TRIANGLE_FAN; + case scene::EPT_TRIANGLES: + return GL_TRIANGLES; + case scene::EPT_POINT_SPRITES: +#ifdef GL_ARB_point_sprite + return GL_POINT_SPRITE_ARB; +#else + return GL_POINTS; +#endif + } + return GL_TRIANGLES; +} + +GLenum COpenGLDriver::getGLBlend(E_BLEND_FACTOR factor) const +{ + GLenum r = 0; + switch (factor) { + case EBF_ZERO: + r = GL_ZERO; + break; + case EBF_ONE: + r = GL_ONE; + break; + case EBF_DST_COLOR: + r = GL_DST_COLOR; + break; + case EBF_ONE_MINUS_DST_COLOR: + r = GL_ONE_MINUS_DST_COLOR; + break; + case EBF_SRC_COLOR: + r = GL_SRC_COLOR; + break; + case EBF_ONE_MINUS_SRC_COLOR: + r = GL_ONE_MINUS_SRC_COLOR; + break; + case EBF_SRC_ALPHA: + r = GL_SRC_ALPHA; + break; + case EBF_ONE_MINUS_SRC_ALPHA: + r = GL_ONE_MINUS_SRC_ALPHA; + break; + case EBF_DST_ALPHA: + r = GL_DST_ALPHA; + break; + case EBF_ONE_MINUS_DST_ALPHA: + r = GL_ONE_MINUS_DST_ALPHA; + break; + case EBF_SRC_ALPHA_SATURATE: + r = GL_SRC_ALPHA_SATURATE; + break; + } + return r; +} + +GLenum COpenGLDriver::getZBufferBits() const +{ + GLenum bits = 0; + switch (Params.ZBufferBits) { + case 16: + bits = GL_DEPTH_COMPONENT16; + break; + case 24: + bits = GL_DEPTH_COMPONENT24; + break; + case 32: + bits = GL_DEPTH_COMPONENT32; + break; + default: + bits = GL_DEPTH_COMPONENT; + break; + } + return bits; +} + +bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, + GLenum &pixelType, void (**converter)(const void *, s32, void *)) const +{ + // NOTE: Converter variable not used here, but don't remove, it's used in the OGL-ES drivers. + + bool supported = false; + internalFormat = GL_RGBA; + pixelFormat = GL_RGBA; + pixelType = GL_UNSIGNED_BYTE; + + switch (format) { + case ECF_A1R5G5B5: + supported = true; + internalFormat = GL_RGBA; + pixelFormat = GL_BGRA_EXT; + pixelType = GL_UNSIGNED_SHORT_1_5_5_5_REV; + break; + case ECF_R5G6B5: + supported = true; + internalFormat = GL_RGB; + pixelFormat = GL_RGB; + pixelType = GL_UNSIGNED_SHORT_5_6_5; + break; + case ECF_R8G8B8: + supported = true; + internalFormat = GL_RGB; + pixelFormat = GL_RGB; + pixelType = GL_UNSIGNED_BYTE; + break; + case ECF_A8R8G8B8: + supported = true; + internalFormat = GL_RGBA; + pixelFormat = GL_BGRA_EXT; + if (Version > 101) + pixelType = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + case ECF_D16: + supported = true; + internalFormat = GL_DEPTH_COMPONENT16; + pixelFormat = GL_DEPTH_COMPONENT; + pixelType = GL_UNSIGNED_SHORT; + break; + case ECF_D32: + supported = true; + internalFormat = GL_DEPTH_COMPONENT32; + pixelFormat = GL_DEPTH_COMPONENT; + pixelType = GL_UNSIGNED_INT; + break; + case ECF_D24S8: +#ifdef GL_VERSION_3_0 + if (Version >= 300) { + supported = true; + internalFormat = GL_DEPTH_STENCIL; + pixelFormat = GL_DEPTH_STENCIL; + pixelType = GL_UNSIGNED_INT_24_8; + } else +#endif +#ifdef GL_EXT_packed_depth_stencil + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_EXT_packed_depth_stencil)) { + supported = true; + internalFormat = GL_DEPTH_STENCIL_EXT; + pixelFormat = GL_DEPTH_STENCIL_EXT; + pixelType = GL_UNSIGNED_INT_24_8_EXT; + } +#endif + break; + case ECF_R8: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_R8; + pixelFormat = GL_RED; + pixelType = GL_UNSIGNED_BYTE; + } + break; + case ECF_R8G8: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_RG8; + pixelFormat = GL_RG; + pixelType = GL_UNSIGNED_BYTE; + } + break; + case ECF_R16: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_R16; + pixelFormat = GL_RED; + pixelType = GL_UNSIGNED_SHORT; + } + break; + case ECF_R16G16: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_RG16; + pixelFormat = GL_RG; + pixelType = GL_UNSIGNED_SHORT; + } + break; + case ECF_R16F: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_R16F; + pixelFormat = GL_RED; +#ifdef GL_ARB_half_float_pixel + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_half_float_pixel)) + pixelType = GL_HALF_FLOAT_ARB; + else +#endif + pixelType = GL_FLOAT; + } + break; + case ECF_G16R16F: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_RG16F; + pixelFormat = GL_RG; +#ifdef GL_ARB_half_float_pixel + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_half_float_pixel)) + pixelType = GL_HALF_FLOAT_ARB; + else +#endif + pixelType = GL_FLOAT; + } + break; + case ECF_A16B16G16R16F: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_float)) { + supported = true; + internalFormat = GL_RGBA16F_ARB; + pixelFormat = GL_RGBA; +#ifdef GL_ARB_half_float_pixel + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_half_float_pixel)) + pixelType = GL_HALF_FLOAT_ARB; + else +#endif + pixelType = GL_FLOAT; + } + break; + case ECF_R32F: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_R32F; + pixelFormat = GL_RED; + pixelType = GL_FLOAT; + } + break; + case ECF_G32R32F: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg)) { + supported = true; + internalFormat = GL_RG32F; + pixelFormat = GL_RG; + pixelType = GL_FLOAT; + } + break; + case ECF_A32B32G32R32F: + if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_float)) { + supported = true; + internalFormat = GL_RGBA32F_ARB; + pixelFormat = GL_RGBA; + pixelType = GL_FLOAT; + } + break; + default: + break; + } + + return supported; +} + +COpenGLDriver::E_OPENGL_FIXED_PIPELINE_STATE COpenGLDriver::getFixedPipelineState() const +{ + return FixedPipelineState; +} + +void COpenGLDriver::setFixedPipelineState(COpenGLDriver::E_OPENGL_FIXED_PIPELINE_STATE state) +{ + FixedPipelineState = state; +} + +const SMaterial &COpenGLDriver::getCurrentMaterial() const +{ + return Material; +} + +COpenGLCacheHandler *COpenGLDriver::getCacheHandler() const +{ + return CacheHandler; +} + +} // end namespace +} // end namespace + +#endif // _IRR_COMPILE_WITH_OPENGL_ + +namespace irr +{ +namespace video +{ + +IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ +#ifdef _IRR_COMPILE_WITH_OPENGL_ + COpenGLDriver *ogl = new COpenGLDriver(params, io, contextManager); + + if (!ogl->initDriver()) { + ogl->drop(); + ogl = 0; + } + + return ogl; +#else + return 0; +#endif +} + +} // end namespace +} // end namespace diff --git a/irr/src/COpenGLDriver.h b/irr/src/COpenGLDriver.h new file mode 100644 index 000000000..6fe8ac37d --- /dev/null +++ b/irr/src/COpenGLDriver.h @@ -0,0 +1,437 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "SIrrCreationParameters.h" + +namespace irr +{ +class CIrrDeviceWin32; +class CIrrDeviceLinux; +class CIrrDeviceSDL; +class CIrrDeviceMacOSX; +} + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "IMaterialRendererServices.h" +#include "CNullDriver.h" + +#include "COpenGLExtensionHandler.h" +#include "IContextManager.h" + +namespace irr +{ + +namespace video +{ +class IContextManager; + +class COpenGLDriver : public CNullDriver, public IMaterialRendererServices, public COpenGLExtensionHandler +{ +public: + // Information about state of fixed pipeline activity. + enum E_OPENGL_FIXED_PIPELINE_STATE + { + EOFPS_ENABLE = 0, // fixed pipeline. + EOFPS_DISABLE, // programmable pipeline. + EOFPS_ENABLE_TO_DISABLE, // switch from fixed to programmable pipeline. + EOFPS_DISABLE_TO_ENABLE // switch from programmable to fixed pipeline. + }; + + COpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + + bool initDriver(); + + //! destructor + virtual ~COpenGLDriver(); + + virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0, + const SExposedVideoData &videoData = SExposedVideoData(), core::rect *sourceRect = 0) override; + + bool endScene() override; + + //! sets transformation + void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) override; + + struct SHWBufferLink_opengl : public SHWBufferLink + { + SHWBufferLink_opengl(const scene::IMeshBuffer *_MeshBuffer) : + SHWBufferLink(_MeshBuffer), vbo_verticesID(0), vbo_indicesID(0) {} + + GLuint vbo_verticesID; // tmp + GLuint vbo_indicesID; // tmp + + GLuint vbo_verticesSize; // tmp + GLuint vbo_indicesSize; // tmp + }; + + //! updates hardware buffer if needed + bool updateHardwareBuffer(SHWBufferLink *HWBuffer) override; + + //! Create hardware buffer from mesh + SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer *mb) override; + + //! Delete hardware buffer (only some drivers can) + void deleteHardwareBuffer(SHWBufferLink *HWBuffer) override; + + //! Draw hardware buffer + void drawHardwareBuffer(SHWBufferLink *HWBuffer) override; + + //! Create occlusion query. + /** Use node for identification and mesh for occlusion test. */ + virtual void addOcclusionQuery(scene::ISceneNode *node, + const scene::IMesh *mesh = 0) override; + + //! Remove occlusion query. + void removeOcclusionQuery(scene::ISceneNode *node) override; + + //! Run occlusion query. Draws mesh stored in query. + /** If the mesh shall not be rendered visible, use + overrideMaterial to disable the color and depth buffer. */ + void runOcclusionQuery(scene::ISceneNode *node, bool visible = false) override; + + //! Update occlusion query. Retrieves results from GPU. + /** If the query shall not block, set the flag to false. + Update might not occur in this case, though */ + void updateOcclusionQuery(scene::ISceneNode *node, bool block = true) override; + + //! Return query result. + /** Return value is the number of visible pixels/fragments. + The value is a safe approximation, i.e. can be larger then the + actual value of pixels. */ + u32 getOcclusionQueryResult(scene::ISceneNode *node) const override; + + //! Create render target. + IRenderTarget *addRenderTarget() override; + + //! draws a vertex primitive list + virtual void drawVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override; + + //! draws a vertex primitive list in 2d + virtual void draw2DVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override; + + //! queries the features of the driver, returns true if feature is available + bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override + { + return FeatureEnabled[feature] && COpenGLExtensionHandler::queryFeature(feature); + } + + //! Disable a feature of the driver. + void disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag = true) override; + + //! Sets a material. All 3d drawing functions draw geometry now + //! using this material. + //! \param material: Material to be used from now on. + void setMaterial(const SMaterial &material) override; + + virtual void draw2DImage(const video::ITexture *texture, const core::position2d &destPos, + const core::rect &sourceRect, const core::rect *clipRect = 0, + SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override; + + virtual void draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect = 0, + const video::SColor *const colors = 0, bool useAlphaChannelOfTexture = false) override; + + // Explicitly bring in base class methods, otherwise + // this overload would hide them. + using CNullDriver::draw2DImage; + virtual void draw2DImage(const video::ITexture *texture, u32 layer, bool flip); + + //! draws a set of 2d images, using a color and the alpha channel of the + //! texture if desired. + void draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect, + SColor color, + bool useAlphaChannelOfTexture) override; + + //! draw an 2d rectangle + virtual void draw2DRectangle(SColor color, const core::rect &pos, + const core::rect *clip = 0) override; + + //! Draws an 2d rectangle with a gradient. + virtual void draw2DRectangle(const core::rect &pos, + SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip = 0) override; + + //! Draws a 2d line. + virtual void draw2DLine(const core::position2d &start, + const core::position2d &end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! Draws a 3d box + void draw3DBox(const core::aabbox3d &box, SColor color = SColor(255, 255, 255, 255)) override; + + //! Draws a 3d line. + virtual void draw3DLine(const core::vector3df &start, + const core::vector3df &end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! \return Returns the name of the video driver. Example: In case of the Direct3D8 + //! driver, it would return "Direct3D8.1". + const char *getName() const override; + + //! Sets the dynamic ambient light color. The default color is + //! (0,0,0,0) which means it is dark. + //! \param color: New color of the ambient light. + void setAmbientLight(const SColorf &color) override; + + //! sets a viewport + void setViewPort(const core::rect &area) override; + + //! Sets the fog mode. + virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start, + f32 end, f32 density, bool pixelFog, bool rangeFog) override; + + //! Only used by the internal engine. Used to notify the driver that + //! the window was resized. + void OnResize(const core::dimension2d &size) override; + + //! Returns type of video driver + E_DRIVER_TYPE getDriverType() const override; + + //! get color format of the current color buffer + ECOLOR_FORMAT getColorFormat() const override; + + //! Returns the transformation set by setTransform + const core::matrix4 &getTransform(E_TRANSFORMATION_STATE state) const override; + + //! Can be called by an IMaterialRenderer to make its work easier. + virtual void setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, + bool resetAllRenderstates) override; + + //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. + virtual void setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates); + + //! Get a vertex shader constant index. + s32 getVertexShaderConstantID(const c8 *name) override; + + //! Get a pixel shader constant index. + s32 getPixelShaderConstantID(const c8 *name) override; + + //! Sets a constant for the vertex shader based on an index. + bool setVertexShaderConstant(s32 index, const f32 *floats, int count) override; + + //! Int interface for the above. + bool setVertexShaderConstant(s32 index, const s32 *ints, int count) override; + + //! Uint interface for the above. + bool setVertexShaderConstant(s32 index, const u32 *ints, int count) override; + + //! Sets a constant for the pixel shader based on an index. + bool setPixelShaderConstant(s32 index, const f32 *floats, int count) override; + + //! Int interface for the above. + bool setPixelShaderConstant(s32 index, const s32 *ints, int count) override; + + //! Uint interface for the above. + bool setPixelShaderConstant(s32 index, const u32 *ints, int count) override; + + //! disables all textures beginning with the optional fromStage parameter. Otherwise all texture stages are disabled. + //! Returns whether disabling was successful or not. + bool disableTextures(u32 fromStage = 0); + + //! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. + virtual s32 addHighLevelShaderMaterial( + const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + const c8 *pixelShaderProgram, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + const c8 *geometryShaderProgram, + const c8 *geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, + s32 userData = 0) override; + + //! Returns a pointer to the IVideoDriver interface. (Implementation for + //! IMaterialRendererServices) + IVideoDriver *getVideoDriver() override; + + //! Returns the maximum amount of primitives (mostly vertices) which + //! the device is able to render with one drawIndexedTriangleList + //! call. + u32 getMaximalPrimitiveCount() const override; + + virtual ITexture *addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override; + + //! Creates a render target texture for a cubemap + ITexture *addRenderTargetTextureCubemap(const irr::u32 sideLen, + const io::path &name, const ECOLOR_FORMAT format) override; + + virtual bool setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), + f32 clearDepth = 1.f, u8 clearStencil = 0) override; + + void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) override; + + //! Returns an image created from the last rendered frame. + IImage *createScreenShot(video::ECOLOR_FORMAT format = video::ECF_UNKNOWN, video::E_RENDER_TARGET target = video::ERT_FRAME_BUFFER) override; + + //! checks if an OpenGL error has happened and prints it (+ some internal code which is usually the line number) + //! for performance reasons only available in debug mode + bool testGLError(int code = 0); + + //! Set/unset a clipping plane. + //! There are at least 6 clipping planes available for the user to set at will. + //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes. + //! \param plane: The plane itself. + //! \param enable: If true, enable the clipping plane else disable it. + bool setClipPlane(u32 index, const core::plane3df &plane, bool enable = false) override; + + //! Enable/disable a clipping plane. + //! There are at least 6 clipping planes available for the user to set at will. + //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes. + //! \param enable: If true, enable the clipping plane else disable it. + void enableClipPlane(u32 index, bool enable) override; + + //! Enable the 2d override material + void enableMaterial2D(bool enable = true) override; + + //! Returns the graphics card vendor name. + core::stringc getVendorInfo() override { return VendorName; } + + //! Returns the maximum texture size supported. + core::dimension2du getMaxTextureSize() const override; + + //! Removes a texture from the texture cache and deletes it, freeing lot of memory. + void removeTexture(ITexture *texture) override; + + //! Check if the driver supports creating textures with the given color format + bool queryTextureFormat(ECOLOR_FORMAT format) const override; + + //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass + bool needsTransparentRenderPass(const irr::video::SMaterial &material) const override; + + //! Convert E_PRIMITIVE_TYPE to OpenGL equivalent + GLenum primitiveTypeToGL(scene::E_PRIMITIVE_TYPE type) const; + + //! Convert E_BLEND_FACTOR to OpenGL equivalent + GLenum getGLBlend(E_BLEND_FACTOR factor) const; + + //! Get ZBuffer bits. + GLenum getZBufferBits() const; + + bool getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, + GLenum &pixelType, void (**converter)(const void *, s32, void *)) const; + + //! Return info about fixed pipeline state. + E_OPENGL_FIXED_PIPELINE_STATE getFixedPipelineState() const; + + //! Set info about fixed pipeline state. + void setFixedPipelineState(E_OPENGL_FIXED_PIPELINE_STATE state); + + //! Get current material. + const SMaterial &getCurrentMaterial() const; + + COpenGLCacheHandler *getCacheHandler() const; + +private: + bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + + void uploadClipPlane(u32 index); + + //! inits the parts of the open gl driver used on all platforms + bool genericDriverInit(); + + ITexture *createDeviceDependentTexture(const io::path &name, IImage *image) override; + + ITexture *createDeviceDependentTextureCubemap(const io::path &name, const core::array &image) override; + + //! creates a transposed matrix in supplied GLfloat array to pass to OpenGL + inline void getGLMatrix(GLfloat gl_matrix[16], const core::matrix4 &m); + inline void getGLTextureMatrix(GLfloat gl_matrix[16], const core::matrix4 &m); + + //! get native wrap mode value + GLint getTextureWrapMode(const u8 clamp); + + //! sets the needed renderstates + void setRenderStates3DMode(); + + //! sets the needed renderstates + void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel); + + void createMaterialRenderers(); + + //! Assign a hardware light to the specified requested light, if any + //! free hardware lights exist. + //! \param[in] lightIndex: the index of the requesting light + void assignHardwareLight(u32 lightIndex); + + //! helper function for render setup. + void getColorBuffer(const void *vertices, u32 vertexCount, E_VERTEX_TYPE vType); + + //! helper function doing the actual rendering. + void renderArray(const void *indexList, u32 primitiveCount, + scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType); + + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + + COpenGLCacheHandler *CacheHandler; + + core::stringc Name; + core::matrix4 Matrices[ETS_COUNT]; + core::array ColorBuffer; + + //! enumeration for rendering modes such as 2d and 3d for minimizing the switching of renderStates. + enum E_RENDER_MODE + { + ERM_NONE = 0, // no render state has been set yet. + ERM_2D, // 2d drawing rendermode + ERM_3D // 3d rendering mode + }; + + E_RENDER_MODE CurrentRenderMode; + //! bool to make all renderstates reset if set to true. + bool ResetRenderStates; + bool Transformation3DChanged; + u8 AntiAlias; + + SMaterial Material, LastMaterial; + + struct SUserClipPlane + { + SUserClipPlane() : + Enabled(false) {} + core::plane3df Plane; + bool Enabled; + }; + core::array UserClipPlanes; + + core::stringc VendorName; + + core::matrix4 TextureFlipMatrix; + + //! Color buffer format + ECOLOR_FORMAT ColorFormat; + + E_OPENGL_FIXED_PIPELINE_STATE FixedPipelineState; + + SIrrlichtCreationParameters Params; + + //! Built-in 2D quad for 2D rendering. + S3DVertex Quad2DVertices[4]; + static const u16 Quad2DIndices[4]; + + IContextManager *ContextManager; +}; + +} // end namespace video +} // end namespace irr + +#endif // _IRR_COMPILE_WITH_OPENGL_ diff --git a/irr/src/COpenGLExtensionHandler.cpp b/irr/src/COpenGLExtensionHandler.cpp new file mode 100644 index 000000000..d5aade126 --- /dev/null +++ b/irr/src/COpenGLExtensionHandler.cpp @@ -0,0 +1,626 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "COpenGLExtensionHandler.h" + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "irrString.h" +#include "SMaterial.h" +#include "fast_atof.h" +#include "IContextManager.h" + +namespace irr +{ +namespace video +{ + +bool COpenGLExtensionHandler::needsDSAFramebufferHack = true; + +COpenGLExtensionHandler::COpenGLExtensionHandler() : + StencilBuffer(false), TextureCompressionExtension(false), MaxLights(1), + MaxAnisotropy(1), MaxUserClipPlanes(0), MaxAuxBuffers(0), MaxIndices(65535), + MaxTextureSize(1), MaxGeometryVerticesOut(0), + MaxTextureLODBias(0.f), Version(0), ShaderLanguageVersion(0), + OcclusionQuerySupport(false), IsAtiRadeonX(false), pGlActiveTexture(0), pGlActiveTextureARB(0), pGlClientActiveTextureARB(0), + pGlGenProgramsARB(0), pGlGenProgramsNV(0), + pGlBindProgramARB(0), pGlBindProgramNV(0), + pGlDeleteProgramsARB(0), pGlDeleteProgramsNV(0), + pGlProgramStringARB(0), pGlLoadProgramNV(0), + pGlProgramLocalParameter4fvARB(0), + pGlCreateShaderObjectARB(0), pGlShaderSourceARB(0), + pGlCompileShaderARB(0), pGlCreateProgramObjectARB(0), pGlAttachObjectARB(0), + pGlLinkProgramARB(0), pGlUseProgramObjectARB(0), pGlDeleteObjectARB(0), + pGlCreateProgram(0), pGlUseProgram(0), + pGlDeleteProgram(0), pGlDeleteShader(0), + pGlGetAttachedObjectsARB(0), pGlGetAttachedShaders(0), + pGlCreateShader(0), pGlShaderSource(0), pGlCompileShader(0), + pGlAttachShader(0), pGlLinkProgram(0), + pGlGetInfoLogARB(0), pGlGetShaderInfoLog(0), pGlGetProgramInfoLog(0), + pGlGetObjectParameterivARB(0), pGlGetShaderiv(0), pGlGetProgramiv(0), + pGlGetUniformLocationARB(0), pGlGetUniformLocation(0), + pGlUniform1fvARB(0), pGlUniform2fvARB(0), pGlUniform3fvARB(0), pGlUniform4fvARB(0), + pGlUniform1ivARB(0), pGlUniform2ivARB(0), pGlUniform3ivARB(0), pGlUniform4ivARB(0), + pGlUniform1uiv(0), pGlUniform2uiv(0), pGlUniform3uiv(0), pGlUniform4uiv(0), + pGlUniformMatrix2fvARB(0), pGlUniformMatrix2x3fv(0), pGlUniformMatrix2x4fv(0), + pGlUniformMatrix3x2fv(0), pGlUniformMatrix3fvARB(0), pGlUniformMatrix3x4fv(0), + pGlUniformMatrix4x2fv(0), pGlUniformMatrix4x3fv(0), pGlUniformMatrix4fvARB(0), + pGlGetActiveUniformARB(0), pGlGetActiveUniform(0), + pGlPointParameterfARB(0), pGlPointParameterfvARB(0), + pGlStencilFuncSeparate(0), pGlStencilOpSeparate(0), + pGlStencilFuncSeparateATI(0), pGlStencilOpSeparateATI(0), + pGlCompressedTexImage2D(0), pGlCompressedTexSubImage2D(0), + // ARB framebuffer object + pGlBindFramebuffer(0), pGlDeleteFramebuffers(0), pGlGenFramebuffers(0), + pGlCheckFramebufferStatus(0), pGlFramebufferTexture2D(0), + pGlBindRenderbuffer(0), pGlDeleteRenderbuffers(0), pGlGenRenderbuffers(0), + pGlRenderbufferStorage(0), pGlFramebufferRenderbuffer(0), pGlGenerateMipmap(0), + // EXT framebuffer object + pGlBindFramebufferEXT(0), pGlDeleteFramebuffersEXT(0), pGlGenFramebuffersEXT(0), + pGlCheckFramebufferStatusEXT(0), pGlFramebufferTexture2DEXT(0), + pGlBindRenderbufferEXT(0), pGlDeleteRenderbuffersEXT(0), pGlGenRenderbuffersEXT(0), + pGlRenderbufferStorageEXT(0), pGlFramebufferRenderbufferEXT(0), pGlGenerateMipmapEXT(0), + pGlActiveStencilFaceEXT(0), + // MRTs + pGlDrawBuffersARB(0), pGlDrawBuffersATI(0), + pGlGenBuffersARB(0), pGlBindBufferARB(0), pGlBufferDataARB(0), pGlDeleteBuffersARB(0), + pGlBufferSubDataARB(0), pGlGetBufferSubDataARB(0), pGlMapBufferARB(0), pGlUnmapBufferARB(0), + pGlIsBufferARB(0), pGlGetBufferParameterivARB(0), pGlGetBufferPointervARB(0), + pGlProvokingVertexARB(0), pGlProvokingVertexEXT(0), + pGlProgramParameteriARB(0), pGlProgramParameteriEXT(0), + pGlGenQueriesARB(0), pGlDeleteQueriesARB(0), pGlIsQueryARB(0), + pGlBeginQueryARB(0), pGlEndQueryARB(0), pGlGetQueryivARB(0), + pGlGetQueryObjectivARB(0), pGlGetQueryObjectuivARB(0), + pGlGenOcclusionQueriesNV(0), pGlDeleteOcclusionQueriesNV(0), + pGlIsOcclusionQueryNV(0), pGlBeginOcclusionQueryNV(0), + pGlEndOcclusionQueryNV(0), pGlGetOcclusionQueryivNV(0), + pGlGetOcclusionQueryuivNV(0), + // Blend + pGlBlendFuncSeparateEXT(0), pGlBlendFuncSeparate(0), + pGlBlendEquationEXT(0), pGlBlendEquation(0), pGlBlendEquationSeparateEXT(0), pGlBlendEquationSeparate(0), + // Indexed + pGlEnableIndexedEXT(0), pGlDisableIndexedEXT(0), + pGlColorMaskIndexedEXT(0), + pGlBlendFuncIndexedAMD(0), pGlBlendFunciARB(0), pGlBlendFuncSeparateIndexedAMD(0), pGlBlendFuncSeparateiARB(0), + pGlBlendEquationIndexedAMD(0), pGlBlendEquationiARB(0), pGlBlendEquationSeparateIndexedAMD(0), pGlBlendEquationSeparateiARB(0), + // DSA + pGlTextureStorage2D(0), pGlTextureStorage3D(0), pGlTextureSubImage2D(0), pGlGetTextureImage(0), pGlNamedFramebufferTexture(0), + pGlTextureParameteri(0), pGlTextureParameterf(0), pGlTextureParameteriv(0), pGlTextureParameterfv(0), + pGlCreateTextures(0), pGlCreateFramebuffers(0), pGlBindTextures(0), pGlGenerateTextureMipmap(0), + // DSA with EXT or functions to simulate it + pGlTextureStorage2DEXT(0), pGlTexStorage2D(0), pGlTextureStorage3DEXT(0), pGlTexStorage3D(0), pGlTextureSubImage2DEXT(0), pGlGetTextureImageEXT(0), + pGlNamedFramebufferTextureEXT(0), pGlFramebufferTexture(0), pGlGenerateTextureMipmapEXT(0) +#if defined(GLX_SGI_swap_control) + , + pGlxSwapIntervalSGI(0) +#endif +#if defined(GLX_EXT_swap_control) + , + pGlxSwapIntervalEXT(0) +#endif +#if defined(WGL_EXT_swap_control) + , + pWglSwapIntervalEXT(0) +#endif +#if defined(GLX_MESA_swap_control) + , + pGlxSwapIntervalMESA(0) +#endif +{ + for (u32 i = 0; i < IRR_OpenGL_Feature_Count; ++i) + FeatureAvailable[i] = false; + DimAliasedLine[0] = 1.f; + DimAliasedLine[1] = 1.f; + DimAliasedPoint[0] = 1.f; + DimAliasedPoint[1] = 1.f; + DimSmoothedLine[0] = 1.f; + DimSmoothedLine[1] = 1.f; + DimSmoothedPoint[0] = 1.f; + DimSmoothedPoint[1] = 1.f; +} + +void COpenGLExtensionHandler::dump(ELOG_LEVEL logLevel) const +{ + for (u32 i = 0; i < IRR_OpenGL_Feature_Count; ++i) + os::Printer::log(OpenGLFeatureStrings[i], FeatureAvailable[i] ? " true" : " false", logLevel); +} + +void COpenGLExtensionHandler::initExtensions(video::IContextManager *cmgr, bool stencilBuffer) +{ + const f32 ogl_ver = core::fast_atof(reinterpret_cast(glGetString(GL_VERSION))); + Version = static_cast(core::floor32(ogl_ver) * 100 + core::round32(core::fract(ogl_ver) * 10.0f)); + if (Version >= 102) + os::Printer::log("OpenGL driver version is 1.2 or better.", ELL_INFORMATION); + else + os::Printer::log("OpenGL driver version is not 1.2 or better.", ELL_WARNING); + + { + const char *t = reinterpret_cast(glGetString(GL_EXTENSIONS)); + size_t len = 0; + c8 *str = 0; + if (t) { + len = strlen(t); + str = new c8[len + 1]; + } + c8 *p = str; + + for (size_t i = 0; i < len; ++i) { + str[i] = static_cast(t[i]); + + if (str[i] == ' ') { + str[i] = 0; + for (u32 j = 0; j < IRR_OpenGL_Feature_Count; ++j) { + if (!strcmp(OpenGLFeatureStrings[j], p)) { + FeatureAvailable[j] = true; + break; + } + } + + p = p + strlen(p) + 1; + } + } + + delete[] str; + } + + TextureCompressionExtension = FeatureAvailable[IRR_ARB_texture_compression]; + StencilBuffer = stencilBuffer; + + const char *renderer = (const char *)glGetString(GL_RENDERER); + if (renderer) { + IsAtiRadeonX = (strncmp(renderer, "ATI RADEON X", 12) == 0) || (strncmp(renderer, "ATI MOBILITY RADEON X", 21) == 0); + } + +#define IRR_OGL_LOAD_EXTENSION(x) cmgr->getProcAddress(x) + + // get multitexturing function pointers + pGlActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)IRR_OGL_LOAD_EXTENSION("glActiveTextureARB"); + pGlClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC)IRR_OGL_LOAD_EXTENSION("glClientActiveTextureARB"); + + // get fragment and vertex program function pointers + pGlGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)IRR_OGL_LOAD_EXTENSION("glGenProgramsARB"); + pGlGenProgramsNV = (PFNGLGENPROGRAMSNVPROC)IRR_OGL_LOAD_EXTENSION("glGenProgramsNV"); + pGlBindProgramARB = (PFNGLBINDPROGRAMARBPROC)IRR_OGL_LOAD_EXTENSION("glBindProgramARB"); + pGlBindProgramNV = (PFNGLBINDPROGRAMNVPROC)IRR_OGL_LOAD_EXTENSION("glBindProgramNV"); + pGlProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)IRR_OGL_LOAD_EXTENSION("glProgramStringARB"); + pGlLoadProgramNV = (PFNGLLOADPROGRAMNVPROC)IRR_OGL_LOAD_EXTENSION("glLoadProgramNV"); + pGlDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)IRR_OGL_LOAD_EXTENSION("glDeleteProgramsARB"); + pGlDeleteProgramsNV = (PFNGLDELETEPROGRAMSNVPROC)IRR_OGL_LOAD_EXTENSION("glDeleteProgramsNV"); + pGlProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)IRR_OGL_LOAD_EXTENSION("glProgramLocalParameter4fvARB"); + pGlCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)IRR_OGL_LOAD_EXTENSION("glCreateShaderObjectARB"); + pGlCreateShader = (PFNGLCREATESHADERPROC)IRR_OGL_LOAD_EXTENSION("glCreateShader"); + pGlShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)IRR_OGL_LOAD_EXTENSION("glShaderSourceARB"); + pGlShaderSource = (PFNGLSHADERSOURCEPROC)IRR_OGL_LOAD_EXTENSION("glShaderSource"); + pGlCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)IRR_OGL_LOAD_EXTENSION("glCompileShaderARB"); + pGlCompileShader = (PFNGLCOMPILESHADERPROC)IRR_OGL_LOAD_EXTENSION("glCompileShader"); + pGlCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)IRR_OGL_LOAD_EXTENSION("glCreateProgramObjectARB"); + pGlCreateProgram = (PFNGLCREATEPROGRAMPROC)IRR_OGL_LOAD_EXTENSION("glCreateProgram"); + pGlAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)IRR_OGL_LOAD_EXTENSION("glAttachObjectARB"); + pGlAttachShader = (PFNGLATTACHSHADERPROC)IRR_OGL_LOAD_EXTENSION("glAttachShader"); + pGlLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)IRR_OGL_LOAD_EXTENSION("glLinkProgramARB"); + pGlLinkProgram = (PFNGLLINKPROGRAMPROC)IRR_OGL_LOAD_EXTENSION("glLinkProgram"); + pGlUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)IRR_OGL_LOAD_EXTENSION("glUseProgramObjectARB"); + pGlUseProgram = (PFNGLUSEPROGRAMPROC)IRR_OGL_LOAD_EXTENSION("glUseProgram"); + pGlDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)IRR_OGL_LOAD_EXTENSION("glDeleteObjectARB"); + pGlDeleteProgram = (PFNGLDELETEPROGRAMPROC)IRR_OGL_LOAD_EXTENSION("glDeleteProgram"); + pGlDeleteShader = (PFNGLDELETESHADERPROC)IRR_OGL_LOAD_EXTENSION("glDeleteShader"); + pGlGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC)IRR_OGL_LOAD_EXTENSION("glGetAttachedShaders"); + pGlGetAttachedObjectsARB = (PFNGLGETATTACHEDOBJECTSARBPROC)IRR_OGL_LOAD_EXTENSION("glGetAttachedObjectsARB"); + pGlGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)IRR_OGL_LOAD_EXTENSION("glGetInfoLogARB"); + pGlGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)IRR_OGL_LOAD_EXTENSION("glGetShaderInfoLog"); + pGlGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)IRR_OGL_LOAD_EXTENSION("glGetProgramInfoLog"); + pGlGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)IRR_OGL_LOAD_EXTENSION("glGetObjectParameterivARB"); + pGlGetShaderiv = (PFNGLGETSHADERIVPROC)IRR_OGL_LOAD_EXTENSION("glGetShaderiv"); + pGlGetProgramiv = (PFNGLGETPROGRAMIVPROC)IRR_OGL_LOAD_EXTENSION("glGetProgramiv"); + pGlGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)IRR_OGL_LOAD_EXTENSION("glGetUniformLocationARB"); + pGlGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)IRR_OGL_LOAD_EXTENSION("glGetUniformLocation"); + pGlUniform1fvARB = (PFNGLUNIFORM1FVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform1fvARB"); + pGlUniform2fvARB = (PFNGLUNIFORM2FVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform2fvARB"); + pGlUniform3fvARB = (PFNGLUNIFORM3FVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform3fvARB"); + pGlUniform4fvARB = (PFNGLUNIFORM4FVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform4fvARB"); + pGlUniform1ivARB = (PFNGLUNIFORM1IVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform1ivARB"); + pGlUniform2ivARB = (PFNGLUNIFORM2IVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform2ivARB"); + pGlUniform3ivARB = (PFNGLUNIFORM3IVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform3ivARB"); + pGlUniform4ivARB = (PFNGLUNIFORM4IVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniform4ivARB"); + pGlUniform1uiv = (PFNGLUNIFORM1UIVPROC)IRR_OGL_LOAD_EXTENSION("glUniform1uiv"); + pGlUniform2uiv = (PFNGLUNIFORM2UIVPROC)IRR_OGL_LOAD_EXTENSION("glUniform2uiv"); + pGlUniform3uiv = (PFNGLUNIFORM3UIVPROC)IRR_OGL_LOAD_EXTENSION("glUniform3uiv"); + pGlUniform4uiv = (PFNGLUNIFORM4UIVPROC)IRR_OGL_LOAD_EXTENSION("glUniform4uiv"); + pGlUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix2fvARB"); + pGlUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix2x3fv"); + pGlUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix2x4fv"); + pGlUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix3x2fv"); + pGlUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix3fvARB"); + pGlUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix3x4fv"); + pGlUniformMatrix4x2fv = (PFNGLUNIFORMMATRIX4X2FVPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix4x2fv"); + pGlUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix4x3fv"); + pGlUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix4fvARB"); + pGlGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC)IRR_OGL_LOAD_EXTENSION("glGetActiveUniformARB"); + pGlGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC)IRR_OGL_LOAD_EXTENSION("glGetActiveUniform"); + + // get point parameter extension + pGlPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC)IRR_OGL_LOAD_EXTENSION("glPointParameterfARB"); + pGlPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC)IRR_OGL_LOAD_EXTENSION("glPointParameterfvARB"); + + // get stencil extension + pGlStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC)IRR_OGL_LOAD_EXTENSION("glStencilFuncSeparate"); + pGlStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC)IRR_OGL_LOAD_EXTENSION("glStencilOpSeparate"); + pGlStencilFuncSeparateATI = (PFNGLSTENCILFUNCSEPARATEATIPROC)IRR_OGL_LOAD_EXTENSION("glStencilFuncSeparateATI"); + pGlStencilOpSeparateATI = (PFNGLSTENCILOPSEPARATEATIPROC)IRR_OGL_LOAD_EXTENSION("glStencilOpSeparateATI"); + + // compressed textures + pGlCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)IRR_OGL_LOAD_EXTENSION("glCompressedTexImage2D"); + pGlCompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC)IRR_OGL_LOAD_EXTENSION("glCompressedTexSubImage2D"); + + // ARB FrameBufferObjects + pGlBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glBindFramebuffer"); + pGlDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glDeleteFramebuffers"); + pGlGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glGenFramebuffers"); + pGlCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatus"); + pGlFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture2D"); + pGlBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glBindRenderbuffer"); + pGlDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glDeleteRenderbuffers"); + pGlGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glGenRenderbuffers"); + pGlRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)IRR_OGL_LOAD_EXTENSION("glRenderbufferStorage"); + pGlFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferRenderbuffer"); + pGlGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)IRR_OGL_LOAD_EXTENSION("glGenerateMipmap"); + + // EXT FrameBufferObjects + pGlBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)IRR_OGL_LOAD_EXTENSION("glBindFramebufferEXT"); + pGlDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)IRR_OGL_LOAD_EXTENSION("glDeleteFramebuffersEXT"); + pGlGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)IRR_OGL_LOAD_EXTENSION("glGenFramebuffersEXT"); + pGlCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatusEXT"); + pGlFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture2DEXT"); + pGlBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)IRR_OGL_LOAD_EXTENSION("glBindRenderbufferEXT"); + pGlDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)IRR_OGL_LOAD_EXTENSION("glDeleteRenderbuffersEXT"); + pGlGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)IRR_OGL_LOAD_EXTENSION("glGenRenderbuffersEXT"); + pGlRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)IRR_OGL_LOAD_EXTENSION("glRenderbufferStorageEXT"); + pGlFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferRenderbufferEXT"); + pGlGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC)IRR_OGL_LOAD_EXTENSION("glGenerateMipmapEXT"); + pGlDrawBuffersARB = (PFNGLDRAWBUFFERSARBPROC)IRR_OGL_LOAD_EXTENSION("glDrawBuffersARB"); + pGlDrawBuffersATI = (PFNGLDRAWBUFFERSATIPROC)IRR_OGL_LOAD_EXTENSION("glDrawBuffersATI"); + + // get vertex buffer extension + pGlGenBuffersARB = (PFNGLGENBUFFERSARBPROC)IRR_OGL_LOAD_EXTENSION("glGenBuffersARB"); + pGlBindBufferARB = (PFNGLBINDBUFFERARBPROC)IRR_OGL_LOAD_EXTENSION("glBindBufferARB"); + pGlBufferDataARB = (PFNGLBUFFERDATAARBPROC)IRR_OGL_LOAD_EXTENSION("glBufferDataARB"); + pGlDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)IRR_OGL_LOAD_EXTENSION("glDeleteBuffersARB"); + pGlBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)IRR_OGL_LOAD_EXTENSION("glBufferSubDataARB"); + pGlGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC)IRR_OGL_LOAD_EXTENSION("glGetBufferSubDataARB"); + pGlMapBufferARB = (PFNGLMAPBUFFERARBPROC)IRR_OGL_LOAD_EXTENSION("glMapBufferARB"); + pGlUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)IRR_OGL_LOAD_EXTENSION("glUnmapBufferARB"); + pGlIsBufferARB = (PFNGLISBUFFERARBPROC)IRR_OGL_LOAD_EXTENSION("glIsBufferARB"); + pGlGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)IRR_OGL_LOAD_EXTENSION("glGetBufferParameterivARB"); + pGlGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC)IRR_OGL_LOAD_EXTENSION("glGetBufferPointervARB"); + pGlProvokingVertexARB = (PFNGLPROVOKINGVERTEXPROC)IRR_OGL_LOAD_EXTENSION("glProvokingVertex"); + pGlProvokingVertexEXT = (PFNGLPROVOKINGVERTEXEXTPROC)IRR_OGL_LOAD_EXTENSION("glProvokingVertexEXT"); + pGlProgramParameteriARB = (PFNGLPROGRAMPARAMETERIARBPROC)IRR_OGL_LOAD_EXTENSION("glProgramParameteriARB"); + pGlProgramParameteriEXT = (PFNGLPROGRAMPARAMETERIEXTPROC)IRR_OGL_LOAD_EXTENSION("glProgramParameteriEXT"); + + // occlusion query + pGlGenQueriesARB = (PFNGLGENQUERIESARBPROC)IRR_OGL_LOAD_EXTENSION("glGenQueriesARB"); + pGlDeleteQueriesARB = (PFNGLDELETEQUERIESARBPROC)IRR_OGL_LOAD_EXTENSION("glDeleteQueriesARB"); + pGlIsQueryARB = (PFNGLISQUERYARBPROC)IRR_OGL_LOAD_EXTENSION("glIsQueryARB"); + pGlBeginQueryARB = (PFNGLBEGINQUERYARBPROC)IRR_OGL_LOAD_EXTENSION("glBeginQueryARB"); + pGlEndQueryARB = (PFNGLENDQUERYARBPROC)IRR_OGL_LOAD_EXTENSION("glEndQueryARB"); + pGlGetQueryivARB = (PFNGLGETQUERYIVARBPROC)IRR_OGL_LOAD_EXTENSION("glGetQueryivARB"); + pGlGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC)IRR_OGL_LOAD_EXTENSION("glGetQueryObjectivARB"); + pGlGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC)IRR_OGL_LOAD_EXTENSION("glGetQueryObjectuivARB"); + pGlGenOcclusionQueriesNV = (PFNGLGENOCCLUSIONQUERIESNVPROC)IRR_OGL_LOAD_EXTENSION("glGenOcclusionQueriesNV"); + pGlDeleteOcclusionQueriesNV = (PFNGLDELETEOCCLUSIONQUERIESNVPROC)IRR_OGL_LOAD_EXTENSION("glDeleteOcclusionQueriesNV"); + pGlIsOcclusionQueryNV = (PFNGLISOCCLUSIONQUERYNVPROC)IRR_OGL_LOAD_EXTENSION("glIsOcclusionQueryNV"); + pGlBeginOcclusionQueryNV = (PFNGLBEGINOCCLUSIONQUERYNVPROC)IRR_OGL_LOAD_EXTENSION("glBeginOcclusionQueryNV"); + pGlEndOcclusionQueryNV = (PFNGLENDOCCLUSIONQUERYNVPROC)IRR_OGL_LOAD_EXTENSION("glEndOcclusionQueryNV"); + pGlGetOcclusionQueryivNV = (PFNGLGETOCCLUSIONQUERYIVNVPROC)IRR_OGL_LOAD_EXTENSION("glGetOcclusionQueryivNV"); + pGlGetOcclusionQueryuivNV = (PFNGLGETOCCLUSIONQUERYUIVNVPROC)IRR_OGL_LOAD_EXTENSION("glGetOcclusionQueryuivNV"); + + // blend + pGlBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC)IRR_OGL_LOAD_EXTENSION("glBlendFuncSeparateEXT"); + pGlBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)IRR_OGL_LOAD_EXTENSION("glBlendFuncSeparate"); + pGlBlendEquationEXT = (PFNGLBLENDEQUATIONEXTPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquationEXT"); + pGlBlendEquation = (PFNGLBLENDEQUATIONPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquation"); + pGlBlendEquationSeparateEXT = (PFNGLBLENDEQUATIONSEPARATEEXTPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquationSeparateEXT"); + pGlBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquationSeparate"); + + // indexed + pGlEnableIndexedEXT = (PFNGLENABLEINDEXEDEXTPROC)IRR_OGL_LOAD_EXTENSION("glEnableIndexedEXT"); + pGlDisableIndexedEXT = (PFNGLDISABLEINDEXEDEXTPROC)IRR_OGL_LOAD_EXTENSION("glDisableIndexedEXT"); + pGlColorMaskIndexedEXT = (PFNGLCOLORMASKINDEXEDEXTPROC)IRR_OGL_LOAD_EXTENSION("glColorMaskIndexedEXT"); + pGlBlendFuncIndexedAMD = (PFNGLBLENDFUNCINDEXEDAMDPROC)IRR_OGL_LOAD_EXTENSION("glBlendFuncIndexedAMD"); + pGlBlendFunciARB = (PFNGLBLENDFUNCIPROC)IRR_OGL_LOAD_EXTENSION("glBlendFunciARB"); + pGlBlendFuncSeparateIndexedAMD = (PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC)IRR_OGL_LOAD_EXTENSION("glBlendFuncSeparateIndexedAMD"); + pGlBlendFuncSeparateiARB = (PFNGLBLENDFUNCSEPARATEIPROC)IRR_OGL_LOAD_EXTENSION("glBlendFuncSeparateiARB"); + pGlBlendEquationIndexedAMD = (PFNGLBLENDEQUATIONINDEXEDAMDPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquationIndexedAMD"); + pGlBlendEquationiARB = (PFNGLBLENDEQUATIONIPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquationiARB"); + pGlBlendEquationSeparateIndexedAMD = (PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquationSeparateIndexedAMD"); + pGlBlendEquationSeparateiARB = (PFNGLBLENDEQUATIONSEPARATEIPROC)IRR_OGL_LOAD_EXTENSION("glBlendEquationSeparateiARB"); + + pGlTextureStorage2D = (PFNGLTEXTURESTORAGE2DPROC)IRR_OGL_LOAD_EXTENSION("glTextureStorage2D"); + pGlTextureStorage3D = (PFNGLTEXTURESTORAGE3DPROC)IRR_OGL_LOAD_EXTENSION("glTextureStorage3D"); + pGlTextureSubImage2D = (PFNGLTEXTURESUBIMAGE2DPROC)IRR_OGL_LOAD_EXTENSION("glTextureSubImage2D"); + pGlGetTextureImage = (PFNGLGETTEXTUREIMAGEPROC)IRR_OGL_LOAD_EXTENSION("glGetTextureImage"); + pGlNamedFramebufferTexture = (PFNGLNAMEDFRAMEBUFFERTEXTUREPROC)IRR_OGL_LOAD_EXTENSION("glNamedFramebufferTexture"); + pGlTextureParameteri = (PFNGLTEXTUREPARAMETERIPROC)IRR_OGL_LOAD_EXTENSION("glTextureParameteri"); + pGlTextureParameterf = (PFNGLTEXTUREPARAMETERFPROC)IRR_OGL_LOAD_EXTENSION("glTextureParameterf"); + pGlTextureParameteriv = (PFNGLTEXTUREPARAMETERIVPROC)IRR_OGL_LOAD_EXTENSION("glTextureParameteriv"); + pGlTextureParameterfv = (PFNGLTEXTUREPARAMETERFVPROC)IRR_OGL_LOAD_EXTENSION("glTextureParameterfv"); + + pGlCreateTextures = (PFNGLCREATETEXTURESPROC)IRR_OGL_LOAD_EXTENSION("glCreateTextures"); + pGlCreateFramebuffers = (PFNGLCREATEFRAMEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glCreateFramebuffers"); + pGlBindTextures = (PFNGLBINDTEXTURESPROC)IRR_OGL_LOAD_EXTENSION("glBindTextures"); + pGlGenerateTextureMipmap = (PFNGLGENERATETEXTUREMIPMAPPROC)IRR_OGL_LOAD_EXTENSION("glGenerateTextureMipmap"); + //============================== + pGlTextureStorage2DEXT = (PFNGLTEXTURESTORAGE2DEXTPROC)IRR_OGL_LOAD_EXTENSION("glTextureStorage2DEXT"); + pGlTexStorage2D = (PFNGLTEXSTORAGE2DPROC)IRR_OGL_LOAD_EXTENSION("glTexStorage2D"); + pGlTextureStorage3DEXT = (PFNGLTEXTURESTORAGE3DEXTPROC)IRR_OGL_LOAD_EXTENSION("glTextureStorage3DEXT"); + pGlTexStorage3D = (PFNGLTEXSTORAGE3DPROC)IRR_OGL_LOAD_EXTENSION("glTexStorage3D"); + pGlTextureSubImage2DEXT = (PFNGLTEXTURESUBIMAGE2DEXTPROC)IRR_OGL_LOAD_EXTENSION("glTextureSubImage2DEXT"); + pGlGetTextureImageEXT = (PFNGLGETTEXTUREIMAGEEXTPROC)IRR_OGL_LOAD_EXTENSION("glGetTextureImageEXT"); + pGlNamedFramebufferTextureEXT = (PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC)IRR_OGL_LOAD_EXTENSION("glNamedFramebufferTextureEXT"); + pGlFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture"); + pGlActiveTexture = (PFNGLACTIVETEXTUREPROC)IRR_OGL_LOAD_EXTENSION("glActiveTexture"); + pGlGenerateTextureMipmapEXT = (PFNGLGENERATETEXTUREMIPMAPEXTPROC)IRR_OGL_LOAD_EXTENSION("glGenerateTextureMipmapEXT"); + +// get vsync extension +#if defined(WGL_EXT_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + pWglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)IRR_OGL_LOAD_EXTENSION("wglSwapIntervalEXT"); +#endif +#if defined(GLX_SGI_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + pGlxSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)IRR_OGL_LOAD_EXTENSION("glXSwapIntervalSGI"); +#endif +#if defined(GLX_EXT_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + pGlxSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)IRR_OGL_LOAD_EXTENSION("glXSwapIntervalEXT"); +#endif +#if defined(GLX_MESA_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + pGlxSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)IRR_OGL_LOAD_EXTENSION("glXSwapIntervalMESA"); +#endif + + GLint num = 0; + // set some properties +#if defined(GL_ARB_multitexture) || defined(GL_VERSION_1_3) + if (Version > 102 || FeatureAvailable[IRR_ARB_multitexture]) { +#if defined(GL_MAX_TEXTURE_UNITS) + glGetIntegerv(GL_MAX_TEXTURE_UNITS, &num); +#elif defined(GL_MAX_TEXTURE_UNITS_ARB) + glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &num); +#endif + Feature.MaxTextureUnits = static_cast(num); // MULTITEXTURING (fixed function pipeline texture units) + } +#endif +#if defined(GL_ARB_vertex_shader) || defined(GL_VERSION_2_0) + if (Version >= 200 || FeatureAvailable[IRR_ARB_vertex_shader]) { + num = 0; +#if defined(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS) + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &num); +#elif defined(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB) + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &num); +#endif + Feature.MaxTextureUnits = core::max_(Feature.MaxTextureUnits, static_cast(num)); + } +#endif + glGetIntegerv(GL_MAX_LIGHTS, &num); + MaxLights = static_cast(num); +#ifdef GL_EXT_texture_filter_anisotropic + if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic]) { + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &num); + MaxAnisotropy = static_cast(num); + } +#endif +#ifdef GL_VERSION_1_2 + if (Version > 101) { + glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &num); + MaxIndices = num; + } +#endif + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &num); + MaxTextureSize = static_cast(num); + if (queryFeature(EVDF_GEOMETRY_SHADER)) { +#if defined(GL_ARB_geometry_shader4) || defined(GL_EXT_geometry_shader4) || defined(GL_NV_geometry_shader4) + glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, &num); + MaxGeometryVerticesOut = static_cast(num); +#elif defined(GL_NV_geometry_program4) + extGlGetProgramiv(GEOMETRY_PROGRAM_NV, GL_MAX_PROGRAM_OUTPUT_VERTICES_NV, &num); + MaxGeometryVerticesOut = static_cast(num); +#endif + } +#ifdef GL_EXT_texture_lod_bias + if (FeatureAvailable[IRR_EXT_texture_lod_bias]) + glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias); +#endif + glGetIntegerv(GL_MAX_CLIP_PLANES, &num); + MaxUserClipPlanes = static_cast(num); + glGetIntegerv(GL_AUX_BUFFERS, &num); + MaxAuxBuffers = static_cast(num); +#ifdef GL_ARB_draw_buffers + if (FeatureAvailable[IRR_ARB_draw_buffers]) { + glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &num); + Feature.MultipleRenderTarget = static_cast(num); + } +#endif +#if defined(GL_ATI_draw_buffers) +#ifdef GL_ARB_draw_buffers + else +#endif + if (FeatureAvailable[IRR_ATI_draw_buffers]) { + glGetIntegerv(GL_MAX_DRAW_BUFFERS_ATI, &num); + Feature.MultipleRenderTarget = static_cast(num); + } +#endif +#ifdef GL_ARB_framebuffer_object + if (FeatureAvailable[IRR_ARB_framebuffer_object]) { + glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &num); + Feature.ColorAttachment = static_cast(num); + } +#endif +#if defined(GL_EXT_framebuffer_object) +#ifdef GL_ARB_framebuffer_object + else +#endif + if (FeatureAvailable[IRR_EXT_framebuffer_object]) { + glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &num); + Feature.ColorAttachment = static_cast(num); + } +#endif + + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); + glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, DimSmoothedLine); + glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, DimSmoothedPoint); +#if defined(GL_ARB_shading_language_100) || defined(GL_VERSION_2_0) + if (FeatureAvailable[IRR_ARB_shading_language_100] || Version >= 200) { + glGetError(); // clean error buffer +#ifdef GL_SHADING_LANGUAGE_VERSION + const GLubyte *shaderVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); +#else + const GLubyte *shaderVersion = glGetString(GL_SHADING_LANGUAGE_VERSION_ARB); +#endif + if (glGetError() == GL_INVALID_ENUM) + ShaderLanguageVersion = 100; + else { + const f32 sl_ver = core::fast_atof(reinterpret_cast(shaderVersion)); + ShaderLanguageVersion = static_cast(core::floor32(sl_ver) * 100 + core::round32(core::fract(sl_ver) * 10.0f)); + } + } +#endif + + if (!pGlActiveTextureARB || !pGlClientActiveTextureARB) { + Feature.MaxTextureUnits = 1; + os::Printer::log("Failed to load OpenGL's multitexture extension, proceeding without.", ELL_WARNING); + } else + Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast(MATERIAL_MAX_TEXTURES)); + +#ifdef GL_ARB_occlusion_query + if (FeatureAvailable[IRR_ARB_occlusion_query]) { + extGlGetQueryiv(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, + &num); + OcclusionQuerySupport = (num > 0); + } else +#endif +#ifdef GL_NV_occlusion_query + if (FeatureAvailable[IRR_NV_occlusion_query]) { + glGetIntegerv(GL_PIXEL_COUNTER_BITS_NV, &num); + OcclusionQuerySupport = (num > 0); + } else +#endif + OcclusionQuerySupport = false; + + Feature.BlendOperation = (Version >= 104) || + FeatureAvailable[IRR_EXT_blend_minmax] || + FeatureAvailable[IRR_EXT_blend_subtract] || + FeatureAvailable[IRR_EXT_blend_logic_op]; + +#ifdef _DEBUG + if (FeatureAvailable[IRR_NVX_gpu_memory_info]) { + // undocumented flags, so use the RAW values + GLint val; + glGetIntegerv(0x9047, &val); + os::Printer::log("Dedicated video memory (kB)", core::stringc(val)); + glGetIntegerv(0x9048, &val); + os::Printer::log("Total video memory (kB)", core::stringc(val)); + glGetIntegerv(0x9049, &val); + os::Printer::log("Available video memory (kB)", core::stringc(val)); + } +#ifdef GL_ATI_meminfo + if (FeatureAvailable[IRR_ATI_meminfo]) { + GLint val[4]; + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, val); + os::Printer::log("Free texture memory (kB)", core::stringc(val[0])); + glGetIntegerv(GL_VBO_FREE_MEMORY_ATI, val); + os::Printer::log("Free VBO memory (kB)", core::stringc(val[0])); + glGetIntegerv(GL_RENDERBUFFER_FREE_MEMORY_ATI, val); + os::Printer::log("Free render buffer memory (kB)", core::stringc(val[0])); + } +#endif + + if (queryFeature(EVDF_TEXTURE_CUBEMAP_SEAMLESS)) + glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + +#endif +} + +const COpenGLCoreFeature &COpenGLExtensionHandler::getFeature() const +{ + return Feature; +} + +bool COpenGLExtensionHandler::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const +{ + switch (feature) { + case EVDF_RENDER_TO_TARGET: + return true; + case EVDF_HARDWARE_TL: + return true; // we cannot tell other things + case EVDF_MULTITEXTURE: + return Feature.MaxTextureUnits > 1; + case EVDF_BILINEAR_FILTER: + return true; + case EVDF_MIP_MAP: + return true; + case EVDF_MIP_MAP_AUTO_UPDATE: + return !IsAtiRadeonX && (FeatureAvailable[IRR_SGIS_generate_mipmap] || FeatureAvailable[IRR_EXT_framebuffer_object] || FeatureAvailable[IRR_ARB_framebuffer_object]); + case EVDF_STENCIL_BUFFER: + return StencilBuffer; + case EVDF_VERTEX_SHADER_1_1: + case EVDF_ARB_VERTEX_PROGRAM_1: + return FeatureAvailable[IRR_ARB_vertex_program] || FeatureAvailable[IRR_NV_vertex_program1_1]; + case EVDF_PIXEL_SHADER_1_1: + case EVDF_PIXEL_SHADER_1_2: + case EVDF_ARB_FRAGMENT_PROGRAM_1: + return FeatureAvailable[IRR_ARB_fragment_program] || FeatureAvailable[IRR_NV_fragment_program]; + case EVDF_PIXEL_SHADER_2_0: + case EVDF_VERTEX_SHADER_2_0: + case EVDF_ARB_GLSL: + return (FeatureAvailable[IRR_ARB_shading_language_100] || Version >= 200); + case EVDF_TEXTURE_NSQUARE: + return true; // non-square is always supported + case EVDF_TEXTURE_NPOT: + // Some ATI cards seem to have only SW support in OpenGL 2.0 + // drivers if the extension is not exposed, so we skip this + // extra test for now! + // return (FeatureAvailable[IRR_ARB_texture_non_power_of_two]||Version>=200); + return (FeatureAvailable[IRR_ARB_texture_non_power_of_two]); + case EVDF_FRAMEBUFFER_OBJECT: + return FeatureAvailable[IRR_EXT_framebuffer_object] || FeatureAvailable[IRR_ARB_framebuffer_object]; + case EVDF_VERTEX_BUFFER_OBJECT: + return FeatureAvailable[IRR_ARB_vertex_buffer_object]; + case EVDF_COLOR_MASK: + return true; + case EVDF_ALPHA_TO_COVERAGE: + return FeatureAvailable[IRR_ARB_multisample]; + case EVDF_GEOMETRY_SHADER: + return FeatureAvailable[IRR_ARB_geometry_shader4] || FeatureAvailable[IRR_EXT_geometry_shader4] || FeatureAvailable[IRR_NV_geometry_program4] || FeatureAvailable[IRR_NV_geometry_shader4]; + case EVDF_MULTIPLE_RENDER_TARGETS: + return FeatureAvailable[IRR_ARB_draw_buffers] || FeatureAvailable[IRR_ATI_draw_buffers]; + case EVDF_MRT_BLEND: + case EVDF_MRT_COLOR_MASK: + return FeatureAvailable[IRR_EXT_draw_buffers2]; + case EVDF_MRT_BLEND_FUNC: + return FeatureAvailable[IRR_ARB_draw_buffers_blend] || FeatureAvailable[IRR_AMD_draw_buffers_blend]; + case EVDF_OCCLUSION_QUERY: + return FeatureAvailable[IRR_ARB_occlusion_query] && OcclusionQuerySupport; + case EVDF_POLYGON_OFFSET: + // both features supported with OpenGL 1.1 + return Version >= 101; + case EVDF_BLEND_OPERATIONS: + return Feature.BlendOperation; + case EVDF_BLEND_SEPARATE: + return (Version >= 104) || FeatureAvailable[IRR_EXT_blend_func_separate]; + case EVDF_TEXTURE_MATRIX: + return true; + case EVDF_TEXTURE_CUBEMAP: + return (Version >= 103) || FeatureAvailable[IRR_ARB_texture_cube_map] || FeatureAvailable[IRR_EXT_texture_cube_map]; + case EVDF_TEXTURE_CUBEMAP_SEAMLESS: + return FeatureAvailable[IRR_ARB_seamless_cube_map]; + case EVDF_DEPTH_CLAMP: + return FeatureAvailable[IRR_NV_depth_clamp] || FeatureAvailable[IRR_ARB_depth_clamp]; + + default: + return false; + }; +} + +} +} + +#endif diff --git a/irr/src/COpenGLExtensionHandler.h b/irr/src/COpenGLExtensionHandler.h new file mode 100644 index 000000000..ada1c9a3a --- /dev/null +++ b/irr/src/COpenGLExtensionHandler.h @@ -0,0 +1,2616 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "EDriverFeatures.h" +#include "irrTypes.h" +#include "os.h" + +#include "COpenGLCommon.h" + +#include "COpenGLCoreFeature.h" + +namespace irr +{ +namespace video +{ + +class IContextManager; + +static const char *const OpenGLFeatureStrings[] = { + "GL_3DFX_multisample", + "GL_3DFX_tbuffer", + "GL_3DFX_texture_compression_FXT1", + "GL_AMD_blend_minmax_factor", + "GL_AMD_conservative_depth", + "GL_AMD_debug_output", + "GL_AMD_depth_clamp_separate", + "GL_AMD_draw_buffers_blend", + "GL_AMD_interleaved_elements", + "GL_AMD_multi_draw_indirect", + "GL_AMD_name_gen_delete", + "GL_AMD_performance_monitor", + "GL_AMD_pinned_memory", + "GL_AMD_query_buffer_object", + "GL_AMD_sample_positions", + "GL_AMD_seamless_cubemap_per_texture", + "GL_AMD_shader_atomic_counter_ops", + "GL_AMD_shader_stencil_export", + "GL_AMD_shader_trinary_minmax", + "GL_AMD_sparse_texture", + "GL_AMD_stencil_operation_extended", + "GL_AMD_texture_texture4", + "GL_AMD_transform_feedback3_lines_triangles", + "GL_AMD_vertex_shader_layer", + "GL_AMD_vertex_shader_tessellator", + "GL_AMD_vertex_shader_viewport_index", + "GL_APPLE_aux_depth_stencil", + "GL_APPLE_client_storage", + "GL_APPLE_element_array", + "GL_APPLE_fence", + "GL_APPLE_float_pixels", + "GL_APPLE_flush_buffer_range", + "GL_APPLE_object_purgeable", + "GL_APPLE_rgb_422", + "GL_APPLE_row_bytes", + "GL_APPLE_specular_vector", + "GL_APPLE_texture_range", + "GL_APPLE_transform_hint", + "GL_APPLE_vertex_array_object", + "GL_APPLE_vertex_array_range", + "GL_APPLE_vertex_program_evaluators", + "GL_APPLE_ycbcr_422", + "GL_ARB_arrays_of_arrays", + "GL_ARB_base_instance", + "GL_ARB_bindless_texture", + "GL_ARB_blend_func_extended", + "GL_ARB_buffer_storage", + "GL_ARB_cl_event", + "GL_ARB_clear_buffer_object", + "GL_ARB_clear_texture", + "GL_ARB_color_buffer_float", + "GL_ARB_compatibility", + "GL_ARB_compressed_texture_pixel_storage", + "GL_ARB_compute_shader", + "GL_ARB_compute_variable_group_size", + "GL_ARB_conservative_depth", + "GL_ARB_copy_buffer", + "GL_ARB_copy_image", + "GL_ARB_debug_output", + "GL_ARB_depth_buffer_float", + "GL_ARB_depth_clamp", + "GL_ARB_depth_texture", + "GL_ARB_direct_state_access", + "GL_ARB_draw_buffers", + "GL_ARB_draw_buffers_blend", + "GL_ARB_draw_elements_base_vertex", + "GL_ARB_draw_indirect", + "GL_ARB_draw_instanced", + "GL_ARB_ES2_compatibility", + "GL_ARB_ES3_compatibility", + "GL_ARB_enhanced_layouts", + "GL_ARB_explicit_attrib_location", + "GL_ARB_explicit_uniform_location", + "GL_ARB_fragment_coord_conventions", + "GL_ARB_fragment_layer_viewport", + "GL_ARB_fragment_program", + "GL_ARB_fragment_program_shadow", + "GL_ARB_fragment_shader", + "GL_ARB_framebuffer_no_attachments", + "GL_ARB_framebuffer_object", + "GL_ARB_framebuffer_sRGB", + "GL_ARB_geometry_shader4", + "GL_ARB_get_program_binary", + "GL_ARB_gpu_shader5", + "GL_ARB_gpu_shader_fp64", + "GL_ARB_half_float_pixel", + "GL_ARB_half_float_vertex", + "GL_ARB_imaging", + "GL_ARB_indirect_parameters", + "GL_ARB_instanced_arrays", + "GL_ARB_internalformat_query", + "GL_ARB_internalformat_query2", + "GL_ARB_invalidate_subdata", + "GL_ARB_map_buffer_alignment", + "GL_ARB_map_buffer_range", + "GL_ARB_matrix_palette", + "GL_ARB_multi_bind", + "GL_ARB_multi_draw_indirect", + "GL_ARB_multisample", + "GL_ARB_multitexture", + "GL_ARB_occlusion_query", + "GL_ARB_occlusion_query2", + "GL_ARB_pixel_buffer_object", + "GL_ARB_point_parameters", + "GL_ARB_point_sprite", + "GL_ARB_program_interface_query", + "GL_ARB_provoking_vertex", + "GL_ARB_query_buffer_object", + "GL_ARB_robust_buffer_access_behavior", + "GL_ARB_robustness", + "GL_ARB_robustness_isolation", + "GL_ARB_sample_shading", + "GL_ARB_sampler_objects", + "GL_ARB_seamless_cube_map", + "GL_ARB_seamless_cubemap_per_texture", + "GL_ARB_separate_shader_objects", + "GL_ARB_shader_atomic_counters", + "GL_ARB_shader_bit_encoding", + "GL_ARB_shader_draw_parameters", + "GL_ARB_shader_group_vote", + "GL_ARB_shader_image_load_store", + "GL_ARB_shader_image_size", + "GL_ARB_shader_objects", + "GL_ARB_shader_precision", + "GL_ARB_shader_stencil_export", + "GL_ARB_shader_storage_buffer_object", + "GL_ARB_shader_subroutine", + "GL_ARB_shader_texture_lod", + "GL_ARB_shading_language_100", + "GL_ARB_shading_language_420pack", + "GL_ARB_shading_language_include", + "GL_ARB_shading_language_packing", + "GL_ARB_shadow", + "GL_ARB_shadow_ambient", + "GL_ARB_sparse_texture", + "GL_ARB_stencil_texturing", + "GL_ARB_sync", + "GL_ARB_tessellation_shader", + "GL_ARB_texture_border_clamp", + "GL_ARB_texture_buffer_object", + "GL_ARB_texture_buffer_object_rgb32", + "GL_ARB_texture_buffer_range", + "GL_ARB_texture_compression", + "GL_ARB_texture_compression_bptc", + "GL_ARB_texture_compression_rgtc", + "GL_ARB_texture_cube_map", + "GL_ARB_texture_cube_map_array", + "GL_ARB_texture_env_add", + "GL_ARB_texture_env_combine", + "GL_ARB_texture_env_crossbar", + "GL_ARB_texture_env_dot3", + "GL_ARB_texture_float", + "GL_ARB_texture_gather", + "GL_ARB_texture_mirror_clamp_to_edge", + "GL_ARB_texture_mirrored_repeat", + "GL_ARB_texture_multisample", + "GL_ARB_texture_non_power_of_two", + "GL_ARB_texture_query_levels", + "GL_ARB_texture_query_lod", + "GL_ARB_texture_rectangle", + "GL_ARB_texture_rg", + "GL_ARB_texture_rgb10_a2ui", + "GL_ARB_texture_stencil8", + "GL_ARB_texture_storage", + "GL_ARB_texture_storage_multisample", + "GL_ARB_texture_swizzle", + "GL_ARB_texture_view", + "GL_ARB_timer_query", + "GL_ARB_transform_feedback2", + "GL_ARB_transform_feedback3", + "GL_ARB_transform_feedback_instanced", + "GL_ARB_transpose_matrix", + "GL_ARB_uniform_buffer_object", + "GL_ARB_vertex_array_bgra", + "GL_ARB_vertex_array_object", + "GL_ARB_vertex_attrib_64bit", + "GL_ARB_vertex_attrib_binding", + "GL_ARB_vertex_blend", + "GL_ARB_vertex_buffer_object", + "GL_ARB_vertex_program", + "GL_ARB_vertex_shader", + "GL_ARB_vertex_type_10f_11f_11f_rev", + "GL_ARB_vertex_type_2_10_10_10_rev", + "GL_ARB_viewport_array", + "GL_ARB_window_pos", + "GL_ATI_draw_buffers", + "GL_ATI_element_array", + "GL_ATI_envmap_bumpmap", + "GL_ATI_fragment_shader", + "GL_ATI_map_object_buffer", + "GL_ATI_meminfo", + "GL_ATI_pixel_format_float", + "GL_ATI_pn_triangles", + "GL_ATI_separate_stencil", + "GL_ATI_text_fragment_shader", + "GL_ATI_texture_env_combine3", + "GL_ATI_texture_float", + "GL_ATI_texture_mirror_once", + "GL_ATI_vertex_array_object", + "GL_ATI_vertex_attrib_array_object", + "GL_ATI_vertex_streams", + "GL_EXT_422_pixels", + "GL_EXT_abgr", + "GL_EXT_bgra", + "GL_EXT_bindable_uniform", + "GL_EXT_blend_color", + "GL_EXT_blend_equation_separate", + "GL_EXT_blend_func_separate", + "GL_EXT_blend_logic_op", + "GL_EXT_blend_minmax", + "GL_EXT_blend_subtract", + "GL_EXT_clip_volume_hint", + "GL_EXT_cmyka", + "GL_EXT_color_subtable", + "GL_EXT_compiled_vertex_array", + "GL_EXT_convolution", + "GL_EXT_coordinate_frame", + "GL_EXT_copy_texture", + "GL_EXT_cull_vertex", + "GL_EXT_debug_label", + "GL_EXT_debug_marker", + "GL_EXT_depth_bounds_test", + "GL_EXT_direct_state_access", + "GL_EXT_draw_buffers2", + "GL_EXT_draw_instanced", + "GL_EXT_draw_range_elements", + "GL_EXT_fog_coord", + "GL_EXT_framebuffer_blit", + "GL_EXT_framebuffer_multisample", + "GL_EXT_framebuffer_multisample_blit_scaled", + "GL_EXT_framebuffer_object", + "GL_EXT_framebuffer_sRGB", + "GL_EXT_geometry_shader4", + "GL_EXT_gpu_program_parameters", + "GL_EXT_gpu_shader4", + "GL_EXT_histogram", + "GL_EXT_index_array_formats", + "GL_EXT_index_func", + "GL_EXT_index_material", + "GL_EXT_index_texture", + "GL_EXT_light_texture", + "GL_EXT_misc_attribute", + "GL_EXT_multi_draw_arrays", + "GL_EXT_multisample", + "GL_EXT_packed_depth_stencil", + "GL_EXT_packed_float", + "GL_EXT_packed_pixels", + "GL_EXT_paletted_texture", + "GL_EXT_pixel_buffer_object", + "GL_EXT_pixel_transform", + "GL_EXT_pixel_transform_color_table", + "GL_EXT_point_parameters", + "GL_EXT_polygon_offset", + "GL_EXT_provoking_vertex", + "GL_EXT_rescale_normal", + "GL_EXT_secondary_color", + "GL_EXT_separate_shader_objects", + "GL_EXT_separate_specular_color", + "GL_EXT_shader_image_load_store", + "GL_EXT_shader_integer_mix", + "GL_EXT_shadow_funcs", + "GL_EXT_shared_texture_palette", + "GL_EXT_stencil_clear_tag", + "GL_EXT_stencil_two_side", + "GL_EXT_stencil_wrap", + "GL_EXT_subtexture", + "GL_EXT_texture", + "GL_EXT_texture3D", + "GL_EXT_texture_array", + "GL_EXT_texture_buffer_object", + "GL_EXT_texture_compression_latc", + "GL_EXT_texture_compression_rgtc", + "GL_EXT_texture_compression_s3tc", + "GL_EXT_texture_cube_map", + "GL_EXT_texture_env_add", + "GL_EXT_texture_env_combine", + "GL_EXT_texture_env_dot3", + "GL_EXT_texture_filter_anisotropic", + "GL_EXT_texture_integer", + "GL_EXT_texture_lod_bias", + "GL_EXT_texture_mirror_clamp", + "GL_EXT_texture_object", + "GL_EXT_texture_perturb_normal", + "GL_EXT_texture_shared_exponent", + "GL_EXT_texture_snorm", + "GL_EXT_texture_sRGB", + "GL_EXT_texture_sRGB_decode", + "GL_EXT_texture_swizzle", + "GL_EXT_timer_query", + "GL_EXT_transform_feedback", + "GL_EXT_vertex_array", + "GL_EXT_vertex_array_bgra", + "GL_EXT_vertex_attrib_64bit", + "GL_EXT_vertex_shader", + "GL_EXT_vertex_weighting", + "GL_EXT_x11_sync_object", + "GL_GREMEDY_frame_terminator", + "GL_GREMEDY_string_marker", + "GL_HP_convolution_border_modes", + "GL_HP_image_transform", + "GL_HP_occlusion_test", + "GL_HP_texture_lighting", + "GL_IBM_cull_vertex", + "GL_IBM_multimode_draw_arrays", + "GL_IBM_rasterpos_clip", + "GL_IBM_static_data", + "GL_IBM_texture_mirrored_repeat", + "GL_IBM_vertex_array_lists", + "GL_INGR_blend_func_separate", + "GL_INGR_color_clamp", + "GL_INGR_interlace_read", + "GL_INGR_palette_buffer", + "GL_INTEL_map_texture", + "GL_INTEL_parallel_arrays", + "GL_INTEL_texture_scissor", + "GL_KHR_debug", + "GL_KHR_texture_compression_astc_hdr", + "GL_KHR_texture_compression_astc_ldr", + "GL_MESA_pack_invert", + "GL_MESA_resize_buffers", + "GL_MESA_window_pos", + "GL_MESAX_texture_stack", + "GL_MESA_ycbcr_texture", + "GL_NVX_conditional_render", + "GL_NV_bindless_multi_draw_indirect", + "GL_NV_bindless_texture", + "GL_NV_blend_equation_advanced", + "GL_NV_blend_equation_advanced_coherent", + "GL_NV_blend_square", + "GL_NV_compute_program5", + "GL_NV_conditional_render", + "GL_NV_copy_depth_to_color", + "GL_NV_copy_image", + "GL_NV_deep_texture3D", + "GL_NV_depth_buffer_float", + "GL_NV_depth_clamp", + "GL_NV_draw_texture", + "GL_NV_evaluators", + "GL_NV_explicit_multisample", + "GL_NV_fence", + "GL_NV_float_buffer", + "GL_NV_fog_distance", + "GL_NV_fragment_program", + "GL_NV_fragment_program2", + "GL_NV_fragment_program4", + "GL_NV_fragment_program_option", + "GL_NV_framebuffer_multisample_coverage", + "GL_NV_geometry_program4", + "GL_NV_geometry_shader4", + "GL_NV_gpu_program4", + "GL_NV_gpu_program5", + "GL_NV_gpu_program5_mem_extended", + "GL_NV_gpu_shader5", + "GL_NV_half_float", + "GL_NV_light_max_exponent", + "GL_NV_multisample_coverage", + "GL_NV_multisample_filter_hint", + "GL_NV_occlusion_query", + "GL_NV_packed_depth_stencil", + "GL_NV_parameter_buffer_object", + "GL_NV_parameter_buffer_object2", + "GL_NV_path_rendering", + "GL_NV_pixel_data_range", + "GL_NV_point_sprite", + "GL_NV_present_video", + "GL_NV_primitive_restart", + "GL_NV_register_combiners", + "GL_NV_register_combiners2", + "GL_NV_shader_atomic_counters", + "GL_NV_shader_atomic_float", + "GL_NV_shader_buffer_load", + "GL_NV_shader_buffer_store", + "GL_NV_shader_storage_buffer_object", + "GL_NV_tessellation_program5", + "GL_NV_texgen_emboss", + "GL_NV_texgen_reflection", + "GL_NV_texture_barrier", + "GL_NV_texture_compression_vtc", + "GL_NV_texture_env_combine4", + "GL_NV_texture_expand_normal", + "GL_NV_texture_multisample", + "GL_NV_texture_rectangle", + "GL_NV_texture_shader", + "GL_NV_texture_shader2", + "GL_NV_texture_shader3", + "GL_NV_transform_feedback", + "GL_NV_transform_feedback2", + "GL_NV_vdpau_interop", + "GL_NV_vertex_array_range", + "GL_NV_vertex_array_range2", + "GL_NV_vertex_attrib_integer_64bit", + "GL_NV_vertex_buffer_unified_memory", + "GL_NV_vertex_program", + "GL_NV_vertex_program1_1", + "GL_NV_vertex_program2", + "GL_NV_vertex_program2_option", + "GL_NV_vertex_program3", + "GL_NV_vertex_program4", + "GL_NV_video_capture", + "GL_OES_byte_coordinates", + "GL_OES_compressed_paletted_texture", + "GL_OES_fixed_point", + "GL_OES_query_matrix", + "GL_OES_read_format", + "GL_OES_single_precision", + "GL_OML_interlace", + "GL_OML_resample", + "GL_OML_subsample", + "GL_PGI_misc_hints", + "GL_PGI_vertex_hints", + "GL_REND_screen_coordinates", + "GL_S3_s3tc", + "GL_SGI_color_matrix", + "GL_SGI_color_table", + "GL_SGI_texture_color_table", + "GL_SGIS_detail_texture", + "GL_SGIS_fog_function", + "GL_SGIS_generate_mipmap", + "GL_SGIS_multisample", + "GL_SGIS_pixel_texture", + "GL_SGIS_point_line_texgen", + "GL_SGIS_point_parameters", + "GL_SGIS_sharpen_texture", + "GL_SGIS_texture4D", + "GL_SGIS_texture_border_clamp", + "GL_SGIS_texture_color_mask", + "GL_SGIS_texture_edge_clamp", + "GL_SGIS_texture_filter4", + "GL_SGIS_texture_lod", + "GL_SGIS_texture_select", + "GL_SGIX_async", + "GL_SGIX_async_histogram", + "GL_SGIX_async_pixel", + "GL_SGIX_blend_alpha_minmax", + "GL_SGIX_calligraphic_fragment", + "GL_SGIX_clipmap", + "GL_SGIX_convolution_accuracy", + "GL_SGIX_depth_pass_instrument", + "GL_SGIX_depth_texture", + "GL_SGIX_flush_raster", + "GL_SGIX_fog_offset", + "GL_SGIX_fog_scale", + "GL_SGIX_fragment_lighting", + "GL_SGIX_framezoom", + "GL_SGIX_igloo_interface", + "GL_SGIX_instruments", + "GL_SGIX_interlace", + "GL_SGIX_ir_instrument1", + "GL_SGIX_list_priority", + "GL_SGIX_pixel_texture", + "GL_SGIX_pixel_tiles", + "GL_SGIX_polynomial_ffd", + "GL_SGIX_reference_plane", + "GL_SGIX_resample", + "GL_SGIX_scalebias_hint", + "GL_SGIX_shadow", + "GL_SGIX_shadow_ambient", + "GL_SGIX_sprite", + "GL_SGIX_subsample", + "GL_SGIX_tag_sample_buffer", + "GL_SGIX_texture_add_env", + "GL_SGIX_texture_coordinate_clamp", + "GL_SGIX_texture_lod_bias", + "GL_SGIX_texture_multi_buffer", + "GL_SGIX_texture_scale_bias", + "GL_SGIX_vertex_preclip", + "GL_SGIX_ycrcb", + "GL_SGIX_ycrcba", + "GL_SGIX_ycrcb_subsample", + "GL_SUN_convolution_border_modes", + "GL_SUN_global_alpha", + "GL_SUN_mesh_array", + "GL_SUN_slice_accum", + "GL_SUN_triangle_list", + "GL_SUN_vertex", + "GL_SUNX_constant_data", + "GL_WIN_phong_shading", + "GL_WIN_specular_fog", + // unofficial stuff + "GL_NVX_gpu_memory_info"}; + +class COpenGLExtensionHandler +{ +public: + enum EOpenGLFeatures + { + IRR_3DFX_multisample = 0, + IRR_3DFX_tbuffer, + IRR_3DFX_texture_compression_FXT1, + IRR_AMD_blend_minmax_factor, + IRR_AMD_conservative_depth, + IRR_AMD_debug_output, + IRR_AMD_depth_clamp_separate, + IRR_AMD_draw_buffers_blend, + IRR_AMD_interleaved_elements, + IRR_AMD_multi_draw_indirect, + IRR_AMD_name_gen_delete, + IRR_AMD_performance_monitor, + IRR_AMD_pinned_memory, + IRR_AMD_query_buffer_object, + IRR_AMD_sample_positions, + IRR_AMD_seamless_cubemap_per_texture, + IRR_AMD_shader_atomic_counter_ops, + IRR_AMD_shader_stencil_export, + IRR_AMD_shader_trinary_minmax, + IRR_AMD_sparse_texture, + IRR_AMD_stencil_operation_extended, + IRR_AMD_texture_texture4, + IRR_AMD_transform_feedback3_lines_triangles, + IRR_AMD_vertex_shader_layer, + IRR_AMD_vertex_shader_tessellator, + IRR_AMD_vertex_shader_viewport_index, + IRR_APPLE_aux_depth_stencil, + IRR_APPLE_client_storage, + IRR_APPLE_element_array, + IRR_APPLE_fence, + IRR_APPLE_float_pixels, + IRR_APPLE_flush_buffer_range, + IRR_APPLE_object_purgeable, + IRR_APPLE_rgb_422, + IRR_APPLE_row_bytes, + IRR_APPLE_specular_vector, + IRR_APPLE_texture_range, + IRR_APPLE_transform_hint, + IRR_APPLE_vertex_array_object, + IRR_APPLE_vertex_array_range, + IRR_APPLE_vertex_program_evaluators, + IRR_APPLE_ycbcr_422, + IRR_ARB_arrays_of_arrays, + IRR_ARB_base_instance, + IRR_ARB_bindless_texture, + IRR_ARB_blend_func_extended, + IRR_ARB_buffer_storage, + IRR_ARB_cl_event, + IRR_ARB_clear_buffer_object, + IRR_ARB_clear_texture, + IRR_ARB_color_buffer_float, + IRR_ARB_compatibility, + IRR_ARB_compressed_texture_pixel_storage, + IRR_ARB_compute_shader, + IRR_ARB_compute_variable_group_size, + IRR_ARB_conservative_depth, + IRR_ARB_copy_buffer, + IRR_ARB_copy_image, + IRR_ARB_debug_output, + IRR_ARB_depth_buffer_float, + IRR_ARB_depth_clamp, + IRR_ARB_depth_texture, + IRR_ARB_direct_state_access, + IRR_ARB_draw_buffers, + IRR_ARB_draw_buffers_blend, + IRR_ARB_draw_elements_base_vertex, + IRR_ARB_draw_indirect, + IRR_ARB_draw_instanced, + IRR_ARB_ES2_compatibility, + IRR_ARB_ES3_compatibility, + IRR_ARB_enhanced_layouts, + IRR_ARB_explicit_attrib_location, + IRR_ARB_explicit_uniform_location, + IRR_ARB_fragment_coord_conventions, + IRR_ARB_fragment_layer_viewport, + IRR_ARB_fragment_program, + IRR_ARB_fragment_program_shadow, + IRR_ARB_fragment_shader, + IRR_ARB_framebuffer_no_attachments, + IRR_ARB_framebuffer_object, + IRR_ARB_framebuffer_sRGB, + IRR_ARB_geometry_shader4, + IRR_ARB_get_program_binary, + IRR_ARB_gpu_shader5, + IRR_ARB_gpu_shader_fp64, + IRR_ARB_half_float_pixel, + IRR_ARB_half_float_vertex, + IRR_ARB_imaging, + IRR_ARB_indirect_parameters, + IRR_ARB_instanced_arrays, + IRR_ARB_internalformat_query, + IRR_ARB_internalformat_query2, + IRR_ARB_invalidate_subdata, + IRR_ARB_map_buffer_alignment, + IRR_ARB_map_buffer_range, + IRR_ARB_matrix_palette, + IRR_ARB_multi_bind, + IRR_ARB_multi_draw_indirect, + IRR_ARB_multisample, + IRR_ARB_multitexture, + IRR_ARB_occlusion_query, + IRR_ARB_occlusion_query2, + IRR_ARB_pixel_buffer_object, + IRR_ARB_point_parameters, + IRR_ARB_point_sprite, + IRR_ARB_program_interface_query, + IRR_ARB_provoking_vertex, + IRR_ARB_query_buffer_object, + IRR_ARB_robust_buffer_access_behavior, + IRR_ARB_robustness, + IRR_ARB_robustness_isolation, + IRR_ARB_sample_shading, + IRR_ARB_sampler_objects, + IRR_ARB_seamless_cube_map, + IRR_ARB_seamless_cubemap_per_texture, + IRR_ARB_separate_shader_objects, + IRR_ARB_shader_atomic_counters, + IRR_ARB_shader_bit_encoding, + IRR_ARB_shader_draw_parameters, + IRR_ARB_shader_group_vote, + IRR_ARB_shader_image_load_store, + IRR_ARB_shader_image_size, + IRR_ARB_shader_objects, + IRR_ARB_shader_precision, + IRR_ARB_shader_stencil_export, + IRR_ARB_shader_storage_buffer_object, + IRR_ARB_shader_subroutine, + IRR_ARB_shader_texture_lod, + IRR_ARB_shading_language_100, + IRR_ARB_shading_language_420pack, + IRR_ARB_shading_language_include, + IRR_ARB_shading_language_packing, + IRR_ARB_shadow, + IRR_ARB_shadow_ambient, + IRR_ARB_sparse_texture, + IRR_ARB_stencil_texturing, + IRR_ARB_sync, + IRR_ARB_tessellation_shader, + IRR_ARB_texture_border_clamp, + IRR_ARB_texture_buffer_object, + IRR_ARB_texture_buffer_object_rgb32, + IRR_ARB_texture_buffer_range, + IRR_ARB_texture_compression, + IRR_ARB_texture_compression_bptc, + IRR_ARB_texture_compression_rgtc, + IRR_ARB_texture_cube_map, + IRR_ARB_texture_cube_map_array, + IRR_ARB_texture_env_add, + IRR_ARB_texture_env_combine, + IRR_ARB_texture_env_crossbar, + IRR_ARB_texture_env_dot3, + IRR_ARB_texture_float, + IRR_ARB_texture_gather, + IRR_ARB_texture_mirror_clamp_to_edge, + IRR_ARB_texture_mirrored_repeat, + IRR_ARB_texture_multisample, + IRR_ARB_texture_non_power_of_two, + IRR_ARB_texture_query_levels, + IRR_ARB_texture_query_lod, + IRR_ARB_texture_rectangle, + IRR_ARB_texture_rg, + IRR_ARB_texture_rgb10_a2ui, + IRR_ARB_texture_stencil8, + IRR_ARB_texture_storage, + IRR_ARB_texture_storage_multisample, + IRR_ARB_texture_swizzle, + IRR_ARB_texture_view, + IRR_ARB_timer_query, + IRR_ARB_transform_feedback2, + IRR_ARB_transform_feedback3, + IRR_ARB_transform_feedback_instanced, + IRR_ARB_transpose_matrix, + IRR_ARB_uniform_buffer_object, + IRR_ARB_vertex_array_bgra, + IRR_ARB_vertex_array_object, + IRR_ARB_vertex_attrib_64bit, + IRR_ARB_vertex_attrib_binding, + IRR_ARB_vertex_blend, + IRR_ARB_vertex_buffer_object, + IRR_ARB_vertex_program, + IRR_ARB_vertex_shader, + IRR_ARB_vertex_type_10f_11f_11f_rev, + IRR_ARB_vertex_type_2_10_10_10_rev, + IRR_ARB_viewport_array, + IRR_ARB_window_pos, + IRR_ATI_draw_buffers, + IRR_ATI_element_array, + IRR_ATI_envmap_bumpmap, + IRR_ATI_fragment_shader, + IRR_ATI_map_object_buffer, + IRR_ATI_meminfo, + IRR_ATI_pixel_format_float, + IRR_ATI_pn_triangles, + IRR_ATI_separate_stencil, + IRR_ATI_text_fragment_shader, + IRR_ATI_texture_env_combine3, + IRR_ATI_texture_float, + IRR_ATI_texture_mirror_once, + IRR_ATI_vertex_array_object, + IRR_ATI_vertex_attrib_array_object, + IRR_ATI_vertex_streams, + IRR_EXT_422_pixels, + IRR_EXT_abgr, + IRR_EXT_bgra, + IRR_EXT_bindable_uniform, + IRR_EXT_blend_color, + IRR_EXT_blend_equation_separate, + IRR_EXT_blend_func_separate, + IRR_EXT_blend_logic_op, + IRR_EXT_blend_minmax, + IRR_EXT_blend_subtract, + IRR_EXT_clip_volume_hint, + IRR_EXT_cmyka, + IRR_EXT_color_subtable, + IRR_EXT_compiled_vertex_array, + IRR_EXT_convolution, + IRR_EXT_coordinate_frame, + IRR_EXT_copy_texture, + IRR_EXT_cull_vertex, + IRR_EXT_debug_label, + IRR_EXT_debug_marker, + IRR_EXT_depth_bounds_test, + IRR_EXT_direct_state_access, + IRR_EXT_draw_buffers2, + IRR_EXT_draw_instanced, + IRR_EXT_draw_range_elements, + IRR_EXT_fog_coord, + IRR_EXT_framebuffer_blit, + IRR_EXT_framebuffer_multisample, + IRR_EXT_framebuffer_multisample_blit_scaled, + IRR_EXT_framebuffer_object, + IRR_EXT_framebuffer_sRGB, + IRR_EXT_geometry_shader4, + IRR_EXT_gpu_program_parameters, + IRR_EXT_gpu_shader4, + IRR_EXT_histogram, + IRR_EXT_index_array_formats, + IRR_EXT_index_func, + IRR_EXT_index_material, + IRR_EXT_index_texture, + IRR_EXT_light_texture, + IRR_EXT_misc_attribute, + IRR_EXT_multi_draw_arrays, + IRR_EXT_multisample, + IRR_EXT_packed_depth_stencil, + IRR_EXT_packed_float, + IRR_EXT_packed_pixels, + IRR_EXT_paletted_texture, + IRR_EXT_pixel_buffer_object, + IRR_EXT_pixel_transform, + IRR_EXT_pixel_transform_color_table, + IRR_EXT_point_parameters, + IRR_EXT_polygon_offset, + IRR_EXT_provoking_vertex, + IRR_EXT_rescale_normal, + IRR_EXT_secondary_color, + IRR_EXT_separate_shader_objects, + IRR_EXT_separate_specular_color, + IRR_EXT_shader_image_load_store, + IRR_EXT_shader_integer_mix, + IRR_EXT_shadow_funcs, + IRR_EXT_shared_texture_palette, + IRR_EXT_stencil_clear_tag, + IRR_EXT_stencil_two_side, + IRR_EXT_stencil_wrap, + IRR_EXT_subtexture, + IRR_EXT_texture, + IRR_EXT_texture3D, + IRR_EXT_texture_array, + IRR_EXT_texture_buffer_object, + IRR_EXT_texture_compression_latc, + IRR_EXT_texture_compression_rgtc, + IRR_EXT_texture_compression_s3tc, + IRR_EXT_texture_cube_map, + IRR_EXT_texture_env_add, + IRR_EXT_texture_env_combine, + IRR_EXT_texture_env_dot3, + IRR_EXT_texture_filter_anisotropic, + IRR_EXT_texture_integer, + IRR_EXT_texture_lod_bias, + IRR_EXT_texture_mirror_clamp, + IRR_EXT_texture_object, + IRR_EXT_texture_perturb_normal, + IRR_EXT_texture_shared_exponent, + IRR_EXT_texture_snorm, + IRR_EXT_texture_sRGB, + IRR_EXT_texture_sRGB_decode, + IRR_EXT_texture_swizzle, + IRR_EXT_timer_query, + IRR_EXT_transform_feedback, + IRR_EXT_vertex_array, + IRR_EXT_vertex_array_bgra, + IRR_EXT_vertex_attrib_64bit, + IRR_EXT_vertex_shader, + IRR_EXT_vertex_weighting, + IRR_EXT_x11_sync_object, + IRR_GREMEDY_frame_terminator, + IRR_GREMEDY_string_marker, + IRR_HP_convolution_border_modes, + IRR_HP_image_transform, + IRR_HP_occlusion_test, + IRR_HP_texture_lighting, + IRR_IBM_cull_vertex, + IRR_IBM_multimode_draw_arrays, + IRR_IBM_rasterpos_clip, + IRR_IBM_static_data, + IRR_IBM_texture_mirrored_repeat, + IRR_IBM_vertex_array_lists, + IRR_INGR_blend_func_separate, + IRR_INGR_color_clamp, + IRR_INGR_interlace_read, + IRR_INGR_palette_buffer, + IRR_INTEL_map_texture, + IRR_INTEL_parallel_arrays, + IRR_INTEL_texture_scissor, + IRR_KHR_debug, + IRR_KHR_texture_compression_astc_hdr, + IRR_KHR_texture_compression_astc_ldr, + IRR_MESA_pack_invert, + IRR_MESA_resize_buffers, + IRR_MESA_window_pos, + IRR_MESAX_texture_stack, + IRR_MESA_ycbcr_texture, + IRR_NVX_conditional_render, + IRR_NV_bindless_multi_draw_indirect, + IRR_NV_bindless_texture, + IRR_NV_blend_equation_advanced, + IRR_NV_blend_equation_advanced_coherent, + IRR_NV_blend_square, + IRR_NV_compute_program5, + IRR_NV_conditional_render, + IRR_NV_copy_depth_to_color, + IRR_NV_copy_image, + IRR_NV_deep_texture3D, + IRR_NV_depth_buffer_float, + IRR_NV_depth_clamp, + IRR_NV_draw_texture, + IRR_NV_evaluators, + IRR_NV_explicit_multisample, + IRR_NV_fence, + IRR_NV_float_buffer, + IRR_NV_fog_distance, + IRR_NV_fragment_program, + IRR_NV_fragment_program2, + IRR_NV_fragment_program4, + IRR_NV_fragment_program_option, + IRR_NV_framebuffer_multisample_coverage, + IRR_NV_geometry_program4, + IRR_NV_geometry_shader4, + IRR_NV_gpu_program4, + IRR_NV_gpu_program5, + IRR_NV_gpu_program5_mem_extended, + IRR_NV_gpu_shader5, + IRR_NV_half_float, + IRR_NV_light_max_exponent, + IRR_NV_multisample_coverage, + IRR_NV_multisample_filter_hint, + IRR_NV_occlusion_query, + IRR_NV_packed_depth_stencil, + IRR_NV_parameter_buffer_object, + IRR_NV_parameter_buffer_object2, + IRR_NV_path_rendering, + IRR_NV_pixel_data_range, + IRR_NV_point_sprite, + IRR_NV_present_video, + IRR_NV_primitive_restart, + IRR_NV_register_combiners, + IRR_NV_register_combiners2, + IRR_NV_shader_atomic_counters, + IRR_NV_shader_atomic_float, + IRR_NV_shader_buffer_load, + IRR_NV_shader_buffer_store, + IRR_NV_shader_storage_buffer_object, + IRR_NV_tessellation_program5, + IRR_NV_texgen_emboss, + IRR_NV_texgen_reflection, + IRR_NV_texture_barrier, + IRR_NV_texture_compression_vtc, + IRR_NV_texture_env_combine4, + IRR_NV_texture_expand_normal, + IRR_NV_texture_multisample, + IRR_NV_texture_rectangle, + IRR_NV_texture_shader, + IRR_NV_texture_shader2, + IRR_NV_texture_shader3, + IRR_NV_transform_feedback, + IRR_NV_transform_feedback2, + IRR_NV_vdpau_interop, + IRR_NV_vertex_array_range, + IRR_NV_vertex_array_range2, + IRR_NV_vertex_attrib_integer_64bit, + IRR_NV_vertex_buffer_unified_memory, + IRR_NV_vertex_program, + IRR_NV_vertex_program1_1, + IRR_NV_vertex_program2, + IRR_NV_vertex_program2_option, + IRR_NV_vertex_program3, + IRR_NV_vertex_program4, + IRR_NV_video_capture, + IRR_OES_byte_coordinates, + IRR_OES_compressed_paletted_texture, + IRR_OES_fixed_point, + IRR_OES_query_matrix, + IRR_OES_read_format, + IRR_OES_single_precision, + IRR_OML_interlace, + IRR_OML_resample, + IRR_OML_subsample, + IRR_PGI_misc_hints, + IRR_PGI_vertex_hints, + IRR_REND_screen_coordinates, + IRR_S3_s3tc, + IRR_SGI_color_matrix, + IRR_SGI_color_table, + IRR_SGI_texture_color_table, + IRR_SGIS_detail_texture, + IRR_SGIS_fog_function, + IRR_SGIS_generate_mipmap, + IRR_SGIS_multisample, + IRR_SGIS_pixel_texture, + IRR_SGIS_point_line_texgen, + IRR_SGIS_point_parameters, + IRR_SGIS_sharpen_texture, + IRR_SGIS_texture4D, + IRR_SGIS_texture_border_clamp, + IRR_SGIS_texture_color_mask, + IRR_SGIS_texture_edge_clamp, + IRR_SGIS_texture_filter4, + IRR_SGIS_texture_lod, + IRR_SGIS_texture_select, + IRR_SGIX_async, + IRR_SGIX_async_histogram, + IRR_SGIX_async_pixel, + IRR_SGIX_blend_alpha_minmax, + IRR_SGIX_calligraphic_fragment, + IRR_SGIX_clipmap, + IRR_SGIX_convolution_accuracy, + IRR_SGIX_depth_pass_instrument, + IRR_SGIX_depth_texture, + IRR_SGIX_flush_raster, + IRR_SGIX_fog_offset, + IRR_SGIX_fog_scale, + IRR_SGIX_fragment_lighting, + IRR_SGIX_framezoom, + IRR_SGIX_igloo_interface, + IRR_SGIX_instruments, + IRR_SGIX_interlace, + IRR_SGIX_ir_instrument1, + IRR_SGIX_list_priority, + IRR_SGIX_pixel_texture, + IRR_SGIX_pixel_tiles, + IRR_SGIX_polynomial_ffd, + IRR_SGIX_reference_plane, + IRR_SGIX_resample, + IRR_SGIX_scalebias_hint, + IRR_SGIX_shadow, + IRR_SGIX_shadow_ambient, + IRR_SGIX_sprite, + IRR_SGIX_subsample, + IRR_SGIX_tag_sample_buffer, + IRR_SGIX_texture_add_env, + IRR_SGIX_texture_coordinate_clamp, + IRR_SGIX_texture_lod_bias, + IRR_SGIX_texture_multi_buffer, + IRR_SGIX_texture_scale_bias, + IRR_SGIX_vertex_preclip, + IRR_SGIX_ycrcb, + IRR_SGIX_ycrcba, + IRR_SGIX_ycrcb_subsample, + IRR_SUN_convolution_border_modes, + IRR_SUN_global_alpha, + IRR_SUN_mesh_array, + IRR_SUN_slice_accum, + IRR_SUN_triangle_list, + IRR_SUN_vertex, + IRR_SUNX_constant_data, + IRR_WIN_phong_shading, + IRR_WIN_specular_fog, + IRR_NVX_gpu_memory_info, + IRR_OpenGL_Feature_Count + }; + + // constructor + COpenGLExtensionHandler(); + + // deferred initialization + void initExtensions(video::IContextManager *cmgr, bool stencilBuffer); + + const COpenGLCoreFeature &getFeature() const; + + //! queries the features of the driver, returns true if feature is available + bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const; + + //! queries the features of the driver, returns true if feature is available + bool queryOpenGLFeature(EOpenGLFeatures feature) const + { + return FeatureAvailable[feature]; + } + + //! show all features with availability + void dump(ELOG_LEVEL logLevel) const; + + // Some variables for properties + bool StencilBuffer; + bool TextureCompressionExtension; + + // Some non-boolean properties + //! Maximum hardware lights supported + u8 MaxLights; + //! Maximal Anisotropy + u8 MaxAnisotropy; + //! Number of user clipplanes + u8 MaxUserClipPlanes; + //! Number of auxiliary buffers + u8 MaxAuxBuffers; + //! Optimal number of indices per meshbuffer + u32 MaxIndices; + //! Maximal texture dimension + u32 MaxTextureSize; + //! Maximal vertices handled by geometry shaders + u32 MaxGeometryVerticesOut; + //! Maximal LOD Bias + f32 MaxTextureLODBias; + //! Minimal and maximal supported thickness for lines without smoothing + GLfloat DimAliasedLine[2]; + //! Minimal and maximal supported thickness for points without smoothing + GLfloat DimAliasedPoint[2]; + //! Minimal and maximal supported thickness for lines with smoothing + GLfloat DimSmoothedLine[2]; + //! Minimal and maximal supported thickness for points with smoothing + GLfloat DimSmoothedPoint[2]; + + //! OpenGL version as Integer: 100*Major+Minor, i.e. 2.1 becomes 201 + u16 Version; + //! GLSL version as Integer: 100*Major+Minor + u16 ShaderLanguageVersion; + + bool OcclusionQuerySupport; + + // Info needed for workarounds. + bool IsAtiRadeonX; + + //! Workaround until direct state access with framebuffers is stable enough in drivers + // https://devtalk.nvidia.com/default/topic/1030494/opengl/bug-amp-amp-spec-violation-checknamedframebufferstatus-returns-gl_framebuffer_incomplete_dimensions_ext-under-gl-4-5-core/ + // https://stackoverflow.com/questions/51304706/problems-with-attaching-textures-of-different-sizes-to-fbo + static bool needsDSAFramebufferHack; + + // public access to the (loaded) extensions. + // general functions + void irrGlActiveTexture(GLenum texture); + void irrGlClientActiveTexture(GLenum texture); + void extGlPointParameterf(GLint loc, GLfloat f); + void extGlPointParameterfv(GLint loc, const GLfloat *v); + void extGlStencilFuncSeparate(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); + void extGlStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass); + void irrGlCompressedTexImage2D(GLenum target, GLint level, + GLenum internalformat, GLsizei width, GLsizei height, + GLint border, GLsizei imageSize, const void *data); + void irrGlCompressedTexSubImage2D(GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, + GLenum format, GLsizei imageSize, const void *data); + + // shader programming + void extGlGenPrograms(GLsizei n, GLuint *programs); + void extGlBindProgram(GLenum target, GLuint program); + void extGlProgramString(GLenum target, GLenum format, GLsizei len, const GLvoid *string); + void extGlLoadProgram(GLenum target, GLuint id, GLsizei len, const GLubyte *string); + void extGlDeletePrograms(GLsizei n, const GLuint *programs); + void extGlProgramLocalParameter4fv(GLenum, GLuint, const GLfloat *); + GLhandleARB extGlCreateShaderObject(GLenum shaderType); + GLuint extGlCreateShader(GLenum shaderType); + // note: Due to the type confusion between shader_objects and OpenGL 2.0 + // we have to add the ARB extension for proper method definitions in case + // that handleARB and uint are the same type + void extGlShaderSourceARB(GLhandleARB shader, GLsizei numOfStrings, const char **strings, const GLint *lenOfStrings); + void extGlShaderSource(GLuint shader, GLsizei numOfStrings, const char **strings, const GLint *lenOfStrings); + // note: Due to the type confusion between shader_objects and OpenGL 2.0 + // we have to add the ARB extension for proper method definitions in case + // that handleARB and uint are the same type + void extGlCompileShaderARB(GLhandleARB shader); + void extGlCompileShader(GLuint shader); + GLhandleARB extGlCreateProgramObject(void); + GLuint extGlCreateProgram(void); + void extGlAttachObject(GLhandleARB program, GLhandleARB shader); + void extGlAttachShader(GLuint program, GLuint shader); + void extGlLinkProgramARB(GLhandleARB program); + // note: Due to the type confusion between shader_objects and OpenGL 2.0 + // we have to add the ARB extension for proper method definitions in case + // that handleARB and uint are the same type + void extGlLinkProgram(GLuint program); + void extGlUseProgramObject(GLhandleARB prog); + void irrGlUseProgram(GLuint prog); + void extGlDeleteObject(GLhandleARB object); + void extGlDeleteProgram(GLuint object); + void extGlDeleteShader(GLuint shader); + void extGlGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders); + void extGlGetAttachedObjects(GLhandleARB program, GLsizei maxcount, GLsizei *count, GLhandleARB *shaders); + void extGlGetInfoLog(GLhandleARB object, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); + void extGlGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog); + void extGlGetProgramInfoLog(GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infoLog); + void extGlGetObjectParameteriv(GLhandleARB object, GLenum type, GLint *param); + void extGlGetShaderiv(GLuint shader, GLenum type, GLint *param); + void extGlGetProgramiv(GLuint program, GLenum type, GLint *param); + GLint extGlGetUniformLocationARB(GLhandleARB program, const char *name); + GLint extGlGetUniformLocation(GLuint program, const char *name); + void extGlUniform1fv(GLint loc, GLsizei count, const GLfloat *v); + void extGlUniform2fv(GLint loc, GLsizei count, const GLfloat *v); + void extGlUniform3fv(GLint loc, GLsizei count, const GLfloat *v); + void extGlUniform4fv(GLint loc, GLsizei count, const GLfloat *v); + void extGlUniform1bv(GLint loc, GLsizei count, const bool *v); + void extGlUniform2bv(GLint loc, GLsizei count, const bool *v); + void extGlUniform3bv(GLint loc, GLsizei count, const bool *v); + void extGlUniform4bv(GLint loc, GLsizei count, const bool *v); + void extGlUniform1iv(GLint loc, GLsizei count, const GLint *v); + void extGlUniform2iv(GLint loc, GLsizei count, const GLint *v); + void extGlUniform3iv(GLint loc, GLsizei count, const GLint *v); + void extGlUniform4iv(GLint loc, GLsizei count, const GLint *v); + void extGlUniform1uiv(GLint loc, GLsizei count, const GLuint *v); + void extGlUniform2uiv(GLint loc, GLsizei count, const GLuint *v); + void extGlUniform3uiv(GLint loc, GLsizei count, const GLuint *v); + void extGlUniform4uiv(GLint loc, GLsizei count, const GLuint *v); + void extGlUniformMatrix2fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix2x3fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix2x4fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix3x2fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix3fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix3x4fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix4x2fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix4x3fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlUniformMatrix4fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); + void extGlGetActiveUniformARB(GLhandleARB program, GLuint index, GLsizei maxlength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); + void extGlGetActiveUniform(GLuint program, GLuint index, GLsizei maxlength, GLsizei *length, GLint *size, GLenum *type, GLchar *name); + + // framebuffer objects + void irrGlBindFramebuffer(GLenum target, GLuint framebuffer); + void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers); + void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers); + GLenum irrGlCheckFramebufferStatus(GLenum target); + void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + void irrGlBindRenderbuffer(GLenum target, GLuint renderbuffer); + void irrGlDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers); + void irrGlGenRenderbuffers(GLsizei n, GLuint *renderbuffers); + void irrGlRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); + void irrGlFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + void irrGlGenerateMipmap(GLenum target); + void irrGlActiveStencilFace(GLenum face); + void irrGlDrawBuffer(GLenum mode); + void irrGlDrawBuffers(GLsizei n, const GLenum *bufs); + + // vertex buffer object + void extGlGenBuffers(GLsizei n, GLuint *buffers); + void extGlBindBuffer(GLenum target, GLuint buffer); + void extGlBufferData(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); + void extGlDeleteBuffers(GLsizei n, const GLuint *buffers); + void extGlBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); + void extGlGetBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); + void *extGlMapBuffer(GLenum target, GLenum access); + GLboolean extGlUnmapBuffer(GLenum target); + GLboolean extGlIsBuffer(GLuint buffer); + void extGlGetBufferParameteriv(GLenum target, GLenum pname, GLint *params); + void extGlGetBufferPointerv(GLenum target, GLenum pname, GLvoid **params); + void extGlProvokingVertex(GLenum mode); + void extGlProgramParameteri(GLuint program, GLenum pname, GLint value); + + // occlusion query + void extGlGenQueries(GLsizei n, GLuint *ids); + void extGlDeleteQueries(GLsizei n, const GLuint *ids); + GLboolean extGlIsQuery(GLuint id); + void extGlBeginQuery(GLenum target, GLuint id); + void extGlEndQuery(GLenum target); + void extGlGetQueryiv(GLenum target, GLenum pname, GLint *params); + void extGlGetQueryObjectiv(GLuint id, GLenum pname, GLint *params); + void extGlGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params); + + // blend + void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); + void irrGlBlendEquation(GLenum mode); + + // indexed + void irrGlEnableIndexed(GLenum target, GLuint index); + void irrGlDisableIndexed(GLenum target, GLuint index); + void irrGlColorMaskIndexed(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a); + void irrGlBlendFuncIndexed(GLuint buf, GLenum src, GLenum dst); + void irrGlBlendFuncSeparateIndexed(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); + void irrGlBlendEquationIndexed(GLuint buf, GLenum mode); + void irrGlBlendEquationSeparateIndexed(GLuint buf, GLenum modeRGB, GLenum modeAlpha); + + void extGlTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); + void extGlTextureStorage2D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); + void extGlTextureStorage3D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); + void extGlGetTextureImage(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *pixels); + void extGlNamedFramebufferTexture(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); + void extGlTextureParameteri(GLuint texture, GLenum pname, GLint param); + void extGlTextureParameterf(GLuint texture, GLenum pname, GLfloat param); + void extGlTextureParameteriv(GLuint texture, GLenum pname, const GLint *params); + void extGlTextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params); + void extGlCreateTextures(GLenum target, GLsizei n, GLuint *textures); + void extGlCreateFramebuffers(GLsizei n, GLuint *framebuffers); + void extGlBindTextures(GLuint first, GLsizei count, const GLuint *textures, const GLenum *targets); + void extGlGenerateTextureMipmap(GLuint texture, GLenum target); + + // generic vsync setting method for several extensions + void extGlSwapInterval(int interval); + + // the global feature array + bool FeatureAvailable[IRR_OpenGL_Feature_Count]; + +protected: + COpenGLCoreFeature Feature; + + PFNGLACTIVETEXTUREPROC pGlActiveTexture; + PFNGLACTIVETEXTUREARBPROC pGlActiveTextureARB; + PFNGLCLIENTACTIVETEXTUREARBPROC pGlClientActiveTextureARB; + PFNGLGENPROGRAMSARBPROC pGlGenProgramsARB; + PFNGLGENPROGRAMSNVPROC pGlGenProgramsNV; + PFNGLBINDPROGRAMARBPROC pGlBindProgramARB; + PFNGLBINDPROGRAMNVPROC pGlBindProgramNV; + PFNGLDELETEPROGRAMSARBPROC pGlDeleteProgramsARB; + PFNGLDELETEPROGRAMSNVPROC pGlDeleteProgramsNV; + PFNGLPROGRAMSTRINGARBPROC pGlProgramStringARB; + PFNGLLOADPROGRAMNVPROC pGlLoadProgramNV; + PFNGLPROGRAMLOCALPARAMETER4FVARBPROC pGlProgramLocalParameter4fvARB; + PFNGLCREATESHADEROBJECTARBPROC pGlCreateShaderObjectARB; + PFNGLSHADERSOURCEARBPROC pGlShaderSourceARB; + PFNGLCOMPILESHADERARBPROC pGlCompileShaderARB; + PFNGLCREATEPROGRAMOBJECTARBPROC pGlCreateProgramObjectARB; + PFNGLATTACHOBJECTARBPROC pGlAttachObjectARB; + PFNGLLINKPROGRAMARBPROC pGlLinkProgramARB; + PFNGLUSEPROGRAMOBJECTARBPROC pGlUseProgramObjectARB; + PFNGLDELETEOBJECTARBPROC pGlDeleteObjectARB; + PFNGLCREATEPROGRAMPROC pGlCreateProgram; + PFNGLUSEPROGRAMPROC pGlUseProgram; + PFNGLDELETEPROGRAMPROC pGlDeleteProgram; + PFNGLDELETESHADERPROC pGlDeleteShader; + PFNGLGETATTACHEDOBJECTSARBPROC pGlGetAttachedObjectsARB; + PFNGLGETATTACHEDSHADERSPROC pGlGetAttachedShaders; + PFNGLCREATESHADERPROC pGlCreateShader; + PFNGLSHADERSOURCEPROC pGlShaderSource; + PFNGLCOMPILESHADERPROC pGlCompileShader; + PFNGLATTACHSHADERPROC pGlAttachShader; + PFNGLLINKPROGRAMPROC pGlLinkProgram; + PFNGLGETINFOLOGARBPROC pGlGetInfoLogARB; + PFNGLGETSHADERINFOLOGPROC pGlGetShaderInfoLog; + PFNGLGETPROGRAMINFOLOGPROC pGlGetProgramInfoLog; + PFNGLGETOBJECTPARAMETERIVARBPROC pGlGetObjectParameterivARB; + PFNGLGETSHADERIVPROC pGlGetShaderiv; + PFNGLGETSHADERIVPROC pGlGetProgramiv; + PFNGLGETUNIFORMLOCATIONARBPROC pGlGetUniformLocationARB; + PFNGLGETUNIFORMLOCATIONPROC pGlGetUniformLocation; + PFNGLUNIFORM1FVARBPROC pGlUniform1fvARB; + PFNGLUNIFORM2FVARBPROC pGlUniform2fvARB; + PFNGLUNIFORM3FVARBPROC pGlUniform3fvARB; + PFNGLUNIFORM4FVARBPROC pGlUniform4fvARB; + PFNGLUNIFORM1IVARBPROC pGlUniform1ivARB; + PFNGLUNIFORM2IVARBPROC pGlUniform2ivARB; + PFNGLUNIFORM3IVARBPROC pGlUniform3ivARB; + PFNGLUNIFORM4IVARBPROC pGlUniform4ivARB; + PFNGLUNIFORM1UIVPROC pGlUniform1uiv; + PFNGLUNIFORM2UIVPROC pGlUniform2uiv; + PFNGLUNIFORM3UIVPROC pGlUniform3uiv; + PFNGLUNIFORM4UIVPROC pGlUniform4uiv; + PFNGLUNIFORMMATRIX2FVARBPROC pGlUniformMatrix2fvARB; + PFNGLUNIFORMMATRIX2X3FVPROC pGlUniformMatrix2x3fv; + PFNGLUNIFORMMATRIX2X4FVPROC pGlUniformMatrix2x4fv; + PFNGLUNIFORMMATRIX3X2FVPROC pGlUniformMatrix3x2fv; + PFNGLUNIFORMMATRIX3FVARBPROC pGlUniformMatrix3fvARB; + PFNGLUNIFORMMATRIX3X4FVPROC pGlUniformMatrix3x4fv; + PFNGLUNIFORMMATRIX4X2FVPROC pGlUniformMatrix4x2fv; + PFNGLUNIFORMMATRIX4X3FVPROC pGlUniformMatrix4x3fv; + PFNGLUNIFORMMATRIX4FVARBPROC pGlUniformMatrix4fvARB; + PFNGLGETACTIVEUNIFORMARBPROC pGlGetActiveUniformARB; + PFNGLGETACTIVEUNIFORMPROC pGlGetActiveUniform; + PFNGLPOINTPARAMETERFARBPROC pGlPointParameterfARB; + PFNGLPOINTPARAMETERFVARBPROC pGlPointParameterfvARB; + PFNGLSTENCILFUNCSEPARATEPROC pGlStencilFuncSeparate; + PFNGLSTENCILOPSEPARATEPROC pGlStencilOpSeparate; + PFNGLSTENCILFUNCSEPARATEATIPROC pGlStencilFuncSeparateATI; + PFNGLSTENCILOPSEPARATEATIPROC pGlStencilOpSeparateATI; + PFNGLCOMPRESSEDTEXIMAGE2DPROC pGlCompressedTexImage2D; + PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC pGlCompressedTexSubImage2D; + // ARB framebuffer object + PFNGLBINDFRAMEBUFFERPROC pGlBindFramebuffer; + PFNGLDELETEFRAMEBUFFERSPROC pGlDeleteFramebuffers; + PFNGLGENFRAMEBUFFERSPROC pGlGenFramebuffers; + PFNGLCHECKFRAMEBUFFERSTATUSPROC pGlCheckFramebufferStatus; + PFNGLFRAMEBUFFERTEXTURE2DPROC pGlFramebufferTexture2D; + PFNGLBINDRENDERBUFFERPROC pGlBindRenderbuffer; + PFNGLDELETERENDERBUFFERSPROC pGlDeleteRenderbuffers; + PFNGLGENRENDERBUFFERSPROC pGlGenRenderbuffers; + PFNGLRENDERBUFFERSTORAGEPROC pGlRenderbufferStorage; + PFNGLFRAMEBUFFERRENDERBUFFERPROC pGlFramebufferRenderbuffer; + PFNGLGENERATEMIPMAPPROC pGlGenerateMipmap; + // EXT framebuffer object + PFNGLBINDFRAMEBUFFEREXTPROC pGlBindFramebufferEXT; + PFNGLDELETEFRAMEBUFFERSEXTPROC pGlDeleteFramebuffersEXT; + PFNGLGENFRAMEBUFFERSEXTPROC pGlGenFramebuffersEXT; + PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC pGlCheckFramebufferStatusEXT; + PFNGLFRAMEBUFFERTEXTURE2DEXTPROC pGlFramebufferTexture2DEXT; + PFNGLBINDRENDERBUFFEREXTPROC pGlBindRenderbufferEXT; + PFNGLDELETERENDERBUFFERSEXTPROC pGlDeleteRenderbuffersEXT; + PFNGLGENRENDERBUFFERSEXTPROC pGlGenRenderbuffersEXT; + PFNGLRENDERBUFFERSTORAGEEXTPROC pGlRenderbufferStorageEXT; + PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC pGlFramebufferRenderbufferEXT; + PFNGLGENERATEMIPMAPEXTPROC pGlGenerateMipmapEXT; + PFNGLACTIVESTENCILFACEEXTPROC pGlActiveStencilFaceEXT; + PFNGLDRAWBUFFERSARBPROC pGlDrawBuffersARB; + PFNGLDRAWBUFFERSATIPROC pGlDrawBuffersATI; + PFNGLGENBUFFERSARBPROC pGlGenBuffersARB; + PFNGLBINDBUFFERARBPROC pGlBindBufferARB; + PFNGLBUFFERDATAARBPROC pGlBufferDataARB; + PFNGLDELETEBUFFERSARBPROC pGlDeleteBuffersARB; + PFNGLBUFFERSUBDATAARBPROC pGlBufferSubDataARB; + PFNGLGETBUFFERSUBDATAARBPROC pGlGetBufferSubDataARB; + PFNGLMAPBUFFERARBPROC pGlMapBufferARB; + PFNGLUNMAPBUFFERARBPROC pGlUnmapBufferARB; + PFNGLISBUFFERARBPROC pGlIsBufferARB; + PFNGLGETBUFFERPARAMETERIVARBPROC pGlGetBufferParameterivARB; + PFNGLGETBUFFERPOINTERVARBPROC pGlGetBufferPointervARB; + PFNGLPROVOKINGVERTEXPROC pGlProvokingVertexARB; + PFNGLPROVOKINGVERTEXEXTPROC pGlProvokingVertexEXT; + PFNGLPROGRAMPARAMETERIARBPROC pGlProgramParameteriARB; + PFNGLPROGRAMPARAMETERIEXTPROC pGlProgramParameteriEXT; + PFNGLGENQUERIESARBPROC pGlGenQueriesARB; + PFNGLDELETEQUERIESARBPROC pGlDeleteQueriesARB; + PFNGLISQUERYARBPROC pGlIsQueryARB; + PFNGLBEGINQUERYARBPROC pGlBeginQueryARB; + PFNGLENDQUERYARBPROC pGlEndQueryARB; + PFNGLGETQUERYIVARBPROC pGlGetQueryivARB; + PFNGLGETQUERYOBJECTIVARBPROC pGlGetQueryObjectivARB; + PFNGLGETQUERYOBJECTUIVARBPROC pGlGetQueryObjectuivARB; + PFNGLGENOCCLUSIONQUERIESNVPROC pGlGenOcclusionQueriesNV; + PFNGLDELETEOCCLUSIONQUERIESNVPROC pGlDeleteOcclusionQueriesNV; + PFNGLISOCCLUSIONQUERYNVPROC pGlIsOcclusionQueryNV; + PFNGLBEGINOCCLUSIONQUERYNVPROC pGlBeginOcclusionQueryNV; + PFNGLENDOCCLUSIONQUERYNVPROC pGlEndOcclusionQueryNV; + PFNGLGETOCCLUSIONQUERYIVNVPROC pGlGetOcclusionQueryivNV; + PFNGLGETOCCLUSIONQUERYUIVNVPROC pGlGetOcclusionQueryuivNV; + // Blend + PFNGLBLENDFUNCSEPARATEEXTPROC pGlBlendFuncSeparateEXT; + PFNGLBLENDFUNCSEPARATEPROC pGlBlendFuncSeparate; + PFNGLBLENDEQUATIONEXTPROC pGlBlendEquationEXT; + PFNGLBLENDEQUATIONPROC pGlBlendEquation; + PFNGLBLENDEQUATIONSEPARATEEXTPROC pGlBlendEquationSeparateEXT; + PFNGLBLENDEQUATIONSEPARATEPROC pGlBlendEquationSeparate; + // Indexed + PFNGLENABLEINDEXEDEXTPROC pGlEnableIndexedEXT; + PFNGLDISABLEINDEXEDEXTPROC pGlDisableIndexedEXT; + PFNGLCOLORMASKINDEXEDEXTPROC pGlColorMaskIndexedEXT; + PFNGLBLENDFUNCINDEXEDAMDPROC pGlBlendFuncIndexedAMD; + PFNGLBLENDFUNCIPROC pGlBlendFunciARB; + PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC pGlBlendFuncSeparateIndexedAMD; + PFNGLBLENDFUNCSEPARATEIPROC pGlBlendFuncSeparateiARB; + PFNGLBLENDEQUATIONINDEXEDAMDPROC pGlBlendEquationIndexedAMD; + PFNGLBLENDEQUATIONIPROC pGlBlendEquationiARB; + PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC pGlBlendEquationSeparateIndexedAMD; + PFNGLBLENDEQUATIONSEPARATEIPROC pGlBlendEquationSeparateiARB; + + // DSA + PFNGLTEXTURESTORAGE2DPROC pGlTextureStorage2D; + PFNGLTEXTURESTORAGE3DPROC pGlTextureStorage3D; + PFNGLTEXTURESUBIMAGE2DPROC pGlTextureSubImage2D; + PFNGLGETTEXTUREIMAGEPROC pGlGetTextureImage; + PFNGLNAMEDFRAMEBUFFERTEXTUREPROC pGlNamedFramebufferTexture; + PFNGLTEXTUREPARAMETERIPROC pGlTextureParameteri; + PFNGLTEXTUREPARAMETERFPROC pGlTextureParameterf; + PFNGLTEXTUREPARAMETERIVPROC pGlTextureParameteriv; + PFNGLTEXTUREPARAMETERFVPROC pGlTextureParameterfv; + + PFNGLCREATETEXTURESPROC pGlCreateTextures; + PFNGLCREATEFRAMEBUFFERSPROC pGlCreateFramebuffers; + PFNGLBINDTEXTURESPROC pGlBindTextures; + PFNGLGENERATETEXTUREMIPMAPPROC pGlGenerateTextureMipmap; + // DSA with EXT or functions to simulate it + PFNGLTEXTURESTORAGE2DEXTPROC pGlTextureStorage2DEXT; + PFNGLTEXSTORAGE2DPROC pGlTexStorage2D; + PFNGLTEXTURESTORAGE3DEXTPROC pGlTextureStorage3DEXT; + PFNGLTEXSTORAGE3DPROC pGlTexStorage3D; + PFNGLTEXTURESUBIMAGE2DEXTPROC pGlTextureSubImage2DEXT; + PFNGLGETTEXTUREIMAGEEXTPROC pGlGetTextureImageEXT; + PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC pGlNamedFramebufferTextureEXT; + PFNGLFRAMEBUFFERTEXTUREPROC pGlFramebufferTexture; + PFNGLGENERATETEXTUREMIPMAPEXTPROC pGlGenerateTextureMipmapEXT; + +#if defined(WGL_EXT_swap_control) + PFNWGLSWAPINTERVALEXTPROC pWglSwapIntervalEXT; +#endif +#if defined(GLX_SGI_swap_control) + PFNGLXSWAPINTERVALSGIPROC pGlxSwapIntervalSGI; +#endif +#if defined(GLX_EXT_swap_control) + PFNGLXSWAPINTERVALEXTPROC pGlxSwapIntervalEXT; +#endif +#if defined(GLX_MESA_swap_control) + PFNGLXSWAPINTERVALMESAPROC pGlxSwapIntervalMESA; +#endif +}; + +inline void COpenGLExtensionHandler::irrGlActiveTexture(GLenum texture) +{ + if (pGlActiveTexture) + pGlActiveTexture(texture); + else if (pGlActiveTextureARB) + pGlActiveTextureARB(texture); +} + +inline void COpenGLExtensionHandler::irrGlClientActiveTexture(GLenum texture) +{ + if (pGlClientActiveTextureARB) + pGlClientActiveTextureARB(texture); +} + +inline void COpenGLExtensionHandler::extGlGenPrograms(GLsizei n, GLuint *programs) +{ + if (programs) + memset(programs, 0, n * sizeof(GLuint)); + if (pGlGenProgramsARB) + pGlGenProgramsARB(n, programs); + else if (pGlGenProgramsNV) + pGlGenProgramsNV(n, programs); +} + +inline void COpenGLExtensionHandler::extGlBindProgram(GLenum target, GLuint program) +{ + if (pGlBindProgramARB) + pGlBindProgramARB(target, program); + else if (pGlBindProgramNV) + pGlBindProgramNV(target, program); +} + +inline void COpenGLExtensionHandler::extGlProgramString(GLenum target, GLenum format, GLsizei len, const GLvoid *string) +{ + if (pGlProgramStringARB) + pGlProgramStringARB(target, format, len, string); +} + +inline void COpenGLExtensionHandler::extGlLoadProgram(GLenum target, GLuint id, GLsizei len, const GLubyte *string) +{ + if (pGlLoadProgramNV) + pGlLoadProgramNV(target, id, len, string); +} + +inline void COpenGLExtensionHandler::extGlDeletePrograms(GLsizei n, const GLuint *programs) +{ + if (pGlDeleteProgramsARB) + pGlDeleteProgramsARB(n, programs); + else if (pGlDeleteProgramsNV) + pGlDeleteProgramsNV(n, programs); +} + +inline void COpenGLExtensionHandler::extGlProgramLocalParameter4fv(GLenum n, GLuint i, const GLfloat *f) +{ + if (pGlProgramLocalParameter4fvARB) + pGlProgramLocalParameter4fvARB(n, i, f); +} + +inline GLhandleARB COpenGLExtensionHandler::extGlCreateShaderObject(GLenum shaderType) +{ + if (pGlCreateShaderObjectARB) + return pGlCreateShaderObjectARB(shaderType); + return 0; +} + +inline GLuint COpenGLExtensionHandler::extGlCreateShader(GLenum shaderType) +{ + if (pGlCreateShader) + return pGlCreateShader(shaderType); + return 0; +} + +inline void COpenGLExtensionHandler::extGlShaderSourceARB(GLhandleARB shader, GLsizei numOfStrings, const char **strings, const GLint *lenOfStrings) +{ + if (pGlShaderSourceARB) + pGlShaderSourceARB(shader, numOfStrings, strings, lenOfStrings); +} + +inline void COpenGLExtensionHandler::extGlShaderSource(GLuint shader, GLsizei numOfStrings, const char **strings, const GLint *lenOfStrings) +{ + if (pGlShaderSource) + pGlShaderSource(shader, numOfStrings, strings, lenOfStrings); +} + +inline void COpenGLExtensionHandler::extGlCompileShaderARB(GLhandleARB shader) +{ + if (pGlCompileShaderARB) + pGlCompileShaderARB(shader); +} + +inline void COpenGLExtensionHandler::extGlCompileShader(GLuint shader) +{ + if (pGlCompileShader) + pGlCompileShader(shader); +} + +inline GLhandleARB COpenGLExtensionHandler::extGlCreateProgramObject(void) +{ + if (pGlCreateProgramObjectARB) + return pGlCreateProgramObjectARB(); + return 0; +} + +inline GLuint COpenGLExtensionHandler::extGlCreateProgram(void) +{ + if (pGlCreateProgram) + return pGlCreateProgram(); + return 0; +} + +inline void COpenGLExtensionHandler::extGlAttachObject(GLhandleARB program, GLhandleARB shader) +{ + if (pGlAttachObjectARB) + pGlAttachObjectARB(program, shader); +} + +inline void COpenGLExtensionHandler::extGlAttachShader(GLuint program, GLuint shader) +{ + if (pGlAttachShader) + pGlAttachShader(program, shader); +} + +inline void COpenGLExtensionHandler::extGlLinkProgramARB(GLhandleARB program) +{ + if (pGlLinkProgramARB) + pGlLinkProgramARB(program); +} + +inline void COpenGLExtensionHandler::extGlLinkProgram(GLuint program) +{ + if (pGlLinkProgram) + pGlLinkProgram(program); +} + +inline void COpenGLExtensionHandler::extGlUseProgramObject(GLhandleARB prog) +{ + if (pGlUseProgramObjectARB) + pGlUseProgramObjectARB(prog); +} + +inline void COpenGLExtensionHandler::irrGlUseProgram(GLuint prog) +{ + if (pGlUseProgram) + pGlUseProgram(prog); +} + +inline void COpenGLExtensionHandler::extGlDeleteObject(GLhandleARB object) +{ + if (pGlDeleteObjectARB) + pGlDeleteObjectARB(object); +} + +inline void COpenGLExtensionHandler::extGlDeleteProgram(GLuint object) +{ + if (pGlDeleteProgram) + pGlDeleteProgram(object); +} + +inline void COpenGLExtensionHandler::extGlDeleteShader(GLuint shader) +{ + if (pGlDeleteShader) + pGlDeleteShader(shader); +} + +inline void COpenGLExtensionHandler::extGlGetAttachedObjects(GLhandleARB program, GLsizei maxcount, GLsizei *count, GLhandleARB *shaders) +{ + if (count) + *count = 0; + if (pGlGetAttachedObjectsARB) + pGlGetAttachedObjectsARB(program, maxcount, count, shaders); +} + +inline void COpenGLExtensionHandler::extGlGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders) +{ + if (count) + *count = 0; + if (pGlGetAttachedShaders) + pGlGetAttachedShaders(program, maxcount, count, shaders); +} + +inline void COpenGLExtensionHandler::extGlGetInfoLog(GLhandleARB object, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog) +{ + if (length) + *length = 0; + if (pGlGetInfoLogARB) + pGlGetInfoLogARB(object, maxLength, length, infoLog); +} + +inline void COpenGLExtensionHandler::extGlGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog) +{ + if (length) + *length = 0; + if (pGlGetShaderInfoLog) + pGlGetShaderInfoLog(shader, maxLength, length, infoLog); +} + +inline void COpenGLExtensionHandler::extGlGetProgramInfoLog(GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infoLog) +{ + if (length) + *length = 0; + if (pGlGetProgramInfoLog) + pGlGetProgramInfoLog(program, maxLength, length, infoLog); +} + +inline void COpenGLExtensionHandler::extGlGetObjectParameteriv(GLhandleARB object, GLenum type, GLint *param) +{ + if (pGlGetObjectParameterivARB) + pGlGetObjectParameterivARB(object, type, param); +} + +inline void COpenGLExtensionHandler::extGlGetShaderiv(GLuint shader, GLenum type, GLint *param) +{ + if (pGlGetShaderiv) + pGlGetShaderiv(shader, type, param); +} + +inline void COpenGLExtensionHandler::extGlGetProgramiv(GLuint program, GLenum type, GLint *param) +{ + if (pGlGetProgramiv) + pGlGetProgramiv(program, type, param); +} + +inline GLint COpenGLExtensionHandler::extGlGetUniformLocationARB(GLhandleARB program, const char *name) +{ + if (pGlGetUniformLocationARB) + return pGlGetUniformLocationARB(program, name); + return 0; +} + +inline GLint COpenGLExtensionHandler::extGlGetUniformLocation(GLuint program, const char *name) +{ + if (pGlGetUniformLocation) + return pGlGetUniformLocation(program, name); + return 0; +} + +inline void COpenGLExtensionHandler::extGlUniform1fv(GLint loc, GLsizei count, const GLfloat *v) +{ + if (pGlUniform1fvARB) + pGlUniform1fvARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform2fv(GLint loc, GLsizei count, const GLfloat *v) +{ + if (pGlUniform2fvARB) + pGlUniform2fvARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform3fv(GLint loc, GLsizei count, const GLfloat *v) +{ + if (pGlUniform3fvARB) + pGlUniform3fvARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform4fv(GLint loc, GLsizei count, const GLfloat *v) +{ + if (pGlUniform4fvARB) + pGlUniform4fvARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform1uiv(GLint loc, GLsizei count, const GLuint *v) +{ + if (pGlUniform1uiv) + pGlUniform1uiv(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform2uiv(GLint loc, GLsizei count, const GLuint *v) +{ + if (pGlUniform2uiv) + pGlUniform2uiv(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform3uiv(GLint loc, GLsizei count, const GLuint *v) +{ + if (pGlUniform3uiv) + pGlUniform3uiv(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform4uiv(GLint loc, GLsizei count, const GLuint *v) +{ + if (pGlUniform4uiv) + pGlUniform4uiv(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform1iv(GLint loc, GLsizei count, const GLint *v) +{ + if (pGlUniform1ivARB) + pGlUniform1ivARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform2iv(GLint loc, GLsizei count, const GLint *v) +{ + if (pGlUniform2ivARB) + pGlUniform2ivARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform3iv(GLint loc, GLsizei count, const GLint *v) +{ + if (pGlUniform3ivARB) + pGlUniform3ivARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniform4iv(GLint loc, GLsizei count, const GLint *v) +{ + if (pGlUniform4ivARB) + pGlUniform4ivARB(loc, count, v); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix2fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix2fvARB) + pGlUniformMatrix2fvARB(loc, count, transpose, v); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix2x3fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix2x3fv) + pGlUniformMatrix2x3fv(loc, count, transpose, v); + else + os::Printer::log("glUniformMatrix2x3fv not supported", ELL_ERROR); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix2x4fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix2x4fv) + pGlUniformMatrix2x4fv(loc, count, transpose, v); + else + os::Printer::log("glUniformMatrix2x4fv not supported", ELL_ERROR); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix3x2fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix3x2fv) + pGlUniformMatrix3x2fv(loc, count, transpose, v); + else + os::Printer::log("glUniformMatrix3x2fv not supported", ELL_ERROR); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix3fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix3fvARB) + pGlUniformMatrix3fvARB(loc, count, transpose, v); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix3x4fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix3x4fv) + pGlUniformMatrix3x4fv(loc, count, transpose, v); + else + os::Printer::log("glUniformMatrix3x4fv not supported", ELL_ERROR); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix4x2fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix4x2fv) + pGlUniformMatrix4x2fv(loc, count, transpose, v); + else + os::Printer::log("glUniformMatrix4x2fv not supported", ELL_ERROR); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix4x3fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix4x3fv) + pGlUniformMatrix4x3fv(loc, count, transpose, v); + else + os::Printer::log("glUniformMatrix4x3fv not supported", ELL_ERROR); +} + +inline void COpenGLExtensionHandler::extGlUniformMatrix4fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v) +{ + if (pGlUniformMatrix4fvARB) + pGlUniformMatrix4fvARB(loc, count, transpose, v); +} + +inline void COpenGLExtensionHandler::extGlGetActiveUniformARB(GLhandleARB program, + GLuint index, GLsizei maxlength, GLsizei *length, + GLint *size, GLenum *type, GLcharARB *name) +{ + if (length) + *length = 0; + if (pGlGetActiveUniformARB) + pGlGetActiveUniformARB(program, index, maxlength, length, size, type, name); +} + +inline void COpenGLExtensionHandler::extGlGetActiveUniform(GLuint program, + GLuint index, GLsizei maxlength, GLsizei *length, + GLint *size, GLenum *type, GLchar *name) +{ + if (length) + *length = 0; + if (pGlGetActiveUniform) + pGlGetActiveUniform(program, index, maxlength, length, size, type, name); +} + +inline void COpenGLExtensionHandler::extGlPointParameterf(GLint loc, GLfloat f) +{ + if (pGlPointParameterfARB) + pGlPointParameterfARB(loc, f); +} + +inline void COpenGLExtensionHandler::extGlPointParameterfv(GLint loc, const GLfloat *v) +{ + if (pGlPointParameterfvARB) + pGlPointParameterfvARB(loc, v); +} + +inline void COpenGLExtensionHandler::extGlStencilFuncSeparate(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask) +{ + if (pGlStencilFuncSeparate) + pGlStencilFuncSeparate(frontfunc, backfunc, ref, mask); + else if (pGlStencilFuncSeparateATI) + pGlStencilFuncSeparateATI(frontfunc, backfunc, ref, mask); +} + +inline void COpenGLExtensionHandler::extGlStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) +{ + if (pGlStencilOpSeparate) + pGlStencilOpSeparate(face, fail, zfail, zpass); + else if (pGlStencilOpSeparateATI) + pGlStencilOpSeparateATI(face, fail, zfail, zpass); +} + +inline void COpenGLExtensionHandler::irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, + GLsizei height, GLint border, GLsizei imageSize, const void *data) +{ + if (pGlCompressedTexImage2D) + pGlCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); +} + +inline void COpenGLExtensionHandler::irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) +{ + if (pGlCompressedTexSubImage2D) + pGlCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); +} + +inline void COpenGLExtensionHandler::irrGlBindFramebuffer(GLenum target, GLuint framebuffer) +{ + if (pGlBindFramebuffer) + pGlBindFramebuffer(target, framebuffer); + else if (pGlBindFramebufferEXT) + pGlBindFramebufferEXT(target, framebuffer); +} + +inline void COpenGLExtensionHandler::irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) +{ + if (pGlDeleteFramebuffers) + pGlDeleteFramebuffers(n, framebuffers); + else if (pGlDeleteFramebuffersEXT) + pGlDeleteFramebuffersEXT(n, framebuffers); +} + +inline void COpenGLExtensionHandler::irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) +{ + if (framebuffers) + memset(framebuffers, 0, n * sizeof(GLuint)); + if (pGlGenFramebuffers) + pGlGenFramebuffers(n, framebuffers); + else if (pGlGenFramebuffersEXT) + pGlGenFramebuffersEXT(n, framebuffers); +} + +inline GLenum COpenGLExtensionHandler::irrGlCheckFramebufferStatus(GLenum target) +{ + if (pGlCheckFramebufferStatus) + return pGlCheckFramebufferStatus(target); + else if (pGlCheckFramebufferStatusEXT) + return pGlCheckFramebufferStatusEXT(target); + else + return 0; +} + +inline void COpenGLExtensionHandler::irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + if (pGlFramebufferTexture2D) + pGlFramebufferTexture2D(target, attachment, textarget, texture, level); + else if (pGlFramebufferTexture2DEXT) + pGlFramebufferTexture2DEXT(target, attachment, textarget, texture, level); +} + +inline void COpenGLExtensionHandler::irrGlBindRenderbuffer(GLenum target, GLuint renderbuffer) +{ + if (pGlBindRenderbuffer) + pGlBindRenderbuffer(target, renderbuffer); + else if (pGlBindRenderbufferEXT) + pGlBindRenderbufferEXT(target, renderbuffer); +} + +inline void COpenGLExtensionHandler::irrGlDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) +{ + if (pGlDeleteRenderbuffers) + pGlDeleteRenderbuffers(n, renderbuffers); + else if (pGlDeleteRenderbuffersEXT) + pGlDeleteRenderbuffersEXT(n, renderbuffers); +} + +inline void COpenGLExtensionHandler::irrGlGenRenderbuffers(GLsizei n, GLuint *renderbuffers) +{ + if (renderbuffers) + memset(renderbuffers, 0, n * sizeof(GLuint)); + if (pGlGenRenderbuffers) + pGlGenRenderbuffers(n, renderbuffers); + else if (pGlGenRenderbuffersEXT) + pGlGenRenderbuffersEXT(n, renderbuffers); +} + +inline void COpenGLExtensionHandler::irrGlRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +{ + if (pGlRenderbufferStorage) + pGlRenderbufferStorage(target, internalformat, width, height); + else if (pGlRenderbufferStorageEXT) + pGlRenderbufferStorageEXT(target, internalformat, width, height); +} + +inline void COpenGLExtensionHandler::irrGlFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +{ + if (pGlFramebufferRenderbuffer) + pGlFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer); + else if (pGlFramebufferRenderbufferEXT) + pGlFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer); +} + +inline void COpenGLExtensionHandler::irrGlGenerateMipmap(GLenum target) +{ + if (pGlGenerateMipmap) + pGlGenerateMipmap(target); + else if (pGlGenerateMipmapEXT) + pGlGenerateMipmapEXT(target); +} + +inline void COpenGLExtensionHandler::irrGlActiveStencilFace(GLenum face) +{ + if (pGlActiveStencilFaceEXT) + pGlActiveStencilFaceEXT(face); +} + +inline void COpenGLExtensionHandler::irrGlDrawBuffer(GLenum mode) +{ + glDrawBuffer(mode); +} + +inline void COpenGLExtensionHandler::irrGlDrawBuffers(GLsizei n, const GLenum *bufs) +{ + if (pGlDrawBuffersARB) + pGlDrawBuffersARB(n, bufs); + else if (pGlDrawBuffersATI) + pGlDrawBuffersATI(n, bufs); +} + +inline void COpenGLExtensionHandler::extGlGenBuffers(GLsizei n, GLuint *buffers) +{ + if (buffers) + memset(buffers, 0, n * sizeof(GLuint)); + if (pGlGenBuffersARB) + pGlGenBuffersARB(n, buffers); +} + +inline void COpenGLExtensionHandler::extGlBindBuffer(GLenum target, GLuint buffer) +{ + if (pGlBindBufferARB) + pGlBindBufferARB(target, buffer); +} + +inline void COpenGLExtensionHandler::extGlBufferData(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) +{ + if (pGlBufferDataARB) + pGlBufferDataARB(target, size, data, usage); +} + +inline void COpenGLExtensionHandler::extGlDeleteBuffers(GLsizei n, const GLuint *buffers) +{ + if (pGlDeleteBuffersARB) + pGlDeleteBuffersARB(n, buffers); +} + +inline void COpenGLExtensionHandler::extGlBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) +{ + if (pGlBufferSubDataARB) + pGlBufferSubDataARB(target, offset, size, data); +} + +inline void COpenGLExtensionHandler::extGlGetBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data) +{ + if (pGlGetBufferSubDataARB) + pGlGetBufferSubDataARB(target, offset, size, data); +} + +inline void *COpenGLExtensionHandler::extGlMapBuffer(GLenum target, GLenum access) +{ + if (pGlMapBufferARB) + return pGlMapBufferARB(target, access); + return 0; +} + +inline GLboolean COpenGLExtensionHandler::extGlUnmapBuffer(GLenum target) +{ + if (pGlUnmapBufferARB) + return pGlUnmapBufferARB(target); + return false; +} + +inline GLboolean COpenGLExtensionHandler::extGlIsBuffer(GLuint buffer) +{ + if (pGlIsBufferARB) + return pGlIsBufferARB(buffer); + return false; +} + +inline void COpenGLExtensionHandler::extGlGetBufferParameteriv(GLenum target, GLenum pname, GLint *params) +{ + if (pGlGetBufferParameterivARB) + pGlGetBufferParameterivARB(target, pname, params); +} + +inline void COpenGLExtensionHandler::extGlGetBufferPointerv(GLenum target, GLenum pname, GLvoid **params) +{ + if (pGlGetBufferPointervARB) + pGlGetBufferPointervARB(target, pname, params); +} + +inline void COpenGLExtensionHandler::extGlProvokingVertex(GLenum mode) +{ + if (FeatureAvailable[IRR_ARB_provoking_vertex] && pGlProvokingVertexARB) + pGlProvokingVertexARB(mode); + else if (FeatureAvailable[IRR_EXT_provoking_vertex] && pGlProvokingVertexEXT) + pGlProvokingVertexEXT(mode); +} + +inline void COpenGLExtensionHandler::extGlProgramParameteri(GLuint program, GLenum pname, GLint value) +{ + if (queryFeature(EVDF_GEOMETRY_SHADER)) { + if (pGlProgramParameteriARB) + pGlProgramParameteriARB(program, pname, value); + else if (pGlProgramParameteriEXT) + pGlProgramParameteriEXT(program, pname, value); + } +} + +inline void COpenGLExtensionHandler::extGlGenQueries(GLsizei n, GLuint *ids) +{ + if (pGlGenQueriesARB) + pGlGenQueriesARB(n, ids); + else if (pGlGenOcclusionQueriesNV) + pGlGenOcclusionQueriesNV(n, ids); +} + +inline void COpenGLExtensionHandler::extGlDeleteQueries(GLsizei n, const GLuint *ids) +{ + if (pGlDeleteQueriesARB) + pGlDeleteQueriesARB(n, ids); + else if (pGlDeleteOcclusionQueriesNV) + pGlDeleteOcclusionQueriesNV(n, ids); +} + +inline GLboolean COpenGLExtensionHandler::extGlIsQuery(GLuint id) +{ + if (pGlIsQueryARB) + return pGlIsQueryARB(id); + else if (pGlIsOcclusionQueryNV) + return pGlIsOcclusionQueryNV(id); + return false; +} + +inline void COpenGLExtensionHandler::extGlBeginQuery(GLenum target, GLuint id) +{ + if (pGlBeginQueryARB) + pGlBeginQueryARB(target, id); + else if (pGlBeginOcclusionQueryNV) + pGlBeginOcclusionQueryNV(id); +} + +inline void COpenGLExtensionHandler::extGlEndQuery(GLenum target) +{ + if (pGlEndQueryARB) + pGlEndQueryARB(target); + else if (pGlEndOcclusionQueryNV) + pGlEndOcclusionQueryNV(); +} + +inline void COpenGLExtensionHandler::extGlGetQueryiv(GLenum target, GLenum pname, GLint *params) +{ + if (pGlGetQueryivARB) + pGlGetQueryivARB(target, pname, params); +} + +inline void COpenGLExtensionHandler::extGlGetQueryObjectiv(GLuint id, GLenum pname, GLint *params) +{ + if (pGlGetQueryObjectivARB) + pGlGetQueryObjectivARB(id, pname, params); + else if (pGlGetOcclusionQueryivNV) + pGlGetOcclusionQueryivNV(id, pname, params); +} + +inline void COpenGLExtensionHandler::extGlGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) +{ + if (pGlGetQueryObjectuivARB) + pGlGetQueryObjectuivARB(id, pname, params); + else if (pGlGetOcclusionQueryuivNV) + pGlGetOcclusionQueryuivNV(id, pname, params); +} + +inline void COpenGLExtensionHandler::irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) +{ + if (pGlBlendFuncSeparate) + pGlBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + else if (pGlBlendFuncSeparateEXT) + pGlBlendFuncSeparateEXT(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); +} + +inline void COpenGLExtensionHandler::irrGlBlendEquation(GLenum mode) +{ + if (pGlBlendEquation) + pGlBlendEquation(mode); + else if (pGlBlendEquationEXT) + pGlBlendEquationEXT(mode); +} + +inline void COpenGLExtensionHandler::irrGlEnableIndexed(GLenum target, GLuint index) +{ + if (FeatureAvailable[IRR_EXT_draw_buffers2] && pGlEnableIndexedEXT) + pGlEnableIndexedEXT(target, index); +} + +inline void COpenGLExtensionHandler::irrGlDisableIndexed(GLenum target, GLuint index) +{ + if (FeatureAvailable[IRR_EXT_draw_buffers2] && pGlDisableIndexedEXT) + pGlDisableIndexedEXT(target, index); +} + +inline void COpenGLExtensionHandler::irrGlColorMaskIndexed(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a) +{ + if (FeatureAvailable[IRR_EXT_draw_buffers2] && pGlColorMaskIndexedEXT) + pGlColorMaskIndexedEXT(buf, r, g, b, a); +} + +inline void COpenGLExtensionHandler::irrGlBlendFuncIndexed(GLuint buf, GLenum src, GLenum dst) +{ + if (FeatureAvailable[IRR_ARB_draw_buffers_blend] && pGlBlendFunciARB) + pGlBlendFunciARB(buf, src, dst); + else if (FeatureAvailable[IRR_AMD_draw_buffers_blend] && pGlBlendFuncIndexedAMD) + pGlBlendFuncIndexedAMD(buf, src, dst); +} + +inline void COpenGLExtensionHandler::irrGlBlendFuncSeparateIndexed(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) +{ + if (FeatureAvailable[IRR_ARB_draw_buffers_blend] && pGlBlendFuncSeparateiARB) + pGlBlendFuncSeparateiARB(buf, srcRGB, dstRGB, srcAlpha, dstAlpha); + else if (FeatureAvailable[IRR_AMD_draw_buffers_blend] && pGlBlendFuncSeparateIndexedAMD) + pGlBlendFuncSeparateIndexedAMD(buf, srcRGB, dstRGB, srcAlpha, dstAlpha); +} + +inline void COpenGLExtensionHandler::irrGlBlendEquationIndexed(GLuint buf, GLenum mode) +{ + if (FeatureAvailable[IRR_ARB_draw_buffers_blend] && pGlBlendEquationiARB) + pGlBlendEquationiARB(buf, mode); + else if (FeatureAvailable[IRR_AMD_draw_buffers_blend] && pGlBlendEquationIndexedAMD) + pGlBlendEquationIndexedAMD(buf, mode); +} + +inline void COpenGLExtensionHandler::irrGlBlendEquationSeparateIndexed(GLuint buf, GLenum modeRGB, GLenum modeAlpha) +{ + if (FeatureAvailable[IRR_ARB_draw_buffers_blend] && pGlBlendEquationSeparateiARB) + pGlBlendEquationSeparateiARB(buf, modeRGB, modeAlpha); + else if (FeatureAvailable[IRR_AMD_draw_buffers_blend] && pGlBlendEquationSeparateIndexedAMD) + pGlBlendEquationSeparateIndexedAMD(buf, modeRGB, modeAlpha); +} + +inline void COpenGLExtensionHandler::extGlTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) +{ + if (Version >= 405 || FeatureAvailable[IRR_ARB_direct_state_access]) { + if (pGlTextureSubImage2D) + pGlTextureSubImage2D(texture, level, xoffset, yoffset, width, height, format, type, pixels); + } else if (FeatureAvailable[IRR_EXT_direct_state_access]) { + if (pGlTextureSubImage2DEXT) + pGlTextureSubImage2DEXT(texture, target, level, xoffset, yoffset, width, height, format, type, pixels); + } else { + GLint bound; + switch (target) { +#ifdef GL_VERSION_3_0 + case GL_TEXTURE_1D_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); + break; +#elif GL_EXT_texture_array + case GL_TEXTURE_1D_ARRAY_EXT: + glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY_EXT, &bound); + break; +#endif + case GL_TEXTURE_2D: + glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); + break; +#ifdef GL_VERSION_3_2 + case GL_TEXTURE_2D_MULTISAMPLE: + glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE, &bound); + break; +#endif + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); + break; +#ifdef GL_VERSION_3_1 + case GL_TEXTURE_RECTANGLE: + glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); + break; +#elif defined(GL_ARB_texture_rectangle) + case GL_TEXTURE_RECTANGLE_ARB: + glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &bound); + break; +#endif + default: + return; + } + glBindTexture(target, texture); + glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + glBindTexture(target, bound); + } +} + +inline void COpenGLExtensionHandler::extGlTextureStorage2D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height) +{ + if (Version >= 405 || FeatureAvailable[IRR_ARB_direct_state_access]) { + if (pGlTextureStorage2D) + pGlTextureStorage2D(texture, levels, internalformat, width, height); + } else if (FeatureAvailable[IRR_EXT_direct_state_access]) { + if (pGlTextureStorage2DEXT) + pGlTextureStorage2DEXT(texture, target, levels, internalformat, width, height); + } + + else if (pGlTexStorage2D) { + GLint bound; + switch (target) { +#ifdef GL_VERSION_3_0 + case GL_TEXTURE_1D_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); + break; +#elif GL_EXT_texture_array + case GL_TEXTURE_1D_ARRAY_EXT: + glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY_EXT, &bound); + break; +#endif + case GL_TEXTURE_2D: + glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); + break; + case GL_TEXTURE_CUBE_MAP: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); + break; +#ifdef GL_VERSION_3_1 + case GL_TEXTURE_RECTANGLE: + glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); + break; +#elif defined(GL_ARB_texture_rectangle) + case GL_TEXTURE_RECTANGLE_ARB: + glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &bound); + break; +#endif + default: + return; + } + glBindTexture(target, texture); + pGlTexStorage2D(target, levels, internalformat, width, height); + glBindTexture(target, bound); + } +} + +inline void COpenGLExtensionHandler::extGlTextureStorage3D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) +{ + if (Version >= 405 || FeatureAvailable[IRR_ARB_direct_state_access]) { + if (pGlTextureStorage3D) + pGlTextureStorage3D(texture, levels, internalformat, width, height, depth); + } else if (FeatureAvailable[IRR_EXT_direct_state_access]) { + if (pGlTextureStorage3DEXT) + pGlTextureStorage3DEXT(texture, target, levels, internalformat, width, height, depth); + } else if (pGlTexStorage3D) { + GLint bound; + switch (target) { +#ifdef GL_VERSION_3_0 + case GL_TEXTURE_2D_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); + break; +#elif GL_EXT_texture_array + case GL_TEXTURE_2D_ARRAY_EXT: + glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY_EXT, &bound); + break; +#endif + case GL_TEXTURE_3D: + glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); + break; +#ifdef GL_VERSION_4_0 + case GL_TEXTURE_CUBE_MAP_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); + break; +#elif defined(GL_ARB_texture_cube_map_array) + case GL_TEXTURE_CUBE_MAP_ARRAY_ARB: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB, &bound); + break; +#endif + default: + return; + } + glBindTexture(target, texture); + pGlTexStorage3D(target, levels, internalformat, width, height, depth); + glBindTexture(target, bound); + } +} + +inline void COpenGLExtensionHandler::extGlGetTextureImage(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *pixels) +{ + if (Version >= 405 || FeatureAvailable[IRR_ARB_direct_state_access]) { + if (pGlGetTextureImage) + pGlGetTextureImage(texture, level, format, type, bufSize, pixels); + } else if (FeatureAvailable[IRR_EXT_direct_state_access]) { + if (pGlGetTextureImageEXT) + pGlGetTextureImageEXT(texture, target, level, format, type, pixels); + } else { + GLint bound; + switch (target) { +#ifdef GL_VERSION_3_0 + case GL_TEXTURE_2D_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); + break; +#elif GL_EXT_texture_array + case GL_TEXTURE_2D_ARRAY_EXT: + glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY_EXT, &bound); + break; +#endif + case GL_TEXTURE_3D: + glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); + break; +#ifdef GL_VERSION_4_0 + case GL_TEXTURE_CUBE_MAP_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); + break; +#elif defined(GL_ARB_texture_cube_map_array) + case GL_TEXTURE_CUBE_MAP_ARRAY_ARB: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB, &bound); + break; +#endif + default: + return; + } + glBindTexture(target, texture); + glGetTexImage(target, level, format, type, pixels); + glBindTexture(target, bound); + } +} + +inline void COpenGLExtensionHandler::extGlNamedFramebufferTexture(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level) +{ + if (!needsDSAFramebufferHack) { + if (Version >= 405 || FeatureAvailable[IRR_ARB_direct_state_access]) { + pGlNamedFramebufferTexture(framebuffer, attachment, texture, level); + return; + } else if (FeatureAvailable[IRR_EXT_direct_state_access]) { + pGlNamedFramebufferTextureEXT(framebuffer, attachment, texture, level); + return; + } + } + + GLuint bound; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, reinterpret_cast(&bound)); + + if (bound != framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + pGlFramebufferTexture(GL_FRAMEBUFFER, attachment, texture, level); + if (bound != framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER, bound); +} + +inline void COpenGLExtensionHandler::extGlTextureParameteri(GLuint texture, GLenum pname, GLint param) +{ + if (pGlTextureParameteri) + pGlTextureParameteri(texture, pname, param); +} + +inline void COpenGLExtensionHandler::extGlTextureParameterf(GLuint texture, GLenum pname, GLfloat param) +{ + if (pGlTextureParameterf) + pGlTextureParameterf(texture, pname, param); +} + +inline void COpenGLExtensionHandler::extGlTextureParameteriv(GLuint texture, GLenum pname, const GLint *params) +{ + if (pGlTextureParameteriv) + pGlTextureParameteriv(texture, pname, params); +} + +inline void COpenGLExtensionHandler::extGlTextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params) +{ + if (pGlTextureParameterfv) + pGlTextureParameterfv(texture, pname, params); +} + +inline void COpenGLExtensionHandler::extGlCreateTextures(GLenum target, GLsizei n, GLuint *textures) +{ + if (Version >= 405) { + if (pGlCreateTextures) + pGlCreateTextures(target, n, textures); + else if (textures) + memset(textures, 0, n * sizeof(GLuint)); + } else { + glGenTextures(n, textures); + } +} + +inline void COpenGLExtensionHandler::extGlCreateFramebuffers(GLsizei n, GLuint *framebuffers) +{ + if (!needsDSAFramebufferHack) { + if (Version >= 405) { + pGlCreateFramebuffers(n, framebuffers); + return; + } + } + + pGlGenFramebuffers(n, framebuffers); +} + +inline void COpenGLExtensionHandler::extGlBindTextures(GLuint first, GLsizei count, const GLuint *textures, const GLenum *targets) +{ + const GLenum supportedTargets[] = {GL_TEXTURE_1D, GL_TEXTURE_2D // GL 1.x + , + GL_TEXTURE_3D // GL 2.x +#ifdef GL_VERSION_3_1 + , + GL_TEXTURE_RECTANGLE +#elif defined(GL_ARB_texture_rectangle) + , + GL_TEXTURE_RECTANGLE_ARB +#endif + , + GL_TEXTURE_CUBE_MAP +#ifdef GL_VERSION_3_0 + , + GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY // GL 3.x +#elif GL_EXT_texture_array + , + GL_TEXTURE_1D_ARRAY_EXT, GL_TEXTURE_2D_ARRAY_EXT +#endif +#ifdef GL_VERSION_3_1 + , + GL_TEXTURE_BUFFER +#elif defined(GL_ARB_texture_buffer_object) + , + GL_TEXTURE_BUFFER_ARB +#elif defined(GL_EXT_texture_buffer_object) + , + GL_TEXTURE_BUFFER_EXT +#endif +#ifdef GL_VERSION_4_0 + , + GL_TEXTURE_CUBE_MAP_ARRAY // GL 4.x +#elif defined(GL_ARB_texture_cube_map_array) + , + GL_TEXTURE_CUBE_MAP_ARRAY_ARB +#endif +#ifdef GL_VERSION_3_2 + , + GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_2D_MULTISAMPLE_ARRAY +#endif + }; + + if (Version >= 404 || FeatureAvailable[IRR_ARB_multi_bind]) { + if (pGlBindTextures) + pGlBindTextures(first, count, textures); + } else { + GLint activeTex = 0; + glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex); + + for (GLsizei i = 0; i < count; i++) { + GLuint texture = textures ? textures[i] : 0; + + GLuint unit = first + i; + irrGlActiveTexture(GL_TEXTURE0 + unit); + + if (texture) + glBindTexture(targets[i], texture); + else { + for (size_t j = 0; j < sizeof(supportedTargets) / sizeof(GLenum); j++) + glBindTexture(supportedTargets[j], 0); + } + } + + irrGlActiveTexture(activeTex); + } +} + +inline void COpenGLExtensionHandler::extGlGenerateTextureMipmap(GLuint texture, GLenum target) +{ + if (Version >= 405 || FeatureAvailable[IRR_ARB_direct_state_access]) { + if (pGlGenerateTextureMipmap) + pGlGenerateTextureMipmap(texture); + } else if (FeatureAvailable[IRR_EXT_direct_state_access]) { + if (pGlGenerateTextureMipmapEXT) + pGlGenerateTextureMipmapEXT(texture, target); + } else if (pGlGenerateMipmap) { + GLint bound; + switch (target) { + case GL_TEXTURE_1D: + glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); + break; +#ifdef GL_VERSION_3_0 + case GL_TEXTURE_1D_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); + break; +#elif GL_EXT_texture_array + case GL_TEXTURE_1D_ARRAY_EXT: + glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY_EXT, &bound); + break; +#endif + case GL_TEXTURE_2D: + glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); + break; +#ifdef GL_VERSION_3_0 + case GL_TEXTURE_2D_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); + break; +#elif GL_EXT_texture_array + case GL_TEXTURE_2D_ARRAY_EXT: + glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY_EXT, &bound); + break; +#endif +#ifdef GL_VERSION_3_2 + case GL_TEXTURE_2D_MULTISAMPLE: + glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE, &bound); + break; + case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY, &bound); + break; +#endif + case GL_TEXTURE_3D: + glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); + break; +#ifdef GL_VERSION_3_1 + case GL_TEXTURE_BUFFER: + glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &bound); + break; +#elif defined(GL_ARB_texture_buffer_object) + case GL_TEXTURE_BUFFER_ARB: + glGetIntegerv(GL_TEXTURE_BINDING_BUFFER_ARB, &bound); + break; +#elif defined(GL_EXT_texture_buffer_object) + case GL_TEXTURE_BUFFER_EXT: + glGetIntegerv(GL_TEXTURE_BINDING_BUFFER_EXT, &bound); + break; +#endif + case GL_TEXTURE_CUBE_MAP: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); + break; +#ifdef GL_VERSION_4_0 + case GL_TEXTURE_CUBE_MAP_ARRAY: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); + break; +#elif defined(GL_ARB_texture_cube_map_array) + case GL_TEXTURE_CUBE_MAP_ARRAY_ARB: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB, &bound); + break; +#endif +#ifdef GL_VERSION_3_1 + case GL_TEXTURE_RECTANGLE: + glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); + break; +#elif defined(GL_ARB_texture_rectangle) + case GL_TEXTURE_RECTANGLE_ARB: + glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &bound); + break; +#endif + default: + os::Printer::log("DevSH would like to ask you what are you doing!!??\n", ELL_ERROR); + return; + } + glBindTexture(target, texture); + pGlGenerateMipmap(target); + glBindTexture(target, bound); + } +} + +inline void COpenGLExtensionHandler::extGlSwapInterval(int interval) +{ + // we have wglext, so try to use that +#if defined(_IRR_WINDOWS_API_) && defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) +#ifdef WGL_EXT_swap_control + if (pWglSwapIntervalEXT) + pWglSwapIntervalEXT(interval); +#endif +#endif +#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ +#if defined(GLX_MESA_swap_control) + if (pGlxSwapIntervalMESA) + pGlxSwapIntervalMESA(interval); +#elif defined(GLX_EXT_swap_control) + Display *dpy = glXGetCurrentDisplay(); + GLXDrawable drawable = glXGetCurrentDrawable(); + if (pGlxSwapIntervalEXT) + pGlxSwapIntervalEXT(dpy, drawable, interval); +#elif defined(GLX_SGI_swap_control) + // does not work with interval==0 + if (interval && pGlxSwapIntervalSGI) + pGlxSwapIntervalSGI(interval); +} +#endif +#endif +} + +} +} + +#endif diff --git a/irr/src/COpenGLMaterialRenderer.h b/irr/src/COpenGLMaterialRenderer.h new file mode 100644 index 000000000..b4706f537 --- /dev/null +++ b/irr/src/COpenGLMaterialRenderer.h @@ -0,0 +1,335 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "IMaterialRenderer.h" + +#include "COpenGLDriver.h" +#include "COpenGLCacheHandler.h" + +namespace irr +{ +namespace video +{ + +//! Solid material renderer +class COpenGLMaterialRenderer_SOLID : public IMaterialRenderer +{ +public: + COpenGLMaterialRenderer_SOLID(video::COpenGLDriver *d) : + Driver(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) override + { + if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE) + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE); + else + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE); + + Driver->disableTextures(1); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + } + +protected: + video::COpenGLDriver *Driver; +}; + +//! Generic Texture Blend +class COpenGLMaterialRenderer_ONETEXTURE_BLEND : public IMaterialRenderer +{ +public: + COpenGLMaterialRenderer_ONETEXTURE_BLEND(video::COpenGLDriver *d) : + Driver(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) override + { + if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE) + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE); + else + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE); + + Driver->disableTextures(1); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + // if (material.MaterialType != lastMaterial.MaterialType || + // material.MaterialTypeParam != lastMaterial.MaterialTypeParam || + // resetAllRenderstates) + { + E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + Driver->getCacheHandler()->setBlend(true); + + if (Driver->queryFeature(EVDF_BLEND_SEPARATE)) { + Driver->getCacheHandler()->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), + Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); + } else { + Driver->getCacheHandler()->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact)); + } + + Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB); + +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (f32)modulate); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT); + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, (f32)modulate); +#endif + + if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || + textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) { + if (alphaSource == EAS_VERTEX_COLOR) { +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT); +#endif + } else if (alphaSource == EAS_TEXTURE) { +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE); +#endif + } else { +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_TEXTURE); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_TEXTURE); +#endif + } + } + } + } + + void OnUnsetMaterial() override + { + Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.f); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.f); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT); +#endif + + Driver->getCacheHandler()->setBlend(false); + } + + //! Returns if the material is transparent. + /** Is not always transparent, but mostly. */ + bool isTransparent() const override + { + return true; + } + +protected: + video::COpenGLDriver *Driver; +}; + +//! Transparent vertex alpha material renderer +class COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA : public IMaterialRenderer +{ +public: + COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA(video::COpenGLDriver *d) : + Driver(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) override + { + if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE) + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE); + else + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE); + + Driver->disableTextures(1); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + Driver->getCacheHandler()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + Driver->getCacheHandler()->setBlend(true); + + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { + Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB); + +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT); +#endif + } + } + + void OnUnsetMaterial() override + { + Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE); +#endif + + Driver->getCacheHandler()->setBlend(false); + } + + //! Returns if the material is transparent. + bool isTransparent() const override + { + return true; + } + +protected: + video::COpenGLDriver *Driver; +}; + +//! Transparent alpha channel material renderer +class COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public IMaterialRenderer +{ +public: + COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(video::COpenGLDriver *d) : + Driver(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) override + { + if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE) + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE); + else + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE); + + Driver->disableTextures(1); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + Driver->getCacheHandler()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + Driver->getCacheHandler()->setBlend(true); + Driver->getCacheHandler()->setAlphaTest(true); + Driver->getCacheHandler()->setAlphaFunc(GL_GREATER, material.MaterialTypeParam); + + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates || material.MaterialTypeParam != lastMaterial.MaterialTypeParam) { + Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB); + +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE); +#endif + } + } + + void OnUnsetMaterial() override + { + Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#ifdef GL_ARB_texture_env_combine + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE); +#else + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); +#endif + Driver->getCacheHandler()->setAlphaTest(false); + Driver->getCacheHandler()->setBlend(false); + } + + //! Returns if the material is transparent. + bool isTransparent() const override + { + return true; + } + +protected: + video::COpenGLDriver *Driver; +}; + +//! Transparent alpha channel material renderer +class COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF : public IMaterialRenderer +{ +public: + COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(video::COpenGLDriver *d) : + Driver(d) {} + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) override + { + if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_DISABLE) + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE_TO_ENABLE); + else + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE); + + Driver->disableTextures(1); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { + Driver->getCacheHandler()->setAlphaTest(true); + Driver->getCacheHandler()->setAlphaFunc(GL_GREATER, 0.5f); + } + } + + void OnUnsetMaterial() override + { + Driver->getCacheHandler()->setAlphaTest(false); + } + + //! Returns if the material is transparent. + bool isTransparent() const override + { + return false; // this material is not really transparent because it does no blending. + } + +protected: + video::COpenGLDriver *Driver; +}; + +} // end namespace video +} // end namespace irr + +#endif diff --git a/irr/src/COpenGLSLMaterialRenderer.cpp b/irr/src/COpenGLSLMaterialRenderer.cpp new file mode 100644 index 000000000..556405d7b --- /dev/null +++ b/irr/src/COpenGLSLMaterialRenderer.cpp @@ -0,0 +1,683 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// This file was originally written by William Finlayson. I (Nikolaus +// Gebhardt) did some minor modifications and changes to it and integrated it +// into Irrlicht. Thanks a lot to William for his work on this and that he gave +// me his permission to add it into Irrlicht using the zlib license. + +// After Irrlicht 0.12, Michael Zoech did some improvements to this renderer, I +// merged this into Irrlicht 0.14, thanks to him for his work. + +#include "COpenGLSLMaterialRenderer.h" + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "IGPUProgrammingServices.h" +#include "IShaderConstantSetCallBack.h" +#include "IMaterialRendererServices.h" +#include "IVideoDriver.h" +#include "os.h" + +#include "COpenGLDriver.h" +#include "COpenGLCacheHandler.h" +#include "COpenGLMaterialRenderer.h" + +#include "COpenGLCoreFeature.h" + +namespace irr +{ +namespace video +{ + +//! Constructor +COpenGLSLMaterialRenderer::COpenGLSLMaterialRenderer(video::COpenGLDriver *driver, + s32 &outMaterialTypeNr, const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + const c8 *pixelShaderProgram, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + const c8 *geometryShaderProgram, + const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, + scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) : + Driver(driver), + CallBack(callback), Alpha(false), Blending(false), AlphaTest(false), Program(0), Program2(0), UserData(userData) +{ +#ifdef _DEBUG + setDebugName("COpenGLSLMaterialRenderer"); +#endif + + switch (baseMaterial) { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + case EMT_TRANSPARENT_ALPHA_CHANNEL_REF: + AlphaTest = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); + + if (!Driver->queryFeature(EVDF_ARB_GLSL)) + return; + + init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram, geometryShaderProgram); +} + +//! constructor only for use by derived classes who want to +//! create a fall back material for example. +COpenGLSLMaterialRenderer::COpenGLSLMaterialRenderer(COpenGLDriver *driver, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, s32 userData) : + Driver(driver), + CallBack(callback), Alpha(false), Blending(false), AlphaTest(false), Program(0), Program2(0), UserData(userData) +{ + switch (baseMaterial) { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + case EMT_TRANSPARENT_ALPHA_CHANNEL_REF: + AlphaTest = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); +} + +//! Destructor +COpenGLSLMaterialRenderer::~COpenGLSLMaterialRenderer() +{ + if (CallBack) + CallBack->drop(); + + if (Program) { + GLhandleARB shaders[8]; + GLint count; + Driver->extGlGetAttachedObjects(Program, 8, &count, shaders); + // avoid bugs in some drivers, which return larger numbers + // use int variable to avoid compiler problems with template + int mincount = core::min_((int)count, 8); + for (int i = 0; i < mincount; ++i) + Driver->extGlDeleteObject(shaders[i]); + Driver->extGlDeleteObject(Program); + Program = 0; + } + + if (Program2) { + GLuint shaders[8]; + GLint count; + Driver->extGlGetAttachedShaders(Program2, 8, &count, shaders); + // avoid bugs in some drivers, which return larger numbers + // use int variable to avoid compiler problems with template + int mincount = core::min_((int)count, 8); + for (int i = 0; i < mincount; ++i) + Driver->extGlDeleteShader(shaders[i]); + Driver->extGlDeleteProgram(Program2); + Program2 = 0; + } + + UniformInfo.clear(); +} + +void COpenGLSLMaterialRenderer::init(s32 &outMaterialTypeNr, + const c8 *vertexShaderProgram, + const c8 *pixelShaderProgram, + const c8 *geometryShaderProgram, + scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut) +{ + outMaterialTypeNr = -1; + + if (!createProgram()) + return; + +#if defined(GL_ARB_vertex_shader) && defined(GL_ARB_fragment_shader) + if (vertexShaderProgram) + if (!createShader(GL_VERTEX_SHADER_ARB, vertexShaderProgram)) + return; + + if (pixelShaderProgram) + if (!createShader(GL_FRAGMENT_SHADER_ARB, pixelShaderProgram)) + return; +#endif + +#if defined(GL_ARB_geometry_shader4) || defined(GL_EXT_geometry_shader4) || defined(GL_NV_geometry_program4) || defined(GL_NV_geometry_shader4) + if (geometryShaderProgram && Driver->queryFeature(EVDF_GEOMETRY_SHADER)) { + if (!createShader(GL_GEOMETRY_SHADER_EXT, geometryShaderProgram)) + return; +#if defined(GL_ARB_geometry_shader4) || defined(GL_EXT_geometry_shader4) || defined(GL_NV_geometry_shader4) + if (Program2) { // Geometry shaders are supported only in OGL2.x+ drivers. + Driver->extGlProgramParameteri(Program2, GL_GEOMETRY_INPUT_TYPE_EXT, Driver->primitiveTypeToGL(inType)); + Driver->extGlProgramParameteri(Program2, GL_GEOMETRY_OUTPUT_TYPE_EXT, Driver->primitiveTypeToGL(outType)); + if (verticesOut == 0) + Driver->extGlProgramParameteri(Program2, GL_GEOMETRY_VERTICES_OUT_EXT, Driver->MaxGeometryVerticesOut); + else + Driver->extGlProgramParameteri(Program2, GL_GEOMETRY_VERTICES_OUT_EXT, core::min_(verticesOut, Driver->MaxGeometryVerticesOut)); + } +#elif defined(GL_NV_geometry_program4) + if (verticesOut == 0) + Driver->extGlProgramVertexLimit(GL_GEOMETRY_PROGRAM_NV, Driver->MaxGeometryVerticesOut); + else + Driver->extGlProgramVertexLimit(GL_GEOMETRY_PROGRAM_NV, core::min_(verticesOut, Driver->MaxGeometryVerticesOut)); +#endif + } +#endif + + if (!linkProgram()) + return; + + // register myself as new material + outMaterialTypeNr = Driver->addMaterialRenderer(this); +} + +bool COpenGLSLMaterialRenderer::OnRender(IMaterialRendererServices *service, + E_VERTEX_TYPE vtxtype) +{ + // call callback to set shader constants + if (CallBack && (Program || Program2)) + CallBack->OnSetConstants(this, UserData); + + return true; +} + +void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial &material, + const video::SMaterial &lastMaterial, + bool resetAllRenderstates, + video::IMaterialRendererServices *services) +{ + if (Driver->getFixedPipelineState() == COpenGLDriver::EOFPS_ENABLE) + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_ENABLE_TO_DISABLE); + else + Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); + + COpenGLCacheHandler *cacheHandler = Driver->getCacheHandler(); + + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { + if (Program2) + Driver->irrGlUseProgram(Program2); + else if (Program) + Driver->extGlUseProgramObject(Program); + } + + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + if (Alpha) { + cacheHandler->setBlend(true); + cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + cacheHandler->setAlphaTest(true); + cacheHandler->setAlphaFunc(GL_GREATER, 0.f); + } else if (Blending) { + E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + if (Driver->queryFeature(EVDF_BLEND_SEPARATE)) { + cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), + Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); + } else { + cacheHandler->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact)); + } + + cacheHandler->setBlend(true); + } else if (AlphaTest) { + cacheHandler->setAlphaTest(true); + cacheHandler->setAlphaFunc(GL_GREATER, 0.5f); + } + + if (CallBack) + CallBack->OnSetMaterial(material); +} + +void COpenGLSLMaterialRenderer::OnUnsetMaterial() +{ + if (Program) + Driver->extGlUseProgramObject(0); + if (Program2) + Driver->irrGlUseProgram(0); + + COpenGLCacheHandler *cacheHandler = Driver->getCacheHandler(); + if (Alpha || Blending) { + cacheHandler->setBlend(false); + } + if (Alpha || AlphaTest) { + cacheHandler->setAlphaTest(false); + } +} + +//! Returns if the material is transparent. +bool COpenGLSLMaterialRenderer::isTransparent() const +{ + return (Alpha || Blending); +} + +bool COpenGLSLMaterialRenderer::createProgram() +{ + if (Driver->Version >= 200) + Program2 = Driver->extGlCreateProgram(); + else + Program = Driver->extGlCreateProgramObject(); + return true; +} + +bool COpenGLSLMaterialRenderer::createShader(GLenum shaderType, const char *shader) +{ + if (Program2) { + GLuint shaderHandle = Driver->extGlCreateShader(shaderType); + Driver->extGlShaderSource(shaderHandle, 1, &shader, NULL); + Driver->extGlCompileShader(shaderHandle); + + GLint status = 0; + +#ifdef GL_VERSION_2_0 + Driver->extGlGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status); +#endif + + if (status != GL_TRUE) { + core::stringc typeInfo("shaderType: "); + typeInfo += core::stringc((unsigned long)shaderType); + os::Printer::log("GLSL (> 2.x) shader failed to compile", typeInfo.c_str(), ELL_ERROR); + // check error message and log it + GLint maxLength = 0; + GLint length; +#ifdef GL_VERSION_2_0 + Driver->extGlGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, + &maxLength); +#endif + if (maxLength) { + GLchar *infoLog = new GLchar[maxLength]; + Driver->extGlGetShaderInfoLog(shaderHandle, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete[] infoLog; + } + + return false; + } + + Driver->extGlAttachShader(Program2, shaderHandle); + } else { + GLhandleARB shaderHandle = Driver->extGlCreateShaderObject(shaderType); + + Driver->extGlShaderSourceARB(shaderHandle, 1, &shader, NULL); + Driver->extGlCompileShaderARB(shaderHandle); + + GLint status = 0; + +#ifdef GL_ARB_shader_objects + Driver->extGlGetObjectParameteriv(shaderHandle, GL_OBJECT_COMPILE_STATUS_ARB, &status); +#endif + + if (!status) { + core::stringc typeInfo("shaderType: "); + typeInfo += core::stringc((unsigned long)shaderType); + os::Printer::log("GLSL shader failed to compile", typeInfo.c_str(), ELL_ERROR); + // check error message and log it + GLint maxLength = 0; + GLsizei length; +#ifdef GL_ARB_shader_objects + Driver->extGlGetObjectParameteriv(shaderHandle, + GL_OBJECT_INFO_LOG_LENGTH_ARB, &maxLength); +#endif + if (maxLength) { + GLcharARB *infoLog = new GLcharARB[maxLength]; + Driver->extGlGetInfoLog(shaderHandle, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete[] infoLog; + } + + return false; + } + + Driver->extGlAttachObject(Program, shaderHandle); + } + return true; +} + +bool COpenGLSLMaterialRenderer::linkProgram() +{ + if (Program2) { + Driver->extGlLinkProgram(Program2); + + GLint status = 0; + +#ifdef GL_VERSION_2_0 + Driver->extGlGetProgramiv(Program2, GL_LINK_STATUS, &status); +#endif + + if (!status) { + os::Printer::log("GLSL (> 2.x) shader program failed to link", ELL_ERROR); + // check error message and log it + GLint maxLength = 0; + GLsizei length; +#ifdef GL_VERSION_2_0 + Driver->extGlGetProgramiv(Program2, GL_INFO_LOG_LENGTH, &maxLength); +#endif + if (maxLength) { + GLchar *infoLog = new GLchar[maxLength]; + Driver->extGlGetProgramInfoLog(Program2, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete[] infoLog; + } + + return false; + } + + // get uniforms information + + GLint num = 0; +#ifdef GL_VERSION_2_0 + Driver->extGlGetProgramiv(Program2, GL_ACTIVE_UNIFORMS, &num); +#endif + + if (num == 0) { + // no uniforms + return true; + } + + GLint maxlen = 0; +#ifdef GL_VERSION_2_0 + Driver->extGlGetProgramiv(Program2, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen); +#endif + + if (maxlen == 0) { + os::Printer::log("GLSL (> 2.x): failed to retrieve uniform information", ELL_ERROR); + return false; + } + + // seems that some implementations use an extra null terminator + ++maxlen; + c8 *buf = new c8[maxlen]; + + UniformInfo.clear(); + UniformInfo.reallocate(num); + + for (GLint i = 0; i < num; ++i) { + SUniformInfo ui; + memset(buf, 0, maxlen); + + GLint size; + Driver->extGlGetActiveUniform(Program2, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); + ui.name = buf; + ui.location = Driver->extGlGetUniformLocation(Program2, buf); + + UniformInfo.push_back(ui); + } + + delete[] buf; + } else { + Driver->extGlLinkProgramARB(Program); + + GLint status = 0; + +#ifdef GL_ARB_shader_objects + Driver->extGlGetObjectParameteriv(Program, GL_OBJECT_LINK_STATUS_ARB, &status); +#endif + + if (!status) { + os::Printer::log("GLSL shader program failed to link", ELL_ERROR); + // check error message and log it + GLint maxLength = 0; + GLsizei length; +#ifdef GL_ARB_shader_objects + Driver->extGlGetObjectParameteriv(Program, + GL_OBJECT_INFO_LOG_LENGTH_ARB, &maxLength); +#endif + if (maxLength) { + GLcharARB *infoLog = new GLcharARB[maxLength]; + Driver->extGlGetInfoLog(Program, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete[] infoLog; + } + + return false; + } + + // get uniforms information + + GLint num = 0; +#ifdef GL_ARB_shader_objects + Driver->extGlGetObjectParameteriv(Program, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &num); +#endif + + if (num == 0) { + // no uniforms + return true; + } + + GLint maxlen = 0; +#ifdef GL_ARB_shader_objects + Driver->extGlGetObjectParameteriv(Program, GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB, &maxlen); +#endif + + if (maxlen == 0) { + os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR); + return false; + } + + // seems that some implementations use an extra null terminator + ++maxlen; + c8 *buf = new c8[maxlen]; + + UniformInfo.clear(); + UniformInfo.reallocate(num); + + for (int i = 0; i < num; ++i) { + SUniformInfo ui; + memset(buf, 0, maxlen); + + GLint size; + Driver->extGlGetActiveUniformARB(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); + ui.name = buf; + ui.location = Driver->extGlGetUniformLocationARB(Program, buf); + + UniformInfo.push_back(ui); + } + + delete[] buf; + } + + return true; +} + +void COpenGLSLMaterialRenderer::setBasicRenderStates(const SMaterial &material, + const SMaterial &lastMaterial, + bool resetAllRenderstates) +{ + // forward + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); +} + +s32 COpenGLSLMaterialRenderer::getVertexShaderConstantID(const c8 *name) +{ + return getPixelShaderConstantID(name); +} + +s32 COpenGLSLMaterialRenderer::getPixelShaderConstantID(const c8 *name) +{ + for (u32 i = 0; i < UniformInfo.size(); ++i) { + if (UniformInfo[i].name == name) + return i; + } + + return -1; +} + +bool COpenGLSLMaterialRenderer::setVertexShaderConstant(s32 index, const f32 *floats, int count) +{ + return setPixelShaderConstant(index, floats, count); +} + +bool COpenGLSLMaterialRenderer::setVertexShaderConstant(s32 index, const s32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGLSLMaterialRenderer::setVertexShaderConstant(s32 index, const u32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const f32 *floats, int count) +{ + if (index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) { + case GL_FLOAT: + Driver->extGlUniform1fv(UniformInfo[index].location, count, floats); + break; + case GL_FLOAT_VEC2: + Driver->extGlUniform2fv(UniformInfo[index].location, count / 2, floats); + break; + case GL_FLOAT_VEC3: + Driver->extGlUniform3fv(UniformInfo[index].location, count / 3, floats); + break; + case GL_FLOAT_VEC4: + Driver->extGlUniform4fv(UniformInfo[index].location, count / 4, floats); + break; + case GL_FLOAT_MAT2: + Driver->extGlUniformMatrix2fv(UniformInfo[index].location, count / 4, false, floats); + break; + case GL_FLOAT_MAT2x3: + Driver->extGlUniformMatrix2x3fv(UniformInfo[index].location, count / 6, false, floats); + break; + case GL_FLOAT_MAT2x4: + Driver->extGlUniformMatrix2x4fv(UniformInfo[index].location, count / 8, false, floats); + break; + case GL_FLOAT_MAT3x2: + Driver->extGlUniformMatrix3x2fv(UniformInfo[index].location, count / 6, false, floats); + break; + case GL_FLOAT_MAT3: + Driver->extGlUniformMatrix3fv(UniformInfo[index].location, count / 9, false, floats); + break; + case GL_FLOAT_MAT3x4: + Driver->extGlUniformMatrix3x4fv(UniformInfo[index].location, count / 12, false, floats); + break; + case GL_FLOAT_MAT4x2: + Driver->extGlUniformMatrix4x2fv(UniformInfo[index].location, count / 8, false, floats); + break; + case GL_FLOAT_MAT4x3: + Driver->extGlUniformMatrix4x3fv(UniformInfo[index].location, count / 12, false, floats); + break; + case GL_FLOAT_MAT4: + Driver->extGlUniformMatrix4fv(UniformInfo[index].location, count / 16, false, floats); + break; + case GL_SAMPLER_1D: + case GL_SAMPLER_2D: + case GL_SAMPLER_3D: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_1D_SHADOW: + case GL_SAMPLER_2D_SHADOW: { + if (floats) { + const GLint id = static_cast(*floats); + Driver->extGlUniform1iv(UniformInfo[index].location, 1, &id); + } else + status = false; + } break; + default: + status = false; + break; + } + return status; +} + +bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const s32 *ints, int count) +{ + if (index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) { + case GL_INT: + case GL_BOOL: + Driver->extGlUniform1iv(UniformInfo[index].location, count, reinterpret_cast(ints)); + break; + case GL_INT_VEC2: + case GL_BOOL_VEC2: + Driver->extGlUniform2iv(UniformInfo[index].location, count / 2, reinterpret_cast(ints)); + break; + case GL_INT_VEC3: + case GL_BOOL_VEC3: + Driver->extGlUniform3iv(UniformInfo[index].location, count / 3, reinterpret_cast(ints)); + break; + case GL_INT_VEC4: + case GL_BOOL_VEC4: + Driver->extGlUniform4iv(UniformInfo[index].location, count / 4, reinterpret_cast(ints)); + break; + case GL_SAMPLER_1D: + case GL_SAMPLER_2D: + case GL_SAMPLER_3D: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_1D_SHADOW: + case GL_SAMPLER_2D_SHADOW: + Driver->extGlUniform1iv(UniformInfo[index].location, 1, reinterpret_cast(ints)); + break; + default: + status = false; + break; + } + return status; +} + +bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const u32 *ints, int count) +{ + if (index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) { + case GL_UNSIGNED_INT: + Driver->extGlUniform1uiv(UniformInfo[index].location, count, reinterpret_cast(ints)); + break; +#if defined(GL_VERSION_3_0) + case GL_UNSIGNED_INT_VEC2: + Driver->extGlUniform2uiv(UniformInfo[index].location, count / 2, reinterpret_cast(ints)); + break; + case GL_UNSIGNED_INT_VEC3: + Driver->extGlUniform3uiv(UniformInfo[index].location, count / 3, reinterpret_cast(ints)); + break; + case GL_UNSIGNED_INT_VEC4: + Driver->extGlUniform4uiv(UniformInfo[index].location, count / 4, reinterpret_cast(ints)); + break; +#endif + default: + status = false; + break; + } + return status; +} + +IVideoDriver *COpenGLSLMaterialRenderer::getVideoDriver() +{ + return Driver; +} + +} // end namespace video +} // end namespace irr + +#endif diff --git a/irr/src/COpenGLSLMaterialRenderer.h b/irr/src/COpenGLSLMaterialRenderer.h new file mode 100644 index 000000000..2f4a485d2 --- /dev/null +++ b/irr/src/COpenGLSLMaterialRenderer.h @@ -0,0 +1,125 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "EMaterialTypes.h" +#include "IMaterialRenderer.h" +#include "IMaterialRendererServices.h" +#include "IGPUProgrammingServices.h" +#include "irrArray.h" +#include "irrString.h" + +#include "COpenGLCommon.h" + +namespace irr +{ +namespace video +{ + +class COpenGLDriver; +class IShaderConstantSetCallBack; + +//! Class for using GLSL shaders with OpenGL +//! Please note: This renderer implements its own IMaterialRendererServices +class COpenGLSLMaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices +{ +public: + //! Constructor + COpenGLSLMaterialRenderer( + COpenGLDriver *driver, + s32 &outMaterialTypeNr, + const c8 *vertexShaderProgram = 0, + const c8 *vertexShaderEntryPointName = 0, + E_VERTEX_SHADER_TYPE vsCompileTarget = video::EVST_VS_1_1, + const c8 *pixelShaderProgram = 0, + const c8 *pixelShaderEntryPointName = 0, + E_PIXEL_SHADER_TYPE psCompileTarget = video::EPST_PS_1_1, + const c8 *geometryShaderProgram = 0, + const c8 *geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = EMT_SOLID, + s32 userData = 0); + + //! Destructor + virtual ~COpenGLSLMaterialRenderer(); + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services) override; + + bool OnRender(IMaterialRendererServices *service, E_VERTEX_TYPE vtxtype) override; + + void OnUnsetMaterial() override; + + //! Returns if the material is transparent. + bool isTransparent() const override; + + //! Access the callback provided by the users when creating shader materials + IShaderConstantSetCallBack *getShaderConstantSetCallBack() const override + { + return CallBack; + } + + // implementations for the render services + void setBasicRenderStates(const SMaterial &material, const SMaterial &lastMaterial, bool resetAllRenderstates) override; + s32 getVertexShaderConstantID(const c8 *name) override; + s32 getPixelShaderConstantID(const c8 *name) override; + bool setVertexShaderConstant(s32 index, const f32 *floats, int count) override; + bool setVertexShaderConstant(s32 index, const s32 *ints, int count) override; + bool setVertexShaderConstant(s32 index, const u32 *ints, int count) override; + bool setPixelShaderConstant(s32 index, const f32 *floats, int count) override; + bool setPixelShaderConstant(s32 index, const s32 *ints, int count) override; + bool setPixelShaderConstant(s32 index, const u32 *ints, int count) override; + IVideoDriver *getVideoDriver() override; + +protected: + //! constructor only for use by derived classes who want to + //! create a fall back material for example. + COpenGLSLMaterialRenderer(COpenGLDriver *driver, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData = 0); + + void init(s32 &outMaterialTypeNr, + const c8 *vertexShaderProgram, + const c8 *pixelShaderProgram, + const c8 *geometryShaderProgram, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0); + + bool createProgram(); + bool createShader(GLenum shaderType, const char *shader); + bool linkProgram(); + + COpenGLDriver *Driver; + IShaderConstantSetCallBack *CallBack; + + bool Alpha; + bool Blending; + bool AlphaTest; + + struct SUniformInfo + { + core::stringc name; + GLenum type; + GLint location; + }; + + GLhandleARB Program; + GLuint Program2; + core::array UniformInfo; + s32 UserData; +}; + +} // end namespace video +} // end namespace irr + +#endif // compile with OpenGL diff --git a/irr/src/CReadFile.cpp b/irr/src/CReadFile.cpp new file mode 100644 index 000000000..6c6e49d55 --- /dev/null +++ b/irr/src/CReadFile.cpp @@ -0,0 +1,96 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CReadFile.h" + +namespace irr +{ +namespace io +{ + +CReadFile::CReadFile(const io::path &fileName) : + File(0), FileSize(0), Filename(fileName) +{ +#ifdef _DEBUG + setDebugName("CReadFile"); +#endif + + openFile(); +} + +CReadFile::~CReadFile() +{ + if (File) + fclose(File); +} + +//! returns how much was read +size_t CReadFile::read(void *buffer, size_t sizeToRead) +{ + if (!isOpen()) + return 0; + + return fread(buffer, 1, sizeToRead, File); +} + +//! changes position in file, returns true if successful +//! if relativeMovement==true, the pos is changed relative to current pos, +//! otherwise from begin of file +bool CReadFile::seek(long finalPos, bool relativeMovement) +{ + if (!isOpen()) + return false; + + return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0; +} + +//! returns size of file +long CReadFile::getSize() const +{ + return FileSize; +} + +//! returns where in the file we are. +long CReadFile::getPos() const +{ + return ftell(File); +} + +//! opens the file +void CReadFile::openFile() +{ + if (Filename.size() == 0) { // bugfix posted by rt + File = 0; + return; + } + + File = fopen(Filename.c_str(), "rb"); + + if (File) { + // get FileSize + + fseek(File, 0, SEEK_END); + FileSize = getPos(); + fseek(File, 0, SEEK_SET); + } +} + +//! returns name of file +const io::path &CReadFile::getFileName() const +{ + return Filename; +} + +IReadFile *CReadFile::createReadFile(const io::path &fileName) +{ + CReadFile *file = new CReadFile(fileName); + if (file->isOpen()) + return file; + + file->drop(); + return 0; +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CReadFile.h b/irr/src/CReadFile.h new file mode 100644 index 000000000..14f674772 --- /dev/null +++ b/irr/src/CReadFile.h @@ -0,0 +1,67 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include +#include "IReadFile.h" +#include "irrString.h" + +namespace irr +{ + +namespace io +{ + +/*! + Class for reading a real file from disk. +*/ +class CReadFile : public IReadFile +{ +public: + CReadFile(const io::path &fileName); + + virtual ~CReadFile(); + + //! returns how much was read + size_t read(void *buffer, size_t sizeToRead) override; + + //! changes position in file, returns true if successful + bool seek(long finalPos, bool relativeMovement = false) override; + + //! returns size of file + long getSize() const override; + + //! returns if file is open + bool isOpen() const + { + return File != 0; + } + + //! returns where in the file we are. + long getPos() const override; + + //! returns name of file + const io::path &getFileName() const override; + + //! Get the type of the class implementing this interface + EREAD_FILE_TYPE getType() const override + { + return ERFT_READ_FILE; + } + + //! create read file on disk. + static IReadFile *createReadFile(const io::path &fileName); + +private: + //! opens the file + void openFile(); + + FILE *File; + long FileSize; + io::path Filename; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CSDLManager.cpp b/irr/src/CSDLManager.cpp new file mode 100644 index 000000000..c2b38e478 --- /dev/null +++ b/irr/src/CSDLManager.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2022 sfan5 +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "CSDLManager.h" + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + +#include "CIrrDeviceSDL.h" +#include "COpenGLCommon.h" + +namespace irr +{ +namespace video +{ + +CSDLManager::CSDLManager(CIrrDeviceSDL *device) : + IContextManager(), SDLDevice(device) +{ +#ifdef _DEBUG + setDebugName("CSDLManager"); +#endif +} + +bool CSDLManager::initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &data) +{ + Data = data; + return true; +} + +const SExposedVideoData &CSDLManager::getContext() const +{ + return Data; +} + +bool CSDLManager::activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) +{ + return true; +} + +void *CSDLManager::getProcAddress(const std::string &procName) +{ + return SDL_GL_GetProcAddress(procName.c_str()); +} + +bool CSDLManager::swapBuffers() +{ + SDLDevice->SwapWindow(); + return true; +} + +} +} + +#endif diff --git a/irr/src/CSDLManager.h b/irr/src/CSDLManager.h new file mode 100644 index 000000000..22efeb1ee --- /dev/null +++ b/irr/src/CSDLManager.h @@ -0,0 +1,49 @@ +// Copyright (C) 2022 sfan5 +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + +#include "IContextManager.h" + +namespace irr +{ +class CIrrDeviceSDL; + +namespace video +{ + +// Manager for SDL with OpenGL +class CSDLManager : public IContextManager +{ +public: + CSDLManager(CIrrDeviceSDL *device); + + virtual ~CSDLManager() {} + + bool initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &data) override; + + void terminate() override{}; + bool generateSurface() override { return true; }; + void destroySurface() override{}; + bool generateContext() override { return true; }; + void destroyContext() override{}; + + const SExposedVideoData &getContext() const override; + + bool activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero = false) override; + + void *getProcAddress(const std::string &procName) override; + + bool swapBuffers() override; + +private: + SExposedVideoData Data; + CIrrDeviceSDL *SDLDevice; +}; +} +} + +#endif diff --git a/irr/src/CSceneCollisionManager.cpp b/irr/src/CSceneCollisionManager.cpp new file mode 100644 index 000000000..692f3c44f --- /dev/null +++ b/irr/src/CSceneCollisionManager.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CSceneCollisionManager.h" +#include "ICameraSceneNode.h" +#include "SViewFrustum.h" + +#include "os.h" +#include "irrMath.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CSceneCollisionManager::CSceneCollisionManager(ISceneManager *smanager, video::IVideoDriver *driver) : + SceneManager(smanager), Driver(driver) +{ +#ifdef _DEBUG + setDebugName("CSceneCollisionManager"); +#endif + + if (Driver) + Driver->grab(); +} + +//! destructor +CSceneCollisionManager::~CSceneCollisionManager() +{ + if (Driver) + Driver->drop(); +} + +//! Returns a 3d ray which would go through the 2d screen coordinates. +core::line3d CSceneCollisionManager::getRayFromScreenCoordinates( + const core::position2d &pos, const ICameraSceneNode *camera) +{ + core::line3d ln(0, 0, 0, 0, 0, 0); + + if (!SceneManager) + return ln; + + if (!camera) + camera = SceneManager->getActiveCamera(); + + if (!camera) + return ln; + + const scene::SViewFrustum *f = camera->getViewFrustum(); + + core::vector3df farLeftUp = f->getFarLeftUp(); + core::vector3df lefttoright = f->getFarRightUp() - farLeftUp; + core::vector3df uptodown = f->getFarLeftDown() - farLeftUp; + + const core::rect &viewPort = Driver->getViewPort(); + core::dimension2d screenSize(viewPort.getWidth(), viewPort.getHeight()); + + f32 dx = pos.X / (f32)screenSize.Width; + f32 dy = pos.Y / (f32)screenSize.Height; + + if (camera->isOrthogonal()) + ln.start = f->cameraPosition + (lefttoright * (dx - 0.5f)) + (uptodown * (dy - 0.5f)); + else + ln.start = f->cameraPosition; + + ln.end = farLeftUp + (lefttoright * dx) + (uptodown * dy); + + return ln; +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CSceneCollisionManager.h b/irr/src/CSceneCollisionManager.h new file mode 100644 index 000000000..d3dc2ef70 --- /dev/null +++ b/irr/src/CSceneCollisionManager.h @@ -0,0 +1,35 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "ISceneCollisionManager.h" +#include "ISceneManager.h" +#include "IVideoDriver.h" + +namespace irr +{ +namespace scene +{ + +class CSceneCollisionManager : public ISceneCollisionManager +{ +public: + //! constructor + CSceneCollisionManager(ISceneManager *smanager, video::IVideoDriver *driver); + + //! destructor + virtual ~CSceneCollisionManager(); + + //! Returns a 3d ray which would go through the 2d screen coordinates. + virtual core::line3d getRayFromScreenCoordinates( + const core::position2d &pos, const ICameraSceneNode *camera = 0) override; + +private: + ISceneManager *SceneManager; + video::IVideoDriver *Driver; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CSceneManager.cpp b/irr/src/CSceneManager.cpp new file mode 100644 index 000000000..b20f6010a --- /dev/null +++ b/irr/src/CSceneManager.cpp @@ -0,0 +1,809 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CSceneManager.h" +#include "IVideoDriver.h" +#include "IFileSystem.h" +#include "SAnimatedMesh.h" +#include "CMeshCache.h" +#include "IGUIEnvironment.h" +#include "IMaterialRenderer.h" +#include "IReadFile.h" +#include "IWriteFile.h" + +#include "os.h" + +#include "CSkinnedMesh.h" +#include "CXMeshFileLoader.h" +#include "COBJMeshFileLoader.h" +#include "CB3DMeshFileLoader.h" +#include "CBillboardSceneNode.h" +#include "CAnimatedMeshSceneNode.h" +#include "CCameraSceneNode.h" +#include "CMeshSceneNode.h" +#include "CDummyTransformationSceneNode.h" +#include "CEmptySceneNode.h" + +#include "CSceneCollisionManager.h" + +namespace irr +{ +namespace scene +{ + +//! constructor +CSceneManager::CSceneManager(video::IVideoDriver *driver, + gui::ICursorControl *cursorControl, IMeshCache *cache) : + ISceneNode(0, 0), + Driver(driver), + CursorControl(cursorControl), + ActiveCamera(0), ShadowColor(150, 0, 0, 0), AmbientLight(0, 0, 0, 0), Parameters(0), + MeshCache(cache), CurrentRenderPass(ESNRP_NONE) +{ +#ifdef _DEBUG + ISceneManager::setDebugName("CSceneManager ISceneManager"); + ISceneNode::setDebugName("CSceneManager ISceneNode"); +#endif + + // root node's scene manager + SceneManager = this; + + if (Driver) + Driver->grab(); + + if (CursorControl) + CursorControl->grab(); + + // create mesh cache if not there already + if (!MeshCache) + MeshCache = new CMeshCache(); + else + MeshCache->grab(); + + // set scene parameters + Parameters = new io::CAttributes(); + + // create collision manager + CollisionManager = new CSceneCollisionManager(this, Driver); + + // add file format loaders. add the least commonly used ones first, + // as these are checked last + + // TODO: now that we have multiple scene managers, these should be + // shallow copies from the previous manager if there is one. + + MeshLoaderList.push_back(new CXMeshFileLoader(this)); + MeshLoaderList.push_back(new COBJMeshFileLoader(this)); + MeshLoaderList.push_back(new CB3DMeshFileLoader(this)); +} + +//! destructor +CSceneManager::~CSceneManager() +{ + clearDeletionList(); + + //! force to remove hardwareTextures from the driver + //! because Scenes may hold internally data bounded to sceneNodes + //! which may be destroyed twice + if (Driver) + Driver->removeAllHardwareBuffers(); + + if (CursorControl) + CursorControl->drop(); + + if (CollisionManager) + CollisionManager->drop(); + + u32 i; + for (i = 0; i < MeshLoaderList.size(); ++i) + MeshLoaderList[i]->drop(); + + if (ActiveCamera) + ActiveCamera->drop(); + ActiveCamera = 0; + + if (MeshCache) + MeshCache->drop(); + + if (Parameters) + Parameters->drop(); + + // remove all nodes before dropping the driver + // as render targets may be destroyed twice + + removeAll(); + + if (Driver) + Driver->drop(); +} + +//! gets an animatable mesh. loads it if needed. returned pointer must not be dropped. +IAnimatedMesh *CSceneManager::getMesh(io::IReadFile *file) +{ + if (!file) + return 0; + + io::path name = file->getFileName(); + IAnimatedMesh *msh = MeshCache->getMeshByName(name); + if (msh) + return msh; + + msh = getUncachedMesh(file, name, name); + + return msh; +} + +// load and create a mesh which we know already isn't in the cache and put it in there +IAnimatedMesh *CSceneManager::getUncachedMesh(io::IReadFile *file, const io::path &filename, const io::path &cachename) +{ + IAnimatedMesh *msh = 0; + + // iterate the list in reverse order so user-added loaders can override the built-in ones + s32 count = MeshLoaderList.size(); + for (s32 i = count - 1; i >= 0; --i) { + if (MeshLoaderList[i]->isALoadableFileExtension(filename)) { + // reset file to avoid side effects of previous calls to createMesh + file->seek(0); + msh = MeshLoaderList[i]->createMesh(file); + if (msh) { + MeshCache->addMesh(cachename, msh); + msh->drop(); + break; + } + } + } + + if (!msh) + os::Printer::log("Could not load mesh, file format seems to be unsupported", filename, ELL_ERROR); + else + os::Printer::log("Loaded mesh", filename, ELL_DEBUG); + + return msh; +} + +//! returns the video driver +video::IVideoDriver *CSceneManager::getVideoDriver() +{ + return Driver; +} + +//! adds a scene node for rendering a static mesh +//! the returned pointer must not be dropped. +IMeshSceneNode *CSceneManager::addMeshSceneNode(IMesh *mesh, ISceneNode *parent, s32 id, + const core::vector3df &position, const core::vector3df &rotation, + const core::vector3df &scale, bool alsoAddIfMeshPointerZero) +{ + if (!alsoAddIfMeshPointerZero && !mesh) + return 0; + + if (!parent) + parent = this; + + IMeshSceneNode *node = new CMeshSceneNode(mesh, parent, this, id, position, rotation, scale); + node->drop(); + + return node; +} + +//! adds a scene node for rendering an animated mesh model +IAnimatedMeshSceneNode *CSceneManager::addAnimatedMeshSceneNode(IAnimatedMesh *mesh, ISceneNode *parent, s32 id, + const core::vector3df &position, const core::vector3df &rotation, + const core::vector3df &scale, bool alsoAddIfMeshPointerZero) +{ + if (!alsoAddIfMeshPointerZero && !mesh) + return 0; + + if (!parent) + parent = this; + + IAnimatedMeshSceneNode *node = + new CAnimatedMeshSceneNode(mesh, parent, this, id, position, rotation, scale); + node->drop(); + + return node; +} + +//! Adds a camera scene node to the tree and sets it as active camera. +//! \param position: Position of the space relative to its parent where the camera will be placed. +//! \param lookat: Position where the camera will look at. Also known as target. +//! \param parent: Parent scene node of the camera. Can be null. If the parent moves, +//! the camera will move too. +//! \return Returns pointer to interface to camera +ICameraSceneNode *CSceneManager::addCameraSceneNode(ISceneNode *parent, + const core::vector3df &position, const core::vector3df &lookat, s32 id, + bool makeActive) +{ + if (!parent) + parent = this; + + ICameraSceneNode *node = new CCameraSceneNode(parent, this, id, position, lookat); + + if (makeActive) + setActiveCamera(node); + node->drop(); + + return node; +} + +//! Adds a billboard scene node to the scene. A billboard is like a 3d sprite: A 2d element, +//! which always looks to the camera. It is usually used for things like explosions, fire, +//! lensflares and things like that. +IBillboardSceneNode *CSceneManager::addBillboardSceneNode(ISceneNode *parent, + const core::dimension2d &size, const core::vector3df &position, s32 id, + video::SColor colorTop, video::SColor colorBottom) +{ + if (!parent) + parent = this; + + IBillboardSceneNode *node = new CBillboardSceneNode(parent, this, id, position, size, + colorTop, colorBottom); + node->drop(); + + return node; +} + +//! Adds an empty scene node. +ISceneNode *CSceneManager::addEmptySceneNode(ISceneNode *parent, s32 id) +{ + if (!parent) + parent = this; + + ISceneNode *node = new CEmptySceneNode(parent, this, id); + node->drop(); + + return node; +} + +//! Adds a dummy transformation scene node to the scene graph. +IDummyTransformationSceneNode *CSceneManager::addDummyTransformationSceneNode( + ISceneNode *parent, s32 id) +{ + if (!parent) + parent = this; + + IDummyTransformationSceneNode *node = new CDummyTransformationSceneNode( + parent, this, id); + node->drop(); + + return node; +} + +//! Returns the root scene node. This is the scene node which is parent +//! of all scene nodes. The root scene node is a special scene node which +//! only exists to manage all scene nodes. It is not rendered and cannot +//! be removed from the scene. +//! \return Returns a pointer to the root scene node. +ISceneNode *CSceneManager::getRootSceneNode() +{ + return this; +} + +//! Returns the current active camera. +//! \return The active camera is returned. Note that this can be NULL, if there +//! was no camera created yet. +ICameraSceneNode *CSceneManager::getActiveCamera() const +{ + return ActiveCamera; +} + +//! Sets the active camera. The previous active camera will be deactivated. +//! \param camera: The new camera which should be active. +void CSceneManager::setActiveCamera(ICameraSceneNode *camera) +{ + if (camera) + camera->grab(); + if (ActiveCamera) + ActiveCamera->drop(); + + ActiveCamera = camera; +} + +//! renders the node. +void CSceneManager::render() +{ +} + +//! returns the axis aligned bounding box of this node +const core::aabbox3d &CSceneManager::getBoundingBox() const +{ + _IRR_DEBUG_BREAK_IF(true) // Bounding Box of Scene Manager should never be used. + + static const core::aabbox3d dummy; + return dummy; +} + +//! returns if node is culled +bool CSceneManager::isCulled(const ISceneNode *node) const +{ + const ICameraSceneNode *cam = getActiveCamera(); + if (!cam) { + return false; + } + bool result = false; + + // has occlusion query information + if (node->getAutomaticCulling() & scene::EAC_OCC_QUERY) { + result = (Driver->getOcclusionQueryResult(const_cast(node)) == 0); + } + + // can be seen by a bounding box ? + if (!result && (node->getAutomaticCulling() & scene::EAC_BOX)) { + core::aabbox3d tbox = node->getBoundingBox(); + node->getAbsoluteTransformation().transformBoxEx(tbox); + result = !(tbox.intersectsWithBox(cam->getViewFrustum()->getBoundingBox())); + } + + // can be seen by a bounding sphere + if (!result && (node->getAutomaticCulling() & scene::EAC_FRUSTUM_SPHERE)) { + const core::aabbox3df nbox = node->getTransformedBoundingBox(); + const float rad = nbox.getRadius(); + const core::vector3df center = nbox.getCenter(); + + const float camrad = cam->getViewFrustum()->getBoundingRadius(); + const core::vector3df camcenter = cam->getViewFrustum()->getBoundingCenter(); + + const float dist = (center - camcenter).getLengthSQ(); + const float maxdist = (rad + camrad) * (rad + camrad); + + result = dist > maxdist; + } + + // can be seen by cam pyramid planes ? + if (!result && (node->getAutomaticCulling() & scene::EAC_FRUSTUM_BOX)) { + SViewFrustum frust = *cam->getViewFrustum(); + + // transform the frustum to the node's current absolute transformation + core::matrix4 invTrans(node->getAbsoluteTransformation(), core::matrix4::EM4CONST_INVERSE); + // invTrans.makeInverse(); + frust.transform(invTrans); + + core::vector3df edges[8]; + node->getBoundingBox().getEdges(edges); + + for (s32 i = 0; i < scene::SViewFrustum::VF_PLANE_COUNT; ++i) { + bool boxInFrustum = false; + for (u32 j = 0; j < 8; ++j) { + if (frust.planes[i].classifyPointRelation(edges[j]) != core::ISREL3D_FRONT) { + boxInFrustum = true; + break; + } + } + + if (!boxInFrustum) { + result = true; + break; + } + } + } + + return result; +} + +//! registers a node for rendering it at a specific time. +u32 CSceneManager::registerNodeForRendering(ISceneNode *node, E_SCENE_NODE_RENDER_PASS pass) +{ + u32 taken = 0; + + switch (pass) { + // take camera if it is not already registered + case ESNRP_CAMERA: { + taken = 1; + for (u32 i = 0; i != CameraList.size(); ++i) { + if (CameraList[i] == node) { + taken = 0; + break; + } + } + if (taken) { + CameraList.push_back(node); + } + } break; + case ESNRP_SKY_BOX: + SkyBoxList.push_back(node); + taken = 1; + break; + case ESNRP_SOLID: + if (!isCulled(node)) { + SolidNodeList.push_back(node); + taken = 1; + } + break; + case ESNRP_TRANSPARENT: + if (!isCulled(node)) { + TransparentNodeList.push_back(TransparentNodeEntry(node, camWorldPos)); + taken = 1; + } + break; + case ESNRP_TRANSPARENT_EFFECT: + if (!isCulled(node)) { + TransparentEffectNodeList.push_back(TransparentNodeEntry(node, camWorldPos)); + taken = 1; + } + break; + case ESNRP_AUTOMATIC: + if (!isCulled(node)) { + const u32 count = node->getMaterialCount(); + + taken = 0; + for (u32 i = 0; i < count; ++i) { + if (Driver->needsTransparentRenderPass(node->getMaterial(i))) { + // register as transparent node + TransparentNodeEntry e(node, camWorldPos); + TransparentNodeList.push_back(e); + taken = 1; + break; + } + } + + // not transparent, register as solid + if (!taken) { + SolidNodeList.push_back(node); + taken = 1; + } + } + break; + case ESNRP_GUI: + if (!isCulled(node)) { + GuiNodeList.push_back(node); + taken = 1; + } + + // as of yet unused + case ESNRP_LIGHT: + case ESNRP_SHADOW: + case ESNRP_NONE: // ignore this one + break; + } + + return taken; +} + +void CSceneManager::clearAllRegisteredNodesForRendering() +{ + CameraList.clear(); + SkyBoxList.clear(); + SolidNodeList.clear(); + TransparentNodeList.clear(); + TransparentEffectNodeList.clear(); + GuiNodeList.clear(); +} + +//! This method is called just before the rendering process of the whole scene. +//! draws all scene nodes +void CSceneManager::drawAll() +{ + if (!Driver) + return; + + u32 i; // new ISO for scoping problem in some compilers + + // reset all transforms + Driver->setMaterial(video::SMaterial()); + Driver->setTransform(video::ETS_PROJECTION, core::IdentityMatrix); + Driver->setTransform(video::ETS_VIEW, core::IdentityMatrix); + Driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); + for (i = video::ETS_COUNT - 1; i >= video::ETS_TEXTURE_0; --i) + Driver->setTransform((video::E_TRANSFORMATION_STATE)i, core::IdentityMatrix); + // TODO: This should not use an attribute here but a real parameter when necessary (too slow!) + Driver->setAllowZWriteOnTransparent(Parameters->getAttributeAsBool(ALLOW_ZWRITE_ON_TRANSPARENT)); + + // do animations and other stuff. + OnAnimate(os::Timer::getTime()); + + /*! + First Scene Node for prerendering should be the active camera + consistent Camera is needed for culling + */ + camWorldPos.set(0, 0, 0); + if (ActiveCamera) { + ActiveCamera->render(); + camWorldPos = ActiveCamera->getAbsolutePosition(); + } + + // let all nodes register themselves + OnRegisterSceneNode(); + + // render camera scenes + { + CurrentRenderPass = ESNRP_CAMERA; + Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRenderPass) != 0); + + for (i = 0; i < CameraList.size(); ++i) + CameraList[i]->render(); + + CameraList.set_used(0); + } + + // render skyboxes + { + CurrentRenderPass = ESNRP_SKY_BOX; + Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRenderPass) != 0); + + for (i = 0; i < SkyBoxList.size(); ++i) + SkyBoxList[i]->render(); + + SkyBoxList.set_used(0); + } + + // render default objects + { + CurrentRenderPass = ESNRP_SOLID; + Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRenderPass) != 0); + + SolidNodeList.sort(); // sort by textures + + for (i = 0; i < SolidNodeList.size(); ++i) + SolidNodeList[i].Node->render(); + + SolidNodeList.set_used(0); + } + + // render transparent objects. + { + CurrentRenderPass = ESNRP_TRANSPARENT; + Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRenderPass) != 0); + + TransparentNodeList.sort(); // sort by distance from camera + for (i = 0; i < TransparentNodeList.size(); ++i) + TransparentNodeList[i].Node->render(); + + TransparentNodeList.set_used(0); + } + + // render transparent effect objects. + { + CurrentRenderPass = ESNRP_TRANSPARENT_EFFECT; + Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRenderPass) != 0); + + TransparentEffectNodeList.sort(); // sort by distance from camera + + for (i = 0; i < TransparentEffectNodeList.size(); ++i) + TransparentEffectNodeList[i].Node->render(); + + TransparentEffectNodeList.set_used(0); + } + + // render custom gui nodes + { + CurrentRenderPass = ESNRP_GUI; + Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRenderPass) != 0); + + for (i = 0; i < GuiNodeList.size(); ++i) + GuiNodeList[i]->render(); + + GuiNodeList.set_used(0); + } + clearDeletionList(); + + CurrentRenderPass = ESNRP_NONE; +} + +//! Adds an external mesh loader. +void CSceneManager::addExternalMeshLoader(IMeshLoader *externalLoader) +{ + if (!externalLoader) + return; + + externalLoader->grab(); + MeshLoaderList.push_back(externalLoader); +} + +//! Returns the number of mesh loaders supported by Irrlicht at this time +u32 CSceneManager::getMeshLoaderCount() const +{ + return MeshLoaderList.size(); +} + +//! Retrieve the given mesh loader +IMeshLoader *CSceneManager::getMeshLoader(u32 index) const +{ + if (index < MeshLoaderList.size()) + return MeshLoaderList[index]; + else + return 0; +} + +//! Returns a pointer to the scene collision manager. +ISceneCollisionManager *CSceneManager::getSceneCollisionManager() +{ + return CollisionManager; +} + +//! Returns a pointer to the mesh manipulator. +IMeshManipulator *CSceneManager::getMeshManipulator() +{ + return Driver->getMeshManipulator(); +} + +//! Adds a scene node to the deletion queue. +void CSceneManager::addToDeletionQueue(ISceneNode *node) +{ + if (!node) + return; + + node->grab(); + DeletionList.push_back(node); +} + +//! clears the deletion list +void CSceneManager::clearDeletionList() +{ + if (DeletionList.empty()) + return; + + for (u32 i = 0; i < DeletionList.size(); ++i) { + DeletionList[i]->remove(); + DeletionList[i]->drop(); + } + + DeletionList.clear(); +} + +//! Returns the first scene node with the specified name. +ISceneNode *CSceneManager::getSceneNodeFromName(const char *name, ISceneNode *start) +{ + if (start == 0) + start = getRootSceneNode(); + + auto startName = start->getName(); + if (startName.has_value() && startName == name) + return start; + + ISceneNode *node = 0; + + const ISceneNodeList &list = start->getChildren(); + ISceneNodeList::const_iterator it = list.begin(); + for (; it != list.end(); ++it) { + node = getSceneNodeFromName(name, *it); + if (node) + return node; + } + + return 0; +} + +//! Returns the first scene node with the specified id. +ISceneNode *CSceneManager::getSceneNodeFromId(s32 id, ISceneNode *start) +{ + if (start == 0) + start = getRootSceneNode(); + + if (start->getID() == id) + return start; + + ISceneNode *node = 0; + + const ISceneNodeList &list = start->getChildren(); + ISceneNodeList::const_iterator it = list.begin(); + for (; it != list.end(); ++it) { + node = getSceneNodeFromId(id, *it); + if (node) + return node; + } + + return 0; +} + +//! Returns the first scene node with the specified type. +ISceneNode *CSceneManager::getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, ISceneNode *start) +{ + if (start == 0) + start = getRootSceneNode(); + + if (start->getType() == type || ESNT_ANY == type) + return start; + + ISceneNode *node = 0; + + const ISceneNodeList &list = start->getChildren(); + ISceneNodeList::const_iterator it = list.begin(); + for (; it != list.end(); ++it) { + node = getSceneNodeFromType(type, *it); + if (node) + return node; + } + + return 0; +} + +//! returns scene nodes by type. +void CSceneManager::getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array &outNodes, ISceneNode *start) +{ + if (start == 0) + start = getRootSceneNode(); + + if (start->getType() == type || ESNT_ANY == type) + outNodes.push_back(start); + + const ISceneNodeList &list = start->getChildren(); + ISceneNodeList::const_iterator it = list.begin(); + + for (; it != list.end(); ++it) { + getSceneNodesFromType(type, outNodes, *it); + } +} + +//! Posts an input event to the environment. Usually you do not have to +//! use this method, it is used by the internal engine. +bool CSceneManager::postEventFromUser(const SEvent &event) +{ + bool ret = false; + ICameraSceneNode *cam = getActiveCamera(); + if (cam) + ret = cam->OnEvent(event); + + return ret; +} + +//! Removes all children of this scene node +void CSceneManager::removeAll() +{ + ISceneNode::removeAll(); + setActiveCamera(0); + // Make sure the driver is reset, might need a more complex method at some point + if (Driver) + Driver->setMaterial(video::SMaterial()); +} + +//! Clears the whole scene. All scene nodes are removed. +void CSceneManager::clear() +{ + removeAll(); +} + +//! Returns interface to the parameters set in this scene. +io::IAttributes *CSceneManager::getParameters() +{ + return Parameters; +} + +//! Returns current render pass. +E_SCENE_NODE_RENDER_PASS CSceneManager::getSceneNodeRenderPass() const +{ + return CurrentRenderPass; +} + +//! Returns an interface to the mesh cache which is shared between all existing scene managers. +IMeshCache *CSceneManager::getMeshCache() +{ + return MeshCache; +} + +//! Creates a new scene manager. +ISceneManager *CSceneManager::createNewSceneManager(bool cloneContent) +{ + CSceneManager *manager = new CSceneManager(Driver, CursorControl, MeshCache); + + if (cloneContent) + manager->cloneMembers(this, manager); + + return manager; +} + +//! Sets ambient color of the scene +void CSceneManager::setAmbientLight(const video::SColorf &ambientColor) +{ + AmbientLight = ambientColor; +} + +//! Returns ambient color of the scene +const video::SColorf &CSceneManager::getAmbientLight() const +{ + return AmbientLight; +} + +//! Get a skinned mesh, which is not available as header-only code +ISkinnedMesh *CSceneManager::createSkinnedMesh() +{ + return new CSkinnedMesh(); +} + +// creates a scenemanager +ISceneManager *createSceneManager(video::IVideoDriver *driver, gui::ICursorControl *cursorcontrol) +{ + return new CSceneManager(driver, cursorcontrol, nullptr); +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CSceneManager.h b/irr/src/CSceneManager.h new file mode 100644 index 000000000..0e27290a8 --- /dev/null +++ b/irr/src/CSceneManager.h @@ -0,0 +1,308 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "ISceneManager.h" +#include "ISceneNode.h" +#include "ICursorControl.h" +#include "irrString.h" +#include "irrArray.h" +#include "IMeshLoader.h" +#include "CAttributes.h" + +namespace irr +{ +namespace io +{ +class IFileSystem; +} +namespace scene +{ +class IMeshCache; + +/*! + The Scene Manager manages scene nodes, mesh resources, cameras and all the other stuff. +*/ +class CSceneManager : public ISceneManager, public ISceneNode +{ +public: + //! constructor + CSceneManager(video::IVideoDriver *driver, gui::ICursorControl *cursorControl, IMeshCache *cache = 0); + + //! destructor + virtual ~CSceneManager(); + + //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped. + IAnimatedMesh *getMesh(io::IReadFile *file) override; + + //! Returns an interface to the mesh cache which is shared between all existing scene managers. + IMeshCache *getMeshCache() override; + + //! returns the video driver + video::IVideoDriver *getVideoDriver() override; + + //! adds a scene node for rendering an animated mesh model + virtual IAnimatedMeshSceneNode *addAnimatedMeshSceneNode(IAnimatedMesh *mesh, ISceneNode *parent = 0, s32 id = -1, + const core::vector3df &position = core::vector3df(0, 0, 0), + const core::vector3df &rotation = core::vector3df(0, 0, 0), + const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f), + bool alsoAddIfMeshPointerZero = false) override; + + //! adds a scene node for rendering a static mesh + //! the returned pointer must not be dropped. + virtual IMeshSceneNode *addMeshSceneNode(IMesh *mesh, ISceneNode *parent = 0, s32 id = -1, + const core::vector3df &position = core::vector3df(0, 0, 0), + const core::vector3df &rotation = core::vector3df(0, 0, 0), + const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f), + bool alsoAddIfMeshPointerZero = false) override; + + //! renders the node. + void render() override; + + //! returns the axis aligned bounding box of this node + const core::aabbox3d &getBoundingBox() const override; + + //! registers a node for rendering it at a specific time. + u32 registerNodeForRendering(ISceneNode *node, E_SCENE_NODE_RENDER_PASS pass = ESNRP_AUTOMATIC) override; + + //! Clear all nodes which are currently registered for rendering + void clearAllRegisteredNodesForRendering() override; + + //! draws all scene nodes + void drawAll() override; + + //! Adds a camera scene node to the tree and sets it as active camera. + //! \param position: Position of the space relative to its parent where the camera will be placed. + //! \param lookat: Position where the camera will look at. Also known as target. + //! \param parent: Parent scene node of the camera. Can be null. If the parent moves, + //! the camera will move too. + //! \return Pointer to interface to camera + virtual ICameraSceneNode *addCameraSceneNode(ISceneNode *parent = 0, + const core::vector3df &position = core::vector3df(0, 0, 0), + const core::vector3df &lookat = core::vector3df(0, 0, 100), + s32 id = -1, bool makeActive = true) override; + + //! Adds a billboard scene node to the scene. A billboard is like a 3d sprite: A 2d element, + //! which always looks to the camera. It is usually used for things like explosions, fire, + //! lensflares and things like that. + virtual IBillboardSceneNode *addBillboardSceneNode(ISceneNode *parent = 0, + const core::dimension2d &size = core::dimension2d(10.0f, 10.0f), + const core::vector3df &position = core::vector3df(0, 0, 0), s32 id = -1, + video::SColor shadeTop = 0xFFFFFFFF, video::SColor shadeBottom = 0xFFFFFFFF) override; + + //! Adds a dummy transformation scene node to the scene graph. + virtual IDummyTransformationSceneNode *addDummyTransformationSceneNode( + ISceneNode *parent = 0, s32 id = -1) override; + + //! Adds an empty scene node. + ISceneNode *addEmptySceneNode(ISceneNode *parent, s32 id = -1) override; + + //! Returns the root scene node. This is the scene node which is parent + //! of all scene nodes. The root scene node is a special scene node which + //! only exists to manage all scene nodes. It is not rendered and cannot + //! be removed from the scene. + //! \return Pointer to the root scene node. + ISceneNode *getRootSceneNode() override; + + //! Returns the current active camera. + //! \return The active camera is returned. Note that this can be NULL, if there + //! was no camera created yet. + ICameraSceneNode *getActiveCamera() const override; + + //! Sets the active camera. The previous active camera will be deactivated. + //! \param camera: The new camera which should be active. + void setActiveCamera(ICameraSceneNode *camera) override; + + //! Adds an external mesh loader. + void addExternalMeshLoader(IMeshLoader *externalLoader) override; + + //! Returns the number of mesh loaders supported by Irrlicht at this time + u32 getMeshLoaderCount() const override; + + //! Retrieve the given mesh loader + IMeshLoader *getMeshLoader(u32 index) const override; + + //! Returns a pointer to the scene collision manager. + ISceneCollisionManager *getSceneCollisionManager() override; + + //! Returns a pointer to the mesh manipulator. + IMeshManipulator *getMeshManipulator() override; + + //! Adds a scene node to the deletion queue. + void addToDeletionQueue(ISceneNode *node) override; + + //! Returns the first scene node with the specified id. + ISceneNode *getSceneNodeFromId(s32 id, ISceneNode *start = 0) override; + + //! Returns the first scene node with the specified name. + ISceneNode *getSceneNodeFromName(const c8 *name, ISceneNode *start = 0) override; + + //! Returns the first scene node with the specified type. + ISceneNode *getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, ISceneNode *start = 0) override; + + //! returns scene nodes by type. + void getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array &outNodes, ISceneNode *start = 0) override; + + //! Posts an input event to the environment. Usually you do not have to + //! use this method, it is used by the internal engine. + bool postEventFromUser(const SEvent &event) override; + + //! Clears the whole scene. All scene nodes are removed. + void clear() override; + + //! Removes all children of this scene node + void removeAll() override; + + //! Returns interface to the parameters set in this scene. + io::IAttributes *getParameters() override; + + //! Returns current render pass. + E_SCENE_NODE_RENDER_PASS getSceneNodeRenderPass() const override; + + //! Creates a new scene manager. + ISceneManager *createNewSceneManager(bool cloneContent) override; + + //! Returns type of the scene node + ESCENE_NODE_TYPE getType() const override { return ESNT_SCENE_MANAGER; } + + //! Get a skinned mesh, which is not available as header-only code + ISkinnedMesh *createSkinnedMesh() override; + + //! Sets ambient color of the scene + void setAmbientLight(const video::SColorf &ambientColor) override; + + //! Returns ambient color of the scene + const video::SColorf &getAmbientLight() const override; + + //! Get current render time. + E_SCENE_NODE_RENDER_PASS getCurrentRenderPass() const override { return CurrentRenderPass; } + + //! Set current render time. + void setCurrentRenderPass(E_SCENE_NODE_RENDER_PASS nextPass) override { CurrentRenderPass = nextPass; } + + //! returns if node is culled + bool isCulled(const ISceneNode *node) const override; + +private: + // load and create a mesh which we know already isn't in the cache and put it in there + IAnimatedMesh *getUncachedMesh(io::IReadFile *file, const io::path &filename, const io::path &cachename); + + //! clears the deletion list + void clearDeletionList(); + + struct DefaultNodeEntry + { + DefaultNodeEntry() + { + } + + DefaultNodeEntry(ISceneNode *n) : + Node(n), TextureValue(0) + { + if (n->getMaterialCount()) + TextureValue = (n->getMaterial(0).getTexture(0)); + } + + bool operator<(const DefaultNodeEntry &other) const + { + return (TextureValue < other.TextureValue); + } + + ISceneNode *Node; + + private: + void *TextureValue; + }; + + //! sort on distance (center) to camera + struct TransparentNodeEntry + { + TransparentNodeEntry() + { + } + + TransparentNodeEntry(ISceneNode *n, const core::vector3df &camera) : + Node(n) + { + Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(camera); + } + + bool operator<(const TransparentNodeEntry &other) const + { + return Distance > other.Distance; + } + + ISceneNode *Node; + + private: + f64 Distance; + }; + + //! sort on distance (sphere) to camera + struct DistanceNodeEntry + { + DistanceNodeEntry(ISceneNode *n, const core::vector3df &cameraPos) : + Node(n) + { + setNodeAndDistanceFromPosition(n, cameraPos); + } + + bool operator<(const DistanceNodeEntry &other) const + { + return Distance < other.Distance; + } + + void setNodeAndDistanceFromPosition(ISceneNode *n, const core::vector3df &fromPosition) + { + Node = n; + Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(fromPosition); + Distance -= Node->getBoundingBox().getExtent().getLengthSQ() * 0.5; + } + + ISceneNode *Node; + + private: + f64 Distance; + }; + + //! video driver + video::IVideoDriver *Driver; + + //! cursor control + gui::ICursorControl *CursorControl; + + //! collision manager + ISceneCollisionManager *CollisionManager; + + //! render pass lists + core::array CameraList; + core::array SkyBoxList; + core::array SolidNodeList; + core::array TransparentNodeList; + core::array TransparentEffectNodeList; + core::array GuiNodeList; + + core::array MeshLoaderList; + core::array DeletionList; + + //! current active camera + ICameraSceneNode *ActiveCamera; + core::vector3df camWorldPos; // Position of camera for transparent nodes. + + video::SColor ShadowColor; + video::SColorf AmbientLight; + + //! String parameters + // NOTE: Attributes are slow and should only be used for debug-info and not in release + io::CAttributes *Parameters; + + //! Mesh cache + IMeshCache *MeshCache; + + E_SCENE_NODE_RENDER_PASS CurrentRenderPass; +}; + +} // end namespace video +} // end namespace scene diff --git a/irr/src/CSkinnedMesh.cpp b/irr/src/CSkinnedMesh.cpp new file mode 100644 index 000000000..eb7317309 --- /dev/null +++ b/irr/src/CSkinnedMesh.cpp @@ -0,0 +1,1336 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CSkinnedMesh.h" +#include +#include "CBoneSceneNode.h" +#include "IAnimatedMeshSceneNode.h" +#include "os.h" + +namespace +{ +// Frames must always be increasing, so we remove objects where this isn't the case +// return number of kicked keys +template // T = objects containing a "frame" variable +irr::u32 dropBadKeys(irr::core::array &array) +{ + if (array.size() < 2) + return 0; + + irr::u32 n = 1; // new index + for (irr::u32 j = 1; j < array.size(); ++j) { + if (array[j].frame < array[n - 1].frame) + continue; // bad frame, unneeded and may cause problems + if (n != j) + array[n] = array[j]; + ++n; + } + irr::u32 d = array.size() - n; // remove already copied keys + if (d > 0) { + array.erase(n, d); + } + return d; +} + +// drop identical middle keys - we only need the first and last +// return number of kicked keys +template // Cmp = comparison for keys of type T +irr::u32 dropMiddleKeys(irr::core::array &array, Cmp &cmp) +{ + if (array.size() < 3) + return 0; + + irr::u32 s = 0; // old index for current key + irr::u32 n = 1; // new index for next key + for (irr::u32 j = 1; j < array.size(); ++j) { + if (cmp(array[j], array[s])) + continue; // same key, handle later + + if (j > s + 1) // had there been identical keys? + array[n++] = array[j - 1]; // keep the last + array[n++] = array[j]; // keep the new one + s = j; + } + if (array.size() > s + 1) // identical keys at the array end? + array[n++] = array[array.size() - 1]; // keep the last + + irr::u32 d = array.size() - n; // remove already copied keys + if (d > 0) { + array.erase(n, d); + } + return d; +} + +bool identicalPos(const irr::scene::ISkinnedMesh::SPositionKey &a, const irr::scene::ISkinnedMesh::SPositionKey &b) +{ + return a.position == b.position; +} + +bool identicalScale(const irr::scene::ISkinnedMesh::SScaleKey &a, const irr::scene::ISkinnedMesh::SScaleKey &b) +{ + return a.scale == b.scale; +} + +bool identicalRotation(const irr::scene::ISkinnedMesh::SRotationKey &a, const irr::scene::ISkinnedMesh::SRotationKey &b) +{ + return a.rotation == b.rotation; +} +} + +namespace irr +{ +namespace scene +{ + +//! constructor +CSkinnedMesh::CSkinnedMesh() : + SkinningBuffers(0), EndFrame(0.f), FramesPerSecond(25.f), + LastAnimatedFrame(-1), SkinnedLastFrame(false), + InterpolationMode(EIM_LINEAR), + HasAnimation(false), PreparedForSkinning(false), + AnimateNormals(true), HardwareSkinning(false) +{ +#ifdef _DEBUG + setDebugName("CSkinnedMesh"); +#endif + + SkinningBuffers = &LocalBuffers; +} + +//! destructor +CSkinnedMesh::~CSkinnedMesh() +{ + for (u32 i = 0; i < AllJoints.size(); ++i) + delete AllJoints[i]; + + for (u32 j = 0; j < LocalBuffers.size(); ++j) { + if (LocalBuffers[j]) + LocalBuffers[j]->drop(); + } +} + +//! returns the amount of frames in milliseconds. +//! If the amount is 1, it is a static (=non animated) mesh. +u32 CSkinnedMesh::getFrameCount() const +{ + return core::floor32(EndFrame + 1.f); +} + +//! Gets the default animation speed of the animated mesh. +/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */ +f32 CSkinnedMesh::getAnimationSpeed() const +{ + return FramesPerSecond; +} + +//! Gets the frame count of the animated mesh. +/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated. +The actual speed is set in the scene node the mesh is instantiated in.*/ +void CSkinnedMesh::setAnimationSpeed(f32 fps) +{ + FramesPerSecond = fps; +} + +//! returns the animated mesh based on a detail level. 0 is the lowest, 255 the highest detail. Note, that some Meshes will ignore the detail level. +IMesh *CSkinnedMesh::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop) +{ + // animate(frame,startFrameLoop, endFrameLoop); + if (frame == -1) + return this; + + animateMesh((f32)frame, 1.0f); + skinMesh(); + return this; +} + +//-------------------------------------------------------------------------- +// Keyframe Animation +//-------------------------------------------------------------------------- + +//! Animates this mesh's joints based on frame input +//! blend: {0-old position, 1-New position} +void CSkinnedMesh::animateMesh(f32 frame, f32 blend) +{ + if (!HasAnimation || LastAnimatedFrame == frame) + return; + + LastAnimatedFrame = frame; + SkinnedLastFrame = false; + + if (blend <= 0.f) + return; // No need to animate + + for (u32 i = 0; i < AllJoints.size(); ++i) { + // The joints can be animated here with no input from their + // parents, but for setAnimationMode extra checks are needed + // to their parents + SJoint *joint = AllJoints[i]; + + const core::vector3df oldPosition = joint->Animatedposition; + const core::vector3df oldScale = joint->Animatedscale; + const core::quaternion oldRotation = joint->Animatedrotation; + + core::vector3df position = oldPosition; + core::vector3df scale = oldScale; + core::quaternion rotation = oldRotation; + + getFrameData(frame, joint, + position, joint->positionHint, + scale, joint->scaleHint, + rotation, joint->rotationHint); + + if (blend == 1.0f) { + // No blending needed + joint->Animatedposition = position; + joint->Animatedscale = scale; + joint->Animatedrotation = rotation; + } else { + // Blend animation + joint->Animatedposition = core::lerp(oldPosition, position, blend); + joint->Animatedscale = core::lerp(oldScale, scale, blend); + joint->Animatedrotation.slerp(oldRotation, rotation, blend); + } + } + + // Note: + // LocalAnimatedMatrix needs to be built at some point, but this function may be called lots of times for + // one render (to play two animations at the same time) LocalAnimatedMatrix only needs to be built once. + // a call to buildAllLocalAnimatedMatrices is needed before skinning the mesh, and before the user gets the joints to move + + //---------------- + // Temp! + buildAllLocalAnimatedMatrices(); + //----------------- + + updateBoundingBox(); +} + +void CSkinnedMesh::buildAllLocalAnimatedMatrices() +{ + for (u32 i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + + // Could be faster: + + if (joint->UseAnimationFrom && + (joint->UseAnimationFrom->PositionKeys.size() || + joint->UseAnimationFrom->ScaleKeys.size() || + joint->UseAnimationFrom->RotationKeys.size())) { + joint->GlobalSkinningSpace = false; + + // IRR_TEST_BROKEN_QUATERNION_USE: TODO - switched to getMatrix_transposed instead of getMatrix for downward compatibility. + // Not tested so far if this was correct or wrong before quaternion fix! + joint->Animatedrotation.getMatrix_transposed(joint->LocalAnimatedMatrix); + + // --- joint->LocalAnimatedMatrix *= joint->Animatedrotation.getMatrix() --- + f32 *m1 = joint->LocalAnimatedMatrix.pointer(); + core::vector3df &Pos = joint->Animatedposition; + m1[0] += Pos.X * m1[3]; + m1[1] += Pos.Y * m1[3]; + m1[2] += Pos.Z * m1[3]; + m1[4] += Pos.X * m1[7]; + m1[5] += Pos.Y * m1[7]; + m1[6] += Pos.Z * m1[7]; + m1[8] += Pos.X * m1[11]; + m1[9] += Pos.Y * m1[11]; + m1[10] += Pos.Z * m1[11]; + m1[12] += Pos.X * m1[15]; + m1[13] += Pos.Y * m1[15]; + m1[14] += Pos.Z * m1[15]; + // ----------------------------------- + + if (joint->ScaleKeys.size()) { + /* + core::matrix4 scaleMatrix; + scaleMatrix.setScale(joint->Animatedscale); + joint->LocalAnimatedMatrix *= scaleMatrix; + */ + + // -------- joint->LocalAnimatedMatrix *= scaleMatrix ----------------- + core::matrix4 &mat = joint->LocalAnimatedMatrix; + mat[0] *= joint->Animatedscale.X; + mat[1] *= joint->Animatedscale.X; + mat[2] *= joint->Animatedscale.X; + mat[3] *= joint->Animatedscale.X; + mat[4] *= joint->Animatedscale.Y; + mat[5] *= joint->Animatedscale.Y; + mat[6] *= joint->Animatedscale.Y; + mat[7] *= joint->Animatedscale.Y; + mat[8] *= joint->Animatedscale.Z; + mat[9] *= joint->Animatedscale.Z; + mat[10] *= joint->Animatedscale.Z; + mat[11] *= joint->Animatedscale.Z; + // ----------------------------------- + } + } else { + joint->LocalAnimatedMatrix = joint->LocalMatrix; + } + } + SkinnedLastFrame = false; +} + +void CSkinnedMesh::buildAllGlobalAnimatedMatrices(SJoint *joint, SJoint *parentJoint) +{ + if (!joint) { + for (u32 i = 0; i < RootJoints.size(); ++i) + buildAllGlobalAnimatedMatrices(RootJoints[i], 0); + return; + } else { + // Find global matrix... + if (!parentJoint || joint->GlobalSkinningSpace) + joint->GlobalAnimatedMatrix = joint->LocalAnimatedMatrix; + else + joint->GlobalAnimatedMatrix = parentJoint->GlobalAnimatedMatrix * joint->LocalAnimatedMatrix; + } + + for (u32 j = 0; j < joint->Children.size(); ++j) + buildAllGlobalAnimatedMatrices(joint->Children[j], joint); +} + +void CSkinnedMesh::getFrameData(f32 frame, SJoint *joint, + core::vector3df &position, s32 &positionHint, + core::vector3df &scale, s32 &scaleHint, + core::quaternion &rotation, s32 &rotationHint) +{ + s32 foundPositionIndex = -1; + s32 foundScaleIndex = -1; + s32 foundRotationIndex = -1; + + if (joint->UseAnimationFrom) { + const core::array &PositionKeys = joint->UseAnimationFrom->PositionKeys; + const core::array &ScaleKeys = joint->UseAnimationFrom->ScaleKeys; + const core::array &RotationKeys = joint->UseAnimationFrom->RotationKeys; + + if (PositionKeys.size()) { + foundPositionIndex = -1; + + // Test the Hints... + if (positionHint >= 0 && (u32)positionHint < PositionKeys.size()) { + // check this hint + if (positionHint > 0 && PositionKeys[positionHint].frame >= frame && PositionKeys[positionHint - 1].frame < frame) + foundPositionIndex = positionHint; + else if (positionHint + 1 < (s32)PositionKeys.size()) { + // check the next index + if (PositionKeys[positionHint + 1].frame >= frame && + PositionKeys[positionHint + 0].frame < frame) { + positionHint++; + foundPositionIndex = positionHint; + } + } + } + + // The hint test failed, do a full scan... + if (foundPositionIndex == -1) { + for (u32 i = 0; i < PositionKeys.size(); ++i) { + if (PositionKeys[i].frame >= frame) { // Keys should to be sorted by frame + foundPositionIndex = i; + positionHint = i; + break; + } + } + } + + // Do interpolation... + if (foundPositionIndex != -1) { + if (InterpolationMode == EIM_CONSTANT || foundPositionIndex == 0) { + position = PositionKeys[foundPositionIndex].position; + } else if (InterpolationMode == EIM_LINEAR) { + const SPositionKey &KeyA = PositionKeys[foundPositionIndex]; + const SPositionKey &KeyB = PositionKeys[foundPositionIndex - 1]; + + const f32 fd1 = frame - KeyA.frame; + const f32 fd2 = KeyB.frame - frame; + position = ((KeyB.position - KeyA.position) / (fd1 + fd2)) * fd1 + KeyA.position; + } + } + } + + //------------------------------------------------------------ + + if (ScaleKeys.size()) { + foundScaleIndex = -1; + + // Test the Hints... + if (scaleHint >= 0 && (u32)scaleHint < ScaleKeys.size()) { + // check this hint + if (scaleHint > 0 && ScaleKeys[scaleHint].frame >= frame && ScaleKeys[scaleHint - 1].frame < frame) + foundScaleIndex = scaleHint; + else if (scaleHint + 1 < (s32)ScaleKeys.size()) { + // check the next index + if (ScaleKeys[scaleHint + 1].frame >= frame && + ScaleKeys[scaleHint + 0].frame < frame) { + scaleHint++; + foundScaleIndex = scaleHint; + } + } + } + + // The hint test failed, do a full scan... + if (foundScaleIndex == -1) { + for (u32 i = 0; i < ScaleKeys.size(); ++i) { + if (ScaleKeys[i].frame >= frame) { // Keys should to be sorted by frame + foundScaleIndex = i; + scaleHint = i; + break; + } + } + } + + // Do interpolation... + if (foundScaleIndex != -1) { + if (InterpolationMode == EIM_CONSTANT || foundScaleIndex == 0) { + scale = ScaleKeys[foundScaleIndex].scale; + } else if (InterpolationMode == EIM_LINEAR) { + const SScaleKey &KeyA = ScaleKeys[foundScaleIndex]; + const SScaleKey &KeyB = ScaleKeys[foundScaleIndex - 1]; + + const f32 fd1 = frame - KeyA.frame; + const f32 fd2 = KeyB.frame - frame; + scale = ((KeyB.scale - KeyA.scale) / (fd1 + fd2)) * fd1 + KeyA.scale; + } + } + } + + //------------------------------------------------------------- + + if (RotationKeys.size()) { + foundRotationIndex = -1; + + // Test the Hints... + if (rotationHint >= 0 && (u32)rotationHint < RotationKeys.size()) { + // check this hint + if (rotationHint > 0 && RotationKeys[rotationHint].frame >= frame && RotationKeys[rotationHint - 1].frame < frame) + foundRotationIndex = rotationHint; + else if (rotationHint + 1 < (s32)RotationKeys.size()) { + // check the next index + if (RotationKeys[rotationHint + 1].frame >= frame && + RotationKeys[rotationHint + 0].frame < frame) { + rotationHint++; + foundRotationIndex = rotationHint; + } + } + } + + // The hint test failed, do a full scan... + if (foundRotationIndex == -1) { + for (u32 i = 0; i < RotationKeys.size(); ++i) { + if (RotationKeys[i].frame >= frame) { // Keys should be sorted by frame + foundRotationIndex = i; + rotationHint = i; + break; + } + } + } + + // Do interpolation... + if (foundRotationIndex != -1) { + if (InterpolationMode == EIM_CONSTANT || foundRotationIndex == 0) { + rotation = RotationKeys[foundRotationIndex].rotation; + } else if (InterpolationMode == EIM_LINEAR) { + const SRotationKey &KeyA = RotationKeys[foundRotationIndex]; + const SRotationKey &KeyB = RotationKeys[foundRotationIndex - 1]; + + const f32 fd1 = frame - KeyA.frame; + const f32 fd2 = KeyB.frame - frame; + const f32 t = fd1 / (fd1 + fd2); + + /* + f32 t = 0; + if (KeyA.frame!=KeyB.frame) + t = (frame-KeyA.frame) / (KeyB.frame - KeyA.frame); + */ + + rotation.slerp(KeyA.rotation, KeyB.rotation, t); + } + } + } + } +} + +//-------------------------------------------------------------------------- +// Software Skinning +//-------------------------------------------------------------------------- + +//! Preforms a software skin on this mesh based of joint positions +void CSkinnedMesh::skinMesh() +{ + if (!HasAnimation || SkinnedLastFrame) + return; + + //---------------- + // This is marked as "Temp!". A shiny dubloon to whomever can tell me why. + buildAllGlobalAnimatedMatrices(); + //----------------- + + SkinnedLastFrame = true; + if (!HardwareSkinning) { + // Software skin.... + u32 i; + + // rigid animation + for (i = 0; i < AllJoints.size(); ++i) { + for (u32 j = 0; j < AllJoints[i]->AttachedMeshes.size(); ++j) { + SSkinMeshBuffer *Buffer = (*SkinningBuffers)[AllJoints[i]->AttachedMeshes[j]]; + Buffer->Transformation = AllJoints[i]->GlobalAnimatedMatrix; + } + } + + // clear skinning helper array + for (i = 0; i < Vertices_Moved.size(); ++i) + for (u32 j = 0; j < Vertices_Moved[i].size(); ++j) + Vertices_Moved[i][j] = false; + + // skin starting with the root joints + for (i = 0; i < RootJoints.size(); ++i) + skinJoint(RootJoints[i], 0); + + for (i = 0; i < SkinningBuffers->size(); ++i) + (*SkinningBuffers)[i]->setDirty(EBT_VERTEX); + } + updateBoundingBox(); +} + +void CSkinnedMesh::skinJoint(SJoint *joint, SJoint *parentJoint) +{ + if (joint->Weights.size()) { + // Find this joints pull on vertices... + core::matrix4 jointVertexPull(core::matrix4::EM4CONST_NOTHING); + jointVertexPull.setbyproduct(joint->GlobalAnimatedMatrix, joint->GlobalInversedMatrix); + + core::vector3df thisVertexMove, thisNormalMove; + + core::array &buffersUsed = *SkinningBuffers; + + // Skin Vertices Positions and Normals... + for (u32 i = 0; i < joint->Weights.size(); ++i) { + SWeight &weight = joint->Weights[i]; + + // Pull this vertex... + jointVertexPull.transformVect(thisVertexMove, weight.StaticPos); + + if (AnimateNormals) + jointVertexPull.rotateVect(thisNormalMove, weight.StaticNormal); + + if (!(*(weight.Moved))) { + *(weight.Moved) = true; + + buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Pos = thisVertexMove * weight.strength; + + if (AnimateNormals) + buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Normal = thisNormalMove * weight.strength; + + //*(weight._Pos) = thisVertexMove * weight.strength; + } else { + buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Pos += thisVertexMove * weight.strength; + + if (AnimateNormals) + buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Normal += thisNormalMove * weight.strength; + + //*(weight._Pos) += thisVertexMove * weight.strength; + } + + buffersUsed[weight.buffer_id]->boundingBoxNeedsRecalculated(); + } + } + + // Skin all children + for (u32 j = 0; j < joint->Children.size(); ++j) + skinJoint(joint->Children[j], joint); +} + +E_ANIMATED_MESH_TYPE CSkinnedMesh::getMeshType() const +{ + return EAMT_SKINNED; +} + +//! Gets joint count. +u32 CSkinnedMesh::getJointCount() const +{ + return AllJoints.size(); +} + +//! Gets the name of a joint. +const std::optional &CSkinnedMesh::getJointName(u32 number) const +{ + if (number >= getJointCount()) { + static const std::optional nullopt; + return nullopt; + } + return AllJoints[number]->Name; +} + +//! Gets a joint number from its name +std::optional CSkinnedMesh::getJointNumber(const std::string &name) const +{ + for (u32 i = 0; i < AllJoints.size(); ++i) { + if (AllJoints[i]->Name == name) + return i; + } + + return std::nullopt; +} + +//! returns amount of mesh buffers. +u32 CSkinnedMesh::getMeshBufferCount() const +{ + return LocalBuffers.size(); +} + +//! returns pointer to a mesh buffer +IMeshBuffer *CSkinnedMesh::getMeshBuffer(u32 nr) const +{ + if (nr < LocalBuffers.size()) + return LocalBuffers[nr]; + else + return 0; +} + +//! Returns pointer to a mesh buffer which fits a material +IMeshBuffer *CSkinnedMesh::getMeshBuffer(const video::SMaterial &material) const +{ + for (u32 i = 0; i < LocalBuffers.size(); ++i) { + if (LocalBuffers[i]->getMaterial() == material) + return LocalBuffers[i]; + } + return 0; +} + +//! returns an axis aligned bounding box +const core::aabbox3d &CSkinnedMesh::getBoundingBox() const +{ + return BoundingBox; +} + +//! set user axis aligned bounding box +void CSkinnedMesh::setBoundingBox(const core::aabbox3df &box) +{ + BoundingBox = box; +} + +//! set the hardware mapping hint, for driver +void CSkinnedMesh::setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, + E_BUFFER_TYPE buffer) +{ + for (u32 i = 0; i < LocalBuffers.size(); ++i) + LocalBuffers[i]->setHardwareMappingHint(newMappingHint, buffer); +} + +//! flags the meshbuffer as changed, reloads hardware buffers +void CSkinnedMesh::setDirty(E_BUFFER_TYPE buffer) +{ + for (u32 i = 0; i < LocalBuffers.size(); ++i) + LocalBuffers[i]->setDirty(buffer); +} + +//! uses animation from another mesh +bool CSkinnedMesh::useAnimationFrom(const ISkinnedMesh *mesh) +{ + bool unmatched = false; + + for (u32 i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + joint->UseAnimationFrom = 0; + + if (joint->Name == "") + unmatched = true; + else { + for (u32 j = 0; j < mesh->getAllJoints().size(); ++j) { + SJoint *otherJoint = mesh->getAllJoints()[j]; + if (joint->Name == otherJoint->Name) { + joint->UseAnimationFrom = otherJoint; + } + } + if (!joint->UseAnimationFrom) + unmatched = true; + } + } + + checkForAnimation(); + + return !unmatched; +} + +//! Update Normals when Animating +//! False= Don't animate them, faster +//! True= Update normals (default) +void CSkinnedMesh::updateNormalsWhenAnimating(bool on) +{ + AnimateNormals = on; +} + +//! Sets Interpolation Mode +void CSkinnedMesh::setInterpolationMode(E_INTERPOLATION_MODE mode) +{ + InterpolationMode = mode; +} + +core::array &CSkinnedMesh::getMeshBuffers() +{ + return LocalBuffers; +} + +core::array &CSkinnedMesh::getAllJoints() +{ + return AllJoints; +} + +const core::array &CSkinnedMesh::getAllJoints() const +{ + return AllJoints; +} + +//! (This feature is not implemented in irrlicht yet) +bool CSkinnedMesh::setHardwareSkinning(bool on) +{ + if (HardwareSkinning != on) { + if (on) { + + // set mesh to static pose... + for (u32 i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + for (u32 j = 0; j < joint->Weights.size(); ++j) { + const u16 buffer_id = joint->Weights[j].buffer_id; + const u32 vertex_id = joint->Weights[j].vertex_id; + LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos = joint->Weights[j].StaticPos; + LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal = joint->Weights[j].StaticNormal; + LocalBuffers[buffer_id]->boundingBoxNeedsRecalculated(); + } + } + } + + HardwareSkinning = on; + } + return HardwareSkinning; +} + +void CSkinnedMesh::refreshJointCache() +{ + // copy cache from the mesh... + for (u32 i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + for (u32 j = 0; j < joint->Weights.size(); ++j) { + const u16 buffer_id = joint->Weights[j].buffer_id; + const u32 vertex_id = joint->Weights[j].vertex_id; + joint->Weights[j].StaticPos = LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos; + joint->Weights[j].StaticNormal = LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal; + } + } +} + +void CSkinnedMesh::resetAnimation() +{ + // copy from the cache to the mesh... + for (u32 i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + for (u32 j = 0; j < joint->Weights.size(); ++j) { + const u16 buffer_id = joint->Weights[j].buffer_id; + const u32 vertex_id = joint->Weights[j].vertex_id; + LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos = joint->Weights[j].StaticPos; + LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal = joint->Weights[j].StaticNormal; + } + } + SkinnedLastFrame = false; + LastAnimatedFrame = -1; +} + +void CSkinnedMesh::calculateGlobalMatrices(SJoint *joint, SJoint *parentJoint) +{ + if (!joint && parentJoint) // bit of protection from endless loops + return; + + // Go through the root bones + if (!joint) { + for (u32 i = 0; i < RootJoints.size(); ++i) + calculateGlobalMatrices(RootJoints[i], 0); + return; + } + + if (!parentJoint) + joint->GlobalMatrix = joint->LocalMatrix; + else + joint->GlobalMatrix = parentJoint->GlobalMatrix * joint->LocalMatrix; + + joint->LocalAnimatedMatrix = joint->LocalMatrix; + joint->GlobalAnimatedMatrix = joint->GlobalMatrix; + + if (joint->GlobalInversedMatrix.isIdentity()) { // might be pre calculated + joint->GlobalInversedMatrix = joint->GlobalMatrix; + joint->GlobalInversedMatrix.makeInverse(); // slow + } + + for (u32 j = 0; j < joint->Children.size(); ++j) + calculateGlobalMatrices(joint->Children[j], joint); + SkinnedLastFrame = false; +} + +void CSkinnedMesh::checkForAnimation() +{ + u32 i, j; + // Check for animation... + HasAnimation = false; + for (i = 0; i < AllJoints.size(); ++i) { + if (AllJoints[i]->UseAnimationFrom) { + if (AllJoints[i]->UseAnimationFrom->PositionKeys.size() || + AllJoints[i]->UseAnimationFrom->ScaleKeys.size() || + AllJoints[i]->UseAnimationFrom->RotationKeys.size()) { + HasAnimation = true; + } + } + } + + // meshes with weights, are still counted as animated for ragdolls, etc + if (!HasAnimation) { + for (i = 0; i < AllJoints.size(); ++i) { + if (AllJoints[i]->Weights.size()) + HasAnimation = true; + } + } + + if (HasAnimation) { + //--- Find the length of the animation --- + EndFrame = 0; + for (i = 0; i < AllJoints.size(); ++i) { + if (AllJoints[i]->UseAnimationFrom) { + if (AllJoints[i]->UseAnimationFrom->PositionKeys.size()) + if (AllJoints[i]->UseAnimationFrom->PositionKeys.getLast().frame > EndFrame) + EndFrame = AllJoints[i]->UseAnimationFrom->PositionKeys.getLast().frame; + + if (AllJoints[i]->UseAnimationFrom->ScaleKeys.size()) + if (AllJoints[i]->UseAnimationFrom->ScaleKeys.getLast().frame > EndFrame) + EndFrame = AllJoints[i]->UseAnimationFrom->ScaleKeys.getLast().frame; + + if (AllJoints[i]->UseAnimationFrom->RotationKeys.size()) + if (AllJoints[i]->UseAnimationFrom->RotationKeys.getLast().frame > EndFrame) + EndFrame = AllJoints[i]->UseAnimationFrom->RotationKeys.getLast().frame; + } + } + } + + if (HasAnimation && !PreparedForSkinning) { + PreparedForSkinning = true; + + // check for bugs: + for (i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + for (j = 0; j < joint->Weights.size(); ++j) { + const u16 buffer_id = joint->Weights[j].buffer_id; + const u32 vertex_id = joint->Weights[j].vertex_id; + + // check for invalid ids + if (buffer_id >= LocalBuffers.size()) { + os::Printer::log("Skinned Mesh: Weight buffer id too large", ELL_WARNING); + joint->Weights[j].buffer_id = joint->Weights[j].vertex_id = 0; + } else if (vertex_id >= LocalBuffers[buffer_id]->getVertexCount()) { + os::Printer::log("Skinned Mesh: Weight vertex id too large", ELL_WARNING); + joint->Weights[j].buffer_id = joint->Weights[j].vertex_id = 0; + } + } + } + + // An array used in skinning + + for (i = 0; i < Vertices_Moved.size(); ++i) + for (j = 0; j < Vertices_Moved[i].size(); ++j) + Vertices_Moved[i][j] = false; + + // For skinning: cache weight values for speed + + for (i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + for (j = 0; j < joint->Weights.size(); ++j) { + const u16 buffer_id = joint->Weights[j].buffer_id; + const u32 vertex_id = joint->Weights[j].vertex_id; + + joint->Weights[j].Moved = &Vertices_Moved[buffer_id][vertex_id]; + joint->Weights[j].StaticPos = LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos; + joint->Weights[j].StaticNormal = LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal; + + // joint->Weights[j]._Pos=&Buffers[buffer_id]->getVertex(vertex_id)->Pos; + } + } + + // normalize weights + normalizeWeights(); + } + SkinnedLastFrame = false; +} + +//! called by loader after populating with mesh and bone data +void CSkinnedMesh::finalize() +{ + os::Printer::log("Skinned Mesh - finalize", ELL_DEBUG); + u32 i; + + // Make sure we recalc the next frame + LastAnimatedFrame = -1; + SkinnedLastFrame = false; + + // calculate bounding box + for (i = 0; i < LocalBuffers.size(); ++i) { + LocalBuffers[i]->recalculateBoundingBox(); + } + + if (AllJoints.size() || RootJoints.size()) { + // populate AllJoints or RootJoints, depending on which is empty + if (!RootJoints.size()) { + + for (u32 CheckingIdx = 0; CheckingIdx < AllJoints.size(); ++CheckingIdx) { + + bool foundParent = false; + for (i = 0; i < AllJoints.size(); ++i) { + for (u32 n = 0; n < AllJoints[i]->Children.size(); ++n) { + if (AllJoints[i]->Children[n] == AllJoints[CheckingIdx]) + foundParent = true; + } + } + + if (!foundParent) + RootJoints.push_back(AllJoints[CheckingIdx]); + } + } else { + AllJoints = RootJoints; + } + } + + for (i = 0; i < AllJoints.size(); ++i) { + AllJoints[i]->UseAnimationFrom = AllJoints[i]; + } + + // Set array sizes... + + for (i = 0; i < LocalBuffers.size(); ++i) { + Vertices_Moved.push_back(core::array()); + Vertices_Moved[i].set_used(LocalBuffers[i]->getVertexCount()); + } + + checkForAnimation(); + + if (HasAnimation) { + irr::u32 redundantPosKeys = 0; + irr::u32 unorderedPosKeys = 0; + irr::u32 redundantScaleKeys = 0; + irr::u32 unorderedScaleKeys = 0; + irr::u32 redundantRotationKeys = 0; + irr::u32 unorderedRotationKeys = 0; + + //--- optimize and check keyframes --- + for (i = 0; i < AllJoints.size(); ++i) { + core::array &PositionKeys = AllJoints[i]->PositionKeys; + core::array &ScaleKeys = AllJoints[i]->ScaleKeys; + core::array &RotationKeys = AllJoints[i]->RotationKeys; + + // redundant = identical middle keys - we only need the first and last frame + // unordered = frames which are out of order - we can't handle those + redundantPosKeys += dropMiddleKeys(PositionKeys, identicalPos); + unorderedPosKeys += dropBadKeys(PositionKeys); + redundantScaleKeys += dropMiddleKeys(ScaleKeys, identicalScale); + unorderedScaleKeys += dropBadKeys(ScaleKeys); + redundantRotationKeys += dropMiddleKeys(RotationKeys, identicalRotation); + unorderedRotationKeys += dropBadKeys(RotationKeys); + + // Fill empty keyframe areas + if (PositionKeys.size()) { + SPositionKey *Key; + Key = &PositionKeys[0]; // getFirst + if (Key->frame != 0) { + PositionKeys.push_front(*Key); + Key = &PositionKeys[0]; // getFirst + Key->frame = 0; + } + + Key = &PositionKeys.getLast(); + if (Key->frame != EndFrame) { + PositionKeys.push_back(*Key); + Key = &PositionKeys.getLast(); + Key->frame = EndFrame; + } + } + + if (ScaleKeys.size()) { + SScaleKey *Key; + Key = &ScaleKeys[0]; // getFirst + if (Key->frame != 0) { + ScaleKeys.push_front(*Key); + Key = &ScaleKeys[0]; // getFirst + Key->frame = 0; + } + + Key = &ScaleKeys.getLast(); + if (Key->frame != EndFrame) { + ScaleKeys.push_back(*Key); + Key = &ScaleKeys.getLast(); + Key->frame = EndFrame; + } + } + + if (RotationKeys.size()) { + SRotationKey *Key; + Key = &RotationKeys[0]; // getFirst + if (Key->frame != 0) { + RotationKeys.push_front(*Key); + Key = &RotationKeys[0]; // getFirst + Key->frame = 0; + } + + Key = &RotationKeys.getLast(); + if (Key->frame != EndFrame) { + RotationKeys.push_back(*Key); + Key = &RotationKeys.getLast(); + Key->frame = EndFrame; + } + } + } + + if (redundantPosKeys > 0) { + os::Printer::log("Skinned Mesh - redundant position frames kicked", core::stringc(redundantPosKeys).c_str(), ELL_DEBUG); + } + if (unorderedPosKeys > 0) { + irr::os::Printer::log("Skinned Mesh - unsorted position frames kicked", irr::core::stringc(unorderedPosKeys).c_str(), irr::ELL_DEBUG); + } + if (redundantScaleKeys > 0) { + os::Printer::log("Skinned Mesh - redundant scale frames kicked", core::stringc(redundantScaleKeys).c_str(), ELL_DEBUG); + } + if (unorderedScaleKeys > 0) { + irr::os::Printer::log("Skinned Mesh - unsorted scale frames kicked", irr::core::stringc(unorderedScaleKeys).c_str(), irr::ELL_DEBUG); + } + if (redundantRotationKeys > 0) { + os::Printer::log("Skinned Mesh - redundant rotation frames kicked", core::stringc(redundantRotationKeys).c_str(), ELL_DEBUG); + } + if (unorderedRotationKeys > 0) { + irr::os::Printer::log("Skinned Mesh - unsorted rotation frames kicked", irr::core::stringc(unorderedRotationKeys).c_str(), irr::ELL_DEBUG); + } + } + + // Needed for animation and skinning... + + calculateGlobalMatrices(0, 0); + + // animateMesh(0, 1); + // buildAllLocalAnimatedMatrices(); + // buildAllGlobalAnimatedMatrices(); + + // rigid animation for non animated meshes + for (i = 0; i < AllJoints.size(); ++i) { + for (u32 j = 0; j < AllJoints[i]->AttachedMeshes.size(); ++j) { + SSkinMeshBuffer *Buffer = (*SkinningBuffers)[AllJoints[i]->AttachedMeshes[j]]; + Buffer->Transformation = AllJoints[i]->GlobalAnimatedMatrix; + } + } + + // calculate bounding box + if (LocalBuffers.empty()) + BoundingBox.reset(0, 0, 0); + else { + irr::core::aabbox3df bb(LocalBuffers[0]->BoundingBox); + LocalBuffers[0]->Transformation.transformBoxEx(bb); + BoundingBox.reset(bb); + + for (u32 j = 1; j < LocalBuffers.size(); ++j) { + bb = LocalBuffers[j]->BoundingBox; + LocalBuffers[j]->Transformation.transformBoxEx(bb); + + BoundingBox.addInternalBox(bb); + } + } +} + +void CSkinnedMesh::updateBoundingBox(void) +{ + if (!SkinningBuffers) + return; + + core::array &buffer = *SkinningBuffers; + BoundingBox.reset(0, 0, 0); + + if (!buffer.empty()) { + for (u32 j = 0; j < buffer.size(); ++j) { + buffer[j]->recalculateBoundingBox(); + core::aabbox3df bb = buffer[j]->BoundingBox; + buffer[j]->Transformation.transformBoxEx(bb); + + BoundingBox.addInternalBox(bb); + } + } +} + +scene::SSkinMeshBuffer *CSkinnedMesh::addMeshBuffer() +{ + scene::SSkinMeshBuffer *buffer = new scene::SSkinMeshBuffer(); + LocalBuffers.push_back(buffer); + return buffer; +} + +CSkinnedMesh::SJoint *CSkinnedMesh::addJoint(SJoint *parent) +{ + SJoint *joint = new SJoint; + + AllJoints.push_back(joint); + if (!parent) { + // Add root joints to array in finalize() + } else { + // Set parent (Be careful of the mesh loader also setting the parent) + parent->Children.push_back(joint); + } + + return joint; +} + +CSkinnedMesh::SPositionKey *CSkinnedMesh::addPositionKey(SJoint *joint) +{ + if (!joint) + return 0; + + joint->PositionKeys.push_back(SPositionKey()); + return &joint->PositionKeys.getLast(); +} + +CSkinnedMesh::SScaleKey *CSkinnedMesh::addScaleKey(SJoint *joint) +{ + if (!joint) + return 0; + + joint->ScaleKeys.push_back(SScaleKey()); + return &joint->ScaleKeys.getLast(); +} + +CSkinnedMesh::SRotationKey *CSkinnedMesh::addRotationKey(SJoint *joint) +{ + if (!joint) + return 0; + + joint->RotationKeys.push_back(SRotationKey()); + return &joint->RotationKeys.getLast(); +} + +CSkinnedMesh::SWeight *CSkinnedMesh::addWeight(SJoint *joint) +{ + if (!joint) + return 0; + + joint->Weights.push_back(SWeight()); + return &joint->Weights.getLast(); +} + +bool CSkinnedMesh::isStatic() +{ + return !HasAnimation; +} + +void CSkinnedMesh::normalizeWeights() +{ + // note: unsure if weights ids are going to be used. + + // Normalise the weights on bones.... + + u32 i, j; + core::array> verticesTotalWeight; + + verticesTotalWeight.reallocate(LocalBuffers.size()); + for (i = 0; i < LocalBuffers.size(); ++i) { + verticesTotalWeight.push_back(core::array()); + verticesTotalWeight[i].set_used(LocalBuffers[i]->getVertexCount()); + } + + for (i = 0; i < verticesTotalWeight.size(); ++i) + for (j = 0; j < verticesTotalWeight[i].size(); ++j) + verticesTotalWeight[i][j] = 0; + + for (i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + for (j = 0; j < joint->Weights.size(); ++j) { + if (joint->Weights[j].strength <= 0) { // Check for invalid weights + joint->Weights.erase(j); + --j; + } else { + verticesTotalWeight[joint->Weights[j].buffer_id][joint->Weights[j].vertex_id] += joint->Weights[j].strength; + } + } + } + + for (i = 0; i < AllJoints.size(); ++i) { + SJoint *joint = AllJoints[i]; + for (j = 0; j < joint->Weights.size(); ++j) { + const f32 total = verticesTotalWeight[joint->Weights[j].buffer_id][joint->Weights[j].vertex_id]; + if (total != 0 && total != 1) + joint->Weights[j].strength /= total; + } + } +} + +void CSkinnedMesh::recoverJointsFromMesh(core::array &jointChildSceneNodes) +{ + for (u32 i = 0; i < AllJoints.size(); ++i) { + IBoneSceneNode *node = jointChildSceneNodes[i]; + SJoint *joint = AllJoints[i]; + node->setPosition(joint->LocalAnimatedMatrix.getTranslation()); + node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees()); + node->setScale(joint->LocalAnimatedMatrix.getScale()); + + node->positionHint = joint->positionHint; + node->scaleHint = joint->scaleHint; + node->rotationHint = joint->rotationHint; + + node->updateAbsolutePosition(); + } +} + +void CSkinnedMesh::transferJointsToMesh(const core::array &jointChildSceneNodes) +{ + for (u32 i = 0; i < AllJoints.size(); ++i) { + const IBoneSceneNode *const node = jointChildSceneNodes[i]; + SJoint *joint = AllJoints[i]; + + joint->LocalAnimatedMatrix.setRotationDegrees(node->getRotation()); + joint->LocalAnimatedMatrix.setTranslation(node->getPosition()); + joint->LocalAnimatedMatrix *= core::matrix4().setScale(node->getScale()); + + joint->positionHint = node->positionHint; + joint->scaleHint = node->scaleHint; + joint->rotationHint = node->rotationHint; + + joint->GlobalSkinningSpace = (node->getSkinningSpace() == EBSS_GLOBAL); + } + // Make sure we recalc the next frame + LastAnimatedFrame = -1; + SkinnedLastFrame = false; +} + +void CSkinnedMesh::transferOnlyJointsHintsToMesh(const core::array &jointChildSceneNodes) +{ + for (u32 i = 0; i < AllJoints.size(); ++i) { + const IBoneSceneNode *const node = jointChildSceneNodes[i]; + SJoint *joint = AllJoints[i]; + + joint->positionHint = node->positionHint; + joint->scaleHint = node->scaleHint; + joint->rotationHint = node->rotationHint; + } + SkinnedLastFrame = false; +} + +void CSkinnedMesh::addJoints(core::array &jointChildSceneNodes, + IAnimatedMeshSceneNode *node, ISceneManager *smgr) +{ + // Create new joints + for (u32 i = 0; i < AllJoints.size(); ++i) { + jointChildSceneNodes.push_back(new CBoneSceneNode(0, smgr, 0, i, AllJoints[i]->Name)); + } + + // Match up parents + for (u32 i = 0; i < jointChildSceneNodes.size(); ++i) { + const SJoint *const joint = AllJoints[i]; // should be fine + + s32 parentID = -1; + + for (u32 j = 0; (parentID == -1) && (j < AllJoints.size()); ++j) { + if (i != j) { + const SJoint *const parentTest = AllJoints[j]; + for (u32 n = 0; n < parentTest->Children.size(); ++n) { + if (parentTest->Children[n] == joint) { + parentID = j; + break; + } + } + } + } + + IBoneSceneNode *bone = jointChildSceneNodes[i]; + if (parentID != -1) + bone->setParent(jointChildSceneNodes[parentID]); + else + bone->setParent(node); + + bone->drop(); + } + SkinnedLastFrame = false; +} + +void CSkinnedMesh::convertMeshToTangents() +{ + // now calculate tangents + for (u32 b = 0; b < LocalBuffers.size(); ++b) { + if (LocalBuffers[b]) { + LocalBuffers[b]->convertToTangents(); + + const s32 idxCnt = LocalBuffers[b]->getIndexCount(); + + u16 *idx = LocalBuffers[b]->getIndices(); + video::S3DVertexTangents *v = + (video::S3DVertexTangents *)LocalBuffers[b]->getVertices(); + + for (s32 i = 0; i < idxCnt; i += 3) { + calculateTangents( + v[idx[i + 0]].Normal, + v[idx[i + 0]].Tangent, + v[idx[i + 0]].Binormal, + v[idx[i + 0]].Pos, + v[idx[i + 1]].Pos, + v[idx[i + 2]].Pos, + v[idx[i + 0]].TCoords, + v[idx[i + 1]].TCoords, + v[idx[i + 2]].TCoords); + + calculateTangents( + v[idx[i + 1]].Normal, + v[idx[i + 1]].Tangent, + v[idx[i + 1]].Binormal, + v[idx[i + 1]].Pos, + v[idx[i + 2]].Pos, + v[idx[i + 0]].Pos, + v[idx[i + 1]].TCoords, + v[idx[i + 2]].TCoords, + v[idx[i + 0]].TCoords); + + calculateTangents( + v[idx[i + 2]].Normal, + v[idx[i + 2]].Tangent, + v[idx[i + 2]].Binormal, + v[idx[i + 2]].Pos, + v[idx[i + 0]].Pos, + v[idx[i + 1]].Pos, + v[idx[i + 2]].TCoords, + v[idx[i + 0]].TCoords, + v[idx[i + 1]].TCoords); + } + } + } +} + +void CSkinnedMesh::calculateTangents( + core::vector3df &normal, + core::vector3df &tangent, + core::vector3df &binormal, + const core::vector3df &vt1, const core::vector3df &vt2, const core::vector3df &vt3, // vertices + const core::vector2df &tc1, const core::vector2df &tc2, const core::vector2df &tc3) // texture coords +{ + core::vector3df v1 = vt1 - vt2; + core::vector3df v2 = vt3 - vt1; + normal = v2.crossProduct(v1); + normal.normalize(); + + // binormal + + f32 deltaX1 = tc1.X - tc2.X; + f32 deltaX2 = tc3.X - tc1.X; + binormal = (v1 * deltaX2) - (v2 * deltaX1); + binormal.normalize(); + + // tangent + + f32 deltaY1 = tc1.Y - tc2.Y; + f32 deltaY2 = tc3.Y - tc1.Y; + tangent = (v1 * deltaY2) - (v2 * deltaY1); + tangent.normalize(); + + // adjust + + core::vector3df txb = tangent.crossProduct(binormal); + if (txb.dotProduct(normal) < 0.0f) { + tangent *= -1.0f; + binormal *= -1.0f; + } +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CSkinnedMesh.h b/irr/src/CSkinnedMesh.h new file mode 100644 index 000000000..b0228c93b --- /dev/null +++ b/irr/src/CSkinnedMesh.h @@ -0,0 +1,212 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// New skinned mesh + +#pragma once + +#include "ISkinnedMesh.h" +#include "SMeshBuffer.h" +#include "quaternion.h" + +namespace irr +{ +namespace scene +{ + +class IAnimatedMeshSceneNode; +class IBoneSceneNode; + +class CSkinnedMesh : public ISkinnedMesh +{ +public: + //! constructor + CSkinnedMesh(); + + //! destructor + virtual ~CSkinnedMesh(); + + //! returns the amount of frames. If the amount is 1, it is a static (=non animated) mesh. + u32 getFrameCount() const override; + + //! Gets the default animation speed of the animated mesh. + /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */ + f32 getAnimationSpeed() const override; + + //! Gets the frame count of the animated mesh. + /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated. + The actual speed is set in the scene node the mesh is instantiated in.*/ + void setAnimationSpeed(f32 fps) override; + + //! returns the animated mesh based on a detail level (which is ignored) + IMesh *getMesh(s32 frame, s32 detailLevel = 255, s32 startFrameLoop = -1, s32 endFrameLoop = -1) override; + + //! Animates this mesh's joints based on frame input + //! blend: {0-old position, 1-New position} + void animateMesh(f32 frame, f32 blend) override; + + //! Preforms a software skin on this mesh based of joint positions + void skinMesh() override; + + //! returns amount of mesh buffers. + u32 getMeshBufferCount() const override; + + //! returns pointer to a mesh buffer + IMeshBuffer *getMeshBuffer(u32 nr) const override; + + //! Returns pointer to a mesh buffer which fits a material + /** \param material: material to search for + \return Returns the pointer to the mesh buffer or + NULL if there is no such mesh buffer. */ + IMeshBuffer *getMeshBuffer(const video::SMaterial &material) const override; + + //! returns an axis aligned bounding box + const core::aabbox3d &getBoundingBox() const override; + + //! set user axis aligned bounding box + void setBoundingBox(const core::aabbox3df &box) override; + + //! set the hardware mapping hint, for driver + void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override; + + //! flags the meshbuffer as changed, reloads hardware buffers + void setDirty(E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override; + + //! Returns the type of the animated mesh. + E_ANIMATED_MESH_TYPE getMeshType() const override; + + //! Gets joint count. + u32 getJointCount() const override; + + //! Gets the name of a joint. + const std::optional &getJointName(u32 number) const override; + + //! Gets a joint number from its name + std::optional getJointNumber(const std::string &name) const override; + + //! uses animation from another mesh + bool useAnimationFrom(const ISkinnedMesh *mesh) override; + + //! Update Normals when Animating + //! False= Don't (default) + //! True = Update normals, slower + void updateNormalsWhenAnimating(bool on) override; + + //! Sets Interpolation Mode + void setInterpolationMode(E_INTERPOLATION_MODE mode) override; + + //! Convertes the mesh to contain tangent information + void convertMeshToTangents() override; + + //! Does the mesh have no animation + bool isStatic() override; + + //! (This feature is not implemented in irrlicht yet) + bool setHardwareSkinning(bool on) override; + + //! Refreshes vertex data cached in joints such as positions and normals + void refreshJointCache() override; + + //! Moves the mesh into static position. + void resetAnimation() override; + + // Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_ + // these functions will use the needed arrays, set values, etc to help the loaders + + //! exposed for loaders to add mesh buffers + core::array &getMeshBuffers() override; + + //! alternative method for adding joints + core::array &getAllJoints() override; + + //! alternative method for adding joints + const core::array &getAllJoints() const override; + + //! loaders should call this after populating the mesh + void finalize() override; + + //! Adds a new meshbuffer to the mesh, access it as last one + SSkinMeshBuffer *addMeshBuffer() override; + + //! Adds a new joint to the mesh, access it as last one + SJoint *addJoint(SJoint *parent = 0) override; + + //! Adds a new position key to the mesh, access it as last one + SPositionKey *addPositionKey(SJoint *joint) override; + //! Adds a new rotation key to the mesh, access it as last one + SRotationKey *addRotationKey(SJoint *joint) override; + //! Adds a new scale key to the mesh, access it as last one + SScaleKey *addScaleKey(SJoint *joint) override; + + //! Adds a new weight to the mesh, access it as last one + SWeight *addWeight(SJoint *joint) override; + + virtual void updateBoundingBox(void); + + //! Recovers the joints from the mesh + void recoverJointsFromMesh(core::array &jointChildSceneNodes); + + //! Tranfers the joint data to the mesh + void transferJointsToMesh(const core::array &jointChildSceneNodes); + + //! Tranfers the joint hints to the mesh + void transferOnlyJointsHintsToMesh(const core::array &jointChildSceneNodes); + + //! Creates an array of joints from this mesh as children of node + void addJoints(core::array &jointChildSceneNodes, + IAnimatedMeshSceneNode *node, + ISceneManager *smgr); + +private: + void checkForAnimation(); + + void normalizeWeights(); + + void buildAllLocalAnimatedMatrices(); + + void buildAllGlobalAnimatedMatrices(SJoint *Joint = 0, SJoint *ParentJoint = 0); + + void getFrameData(f32 frame, SJoint *Node, + core::vector3df &position, s32 &positionHint, + core::vector3df &scale, s32 &scaleHint, + core::quaternion &rotation, s32 &rotationHint); + + void calculateGlobalMatrices(SJoint *Joint, SJoint *ParentJoint); + + void skinJoint(SJoint *Joint, SJoint *ParentJoint); + + void calculateTangents(core::vector3df &normal, + core::vector3df &tangent, core::vector3df &binormal, + const core::vector3df &vt1, const core::vector3df &vt2, const core::vector3df &vt3, + const core::vector2df &tc1, const core::vector2df &tc2, const core::vector2df &tc3); + + core::array *SkinningBuffers; // Meshbuffer to skin, default is to skin localBuffers + + core::array LocalBuffers; + + core::array AllJoints; + core::array RootJoints; + + // bool can't be used here because std::vector + // doesn't allow taking a reference to individual elements. + core::array> Vertices_Moved; + + core::aabbox3d BoundingBox; + + f32 EndFrame; + f32 FramesPerSecond; + + f32 LastAnimatedFrame; + bool SkinnedLastFrame; + + E_INTERPOLATION_MODE InterpolationMode : 8; + + bool HasAnimation; + bool PreparedForSkinning; + bool AnimateNormals; + bool HardwareSkinning; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CTimer.h b/irr/src/CTimer.h new file mode 100644 index 000000000..950365cd5 --- /dev/null +++ b/irr/src/CTimer.h @@ -0,0 +1,96 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "ITimer.h" +#include "os.h" + +namespace irr +{ +//! Device independent implementation of the timer +class CTimer : public ITimer +{ +public: + CTimer() + { + os::Timer::initTimer(); + } + + //! Returns current real time in milliseconds of the system. + /** This value does not start with 0 when the application starts. + For example in one implementation the value returned could be the + amount of milliseconds which have elapsed since the system was started. */ + u32 getRealTime() const override + { + return os::Timer::getRealTime(); + } + + //! Returns current virtual time in milliseconds. + /** This value starts with 0 and can be manipulated using setTime(), stopTimer(), + startTimer(), etc. This value depends on the set speed of the timer if the timer + is stopped, etc. If you need the system time, use getRealTime() */ + u32 getTime() const override + { + return os::Timer::getTime(); + } + + //! sets current virtual time + void setTime(u32 time) override + { + os::Timer::setTime(time); + } + + //! Stops the game timer. + /** The timer is reference counted, which means everything which calls + stopTimer() will also have to call startTimer(), otherwise the timer may not start/stop + corretly again. */ + void stop() override + { + os::Timer::stopTimer(); + } + + //! Starts the game timer. + /** The timer is reference counted, which means everything which calls + stopTimer() will also have to call startTimer(), otherwise the timer may not start/stop + corretly again. */ + void start() override + { + os::Timer::startTimer(); + } + + //! Sets the speed of the timer + /** The speed is the factor with which the time is running faster or slower then the + real system time. */ + void setSpeed(f32 speed = 1.0f) override + { + os::Timer::setSpeed(speed); + } + + //! Returns current speed of the timer + /** The speed is the factor with which the time is running faster or slower then the + real system time. */ + f32 getSpeed() const override + { + return os::Timer::getSpeed(); + } + + //! Returns if game timer is currently stopped + bool isStopped() const override + { + bool ret = os::Timer::isStopped(); + return ret; + } + + //! Advances the virtual time + /** Makes the virtual timer update the time value based on the real time. This is + called automatically when calling IrrlichtDevice::run(), but you can call it manually + if you don't use this method. */ + void tick() override + { + os::Timer::tick(); + } +}; + +} // end namespace diff --git a/irr/src/CWGLManager.cpp b/irr/src/CWGLManager.cpp new file mode 100644 index 000000000..9c071a9e8 --- /dev/null +++ b/irr/src/CWGLManager.cpp @@ -0,0 +1,443 @@ +// Copyright (C) 2013 Christian Stehno +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "CWGLManager.h" + +#ifdef _IRR_COMPILE_WITH_WGL_MANAGER_ + +#include "os.h" + +#include +#include + +namespace irr +{ +namespace video +{ + +CWGLManager::CWGLManager() : + PrimaryContext(SExposedVideoData(0)), PixelFormat(0), libHandle(NULL) +{ +#ifdef _DEBUG + setDebugName("CWGLManager"); +#endif + memset(FunctionPointers, 0, sizeof(FunctionPointers)); +} + +CWGLManager::~CWGLManager() +{ +} + +bool CWGLManager::initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &videodata) +{ + // store params, videoData is set later as it would be overwritten else + Params = params; + + // Create a window to test antialiasing support + const fschar_t *ClassName = __TEXT("CWGLManager"); + HINSTANCE lhInstance = GetModuleHandle(0); + + // Register Class + WNDCLASSEX wcex; + wcex.cbSize = sizeof(WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = (WNDPROC)DefWindowProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = lhInstance; + wcex.hIcon = 0; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszMenuName = 0; + wcex.lpszClassName = ClassName; + wcex.hIconSm = 0; + RegisterClassEx(&wcex); + + RECT clientSize; + clientSize.top = 0; + clientSize.left = 0; + clientSize.right = Params.WindowSize.Width; + clientSize.bottom = Params.WindowSize.Height; + + DWORD style = WS_POPUP; + if (!Params.Fullscreen) + style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; + + AdjustWindowRect(&clientSize, style, FALSE); + + const s32 realWidth = clientSize.right - clientSize.left; + const s32 realHeight = clientSize.bottom - clientSize.top; + + const s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2; + const s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2; + + HWND temporary_wnd = CreateWindow(ClassName, __TEXT(""), style, windowLeft, + windowTop, realWidth, realHeight, NULL, NULL, lhInstance, NULL); + + if (!temporary_wnd) { + os::Printer::log("Cannot create a temporary window.", ELL_ERROR); + UnregisterClass(ClassName, lhInstance); + return false; + } + + HDC HDc = GetDC(temporary_wnd); + + // Set up pixel format descriptor with desired parameters + PIXELFORMATDESCRIPTOR tmp_pfd = { + sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + 1, // Version Number + (DWORD)(PFD_DRAW_TO_WINDOW | // Format Must Support Window + PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + (Params.Doublebuffer ? PFD_DOUBLEBUFFER : 0) | // Must Support Double Buffering + (Params.Stereobuffer ? PFD_STEREO : 0)), // Must Support Stereo Buffer + PFD_TYPE_RGBA, // Request An RGBA Format + Params.Bits, // Select Our Color Depth + 0, 0, 0, 0, 0, 0, // Color Bits Ignored + 0, // No Alpha Buffer + 0, // Shift Bit Ignored + 0, // No Accumulation Buffer + 0, 0, 0, 0, // Accumulation Bits Ignored + Params.ZBufferBits, // Z-Buffer (Depth Buffer) + BYTE(Params.Stencilbuffer ? 1 : 0), // Stencil Buffer Depth + 0, // No Auxiliary Buffer + PFD_MAIN_PLANE, // Main Drawing Layer + 0, // Reserved + 0, 0, 0 // Layer Masks Ignored + }; + pfd = tmp_pfd; + + for (u32 i = 0; i < 6; ++i) { + if (i == 1) { + if (Params.Stencilbuffer) { + os::Printer::log("Cannot create a GL device with stencil buffer, disabling stencil shadows.", ELL_WARNING); + Params.Stencilbuffer = false; + pfd.cStencilBits = 0; + } else + continue; + } else if (i == 2) { + pfd.cDepthBits = 24; + } else if (i == 3) { + if (Params.Bits != 16) + pfd.cDepthBits = 16; + else + continue; + } else if (i == 4) { + // try single buffer + if (Params.Doublebuffer) + pfd.dwFlags &= ~PFD_DOUBLEBUFFER; + else + continue; + } else if (i == 5) { + os::Printer::log("Cannot create a GL device context", "No suitable format for temporary window.", ELL_ERROR); + ReleaseDC(temporary_wnd, HDc); + DestroyWindow(temporary_wnd); + UnregisterClass(ClassName, lhInstance); + return false; + } + + // choose pixelformat + PixelFormat = ChoosePixelFormat(HDc, &pfd); + if (PixelFormat) + break; + } + + SetPixelFormat(HDc, PixelFormat, &pfd); + os::Printer::log("Create temporary GL rendering context", ELL_DEBUG); + HGLRC hrc = wglCreateContext(HDc); + if (!hrc) { + os::Printer::log("Cannot create a temporary GL rendering context.", ELL_ERROR); + ReleaseDC(temporary_wnd, HDc); + DestroyWindow(temporary_wnd); + UnregisterClass(ClassName, lhInstance); + return false; + } + + CurrentContext.OpenGLWin32.HDc = HDc; + CurrentContext.OpenGLWin32.HRc = hrc; + CurrentContext.OpenGLWin32.HWnd = temporary_wnd; + + if (!activateContext(CurrentContext, false)) { + os::Printer::log("Cannot activate a temporary GL rendering context.", ELL_ERROR); + wglDeleteContext(hrc); + ReleaseDC(temporary_wnd, HDc); + DestroyWindow(temporary_wnd); + UnregisterClass(ClassName, lhInstance); + return false; + } + + core::stringc wglExtensions; +#ifdef WGL_ARB_extensions_string + PFNWGLGETEXTENSIONSSTRINGARBPROC irrGetExtensionsString = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); + if (irrGetExtensionsString) + wglExtensions = irrGetExtensionsString(HDc); +#elif defined(WGL_EXT_extensions_string) + PFNWGLGETEXTENSIONSSTRINGEXTPROC irrGetExtensionsString = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddress("wglGetExtensionsStringEXT"); + if (irrGetExtensionsString) + wglExtensions = irrGetExtensionsString(HDc); +#endif + const bool pixel_format_supported = (wglExtensions.find("WGL_ARB_pixel_format") != -1); + const bool multi_sample_supported = ((wglExtensions.find("WGL_ARB_multisample") != -1) || + (wglExtensions.find("WGL_EXT_multisample") != -1) || (wglExtensions.find("WGL_3DFX_multisample") != -1)); +#ifdef _DEBUG + os::Printer::log("WGL_extensions", wglExtensions); +#endif + + // Without a GL context we can't call wglGetProcAddress so store this for later + FunctionPointers[0] = (void *)wglGetProcAddress("wglCreateContextAttribsARB"); + +#ifdef WGL_ARB_pixel_format + PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat_ARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); + if (pixel_format_supported && wglChoosePixelFormat_ARB) { + // This value determines the number of samples used for antialiasing + // My experience is that 8 does not show a big + // improvement over 4, but 4 shows a big improvement + // over 2. + + if (Params.AntiAlias > 32) + Params.AntiAlias = 32; + + f32 fAttributes[] = {0.0, 0.0}; + s32 iAttributes[] = { + WGL_DRAW_TO_WINDOW_ARB, 1, + WGL_SUPPORT_OPENGL_ARB, 1, + WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, + WGL_COLOR_BITS_ARB, (Params.Bits == 32) ? 24 : 15, + WGL_ALPHA_BITS_ARB, (Params.Bits == 32) ? 8 : 1, + WGL_DEPTH_BITS_ARB, Params.ZBufferBits, // 10,11 + WGL_STENCIL_BITS_ARB, Params.Stencilbuffer ? 1 : 0, + WGL_DOUBLE_BUFFER_ARB, Params.Doublebuffer ? 1 : 0, + WGL_STEREO_ARB, Params.Stereobuffer ? 1 : 0, + WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, +#ifdef WGL_ARB_multisample + WGL_SAMPLES_ARB, Params.AntiAlias, // 20,21 + WGL_SAMPLE_BUFFERS_ARB, (Params.AntiAlias > 0) ? 1 : 0, +#elif defined(WGL_EXT_multisample) + WGL_SAMPLES_EXT, AntiAlias, // 20,21 + WGL_SAMPLE_BUFFERS_EXT, (Params.AntiAlias > 0) ? 1 : 0, +#elif defined(WGL_3DFX_multisample) + WGL_SAMPLES_3DFX, AntiAlias, // 20,21 + WGL_SAMPLE_BUFFERS_3DFX, (Params.AntiAlias > 0) ? 1 : 0, +#endif + // WGL_DEPTH_FLOAT_EXT, 1, + 0, 0, 0, 0, + }; + int iAttrSize = sizeof(iAttributes) / sizeof(int); + if (!multi_sample_supported) { + memmove(&iAttributes[20], &iAttributes[24], sizeof(int) * (iAttrSize - 24)); + iAttrSize -= 4; + } + + s32 rv = 0; + // Try to get an acceptable pixel format + do { + int pixelFormat = 0; + UINT numFormats = 0; + const BOOL valid = wglChoosePixelFormat_ARB(HDc, iAttributes, fAttributes, 1, &pixelFormat, &numFormats); + + if (valid && numFormats) + rv = pixelFormat; + else + iAttributes[21] -= 1; + } while (rv == 0 && iAttributes[21] > 1); + if (rv) { + PixelFormat = rv; + Params.AntiAlias = iAttributes[21]; + } + } else +#endif + Params.AntiAlias = 0; + + // this only terminates the temporary HRc + destroyContext(); + destroySurface(); + terminate(); + DestroyWindow(temporary_wnd); + UnregisterClass(ClassName, lhInstance); + + // now get new window + CurrentContext.OpenGLWin32.HWnd = videodata.OpenGLWin32.HWnd; + // get hdc + if (!(CurrentContext.OpenGLWin32.HDc = GetDC((HWND)videodata.OpenGLWin32.HWnd))) { + os::Printer::log("Cannot create a GL device context.", ELL_ERROR); + return false; + } + if (!PrimaryContext.OpenGLWin32.HWnd) { + PrimaryContext.OpenGLWin32.HWnd = CurrentContext.OpenGLWin32.HWnd; + PrimaryContext.OpenGLWin32.HDc = CurrentContext.OpenGLWin32.HDc; + } + + return true; +} + +void CWGLManager::terminate() +{ + if (CurrentContext.OpenGLWin32.HDc) + ReleaseDC((HWND)CurrentContext.OpenGLWin32.HWnd, (HDC)CurrentContext.OpenGLWin32.HDc); + if (PrimaryContext.OpenGLWin32.HDc && PrimaryContext.OpenGLWin32.HDc == CurrentContext.OpenGLWin32.HDc) + memset(&PrimaryContext, 0, sizeof(PrimaryContext)); + memset(&CurrentContext, 0, sizeof(CurrentContext)); + if (libHandle) + FreeLibrary(libHandle); +} + +bool CWGLManager::generateSurface() +{ + HDC HDc = (HDC)CurrentContext.OpenGLWin32.HDc; + // search for pixel format the simple way + if (PixelFormat == 0 || (!SetPixelFormat(HDc, PixelFormat, &pfd))) { + for (u32 i = 0; i < 5; ++i) { + if (i == 1) { + if (Params.Stencilbuffer) { + os::Printer::log("Cannot create a GL device with stencil buffer, disabling stencil shadows.", ELL_WARNING); + Params.Stencilbuffer = false; + pfd.cStencilBits = 0; + } else + continue; + } else if (i == 2) { + pfd.cDepthBits = 24; + } + if (i == 3) { + if (Params.Bits != 16) + pfd.cDepthBits = 16; + else + continue; + } else if (i == 4) { + os::Printer::log("Cannot create a GL device context", "No suitable format.", ELL_ERROR); + return false; + } + + // choose pixelformat + PixelFormat = ChoosePixelFormat(HDc, &pfd); + if (PixelFormat) + break; + } + + // set pixel format + if (!SetPixelFormat(HDc, PixelFormat, &pfd)) { + os::Printer::log("Cannot set the pixel format.", ELL_ERROR); + return false; + } + } + + if (pfd.cAlphaBits != 0) { + if (pfd.cRedBits == 8) + ColorFormat = ECF_A8R8G8B8; + else + ColorFormat = ECF_A1R5G5B5; + } else { + if (pfd.cRedBits == 8) + ColorFormat = ECF_R8G8B8; + else + ColorFormat = ECF_R5G6B5; + } + os::Printer::log("Pixel Format", core::stringc(PixelFormat).c_str(), ELL_DEBUG); + return true; +} + +void CWGLManager::destroySurface() +{ +} + +bool CWGLManager::generateContext() +{ + HDC HDc = (HDC)CurrentContext.OpenGLWin32.HDc; + HGLRC hrc; + // create rendering context +#ifdef WGL_ARB_create_context + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs_ARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)FunctionPointers[0]; + if (wglCreateContextAttribs_ARB) { + // with 3.0 all available profiles should be usable, higher versions impose restrictions + // we need at least 1.1 + const int iAttribs[] = { + WGL_CONTEXT_MAJOR_VERSION_ARB, 1, + WGL_CONTEXT_MINOR_VERSION_ARB, 1, + // WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, // enable to get a debug context (depends on driver if that does anything) + 0, + }; + hrc = wglCreateContextAttribs_ARB(HDc, 0, iAttribs); + } else +#endif + hrc = wglCreateContext(HDc); + os::Printer::log("Irrlicht context"); + + if (!hrc) { + os::Printer::log("Cannot create a GL rendering context.", ELL_ERROR); + return false; + } + + // set exposed data + CurrentContext.OpenGLWin32.HRc = hrc; + if (!PrimaryContext.OpenGLWin32.HRc) + PrimaryContext.OpenGLWin32.HRc = CurrentContext.OpenGLWin32.HRc; + + return true; +} + +const SExposedVideoData &CWGLManager::getContext() const +{ + return CurrentContext; +} + +bool CWGLManager::activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) +{ + if (videoData.OpenGLWin32.HWnd && videoData.OpenGLWin32.HDc && videoData.OpenGLWin32.HRc) { + if (!wglMakeCurrent((HDC)videoData.OpenGLWin32.HDc, (HGLRC)videoData.OpenGLWin32.HRc)) { + os::Printer::log("Render Context switch failed."); + return false; + } + CurrentContext = videoData; + } else if (!restorePrimaryOnZero && !videoData.OpenGLWin32.HDc && !videoData.OpenGLWin32.HRc) { + if (!wglMakeCurrent((HDC)0, (HGLRC)0)) { + os::Printer::log("Render Context reset failed."); + return false; + } + CurrentContext = videoData; + } + // set back to main context + else if (!videoData.OpenGLWin32.HWnd && CurrentContext.OpenGLWin32.HDc != PrimaryContext.OpenGLWin32.HDc) { + if (!wglMakeCurrent((HDC)PrimaryContext.OpenGLWin32.HDc, (HGLRC)PrimaryContext.OpenGLWin32.HRc)) { + os::Printer::log("Render Context switch (back to main) failed."); + return false; + } + CurrentContext = PrimaryContext; + } + return true; +} + +void CWGLManager::destroyContext() +{ + if (CurrentContext.OpenGLWin32.HRc) { + if (!wglMakeCurrent((HDC)CurrentContext.OpenGLWin32.HDc, 0)) + os::Printer::log("Release of render context failed.", ELL_WARNING); + + if (!wglDeleteContext((HGLRC)CurrentContext.OpenGLWin32.HRc)) + os::Printer::log("Deletion of render context failed.", ELL_WARNING); + if (PrimaryContext.OpenGLWin32.HRc == CurrentContext.OpenGLWin32.HRc) + PrimaryContext.OpenGLWin32.HRc = 0; + CurrentContext.OpenGLWin32.HRc = 0; + } +} + +void *CWGLManager::getProcAddress(const std::string &procName) +{ + void *proc = NULL; + proc = (void *)wglGetProcAddress(procName.c_str()); + if (!proc) { // Fallback + if (!libHandle) + libHandle = LoadLibraryA("opengl32.dll"); + if (libHandle) + proc = (void *)GetProcAddress(libHandle, procName.c_str()); + } + return proc; +} + +bool CWGLManager::swapBuffers() +{ + return SwapBuffers((HDC)CurrentContext.OpenGLWin32.HDc) == TRUE; +} + +} +} + +#endif diff --git a/irr/src/CWGLManager.h b/irr/src/CWGLManager.h new file mode 100644 index 000000000..b8276d5f8 --- /dev/null +++ b/irr/src/CWGLManager.h @@ -0,0 +1,76 @@ +// Copyright (C) 2013 Christian Stehno +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#ifdef _IRR_COMPILE_WITH_WGL_MANAGER_ + +#include "SIrrCreationParameters.h" +#include "SExposedVideoData.h" +#include "IContextManager.h" +#include "SColor.h" + +#define WIN32_LEAN_AND_MEAN +#include +#include + +namespace irr +{ +namespace video +{ +// WGL manager. +class CWGLManager : public IContextManager +{ +public: + //! Constructor. + CWGLManager(); + + //! Destructor + ~CWGLManager(); + + // Initialize + bool initialize(const SIrrlichtCreationParameters ¶ms, const SExposedVideoData &data) override; + + // Terminate + void terminate() override; + + // Create surface. + bool generateSurface() override; + + // Destroy surface. + void destroySurface() override; + + // Create context. + bool generateContext() override; + + // Destroy EGL context. + void destroyContext() override; + + //! Get current context + const SExposedVideoData &getContext() const override; + + //! Change render context, disable old and activate new defined by videoData + bool activateContext(const SExposedVideoData &videoData, bool restorePrimaryOnZero) override; + + // Get procedure address. + void *getProcAddress(const std::string &procName) override; + + // Swap buffers. + bool swapBuffers() override; + +private: + SIrrlichtCreationParameters Params; + SExposedVideoData PrimaryContext; + SExposedVideoData CurrentContext; + s32 PixelFormat; + PIXELFORMATDESCRIPTOR pfd; + ECOLOR_FORMAT ColorFormat; + void *FunctionPointers[1]; + + HMODULE libHandle; +}; +} +} + +#endif diff --git a/irr/src/CWriteFile.cpp b/irr/src/CWriteFile.cpp new file mode 100644 index 000000000..362b284ee --- /dev/null +++ b/irr/src/CWriteFile.cpp @@ -0,0 +1,106 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CWriteFile.h" +#include + +namespace irr +{ +namespace io +{ + +CWriteFile::CWriteFile(const io::path &fileName, bool append) : + Filename(fileName), FileSize(0) +{ +#ifdef _DEBUG + setDebugName("CWriteFile"); +#endif + + openFile(append); +} + +CWriteFile::~CWriteFile() +{ + if (File) + fclose(File); +} + +//! returns if file is open +inline bool CWriteFile::isOpen() const +{ + return File != 0; +} + +//! returns how much was read +size_t CWriteFile::write(const void *buffer, size_t sizeToWrite) +{ + if (!isOpen()) + return 0; + + return fwrite(buffer, 1, sizeToWrite, File); +} + +//! changes position in file, returns true if successful +//! if relativeMovement==true, the pos is changed relative to current pos, +//! otherwise from begin of file +bool CWriteFile::seek(long finalPos, bool relativeMovement) +{ + if (!isOpen()) + return false; + + return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0; +} + +//! returns where in the file we are. +long CWriteFile::getPos() const +{ + return ftell(File); +} + +//! opens the file +void CWriteFile::openFile(bool append) +{ + if (Filename.size() == 0) { + File = 0; + return; + } + + File = fopen(Filename.c_str(), append ? "ab" : "wb"); + + if (File) { + // get FileSize + + fseek(File, 0, SEEK_END); + FileSize = ftell(File); + fseek(File, 0, SEEK_SET); + } +} + +//! returns name of file +const io::path &CWriteFile::getFileName() const +{ + return Filename; +} + +//! Flush the content of the buffer in the file +bool CWriteFile::flush() +{ + if (!isOpen()) + return false; + + return fflush(File) == 0; // 0 indicates success, otherwise EOF and errno is set +} + +IWriteFile *CWriteFile::createWriteFile(const io::path &fileName, bool append) +{ + CWriteFile *file = new CWriteFile(fileName, append); + if (file->isOpen()) + return file; + + file->drop(); + return 0; +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CWriteFile.h b/irr/src/CWriteFile.h new file mode 100644 index 000000000..20bca0894 --- /dev/null +++ b/irr/src/CWriteFile.h @@ -0,0 +1,58 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include +#include "IWriteFile.h" +#include "irrString.h" + +namespace irr +{ + +namespace io +{ + +/*! + Class for writing a real file to disk. +*/ +class CWriteFile : public IWriteFile +{ +public: + CWriteFile(const io::path &fileName, bool append); + + virtual ~CWriteFile(); + + //! Reads an amount of bytes from the file. + size_t write(const void *buffer, size_t sizeToWrite) override; + + //! Changes position in file, returns true if successful. + bool seek(long finalPos, bool relativeMovement = false) override; + + //! Returns the current position in the file. + long getPos() const override; + + //! Returns name of file. + const io::path &getFileName() const override; + + //! Flush the content of the buffer in the file + bool flush() override; + + //! returns if file is open + bool isOpen() const; + + //! creator method + static IWriteFile *createWriteFile(const io::path &fileName, bool append); + +private: + //! opens the file + void openFile(bool append); + + io::path Filename; + FILE *File; + long FileSize; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CXMeshFileLoader.cpp b/irr/src/CXMeshFileLoader.cpp new file mode 100644 index 000000000..5978980f4 --- /dev/null +++ b/irr/src/CXMeshFileLoader.cpp @@ -0,0 +1,2042 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CXMeshFileLoader.h" +#include "os.h" + +#include "fast_atof.h" +#include "coreutil.h" +#include "ISceneManager.h" +#include "IVideoDriver.h" +#include "IReadFile.h" + +#ifdef _DEBUG +#define _XREADER_DEBUG +#endif +// #define BETTER_MESHBUFFER_SPLITTING_FOR_X + +#define SET_ERR_AND_RETURN() \ + do { \ + ErrorState = true; \ + return false; \ + } while (0) + +namespace irr +{ +namespace scene +{ + +//! Constructor +CXMeshFileLoader::CXMeshFileLoader(scene::ISceneManager *smgr) : + AnimatedMesh(0), Buffer(0), P(0), End(0), BinaryNumCount(0), Line(0), ErrorState(false), + CurFrame(0), MajorVersion(0), MinorVersion(0), BinaryFormat(false), FloatSize(0) +{ +#ifdef _DEBUG + setDebugName("CXMeshFileLoader"); +#endif +} + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".bsp") +bool CXMeshFileLoader::isALoadableFileExtension(const io::path &filename) const +{ + return core::hasFileExtension(filename, "x"); +} + +//! creates/loads an animated mesh from the file. +//! \return Pointer to the created mesh. Returns 0 if loading failed. +//! If you no longer need the mesh, you should call IAnimatedMesh::drop(). +//! See IReferenceCounted::drop() for more information. +IAnimatedMesh *CXMeshFileLoader::createMesh(io::IReadFile *file) +{ + if (!file) + return 0; + +#ifdef _XREADER_DEBUG + u32 time = os::Timer::getRealTime(); +#endif + + AnimatedMesh = new CSkinnedMesh(); + + if (load(file)) { + AnimatedMesh->finalize(); + } else { + AnimatedMesh->drop(); + AnimatedMesh = 0; + } +#ifdef _XREADER_DEBUG + time = os::Timer::getRealTime() - time; + core::stringc tmpString = "Time to load "; + tmpString += BinaryFormat ? "binary" : "ascii"; + tmpString += " X file: "; + tmpString += time; + tmpString += "ms"; + os::Printer::log(tmpString.c_str()); +#endif + // Clear up + + MajorVersion = 0; + MinorVersion = 0; + BinaryFormat = 0; + BinaryNumCount = 0; + FloatSize = 0; + P = 0; + End = 0; + CurFrame = 0; + + delete[] Buffer; + Buffer = 0; + + for (u32 i = 0; i < Meshes.size(); ++i) + delete Meshes[i]; + Meshes.clear(); + + return AnimatedMesh; +} + +bool CXMeshFileLoader::load(io::IReadFile *file) +{ + if (!readFileIntoMemory(file)) + return false; + + if (!parseFile()) + return false; + + for (u32 n = 0; n < Meshes.size(); ++n) { + SXMesh *mesh = Meshes[n]; + + // default material if nothing loaded + if (!mesh->Materials.size()) { + mesh->Materials.push_back(video::SMaterial()); + mesh->Materials[0].DiffuseColor.set(0xff777777); + mesh->Materials[0].Shininess = 0.f; + mesh->Materials[0].SpecularColor.set(0xff777777); + mesh->Materials[0].EmissiveColor.set(0xff000000); + } + + u32 i; + + mesh->Buffers.reallocate(mesh->Materials.size()); +#ifndef BETTER_MESHBUFFER_SPLITTING_FOR_X + const u32 bufferOffset = AnimatedMesh->getMeshBufferCount(); +#endif + for (i = 0; i < mesh->Materials.size(); ++i) { + mesh->Buffers.push_back(AnimatedMesh->addMeshBuffer()); + mesh->Buffers.getLast()->Material = mesh->Materials[i]; + + if (!mesh->HasSkinning) { + // Set up rigid animation + if (mesh->AttachedJointID != -1) { + AnimatedMesh->getAllJoints()[mesh->AttachedJointID]->AttachedMeshes.push_back(AnimatedMesh->getMeshBuffers().size() - 1); + } + } + } + + if (!mesh->FaceMaterialIndices.size()) { + mesh->FaceMaterialIndices.set_used(mesh->Indices.size() / 3); + for (i = 0; i < mesh->FaceMaterialIndices.size(); ++i) + mesh->FaceMaterialIndices[i] = 0; + } + + if (!mesh->HasVertexColors) { + for (u32 j = 0; j < mesh->FaceMaterialIndices.size(); ++j) { + for (u32 id = j * 3 + 0; id <= j * 3 + 2; ++id) { + mesh->Vertices[mesh->Indices[id]].Color = mesh->Buffers[mesh->FaceMaterialIndices[j]]->Material.DiffuseColor; + } + } + } + +#ifdef BETTER_MESHBUFFER_SPLITTING_FOR_X + { + // the same vertex can be used in many different meshbuffers, but it's slow to work out + + core::array> verticesLinkIndex; + verticesLinkIndex.reallocate(mesh->Vertices.size()); + core::array> verticesLinkBuffer; + verticesLinkBuffer.reallocate(mesh->Vertices.size()); + + for (i = 0; i < mesh->Vertices.size(); ++i) { + verticesLinkIndex.push_back(core::array()); + verticesLinkBuffer.push_back(core::array()); + } + + for (i = 0; i < mesh->FaceMaterialIndices.size(); ++i) { + for (u32 id = i * 3 + 0; id <= i * 3 + 2; ++id) { + core::array &Array = verticesLinkBuffer[mesh->Indices[id]]; + bool found = false; + + for (u32 j = 0; j < Array.size(); ++j) { + if (Array[j] == mesh->FaceMaterialIndices[i]) { + found = true; + break; + } + } + + if (!found) + Array.push_back(mesh->FaceMaterialIndices[i]); + } + } + + for (i = 0; i < verticesLinkBuffer.size(); ++i) { + if (!verticesLinkBuffer[i].size()) + verticesLinkBuffer[i].push_back(0); + } + + for (i = 0; i < mesh->Vertices.size(); ++i) { + core::array &Array = verticesLinkBuffer[i]; + verticesLinkIndex[i].reallocate(Array.size()); + for (u32 j = 0; j < Array.size(); ++j) { + scene::SSkinMeshBuffer *buffer = mesh->Buffers[Array[j]]; + verticesLinkIndex[i].push_back(buffer->Vertices_Standard.size()); + buffer->Vertices_Standard.push_back(mesh->Vertices[i]); + } + } + + for (i = 0; i < mesh->FaceMaterialIndices.size(); ++i) { + scene::SSkinMeshBuffer *buffer = mesh->Buffers[mesh->FaceMaterialIndices[i]]; + + for (u32 id = i * 3 + 0; id <= i * 3 + 2; ++id) { + core::array &Array = verticesLinkBuffer[mesh->Indices[id]]; + + for (u32 j = 0; j < Array.size(); ++j) { + if (Array[j] == mesh->FaceMaterialIndices[i]) + buffer->Indices.push_back(verticesLinkIndex[mesh->Indices[id]][j]); + } + } + } + + for (u32 j = 0; j < mesh->WeightJoint.size(); ++j) { + ISkinnedMesh::SJoint *joint = AnimatedMesh->getAllJoints()[mesh->WeightJoint[j]]; + ISkinnedMesh::SWeight &weight = joint->Weights[mesh->WeightNum[j]]; + + u32 id = weight.vertex_id; + + if (id >= verticesLinkIndex.size()) { + os::Printer::log("X loader: Weight id out of range", ELL_WARNING); + id = 0; + weight.strength = 0.f; + } + + if (verticesLinkBuffer[id].size() == 1) { + weight.vertex_id = verticesLinkIndex[id][0]; + weight.buffer_id = verticesLinkBuffer[id][0]; + } else if (verticesLinkBuffer[id].size() != 0) { + for (u32 k = 1; k < verticesLinkBuffer[id].size(); ++k) { + ISkinnedMesh::SWeight *WeightClone = AnimatedMesh->addWeight(joint); + WeightClone->strength = weight.strength; + WeightClone->vertex_id = verticesLinkIndex[id][k]; + WeightClone->buffer_id = verticesLinkBuffer[id][k]; + } + } + } + } +#else + { + core::array verticesLinkIndex; + core::array verticesLinkBuffer; + verticesLinkBuffer.set_used(mesh->Vertices.size()); + + // init with 0 + for (i = 0; i < mesh->Vertices.size(); ++i) { + // watch out for vertices which are not part of the mesh + // they will keep the -1 and can lead to out-of-bounds access + verticesLinkBuffer[i] = -1; + } + + bool warned = false; + // store meshbuffer number per vertex + for (i = 0; i < mesh->FaceMaterialIndices.size(); ++i) { + for (u32 id = i * 3 + 0; id <= i * 3 + 2; ++id) { + if ((verticesLinkBuffer[mesh->Indices[id]] != -1) && (verticesLinkBuffer[mesh->Indices[id]] != (s16)mesh->FaceMaterialIndices[i])) { + if (!warned) { + os::Printer::log("X loader", "Duplicated vertex, animation might be corrupted.", ELL_WARNING); + warned = true; + } + const u32 tmp = mesh->Vertices.size(); + mesh->Vertices.push_back(mesh->Vertices[mesh->Indices[id]]); + mesh->Indices[id] = tmp; + verticesLinkBuffer.set_used(mesh->Vertices.size()); + } + verticesLinkBuffer[mesh->Indices[id]] = mesh->FaceMaterialIndices[i]; + } + } + + if (mesh->FaceMaterialIndices.size() != 0) { + // store vertices in buffers and remember relation in verticesLinkIndex + u32 *vCountArray = new u32[mesh->Buffers.size()]; + memset(vCountArray, 0, mesh->Buffers.size() * sizeof(u32)); + // count vertices in each buffer and reallocate + for (i = 0; i < mesh->Vertices.size(); ++i) { + if (verticesLinkBuffer[i] != -1) + ++vCountArray[verticesLinkBuffer[i]]; + } + if (mesh->TCoords2.size()) { + for (i = 0; i != mesh->Buffers.size(); ++i) { + mesh->Buffers[i]->Vertices_2TCoords.reallocate(vCountArray[i]); + mesh->Buffers[i]->VertexType = video::EVT_2TCOORDS; + } + } else { + for (i = 0; i != mesh->Buffers.size(); ++i) + mesh->Buffers[i]->Vertices_Standard.reallocate(vCountArray[i]); + } + + verticesLinkIndex.set_used(mesh->Vertices.size()); + // actually store vertices + for (i = 0; i < mesh->Vertices.size(); ++i) { + // if a vertex is missing for some reason, just skip it + if (verticesLinkBuffer[i] == -1) + continue; + scene::SSkinMeshBuffer *buffer = mesh->Buffers[verticesLinkBuffer[i]]; + + if (mesh->TCoords2.size()) { + verticesLinkIndex[i] = buffer->Vertices_2TCoords.size(); + buffer->Vertices_2TCoords.push_back(mesh->Vertices[i]); + // We have a problem with correct tcoord2 handling here + // crash fixed for now by checking the values + buffer->Vertices_2TCoords.getLast().TCoords2 = (i < mesh->TCoords2.size()) ? mesh->TCoords2[i] : mesh->Vertices[i].TCoords; + } else { + verticesLinkIndex[i] = buffer->Vertices_Standard.size(); + buffer->Vertices_Standard.push_back(mesh->Vertices[i]); + } + } + + // count indices per buffer and reallocate + memset(vCountArray, 0, mesh->Buffers.size() * sizeof(u32)); + for (i = 0; i < mesh->FaceMaterialIndices.size(); ++i) + ++vCountArray[mesh->FaceMaterialIndices[i]]; + for (i = 0; i != mesh->Buffers.size(); ++i) + mesh->Buffers[i]->Indices.reallocate(vCountArray[i]); + delete[] vCountArray; + // create indices per buffer + for (i = 0; i < mesh->FaceMaterialIndices.size(); ++i) { + scene::SSkinMeshBuffer *buffer = mesh->Buffers[mesh->FaceMaterialIndices[i]]; + for (u32 id = i * 3 + 0; id != i * 3 + 3; ++id) { + buffer->Indices.push_back(verticesLinkIndex[mesh->Indices[id]]); + } + } + } + + for (u32 j = 0; j < mesh->WeightJoint.size(); ++j) { + ISkinnedMesh::SWeight &weight = (AnimatedMesh->getAllJoints()[mesh->WeightJoint[j]]->Weights[mesh->WeightNum[j]]); + + u32 id = weight.vertex_id; + + if (id >= verticesLinkIndex.size()) { + os::Printer::log("X loader: Weight id out of range", ELL_WARNING); + id = 0; + weight.strength = 0.f; + } + + weight.vertex_id = verticesLinkIndex[id]; + weight.buffer_id = verticesLinkBuffer[id] + bufferOffset; + } + } +#endif + } + + return true; +} + +//! Reads file into memory +bool CXMeshFileLoader::readFileIntoMemory(io::IReadFile *file) +{ + const long size = file->getSize(); + if (size < 12) { + os::Printer::log("X File is too small.", ELL_WARNING); + return false; + } + + Buffer = new c8[size + 1]; + Buffer[size] = 0x0; // null-terminate + + //! read all into memory + if (file->read(Buffer, size) != static_cast(size)) { + os::Printer::log("Could not read from x file.", ELL_WARNING); + return false; + } + + Line = 1; + End = Buffer + size; + + //! check header "xof " + if (strncmp(Buffer, "xof ", 4) != 0) { + os::Printer::log("Not an x file, wrong header.", ELL_WARNING); + return false; + } + + //! read minor and major version, e.g. 0302 or 0303 + c8 tmp[3]; + tmp[0] = Buffer[4]; + tmp[1] = Buffer[5]; + tmp[2] = 0x0; + MajorVersion = core::strtoul10(tmp); + + tmp[0] = Buffer[6]; + tmp[1] = Buffer[7]; + MinorVersion = core::strtoul10(tmp); + + //! read format + if (strncmp(&Buffer[8], "txt ", 4) == 0) + BinaryFormat = false; + else if (strncmp(&Buffer[8], "bin ", 4) == 0) + BinaryFormat = true; + else { + os::Printer::log("Only uncompressed x files currently supported.", ELL_WARNING); + return false; + } + BinaryNumCount = 0; + + //! read float size + if (strncmp(&Buffer[12], "0032", 4) == 0) + FloatSize = 4; + else if (strncmp(&Buffer[12], "0064", 4) == 0) + FloatSize = 8; + else { + os::Printer::log("Float size not supported.", ELL_WARNING); + return false; + } + + P = &Buffer[16]; + + readUntilEndOfLine(); + + return true; +} + +//! Parses the file +bool CXMeshFileLoader::parseFile() +{ + while (parseDataObject()) { + // loop + } + + return !ErrorState; +} + +//! Parses the next Data object in the file +bool CXMeshFileLoader::parseDataObject() +{ + core::stringc objectName = getNextToken(); + + if (objectName.size() == 0) + return false; + + // parse specific object +#ifdef _XREADER_DEBUG + os::Printer::log("debug DataObject", objectName.c_str(), ELL_DEBUG); +#endif + + if (objectName == "template") + return parseDataObjectTemplate(); + else if (objectName == "Frame") { + return parseDataObjectFrame(0); + } else if (objectName == "Mesh") { + // some meshes have no frames at all + // CurFrame = AnimatedMesh->addJoint(0); + + SXMesh *mesh = new SXMesh; + + // mesh->Buffer=AnimatedMesh->addMeshBuffer(); + Meshes.push_back(mesh); + + return parseDataObjectMesh(*mesh); + } else if (objectName == "AnimationSet") { + return parseDataObjectAnimationSet(); + } else if (objectName == "AnimTicksPerSecond") { + return parseDataObjectAnimationTicksPerSecond(); + } else if (objectName == "Material") { + return parseUnknownDataObject(); + } else if (objectName == "}") { + os::Printer::log("} found in dataObject", ELL_WARNING); + return true; + } + + os::Printer::log("Unknown data object in animation of .x file", objectName.c_str(), ELL_WARNING); + + return parseUnknownDataObject(); +} + +bool CXMeshFileLoader::parseDataObjectTemplate() +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading template", ELL_DEBUG); +#endif + + // parse a template data object. Currently not stored. + core::stringc name; + + if (!readHeadOfDataObject(&name)) { + os::Printer::log("Left delimiter in template data object missing.", + name.c_str(), ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // read GUID + getNextToken(); + + // read and ignore data members + while (true) { + core::stringc s = getNextToken(); + + if (s == "}") + break; + + if (s.size() == 0) + return false; + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectFrame(CSkinnedMesh::SJoint *Parent) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading frame", ELL_DEBUG); +#endif + + // A coordinate frame, or "frame of reference." The Frame template + // is open and can contain any object. The Direct3D extensions (D3DX) + // mesh-loading functions recognize Mesh, FrameTransformMatrix, and + // Frame template instances as child objects when loading a Frame + // instance. + + u32 JointID = 0; + + core::stringc name; + + if (!readHeadOfDataObject(&name)) { + os::Printer::log("No opening brace in Frame found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + CSkinnedMesh::SJoint *joint = 0; + + if (name.size()) { + auto n = AnimatedMesh->getJointNumber(name.c_str()); + if (n.has_value()) { + JointID = *n; + joint = AnimatedMesh->getAllJoints()[JointID]; + } + } + + if (!joint) { +#ifdef _XREADER_DEBUG + os::Printer::log("creating joint ", name.c_str(), ELL_DEBUG); +#endif + joint = AnimatedMesh->addJoint(Parent); + joint->Name = name.c_str(); + JointID = AnimatedMesh->getAllJoints().size() - 1; + } else { +#ifdef _XREADER_DEBUG + os::Printer::log("using joint ", name.c_str(), ELL_DEBUG); +#endif + if (Parent) + Parent->Children.push_back(joint); + } + + // Now inside a frame. + // read tokens until closing brace is reached. + + while (true) { + core::stringc objectName = getNextToken(); + +#ifdef _XREADER_DEBUG + os::Printer::log("debug DataObject in frame:", objectName.c_str(), ELL_DEBUG); +#endif + + if (objectName.size() == 0) { + os::Printer::log("Unexpected ending found in Frame in x file.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } else if (objectName == "}") { + break; // frame finished + } else if (objectName == "Frame") { + + if (!parseDataObjectFrame(joint)) + return false; + } else if (objectName == "FrameTransformMatrix") { + if (!parseDataObjectTransformationMatrix(joint->LocalMatrix)) + return false; + + // joint->LocalAnimatedMatrix + // joint->LocalAnimatedMatrix.makeInverse(); + // joint->LocalMatrix=tmp*joint->LocalAnimatedMatrix; + } else if (objectName == "Mesh") { + /* + frame.Meshes.push_back(SXMesh()); + if (!parseDataObjectMesh(frame.Meshes.getLast())) + return false; + */ + SXMesh *mesh = new SXMesh; + + mesh->AttachedJointID = JointID; + + Meshes.push_back(mesh); + + if (!parseDataObjectMesh(*mesh)) + return false; + } else { + os::Printer::log("Unknown data object in frame in x file", objectName.c_str(), ELL_WARNING); + if (!parseUnknownDataObject()) + return false; + } + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectTransformationMatrix(core::matrix4 &mat) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading Transformation Matrix", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Transformation Matrix found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + readMatrix(mat); + + if (!checkForOneFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Transformation Matrix found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in Transformation Matrix found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectMesh(SXMesh &mesh) +{ + core::stringc name; + + if (!readHeadOfDataObject(&name)) { +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading mesh", ELL_DEBUG); +#endif + os::Printer::log("No opening brace in Mesh found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading mesh", name.c_str(), ELL_DEBUG); +#endif + + // read vertex count + const u32 nVertices = readInt(); + + // read vertices + mesh.Vertices.set_used(nVertices); + for (u32 n = 0; n < nVertices; ++n) { + readVector3(mesh.Vertices[n].Pos); + mesh.Vertices[n].Color = 0xFFFFFFFF; + mesh.Vertices[n].Normal = core::vector3df(0.0f); + } + + if (!checkForTwoFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Mesh Vertex Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + // read faces + const u32 nFaces = readInt(); + + mesh.Indices.set_used(nFaces * 3); + mesh.IndexCountPerFace.set_used(nFaces); + + core::array polygonfaces; + u32 currentIndex = 0; + + for (u32 k = 0; k < nFaces; ++k) { + const u32 fcnt = readInt(); + + if (fcnt != 3) { + if (fcnt < 3) { + os::Printer::log("Invalid face count (<3) found in Mesh x file reader.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // read face indices + polygonfaces.set_used(fcnt); + u32 triangles = (fcnt - 2); + mesh.Indices.set_used(mesh.Indices.size() + ((triangles - 1) * 3)); + mesh.IndexCountPerFace[k] = (u16)(triangles * 3); + + for (u32 f = 0; f < fcnt; ++f) + polygonfaces[f] = readInt(); + + for (u32 jk = 0; jk < triangles; ++jk) { + mesh.Indices[currentIndex++] = polygonfaces[0]; + mesh.Indices[currentIndex++] = polygonfaces[jk + 1]; + mesh.Indices[currentIndex++] = polygonfaces[jk + 2]; + } + + // TODO: change face indices in material list + } else { + mesh.Indices[currentIndex++] = readInt(); + mesh.Indices[currentIndex++] = readInt(); + mesh.Indices[currentIndex++] = readInt(); + mesh.IndexCountPerFace[k] = 3; + } + } + + for (u32 j = 0; j < mesh.Indices.size(); j++) { + if (mesh.Indices[j] >= mesh.Vertices.size()) { + os::Printer::log("Out of range index found in Mesh x file reader.", ELL_WARNING); + SET_ERR_AND_RETURN(); + } + } + + if (!checkForTwoFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Mesh Face Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + // here, other data objects may follow + + while (true) { + core::stringc objectName = getNextToken(); + + if (objectName.size() == 0) { + os::Printer::log("Unexpected ending found in Mesh in x file.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } else if (objectName == "}") { + break; // mesh finished + } + +#ifdef _XREADER_DEBUG + os::Printer::log("debug DataObject in mesh", objectName.c_str(), ELL_DEBUG); +#endif + + if (objectName == "MeshNormals") { + if (!parseDataObjectMeshNormals(mesh)) + return false; + } else if (objectName == "MeshTextureCoords") { + if (!parseDataObjectMeshTextureCoords(mesh)) + return false; + } else if (objectName == "MeshVertexColors") { + if (!parseDataObjectMeshVertexColors(mesh)) + return false; + } else if (objectName == "MeshMaterialList") { + if (!parseDataObjectMeshMaterialList(mesh)) + return false; + } else if (objectName == "VertexDuplicationIndices") { + // we'll ignore vertex duplication indices + // TODO: read them + if (!parseUnknownDataObject()) + return false; + } else if (objectName == "DeclData") { + if (!readHeadOfDataObject()) { + os::Printer::log("No starting brace in DeclData found.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + // arbitrary vertex attributes + // first comes the number of element definitions + // then the vertex element type definitions + // with format type;tesselator;semantics;usageindex + // we want to support 2;0;6;0 == tangent + // 2;0;7;0 == binormal + // 2;0;3;0 == normal + // 1/2;0;5;0 == 1st uv coord + // and 1/2;0;5;1 == 2nd uv coord + // type==2 is 3xf32, type==1 is 2xf32 + u32 j; + const u32 dcnt = readInt(); + u16 size = 0; + s16 normalpos = -1; + s16 uvpos = -1; + s16 uv2pos = -1; + s16 tangentpos = -1; + s16 binormalpos = -1; + s16 normaltype = -1; + s16 uvtype = -1; + s16 uv2type = -1; + s16 tangenttype = -1; + s16 binormaltype = -1; + + (void)tangentpos; // disable unused variable warnings + (void)binormalpos; // disable unused variable warnings + (void)tangenttype; // disable unused variable warnings + (void)binormaltype; // disable unused variable warnings + + for (j = 0; j < dcnt; ++j) { + const u32 type = readInt(); + // const u32 tesselator = readInt(); + readInt(); + const u32 semantics = readInt(); + const u32 index = readInt(); + switch (semantics) { + case 3: + normalpos = size; + normaltype = type; + break; + case 5: + if (index == 0) { + uvpos = size; + uvtype = type; + } else if (index == 1) { + uv2pos = size; + uv2type = type; + } + break; + case 6: + tangentpos = size; + tangenttype = type; + break; + case 7: + binormalpos = size; + binormaltype = type; + break; + default: + break; + } + switch (type) { + case 0: + size += 4; + break; + case 1: + size += 8; + break; + case 2: + size += 12; + break; + case 3: + size += 16; + break; + case 4: + case 5: + case 6: + size += 4; + break; + case 7: + size += 8; + break; + case 8: + case 9: + size += 4; + break; + case 10: + size += 8; + break; + case 11: + size += 4; + break; + case 12: + size += 8; + break; + case 13: + size += 4; + break; + case 14: + size += 4; + break; + case 15: + size += 4; + break; + case 16: + size += 8; + break; + } + } + const u32 datasize = readInt(); + u32 *data = new u32[datasize]; + for (j = 0; j < datasize; ++j) + data[j] = readInt(); + + if (!checkForOneFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in DeclData found.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in DeclData.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + delete[] data; + SET_ERR_AND_RETURN(); + } + u8 *dataptr = (u8 *)data; + if ((uv2pos != -1) && (uv2type == 1)) + mesh.TCoords2.reallocate(mesh.Vertices.size()); + for (j = 0; j < mesh.Vertices.size(); ++j) { + if ((normalpos != -1) && (normaltype == 2)) + mesh.Vertices[j].Normal.set(*((core::vector3df *)(dataptr + normalpos))); + if ((uvpos != -1) && (uvtype == 1)) + mesh.Vertices[j].TCoords.set(*((core::vector2df *)(dataptr + uvpos))); + if ((uv2pos != -1) && (uv2type == 1)) + mesh.TCoords2.push_back(*((core::vector2df *)(dataptr + uv2pos))); + dataptr += size; + } + delete[] data; + } else if (objectName == "FVFData") { + if (!readHeadOfDataObject()) { + os::Printer::log("No starting brace in FVFData found.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + const u32 dataformat = readInt(); + const u32 datasize = readInt(); + u32 *data = new u32[datasize]; + for (u32 j = 0; j < datasize; ++j) + data[j] = readInt(); + if (dataformat & 0x102) { // 2nd uv set + mesh.TCoords2.reallocate(mesh.Vertices.size()); + u8 *dataptr = (u8 *)data; + const u32 size = ((dataformat >> 8) & 0xf) * sizeof(core::vector2df); + for (u32 j = 0; j < mesh.Vertices.size(); ++j) { + mesh.TCoords2.push_back(*((core::vector2df *)(dataptr))); + dataptr += size; + } + } + delete[] data; + if (!checkForOneFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in FVFData found.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in FVFData found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + } else if (objectName == "XSkinMeshHeader") { + if (!parseDataObjectSkinMeshHeader(mesh)) + return false; + } else if (objectName == "SkinWeights") { + // mesh.SkinWeights.push_back(SXSkinWeight()); + // if (!parseDataObjectSkinWeights(mesh.SkinWeights.getLast())) + if (!parseDataObjectSkinWeights(mesh)) + return false; + } else { + os::Printer::log("Unknown data object in mesh in x file", objectName.c_str(), ELL_WARNING); + if (!parseUnknownDataObject()) + return false; + } + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading mesh skin weights", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Skin Weights found in .x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + core::stringc TransformNodeName; + + if (!getNextTokenAsString(TransformNodeName)) { + os::Printer::log("Unknown syntax while reading transform node name string in .x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + mesh.HasSkinning = true; + + auto n = AnimatedMesh->getJointNumber(TransformNodeName.c_str()); + CSkinnedMesh::SJoint *joint = n.has_value() ? AnimatedMesh->getAllJoints()[*n] : nullptr; + + if (!joint) { +#ifdef _XREADER_DEBUG + os::Printer::log("creating joint for skinning ", TransformNodeName.c_str(), ELL_DEBUG); +#endif + n = AnimatedMesh->getAllJoints().size(); + joint = AnimatedMesh->addJoint(0); + joint->Name = TransformNodeName.c_str(); + } + + // read vertex weights + const u32 nWeights = readInt(); + + // read vertex indices + u32 i; + + const u32 jointStart = joint->Weights.size(); + joint->Weights.reallocate(jointStart + nWeights); + + mesh.WeightJoint.reallocate(mesh.WeightJoint.size() + nWeights); + mesh.WeightNum.reallocate(mesh.WeightNum.size() + nWeights); + + for (i = 0; i < nWeights; ++i) { + mesh.WeightJoint.push_back(*n); + mesh.WeightNum.push_back(joint->Weights.size()); + + CSkinnedMesh::SWeight *weight = AnimatedMesh->addWeight(joint); + + weight->buffer_id = 0; + weight->vertex_id = readInt(); + } + + // read vertex weights + + for (i = jointStart; i < jointStart + nWeights; ++i) + joint->Weights[i].strength = readFloat(); + + // read matrix offset + + // transforms the mesh vertices to the space of the bone + // When concatenated to the bone's transform, this provides the + // world space coordinates of the mesh as affected by the bone + core::matrix4 &MatrixOffset = joint->GlobalInversedMatrix; + + readMatrix(MatrixOffset); + + if (!checkForOneFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Skin Weights found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in Skin Weights found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectSkinMeshHeader(SXMesh &mesh) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading skin mesh header", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Skin Mesh header found in .x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + mesh.MaxSkinWeightsPerVertex = readInt(); + mesh.MaxSkinWeightsPerFace = readInt(); + mesh.BoneCount = readInt(); + + if (!BinaryFormat) + getNextToken(); // skip semicolon + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in skin mesh header in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectMeshNormals(SXMesh &mesh) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: reading mesh normals", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Mesh Normals found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // read count + const u32 nNormals = readInt(); + core::array normals; + normals.set_used(nNormals); + + // read normals + for (u32 i = 0; i < nNormals; ++i) + readVector3(normals[i]); + + if (!checkForTwoFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Mesh Normals Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + core::array normalIndices; + normalIndices.set_used(mesh.Indices.size()); + + // read face normal indices + const u32 nFNormals = readInt(); + // if (nFNormals >= mesh.IndexCountPerFace.size()) + if (0) { // this condition doesn't work for some reason + os::Printer::log("Too many face normals found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + u32 normalidx = 0; + core::array polygonfaces; + for (u32 k = 0; k < nFNormals; ++k) { + const u32 fcnt = readInt(); + u32 triangles = fcnt - 2; + u32 indexcount = triangles * 3; + + if (indexcount != mesh.IndexCountPerFace[k]) { + os::Printer::log("Not matching normal and face index count found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + if (indexcount == 3) { + // default, only one triangle in this face + for (u32 h = 0; h < 3; ++h) { + const u32 normalnum = readInt(); + mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[normalnum]); + } + } else { + polygonfaces.set_used(fcnt); + // multiple triangles in this face + for (u32 h = 0; h < fcnt; ++h) + polygonfaces[h] = readInt(); + + for (u32 jk = 0; jk < triangles; ++jk) { + mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[0]]); + mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 1]]); + mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 2]]); + } + } + } + + if (!checkForTwoFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Mesh Face Normals Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in Mesh Normals found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectMeshTextureCoords(SXMesh &mesh) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: reading mesh texture coordinates", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Mesh Texture Coordinates found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + const u32 nCoords = readInt(); + // if (nCoords >= mesh.Vertices.size()) + if (0) { // this condition doesn't work for some reason + os::Printer::log("Too many texture coords found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + for (u32 i = 0; i < nCoords; ++i) + readVector2(mesh.Vertices[i].TCoords); + + if (!checkForTwoFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Mesh Texture Coordinates Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in Mesh Texture Coordinates Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectMeshVertexColors(SXMesh &mesh) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: reading mesh vertex colors", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace for Mesh Vertex Colors found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + mesh.HasVertexColors = true; + const u32 nColors = readInt(); + for (u32 i = 0; i < nColors; ++i) { + const u32 Index = readInt(); + if (Index >= mesh.Vertices.size()) { + os::Printer::log("index value in parseDataObjectMeshVertexColors out of bounds", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + readRGBA(mesh.Vertices[Index].Color); + checkForOneFollowingSemicolons(); + } + + if (!checkForOneFollowingSemicolons()) { + os::Printer::log("No finishing semicolon in Mesh Vertex Colors Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in Mesh Texture Coordinates Array found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + return false; + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectMeshMaterialList(SXMesh &mesh) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading mesh material list", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Mesh Material List found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // read material count + const u32 nMaterials = readInt(); + mesh.Materials.reallocate(nMaterials); + + // read non triangulated face material index count + const u32 nFaceIndices = readInt(); + + // There seems to be a compact representation of "all faces the same material" + // being represented as 1;1;0;; which means 1 material, 1 face with first material + // all the other faces have to obey then, so check is disabled + // if (nFaceIndices != mesh.IndexCountPerFace.size()) + // os::Printer::log("Index count per face not equal to face material index count in x file.", ELL_WARNING); + + // read non triangulated face indices and create triangulated ones + mesh.FaceMaterialIndices.set_used(mesh.Indices.size() / 3); + u32 triangulatedindex = 0; + u32 ind = 0; + for (u32 tfi = 0; tfi < mesh.IndexCountPerFace.size(); ++tfi) { + if (tfi < nFaceIndices) + ind = readInt(); + if (ind >= core::max_(nMaterials, 1U)) { + os::Printer::log("Out of range index found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + const u32 fc = mesh.IndexCountPerFace[tfi] / 3; + for (u32 k = 0; k < fc; ++k) + mesh.FaceMaterialIndices[triangulatedindex++] = ind; + } + + // in version 03.02, the face indices end with two semicolons. + // commented out version check, as version 03.03 exported from blender also has 2 semicolons + if (!BinaryFormat) { // && MajorVersion == 3 && MinorVersion <= 2) + if (P[0] == ';') + ++P; + } + + // read following data objects + + while (true) { + core::stringc objectName = getNextToken(); + + if (objectName.size() == 0) { + os::Printer::log("Unexpected ending found in Mesh Material list in .x file.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } else if (objectName == "}") { + break; // material list finished + } else if (objectName == "{") { + // template materials now available thanks to joeWright + objectName = getNextToken(); + mesh.Materials.push_back(video::SMaterial()); + getNextToken(); // skip } + } else if (objectName == "Material") { + mesh.Materials.push_back(video::SMaterial()); + if (!parseUnknownDataObject()) + return false; + } else if (objectName == ";") { + // ignore + } else { + os::Printer::log("Unknown data object in material list in x file", objectName.c_str(), ELL_WARNING); + if (!parseUnknownDataObject()) + return false; + } + } + return true; +} + +bool CXMeshFileLoader::parseDataObjectAnimationSet() +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: Reading animation set", ELL_DEBUG); +#endif + + core::stringc AnimationName; + + if (!readHeadOfDataObject(&AnimationName)) { + os::Printer::log("No opening brace in Animation Set found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + os::Printer::log("Reading animationset ", AnimationName, ELL_DEBUG); + + while (true) { + core::stringc objectName = getNextToken(); + + if (objectName.size() == 0) { + os::Printer::log("Unexpected ending found in Animation set in x file.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } else if (objectName == "}") { + break; // animation set finished + } else if (objectName == "Animation") { + if (!parseDataObjectAnimation()) + return false; + } else { + os::Printer::log("Unknown data object in animation set in x file", objectName.c_str(), ELL_WARNING); + if (!parseUnknownDataObject()) + return false; + } + } + return true; +} + +bool CXMeshFileLoader::parseDataObjectAnimationTicksPerSecond() +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: reading AnimationTicksPerSecond", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Animation found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + const u32 ticks = readInt(); + + if (!checkForOneFollowingSemicolons()) { + os::Printer::log("No closing semicolon in AnimationTicksPerSecond in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in AnimationTicksPerSecond in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + AnimatedMesh->setAnimationSpeed(static_cast(ticks)); + + return true; +} + +bool CXMeshFileLoader::parseDataObjectAnimation() +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: reading animation", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Animation found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // anim.closed = true; + // anim.linearPositionQuality = true; + CSkinnedMesh::SJoint animationDump; + + core::stringc FrameName; + + while (true) { + core::stringc objectName = getNextToken(); + + if (objectName.size() == 0) { + os::Printer::log("Unexpected ending found in Animation in x file.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } else if (objectName == "}") { + break; // animation finished + } else if (objectName == "AnimationKey") { + if (!parseDataObjectAnimationKey(&animationDump)) + return false; + } else if (objectName == "AnimationOptions") { + // TODO: parse options. + if (!parseUnknownDataObject()) + return false; + } else if (objectName == "{") { + // read frame name + FrameName = getNextToken(); + + if (!checkForClosingBrace()) { + os::Printer::log("Unexpected ending found in Animation in x file.", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + } else { + os::Printer::log("Unknown data object in animation in x file", objectName.c_str(), ELL_WARNING); + if (!parseUnknownDataObject()) + SET_ERR_AND_RETURN(); + } + } + + if (FrameName.size() != 0) { +#ifdef _XREADER_DEBUG + os::Printer::log("frame name", FrameName.c_str(), ELL_DEBUG); +#endif + auto n = AnimatedMesh->getJointNumber(FrameName.c_str()); + + CSkinnedMesh::SJoint *joint; + if (n.has_value()) { + joint = AnimatedMesh->getAllJoints()[*n]; + } else { +#ifdef _XREADER_DEBUG + os::Printer::log("creating joint for animation ", FrameName.c_str(), ELL_DEBUG); +#endif + joint = AnimatedMesh->addJoint(0); + joint->Name = FrameName.c_str(); + } + + joint->PositionKeys.reallocate(joint->PositionKeys.size() + animationDump.PositionKeys.size()); + for (u32 n = 0; n < animationDump.PositionKeys.size(); ++n) { + joint->PositionKeys.push_back(animationDump.PositionKeys[n]); + } + + joint->ScaleKeys.reallocate(joint->ScaleKeys.size() + animationDump.ScaleKeys.size()); + for (u32 n = 0; n < animationDump.ScaleKeys.size(); ++n) { + joint->ScaleKeys.push_back(animationDump.ScaleKeys[n]); + } + + joint->RotationKeys.reallocate(joint->RotationKeys.size() + animationDump.RotationKeys.size()); + for (u32 n = 0; n < animationDump.RotationKeys.size(); ++n) { + joint->RotationKeys.push_back(animationDump.RotationKeys[n]); + } + } else + os::Printer::log("joint name was never given", ELL_WARNING); + + return true; +} + +bool CXMeshFileLoader::parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: reading animation key", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Animation Key found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // read key type + + const u32 keyType = readInt(); + + if (keyType > 4) { + os::Printer::log("Unknown key type found in Animation Key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // read number of keys + const u32 numberOfKeys = readInt(); + + // eat the semicolon after the "0". if there are keys present, readInt() + // does this for us. If there aren't, we need to do it explicitly + if (numberOfKeys == 0) + checkForOneFollowingSemicolons(); + + for (u32 i = 0; i < numberOfKeys; ++i) { + // read time + const f32 time = (f32)readInt(); + + // read keys + switch (keyType) { + case 0: // rotation + { + // read quaternions + + // read count + if (readInt() != 4) { + os::Printer::log("Expected 4 numbers in animation key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + f32 W = -readFloat(); + f32 X = -readFloat(); + f32 Y = -readFloat(); + f32 Z = -readFloat(); + + if (!checkForTwoFollowingSemicolons()) { + os::Printer::log("No finishing semicolon after quaternion animation key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + ISkinnedMesh::SRotationKey *key = AnimatedMesh->addRotationKey(joint); + key->frame = time; + key->rotation.set(X, Y, Z, W); + key->rotation.normalize(); + } break; + case 1: // scale + case 2: // position + { + // read vectors + + // read count + if (readInt() != 3) { + os::Printer::log("Expected 3 numbers in animation key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + core::vector3df vector; + readVector3(vector); + + if (!checkForTwoFollowingSemicolons()) { + os::Printer::log("No finishing semicolon after vector animation key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + if (keyType == 2) { + ISkinnedMesh::SPositionKey *key = AnimatedMesh->addPositionKey(joint); + key->frame = time; + key->position = vector; + } else { + ISkinnedMesh::SScaleKey *key = AnimatedMesh->addScaleKey(joint); + key->frame = time; + key->scale = vector; + } + } break; + case 3: + case 4: { + // read matrix + + // read count + if (readInt() != 16) { + os::Printer::log("Expected 16 numbers in animation key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + // read matrix + core::matrix4 mat(core::matrix4::EM4CONST_NOTHING); + readMatrix(mat); + + // mat=joint->LocalMatrix*mat; + + if (!checkForOneFollowingSemicolons()) { + os::Printer::log("No finishing semicolon after matrix animation key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + } + + // core::vector3df rotation = mat.getRotationDegrees(); + + ISkinnedMesh::SRotationKey *keyR = AnimatedMesh->addRotationKey(joint); + keyR->frame = time; + + // IRR_TEST_BROKEN_QUATERNION_USE: TODO - switched from mat to mat.getTransposed() for downward compatibility. + // Not tested so far if this was correct or wrong before quaternion fix! + keyR->rotation = core::quaternion(mat.getTransposed()); + + ISkinnedMesh::SPositionKey *keyP = AnimatedMesh->addPositionKey(joint); + keyP->frame = time; + keyP->position = mat.getTranslation(); + + /* + core::vector3df scale=mat.getScale(); + + if (scale.X==0) + scale.X=1; + if (scale.Y==0) + scale.Y=1; + if (scale.Z==0) + scale.Z=1; + ISkinnedMesh::SScaleKey *keyS=AnimatedMesh->addScaleKey(joint); + keyS->frame=time; + keyS->scale=scale; + */ + } break; + } // end switch + } + + if (!checkForOneFollowingSemicolons()) + --P; + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in animation key in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + return true; +} + +bool CXMeshFileLoader::parseDataObjectTextureFilename(core::stringc &texturename) +{ +#ifdef _XREADER_DEBUG + os::Printer::log("CXFileReader: reading texture filename", ELL_DEBUG); +#endif + + if (!readHeadOfDataObject()) { + os::Printer::log("No opening brace in Texture filename found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + if (!getNextTokenAsString(texturename)) { + os::Printer::log("Unknown syntax while reading texture filename string in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + if (!checkForClosingBrace()) { + os::Printer::log("No closing brace in Texture filename found in x file", ELL_WARNING); + os::Printer::log("Line", core::stringc(Line).c_str(), ELL_WARNING); + SET_ERR_AND_RETURN(); + } + + return true; +} + +bool CXMeshFileLoader::parseUnknownDataObject() +{ + // find opening delimiter + while (true) { + core::stringc t = getNextToken(); + + if (t.size() == 0) + return false; + + if (t == "{") + break; + } + + u32 counter = 1; + + // parse until closing delimiter + + while (counter) { + core::stringc t = getNextToken(); + + if (t.size() == 0) + return false; + + if (t == "{") + ++counter; + else if (t == "}") + --counter; + } + + return true; +} + +//! checks for closing curly brace, returns false if not there +bool CXMeshFileLoader::checkForClosingBrace() +{ + return (getNextToken() == "}"); +} + +//! checks for one following semicolon, returns false if not there +bool CXMeshFileLoader::checkForOneFollowingSemicolons() +{ + if (BinaryFormat) + return true; + + if (getNextToken() == ";") + return true; + else { + --P; + return false; + } +} + +//! checks for two following semicolons, returns false if they are not there +bool CXMeshFileLoader::checkForTwoFollowingSemicolons() +{ + if (BinaryFormat) + return true; + + for (u32 k = 0; k < 2; ++k) { + if (getNextToken() != ";") { + --P; + return false; + } + } + + return true; +} + +//! reads header of dataobject including the opening brace. +//! returns false if error happened, and writes name of object +//! if there is one +bool CXMeshFileLoader::readHeadOfDataObject(core::stringc *outname) +{ + core::stringc nameOrBrace = getNextToken(); + if (nameOrBrace != "{") { + if (outname) + (*outname) = nameOrBrace; + + if (getNextToken() != "{") + return false; + } + + return true; +} + +//! returns next parseable token. Returns empty string if no token there +core::stringc CXMeshFileLoader::getNextToken() +{ + core::stringc s; + + // process binary-formatted file + if (BinaryFormat) { + // in binary mode it will only return NAME and STRING token + // and (correctly) skip over other tokens. + + s16 tok = readBinWord(); + u32 len; + + // standalone tokens + switch (tok) { + case 1: + // name token + len = readBinDWord(); + s = core::stringc(P, len); + P += len; + return s; + case 2: + // string token + len = readBinDWord(); + s = core::stringc(P, len); + P += (len + 2); + return s; + case 3: + // integer token + P += 4; + return ""; + case 5: + // GUID token + P += 16; + return ""; + case 6: + len = readBinDWord(); + P += (len * 4); + return ""; + case 7: + len = readBinDWord(); + P += (len * FloatSize); + return ""; + case 0x0a: + return "{"; + case 0x0b: + return "}"; + case 0x0c: + return "("; + case 0x0d: + return ")"; + case 0x0e: + return "["; + case 0x0f: + return "]"; + case 0x10: + return "<"; + case 0x11: + return ">"; + case 0x12: + return "."; + case 0x13: + return ","; + case 0x14: + return ";"; + case 0x1f: + return "template"; + case 0x28: + return "WORD"; + case 0x29: + return "DWORD"; + case 0x2a: + return "FLOAT"; + case 0x2b: + return "DOUBLE"; + case 0x2c: + return "CHAR"; + case 0x2d: + return "UCHAR"; + case 0x2e: + return "SWORD"; + case 0x2f: + return "SDWORD"; + case 0x30: + return "void"; + case 0x31: + return "string"; + case 0x32: + return "unicode"; + case 0x33: + return "cstring"; + case 0x34: + return "array"; + } + } + // process text-formatted file + else { + findNextNoneWhiteSpace(); + + if (P >= End) + return s; + + while ((P < End) && !core::isspace(P[0])) { + // either keep token delimiters when already holding a token, or return if first valid char + if (P[0] == ';' || P[0] == '}' || P[0] == '{' || P[0] == ',') { + if (!s.size()) { + s.append(P[0]); + ++P; + } + break; // stop for delimiter + } + s.append(P[0]); + ++P; + } + } + return s; +} + +//! places pointer to next begin of a token, which must be a number, +// and ignores comments +void CXMeshFileLoader::findNextNoneWhiteSpaceNumber() +{ + if (BinaryFormat) + return; + + while ((P < End) && (P[0] != '-') && (P[0] != '.') && + !(core::isdigit(P[0]))) { + // check if this is a comment + if ((P[0] == '/' && P[1] == '/') || P[0] == '#') + readUntilEndOfLine(); + else + ++P; + } +} + +// places pointer to next begin of a token, and ignores comments +void CXMeshFileLoader::findNextNoneWhiteSpace() +{ + if (BinaryFormat) + return; + + while (true) { + while ((P < End) && core::isspace(P[0])) { + if (*P == '\n') + ++Line; + ++P; + } + + if (P >= End) + return; + + // check if this is a comment + if ((P[0] == '/' && P[1] == '/') || + P[0] == '#') + readUntilEndOfLine(); + else + break; + } +} + +//! reads a x file style string +bool CXMeshFileLoader::getNextTokenAsString(core::stringc &out) +{ + if (BinaryFormat) { + out = getNextToken(); + return true; + } + findNextNoneWhiteSpace(); + + if (P >= End) + return false; + + if (P[0] != '"') + return false; + ++P; + + while (P < End && P[0] != '"') { + out.append(P[0]); + ++P; + } + + if (P[1] != ';' || P[0] != '"') + return false; + P += 2; + + return true; +} + +void CXMeshFileLoader::readUntilEndOfLine() +{ + if (BinaryFormat) + return; + + while (P < End) { + if (P[0] == '\n' || P[0] == '\r') { + ++P; + ++Line; + return; + } + + ++P; + } +} + +u16 CXMeshFileLoader::readBinWord() +{ + if (P >= End) + return 0; +#ifdef __BIG_ENDIAN__ + const u16 tmp = os::Byteswap::byteswap(*(u16 *)P); +#else + const u16 tmp = *(u16 *)P; +#endif + P += 2; + return tmp; +} + +u32 CXMeshFileLoader::readBinDWord() +{ + if (P >= End) + return 0; +#ifdef __BIG_ENDIAN__ + const u32 tmp = os::Byteswap::byteswap(*(u32 *)P); +#else + const u32 tmp = *(u32 *)P; +#endif + P += 4; + return tmp; +} + +u32 CXMeshFileLoader::readInt() +{ + if (BinaryFormat) { + if (!BinaryNumCount) { + const u16 tmp = readBinWord(); // 0x06 or 0x03 + if (tmp == 0x06) + BinaryNumCount = readBinDWord(); + else + BinaryNumCount = 1; // single int + } + --BinaryNumCount; + return readBinDWord(); + } else { + findNextNoneWhiteSpaceNumber(); + return core::strtoul10(P, &P); + } +} + +f32 CXMeshFileLoader::readFloat() +{ + if (BinaryFormat) { + if (!BinaryNumCount) { + const u16 tmp = readBinWord(); // 0x07 or 0x42 + if (tmp == 0x07) + BinaryNumCount = readBinDWord(); + else + BinaryNumCount = 1; // single int + } + --BinaryNumCount; + if (FloatSize == 8) { +#ifdef __BIG_ENDIAN__ + // TODO: Check if data is properly converted here + f32 ctmp[2]; + ctmp[1] = os::Byteswap::byteswap(*(f32 *)P); + ctmp[0] = os::Byteswap::byteswap(*(f32 *)P + 4); + const f32 tmp = (f32)(*(f64 *)(void *)ctmp); +#else + const f32 tmp = (f32)(*(f64 *)P); +#endif + P += 8; + return tmp; + } else { +#ifdef __BIG_ENDIAN__ + const f32 tmp = os::Byteswap::byteswap(*(f32 *)P); +#else + const f32 tmp = *(f32 *)P; +#endif + P += 4; + return tmp; + } + } + findNextNoneWhiteSpaceNumber(); + f32 ftmp; + P = core::fast_atof_move(P, ftmp); + return ftmp; +} + +// read 2-dimensional vector. Stops at semicolon after second value for text file format +bool CXMeshFileLoader::readVector2(core::vector2df &vec) +{ + vec.X = readFloat(); + vec.Y = readFloat(); + return true; +} + +// read 3-dimensional vector. Stops at semicolon after third value for text file format +bool CXMeshFileLoader::readVector3(core::vector3df &vec) +{ + vec.X = readFloat(); + vec.Y = readFloat(); + vec.Z = readFloat(); + return true; +} + +// read color without alpha value. Stops after second semicolon after blue value +bool CXMeshFileLoader::readRGB(video::SColor &color) +{ + video::SColorf tmpColor; + tmpColor.r = readFloat(); + tmpColor.g = readFloat(); + tmpColor.b = readFloat(); + color = tmpColor.toSColor(); + return checkForOneFollowingSemicolons(); +} + +// read color with alpha value. Stops after second semicolon after blue value +bool CXMeshFileLoader::readRGBA(video::SColor &color) +{ + video::SColorf tmpColor; + tmpColor.r = readFloat(); + tmpColor.g = readFloat(); + tmpColor.b = readFloat(); + tmpColor.a = readFloat(); + color = tmpColor.toSColor(); + return checkForOneFollowingSemicolons(); +} + +// read matrix from list of floats +bool CXMeshFileLoader::readMatrix(core::matrix4 &mat) +{ + for (u32 i = 0; i < 16; ++i) + mat[i] = readFloat(); + return checkForOneFollowingSemicolons(); +} + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CXMeshFileLoader.h b/irr/src/CXMeshFileLoader.h new file mode 100644 index 000000000..711806270 --- /dev/null +++ b/irr/src/CXMeshFileLoader.h @@ -0,0 +1,181 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IMeshLoader.h" +#include "irrString.h" +#include "CSkinnedMesh.h" + +namespace irr +{ +namespace io +{ +class IReadFile; +} // end namespace io +namespace scene +{ +class IMeshManipulator; + +//! Meshloader capable of loading x meshes. +class CXMeshFileLoader : public IMeshLoader +{ +public: + //! Constructor + CXMeshFileLoader(scene::ISceneManager *smgr); + + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".cob") + bool isALoadableFileExtension(const io::path &filename) const override; + + //! creates/loads an animated mesh from the file. + //! \return Pointer to the created mesh. Returns 0 if loading failed. + //! If you no longer need the mesh, you should call IAnimatedMesh::drop(). + //! See IReferenceCounted::drop() for more information. + IAnimatedMesh *createMesh(io::IReadFile *file) override; + + struct SXMesh + { + SXMesh() : + MaxSkinWeightsPerVertex(0), MaxSkinWeightsPerFace(0), BoneCount(0), AttachedJointID(-1), HasSkinning(false), HasVertexColors(false) {} + // this mesh contains triangulated texture data. + // because in an .x file, faces can be made of more than 3 + // vertices, the indices data structure is triangulated during the + // loading process. The IndexCountPerFace array is filled during + // this triangulation process and stores how much indices belong to + // every face. This data structure can be ignored, because all data + // in this structure is triangulated. + + core::stringc Name; + + u32 MaxSkinWeightsPerVertex; + u32 MaxSkinWeightsPerFace; + u32 BoneCount; + + core::array IndexCountPerFace; // default 3, but could be more + + core::array Buffers; + + core::array Vertices; + core::array TCoords2; + + core::array Indices; + + core::array FaceMaterialIndices; // index of material for each face + + core::array Materials; // material array + + core::array WeightJoint; + core::array WeightNum; + + s32 AttachedJointID; + + bool HasSkinning; + bool HasVertexColors; + }; + +private: + bool load(io::IReadFile *file); + + bool readFileIntoMemory(io::IReadFile *file); + + bool parseFile(); + + bool parseDataObject(); + + bool parseDataObjectTemplate(); + + bool parseDataObjectFrame(CSkinnedMesh::SJoint *parent); + + bool parseDataObjectTransformationMatrix(core::matrix4 &mat); + + bool parseDataObjectMesh(SXMesh &mesh); + + bool parseDataObjectSkinWeights(SXMesh &mesh); + + bool parseDataObjectSkinMeshHeader(SXMesh &mesh); + + bool parseDataObjectMeshNormals(SXMesh &mesh); + + bool parseDataObjectMeshTextureCoords(SXMesh &mesh); + + bool parseDataObjectMeshVertexColors(SXMesh &mesh); + + bool parseDataObjectMeshMaterialList(SXMesh &mesh); + + bool parseDataObjectAnimationSet(); + + bool parseDataObjectAnimationTicksPerSecond(); + + bool parseDataObjectAnimation(); + + bool parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint); + + bool parseDataObjectTextureFilename(core::stringc &texturename); + + bool parseUnknownDataObject(); + + //! places pointer to next begin of a token, and ignores comments + void findNextNoneWhiteSpace(); + + //! places pointer to next begin of a token, which must be a number, + // and ignores comments + void findNextNoneWhiteSpaceNumber(); + + //! returns next parseable token. Returns empty string if no token there + core::stringc getNextToken(); + + //! reads header of dataobject including the opening brace. + //! returns false if error happened, and writes name of object + //! if there is one + bool readHeadOfDataObject(core::stringc *outname = 0); + + //! checks for closing curly brace, returns false if not there + bool checkForClosingBrace(); + + //! checks for one following semicolons, returns false if not there + bool checkForOneFollowingSemicolons(); + + //! checks for two following semicolons, returns false if they are not there + bool checkForTwoFollowingSemicolons(); + + //! reads a x file style string + bool getNextTokenAsString(core::stringc &out); + + void readUntilEndOfLine(); + + u16 readBinWord(); + u32 readBinDWord(); + u32 readInt(); + f32 readFloat(); + bool readVector2(core::vector2df &vec); + bool readVector3(core::vector3df &vec); + bool readMatrix(core::matrix4 &mat); + bool readRGB(video::SColor &color); + bool readRGBA(video::SColor &color); + + CSkinnedMesh *AnimatedMesh; + + c8 *Buffer; + const c8 *P; + c8 *End; + // counter for number arrays in binary format + u32 BinaryNumCount; + u32 Line; + io::path FilePath; + + bool ErrorState; + + CSkinnedMesh::SJoint *CurFrame; + + core::array Meshes; + + u32 MajorVersion; + u32 MinorVersion; + bool BinaryFormat; + c8 FloatSize; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/CZipReader.cpp b/irr/src/CZipReader.cpp new file mode 100644 index 000000000..b761c72e8 --- /dev/null +++ b/irr/src/CZipReader.cpp @@ -0,0 +1,519 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CZipReader.h" + +#include "os.h" + +#include "CFileList.h" +#include "CReadFile.h" +#include "coreutil.h" + +#include // use system lib + +namespace irr +{ +namespace io +{ + +// ----------------------------------------------------------------------------- +// zip loader +// ----------------------------------------------------------------------------- + +//! Constructor +CArchiveLoaderZIP::CArchiveLoaderZIP(io::IFileSystem *fs) : + FileSystem(fs) +{ +#ifdef _DEBUG + setDebugName("CArchiveLoaderZIP"); +#endif +} + +//! returns true if the file maybe is able to be loaded by this class +bool CArchiveLoaderZIP::isALoadableFileFormat(const io::path &filename) const +{ + return core::hasFileExtension(filename, "zip", "pk3") || + core::hasFileExtension(filename, "gz", "tgz"); +} + +//! Check to see if the loader can create archives of this type. +bool CArchiveLoaderZIP::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const +{ + return (fileType == EFAT_ZIP || fileType == EFAT_GZIP); +} + +//! Creates an archive from the filename +/** \param file File handle to check. +\return Pointer to newly created archive, or 0 upon error. */ +IFileArchive *CArchiveLoaderZIP::createArchive(const io::path &filename, bool ignoreCase, bool ignorePaths) const +{ + IFileArchive *archive = 0; + io::IReadFile *file = FileSystem->createAndOpenFile(filename); + + if (file) { + archive = createArchive(file, ignoreCase, ignorePaths); + file->drop(); + } + + return archive; +} + +//! creates/loads an archive from the file. +//! \return Pointer to the created archive. Returns 0 if loading failed. +IFileArchive *CArchiveLoaderZIP::createArchive(io::IReadFile *file, bool ignoreCase, bool ignorePaths) const +{ + IFileArchive *archive = 0; + if (file) { + file->seek(0); + + u16 sig; + file->read(&sig, 2); + +#ifdef __BIG_ENDIAN__ + sig = os::Byteswap::byteswap(sig); +#endif + + file->seek(0); + + bool isGZip = (sig == 0x8b1f); + + archive = new CZipReader(FileSystem, file, ignoreCase, ignorePaths, isGZip); + } + return archive; +} + +//! Check if the file might be loaded by this class +/** Check might look into the file. +\param file File handle to check. +\return True if file seems to be loadable. */ +bool CArchiveLoaderZIP::isALoadableFileFormat(io::IReadFile *file) const +{ + SZIPFileHeader header; + + file->read(&header.Sig, 4); +#ifdef __BIG_ENDIAN__ + header.Sig = os::Byteswap::byteswap(header.Sig); +#endif + + return header.Sig == 0x04034b50 || // ZIP + (header.Sig & 0xffff) == 0x8b1f; // gzip +} + +// ----------------------------------------------------------------------------- +// zip archive +// ----------------------------------------------------------------------------- + +CZipReader::CZipReader(IFileSystem *fs, IReadFile *file, bool ignoreCase, bool ignorePaths, bool isGZip) : + CFileList((file ? file->getFileName() : io::path("")), ignoreCase, ignorePaths), FileSystem(fs), File(file), IsGZip(isGZip) +{ +#ifdef _DEBUG + setDebugName("CZipReader"); +#endif + + if (File) { + File->grab(); + + // load file entries + if (IsGZip) + while (scanGZipHeader()) { + } + else + while (scanZipHeader()) { + } + + sort(); + } +} + +CZipReader::~CZipReader() +{ + if (File) + File->drop(); +} + +//! get the archive type +E_FILE_ARCHIVE_TYPE CZipReader::getType() const +{ + return IsGZip ? EFAT_GZIP : EFAT_ZIP; +} + +const IFileList *CZipReader::getFileList() const +{ + return this; +} + +//! scans for a local header, returns false if there is no more local file header. +//! The gzip file format seems to think that there can be multiple files in a gzip file +//! but none +bool CZipReader::scanGZipHeader() +{ + SZipFileEntry entry; + entry.Offset = 0; + memset(&entry.header, 0, sizeof(SZIPFileHeader)); + + // read header + SGZIPMemberHeader header; + if (File->read(&header, sizeof(SGZIPMemberHeader)) == sizeof(SGZIPMemberHeader)) { + +#ifdef __BIG_ENDIAN__ + header.sig = os::Byteswap::byteswap(header.sig); + header.time = os::Byteswap::byteswap(header.time); +#endif + + // check header value + if (header.sig != 0x8b1f) + return false; + + // now get the file info + if (header.flags & EGZF_EXTRA_FIELDS) { + // read lenth of extra data + u16 dataLen; + + File->read(&dataLen, 2); + +#ifdef __BIG_ENDIAN__ + dataLen = os::Byteswap::byteswap(dataLen); +#endif + + // skip it + File->seek(dataLen, true); + } + + io::path ZipFileName = ""; + + if (header.flags & EGZF_FILE_NAME) { + c8 c; + File->read(&c, 1); + while (c) { + ZipFileName.append(c); + File->read(&c, 1); + } + } else { + // no file name? + ZipFileName = Path; + core::deletePathFromFilename(ZipFileName); + + // rename tgz to tar or remove gz extension + if (core::hasFileExtension(ZipFileName, "tgz")) { + ZipFileName[ZipFileName.size() - 2] = 'a'; + ZipFileName[ZipFileName.size() - 1] = 'r'; + } else if (core::hasFileExtension(ZipFileName, "gz")) { + ZipFileName[ZipFileName.size() - 3] = 0; + ZipFileName.validate(); + } + } + + if (header.flags & EGZF_COMMENT) { + c8 c = 'a'; + while (c) + File->read(&c, 1); + } + + if (header.flags & EGZF_CRC16) + File->seek(2, true); + + // we are now at the start of the data blocks + entry.Offset = File->getPos(); + + entry.header.FilenameLength = ZipFileName.size(); + + entry.header.CompressionMethod = header.compressionMethod; + entry.header.DataDescriptor.CompressedSize = (File->getSize() - 8) - File->getPos(); + + // seek to file end + File->seek(entry.header.DataDescriptor.CompressedSize, true); + + // read CRC + File->read(&entry.header.DataDescriptor.CRC32, 4); + // read uncompressed size + File->read(&entry.header.DataDescriptor.UncompressedSize, 4); + +#ifdef __BIG_ENDIAN__ + entry.header.DataDescriptor.CRC32 = os::Byteswap::byteswap(entry.header.DataDescriptor.CRC32); + entry.header.DataDescriptor.UncompressedSize = os::Byteswap::byteswap(entry.header.DataDescriptor.UncompressedSize); +#endif + + // now we've filled all the fields, this is just a standard deflate block + addItem(ZipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, false, 0); + FileInfo.push_back(entry); + } + + // there's only one block of data in a gzip file + return false; +} + +//! scans for a local header, returns false if there is no more local file header. +bool CZipReader::scanZipHeader(bool ignoreGPBits) +{ + io::path ZipFileName = ""; + SZipFileEntry entry; + entry.Offset = 0; + memset(&entry.header, 0, sizeof(SZIPFileHeader)); + + File->read(&entry.header, sizeof(SZIPFileHeader)); + +#ifdef __BIG_ENDIAN__ + entry.header.Sig = os::Byteswap::byteswap(entry.header.Sig); + entry.header.VersionToExtract = os::Byteswap::byteswap(entry.header.VersionToExtract); + entry.header.GeneralBitFlag = os::Byteswap::byteswap(entry.header.GeneralBitFlag); + entry.header.CompressionMethod = os::Byteswap::byteswap(entry.header.CompressionMethod); + entry.header.LastModFileTime = os::Byteswap::byteswap(entry.header.LastModFileTime); + entry.header.LastModFileDate = os::Byteswap::byteswap(entry.header.LastModFileDate); + entry.header.DataDescriptor.CRC32 = os::Byteswap::byteswap(entry.header.DataDescriptor.CRC32); + entry.header.DataDescriptor.CompressedSize = os::Byteswap::byteswap(entry.header.DataDescriptor.CompressedSize); + entry.header.DataDescriptor.UncompressedSize = os::Byteswap::byteswap(entry.header.DataDescriptor.UncompressedSize); + entry.header.FilenameLength = os::Byteswap::byteswap(entry.header.FilenameLength); + entry.header.ExtraFieldLength = os::Byteswap::byteswap(entry.header.ExtraFieldLength); +#endif + + if (entry.header.Sig != 0x04034b50) + return false; // local file headers end here. + + // read filename + { + c8 *tmp = new c8[entry.header.FilenameLength + 2]; + File->read(tmp, entry.header.FilenameLength); + tmp[entry.header.FilenameLength] = 0; + ZipFileName = tmp; + delete[] tmp; + } + + if (entry.header.ExtraFieldLength) + File->seek(entry.header.ExtraFieldLength, true); + + // if bit 3 was set, use CentralDirectory for setup + if (!ignoreGPBits && entry.header.GeneralBitFlag & ZIP_INFO_IN_DATA_DESCRIPTOR) { + SZIPFileCentralDirEnd dirEnd; + FileInfo.clear(); + Files.clear(); + // First place where the end record could be stored + File->seek(File->getSize() - 22); + const char endID[] = {0x50, 0x4b, 0x05, 0x06, 0x0}; + char tmp[5] = {'\0'}; + bool found = false; + // search for the end record ID + while (!found && File->getPos() > 0) { + int seek = 8; + File->read(tmp, 4); + switch (tmp[0]) { + case 0x50: + if (!strcmp(endID, tmp)) { + seek = 4; + found = true; + } + break; + case 0x4b: + seek = 5; + break; + case 0x05: + seek = 6; + break; + case 0x06: + seek = 7; + break; + } + File->seek(-seek, true); + } + File->read(&dirEnd, sizeof(dirEnd)); +#ifdef __BIG_ENDIAN__ + dirEnd.NumberDisk = os::Byteswap::byteswap(dirEnd.NumberDisk); + dirEnd.NumberStart = os::Byteswap::byteswap(dirEnd.NumberStart); + dirEnd.TotalDisk = os::Byteswap::byteswap(dirEnd.TotalDisk); + dirEnd.TotalEntries = os::Byteswap::byteswap(dirEnd.TotalEntries); + dirEnd.Size = os::Byteswap::byteswap(dirEnd.Size); + dirEnd.Offset = os::Byteswap::byteswap(dirEnd.Offset); + dirEnd.CommentLength = os::Byteswap::byteswap(dirEnd.CommentLength); +#endif + FileInfo.reallocate(dirEnd.TotalEntries); + File->seek(dirEnd.Offset); + while (scanCentralDirectoryHeader()) { + } + return false; + } + + // store position in file + entry.Offset = File->getPos(); + // move forward length of data + File->seek(entry.header.DataDescriptor.CompressedSize, true); + +#ifdef _DEBUG +// os::Debuginfo::print("added file from archive", ZipFileName.c_str()); +#endif + + addItem(ZipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, ZipFileName.lastChar() == '/', FileInfo.size()); + FileInfo.push_back(entry); + + return true; +} + +//! scans for a local header, returns false if there is no more local file header. +bool CZipReader::scanCentralDirectoryHeader() +{ + io::path ZipFileName = ""; + SZIPFileCentralDirFileHeader entry; + File->read(&entry, sizeof(SZIPFileCentralDirFileHeader)); + +#ifdef __BIG_ENDIAN__ + entry.Sig = os::Byteswap::byteswap(entry.Sig); + entry.VersionMadeBy = os::Byteswap::byteswap(entry.VersionMadeBy); + entry.VersionToExtract = os::Byteswap::byteswap(entry.VersionToExtract); + entry.GeneralBitFlag = os::Byteswap::byteswap(entry.GeneralBitFlag); + entry.CompressionMethod = os::Byteswap::byteswap(entry.CompressionMethod); + entry.LastModFileTime = os::Byteswap::byteswap(entry.LastModFileTime); + entry.LastModFileDate = os::Byteswap::byteswap(entry.LastModFileDate); + entry.CRC32 = os::Byteswap::byteswap(entry.CRC32); + entry.CompressedSize = os::Byteswap::byteswap(entry.CompressedSize); + entry.UncompressedSize = os::Byteswap::byteswap(entry.UncompressedSize); + entry.FilenameLength = os::Byteswap::byteswap(entry.FilenameLength); + entry.ExtraFieldLength = os::Byteswap::byteswap(entry.ExtraFieldLength); + entry.FileCommentLength = os::Byteswap::byteswap(entry.FileCommentLength); + entry.DiskNumberStart = os::Byteswap::byteswap(entry.DiskNumberStart); + entry.InternalFileAttributes = os::Byteswap::byteswap(entry.InternalFileAttributes); + entry.ExternalFileAttributes = os::Byteswap::byteswap(entry.ExternalFileAttributes); + entry.RelativeOffsetOfLocalHeader = os::Byteswap::byteswap(entry.RelativeOffsetOfLocalHeader); +#endif + + if (entry.Sig != 0x02014b50) + return false; // central dir headers end here. + + const long pos = File->getPos(); + File->seek(entry.RelativeOffsetOfLocalHeader); + scanZipHeader(true); + File->seek(pos + entry.FilenameLength + entry.ExtraFieldLength + entry.FileCommentLength); + FileInfo.getLast().header.DataDescriptor.CompressedSize = entry.CompressedSize; + FileInfo.getLast().header.DataDescriptor.UncompressedSize = entry.UncompressedSize; + FileInfo.getLast().header.DataDescriptor.CRC32 = entry.CRC32; + Files.getLast().Size = entry.UncompressedSize; + return true; +} + +//! opens a file by file name +IReadFile *CZipReader::createAndOpenFile(const io::path &filename) +{ + s32 index = findFile(filename, false); + + if (index != -1) + return createAndOpenFile(index); + + return 0; +} + +//! opens a file by index +IReadFile *CZipReader::createAndOpenFile(u32 index) +{ + // Irrlicht supports 0, 8, 12, 14, 99 + // 0 - The file is stored (no compression) + // 1 - The file is Shrunk + // 2 - The file is Reduced with compression factor 1 + // 3 - The file is Reduced with compression factor 2 + // 4 - The file is Reduced with compression factor 3 + // 5 - The file is Reduced with compression factor 4 + // 6 - The file is Imploded + // 7 - Reserved for Tokenizing compression algorithm + // 8 - The file is Deflated + // 9 - Reserved for enhanced Deflating + // 10 - PKWARE Date Compression Library Imploding + // 12 - bzip2 - Compression Method from libbz2, WinZip 10 + // 14 - LZMA - Compression Method, WinZip 12 + // 96 - Jpeg compression - Compression Method, WinZip 12 + // 97 - WavPack - Compression Method, WinZip 11 + // 98 - PPMd - Compression Method, WinZip 10 + // 99 - AES encryption, WinZip 9 + + const SZipFileEntry &e = FileInfo[Files[index].ID]; + char buf[64]; + s16 actualCompressionMethod = e.header.CompressionMethod; + IReadFile *decrypted = 0; + u8 *decryptedBuf = 0; + u32 decryptedSize = e.header.DataDescriptor.CompressedSize; + switch (actualCompressionMethod) { + case 0: // no compression + { + if (decrypted) + return decrypted; + else + return createLimitReadFile(Files[index].FullName, File, e.Offset, decryptedSize); + } + case 8: { + const u32 uncompressedSize = e.header.DataDescriptor.UncompressedSize; + c8 *pBuf = new c8[uncompressedSize]; + if (!pBuf) { + snprintf_irr(buf, 64, "Not enough memory for decompressing %s", Files[index].FullName.c_str()); + os::Printer::log(buf, ELL_ERROR); + if (decrypted) + decrypted->drop(); + return 0; + } + + u8 *pcData = decryptedBuf; + if (!pcData) { + pcData = new u8[decryptedSize]; + if (!pcData) { + snprintf_irr(buf, 64, "Not enough memory for decompressing %s", Files[index].FullName.c_str()); + os::Printer::log(buf, ELL_ERROR); + delete[] pBuf; + return 0; + } + + // memset(pcData, 0, decryptedSize); + File->seek(e.Offset); + File->read(pcData, decryptedSize); + } + + // Setup the inflate stream. + z_stream stream; + s32 err; + + stream.next_in = (Bytef *)pcData; + stream.avail_in = (uInt)decryptedSize; + stream.next_out = (Bytef *)pBuf; + stream.avail_out = uncompressedSize; + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + + // Perform inflation. wbits < 0 indicates no zlib header inside the data. + err = inflateInit2(&stream, -MAX_WBITS); + if (err == Z_OK) { + err = inflate(&stream, Z_FINISH); + inflateEnd(&stream); + if (err == Z_STREAM_END) + err = Z_OK; + err = Z_OK; + inflateEnd(&stream); + } + + if (decrypted) + decrypted->drop(); + else + delete[] pcData; + + if (err != Z_OK) { + snprintf_irr(buf, 64, "Error decompressing %s", Files[index].FullName.c_str()); + os::Printer::log(buf, ELL_ERROR); + delete[] pBuf; + return 0; + } else + return FileSystem->createMemoryReadFile(pBuf, uncompressedSize, Files[index].FullName, true); + } + case 12: { + os::Printer::log("bzip2 decompression not supported. File cannot be read.", ELL_ERROR); + return 0; + } + case 14: { + os::Printer::log("lzma decompression not supported. File cannot be read.", ELL_ERROR); + return 0; + } + case 99: + // If we come here with an encrypted file, decryption support is missing + os::Printer::log("Decryption support not enabled. File cannot be read.", ELL_ERROR); + return 0; + default: + snprintf_irr(buf, 64, "file has unsupported compression method. %s", Files[index].FullName.c_str()); + os::Printer::log(buf, ELL_ERROR); + return 0; + }; +} + +} // end namespace io +} // end namespace irr diff --git a/irr/src/CZipReader.h b/irr/src/CZipReader.h new file mode 100644 index 000000000..d9afd668a --- /dev/null +++ b/irr/src/CZipReader.h @@ -0,0 +1,218 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IReadFile.h" +#include "irrArray.h" +#include "irrString.h" +#include "IFileSystem.h" +#include "CFileList.h" + +namespace irr +{ +namespace io +{ +// set if the file is encrypted +const s16 ZIP_FILE_ENCRYPTED = 0x0001; +// the fields crc-32, compressed size and uncompressed size are set to +// zero in the local header +const s16 ZIP_INFO_IN_DATA_DESCRIPTOR = 0x0008; + +// byte-align structures +#include "irrpack.h" + +struct SZIPFileDataDescriptor +{ + u32 CRC32; + u32 CompressedSize; + u32 UncompressedSize; +} PACK_STRUCT; + +struct SZIPFileHeader +{ + u32 Sig; // 'PK0304' little endian (0x04034b50) + s16 VersionToExtract; + s16 GeneralBitFlag; + s16 CompressionMethod; + s16 LastModFileTime; + s16 LastModFileDate; + SZIPFileDataDescriptor DataDescriptor; + s16 FilenameLength; + s16 ExtraFieldLength; + // filename (variable size) + // extra field (variable size ) +} PACK_STRUCT; + +struct SZIPFileCentralDirFileHeader +{ + u32 Sig; // 'PK0102' (0x02014b50) + u16 VersionMadeBy; + u16 VersionToExtract; + u16 GeneralBitFlag; + u16 CompressionMethod; + u16 LastModFileTime; + u16 LastModFileDate; + u32 CRC32; + u32 CompressedSize; + u32 UncompressedSize; + u16 FilenameLength; + u16 ExtraFieldLength; + u16 FileCommentLength; + u16 DiskNumberStart; + u16 InternalFileAttributes; + u32 ExternalFileAttributes; + u32 RelativeOffsetOfLocalHeader; + + // filename (variable size) + // extra field (variable size) + // file comment (variable size) + +} PACK_STRUCT; + +struct SZIPFileCentralDirEnd +{ + u32 Sig; // 'PK0506' end_of central dir signature // (0x06054b50) + u16 NumberDisk; // number of this disk + u16 NumberStart; // number of the disk with the start of the central directory + u16 TotalDisk; // total number of entries in the central dir on this disk + u16 TotalEntries; // total number of entries in the central dir + u32 Size; // size of the central directory + u32 Offset; // offset of start of centraldirectory with respect to the starting disk number + u16 CommentLength; // zipfile comment length + // zipfile comment (variable size) +} PACK_STRUCT; + +struct SZipFileExtraHeader +{ + s16 ID; + s16 Size; +} PACK_STRUCT; + +struct SZipFileAESExtraData +{ + s16 Version; + u8 Vendor[2]; + u8 EncryptionStrength; + s16 CompressionMode; +} PACK_STRUCT; + +enum E_GZIP_FLAGS +{ + EGZF_TEXT_DAT = 1, + EGZF_CRC16 = 2, + EGZF_EXTRA_FIELDS = 4, + EGZF_FILE_NAME = 8, + EGZF_COMMENT = 16 +}; + +struct SGZIPMemberHeader +{ + u16 sig; // 0x8b1f + u8 compressionMethod; // 8 = deflate + u8 flags; + u32 time; + u8 extraFlags; // slow compress = 2, fast compress = 4 + u8 operatingSystem; +} PACK_STRUCT; + +// Default alignment +#include "irrunpack.h" + +//! Contains extended info about zip files in the archive +struct SZipFileEntry +{ + //! Position of data in the archive file + s32 Offset; + + //! The header for this file containing compression info etc + SZIPFileHeader header; +}; + +//! Archiveloader capable of loading ZIP Archives +class CArchiveLoaderZIP : public IArchiveLoader +{ +public: + //! Constructor + CArchiveLoaderZIP(io::IFileSystem *fs); + + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".zip") + bool isALoadableFileFormat(const io::path &filename) const override; + + //! Check if the file might be loaded by this class + /** Check might look into the file. + \param file File handle to check. + \return True if file seems to be loadable. */ + bool isALoadableFileFormat(io::IReadFile *file) const override; + + //! Check to see if the loader can create archives of this type. + /** Check based on the archive type. + \param fileType The archive type to check. + \return True if the archile loader supports this type, false if not */ + bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const override; + + //! Creates an archive from the filename + /** \param file File handle to check. + \return Pointer to newly created archive, or 0 upon error. */ + IFileArchive *createArchive(const io::path &filename, bool ignoreCase, bool ignorePaths) const override; + + //! creates/loads an archive from the file. + //! \return Pointer to the created archive. Returns 0 if loading failed. + io::IFileArchive *createArchive(io::IReadFile *file, bool ignoreCase, bool ignorePaths) const override; + +private: + io::IFileSystem *FileSystem; +}; + +/*! + Zip file Reader written April 2002 by N.Gebhardt. +*/ +class CZipReader : public virtual IFileArchive, virtual CFileList +{ +public: + //! constructor + CZipReader(IFileSystem *fs, IReadFile *file, bool ignoreCase, bool ignorePaths, bool isGZip = false); + + //! destructor + virtual ~CZipReader(); + + //! opens a file by file name + IReadFile *createAndOpenFile(const io::path &filename) override; + + //! opens a file by index + IReadFile *createAndOpenFile(u32 index) override; + + //! returns the list of files + const IFileList *getFileList() const override; + + //! get the archive type + E_FILE_ARCHIVE_TYPE getType() const override; + + //! return the id of the file Archive + const io::path &getArchiveName() const override { return Path; } + +protected: + //! reads the next file header from a ZIP file, returns false if there are no more headers. + /* if ignoreGPBits is set, the item will be read despite missing + file information. This is used when reading items from the central + directory. */ + bool scanZipHeader(bool ignoreGPBits = false); + + //! the same but for gzip files + bool scanGZipHeader(); + + bool scanCentralDirectoryHeader(); + + io::IFileSystem *FileSystem; + IReadFile *File; + + // holds extended info about files + core::array FileInfo; + + bool IsGZip; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/IAttribute.h b/irr/src/IAttribute.h new file mode 100644 index 000000000..b0dc76eee --- /dev/null +++ b/irr/src/IAttribute.h @@ -0,0 +1,51 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "IReferenceCounted.h" +#include "SColor.h" +#include "vector3d.h" +#include "vector2d.h" +#include "position2d.h" +#include "rect.h" +#include "dimension2d.h" +#include "irrString.h" +#include "irrArray.h" +#include "EAttributes.h" + +namespace irr +{ +namespace io +{ + +// All derived attribute types implement at least getter/setter for their own type (like CBoolAttribute will have setBool/getBool). +// Simple types will also implement getStringW and setString, but don't expect it to work for all types. +// String serialization makes no sense for some attribute-types (like stringw arrays or pointers), but is still useful for many types. +// (Note: I do _not_ know yet why the default string serialization is asymmetric with char* in set and wchar_t* in get). +// Additionally many attribute types will implement conversion functions like CBoolAttribute has p.E. getInt/setInt(). +// The reason for conversion functions is likely to make reading old formats easier which have changed in the meantime. For example +// an old xml can contain a bool attribute which is an int in a newer format. You can still call getInt() even thought the attribute has the wrong type. +// And please do _not_ confuse these attributes here with the ones used in the xml-reader (aka SAttribute which is just a key-value pair). + +class IAttribute : public virtual IReferenceCounted +{ +public: + virtual ~IAttribute(){}; + + virtual s32 getInt() const { return 0; } + virtual f32 getFloat() const { return 0; } + virtual bool getBool() const { return false; } + + virtual void setInt(s32 intValue){}; + virtual void setFloat(f32 floatValue){}; + virtual void setBool(bool boolValue){}; + + core::stringc Name; + + virtual E_ATTRIBUTE_TYPE getType() const = 0; +}; + +} // end namespace io +} // end namespace irr diff --git a/irr/src/Irrlicht.cpp b/irr/src/Irrlicht.cpp new file mode 100644 index 000000000..c97e5d308 --- /dev/null +++ b/irr/src/Irrlicht.cpp @@ -0,0 +1,161 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +static const char *const copyright = "Irrlicht Engine (c) 2002-2017 Nikolaus Gebhardt"; // put string in binary + +#ifdef _IRR_WINDOWS_ +#include +#if defined(_DEBUG) && !defined(__GNUWIN32__) +#include +#endif // _DEBUG +#endif + +#include "irrlicht.h" +#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ +#include "CIrrDeviceWin32.h" +#endif + +#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ +#include "CIrrDeviceLinux.h" +#endif + +#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ +#include "CIrrDeviceOSX.h" +#endif + +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ +#include "CIrrDeviceSDL.h" +#endif + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ +#include "Android/CIrrDeviceAndroid.h" +#endif + +namespace irr +{ +//! stub for calling createDeviceEx +IRRLICHT_API IrrlichtDevice *IRRCALLCONV createDevice(video::E_DRIVER_TYPE driverType, + const core::dimension2d &windowSize, + u32 bits, bool fullscreen, + bool stencilbuffer, bool vsync, IEventReceiver *res) +{ + (void)copyright; // prevent unused variable warning + + SIrrlichtCreationParameters p; + p.DriverType = driverType; + p.WindowSize = windowSize; + p.Bits = (u8)bits; + p.Fullscreen = fullscreen; + p.Stencilbuffer = stencilbuffer; + p.Vsync = vsync; + p.EventReceiver = res; + + return createDeviceEx(p); +} + +extern "C" IRRLICHT_API IrrlichtDevice *IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters ¶ms) +{ + + IrrlichtDevice *dev = 0; + +#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ + if (params.DeviceType == EIDT_WIN32 || (!dev && params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceWin32(params); +#endif + +#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ + if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceMacOSX(params); +#endif + +#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ + if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceLinux(params); +#endif + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ + if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceAndroid(params); +#endif + +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + if (params.DeviceType == EIDT_SDL || (!dev && params.DeviceType == EIDT_BEST)) + dev = new CIrrDeviceSDL(params); +#endif + + if (dev && !dev->getVideoDriver() && params.DriverType != video::EDT_NULL) { + dev->closeDevice(); // destroy window + dev->run(); // consume quit message + dev->drop(); + dev = 0; + } + + return dev; +} + +namespace core +{ +const matrix4 IdentityMatrix(matrix4::EM4CONST_IDENTITY); +} + +namespace video +{ +SMaterial IdentityMaterial; + +extern "C" IRRLICHT_API bool IRRCALLCONV isDriverSupported(E_DRIVER_TYPE driver) +{ + switch (driver) { + case EDT_NULL: + return true; +#ifdef ENABLE_OPENGL3 + case EDT_OPENGL3: + return true; +#endif +#ifdef _IRR_COMPILE_WITH_OPENGL_ + case EDT_OPENGL: + return true; +#endif +#ifdef _IRR_COMPILE_WITH_OGLES1_ + case EDT_OGLES1: + return true; +#endif +#ifdef _IRR_COMPILE_WITH_OGLES2_ + case EDT_OGLES2: + return true; +#endif +#ifdef _IRR_COMPILE_WITH_WEBGL1_ + case EDT_WEBGL1: + return true; +#endif + default: + return false; + } +} +} + +} // end namespace irr + +#if defined(_IRR_WINDOWS_API_) && !defined(_IRR_STATIC_LIB_) + +BOOL APIENTRY DllMain(HANDLE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved) +{ + // _crtBreakAlloc = 139; + + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: +#if defined(_DEBUG) && !defined(__GNUWIN32__) + _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF); +#endif + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + +#endif // defined(_IRR_WINDOWS_) diff --git a/irr/src/KHR/khrplatform.h b/irr/src/KHR/khrplatform.h new file mode 100644 index 000000000..84821e08b --- /dev/null +++ b/irr/src/KHR/khrplatform.h @@ -0,0 +1,310 @@ +#ifndef __khrplatform_h_ +#define __khrplatform_h_ + +/* +** Copyright (c) 2008-2018 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Khronos platform-specific types and definitions. + * + * The master copy of khrplatform.h is maintained in the Khronos EGL + * Registry repository at https://github.com/KhronosGroup/EGL-Registry + * The last semantic modification to khrplatform.h was at commit ID: + * 67a3e0864c2d75ea5287b9f3d2eb74a745936692 + * + * Adopters may modify this file to suit their platform. Adopters are + * encouraged to submit platform specific modifications to the Khronos + * group so that they can be included in future versions of this file. + * Please submit changes by filing pull requests or issues on + * the EGL Registry repository linked above. + * + * + * See the Implementer's Guidelines for information about where this file + * should be located on your system and for more details of its use: + * http://www.khronos.org/registry/implementers_guide.pdf + * + * This file should be included as + * #include + * by Khronos client API header files that use its types and defines. + * + * The types in khrplatform.h should only be used to define API-specific types. + * + * Types defined in khrplatform.h: + * khronos_int8_t signed 8 bit + * khronos_uint8_t unsigned 8 bit + * khronos_int16_t signed 16 bit + * khronos_uint16_t unsigned 16 bit + * khronos_int32_t signed 32 bit + * khronos_uint32_t unsigned 32 bit + * khronos_int64_t signed 64 bit + * khronos_uint64_t unsigned 64 bit + * khronos_intptr_t signed same number of bits as a pointer + * khronos_uintptr_t unsigned same number of bits as a pointer + * khronos_ssize_t signed size + * khronos_usize_t unsigned size + * khronos_float_t signed 32 bit floating point + * khronos_time_ns_t unsigned 64 bit time in nanoseconds + * khronos_utime_nanoseconds_t unsigned time interval or absolute time in + * nanoseconds + * khronos_stime_nanoseconds_t signed time interval in nanoseconds + * khronos_boolean_enum_t enumerated boolean type. This should + * only be used as a base type when a client API's boolean type is + * an enum. Client APIs which use an integer or other type for + * booleans cannot use this as the base type for their boolean. + * + * Tokens defined in khrplatform.h: + * + * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. + * + * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. + * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. + * + * Calling convention macros defined in this file: + * KHRONOS_APICALL + * KHRONOS_APIENTRY + * KHRONOS_APIATTRIBUTES + * + * These may be used in function prototypes as: + * + * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( + * int arg1, + * int arg2) KHRONOS_APIATTRIBUTES; + */ + +#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) +#define KHRONOS_STATIC 1 +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APICALL + *------------------------------------------------------------------------- + * This precedes the return type of the function in the function prototype. + */ +#if defined(KHRONOS_STATIC) +/* If the preprocessor constant KHRONOS_STATIC is defined, make the + * header compatible with static linking. */ +#define KHRONOS_APICALL +#elif defined(_WIN32) +#define KHRONOS_APICALL __declspec(dllimport) +#elif defined(__SYMBIAN32__) +#define KHRONOS_APICALL IMPORT_C +#elif defined(__ANDROID__) +#define KHRONOS_APICALL __attribute__((visibility("default"))) +#else +#define KHRONOS_APICALL +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIENTRY + *------------------------------------------------------------------------- + * This follows the return type of the function and precedes the function + * name in the function prototype. + */ +#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) +/* Win32 but not WinCE */ +#define KHRONOS_APIENTRY __stdcall +#else +#define KHRONOS_APIENTRY +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIATTRIBUTES + *------------------------------------------------------------------------- + * This follows the closing parenthesis of the function prototype arguments. + */ +#if defined(__ARMCC_2__) +#define KHRONOS_APIATTRIBUTES __softfp +#else +#define KHRONOS_APIATTRIBUTES +#endif + +/*------------------------------------------------------------------------- + * basic type definitions + *-----------------------------------------------------------------------*/ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 +/* + * To support platform where unsigned long cannot be used interchangeably with + * inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t. + * Ideally, we could just use (u)intptr_t everywhere, but this could result in + * ABI breakage if khronos_uintptr_t is changed from unsigned long to + * unsigned long long or similar (this results in different C++ name mangling). + * To avoid changes for existing platforms, we restrict usage of intptr_t to + * platforms where the size of a pointer is larger than the size of long. + */ +#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) +#if __SIZEOF_POINTER__ > __SIZEOF_LONG__ +#define KHRONOS_USE_INTPTR_T +#endif +#endif + +#elif defined(__VMS) || defined(__sgi) + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) + +/* + * Win32 + */ +typedef __int32 khronos_int32_t; +typedef unsigned __int32 khronos_uint32_t; +typedef __int64 khronos_int64_t; +typedef unsigned __int64 khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__sun__) || defined(__digital__) + +/* + * Sun or Digital + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#if defined(__arch64__) || defined(_LP64) +typedef long int khronos_int64_t; +typedef unsigned long int khronos_uint64_t; +#else +typedef long long int khronos_int64_t; +typedef unsigned long long int khronos_uint64_t; +#endif /* __arch64__ */ +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif 0 + +/* + * Hypothetical platform with no float or int64 support + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#define KHRONOS_SUPPORT_INT64 0 +#define KHRONOS_SUPPORT_FLOAT 0 + +#else + +/* + * Generic fallback + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#endif + +/* + * Types that are (so far) the same on all platforms + */ +typedef signed char khronos_int8_t; +typedef unsigned char khronos_uint8_t; +typedef signed short int khronos_int16_t; +typedef unsigned short int khronos_uint16_t; + +/* + * Types that differ between LLP64 and LP64 architectures - in LLP64, + * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears + * to be the only LLP64 architecture in current use. + */ +#ifdef KHRONOS_USE_INTPTR_T +typedef intptr_t khronos_intptr_t; +typedef uintptr_t khronos_uintptr_t; +#elif defined(_WIN64) +typedef signed long long int khronos_intptr_t; +typedef unsigned long long int khronos_uintptr_t; +#else +typedef signed long int khronos_intptr_t; +typedef unsigned long int khronos_uintptr_t; +#endif + +#if defined(_WIN64) +typedef signed long long int khronos_ssize_t; +typedef unsigned long long int khronos_usize_t; +#else +typedef signed long int khronos_ssize_t; +typedef unsigned long int khronos_usize_t; +#endif + +#if KHRONOS_SUPPORT_FLOAT +/* + * Float type + */ +typedef float khronos_float_t; +#endif + +#if KHRONOS_SUPPORT_INT64 +/* Time types + * + * These types can be used to represent a time interval in nanoseconds or + * an absolute Unadjusted System Time. Unadjusted System Time is the number + * of nanoseconds since some arbitrary system event (e.g. since the last + * time the system booted). The Unadjusted System Time is an unsigned + * 64 bit value that wraps back to 0 every 584 years. Time intervals + * may be either signed or unsigned. + */ +typedef khronos_uint64_t khronos_utime_nanoseconds_t; +typedef khronos_int64_t khronos_stime_nanoseconds_t; +#endif + +/* + * Dummy value used to pad enum types to 32 bits. + */ +#ifndef KHRONOS_MAX_ENUM +#define KHRONOS_MAX_ENUM 0x7FFFFFFF +#endif + +/* + * Enumerated boolean type + * + * Values other than zero should be considered to be true. Therefore + * comparisons should not be made against KHRONOS_TRUE. + */ +typedef enum +{ + KHRONOS_FALSE = 0, + KHRONOS_TRUE = 1, + KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM +} khronos_boolean_enum_t; + +#endif /* __khrplatform_h_ */ diff --git a/irr/src/OpenGL/Common.h b/irr/src/OpenGL/Common.h new file mode 100644 index 000000000..92445cc34 --- /dev/null +++ b/irr/src/OpenGL/Common.h @@ -0,0 +1,57 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2015 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" +// even though we have mt_opengl.h our driver code still uses GL_* constants +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#include +#include +#else +#include "vendor/gl.h" +#endif + +namespace irr +{ +namespace video +{ + +// Forward declarations. + +class COpenGLCoreFeature; + +template +class COpenGLCoreTexture; + +template +class COpenGLCoreRenderTarget; + +template +class COpenGLCoreCacheHandler; + +class COpenGL3DriverBase; +typedef COpenGLCoreTexture COpenGL3Texture; +typedef COpenGLCoreRenderTarget COpenGL3RenderTarget; +typedef COpenGLCoreCacheHandler COpenGL3CacheHandler; + +enum class OpenGLSpec : u8 +{ + Core, + Compat, + ES, + // WebGL, // TODO +}; + +struct OpenGLVersion +{ + OpenGLSpec Spec; + u8 Major; + u8 Minor; + u8 Release; +}; + +} +} diff --git a/irr/src/OpenGL/Driver.cpp b/irr/src/OpenGL/Driver.cpp new file mode 100644 index 000000000..73c3451f7 --- /dev/null +++ b/irr/src/OpenGL/Driver.cpp @@ -0,0 +1,1991 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Driver.h" +#include +#include "CNullDriver.h" +#include "IContextManager.h" + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreRenderTarget.h" +#include "COpenGLCoreCacheHandler.h" + +#include "MaterialRenderer.h" +#include "FixedPipelineRenderer.h" +#include "Renderer2D.h" + +#include "EVertexAttributes.h" +#include "CImage.h" +#include "os.h" + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ +#include "android_native_app_glue.h" +#endif + +#include "mt_opengl.h" + +namespace irr +{ +namespace video +{ +struct VertexAttribute +{ + enum class Mode + { + Regular, + Normalized, + Integral, + }; + int Index; + int ComponentCount; + GLenum ComponentType; + Mode mode; + int Offset; +}; + +struct VertexType +{ + int VertexSize; + std::vector Attributes; +}; + +static const VertexAttribute *begin(const VertexType &type) +{ + return type.Attributes.data(); +} + +static const VertexAttribute *end(const VertexType &type) +{ + return type.Attributes.data() + type.Attributes.size(); +} + +static const VertexType vtStandard = { + sizeof(S3DVertex), + { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + }, +}; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winvalid-offsetof" + +static const VertexType vt2TCoords = { + sizeof(S3DVertex2TCoords), + { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex2TCoords, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords)}, + {EVA_TCOORD1, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords2)}, + }, +}; + +static const VertexType vtTangents = { + sizeof(S3DVertexTangents), + { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertexTangents, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, TCoords)}, + {EVA_TANGENT, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Tangent)}, + {EVA_BINORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Binormal)}, + }, +}; + +#pragma GCC diagnostic pop + +static const VertexType &getVertexTypeDescription(E_VERTEX_TYPE type) +{ + switch (type) { + case EVT_STANDARD: + return vtStandard; + case EVT_2TCOORDS: + return vt2TCoords; + case EVT_TANGENTS: + return vtTangents; + default: + assert(false); + } +} + +static const VertexType vt2DImage = { + sizeof(S3DVertex), + { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + }, +}; + +static const VertexType vtPrimitive = { + sizeof(S3DVertex), + { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + }, +}; + +void APIENTRY COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +{ + ((COpenGL3DriverBase *)userParam)->debugCb(source, type, id, severity, length, message); +} + +void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) +{ + printf("%04x %04x %x %x %.*s\n", source, type, id, severity, length, message); +} + +COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) : + CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), + Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), + MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), + CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), + OGLES2ShaderPath(params.OGLES2ShaderPath), + ColorFormat(ECF_R8G8B8), ContextManager(contextManager) +{ +#ifdef _DEBUG + setDebugName("Driver"); +#endif + + if (!ContextManager) + return; + + ContextManager->grab(); + ContextManager->generateSurface(); + ContextManager->generateContext(); + ExposedData = ContextManager->getContext(); + ContextManager->activateContext(ExposedData, false); + GL.LoadAllProcedures(ContextManager); + GL.DebugMessageCallback(debugCb, this); + initQuadsIndices(); +} + +COpenGL3DriverBase::~COpenGL3DriverBase() +{ + deleteMaterialRenders(); + + CacheHandler->getTextureCache().clear(); + + removeAllRenderTargets(); + deleteAllTextures(); + removeAllOcclusionQueries(); + removeAllHardwareBuffers(); + + delete MaterialRenderer2DTexture; + delete MaterialRenderer2DNoTexture; + delete CacheHandler; + + if (ContextManager) { + ContextManager->destroyContext(); + ContextManager->destroySurface(); + ContextManager->terminate(); + ContextManager->drop(); + } +} + +void COpenGL3DriverBase::initQuadsIndices(int max_vertex_count) +{ + int max_quad_count = max_vertex_count / 4; + std::vector QuadsIndices; + QuadsIndices.reserve(6 * max_quad_count); + for (int k = 0; k < max_quad_count; k++) { + QuadsIndices.push_back(4 * k + 0); + QuadsIndices.push_back(4 * k + 1); + QuadsIndices.push_back(4 * k + 2); + QuadsIndices.push_back(4 * k + 0); + QuadsIndices.push_back(4 * k + 2); + QuadsIndices.push_back(4 * k + 3); + } + GL.GenBuffers(1, &QuadIndexBuffer); + GL.BindBuffer(GL_ARRAY_BUFFER, QuadIndexBuffer); + GL.BufferData(GL_ARRAY_BUFFER, sizeof(QuadsIndices[0]) * QuadsIndices.size(), QuadsIndices.data(), GL_STATIC_DRAW); + GL.BindBuffer(GL_ARRAY_BUFFER, 0); + QuadIndexCount = QuadsIndices.size(); +} + +void COpenGL3DriverBase::initVersion() +{ + Name = GL.GetString(GL_VERSION); + printVersion(); + + // print renderer information + VendorName = GL.GetString(GL_VENDOR); + os::Printer::log("Vendor", VendorName.c_str(), ELL_INFORMATION); + + Version = getVersionFromOpenGL(); +} + +bool COpenGL3DriverBase::isVersionAtLeast(int major, int minor) const noexcept +{ + if (Version.Major < major) + return false; + if (Version.Major > major) + return true; + return Version.Minor >= minor; +} + +bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d &screenSize, bool stencilBuffer) +{ + initVersion(); + initFeatures(); + printTextureFormats(); + + // reset cache handler + delete CacheHandler; + CacheHandler = new COpenGL3CacheHandler(this); + + StencilBuffer = stencilBuffer; + + DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits); + DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits); + // DriverAttributes->setAttribute("MaxLights", MaxLights); + DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy); + // DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes); + // DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers); + // DriverAttributes->setAttribute("MaxMultipleRenderTargets", MaxMultipleRenderTargets); + DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices); + DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize); + DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias); + DriverAttributes->setAttribute("Version", 100 * Version.Major + Version.Minor); + DriverAttributes->setAttribute("AntiAlias", AntiAlias); + + GL.PixelStorei(GL_PACK_ALIGNMENT, 1); + + UserClipPlane.reallocate(0); + + for (s32 i = 0; i < ETS_COUNT; ++i) + setTransform(static_cast(i), core::IdentityMatrix); + + setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); + GL.ClearDepthf(1.0f); + + GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + GL.FrontFace(GL_CW); + + // create material renderers + createMaterialRenderers(); + + // set the renderstates + setRenderStates3DMode(); + + // set fog mode + setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog); + + // create matrix for flipping textures + TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f)); + + // We need to reset once more at the beginning of the first rendering. + // This fixes problems with intermediate changes to the material during texture load. + ResetRenderStates = true; + + testGLError(__LINE__); + + return true; +} + +void COpenGL3DriverBase::printTextureFormats() +{ + char buf[128]; + for (u32 i = 0; i < static_cast(ECF_UNKNOWN); i++) { + auto &info = TextureFormats[i]; + if (!info.InternalFormat) { + snprintf_irr(buf, sizeof(buf), "%s -> unsupported", ColorFormatNames[i]); + } else { + snprintf_irr(buf, sizeof(buf), "%s -> %#06x %#06x %#06x%s", + ColorFormatNames[i], info.InternalFormat, info.PixelFormat, + info.PixelType, info.Converter ? " (c)" : ""); + } + os::Printer::log(buf, ELL_DEBUG); + } +} + +void COpenGL3DriverBase::loadShaderData(const io::path &vertexShaderName, const io::path &fragmentShaderName, c8 **vertexShaderData, c8 **fragmentShaderData) +{ + io::path vsPath(OGLES2ShaderPath); + vsPath += vertexShaderName; + + io::path fsPath(OGLES2ShaderPath); + fsPath += fragmentShaderName; + + *vertexShaderData = 0; + *fragmentShaderData = 0; + + io::IReadFile *vsFile = FileSystem->createAndOpenFile(vsPath); + if (!vsFile) { + std::string warning("Warning: Missing shader files needed to simulate fixed function materials:\n"); + warning.append(vsPath.c_str()).append("\n"); + warning += "Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; + os::Printer::log(warning.c_str(), ELL_WARNING); + return; + } + + io::IReadFile *fsFile = FileSystem->createAndOpenFile(fsPath); + if (!fsFile) { + std::string warning("Warning: Missing shader files needed to simulate fixed function materials:\n"); + warning.append(fsPath.c_str()).append("\n"); + warning += "Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; + os::Printer::log(warning.c_str(), ELL_WARNING); + return; + } + + long size = vsFile->getSize(); + if (size) { + *vertexShaderData = new c8[size + 1]; + vsFile->read(*vertexShaderData, size); + (*vertexShaderData)[size] = 0; + } + { + auto tmp = std::string("Loaded ") + std::to_string(size) + " bytes for vertex shader " + vertexShaderName.c_str(); + os::Printer::log(tmp.c_str(), ELL_INFORMATION); + } + + size = fsFile->getSize(); + if (size) { + // if both handles are the same we must reset the file + if (fsFile == vsFile) + fsFile->seek(0); + + *fragmentShaderData = new c8[size + 1]; + fsFile->read(*fragmentShaderData, size); + (*fragmentShaderData)[size] = 0; + } + { + auto tmp = std::string("Loaded ") + std::to_string(size) + " bytes for fragment shader " + fragmentShaderName.c_str(); + os::Printer::log(tmp.c_str(), ELL_INFORMATION); + } + + vsFile->drop(); + fsFile->drop(); +} + +void COpenGL3DriverBase::createMaterialRenderers() +{ + // Create callbacks. + + COpenGL3MaterialSolidCB *SolidCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB *TransparentAlphaChannelCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB *TransparentAlphaChannelRefCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB *TransparentVertexAlphaCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialOneTextureBlendCB *OneTextureBlendCB = new COpenGL3MaterialOneTextureBlendCB(); + + // Create built-in materials. + // The addition order must be the same as in the E_MATERIAL_TYPE enumeration. Thus the + + const core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; + + // EMT_SOLID + core::stringc FragmentShader = OGLES2ShaderPath + "Solid.fsh"; + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SolidCB, EMT_SOLID, 0); + + // EMT_TRANSPARENT_ALPHA_CHANNEL + FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannel.fsh"; + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + // EMT_TRANSPARENT_ALPHA_CHANNEL_REF + FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannelRef.fsh"; + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelRefCB, EMT_SOLID, 0); + + // EMT_TRANSPARENT_VERTEX_ALPHA + FragmentShader = OGLES2ShaderPath + "TransparentVertexAlpha.fsh"; + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + // EMT_ONETEXTURE_BLEND + FragmentShader = OGLES2ShaderPath + "OneTextureBlend.fsh"; + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, OneTextureBlendCB, EMT_ONETEXTURE_BLEND, 0); + + // Drop callbacks. + + SolidCB->drop(); + TransparentAlphaChannelCB->drop(); + TransparentAlphaChannelRefCB->drop(); + TransparentVertexAlphaCB->drop(); + OneTextureBlendCB->drop(); + + // Create 2D material renderers + + c8 *vs2DData = 0; + c8 *fs2DData = 0; + loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D.fsh"), &vs2DData, &fs2DData); + MaterialRenderer2DTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, true); + delete[] vs2DData; + delete[] fs2DData; + vs2DData = 0; + fs2DData = 0; + + loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D_noTex.fsh"), &vs2DData, &fs2DData); + MaterialRenderer2DNoTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, false); + delete[] vs2DData; + delete[] fs2DData; +} + +bool COpenGL3DriverBase::setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture *texture) +{ + Material.TextureLayers[layerIdx].Texture = const_cast(texture); // function uses const-pointer for texture because all draw functions use const-pointers already + return CacheHandler->getTextureCache().set(0, texture); +} + +bool COpenGL3DriverBase::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData &videoData, core::rect *sourceRect) +{ + CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect); + + if (ContextManager) + ContextManager->activateContext(videoData, true); + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; +} + +bool COpenGL3DriverBase::endScene() +{ + CNullDriver::endScene(); + + GL.Flush(); + + if (ContextManager) + return ContextManager->swapBuffers(); + + return false; +} + +//! Returns the transformation set by setTransform +const core::matrix4 &COpenGL3DriverBase::getTransform(E_TRANSFORMATION_STATE state) const +{ + return Matrices[state]; +} + +//! sets transformation +void COpenGL3DriverBase::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) +{ + Matrices[state] = mat; + Transformation3DChanged = true; +} + +bool COpenGL3DriverBase::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) +{ + if (!HWBuffer) + return false; + + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + const void *vertices = mb->getVertices(); + const u32 vertexCount = mb->getVertexCount(); + const E_VERTEX_TYPE vType = mb->getVertexType(); + const u32 vertexSize = getVertexPitchFromType(vType); + + const void *buffer = vertices; + size_t bufferSize = vertexSize * vertexCount; + + // get or create buffer + bool newBuffer = false; + if (!HWBuffer->vbo_verticesID) { + GL.GenBuffers(1, &HWBuffer->vbo_verticesID); + if (!HWBuffer->vbo_verticesID) + return false; + newBuffer = true; + } else if (HWBuffer->vbo_verticesSize < bufferSize) { + newBuffer = true; + } + + GL.BindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + + // copy data to graphics card + if (!newBuffer) + GL.BufferSubData(GL_ARRAY_BUFFER, 0, bufferSize, buffer); + else { + HWBuffer->vbo_verticesSize = bufferSize; + + GLenum usage = GL_STATIC_DRAW; + if (HWBuffer->Mapped_Index == scene::EHM_STREAM) + usage = GL_STREAM_DRAW; + else if (HWBuffer->Mapped_Index == scene::EHM_DYNAMIC) + usage = GL_DYNAMIC_DRAW; + GL.BufferData(GL_ARRAY_BUFFER, bufferSize, buffer, usage); + } + + GL.BindBuffer(GL_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); +} + +bool COpenGL3DriverBase::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) +{ + if (!HWBuffer) + return false; + + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + + const void *indices = mb->getIndices(); + u32 indexCount = mb->getIndexCount(); + + GLenum indexSize; + switch (mb->getIndexType()) { + case (EIT_16BIT): { + indexSize = sizeof(u16); + break; + } + case (EIT_32BIT): { + indexSize = sizeof(u32); + break; + } + default: { + return false; + } + } + + // get or create buffer + bool newBuffer = false; + if (!HWBuffer->vbo_indicesID) { + GL.GenBuffers(1, &HWBuffer->vbo_indicesID); + if (!HWBuffer->vbo_indicesID) + return false; + newBuffer = true; + } else if (HWBuffer->vbo_indicesSize < indexCount * indexSize) { + newBuffer = true; + } + + GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + + // copy data to graphics card + if (!newBuffer) + GL.BufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices); + else { + HWBuffer->vbo_indicesSize = indexCount * indexSize; + + GLenum usage = GL_STATIC_DRAW; + if (HWBuffer->Mapped_Index == scene::EHM_STREAM) + usage = GL_STREAM_DRAW; + else if (HWBuffer->Mapped_Index == scene::EHM_DYNAMIC) + usage = GL_DYNAMIC_DRAW; + GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, usage); + } + + GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); +} + +//! updates hardware buffer if needed +bool COpenGL3DriverBase::updateHardwareBuffer(SHWBufferLink *HWBuffer) +{ + if (!HWBuffer) + return false; + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { + if (HWBuffer->ChangedID_Vertex != HWBuffer->MeshBuffer->getChangedID_Vertex() || !static_cast(HWBuffer)->vbo_verticesID) { + + HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); + + if (!updateVertexHardwareBuffer(static_cast(HWBuffer))) + return false; + } + } + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { + if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index() || !static_cast(HWBuffer)->vbo_indicesID) { + + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + + if (!updateIndexHardwareBuffer((SHWBufferLink_opengl *)HWBuffer)) + return false; + } + } + + return true; +} + +//! Create hardware buffer from meshbuffer +COpenGL3DriverBase::SHWBufferLink *COpenGL3DriverBase::createHardwareBuffer(const scene::IMeshBuffer *mb) +{ + if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER)) + return 0; + + SHWBufferLink_opengl *HWBuffer = new SHWBufferLink_opengl(mb); + + // add to map + HWBuffer->listPosition = HWBufferList.insert(HWBufferList.end(), HWBuffer); + + HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + HWBuffer->Mapped_Vertex = mb->getHardwareMappingHint_Vertex(); + HWBuffer->Mapped_Index = mb->getHardwareMappingHint_Index(); + HWBuffer->vbo_verticesID = 0; + HWBuffer->vbo_indicesID = 0; + HWBuffer->vbo_verticesSize = 0; + HWBuffer->vbo_indicesSize = 0; + + if (!updateHardwareBuffer(HWBuffer)) { + deleteHardwareBuffer(HWBuffer); + return 0; + } + + return HWBuffer; +} + +void COpenGL3DriverBase::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) +{ + if (!_HWBuffer) + return; + + SHWBufferLink_opengl *HWBuffer = static_cast(_HWBuffer); + if (HWBuffer->vbo_verticesID) { + GL.DeleteBuffers(1, &HWBuffer->vbo_verticesID); + HWBuffer->vbo_verticesID = 0; + } + if (HWBuffer->vbo_indicesID) { + GL.DeleteBuffers(1, &HWBuffer->vbo_indicesID); + HWBuffer->vbo_indicesID = 0; + } + + CNullDriver::deleteHardwareBuffer(_HWBuffer); +} + +//! Draw hardware buffer +void COpenGL3DriverBase::drawHardwareBuffer(SHWBufferLink *_HWBuffer) +{ + if (!_HWBuffer) + return; + + SHWBufferLink_opengl *HWBuffer = static_cast(_HWBuffer); + + updateHardwareBuffer(HWBuffer); // check if update is needed + + const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; + const void *vertices = mb->getVertices(); + const void *indexList = mb->getIndices(); + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { + GL.BindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + vertices = 0; + } + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { + GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + indexList = 0; + } + + drawVertexPrimitiveList(vertices, mb->getVertexCount(), + indexList, mb->getPrimitiveCount(), + mb->getVertexType(), mb->getPrimitiveType(), + mb->getIndexType()); + + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) + GL.BindBuffer(GL_ARRAY_BUFFER, 0); + + if (HWBuffer->Mapped_Index != scene::EHM_NEVER) + GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} + +IRenderTarget *COpenGL3DriverBase::addRenderTarget() +{ + COpenGL3RenderTarget *renderTarget = new COpenGL3RenderTarget(this); + RenderTargets.push_back(renderTarget); + + return renderTarget; +} + +// small helper function to create vertex buffer object adress offsets +static inline u8 *buffer_offset(const long offset) +{ + return ((u8 *)0 + offset); +} + +//! draws a vertex primitive list +void COpenGL3DriverBase::drawVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) +{ + if (!primitiveCount || !vertexCount) + return; + + if (!checkPrimitiveCount(primitiveCount)) + return; + + CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); + + setRenderStates3DMode(); + + auto &vTypeDesc = getVertexTypeDescription(vType); + beginDraw(vTypeDesc, reinterpret_cast(vertices)); + GLenum indexSize = 0; + + switch (iType) { + case (EIT_16BIT): { + indexSize = GL_UNSIGNED_SHORT; + break; + } + case (EIT_32BIT): { +#ifdef GL_OES_element_index_uint +#ifndef GL_UNSIGNED_INT +#define GL_UNSIGNED_INT 0x1405 +#endif + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_element_index_uint]) + indexSize = GL_UNSIGNED_INT; + else +#endif + indexSize = GL_UNSIGNED_SHORT; + break; + } + } + + switch (pType) { + case scene::EPT_POINTS: + case scene::EPT_POINT_SPRITES: + GL.DrawArrays(GL_POINTS, 0, primitiveCount); + break; + case scene::EPT_LINE_STRIP: + GL.DrawElements(GL_LINE_STRIP, primitiveCount + 1, indexSize, indexList); + break; + case scene::EPT_LINE_LOOP: + GL.DrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList); + break; + case scene::EPT_LINES: + GL.DrawElements(GL_LINES, primitiveCount * 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_STRIP: + GL.DrawElements(GL_TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_FAN: + GL.DrawElements(GL_TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLES: + GL.DrawElements((LastMaterial.Wireframe) ? GL_LINES : (LastMaterial.PointCloud) ? GL_POINTS + : GL_TRIANGLES, + primitiveCount * 3, indexSize, indexList); + break; + default: + break; + } + + endDraw(vTypeDesc); +} + +void COpenGL3DriverBase::draw2DImage(const video::ITexture *texture, const core::position2d &destPos, + const core::rect &sourceRect, const core::rect *clipRect, SColor color, + bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + if (!sourceRect.isValid()) + return; + + SColor colors[4] = {color, color, color, color}; + draw2DImage(texture, {destPos, sourceRect.getSize()}, sourceRect, clipRect, colors, useAlphaChannelOfTexture); +} + +void COpenGL3DriverBase::draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect, + const video::SColor *const colors, bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + // texcoords need to be flipped horizontally for RTTs + const bool isRTT = texture->isRenderTarget(); + const core::dimension2du &ss = texture->getOriginalSize(); + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + const core::rect tcoords( + sourceRect.UpperLeftCorner.X * invW, + (isRTT ? sourceRect.LowerRightCorner.Y : sourceRect.UpperLeftCorner.Y) * invH, + sourceRect.LowerRightCorner.X * invW, + (isRTT ? sourceRect.UpperLeftCorner.Y : sourceRect.LowerRightCorner.Y) * invH); + + const video::SColor temp[4] = { + 0xFFFFFFFF, + 0xFFFFFFFF, + 0xFFFFFFFF, + 0xFFFFFFFF, + }; + + const video::SColor *const useColor = colors ? colors : temp; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture)) + return; + + setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 || + useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255, + true, useAlphaChannelOfTexture); + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + if (clipRect) { + if (!clipRect->isValid()) + return; + + GL.Enable(GL_SCISSOR_TEST); + GL.Scissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + f32 left = (f32)destRect.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)destRect.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)destRect.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)destRect.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + + drawQuad(vt2DImage, vertices); + + if (clipRect) + GL.Disable(GL_SCISSOR_TEST); + + testGLError(__LINE__); +} + +void COpenGL3DriverBase::draw2DImage(const video::ITexture *texture, u32 layer, bool flip) +{ + if (!texture) + return; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture)) + return; + + setRenderStates2DMode(false, true, true); + + S3DVertex quad2DVertices[4]; + + quad2DVertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); + quad2DVertices[1].Pos = core::vector3df(1.f, 1.f, 0.f); + quad2DVertices[2].Pos = core::vector3df(1.f, -1.f, 0.f); + quad2DVertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f); + + f32 modificator = (flip) ? 1.f : 0.f; + + quad2DVertices[0].TCoords = core::vector2df(0.f, 0.f + modificator); + quad2DVertices[1].TCoords = core::vector2df(1.f, 0.f + modificator); + quad2DVertices[2].TCoords = core::vector2df(1.f, 1.f - modificator); + quad2DVertices[3].TCoords = core::vector2df(0.f, 1.f - modificator); + + quad2DVertices[0].Color = SColor(0xFFFFFFFF); + quad2DVertices[1].Color = SColor(0xFFFFFFFF); + quad2DVertices[2].Color = SColor(0xFFFFFFFF); + quad2DVertices[3].Color = SColor(0xFFFFFFFF); + + drawQuad(vt2DImage, quad2DVertices); +} + +void COpenGL3DriverBase::draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect, + SColor color, bool useAlphaChannelOfTexture) +{ + if (!texture) + return; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture)) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + if (clipRect) { + if (!clipRect->isValid()) + return; + + GL.Enable(GL_SCISSOR_TEST); + GL.Scissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); + assert(6 * drawCount <= QuadIndexCount); // FIXME split the batch? or let it crash? + + core::array vtx(drawCount * 4); + + for (u32 i = 0; i < drawCount; i++) { + core::position2d targetPos = positions[i]; + core::position2d sourcePos = sourceRects[i].UpperLeftCorner; + // This needs to be signed as it may go negative. + core::dimension2d sourceSize(sourceRects[i].getSize()); + + // now draw it. + + core::rect tcoords; + tcoords.UpperLeftCorner.X = (((f32)sourcePos.X)) / texture->getOriginalSize().Width; + tcoords.UpperLeftCorner.Y = (((f32)sourcePos.Y)) / texture->getOriginalSize().Height; + tcoords.LowerRightCorner.X = tcoords.UpperLeftCorner.X + ((f32)(sourceSize.Width) / texture->getOriginalSize().Width); + tcoords.LowerRightCorner.Y = tcoords.UpperLeftCorner.Y + ((f32)(sourceSize.Height) / texture->getOriginalSize().Height); + + const core::rect poss(targetPos, sourceSize); + + f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + vtx.push_back(S3DVertex(left, top, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); + vtx.push_back(S3DVertex(right, top, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); + vtx.push_back(S3DVertex(right, down, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); + vtx.push_back(S3DVertex(left, down, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); + } + + GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, QuadIndexBuffer); + drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), vtx.size(), 0, 6 * drawCount); + GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + if (clipRect) + GL.Disable(GL_SCISSOR_TEST); +} + +//! draw a 2d rectangle +void COpenGL3DriverBase::draw2DRectangle(SColor color, + const core::rect &position, + const core::rect *clip) +{ + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, 0, 0); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, 0, 0); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, 0, 0); + + drawQuad(vtPrimitive, vertices); +} + +//! draw an 2d rectangle +void COpenGL3DriverBase::draw2DRectangle(const core::rect &position, + SColor colorLeftUp, SColor colorRightUp, + SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip) +{ + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(colorLeftUp.getAlpha() < 255 || + colorRightUp.getAlpha() < 255 || + colorLeftDown.getAlpha() < 255 || + colorRightDown.getAlpha() < 255, + false, false); + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, colorLeftUp, 0, 0); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, colorRightUp, 0, 0); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, colorRightDown, 0, 0); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, colorLeftDown, 0, 0); + + drawQuad(vtPrimitive, vertices); +} + +//! Draws a 2d line. +void COpenGL3DriverBase::draw2DLine(const core::position2d &start, + const core::position2d &end, SColor color) +{ + { + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); + + f32 startX = (f32)start.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 endX = (f32)end.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 startY = 2.f - (f32)start.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 endY = 2.f - (f32)end.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[2]; + vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1); + + drawArrays(GL_LINES, vtPrimitive, vertices, 2); + } +} + +void COpenGL3DriverBase::drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]) +{ + drawArrays(GL_TRIANGLE_FAN, vertexType, vertices, 4); +} + +void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) +{ + beginDraw(vertexType, reinterpret_cast(vertices)); + GL.DrawArrays(primitiveType, 0, vertexCount); + endDraw(vertexType); +} + +void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount) +{ + beginDraw(vertexType, reinterpret_cast(vertices)); + GL.DrawRangeElements(primitiveType, 0, vertexCount - 1, indexCount, GL_UNSIGNED_SHORT, indices); + endDraw(vertexType); +} + +void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) +{ + for (auto attr : vertexType) { + GL.EnableVertexAttribArray(attr.Index); + switch (attr.mode) { + case VertexAttribute::Mode::Regular: + GL.VertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); + break; + case VertexAttribute::Mode::Normalized: + GL.VertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); + break; + case VertexAttribute::Mode::Integral: + GL.VertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); + break; + } + } +} + +void COpenGL3DriverBase::endDraw(const VertexType &vertexType) +{ + for (auto attr : vertexType) + GL.DisableVertexAttribArray(attr.Index); +} + +ITexture *COpenGL3DriverBase::createDeviceDependentTexture(const io::path &name, IImage *image) +{ + core::array imageArray(1); + imageArray.push_back(image); + + COpenGL3Texture *texture = new COpenGL3Texture(name, imageArray, ETT_2D, this); + + return texture; +} + +ITexture *COpenGL3DriverBase::createDeviceDependentTextureCubemap(const io::path &name, const core::array &image) +{ + COpenGL3Texture *texture = new COpenGL3Texture(name, image, ETT_CUBEMAP, this); + + return texture; +} + +//! Sets a material. +void COpenGL3DriverBase::setMaterial(const SMaterial &material) +{ + Material = material; + OverrideMaterial.apply(Material); + + for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) { + CacheHandler->getTextureCache().set(i, material.getTexture(i)); + setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); + } +} + +//! prints error if an error happened. +bool COpenGL3DriverBase::testGLError(int code) +{ +#ifdef _DEBUG + GLenum g = GL.GetError(); + switch (g) { + case GL_NO_ERROR: + return false; + case GL_INVALID_ENUM: + os::Printer::log("GL_INVALID_ENUM", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_INVALID_VALUE: + os::Printer::log("GL_INVALID_VALUE", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_INVALID_OPERATION: + os::Printer::log("GL_INVALID_OPERATION", core::stringc(code).c_str(), ELL_ERROR); + break; + case GL_OUT_OF_MEMORY: + os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); + break; + }; + return true; +#else + return false; +#endif +} + +//! prints error if an error happened. +bool COpenGL3DriverBase::testEGLError() +{ +#if defined(EGL_VERSION_1_0) && defined(_DEBUG) + EGLint g = eglGetError(); + switch (g) { + case EGL_SUCCESS: + return false; + case EGL_NOT_INITIALIZED: + os::Printer::log("Not Initialized", ELL_ERROR); + break; + case EGL_BAD_ACCESS: + os::Printer::log("Bad Access", ELL_ERROR); + break; + case EGL_BAD_ALLOC: + os::Printer::log("Bad Alloc", ELL_ERROR); + break; + case EGL_BAD_ATTRIBUTE: + os::Printer::log("Bad Attribute", ELL_ERROR); + break; + case EGL_BAD_CONTEXT: + os::Printer::log("Bad Context", ELL_ERROR); + break; + case EGL_BAD_CONFIG: + os::Printer::log("Bad Config", ELL_ERROR); + break; + case EGL_BAD_CURRENT_SURFACE: + os::Printer::log("Bad Current Surface", ELL_ERROR); + break; + case EGL_BAD_DISPLAY: + os::Printer::log("Bad Display", ELL_ERROR); + break; + case EGL_BAD_SURFACE: + os::Printer::log("Bad Surface", ELL_ERROR); + break; + case EGL_BAD_MATCH: + os::Printer::log("Bad Match", ELL_ERROR); + break; + case EGL_BAD_PARAMETER: + os::Printer::log("Bad Parameter", ELL_ERROR); + break; + case EGL_BAD_NATIVE_PIXMAP: + os::Printer::log("Bad Native Pixmap", ELL_ERROR); + break; + case EGL_BAD_NATIVE_WINDOW: + os::Printer::log("Bad Native Window", ELL_ERROR); + break; + case EGL_CONTEXT_LOST: + os::Printer::log("Context Lost", ELL_ERROR); + break; + }; + return true; +#else + return false; +#endif +} + +void COpenGL3DriverBase::setRenderStates3DMode() +{ + if (LockRenderStateMode) + return; + + if (CurrentRenderMode != ERM_3D) { + // Reset Texture Stages + CacheHandler->setBlend(false); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + ResetRenderStates = true; + } + + if (ResetRenderStates || LastMaterial != Material) { + // unset old material + + // unset last 3d material + if (CurrentRenderMode == ERM_2D && MaterialRenderer2DActive) { + MaterialRenderer2DActive->OnUnsetMaterial(); + MaterialRenderer2DActive = 0; + } else if (LastMaterial.MaterialType != Material.MaterialType && + static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + + // set new material. + if (static_cast(Material.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial( + Material, LastMaterial, ResetRenderStates, this); + + LastMaterial = Material; + CacheHandler->correctCacheMaterial(LastMaterial); + ResetRenderStates = false; + } + + if (static_cast(Material.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, video::EVT_STANDARD); + + CurrentRenderMode = ERM_3D; +} + +//! Can be called by an IMaterialRenderer to make its work easier. +void COpenGL3DriverBase::setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, bool resetAllRenderStates) +{ + // ZBuffer + switch (material.ZBuffer) { + case ECFN_DISABLED: + CacheHandler->setDepthTest(false); + break; + case ECFN_LESSEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LEQUAL); + break; + case ECFN_EQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_EQUAL); + break; + case ECFN_LESS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LESS); + break; + case ECFN_NOTEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NOTEQUAL); + break; + case ECFN_GREATEREQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GEQUAL); + break; + case ECFN_GREATER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GREATER); + break; + case ECFN_ALWAYS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_ALWAYS); + break; + case ECFN_NEVER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NEVER); + break; + default: + break; + } + + // ZWrite + if (getWriteZBuffer(material)) { + CacheHandler->setDepthMask(true); + } else { + CacheHandler->setDepthMask(false); + } + + // Back face culling + if ((material.FrontfaceCulling) && (material.BackfaceCulling)) { + CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK); + CacheHandler->setCullFace(true); + } else if (material.BackfaceCulling) { + CacheHandler->setCullFaceFunc(GL_BACK); + CacheHandler->setCullFace(true); + } else if (material.FrontfaceCulling) { + CacheHandler->setCullFaceFunc(GL_FRONT); + CacheHandler->setCullFace(true); + } else { + CacheHandler->setCullFace(false); + } + + // Color Mask + CacheHandler->setColorMask(material.ColorMask); + + // Blend Equation + if (material.BlendOperation == EBO_NONE) + CacheHandler->setBlend(false); + else { + CacheHandler->setBlend(true); + + switch (material.BlendOperation) { + case EBO_ADD: + CacheHandler->setBlendEquation(GL_FUNC_ADD); + break; + case EBO_SUBTRACT: + CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT); + break; + case EBO_REVSUBTRACT: + CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + break; + case EBO_MIN: + if (BlendMinMaxSupported) + CacheHandler->setBlendEquation(GL_MIN); + else + os::Printer::log("Attempt to use EBO_MIN without driver support", ELL_WARNING); + break; + case EBO_MAX: + if (BlendMinMaxSupported) + CacheHandler->setBlendEquation(GL_MAX); + else + os::Printer::log("Attempt to use EBO_MAX without driver support", ELL_WARNING); + break; + default: + break; + } + } + + // Blend Factor + if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF? + && material.MaterialType != EMT_ONETEXTURE_BLEND) { + E_BLEND_FACTOR srcRGBFact = EBF_ZERO; + E_BLEND_FACTOR dstRGBFact = EBF_ZERO; + E_BLEND_FACTOR srcAlphaFact = EBF_ZERO; + E_BLEND_FACTOR dstAlphaFact = EBF_ZERO; + E_MODULATE_FUNC modulo = EMFN_MODULATE_1X; + u32 alphaSource = 0; + + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, material.BlendFactor); + + CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact), + getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact)); + } + + // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver. + + if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) + GL.LineWidth(core::clamp(static_cast(material.Thickness), DimAliasedLine[0], DimAliasedLine[1])); + + // Anti aliasing + if (resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing) { + if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) + GL.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE); + else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) + GL.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } + + // Texture parameters + setTextureRenderStates(material, resetAllRenderStates); +} + +//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. +void COpenGL3DriverBase::setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates) +{ + // Set textures to TU/TIU and apply filters to them + + for (s32 i = Feature.MaxTextureUnits - 1; i >= 0; --i) { + const COpenGL3Texture *tmpTexture = CacheHandler->getTextureCache()[i]; + + if (!tmpTexture) + continue; + + GLenum tmpTextureType = tmpTexture->getOpenGLTextureType(); + + CacheHandler->setActiveTexture(GL_TEXTURE0 + i); + + if (resetAllRenderstates) + tmpTexture->getStatesCache().IsCached = false; + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].MagFilter != tmpTexture->getStatesCache().MagFilter) { + E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter; + GL.TexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER, + magFilter == ETMAGF_NEAREST ? GL_NEAREST : (assert(magFilter == ETMAGF_LINEAR), GL_LINEAR)); + + tmpTexture->getStatesCache().MagFilter = magFilter; + } + + if (material.UseMipMaps && tmpTexture->hasMipMaps()) { + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].MinFilter != tmpTexture->getStatesCache().MinFilter || + !tmpTexture->getStatesCache().MipMapStatus) { + E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; + GL.TexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST : minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST + : minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR + : (assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR)); + + tmpTexture->getStatesCache().MinFilter = minFilter; + tmpTexture->getStatesCache().MipMapStatus = true; + } + } else { + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].MinFilter != tmpTexture->getStatesCache().MinFilter || + tmpTexture->getStatesCache().MipMapStatus) { + E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; + GL.TexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + (minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST : (assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR)); + + tmpTexture->getStatesCache().MinFilter = minFilter; + tmpTexture->getStatesCache().MipMapStatus = false; + } + } + + if (AnisotropicFilterSupported && + (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].AnisotropicFilter != tmpTexture->getStatesCache().AnisotropicFilter)) { + GL.TexParameteri(tmpTextureType, GL.TEXTURE_MAX_ANISOTROPY, + material.TextureLayers[i].AnisotropicFilter > 1 ? core::min_(MaxAnisotropy, material.TextureLayers[i].AnisotropicFilter) : 1); + + tmpTexture->getStatesCache().AnisotropicFilter = material.TextureLayers[i].AnisotropicFilter; + } + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].TextureWrapU != tmpTexture->getStatesCache().WrapU) { + GL.TexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayers[i].TextureWrapU)); + tmpTexture->getStatesCache().WrapU = material.TextureLayers[i].TextureWrapU; + } + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].TextureWrapV != tmpTexture->getStatesCache().WrapV) { + GL.TexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayers[i].TextureWrapV)); + tmpTexture->getStatesCache().WrapV = material.TextureLayers[i].TextureWrapV; + } + + tmpTexture->getStatesCache().IsCached = true; + } +} + +// Get OpenGL ES2.0 texture wrap mode from Irrlicht wrap mode. +GLint COpenGL3DriverBase::getTextureWrapMode(u8 clamp) const +{ + switch (clamp) { + case ETC_CLAMP: + case ETC_CLAMP_TO_EDGE: + case ETC_CLAMP_TO_BORDER: + return GL_CLAMP_TO_EDGE; + case ETC_MIRROR: + return GL_REPEAT; + default: + return GL_REPEAT; + } +} + +//! sets the needed renderstates +void COpenGL3DriverBase::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) +{ + if (LockRenderStateMode) + return; + + COpenGL3Renderer2D *nextActiveRenderer = texture ? MaterialRenderer2DTexture : MaterialRenderer2DNoTexture; + + if (CurrentRenderMode != ERM_2D) { + // unset last 3d material + if (CurrentRenderMode == ERM_3D) { + if (static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + } + + CurrentRenderMode = ERM_2D; + } else if (MaterialRenderer2DActive && MaterialRenderer2DActive != nextActiveRenderer) { + MaterialRenderer2DActive->OnUnsetMaterial(); + } + + MaterialRenderer2DActive = nextActiveRenderer; + + MaterialRenderer2DActive->OnSetMaterial(Material, LastMaterial, true, 0); + LastMaterial = Material; + CacheHandler->correctCacheMaterial(LastMaterial); + + // no alphaChannel without texture + alphaChannel &= texture; + + if (alphaChannel || alpha) { + CacheHandler->setBlend(true); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + CacheHandler->setBlendEquation(GL_FUNC_ADD); + } else + CacheHandler->setBlend(false); + + Material.setTexture(0, const_cast(CacheHandler->getTextureCache().get(0))); + setTransform(ETS_TEXTURE_0, core::IdentityMatrix); + + if (texture) { + if (OverrideMaterial2DEnabled) + setTextureRenderStates(OverrideMaterial2D, false); + else + setTextureRenderStates(InitMaterial2D, false); + } + + MaterialRenderer2DActive->OnRender(this, video::EVT_STANDARD); +} + +void COpenGL3DriverBase::chooseMaterial2D() +{ + if (!OverrideMaterial2DEnabled) + Material = InitMaterial2D; + + if (OverrideMaterial2DEnabled) { + OverrideMaterial2D.Lighting = false; + OverrideMaterial2D.ZWriteEnable = EZW_OFF; + OverrideMaterial2D.ZBuffer = ECFN_DISABLED; // it will be ECFN_DISABLED after merge + OverrideMaterial2D.Lighting = false; + + Material = OverrideMaterial2D; + } +} + +//! \return Returns the name of the video driver. +const char *COpenGL3DriverBase::getName() const +{ + return Name.c_str(); +} + +void COpenGL3DriverBase::setViewPort(const core::rect &area) +{ + core::rect vp = area; + core::rect rendert(0, 0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height); + vp.clipAgainst(rendert); + + if (vp.getHeight() > 0 && vp.getWidth() > 0) + CacheHandler->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight()); + + ViewPort = vp; +} + +void COpenGL3DriverBase::setViewPortRaw(u32 width, u32 height) +{ + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); +} + +//! Draws a 3d line. +void COpenGL3DriverBase::draw3DLine(const core::vector3df &start, + const core::vector3df &end, SColor color) +{ + setRenderStates3DMode(); + + S3DVertex vertices[2]; + vertices[0] = S3DVertex(start.X, start.Y, start.Z, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(end.X, end.Y, end.Z, 0, 0, 1, color, 0, 0); + + drawArrays(GL_LINES, vtPrimitive, vertices, 2); +} + +//! Only used by the internal engine. Used to notify the driver that +//! the window was resized. +void COpenGL3DriverBase::OnResize(const core::dimension2d &size) +{ + CNullDriver::OnResize(size); + CacheHandler->setViewport(0, 0, size.Width, size.Height); + Transformation3DChanged = true; +} + +//! Returns type of video driver +E_DRIVER_TYPE COpenGL3DriverBase::getDriverType() const +{ + return EDT_OPENGL3; +} + +//! returns color format +ECOLOR_FORMAT COpenGL3DriverBase::getColorFormat() const +{ + return ColorFormat; +} + +//! Get a vertex shader constant index. +s32 COpenGL3DriverBase::getVertexShaderConstantID(const c8 *name) +{ + return getPixelShaderConstantID(name); +} + +//! Get a pixel shader constant index. +s32 COpenGL3DriverBase::getPixelShaderConstantID(const c8 *name) +{ + os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID()."); + return -1; +} + +//! Sets a constant for the vertex shader based on an index. +bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const f32 *floats, int count) +{ + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; +} + +//! Int interface for the above. +bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const s32 *ints, int count) +{ + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; +} + +bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const u32 *ints, int count) +{ + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; +} + +//! Sets a constant for the pixel shader based on an index. +bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const f32 *floats, int count) +{ + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; +} + +//! Int interface for the above. +bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const s32 *ints, int count) +{ + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; +} + +bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const u32 *ints, int count) +{ + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; +} + +//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. +s32 COpenGL3DriverBase::addHighLevelShaderMaterial( + const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName, + E_VERTEX_SHADER_TYPE vsCompileTarget, + const c8 *pixelShaderProgram, + const c8 *pixelShaderEntryPointName, + E_PIXEL_SHADER_TYPE psCompileTarget, + const c8 *geometryShaderProgram, + const c8 *geometryShaderEntryPointName, + E_GEOMETRY_SHADER_TYPE gsCompileTarget, + scene::E_PRIMITIVE_TYPE inType, + scene::E_PRIMITIVE_TYPE outType, + u32 verticesOut, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) +{ + s32 nr = -1; + COpenGL3MaterialRenderer *r = new COpenGL3MaterialRenderer( + this, nr, vertexShaderProgram, + pixelShaderProgram, + callback, baseMaterial, userData); + + r->drop(); + return nr; +} + +//! Returns a pointer to the IVideoDriver interface. (Implementation for +//! IMaterialRendererServices) +IVideoDriver *COpenGL3DriverBase::getVideoDriver() +{ + return this; +} + +//! Returns pointer to the IGPUProgrammingServices interface. +IGPUProgrammingServices *COpenGL3DriverBase::getGPUProgrammingServices() +{ + return this; +} + +ITexture *COpenGL3DriverBase::addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format) +{ + // disable mip-mapping + bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); + + COpenGL3Texture *renderTargetTexture = new COpenGL3Texture(name, size, ETT_2D, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + // restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; +} + +ITexture *COpenGL3DriverBase::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path &name, const ECOLOR_FORMAT format) +{ + // disable mip-mapping + bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); + + bool supportForFBO = (Feature.ColorAttachment > 0); + + const core::dimension2d size(sideLen, sideLen); + core::dimension2du destSize(size); + + if (!supportForFBO) { + destSize = core::dimension2d(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height)); + destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false); + } + + COpenGL3Texture *renderTargetTexture = new COpenGL3Texture(name, destSize, ETT_CUBEMAP, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + // restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; +} + +//! Returns the maximum amount of primitives +u32 COpenGL3DriverBase::getMaximalPrimitiveCount() const +{ + return 65535; +} + +bool COpenGL3DriverBase::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +{ + if (target && target->getDriverType() != getDriverType()) { + os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL 3 driver.", ELL_ERROR); + return false; + } + + core::dimension2d destRenderTargetSize(0, 0); + + if (target) { + COpenGL3RenderTarget *renderTarget = static_cast(target); + + CacheHandler->setFBO(renderTarget->getBufferID()); + renderTarget->update(); + + destRenderTargetSize = renderTarget->getSize(); + + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); + } else { + CacheHandler->setFBO(0); + + destRenderTargetSize = core::dimension2d(0, 0); + + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); + } + + if (CurrentRenderTargetSize != destRenderTargetSize) { + CurrentRenderTargetSize = destRenderTargetSize; + + Transformation3DChanged = true; + } + + CurrentRenderTarget = target; + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; +} + +void COpenGL3DriverBase::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) +{ + GLbitfield mask = 0; + u8 colorMask = 0; + bool depthMask = false; + + CacheHandler->getColorMask(colorMask); + CacheHandler->getDepthMask(depthMask); + + if (flag & ECBF_COLOR) { + CacheHandler->setColorMask(ECP_ALL); + + const f32 inv = 1.0f / 255.0f; + GL.ClearColor(color.getRed() * inv, color.getGreen() * inv, + color.getBlue() * inv, color.getAlpha() * inv); + + mask |= GL_COLOR_BUFFER_BIT; + } + + if (flag & ECBF_DEPTH) { + CacheHandler->setDepthMask(true); + GL.ClearDepthf(depth); + mask |= GL_DEPTH_BUFFER_BIT; + } + + if (flag & ECBF_STENCIL) { + GL.ClearStencil(stencil); + mask |= GL_STENCIL_BUFFER_BIT; + } + + if (mask) + GL.Clear(mask); + + CacheHandler->setColorMask(colorMask); + CacheHandler->setDepthMask(depthMask); +} + +//! Returns an image created from the last rendered frame. +// We want to read the front buffer to get the latest render finished. +// This is not possible under ogl-es, though, so one has to call this method +// outside of the render loop only. +IImage *COpenGL3DriverBase::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target) +{ + if (target == video::ERT_MULTI_RENDER_TEXTURES || target == video::ERT_RENDER_TEXTURE || target == video::ERT_STEREO_BOTH_BUFFERS) + return 0; + + GLint internalformat = GL_RGBA; + GLint type = GL_UNSIGNED_BYTE; + { + // GL.GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalformat); + // GL.GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &type); + // there's a format we don't support ATM + if (GL_UNSIGNED_SHORT_4_4_4_4 == type) { + internalformat = GL_RGBA; + type = GL_UNSIGNED_BYTE; + } + } + + IImage *newImage = 0; + if (GL_RGBA == internalformat) { + if (GL_UNSIGNED_BYTE == type) + newImage = new CImage(ECF_A8R8G8B8, ScreenSize); + else + newImage = new CImage(ECF_A1R5G5B5, ScreenSize); + } else { + if (GL_UNSIGNED_BYTE == type) + newImage = new CImage(ECF_R8G8B8, ScreenSize); + else + newImage = new CImage(ECF_R5G6B5, ScreenSize); + } + + if (!newImage) + return 0; + + u8 *pixels = static_cast(newImage->getData()); + if (!pixels) { + newImage->drop(); + return 0; + } + + GL.ReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); + testGLError(__LINE__); + + // opengl images are horizontally flipped, so we have to fix that here. + const s32 pitch = newImage->getPitch(); + u8 *p2 = pixels + (ScreenSize.Height - 1) * pitch; + u8 *tmpBuffer = new u8[pitch]; + for (u32 i = 0; i < ScreenSize.Height; i += 2) { + memcpy(tmpBuffer, pixels, pitch); + memcpy(pixels, p2, pitch); + memcpy(p2, tmpBuffer, pitch); + pixels += pitch; + p2 -= pitch; + } + delete[] tmpBuffer; + + // also GL_RGBA doesn't match the internal encoding of the image (which is BGRA) + if (GL_RGBA == internalformat && GL_UNSIGNED_BYTE == type) { + pixels = static_cast(newImage->getData()); + for (u32 i = 0; i < ScreenSize.Height; i++) { + for (u32 j = 0; j < ScreenSize.Width; j++) { + u32 c = *(u32 *)(pixels + 4 * j); + *(u32 *)(pixels + 4 * j) = (c & 0xFF00FF00) | + ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16); + } + pixels += pitch; + } + } + + if (testGLError(__LINE__)) { + newImage->drop(); + return 0; + } + testGLError(__LINE__); + return newImage; +} + +void COpenGL3DriverBase::removeTexture(ITexture *texture) +{ + CacheHandler->getTextureCache().remove(texture); + CNullDriver::removeTexture(texture); +} + +//! Set/unset a clipping plane. +bool COpenGL3DriverBase::setClipPlane(u32 index, const core::plane3df &plane, bool enable) +{ + if (index >= UserClipPlane.size()) + UserClipPlane.push_back(SUserClipPlane()); + + UserClipPlane[index].Plane = plane; + UserClipPlane[index].Enabled = enable; + return true; +} + +//! Enable/disable a clipping plane. +void COpenGL3DriverBase::enableClipPlane(u32 index, bool enable) +{ + UserClipPlane[index].Enabled = enable; +} + +//! Get the ClipPlane Count +u32 COpenGL3DriverBase::getClipPlaneCount() const +{ + return UserClipPlane.size(); +} + +const core::plane3df &COpenGL3DriverBase::getClipPlane(irr::u32 index) const +{ + if (index < UserClipPlane.size()) + return UserClipPlane[index].Plane; + else { + _IRR_DEBUG_BREAK_IF(true) // invalid index + static const core::plane3df dummy; + return dummy; + } +} + +core::dimension2du COpenGL3DriverBase::getMaxTextureSize() const +{ + return core::dimension2du(MaxTextureSize, MaxTextureSize); +} + +GLenum COpenGL3DriverBase::getGLBlend(E_BLEND_FACTOR factor) const +{ + static GLenum const blendTable[] = { + GL_ZERO, + GL_ONE, + GL_DST_COLOR, + GL_ONE_MINUS_DST_COLOR, + GL_SRC_COLOR, + GL_ONE_MINUS_SRC_COLOR, + GL_SRC_ALPHA, + GL_ONE_MINUS_SRC_ALPHA, + GL_DST_ALPHA, + GL_ONE_MINUS_DST_ALPHA, + GL_SRC_ALPHA_SATURATE, + }; + + return blendTable[factor]; +} + +bool COpenGL3DriverBase::getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, + GLenum &pixelType, void (**converter)(const void *, s32, void *)) const +{ + auto &info = TextureFormats[format]; + internalFormat = info.InternalFormat; + pixelFormat = info.PixelFormat; + pixelType = info.PixelType; + *converter = info.Converter; + return info.InternalFormat != 0; +} + +bool COpenGL3DriverBase::queryTextureFormat(ECOLOR_FORMAT format) const +{ + return TextureFormats[format].InternalFormat != 0; +} + +bool COpenGL3DriverBase::needsTransparentRenderPass(const irr::video::SMaterial &material) const +{ + return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); +} + +const SMaterial &COpenGL3DriverBase::getCurrentMaterial() const +{ + return Material; +} + +COpenGL3CacheHandler *COpenGL3DriverBase::getCacheHandler() const +{ + return CacheHandler; +} + +} // end namespace +} // end namespace diff --git a/irr/src/OpenGL/Driver.h b/irr/src/OpenGL/Driver.h new file mode 100644 index 000000000..fefb12e2b --- /dev/null +++ b/irr/src/OpenGL/Driver.h @@ -0,0 +1,399 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "SIrrCreationParameters.h" + +#include "Common.h" +#include "CNullDriver.h" +#include "IMaterialRendererServices.h" +#include "EDriverFeatures.h" +#include "fast_atof.h" +#include "ExtensionHandler.h" +#include "IContextManager.h" + +namespace irr +{ +namespace video +{ +struct VertexType; + +class COpenGL3FixedPipelineRenderer; +class COpenGL3Renderer2D; + +class COpenGL3DriverBase : public CNullDriver, public IMaterialRendererServices, public COpenGL3ExtensionHandler +{ + friend class COpenGLCoreTexture; + +protected: + //! constructor (use createOpenGL3Driver instead) + COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + +public: + //! destructor + virtual ~COpenGL3DriverBase(); + + virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0, + const SExposedVideoData &videoData = SExposedVideoData(), core::rect *sourceRect = 0) override; + + bool endScene() override; + + //! sets transformation + void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) override; + + struct SHWBufferLink_opengl : public SHWBufferLink + { + SHWBufferLink_opengl(const scene::IMeshBuffer *meshBuffer) : + SHWBufferLink(meshBuffer), vbo_verticesID(0), vbo_indicesID(0), vbo_verticesSize(0), vbo_indicesSize(0) + { + } + + u32 vbo_verticesID; // tmp + u32 vbo_indicesID; // tmp + + u32 vbo_verticesSize; // tmp + u32 vbo_indicesSize; // tmp + }; + + bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + + //! updates hardware buffer if needed + bool updateHardwareBuffer(SHWBufferLink *HWBuffer) override; + + //! Create hardware buffer from mesh + SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer *mb) override; + + //! Delete hardware buffer (only some drivers can) + void deleteHardwareBuffer(SHWBufferLink *HWBuffer) override; + + //! Draw hardware buffer + void drawHardwareBuffer(SHWBufferLink *HWBuffer) override; + + IRenderTarget *addRenderTarget() override; + + //! draws a vertex primitive list + virtual void drawVertexPrimitiveList(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) override; + + //! queries the features of the driver, returns true if feature is available + bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override + { + return FeatureEnabled[feature] && COpenGL3ExtensionHandler::queryFeature(feature); + } + + //! Sets a material. + void setMaterial(const SMaterial &material) override; + + virtual void draw2DImage(const video::ITexture *texture, + const core::position2d &destPos, + const core::rect &sourceRect, const core::rect *clipRect = 0, + SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override; + + virtual void draw2DImage(const video::ITexture *texture, const core::rect &destRect, + const core::rect &sourceRect, const core::rect *clipRect = 0, + const video::SColor *const colors = 0, bool useAlphaChannelOfTexture = false) override; + + // internally used + virtual void draw2DImage(const video::ITexture *texture, u32 layer, bool flip); + + void draw2DImageBatch(const video::ITexture *texture, + const core::array> &positions, + const core::array> &sourceRects, + const core::rect *clipRect, + SColor color, + bool useAlphaChannelOfTexture) override; + + //! draw an 2d rectangle + virtual void draw2DRectangle(SColor color, const core::rect &pos, + const core::rect *clip = 0) override; + + //! Draws an 2d rectangle with a gradient. + virtual void draw2DRectangle(const core::rect &pos, + SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, + const core::rect *clip = 0) override; + + //! Draws a 2d line. + virtual void draw2DLine(const core::position2d &start, + const core::position2d &end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! Draws a 3d line. + virtual void draw3DLine(const core::vector3df &start, + const core::vector3df &end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! Returns the name of the video driver. + const char *getName() const override; + + //! Returns the maximum texture size supported. + core::dimension2du getMaxTextureSize() const override; + + //! sets a viewport + void setViewPort(const core::rect &area) override; + + //! Only used internally by the engine + void OnResize(const core::dimension2d &size) override; + + //! Returns type of video driver + E_DRIVER_TYPE getDriverType() const override; + + //! get color format of the current color buffer + ECOLOR_FORMAT getColorFormat() const override; + + //! Returns the transformation set by setTransform + const core::matrix4 &getTransform(E_TRANSFORMATION_STATE state) const override; + + //! Can be called by an IMaterialRenderer to make its work easier. + void setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, bool resetAllRenderstates) override; + + //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. + void setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates); + + //! Get a vertex shader constant index. + s32 getVertexShaderConstantID(const c8 *name) override; + + //! Get a pixel shader constant index. + s32 getPixelShaderConstantID(const c8 *name) override; + + //! Sets a constant for the vertex shader based on an index. + bool setVertexShaderConstant(s32 index, const f32 *floats, int count) override; + + //! Int interface for the above. + bool setVertexShaderConstant(s32 index, const s32 *ints, int count) override; + + //! Uint interface for the above. + bool setVertexShaderConstant(s32 index, const u32 *ints, int count) override; + + //! Sets a constant for the pixel shader based on an index. + bool setPixelShaderConstant(s32 index, const f32 *floats, int count) override; + + //! Int interface for the above. + bool setPixelShaderConstant(s32 index, const s32 *ints, int count) override; + + //! Uint interface for the above. + bool setPixelShaderConstant(s32 index, const u32 *ints, int count) override; + + //! Adds a new material renderer to the VideoDriver + virtual s32 addHighLevelShaderMaterial( + const c8 *vertexShaderProgram, + const c8 *vertexShaderEntryPointName = 0, + E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1, + const c8 *pixelShaderProgram = 0, + const c8 *pixelShaderEntryPointName = 0, + E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1, + const c8 *geometryShaderProgram = 0, + const c8 *geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, + s32 userData = 0) override; + + //! Returns pointer to the IGPUProgrammingServices interface. + IGPUProgrammingServices *getGPUProgrammingServices() override; + + //! Returns a pointer to the IVideoDriver interface. + IVideoDriver *getVideoDriver() override; + + //! Returns the maximum amount of primitives + u32 getMaximalPrimitiveCount() const override; + + virtual ITexture *addRenderTargetTexture(const core::dimension2d &size, + const io::path &name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override; + + //! Creates a render target texture for a cubemap + ITexture *addRenderTargetTextureCubemap(const irr::u32 sideLen, + const io::path &name, const ECOLOR_FORMAT format) override; + + virtual bool setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), + f32 clearDepth = 1.f, u8 clearStencil = 0) override; + + void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) override; + + //! Returns an image created from the last rendered frame. + IImage *createScreenShot(video::ECOLOR_FORMAT format = video::ECF_UNKNOWN, video::E_RENDER_TARGET target = video::ERT_FRAME_BUFFER) override; + + //! checks if an OpenGL error has happened and prints it (+ some internal code which is usually the line number) + bool testGLError(int code = 0); + + //! checks if an OGLES1 error has happened and prints it + bool testEGLError(); + + //! Set/unset a clipping plane. + bool setClipPlane(u32 index, const core::plane3df &plane, bool enable = false) override; + + //! returns the current amount of user clip planes set. + u32 getClipPlaneCount() const; + + //! returns the 0 indexed Plane + const core::plane3df &getClipPlane(u32 index) const; + + //! Enable/disable a clipping plane. + void enableClipPlane(u32 index, bool enable) override; + + //! Returns the graphics card vendor name. + core::stringc getVendorInfo() override + { + return VendorName; + }; + + void removeTexture(ITexture *texture) override; + + //! Check if the driver supports creating textures with the given color format + bool queryTextureFormat(ECOLOR_FORMAT format) const override; + + //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass + bool needsTransparentRenderPass(const irr::video::SMaterial &material) const override; + + //! Convert E_BLEND_FACTOR to OpenGL equivalent + GLenum getGLBlend(E_BLEND_FACTOR factor) const; + + virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, + GLenum &pixelType, void (**converter)(const void *, s32, void *)) const; + + //! Get current material. + const SMaterial &getCurrentMaterial() const; + + COpenGL3CacheHandler *getCacheHandler() const; + +protected: + virtual bool genericDriverInit(const core::dimension2d &screenSize, bool stencilBuffer); + + void initVersion(); + virtual OpenGLVersion getVersionFromOpenGL() const = 0; + + virtual void initFeatures() = 0; + + bool isVersionAtLeast(int major, int minor = 0) const noexcept; + + void chooseMaterial2D(); + + ITexture *createDeviceDependentTexture(const io::path &name, IImage *image) override; + + ITexture *createDeviceDependentTextureCubemap(const io::path &name, const core::array &image) override; + + //! Map Irrlicht wrap mode to OpenGL enum + GLint getTextureWrapMode(u8 clamp) const; + + //! sets the needed renderstates + void setRenderStates3DMode(); + + //! sets the needed renderstates + void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel); + + //! Prevent setRenderStateMode calls to do anything. + // hack to allow drawing meshbuffers in 2D mode. + // Better solution would be passing this flag through meshbuffers, + // but the way this is currently implemented in Irrlicht makes this tricky to implement + void lockRenderStateMode() + { + LockRenderStateMode = true; + } + + //! Allow setRenderStateMode calls to work again + void unlockRenderStateMode() + { + LockRenderStateMode = false; + } + + void draw2D3DVertexPrimitiveList(const void *vertices, + u32 vertexCount, const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, + E_INDEX_TYPE iType, bool is3D); + + void createMaterialRenderers(); + + void loadShaderData(const io::path &vertexShaderName, const io::path &fragmentShaderName, c8 **vertexShaderData, c8 **fragmentShaderData); + + bool setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture *texture); + + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + + void drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]); + void drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount); + void drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount); + void drawElements(GLenum primitiveType, const VertexType &vertexType, uintptr_t vertices, uintptr_t indices, int indexCount); + + void beginDraw(const VertexType &vertexType, uintptr_t verticesBase); + void endDraw(const VertexType &vertexType); + + COpenGL3CacheHandler *CacheHandler; + core::stringc Name; + core::stringc VendorName; + SIrrlichtCreationParameters Params; + OpenGLVersion Version; + + //! bool to make all renderstates reset if set to true. + bool ResetRenderStates; + bool LockRenderStateMode; + u8 AntiAlias; + + struct SUserClipPlane + { + core::plane3df Plane; + bool Enabled; + }; + + core::array UserClipPlane; + + core::matrix4 TextureFlipMatrix; + + using FColorConverter = void (*)(const void *source, s32 count, void *dest); + struct STextureFormatInfo + { + GLenum InternalFormat; + GLenum PixelFormat; + GLenum PixelType; + FColorConverter Converter; + }; + STextureFormatInfo TextureFormats[ECF_UNKNOWN] = {}; + +private: + COpenGL3Renderer2D *MaterialRenderer2DActive; + COpenGL3Renderer2D *MaterialRenderer2DTexture; + COpenGL3Renderer2D *MaterialRenderer2DNoTexture; + + core::matrix4 Matrices[ETS_COUNT]; + + //! enumeration for rendering modes such as 2d and 3d for minimizing the switching of renderStates. + enum E_RENDER_MODE + { + ERM_NONE = 0, // no render state has been set yet. + ERM_2D, // 2d drawing rendermode + ERM_3D // 3d rendering mode + }; + + E_RENDER_MODE CurrentRenderMode; + bool Transformation3DChanged; + irr::io::path OGLES2ShaderPath; + + SMaterial Material, LastMaterial; + + //! Color buffer format + ECOLOR_FORMAT ColorFormat; + + IContextManager *ContextManager; + + void printTextureFormats(); + + void addDummyMaterial(E_MATERIAL_TYPE type); + + unsigned QuadIndexCount; + GLuint QuadIndexBuffer = 0; + void initQuadsIndices(int max_vertex_count = 65536); + + void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); + static void APIENTRY debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); +}; + +} // end namespace video +} // end namespace irr diff --git a/irr/src/OpenGL/ExtensionHandler.cpp b/irr/src/OpenGL/ExtensionHandler.cpp new file mode 100644 index 000000000..3ac212987 --- /dev/null +++ b/irr/src/OpenGL/ExtensionHandler.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2015 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// 2017 modified by Michael Zeilfelder (unifying extension handlers) +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "ExtensionHandler.h" + +#include "irrString.h" +#include "SMaterial.h" +#include "fast_atof.h" +#include "os.h" +#include + +// FIXME: this basically duplicates what mt_opengl.h already does + +namespace irr +{ +namespace video +{ +void COpenGL3ExtensionHandler::initExtensionsOld() +{ + auto extensions_string = reinterpret_cast(GL.GetString(GL_EXTENSIONS)); + const char *pos = extensions_string; + while (const char *next = strchr(pos, ' ')) { + addExtension(std::string{pos, next}); + pos = next + 1; + } + addExtension(pos); + extensionsLoaded(); +} + +void COpenGL3ExtensionHandler::initExtensionsNew() +{ + int ext_count = GetInteger(GL_NUM_EXTENSIONS); + for (int k = 0; k < ext_count; k++) + addExtension(reinterpret_cast(GL.GetStringi(GL_EXTENSIONS, k))); + extensionsLoaded(); +} + +void COpenGL3ExtensionHandler::addExtension(std::string &&name) +{ + Extensions.emplace(std::move(name)); +} + +bool COpenGL3ExtensionHandler::queryExtension(const std::string &name) const noexcept +{ + return Extensions.find(name) != Extensions.end(); +} + +void COpenGL3ExtensionHandler::extensionsLoaded() +{ + os::Printer::log((std::string("Loaded ") + std::to_string(Extensions.size()) + " extensions:").c_str(), ELL_DEBUG); + for (const auto &it : Extensions) + os::Printer::log((std::string(" ") + it).c_str(), ELL_DEBUG); + for (size_t j = 0; j < IRR_OGLES_Feature_Count; ++j) + FeatureAvailable[j] = queryExtension(getFeatureString(j)); +} + +} // end namespace video +} // end namespace irr diff --git a/irr/src/OpenGL/ExtensionHandler.h b/irr/src/OpenGL/ExtensionHandler.h new file mode 100644 index 000000000..8f96f0d4a --- /dev/null +++ b/irr/src/OpenGL/ExtensionHandler.h @@ -0,0 +1,170 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2015 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include + +#include "EDriverFeatures.h" +#include "irrTypes.h" +#include "os.h" + +#include "Common.h" +#include // must be after Common.h + +#include "COGLESCoreExtensionHandler.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3ExtensionHandler : public COGLESCoreExtensionHandler +{ +public: + COpenGL3ExtensionHandler() : + COGLESCoreExtensionHandler() {} + + void initExtensionsOld(); + void initExtensionsNew(); + + /// Checks whether a named extension is present + bool queryExtension(const std::string &name) const noexcept; + + bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const + { + switch (feature) { + case EVDF_RENDER_TO_TARGET: + case EVDF_HARDWARE_TL: + case EVDF_MULTITEXTURE: + case EVDF_BILINEAR_FILTER: + case EVDF_MIP_MAP: + case EVDF_MIP_MAP_AUTO_UPDATE: + case EVDF_VERTEX_SHADER_1_1: + case EVDF_PIXEL_SHADER_1_1: + case EVDF_PIXEL_SHADER_1_2: + case EVDF_PIXEL_SHADER_2_0: + case EVDF_VERTEX_SHADER_2_0: + case EVDF_ARB_GLSL: + case EVDF_TEXTURE_NSQUARE: + case EVDF_TEXTURE_NPOT: + case EVDF_FRAMEBUFFER_OBJECT: + case EVDF_VERTEX_BUFFER_OBJECT: + case EVDF_COLOR_MASK: + case EVDF_ALPHA_TO_COVERAGE: + case EVDF_POLYGON_OFFSET: + case EVDF_BLEND_OPERATIONS: + case EVDF_BLEND_SEPARATE: + case EVDF_TEXTURE_MATRIX: + case EVDF_TEXTURE_CUBEMAP: + return true; + case EVDF_ARB_VERTEX_PROGRAM_1: + case EVDF_ARB_FRAGMENT_PROGRAM_1: + case EVDF_GEOMETRY_SHADER: + case EVDF_MULTIPLE_RENDER_TARGETS: + case EVDF_MRT_BLEND: + case EVDF_MRT_COLOR_MASK: + case EVDF_MRT_BLEND_FUNC: + case EVDF_OCCLUSION_QUERY: + return false; + case EVDF_STENCIL_BUFFER: + return StencilBuffer; + default: + return false; + }; + } + + static GLint GetInteger(GLenum key) + { + GLint val = 0; + GL.GetIntegerv(key, &val); + return val; + }; + + inline void irrGlActiveTexture(GLenum texture) + { + GL.ActiveTexture(texture); + } + + inline void irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, + GLsizei imageSize, const void *data) + { + os::Printer::log("Compressed textures aren't supported", ELL_ERROR); + } + + inline void irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, + GLenum format, GLsizei imageSize, const void *data) + { + os::Printer::log("Compressed textures aren't supported", ELL_ERROR); + } + + inline void irrGlUseProgram(GLuint prog) + { + GL.UseProgram(prog); + } + + inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer) + { + GL.BindFramebuffer(target, framebuffer); + } + + inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) + { + GL.DeleteFramebuffers(n, framebuffers); + } + + inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) + { + GL.GenFramebuffers(n, framebuffers); + } + + inline GLenum irrGlCheckFramebufferStatus(GLenum target) + { + return GL.CheckFramebufferStatus(target); + } + + inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) + { + GL.FramebufferTexture2D(target, attachment, textarget, texture, level); + } + + inline void irrGlGenerateMipmap(GLenum target) + { + GL.GenerateMipmap(target); + } + + inline void irrGlDrawBuffer(GLenum mode) + { + GL.DrawBuffer(mode); + } + + inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) + { + GL.DrawBuffers(n, bufs); + } + + inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) + { + GL.BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + } + + inline void irrGlBlendEquation(GLenum mode) + { + GL.BlendEquation(mode); + } + + bool AnisotropicFilterSupported = false; + bool BlendMinMaxSupported = false; + +private: + void addExtension(std::string &&name); + void extensionsLoaded(); + + std::unordered_set Extensions; +}; + +} +} diff --git a/irr/src/OpenGL/FixedPipelineRenderer.cpp b/irr/src/OpenGL/FixedPipelineRenderer.cpp new file mode 100644 index 000000000..7c4adf719 --- /dev/null +++ b/irr/src/OpenGL/FixedPipelineRenderer.cpp @@ -0,0 +1,186 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "FixedPipelineRenderer.h" + +#include "IVideoDriver.h" + +namespace irr +{ +namespace video +{ + +// Base callback + +COpenGL3MaterialBaseCB::COpenGL3MaterialBaseCB() : + FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-1), + FogEnableID(-1), FogTypeID(-1), FogColorID(-1), FogStartID(-1), + FogEndID(-1), FogDensityID(-1), ThicknessID(-1), LightEnable(false), MaterialAmbient(SColorf(0.f, 0.f, 0.f)), MaterialDiffuse(SColorf(0.f, 0.f, 0.f)), MaterialEmissive(SColorf(0.f, 0.f, 0.f)), MaterialSpecular(SColorf(0.f, 0.f, 0.f)), + MaterialShininess(0.f), FogEnable(0), FogType(1), FogColor(SColorf(0.f, 0.f, 0.f, 1.f)), FogStart(0.f), FogEnd(0.f), FogDensity(0.f), Thickness(1.f) +{ +} + +void COpenGL3MaterialBaseCB::OnSetMaterial(const SMaterial &material) +{ + LightEnable = material.Lighting; + MaterialAmbient = SColorf(material.AmbientColor); + MaterialDiffuse = SColorf(material.DiffuseColor); + MaterialEmissive = SColorf(material.EmissiveColor); + MaterialSpecular = SColorf(material.SpecularColor); + MaterialShininess = material.Shininess; + + FogEnable = material.FogEnable ? 1 : 0; + + Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; +} + +void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices *services, s32 userData) +{ + IVideoDriver *driver = services->getVideoDriver(); + + if (FirstUpdateBase) { + WVPMatrixID = services->getVertexShaderConstantID("uWVPMatrix"); + WVMatrixID = services->getVertexShaderConstantID("uWVMatrix"); + NMatrixID = services->getVertexShaderConstantID("uNMatrix"); + + FogEnableID = services->getVertexShaderConstantID("uFogEnable"); + FogTypeID = services->getVertexShaderConstantID("uFogType"); + FogColorID = services->getVertexShaderConstantID("uFogColor"); + FogStartID = services->getVertexShaderConstantID("uFogStart"); + FogEndID = services->getVertexShaderConstantID("uFogEnd"); + FogDensityID = services->getVertexShaderConstantID("uFogDensity"); + ThicknessID = services->getVertexShaderConstantID("uThickness"); + + FirstUpdateBase = false; + } + + const core::matrix4 W = driver->getTransform(ETS_WORLD); + const core::matrix4 V = driver->getTransform(ETS_VIEW); + const core::matrix4 P = driver->getTransform(ETS_PROJECTION); + + core::matrix4 Matrix = P * V * W; + services->setPixelShaderConstant(WVPMatrixID, Matrix.pointer(), 16); + + Matrix = V * W; + services->setPixelShaderConstant(WVMatrixID, Matrix.pointer(), 16); + + Matrix.makeInverse(); + services->setPixelShaderConstant(NMatrixID, Matrix.getTransposed().pointer(), 16); + + services->setPixelShaderConstant(FogEnableID, &FogEnable, 1); + + if (FogEnable) { + SColor TempColor(0); + E_FOG_TYPE TempType = EFT_FOG_LINEAR; + bool TempPerFragment = false; + bool TempRange = false; + + driver->getFog(TempColor, TempType, FogStart, FogEnd, FogDensity, TempPerFragment, TempRange); + + FogType = (s32)TempType; + FogColor = SColorf(TempColor); + + services->setPixelShaderConstant(FogTypeID, &FogType, 1); + services->setPixelShaderConstant(FogColorID, reinterpret_cast(&FogColor), 4); + services->setPixelShaderConstant(FogStartID, &FogStart, 1); + services->setPixelShaderConstant(FogEndID, &FogEnd, 1); + services->setPixelShaderConstant(FogDensityID, &FogDensity, 1); + } + + services->setPixelShaderConstant(ThicknessID, &Thickness, 1); +} + +// EMT_SOLID + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA + +COpenGL3MaterialSolidCB::COpenGL3MaterialSolidCB() : + FirstUpdate(true), TMatrix0ID(-1), AlphaRefID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), AlphaRef(0.5f), TextureUsage0(0), TextureUnit0(0) +{ +} + +void COpenGL3MaterialSolidCB::OnSetMaterial(const SMaterial &material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + AlphaRef = material.MaterialTypeParam; + TextureUsage0 = (material.TextureLayers[0].Texture) ? 1 : 0; +} + +void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices *services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver *driver = services->getVideoDriver(); + + if (FirstUpdate) { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + AlphaRefID = services->getVertexShaderConstantID("uAlphaRef"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(AlphaRefID, &AlphaRef, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); +} + +// EMT_ONETEXTURE_BLEND + +COpenGL3MaterialOneTextureBlendCB::COpenGL3MaterialOneTextureBlendCB() : + FirstUpdate(true), TMatrix0ID(-1), BlendTypeID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), BlendType(0), TextureUsage0(0), TextureUnit0(0) +{ +} + +void COpenGL3MaterialOneTextureBlendCB::OnSetMaterial(const SMaterial &material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + BlendType = 0; + + E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) { + if (alphaSource == EAS_VERTEX_COLOR) { + BlendType = 1; + } else if (alphaSource == EAS_TEXTURE) { + BlendType = 2; + } + } + + TextureUsage0 = (material.TextureLayers[0].Texture) ? 1 : 0; +} + +void COpenGL3MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices *services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver *driver = services->getVideoDriver(); + + if (FirstUpdate) { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + BlendTypeID = services->getVertexShaderConstantID("uBlendType"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(BlendTypeID, &BlendType, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); +} + +} +} diff --git a/irr/src/OpenGL/FixedPipelineRenderer.h b/irr/src/OpenGL/FixedPipelineRenderer.h new file mode 100644 index 000000000..a07af1df9 --- /dev/null +++ b/irr/src/OpenGL/FixedPipelineRenderer.h @@ -0,0 +1,101 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "IShaderConstantSetCallBack.h" +#include "IMaterialRendererServices.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3MaterialBaseCB : public IShaderConstantSetCallBack +{ +public: + COpenGL3MaterialBaseCB(); + + virtual void OnSetMaterial(const SMaterial &material); + virtual void OnSetConstants(IMaterialRendererServices *services, s32 userData); + +protected: + bool FirstUpdateBase; + + s32 WVPMatrixID; + s32 WVMatrixID; + s32 NMatrixID; + + s32 FogEnableID; + s32 FogTypeID; + s32 FogColorID; + s32 FogStartID; + s32 FogEndID; + s32 FogDensityID; + + s32 ThicknessID; + + bool LightEnable; + SColorf GlobalAmbient; + SColorf MaterialAmbient; + SColorf MaterialDiffuse; + SColorf MaterialEmissive; + SColorf MaterialSpecular; + f32 MaterialShininess; + + s32 FogEnable; + s32 FogType; + SColorf FogColor; + f32 FogStart; + f32 FogEnd; + f32 FogDensity; + + f32 Thickness; +}; + +class COpenGL3MaterialSolidCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialSolidCB(); + + virtual void OnSetMaterial(const SMaterial &material); + virtual void OnSetConstants(IMaterialRendererServices *services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 AlphaRefID; + s32 TextureUsage0ID; + s32 TextureUnit0ID; + + f32 AlphaRef; + s32 TextureUsage0; + s32 TextureUnit0; +}; + +class COpenGL3MaterialOneTextureBlendCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialOneTextureBlendCB(); + + virtual void OnSetMaterial(const SMaterial &material); + virtual void OnSetConstants(IMaterialRendererServices *services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 BlendTypeID; + s32 TextureUsage0ID; + s32 TextureUnit0ID; + + s32 BlendType; + s32 TextureUsage0; + s32 TextureUnit0; +}; + +} +} diff --git a/irr/src/OpenGL/MaterialRenderer.cpp b/irr/src/OpenGL/MaterialRenderer.cpp new file mode 100644 index 000000000..51a796d48 --- /dev/null +++ b/irr/src/OpenGL/MaterialRenderer.cpp @@ -0,0 +1,429 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "MaterialRenderer.h" + +#include "EVertexAttributes.h" +#include "IGPUProgrammingServices.h" +#include "IShaderConstantSetCallBack.h" +#include "IVideoDriver.h" +#include "os.h" + +#include "Driver.h" + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreCacheHandler.h" + +namespace irr +{ +namespace video +{ + +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase *driver, + s32 &outMaterialTypeNr, + const c8 *vertexShaderProgram, + const c8 *pixelShaderProgram, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) : + Driver(driver), + CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData) +{ +#ifdef _DEBUG + setDebugName("MaterialRenderer"); +#endif + + switch (baseMaterial) { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); + + init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram); +} + +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase *driver, + IShaderConstantSetCallBack *callback, + E_MATERIAL_TYPE baseMaterial, s32 userData) : + Driver(driver), + CallBack(callback), Alpha(false), Blending(false), Program(0), UserData(userData) +{ + switch (baseMaterial) { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); +} + +COpenGL3MaterialRenderer::~COpenGL3MaterialRenderer() +{ + if (CallBack) + CallBack->drop(); + + if (Program) { + GLuint shaders[8]; + GLint count; + GL.GetAttachedShaders(Program, 8, &count, shaders); + + count = core::min_(count, 8); + for (GLint i = 0; i < count; ++i) + GL.DeleteShader(shaders[i]); + GL.DeleteProgram(Program); + Program = 0; + } + + UniformInfo.clear(); +} + +GLuint COpenGL3MaterialRenderer::getProgram() const +{ + return Program; +} + +void COpenGL3MaterialRenderer::init(s32 &outMaterialTypeNr, + const c8 *vertexShaderProgram, + const c8 *pixelShaderProgram, + bool addMaterial) +{ + outMaterialTypeNr = -1; + + Program = GL.CreateProgram(); + + if (!Program) + return; + + if (vertexShaderProgram) + if (!createShader(GL_VERTEX_SHADER, vertexShaderProgram)) + return; + + if (pixelShaderProgram) + if (!createShader(GL_FRAGMENT_SHADER, pixelShaderProgram)) + return; + + for (size_t i = 0; i < EVA_COUNT; ++i) + GL.BindAttribLocation(Program, i, sBuiltInVertexAttributeNames[i]); + + if (!linkProgram()) + return; + + if (addMaterial) + outMaterialTypeNr = Driver->addMaterialRenderer(this); +} + +bool COpenGL3MaterialRenderer::OnRender(IMaterialRendererServices *service, E_VERTEX_TYPE vtxtype) +{ + if (CallBack && Program) + CallBack->OnSetConstants(this, UserData); + + return true; +} + +void COpenGL3MaterialRenderer::OnSetMaterial(const video::SMaterial &material, + const video::SMaterial &lastMaterial, + bool resetAllRenderstates, + video::IMaterialRendererServices *services) +{ + COpenGL3CacheHandler *cacheHandler = Driver->getCacheHandler(); + + cacheHandler->setProgram(Program); + + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + if (Alpha) { + cacheHandler->setBlend(true); + cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } else if (Blending) { + E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), + Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); + + cacheHandler->setBlend(true); + } + + if (CallBack) + CallBack->OnSetMaterial(material); +} + +void COpenGL3MaterialRenderer::OnUnsetMaterial() +{ +} + +bool COpenGL3MaterialRenderer::isTransparent() const +{ + return (Alpha || Blending); +} + +s32 COpenGL3MaterialRenderer::getRenderCapability() const +{ + return 0; +} + +bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char *shader) +{ + if (Program) { + GLuint shaderHandle = GL.CreateShader(shaderType); + GL.ShaderSource(shaderHandle, 1, &shader, NULL); + GL.CompileShader(shaderHandle); + + GLint status = 0; + + GL.GetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status); + + if (status != GL_TRUE) { + os::Printer::log("GLSL shader failed to compile", ELL_ERROR); + + GLint maxLength = 0; + GLint length; + + GL.GetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, + &maxLength); + + if (maxLength) { + GLchar *infoLog = new GLchar[maxLength]; + GL.GetShaderInfoLog(shaderHandle, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete[] infoLog; + } + + return false; + } + + GL.AttachShader(Program, shaderHandle); + } + + return true; +} + +bool COpenGL3MaterialRenderer::linkProgram() +{ + if (Program) { + GL.LinkProgram(Program); + + GLint status = 0; + + GL.GetProgramiv(Program, GL_LINK_STATUS, &status); + + if (!status) { + os::Printer::log("GLSL shader program failed to link", ELL_ERROR); + + GLint maxLength = 0; + GLsizei length; + + GL.GetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength); + + if (maxLength) { + GLchar *infoLog = new GLchar[maxLength]; + GL.GetProgramInfoLog(Program, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete[] infoLog; + } + + return false; + } + + GLint num = 0; + + GL.GetProgramiv(Program, GL_ACTIVE_UNIFORMS, &num); + + if (num == 0) + return true; + + GLint maxlen = 0; + + GL.GetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen); + + if (maxlen == 0) { + os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR); + return false; + } + + // seems that some implementations use an extra null terminator. + ++maxlen; + c8 *buf = new c8[maxlen]; + + UniformInfo.clear(); + UniformInfo.reallocate(num); + + for (GLint i = 0; i < num; ++i) { + SUniformInfo ui; + memset(buf, 0, maxlen); + + GLint size; + GL.GetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); + + core::stringc name = ""; + + // array support, workaround for some bugged drivers. + for (s32 i = 0; i < maxlen; ++i) { + if (buf[i] == '[' || buf[i] == '\0') + break; + + name += buf[i]; + } + + ui.name = name; + ui.location = GL.GetUniformLocation(Program, buf); + + UniformInfo.push_back(ui); + } + + delete[] buf; + } + + return true; +} + +void COpenGL3MaterialRenderer::setBasicRenderStates(const SMaterial &material, + const SMaterial &lastMaterial, + bool resetAllRenderstates) +{ + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); +} + +s32 COpenGL3MaterialRenderer::getVertexShaderConstantID(const c8 *name) +{ + return getPixelShaderConstantID(name); +} + +s32 COpenGL3MaterialRenderer::getPixelShaderConstantID(const c8 *name) +{ + for (u32 i = 0; i < UniformInfo.size(); ++i) { + if (UniformInfo[i].name == name) + return i; + } + + return -1; +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const f32 *floats, int count) +{ + return setPixelShaderConstant(index, floats, count); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const s32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const u32 *ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const f32 *floats, int count) +{ + if (index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) { + case GL_FLOAT: + GL.Uniform1fv(UniformInfo[index].location, count, floats); + break; + case GL_FLOAT_VEC2: + GL.Uniform2fv(UniformInfo[index].location, count / 2, floats); + break; + case GL_FLOAT_VEC3: + GL.Uniform3fv(UniformInfo[index].location, count / 3, floats); + break; + case GL_FLOAT_VEC4: + GL.Uniform4fv(UniformInfo[index].location, count / 4, floats); + break; + case GL_FLOAT_MAT2: + GL.UniformMatrix2fv(UniformInfo[index].location, count / 4, false, floats); + break; + case GL_FLOAT_MAT3: + GL.UniformMatrix3fv(UniformInfo[index].location, count / 9, false, floats); + break; + case GL_FLOAT_MAT4: + GL.UniformMatrix4fv(UniformInfo[index].location, count / 16, false, floats); + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: { + if (floats) { + const GLint id = (GLint)(*floats); + GL.Uniform1iv(UniformInfo[index].location, 1, &id); + } else + status = false; + } break; + default: + status = false; + break; + } + + return status; +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const s32 *ints, int count) +{ + if (index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) { + case GL_INT: + case GL_BOOL: + GL.Uniform1iv(UniformInfo[index].location, count, ints); + break; + case GL_INT_VEC2: + case GL_BOOL_VEC2: + GL.Uniform2iv(UniformInfo[index].location, count / 2, ints); + break; + case GL_INT_VEC3: + case GL_BOOL_VEC3: + GL.Uniform3iv(UniformInfo[index].location, count / 3, ints); + break; + case GL_INT_VEC4: + case GL_BOOL_VEC4: + GL.Uniform4iv(UniformInfo[index].location, count / 4, ints); + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + GL.Uniform1iv(UniformInfo[index].location, 1, ints); + break; + default: + status = false; + break; + } + + return status; +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const u32 *ints, int count) +{ + os::Printer::log("Unsigned int support needs at least GLES 3.0", ELL_WARNING); + return false; +} + +IVideoDriver *COpenGL3MaterialRenderer::getVideoDriver() +{ + return Driver; +} + +} +} diff --git a/irr/src/OpenGL/MaterialRenderer.h b/irr/src/OpenGL/MaterialRenderer.h new file mode 100644 index 000000000..be74461e3 --- /dev/null +++ b/irr/src/OpenGL/MaterialRenderer.h @@ -0,0 +1,93 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "EMaterialTypes.h" +#include "IMaterialRenderer.h" +#include "IMaterialRendererServices.h" +#include "IGPUProgrammingServices.h" +#include "irrArray.h" +#include "irrString.h" + +#include "Common.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3DriverBase; + +class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices +{ +public: + COpenGL3MaterialRenderer( + COpenGL3DriverBase *driver, + s32 &outMaterialTypeNr, + const c8 *vertexShaderProgram = 0, + const c8 *pixelShaderProgram = 0, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = EMT_SOLID, + s32 userData = 0); + + virtual ~COpenGL3MaterialRenderer(); + + GLuint getProgram() const; + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services); + + virtual bool OnRender(IMaterialRendererServices *service, E_VERTEX_TYPE vtxtype); + + virtual void OnUnsetMaterial(); + + virtual bool isTransparent() const; + + virtual s32 getRenderCapability() const; + + void setBasicRenderStates(const SMaterial &material, const SMaterial &lastMaterial, bool resetAllRenderstates) override; + + s32 getVertexShaderConstantID(const c8 *name) override; + s32 getPixelShaderConstantID(const c8 *name) override; + bool setVertexShaderConstant(s32 index, const f32 *floats, int count) override; + bool setVertexShaderConstant(s32 index, const s32 *ints, int count) override; + bool setVertexShaderConstant(s32 index, const u32 *ints, int count) override; + bool setPixelShaderConstant(s32 index, const f32 *floats, int count) override; + bool setPixelShaderConstant(s32 index, const s32 *ints, int count) override; + bool setPixelShaderConstant(s32 index, const u32 *ints, int count) override; + + IVideoDriver *getVideoDriver() override; + +protected: + COpenGL3MaterialRenderer(COpenGL3DriverBase *driver, + IShaderConstantSetCallBack *callback = 0, + E_MATERIAL_TYPE baseMaterial = EMT_SOLID, + s32 userData = 0); + + void init(s32 &outMaterialTypeNr, const c8 *vertexShaderProgram, const c8 *pixelShaderProgram, bool addMaterial = true); + + bool createShader(GLenum shaderType, const char *shader); + bool linkProgram(); + + COpenGL3DriverBase *Driver; + IShaderConstantSetCallBack *CallBack; + + bool Alpha; + bool Blending; + + struct SUniformInfo + { + core::stringc name; + GLenum type; + GLint location; + }; + + GLuint Program; + core::array UniformInfo; + s32 UserData; +}; + +} +} diff --git a/irr/src/OpenGL/Renderer2D.cpp b/irr/src/OpenGL/Renderer2D.cpp new file mode 100644 index 000000000..b625feda4 --- /dev/null +++ b/irr/src/OpenGL/Renderer2D.cpp @@ -0,0 +1,81 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Renderer2D.h" + +#include "IGPUProgrammingServices.h" +#include "os.h" + +#include "Driver.h" + +#include "COpenGLCoreFeature.h" +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreCacheHandler.h" + +namespace irr +{ +namespace video +{ + +COpenGL3Renderer2D::COpenGL3Renderer2D(const c8 *vertexShaderProgram, const c8 *pixelShaderProgram, COpenGL3DriverBase *driver, bool withTexture) : + COpenGL3MaterialRenderer(driver, 0, EMT_SOLID), + WithTexture(withTexture) +{ +#ifdef _DEBUG + setDebugName("Renderer2D"); +#endif + + int Temp = 0; + + init(Temp, vertexShaderProgram, pixelShaderProgram, false); + + COpenGL3CacheHandler *cacheHandler = Driver->getCacheHandler(); + + cacheHandler->setProgram(Program); + + // These states don't change later. + + ThicknessID = getPixelShaderConstantID("uThickness"); + if (WithTexture) { + TextureUsageID = getPixelShaderConstantID("uTextureUsage"); + s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit"); + + s32 TextureUnit = 0; + setPixelShaderConstant(TextureUnitID, &TextureUnit, 1); + + s32 TextureUsage = 0; + setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); + } + + cacheHandler->setProgram(0); +} + +COpenGL3Renderer2D::~COpenGL3Renderer2D() +{ +} + +void COpenGL3Renderer2D::OnSetMaterial(const video::SMaterial &material, + const video::SMaterial &lastMaterial, + bool resetAllRenderstates, + video::IMaterialRendererServices *services) +{ + Driver->getCacheHandler()->setProgram(Program); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + f32 Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; + setPixelShaderConstant(ThicknessID, &Thickness, 1); + + if (WithTexture) { + s32 TextureUsage = material.TextureLayers[0].Texture ? 1 : 0; + setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); + } +} + +bool COpenGL3Renderer2D::OnRender(IMaterialRendererServices *service, E_VERTEX_TYPE vtxtype) +{ + return true; +} + +} +} diff --git a/irr/src/OpenGL/Renderer2D.h b/irr/src/OpenGL/Renderer2D.h new file mode 100644 index 000000000..6cfc7029d --- /dev/null +++ b/irr/src/OpenGL/Renderer2D.h @@ -0,0 +1,32 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "MaterialRenderer.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3Renderer2D : public COpenGL3MaterialRenderer +{ +public: + COpenGL3Renderer2D(const c8 *vertexShaderProgram, const c8 *pixelShaderProgram, COpenGL3DriverBase *driver, bool withTexture); + ~COpenGL3Renderer2D(); + + virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices *services); + + virtual bool OnRender(IMaterialRendererServices *service, E_VERTEX_TYPE vtxtype); + +protected: + bool WithTexture; + s32 ThicknessID; + s32 TextureUsageID; +}; + +} +} diff --git a/irr/src/OpenGL3/Driver.cpp b/irr/src/OpenGL3/Driver.cpp new file mode 100644 index 000000000..8196a8117 --- /dev/null +++ b/irr/src/OpenGL3/Driver.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Driver.h" +#include +#include "mt_opengl.h" + +namespace irr +{ +namespace video +{ + +E_DRIVER_TYPE COpenGL3Driver::getDriverType() const +{ + return EDT_OPENGL3; +} + +OpenGLVersion COpenGL3Driver::getVersionFromOpenGL() const +{ + GLint major, minor, profile; + GL.GetIntegerv(GL_MAJOR_VERSION, &major); + GL.GetIntegerv(GL_MINOR_VERSION, &minor); + GL.GetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile); + // The spec is clear a context can’t be both core and compatibility at the same time. + // However, the returned value is a mask. Ask Khronos why. -- numzero + if (profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) + return {OpenGLSpec::Compat, (u8)major, (u8)minor, 0}; + if (profile & GL_CONTEXT_CORE_PROFILE_BIT) + return {OpenGLSpec::Core, (u8)major, (u8)minor, 0}; + os::Printer::log("Got unrecognized OpenGL profile", ELL_ERROR); + return {OpenGLSpec::Core, (u8)major, (u8)minor, 0}; +} + +void COpenGL3Driver::initFeatures() +{ + assert(Version.Spec == OpenGLSpec::Compat); + assert(isVersionAtLeast(3, 2)); + initExtensionsNew(); + + TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable + TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; // GL_RGB565 is an extension until 4.1 + TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; // WARNING: may not be renderable + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}; + TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; + TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; + TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}; + TextureFormats[ECF_R32F] = {GL_R32F, GL_RED, GL_FLOAT}; + TextureFormats[ECF_G32R32F] = {GL_RG32F, GL_RG, GL_FLOAT}; + TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA32F, GL_RGBA, GL_FLOAT}; + TextureFormats[ECF_R8] = {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R16] = {GL_R16, GL_RED, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_R16G16] = {GL_RG16, GL_RG, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; // WARNING: may not be renderable (?!) + TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + + AnisotropicFilterSupported = isVersionAtLeast(4, 6) || queryExtension("GL_ARB_texture_filter_anisotropic") || queryExtension("GL_EXT_texture_filter_anisotropic"); + BlendMinMaxSupported = true; + + // COGLESCoreExtensionHandler::Feature + static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed"); + Feature.BlendOperation = true; + Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; + Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + + // COGLESCoreExtensionHandler + if (AnisotropicFilterSupported) + MaxAnisotropy = GetInteger(GL.MAX_TEXTURE_MAX_ANISOTROPY); + MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); + GL.GetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + GL.GetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); + DimAliasedPoint[0] = 1.0f; + DimAliasedPoint[1] = 1.0f; +} + +IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ + os::Printer::log("Using COpenGL3Driver", ELL_INFORMATION); + COpenGL3Driver *driver = new COpenGL3Driver(params, io, contextManager); + driver->genericDriverInit(params.WindowSize, params.Stencilbuffer); // don't call in constructor, it uses virtual function calls of driver + return driver; +} + +} +} diff --git a/irr/src/OpenGL3/Driver.h b/irr/src/OpenGL3/Driver.h new file mode 100644 index 000000000..f4934051e --- /dev/null +++ b/irr/src/OpenGL3/Driver.h @@ -0,0 +1,30 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once +#include "OpenGL/Driver.h" + +namespace irr +{ +namespace video +{ + +/// OpenGL 3+ driver +/// +/// For OpenGL 3.2 and higher. Compatibility profile is required currently. +class COpenGL3Driver : public COpenGL3DriverBase +{ + friend IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + +public: + using COpenGL3DriverBase::COpenGL3DriverBase; + E_DRIVER_TYPE getDriverType() const override; + +protected: + OpenGLVersion getVersionFromOpenGL() const override; + void initFeatures() override; +}; + +} +} diff --git a/irr/src/OpenGLES2/Driver.cpp b/irr/src/OpenGLES2/Driver.cpp new file mode 100644 index 000000000..6278ee9c3 --- /dev/null +++ b/irr/src/OpenGLES2/Driver.cpp @@ -0,0 +1,147 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Driver.h" +#include +#include + +namespace irr +{ +namespace video +{ + +E_DRIVER_TYPE COpenGLES2Driver::getDriverType() const +{ + return EDT_OGLES2; +} + +OpenGLVersion COpenGLES2Driver::getVersionFromOpenGL() const +{ + auto version_string = reinterpret_cast(GL.GetString(GL_VERSION)); + int major, minor; + if (sscanf(version_string, "OpenGL ES %d.%d", &major, &minor) != 2) { + os::Printer::log("Failed to parse OpenGL ES version string", version_string, ELL_ERROR); + return {OpenGLSpec::ES, 0, 0, 0}; + } + return {OpenGLSpec::ES, (u8)major, (u8)minor, 0}; +} + +void COpenGLES2Driver::initFeatures() +{ + assert(Version.Spec == OpenGLSpec::ES); + assert(Version.Major >= 2); + if (Version.Major >= 3) + initExtensionsNew(); + else + initExtensionsOld(); + + static const GLenum BGRA8_EXT = 0x93A1; + + if (Version.Major >= 3) { + // NOTE floating-point formats may not be suitable for render targets. + TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; + TextureFormats[ECF_R5G6B5] = {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; + TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; + TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; + TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; + TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}; + TextureFormats[ECF_R32F] = {GL_R32F, GL_RED, GL_FLOAT}; + TextureFormats[ECF_G32R32F] = {GL_RG32F, GL_RG, GL_FLOAT}; + TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA32F, GL_RGBA, GL_FLOAT}; + TextureFormats[ECF_R8] = {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + + if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE}; + else if (FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {BGRA8_EXT, GL_BGRA, GL_UNSIGNED_BYTE}; + + if (FeatureAvailable[IRR_GL_OES_depth32]) + TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; + } else { + // NOTE These are *texture* formats. They may or may not be suitable + // for render targets. The specs only talks on *sized* formats for the + // latter but forbids creating textures with sized internal formats, + // reserving them for renderbuffers. + + static const GLenum HALF_FLOAT_OES = 0x8D61; // not equal to GL_HALF_FLOAT + TextureFormats[ECF_A1R5G5B5] = {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; + TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; + TextureFormats[ECF_R8G8B8] = {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; + + if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE}; + else if (FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {BGRA8_EXT, GL_BGRA, GL_UNSIGNED_BYTE}; + + if (FeatureAvailable[IRR_GL_OES_texture_half_float]) { + TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA, GL_RGBA, HALF_FLOAT_OES}; + } + if (FeatureAvailable[IRR_GL_OES_texture_float]) { + TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA, GL_RGBA, GL_FLOAT}; + } + if (FeatureAvailable[IRR_GL_EXT_texture_rg]) { + TextureFormats[ECF_R8] = {GL_RED, GL_RED, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL_RG, GL_RG, GL_UNSIGNED_BYTE}; + + if (FeatureAvailable[IRR_GL_OES_texture_half_float]) { + TextureFormats[ECF_R16F] = {GL_RED, GL_RED, HALF_FLOAT_OES}; + TextureFormats[ECF_G16R16F] = {GL_RG, GL_RG, HALF_FLOAT_OES}; + } + if (FeatureAvailable[IRR_GL_OES_texture_float]) { + TextureFormats[ECF_R32F] = {GL_RED, GL_RED, GL_FLOAT}; + TextureFormats[ECF_G32R32F] = {GL_RG, GL_RG, GL_FLOAT}; + } + } + + if (FeatureAvailable[IRR_GL_OES_depth_texture]) { + TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + if (FeatureAvailable[IRR_GL_OES_depth32]) + TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; + if (FeatureAvailable[IRR_GL_OES_packed_depth_stencil]) + TextureFormats[ECF_D24S8] = {GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + } + } + + const bool MRTSupported = Version.Major >= 3 || queryExtension("GL_EXT_draw_buffers"); + AnisotropicFilterSupported = queryExtension("GL_EXT_texture_filter_anisotropic"); + BlendMinMaxSupported = (Version.Major >= 3) || FeatureAvailable[IRR_GL_EXT_blend_minmax]; + const bool TextureLODBiasSupported = queryExtension("GL_EXT_texture_lod_bias"); + + // COGLESCoreExtensionHandler::Feature + static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed"); + Feature.BlendOperation = true; + Feature.ColorAttachment = 1; + if (MRTSupported) + Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; + if (MRTSupported) + Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + + // COGLESCoreExtensionHandler + if (AnisotropicFilterSupported) + MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); + if (Version.Major >= 3 || queryExtension("GL_EXT_draw_range_elements")) + MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); + if (TextureLODBiasSupported) + GL.GetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + GL.GetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... + GL.GetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); +} + +IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ + os::Printer::log("Using COpenGLES2Driver", ELL_INFORMATION); + COpenGLES2Driver *driver = new COpenGLES2Driver(params, io, contextManager); + driver->genericDriverInit(params.WindowSize, params.Stencilbuffer); // don't call in constructor, it uses virtual function calls of driver + return driver; +} + +} +} diff --git a/irr/src/OpenGLES2/Driver.h b/irr/src/OpenGLES2/Driver.h new file mode 100644 index 000000000..003f6d454 --- /dev/null +++ b/irr/src/OpenGLES2/Driver.h @@ -0,0 +1,30 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once +#include "OpenGL/Driver.h" + +namespace irr +{ +namespace video +{ + +/// OpenGL ES 2+ driver +/// +/// For OpenGL ES 2.0 and higher. +class COpenGLES2Driver : public COpenGL3DriverBase +{ + friend IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + +public: + using COpenGL3DriverBase::COpenGL3DriverBase; + E_DRIVER_TYPE getDriverType() const override; + +protected: + OpenGLVersion getVersionFromOpenGL() const override; + void initFeatures() override; +}; + +} +} diff --git a/irr/src/SB3DStructs.h b/irr/src/SB3DStructs.h new file mode 100644 index 000000000..b5e61daae --- /dev/null +++ b/irr/src/SB3DStructs.h @@ -0,0 +1,71 @@ +// Copyright (C) 2006-2012 Luke Hoschke +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// B3D Mesh loader +// File format designed by Mark Sibly for the Blitz3D engine and has been +// declared public domain + +#pragma once + +#include "SMaterial.h" +#include "irrMath.h" + +namespace irr +{ +namespace scene +{ + +struct SB3dChunkHeader +{ + c8 name[4]; + s32 size; +}; + +struct SB3dChunk +{ + SB3dChunk(const SB3dChunkHeader &header, long sp) : + length(header.size + 8), startposition(sp) + { + length = core::max_(length, 8); + name[0] = header.name[0]; + name[1] = header.name[1]; + name[2] = header.name[2]; + name[3] = header.name[3]; + } + c8 name[4]; + s32 length; + long startposition; +}; + +struct SB3dTexture +{ + std::string TextureName; + s32 Flags; + s32 Blend; + f32 Xpos; + f32 Ypos; + f32 Xscale; + f32 Yscale; + f32 Angle; +}; + +struct SB3dMaterial +{ + SB3dMaterial() : + red(1.0f), green(1.0f), + blue(1.0f), alpha(1.0f), shininess(0.0f), blend(1), + fx(0) + { + for (u32 i = 0; i < video::MATERIAL_MAX_TEXTURES; ++i) + Textures[i] = 0; + } + video::SMaterial Material; + f32 red, green, blue, alpha; + f32 shininess; + s32 blend, fx; + SB3dTexture *Textures[video::MATERIAL_MAX_TEXTURES]; +}; + +} // end namespace scene +} // end namespace irr diff --git a/irr/src/SoftwareDriver2_helper.h b/irr/src/SoftwareDriver2_helper.h new file mode 100644 index 000000000..602f9e295 --- /dev/null +++ b/irr/src/SoftwareDriver2_helper.h @@ -0,0 +1,290 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +/* + History: + - changed behavior for log2 textures ( replaced multiplies by shift ) +*/ + +#pragma once + +#include "irrMath.h" +#include "SMaterial.h" + +#ifndef REALINLINE +#ifdef _MSC_VER +#define REALINLINE __forceinline +#else +#define REALINLINE inline +#endif +#endif + +namespace irr +{ + +// ----------------------- Generic ---------------------------------- +//! align_next - align to next upper 2^n +#define align_next(num, to) (((num) + (to - 1)) & (~(to - 1))) + +//! a more useful memset for pixel. dest must be aligned at least to 4 byte +// (standard memset only works with 8-bit values) +inline void memset32(void *dest, const u32 value, size_t bytesize) +{ + u32 *d = (u32 *)dest; + + size_t i; + + // loops unrolled to reduce the number of increments by factor ~8. + i = bytesize >> (2 + 3); + while (i) { + d[0] = value; + d[1] = value; + d[2] = value; + d[3] = value; + + d[4] = value; + d[5] = value; + d[6] = value; + d[7] = value; + + d += 8; + i -= 1; + } + + i = (bytesize >> 2) & 7; + while (i) { + d[0] = value; + d += 1; + i -= 1; + } +} + +//! a more useful memset for pixel. dest must be aligned at least to 2 byte +// (standard memset only works with 8-bit values) +inline void memset16(void *dest, const u16 value, size_t bytesize) +{ + u16 *d = (u16 *)dest; + + size_t i; + + // loops unrolled to reduce the number of increments by factor ~8. + i = bytesize >> (1 + 3); + while (i) { + d[0] = value; + d[1] = value; + d[2] = value; + d[3] = value; + + d[4] = value; + d[5] = value; + d[6] = value; + d[7] = value; + + d += 8; + --i; + } + + i = (bytesize >> 1) & 7; + while (i) { + d[0] = value; + ++d; + --i; + } +} + +// integer log2 of an integer. returning 0 as denormal +static inline s32 s32_log2_s32(u32 in) +{ + s32 ret = 0; + while (in > 1) { + in >>= 1; + ret++; + } + return ret; +} + +// ------------------ Video--------------------------------------- +/*! + Pixel = dest * ( 1 - alpha ) + source * alpha + alpha [0;256] +*/ +REALINLINE u32 PixelBlend32(const u32 c2, const u32 c1, const u32 alpha) +{ + u32 srcRB = c1 & 0x00FF00FF; + u32 srcXG = c1 & 0x0000FF00; + + u32 dstRB = c2 & 0x00FF00FF; + u32 dstXG = c2 & 0x0000FF00; + + u32 rb = srcRB - dstRB; + u32 xg = srcXG - dstXG; + + rb *= alpha; + xg *= alpha; + rb >>= 8; + xg >>= 8; + + rb += dstRB; + xg += dstXG; + + rb &= 0x00FF00FF; + xg &= 0x0000FF00; + + return rb | xg; +} + +/*! + Pixel = dest * ( 1 - alpha ) + source * alpha + alpha [0;32] +*/ +inline u16 PixelBlend16(const u16 c2, const u16 c1, const u16 alpha) +{ + const u16 srcRB = c1 & 0x7C1F; + const u16 srcXG = c1 & 0x03E0; + + const u16 dstRB = c2 & 0x7C1F; + const u16 dstXG = c2 & 0x03E0; + + u32 rb = srcRB - dstRB; + u32 xg = srcXG - dstXG; + + rb *= alpha; + xg *= alpha; + rb >>= 5; + xg >>= 5; + + rb += dstRB; + xg += dstXG; + + rb &= 0x7C1F; + xg &= 0x03E0; + + return (u16)(rb | xg); +} + +/* + Pixel = c0 * (c1/31). c0 Alpha retain +*/ +inline u16 PixelMul16(const u16 c0, const u16 c1) +{ + return (u16)(((((c0 & 0x7C00) * (c1 & 0x7C00)) & 0x3E000000) >> 15) | + ((((c0 & 0x03E0) * (c1 & 0x03E0)) & 0x000F8000) >> 10) | + ((((c0 & 0x001F) * (c1 & 0x001F)) & 0x000003E0) >> 5) | + (c0 & 0x8000)); +} + +/* + Pixel = c0 * (c1/31). +*/ +inline u16 PixelMul16_2(u16 c0, u16 c1) +{ + return (u16)((((c0 & 0x7C00) * (c1 & 0x7C00)) & 0x3E000000) >> 15 | + (((c0 & 0x03E0) * (c1 & 0x03E0)) & 0x000F8000) >> 10 | + (((c0 & 0x001F) * (c1 & 0x001F)) & 0x000003E0) >> 5 | + (c0 & c1 & 0x8000)); +} + +/* + Pixel = c0 * (c1/255). c0 Alpha Retain +*/ +REALINLINE u32 PixelMul32(const u32 c0, const u32 c1) +{ + return (c0 & 0xFF000000) | + ((((c0 & 0x00FF0000) >> 12) * ((c1 & 0x00FF0000) >> 12)) & 0x00FF0000) | + ((((c0 & 0x0000FF00) * (c1 & 0x0000FF00)) >> 16) & 0x0000FF00) | + ((((c0 & 0x000000FF) * (c1 & 0x000000FF)) >> 8) & 0x000000FF); +} + +/* + Pixel = c0 * (c1/255). +*/ +REALINLINE u32 PixelMul32_2(const u32 c0, const u32 c1) +{ + return ((((c0 & 0xFF000000) >> 16) * ((c1 & 0xFF000000) >> 16)) & 0xFF000000) | + ((((c0 & 0x00FF0000) >> 12) * ((c1 & 0x00FF0000) >> 12)) & 0x00FF0000) | + ((((c0 & 0x0000FF00) * (c1 & 0x0000FF00)) >> 16) & 0x0000FF00) | + ((((c0 & 0x000000FF) * (c1 & 0x000000FF)) >> 8) & 0x000000FF); +} + +/* + Pixel = clamp ( c0 + c1, 0, 255 ) +*/ +REALINLINE u32 PixelAdd32(const u32 c2, const u32 c1) +{ + u32 sum = (c2 & 0x00FFFFFF) + (c1 & 0x00FFFFFF); + u32 low_bits = (c2 ^ c1) & 0x00010101; + s32 carries = (sum - low_bits) & 0x01010100; + u32 modulo = sum - carries; + u32 clamp = carries - (carries >> 8); + return modulo | clamp; +} + +// 1 - Bit Alpha Blending +inline u16 PixelBlend16(const u16 c2, const u16 c1) +{ + u16 mask = ((c1 & 0x8000) >> 15) + 0x7fff; + return (c2 & mask) | (c1 & ~mask); +} +/*! + Pixel = dest * ( 1 - SourceAlpha ) + source * SourceAlpha (OpenGL blending) +*/ +inline u32 PixelBlend32(const u32 c2, const u32 c1) +{ + // alpha test + u32 alpha = c1 & 0xFF000000; + + if (0 == alpha) + return c2; + if (0xFF000000 == alpha) { + return c1; + } + + alpha >>= 24; + + // add highbit alpha, if ( alpha > 127 ) alpha += 1; + alpha += (alpha >> 7); + + u32 srcRB = c1 & 0x00FF00FF; + u32 srcXG = c1 & 0x0000FF00; + + u32 dstRB = c2 & 0x00FF00FF; + u32 dstXG = c2 & 0x0000FF00; + + u32 rb = srcRB - dstRB; + u32 xg = srcXG - dstXG; + + rb *= alpha; + xg *= alpha; + rb >>= 8; + xg >>= 8; + + rb += dstRB; + xg += dstXG; + + rb &= 0x00FF00FF; + xg &= 0x0000FF00; + + return (c1 & 0xFF000000) | rb | xg; +} + +// 2D Region closed [x0;x1] +struct AbsRectangle +{ + s32 x0; + s32 y0; + s32 x1; + s32 y1; +}; + +//! 2D Intersection test +inline bool intersect(AbsRectangle &dest, const AbsRectangle &a, const AbsRectangle &b) +{ + dest.x0 = core::s32_max(a.x0, b.x0); + dest.y0 = core::s32_max(a.y0, b.y0); + dest.x1 = core::s32_min(a.x1, b.x1); + dest.y1 = core::s32_min(a.y1, b.y1); + return dest.x0 < dest.x1 && dest.y0 < dest.y1; +} + +} // end namespace irr diff --git a/irr/src/builtInFont.png b/irr/src/builtInFont.png new file mode 100644 index 0000000000000000000000000000000000000000..feed4f6f0690389f22b9860ddfe03ec8c5d6fc2a GIT binary patch literal 1381 zcmV-r1)BPaP)_;jje$uc83#KGysgA3MJee~(93TxiMU}A#OzyOd~ zA;QK2?*JCTDlSG7wF&@8#qVNc-T>4n>c@AAf(M|>;0%C5K?@**u))HOB1RGu9PC>K z1JIqx0K8}+5TpUnBytlmwv%ilEKk{%m#59gqBpC**cbv_Z@{XkEfkbHlIV?{zRK^t*rikLlXU!X24glQ&NcRQ|@c>NW z$q7LA7XD2#e=&bAL(0)QC!PB=pmqs?ey$40uspNIfF?_K^$=Jjb{ z8-4=tYXFzM1cj`auwp`k#4;gxt+}I`TxbawO<2ZKoza#x0BbtjEdV=!UH~-R7!4L% z1q7qq0hku%l2(AF94%Dz;;fE@TYLaUrqbK9o?_q+1jI^19LzG3_J zU0SDvUA*0Y05)~ZC4P|Pjdm=dY^}`+vk?c-7;r$|Yk4u*?UC=~k zTWg#fDU6u~H-LsyG~n5G5@U>Fg5uEuB|&KJ*UAq7=|{q*o=4U)jX{~E-H=!u6*Soj zmVN~oQ+-(hIRTWA_%Oe=fNlWj9#>3Wwea!~e<$GQ65f!Z=a^+refDX_X@+RQ%#AnM7l&1C{e@1gskXHd*6uGJAx52M}14 z701vCM+N>7zyfm)?x3TB@B$!nkv@hD)NzQ(IAi9Oa%+HOrhFuS&-HS$c!_PM^Wr~V|tpPYh{^u`1nwd8; zV!~aGa#G0*3#Wwv=n|&}-vD#~fEfT6?NChg3jjf91@{&p2bqx(1Mt2GQT-6W?Rt1X zIr;2U=hRnZ?iMJO+5b;Ge~+2Wd~&!(N0RWl6hOXn&@S6vfonbIp@fXn94|k_6F`XEf1DWNEuTY7k>a|PGS-(PUJMrm_(K#WIC9xjWQJ|2@0)X&BL@X z6)*^403hQv(ldzJ<$eaT2B1fj>>&P;r*j7RK7;r8&<@&7W&c0%{C&-2=94q?A@X)p zc>I5qq(&DP2Fie=hy$eth%m6YkZFhj*Z>y?7eVqo!U&30M?pacAQmCp1r!;;FenUg naRCM*5Rg4bf=H$#6N~}?=lg^k`HsLN00000NkvXXu0mjf{P16s literal 0 HcmV?d00001 diff --git a/irr/src/mt_opengl_loader.cpp b/irr/src/mt_opengl_loader.cpp new file mode 100755 index 000000000..084f83118 --- /dev/null +++ b/irr/src/mt_opengl_loader.cpp @@ -0,0 +1,783 @@ +// This code was generated by scripts/BindingGenerator.lua +// Do not modify it, modify and run the generator instead. + +#include "mt_opengl.h" +#include +#include + +OpenGLProcedures GL = OpenGLProcedures(); + +void OpenGLProcedures::LoadAllProcedures(irr::video::IContextManager *cmgr) +{ + + if (!CullFace) CullFace = (PFNGLCULLFACEPROC_MT)cmgr->getProcAddress("glCullFace"); + if (!FrontFace) FrontFace = (PFNGLFRONTFACEPROC_MT)cmgr->getProcAddress("glFrontFace"); + if (!Hint) Hint = (PFNGLHINTPROC_MT)cmgr->getProcAddress("glHint"); + if (!LineWidth) LineWidth = (PFNGLLINEWIDTHPROC_MT)cmgr->getProcAddress("glLineWidth"); + if (!PointSize) PointSize = (PFNGLPOINTSIZEPROC_MT)cmgr->getProcAddress("glPointSize"); + if (!PolygonMode) PolygonMode = (PFNGLPOLYGONMODEPROC_MT)cmgr->getProcAddress("glPolygonMode"); + if (!Scissor) Scissor = (PFNGLSCISSORPROC_MT)cmgr->getProcAddress("glScissor"); + if (!TexParameterf) TexParameterf = (PFNGLTEXPARAMETERFPROC_MT)cmgr->getProcAddress("glTexParameterf"); + if (!TexParameterfv) TexParameterfv = (PFNGLTEXPARAMETERFVPROC_MT)cmgr->getProcAddress("glTexParameterfv"); + if (!TexParameteri) TexParameteri = (PFNGLTEXPARAMETERIPROC_MT)cmgr->getProcAddress("glTexParameteri"); + if (!TexParameteriv) TexParameteriv = (PFNGLTEXPARAMETERIVPROC_MT)cmgr->getProcAddress("glTexParameteriv"); + if (!TexImage1D) TexImage1D = (PFNGLTEXIMAGE1DPROC_MT)cmgr->getProcAddress("glTexImage1D"); + if (!TexImage2D) TexImage2D = (PFNGLTEXIMAGE2DPROC_MT)cmgr->getProcAddress("glTexImage2D"); + if (!DrawBuffer) DrawBuffer = (PFNGLDRAWBUFFERPROC_MT)cmgr->getProcAddress("glDrawBuffer"); + if (!Clear) Clear = (PFNGLCLEARPROC_MT)cmgr->getProcAddress("glClear"); + if (!ClearColor) ClearColor = (PFNGLCLEARCOLORPROC_MT)cmgr->getProcAddress("glClearColor"); + if (!ClearStencil) ClearStencil = (PFNGLCLEARSTENCILPROC_MT)cmgr->getProcAddress("glClearStencil"); + if (!ClearDepth) ClearDepth = (PFNGLCLEARDEPTHPROC_MT)cmgr->getProcAddress("glClearDepth"); + if (!StencilMask) StencilMask = (PFNGLSTENCILMASKPROC_MT)cmgr->getProcAddress("glStencilMask"); + if (!ColorMask) ColorMask = (PFNGLCOLORMASKPROC_MT)cmgr->getProcAddress("glColorMask"); + if (!DepthMask) DepthMask = (PFNGLDEPTHMASKPROC_MT)cmgr->getProcAddress("glDepthMask"); + if (!Disable) Disable = (PFNGLDISABLEPROC_MT)cmgr->getProcAddress("glDisable"); + if (!Enable) Enable = (PFNGLENABLEPROC_MT)cmgr->getProcAddress("glEnable"); + if (!Finish) Finish = (PFNGLFINISHPROC_MT)cmgr->getProcAddress("glFinish"); + if (!Flush) Flush = (PFNGLFLUSHPROC_MT)cmgr->getProcAddress("glFlush"); + if (!BlendFunc) BlendFunc = (PFNGLBLENDFUNCPROC_MT)cmgr->getProcAddress("glBlendFunc"); + if (!LogicOp) LogicOp = (PFNGLLOGICOPPROC_MT)cmgr->getProcAddress("glLogicOp"); + if (!StencilFunc) StencilFunc = (PFNGLSTENCILFUNCPROC_MT)cmgr->getProcAddress("glStencilFunc"); + if (!StencilOp) StencilOp = (PFNGLSTENCILOPPROC_MT)cmgr->getProcAddress("glStencilOp"); + if (!DepthFunc) DepthFunc = (PFNGLDEPTHFUNCPROC_MT)cmgr->getProcAddress("glDepthFunc"); + if (!PixelStoref) PixelStoref = (PFNGLPIXELSTOREFPROC_MT)cmgr->getProcAddress("glPixelStoref"); + if (!PixelStorei) PixelStorei = (PFNGLPIXELSTOREIPROC_MT)cmgr->getProcAddress("glPixelStorei"); + if (!ReadBuffer) ReadBuffer = (PFNGLREADBUFFERPROC_MT)cmgr->getProcAddress("glReadBuffer"); + if (!ReadPixels) ReadPixels = (PFNGLREADPIXELSPROC_MT)cmgr->getProcAddress("glReadPixels"); + if (!GetBooleanv) GetBooleanv = (PFNGLGETBOOLEANVPROC_MT)cmgr->getProcAddress("glGetBooleanv"); + if (!GetDoublev) GetDoublev = (PFNGLGETDOUBLEVPROC_MT)cmgr->getProcAddress("glGetDoublev"); + if (!GetError) GetError = (PFNGLGETERRORPROC_MT)cmgr->getProcAddress("glGetError"); + if (!GetFloatv) GetFloatv = (PFNGLGETFLOATVPROC_MT)cmgr->getProcAddress("glGetFloatv"); + if (!GetIntegerv) GetIntegerv = (PFNGLGETINTEGERVPROC_MT)cmgr->getProcAddress("glGetIntegerv"); + if (!GetString) GetString = (PFNGLGETSTRINGPROC_MT)cmgr->getProcAddress("glGetString"); + if (!GetTexImage) GetTexImage = (PFNGLGETTEXIMAGEPROC_MT)cmgr->getProcAddress("glGetTexImage"); + if (!GetTexParameterfv) GetTexParameterfv = (PFNGLGETTEXPARAMETERFVPROC_MT)cmgr->getProcAddress("glGetTexParameterfv"); + if (!GetTexParameteriv) GetTexParameteriv = (PFNGLGETTEXPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetTexParameteriv"); + if (!GetTexLevelParameterfv) GetTexLevelParameterfv = (PFNGLGETTEXLEVELPARAMETERFVPROC_MT)cmgr->getProcAddress("glGetTexLevelParameterfv"); + if (!GetTexLevelParameteriv) GetTexLevelParameteriv = (PFNGLGETTEXLEVELPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetTexLevelParameteriv"); + if (!IsEnabled) IsEnabled = (PFNGLISENABLEDPROC_MT)cmgr->getProcAddress("glIsEnabled"); + if (!DepthRange) DepthRange = (PFNGLDEPTHRANGEPROC_MT)cmgr->getProcAddress("glDepthRange"); + if (!Viewport) Viewport = (PFNGLVIEWPORTPROC_MT)cmgr->getProcAddress("glViewport"); + if (!DrawArrays) DrawArrays = (PFNGLDRAWARRAYSPROC_MT)cmgr->getProcAddress("glDrawArrays"); + if (!DrawElements) DrawElements = (PFNGLDRAWELEMENTSPROC_MT)cmgr->getProcAddress("glDrawElements"); + if (!GetPointerv) GetPointerv = (PFNGLGETPOINTERVPROC_MT)cmgr->getProcAddress("glGetPointerv"); + if (!PolygonOffset) PolygonOffset = (PFNGLPOLYGONOFFSETPROC_MT)cmgr->getProcAddress("glPolygonOffset"); + if (!CopyTexImage1D) CopyTexImage1D = (PFNGLCOPYTEXIMAGE1DPROC_MT)cmgr->getProcAddress("glCopyTexImage1D"); + if (!CopyTexImage2D) CopyTexImage2D = (PFNGLCOPYTEXIMAGE2DPROC_MT)cmgr->getProcAddress("glCopyTexImage2D"); + if (!CopyTexSubImage1D) CopyTexSubImage1D = (PFNGLCOPYTEXSUBIMAGE1DPROC_MT)cmgr->getProcAddress("glCopyTexSubImage1D"); + if (!CopyTexSubImage2D) CopyTexSubImage2D = (PFNGLCOPYTEXSUBIMAGE2DPROC_MT)cmgr->getProcAddress("glCopyTexSubImage2D"); + if (!TexSubImage1D) TexSubImage1D = (PFNGLTEXSUBIMAGE1DPROC_MT)cmgr->getProcAddress("glTexSubImage1D"); + if (!TexSubImage2D) TexSubImage2D = (PFNGLTEXSUBIMAGE2DPROC_MT)cmgr->getProcAddress("glTexSubImage2D"); + if (!BindTexture) BindTexture = (PFNGLBINDTEXTUREPROC_MT)cmgr->getProcAddress("glBindTexture"); + if (!DeleteTextures) DeleteTextures = (PFNGLDELETETEXTURESPROC_MT)cmgr->getProcAddress("glDeleteTextures"); + if (!GenTextures) GenTextures = (PFNGLGENTEXTURESPROC_MT)cmgr->getProcAddress("glGenTextures"); + if (!IsTexture) IsTexture = (PFNGLISTEXTUREPROC_MT)cmgr->getProcAddress("glIsTexture"); + if (!DrawRangeElements) DrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC_MT)cmgr->getProcAddress("glDrawRangeElements"); + if (!TexImage3D) TexImage3D = (PFNGLTEXIMAGE3DPROC_MT)cmgr->getProcAddress("glTexImage3D"); + if (!TexSubImage3D) TexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC_MT)cmgr->getProcAddress("glTexSubImage3D"); + if (!CopyTexSubImage3D) CopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC_MT)cmgr->getProcAddress("glCopyTexSubImage3D"); + if (!ActiveTexture) ActiveTexture = (PFNGLACTIVETEXTUREPROC_MT)cmgr->getProcAddress("glActiveTexture"); + if (!SampleCoverage) SampleCoverage = (PFNGLSAMPLECOVERAGEPROC_MT)cmgr->getProcAddress("glSampleCoverage"); + if (!CompressedTexImage3D) CompressedTexImage3D = (PFNGLCOMPRESSEDTEXIMAGE3DPROC_MT)cmgr->getProcAddress("glCompressedTexImage3D"); + if (!CompressedTexImage2D) CompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC_MT)cmgr->getProcAddress("glCompressedTexImage2D"); + if (!CompressedTexImage1D) CompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC_MT)cmgr->getProcAddress("glCompressedTexImage1D"); + if (!CompressedTexSubImage3D) CompressedTexSubImage3D = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC_MT)cmgr->getProcAddress("glCompressedTexSubImage3D"); + if (!CompressedTexSubImage2D) CompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC_MT)cmgr->getProcAddress("glCompressedTexSubImage2D"); + if (!CompressedTexSubImage1D) CompressedTexSubImage1D = (PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC_MT)cmgr->getProcAddress("glCompressedTexSubImage1D"); + if (!GetCompressedTexImage) GetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC_MT)cmgr->getProcAddress("glGetCompressedTexImage"); + if (!BlendFuncSeparate) BlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC_MT)cmgr->getProcAddress("glBlendFuncSeparate"); + if (!MultiDrawArrays) MultiDrawArrays = (PFNGLMULTIDRAWARRAYSPROC_MT)cmgr->getProcAddress("glMultiDrawArrays"); + if (!MultiDrawElements) MultiDrawElements = (PFNGLMULTIDRAWELEMENTSPROC_MT)cmgr->getProcAddress("glMultiDrawElements"); + if (!PointParameterf) PointParameterf = (PFNGLPOINTPARAMETERFPROC_MT)cmgr->getProcAddress("glPointParameterf"); + if (!PointParameterfv) PointParameterfv = (PFNGLPOINTPARAMETERFVPROC_MT)cmgr->getProcAddress("glPointParameterfv"); + if (!PointParameteri) PointParameteri = (PFNGLPOINTPARAMETERIPROC_MT)cmgr->getProcAddress("glPointParameteri"); + if (!PointParameteriv) PointParameteriv = (PFNGLPOINTPARAMETERIVPROC_MT)cmgr->getProcAddress("glPointParameteriv"); + if (!BlendColor) BlendColor = (PFNGLBLENDCOLORPROC_MT)cmgr->getProcAddress("glBlendColor"); + if (!BlendEquation) BlendEquation = (PFNGLBLENDEQUATIONPROC_MT)cmgr->getProcAddress("glBlendEquation"); + if (!GenQueries) GenQueries = (PFNGLGENQUERIESPROC_MT)cmgr->getProcAddress("glGenQueries"); + if (!DeleteQueries) DeleteQueries = (PFNGLDELETEQUERIESPROC_MT)cmgr->getProcAddress("glDeleteQueries"); + if (!IsQuery) IsQuery = (PFNGLISQUERYPROC_MT)cmgr->getProcAddress("glIsQuery"); + if (!BeginQuery) BeginQuery = (PFNGLBEGINQUERYPROC_MT)cmgr->getProcAddress("glBeginQuery"); + if (!EndQuery) EndQuery = (PFNGLENDQUERYPROC_MT)cmgr->getProcAddress("glEndQuery"); + if (!GetQueryiv) GetQueryiv = (PFNGLGETQUERYIVPROC_MT)cmgr->getProcAddress("glGetQueryiv"); + if (!GetQueryObjectiv) GetQueryObjectiv = (PFNGLGETQUERYOBJECTIVPROC_MT)cmgr->getProcAddress("glGetQueryObjectiv"); + if (!GetQueryObjectuiv) GetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC_MT)cmgr->getProcAddress("glGetQueryObjectuiv"); + if (!BindBuffer) BindBuffer = (PFNGLBINDBUFFERPROC_MT)cmgr->getProcAddress("glBindBuffer"); + if (!DeleteBuffers) DeleteBuffers = (PFNGLDELETEBUFFERSPROC_MT)cmgr->getProcAddress("glDeleteBuffers"); + if (!GenBuffers) GenBuffers = (PFNGLGENBUFFERSPROC_MT)cmgr->getProcAddress("glGenBuffers"); + if (!IsBuffer) IsBuffer = (PFNGLISBUFFERPROC_MT)cmgr->getProcAddress("glIsBuffer"); + if (!BufferData) BufferData = (PFNGLBUFFERDATAPROC_MT)cmgr->getProcAddress("glBufferData"); + if (!BufferSubData) BufferSubData = (PFNGLBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glBufferSubData"); + if (!GetBufferSubData) GetBufferSubData = (PFNGLGETBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glGetBufferSubData"); + if (!MapBuffer) MapBuffer = (PFNGLMAPBUFFERPROC_MT)cmgr->getProcAddress("glMapBuffer"); + if (!UnmapBuffer) UnmapBuffer = (PFNGLUNMAPBUFFERPROC_MT)cmgr->getProcAddress("glUnmapBuffer"); + if (!GetBufferParameteriv) GetBufferParameteriv = (PFNGLGETBUFFERPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetBufferParameteriv"); + if (!GetBufferPointerv) GetBufferPointerv = (PFNGLGETBUFFERPOINTERVPROC_MT)cmgr->getProcAddress("glGetBufferPointerv"); + if (!BlendEquationSeparate) BlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC_MT)cmgr->getProcAddress("glBlendEquationSeparate"); + if (!DrawBuffers) DrawBuffers = (PFNGLDRAWBUFFERSPROC_MT)cmgr->getProcAddress("glDrawBuffers"); + if (!StencilOpSeparate) StencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC_MT)cmgr->getProcAddress("glStencilOpSeparate"); + if (!StencilFuncSeparate) StencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC_MT)cmgr->getProcAddress("glStencilFuncSeparate"); + if (!StencilMaskSeparate) StencilMaskSeparate = (PFNGLSTENCILMASKSEPARATEPROC_MT)cmgr->getProcAddress("glStencilMaskSeparate"); + if (!AttachShader) AttachShader = (PFNGLATTACHSHADERPROC_MT)cmgr->getProcAddress("glAttachShader"); + if (!BindAttribLocation) BindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC_MT)cmgr->getProcAddress("glBindAttribLocation"); + if (!CompileShader) CompileShader = (PFNGLCOMPILESHADERPROC_MT)cmgr->getProcAddress("glCompileShader"); + if (!CreateProgram) CreateProgram = (PFNGLCREATEPROGRAMPROC_MT)cmgr->getProcAddress("glCreateProgram"); + if (!CreateShader) CreateShader = (PFNGLCREATESHADERPROC_MT)cmgr->getProcAddress("glCreateShader"); + if (!DeleteProgram) DeleteProgram = (PFNGLDELETEPROGRAMPROC_MT)cmgr->getProcAddress("glDeleteProgram"); + if (!DeleteShader) DeleteShader = (PFNGLDELETESHADERPROC_MT)cmgr->getProcAddress("glDeleteShader"); + if (!DetachShader) DetachShader = (PFNGLDETACHSHADERPROC_MT)cmgr->getProcAddress("glDetachShader"); + if (!DisableVertexAttribArray) DisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC_MT)cmgr->getProcAddress("glDisableVertexAttribArray"); + if (!EnableVertexAttribArray) EnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC_MT)cmgr->getProcAddress("glEnableVertexAttribArray"); + if (!GetActiveAttrib) GetActiveAttrib = (PFNGLGETACTIVEATTRIBPROC_MT)cmgr->getProcAddress("glGetActiveAttrib"); + if (!GetActiveUniform) GetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC_MT)cmgr->getProcAddress("glGetActiveUniform"); + if (!GetAttachedShaders) GetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC_MT)cmgr->getProcAddress("glGetAttachedShaders"); + if (!GetAttribLocation) GetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC_MT)cmgr->getProcAddress("glGetAttribLocation"); + if (!GetProgramiv) GetProgramiv = (PFNGLGETPROGRAMIVPROC_MT)cmgr->getProcAddress("glGetProgramiv"); + if (!GetProgramInfoLog) GetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC_MT)cmgr->getProcAddress("glGetProgramInfoLog"); + if (!GetShaderiv) GetShaderiv = (PFNGLGETSHADERIVPROC_MT)cmgr->getProcAddress("glGetShaderiv"); + if (!GetShaderInfoLog) GetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC_MT)cmgr->getProcAddress("glGetShaderInfoLog"); + if (!GetShaderSource) GetShaderSource = (PFNGLGETSHADERSOURCEPROC_MT)cmgr->getProcAddress("glGetShaderSource"); + if (!GetUniformLocation) GetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC_MT)cmgr->getProcAddress("glGetUniformLocation"); + if (!GetUniformfv) GetUniformfv = (PFNGLGETUNIFORMFVPROC_MT)cmgr->getProcAddress("glGetUniformfv"); + if (!GetUniformiv) GetUniformiv = (PFNGLGETUNIFORMIVPROC_MT)cmgr->getProcAddress("glGetUniformiv"); + if (!GetVertexAttribdv) GetVertexAttribdv = (PFNGLGETVERTEXATTRIBDVPROC_MT)cmgr->getProcAddress("glGetVertexAttribdv"); + if (!GetVertexAttribfv) GetVertexAttribfv = (PFNGLGETVERTEXATTRIBFVPROC_MT)cmgr->getProcAddress("glGetVertexAttribfv"); + if (!GetVertexAttribiv) GetVertexAttribiv = (PFNGLGETVERTEXATTRIBIVPROC_MT)cmgr->getProcAddress("glGetVertexAttribiv"); + if (!GetVertexAttribPointerv) GetVertexAttribPointerv = (PFNGLGETVERTEXATTRIBPOINTERVPROC_MT)cmgr->getProcAddress("glGetVertexAttribPointerv"); + if (!IsProgram) IsProgram = (PFNGLISPROGRAMPROC_MT)cmgr->getProcAddress("glIsProgram"); + if (!IsShader) IsShader = (PFNGLISSHADERPROC_MT)cmgr->getProcAddress("glIsShader"); + if (!LinkProgram) LinkProgram = (PFNGLLINKPROGRAMPROC_MT)cmgr->getProcAddress("glLinkProgram"); + if (!ShaderSource) ShaderSource = (PFNGLSHADERSOURCEPROC_MT)cmgr->getProcAddress("glShaderSource"); + if (!UseProgram) UseProgram = (PFNGLUSEPROGRAMPROC_MT)cmgr->getProcAddress("glUseProgram"); + if (!Uniform1f) Uniform1f = (PFNGLUNIFORM1FPROC_MT)cmgr->getProcAddress("glUniform1f"); + if (!Uniform2f) Uniform2f = (PFNGLUNIFORM2FPROC_MT)cmgr->getProcAddress("glUniform2f"); + if (!Uniform3f) Uniform3f = (PFNGLUNIFORM3FPROC_MT)cmgr->getProcAddress("glUniform3f"); + if (!Uniform4f) Uniform4f = (PFNGLUNIFORM4FPROC_MT)cmgr->getProcAddress("glUniform4f"); + if (!Uniform1i) Uniform1i = (PFNGLUNIFORM1IPROC_MT)cmgr->getProcAddress("glUniform1i"); + if (!Uniform2i) Uniform2i = (PFNGLUNIFORM2IPROC_MT)cmgr->getProcAddress("glUniform2i"); + if (!Uniform3i) Uniform3i = (PFNGLUNIFORM3IPROC_MT)cmgr->getProcAddress("glUniform3i"); + if (!Uniform4i) Uniform4i = (PFNGLUNIFORM4IPROC_MT)cmgr->getProcAddress("glUniform4i"); + if (!Uniform1fv) Uniform1fv = (PFNGLUNIFORM1FVPROC_MT)cmgr->getProcAddress("glUniform1fv"); + if (!Uniform2fv) Uniform2fv = (PFNGLUNIFORM2FVPROC_MT)cmgr->getProcAddress("glUniform2fv"); + if (!Uniform3fv) Uniform3fv = (PFNGLUNIFORM3FVPROC_MT)cmgr->getProcAddress("glUniform3fv"); + if (!Uniform4fv) Uniform4fv = (PFNGLUNIFORM4FVPROC_MT)cmgr->getProcAddress("glUniform4fv"); + if (!Uniform1iv) Uniform1iv = (PFNGLUNIFORM1IVPROC_MT)cmgr->getProcAddress("glUniform1iv"); + if (!Uniform2iv) Uniform2iv = (PFNGLUNIFORM2IVPROC_MT)cmgr->getProcAddress("glUniform2iv"); + if (!Uniform3iv) Uniform3iv = (PFNGLUNIFORM3IVPROC_MT)cmgr->getProcAddress("glUniform3iv"); + if (!Uniform4iv) Uniform4iv = (PFNGLUNIFORM4IVPROC_MT)cmgr->getProcAddress("glUniform4iv"); + if (!UniformMatrix2fv) UniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC_MT)cmgr->getProcAddress("glUniformMatrix2fv"); + if (!UniformMatrix3fv) UniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC_MT)cmgr->getProcAddress("glUniformMatrix3fv"); + if (!UniformMatrix4fv) UniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC_MT)cmgr->getProcAddress("glUniformMatrix4fv"); + if (!ValidateProgram) ValidateProgram = (PFNGLVALIDATEPROGRAMPROC_MT)cmgr->getProcAddress("glValidateProgram"); + if (!VertexAttrib1d) VertexAttrib1d = (PFNGLVERTEXATTRIB1DPROC_MT)cmgr->getProcAddress("glVertexAttrib1d"); + if (!VertexAttrib1dv) VertexAttrib1dv = (PFNGLVERTEXATTRIB1DVPROC_MT)cmgr->getProcAddress("glVertexAttrib1dv"); + if (!VertexAttrib1f) VertexAttrib1f = (PFNGLVERTEXATTRIB1FPROC_MT)cmgr->getProcAddress("glVertexAttrib1f"); + if (!VertexAttrib1fv) VertexAttrib1fv = (PFNGLVERTEXATTRIB1FVPROC_MT)cmgr->getProcAddress("glVertexAttrib1fv"); + if (!VertexAttrib1s) VertexAttrib1s = (PFNGLVERTEXATTRIB1SPROC_MT)cmgr->getProcAddress("glVertexAttrib1s"); + if (!VertexAttrib1sv) VertexAttrib1sv = (PFNGLVERTEXATTRIB1SVPROC_MT)cmgr->getProcAddress("glVertexAttrib1sv"); + if (!VertexAttrib2d) VertexAttrib2d = (PFNGLVERTEXATTRIB2DPROC_MT)cmgr->getProcAddress("glVertexAttrib2d"); + if (!VertexAttrib2dv) VertexAttrib2dv = (PFNGLVERTEXATTRIB2DVPROC_MT)cmgr->getProcAddress("glVertexAttrib2dv"); + if (!VertexAttrib2f) VertexAttrib2f = (PFNGLVERTEXATTRIB2FPROC_MT)cmgr->getProcAddress("glVertexAttrib2f"); + if (!VertexAttrib2fv) VertexAttrib2fv = (PFNGLVERTEXATTRIB2FVPROC_MT)cmgr->getProcAddress("glVertexAttrib2fv"); + if (!VertexAttrib2s) VertexAttrib2s = (PFNGLVERTEXATTRIB2SPROC_MT)cmgr->getProcAddress("glVertexAttrib2s"); + if (!VertexAttrib2sv) VertexAttrib2sv = (PFNGLVERTEXATTRIB2SVPROC_MT)cmgr->getProcAddress("glVertexAttrib2sv"); + if (!VertexAttrib3d) VertexAttrib3d = (PFNGLVERTEXATTRIB3DPROC_MT)cmgr->getProcAddress("glVertexAttrib3d"); + if (!VertexAttrib3dv) VertexAttrib3dv = (PFNGLVERTEXATTRIB3DVPROC_MT)cmgr->getProcAddress("glVertexAttrib3dv"); + if (!VertexAttrib3f) VertexAttrib3f = (PFNGLVERTEXATTRIB3FPROC_MT)cmgr->getProcAddress("glVertexAttrib3f"); + if (!VertexAttrib3fv) VertexAttrib3fv = (PFNGLVERTEXATTRIB3FVPROC_MT)cmgr->getProcAddress("glVertexAttrib3fv"); + if (!VertexAttrib3s) VertexAttrib3s = (PFNGLVERTEXATTRIB3SPROC_MT)cmgr->getProcAddress("glVertexAttrib3s"); + if (!VertexAttrib3sv) VertexAttrib3sv = (PFNGLVERTEXATTRIB3SVPROC_MT)cmgr->getProcAddress("glVertexAttrib3sv"); + if (!VertexAttrib4Nbv) VertexAttrib4Nbv = (PFNGLVERTEXATTRIB4NBVPROC_MT)cmgr->getProcAddress("glVertexAttrib4Nbv"); + if (!VertexAttrib4Niv) VertexAttrib4Niv = (PFNGLVERTEXATTRIB4NIVPROC_MT)cmgr->getProcAddress("glVertexAttrib4Niv"); + if (!VertexAttrib4Nsv) VertexAttrib4Nsv = (PFNGLVERTEXATTRIB4NSVPROC_MT)cmgr->getProcAddress("glVertexAttrib4Nsv"); + if (!VertexAttrib4Nub) VertexAttrib4Nub = (PFNGLVERTEXATTRIB4NUBPROC_MT)cmgr->getProcAddress("glVertexAttrib4Nub"); + if (!VertexAttrib4Nubv) VertexAttrib4Nubv = (PFNGLVERTEXATTRIB4NUBVPROC_MT)cmgr->getProcAddress("glVertexAttrib4Nubv"); + if (!VertexAttrib4Nuiv) VertexAttrib4Nuiv = (PFNGLVERTEXATTRIB4NUIVPROC_MT)cmgr->getProcAddress("glVertexAttrib4Nuiv"); + if (!VertexAttrib4Nusv) VertexAttrib4Nusv = (PFNGLVERTEXATTRIB4NUSVPROC_MT)cmgr->getProcAddress("glVertexAttrib4Nusv"); + if (!VertexAttrib4bv) VertexAttrib4bv = (PFNGLVERTEXATTRIB4BVPROC_MT)cmgr->getProcAddress("glVertexAttrib4bv"); + if (!VertexAttrib4d) VertexAttrib4d = (PFNGLVERTEXATTRIB4DPROC_MT)cmgr->getProcAddress("glVertexAttrib4d"); + if (!VertexAttrib4dv) VertexAttrib4dv = (PFNGLVERTEXATTRIB4DVPROC_MT)cmgr->getProcAddress("glVertexAttrib4dv"); + if (!VertexAttrib4f) VertexAttrib4f = (PFNGLVERTEXATTRIB4FPROC_MT)cmgr->getProcAddress("glVertexAttrib4f"); + if (!VertexAttrib4fv) VertexAttrib4fv = (PFNGLVERTEXATTRIB4FVPROC_MT)cmgr->getProcAddress("glVertexAttrib4fv"); + if (!VertexAttrib4iv) VertexAttrib4iv = (PFNGLVERTEXATTRIB4IVPROC_MT)cmgr->getProcAddress("glVertexAttrib4iv"); + if (!VertexAttrib4s) VertexAttrib4s = (PFNGLVERTEXATTRIB4SPROC_MT)cmgr->getProcAddress("glVertexAttrib4s"); + if (!VertexAttrib4sv) VertexAttrib4sv = (PFNGLVERTEXATTRIB4SVPROC_MT)cmgr->getProcAddress("glVertexAttrib4sv"); + if (!VertexAttrib4ubv) VertexAttrib4ubv = (PFNGLVERTEXATTRIB4UBVPROC_MT)cmgr->getProcAddress("glVertexAttrib4ubv"); + if (!VertexAttrib4uiv) VertexAttrib4uiv = (PFNGLVERTEXATTRIB4UIVPROC_MT)cmgr->getProcAddress("glVertexAttrib4uiv"); + if (!VertexAttrib4usv) VertexAttrib4usv = (PFNGLVERTEXATTRIB4USVPROC_MT)cmgr->getProcAddress("glVertexAttrib4usv"); + if (!VertexAttribPointer) VertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC_MT)cmgr->getProcAddress("glVertexAttribPointer"); + if (!UniformMatrix2x3fv) UniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC_MT)cmgr->getProcAddress("glUniformMatrix2x3fv"); + if (!UniformMatrix3x2fv) UniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC_MT)cmgr->getProcAddress("glUniformMatrix3x2fv"); + if (!UniformMatrix2x4fv) UniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC_MT)cmgr->getProcAddress("glUniformMatrix2x4fv"); + if (!UniformMatrix4x2fv) UniformMatrix4x2fv = (PFNGLUNIFORMMATRIX4X2FVPROC_MT)cmgr->getProcAddress("glUniformMatrix4x2fv"); + if (!UniformMatrix3x4fv) UniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC_MT)cmgr->getProcAddress("glUniformMatrix3x4fv"); + if (!UniformMatrix4x3fv) UniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC_MT)cmgr->getProcAddress("glUniformMatrix4x3fv"); + if (!ColorMaski) ColorMaski = (PFNGLCOLORMASKIPROC_MT)cmgr->getProcAddress("glColorMaski"); + if (!Enablei) Enablei = (PFNGLENABLEIPROC_MT)cmgr->getProcAddress("glEnablei"); + if (!Disablei) Disablei = (PFNGLDISABLEIPROC_MT)cmgr->getProcAddress("glDisablei"); + if (!IsEnabledi) IsEnabledi = (PFNGLISENABLEDIPROC_MT)cmgr->getProcAddress("glIsEnabledi"); + if (!BeginTransformFeedback) BeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC_MT)cmgr->getProcAddress("glBeginTransformFeedback"); + if (!EndTransformFeedback) EndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC_MT)cmgr->getProcAddress("glEndTransformFeedback"); + if (!BindBufferRange) BindBufferRange = (PFNGLBINDBUFFERRANGEPROC_MT)cmgr->getProcAddress("glBindBufferRange"); + if (!BindBufferBase) BindBufferBase = (PFNGLBINDBUFFERBASEPROC_MT)cmgr->getProcAddress("glBindBufferBase"); + if (!TransformFeedbackVaryings) TransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC_MT)cmgr->getProcAddress("glTransformFeedbackVaryings"); + if (!GetTransformFeedbackVarying) GetTransformFeedbackVarying = (PFNGLGETTRANSFORMFEEDBACKVARYINGPROC_MT)cmgr->getProcAddress("glGetTransformFeedbackVarying"); + if (!ClampColor) ClampColor = (PFNGLCLAMPCOLORPROC_MT)cmgr->getProcAddress("glClampColor"); + if (!BeginConditionalRender) BeginConditionalRender = (PFNGLBEGINCONDITIONALRENDERPROC_MT)cmgr->getProcAddress("glBeginConditionalRender"); + if (!EndConditionalRender) EndConditionalRender = (PFNGLENDCONDITIONALRENDERPROC_MT)cmgr->getProcAddress("glEndConditionalRender"); + if (!VertexAttribIPointer) VertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC_MT)cmgr->getProcAddress("glVertexAttribIPointer"); + if (!GetVertexAttribIiv) GetVertexAttribIiv = (PFNGLGETVERTEXATTRIBIIVPROC_MT)cmgr->getProcAddress("glGetVertexAttribIiv"); + if (!GetVertexAttribIuiv) GetVertexAttribIuiv = (PFNGLGETVERTEXATTRIBIUIVPROC_MT)cmgr->getProcAddress("glGetVertexAttribIuiv"); + if (!VertexAttribI1i) VertexAttribI1i = (PFNGLVERTEXATTRIBI1IPROC_MT)cmgr->getProcAddress("glVertexAttribI1i"); + if (!VertexAttribI2i) VertexAttribI2i = (PFNGLVERTEXATTRIBI2IPROC_MT)cmgr->getProcAddress("glVertexAttribI2i"); + if (!VertexAttribI3i) VertexAttribI3i = (PFNGLVERTEXATTRIBI3IPROC_MT)cmgr->getProcAddress("glVertexAttribI3i"); + if (!VertexAttribI4i) VertexAttribI4i = (PFNGLVERTEXATTRIBI4IPROC_MT)cmgr->getProcAddress("glVertexAttribI4i"); + if (!VertexAttribI1ui) VertexAttribI1ui = (PFNGLVERTEXATTRIBI1UIPROC_MT)cmgr->getProcAddress("glVertexAttribI1ui"); + if (!VertexAttribI2ui) VertexAttribI2ui = (PFNGLVERTEXATTRIBI2UIPROC_MT)cmgr->getProcAddress("glVertexAttribI2ui"); + if (!VertexAttribI3ui) VertexAttribI3ui = (PFNGLVERTEXATTRIBI3UIPROC_MT)cmgr->getProcAddress("glVertexAttribI3ui"); + if (!VertexAttribI4ui) VertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC_MT)cmgr->getProcAddress("glVertexAttribI4ui"); + if (!VertexAttribI1iv) VertexAttribI1iv = (PFNGLVERTEXATTRIBI1IVPROC_MT)cmgr->getProcAddress("glVertexAttribI1iv"); + if (!VertexAttribI2iv) VertexAttribI2iv = (PFNGLVERTEXATTRIBI2IVPROC_MT)cmgr->getProcAddress("glVertexAttribI2iv"); + if (!VertexAttribI3iv) VertexAttribI3iv = (PFNGLVERTEXATTRIBI3IVPROC_MT)cmgr->getProcAddress("glVertexAttribI3iv"); + if (!VertexAttribI4iv) VertexAttribI4iv = (PFNGLVERTEXATTRIBI4IVPROC_MT)cmgr->getProcAddress("glVertexAttribI4iv"); + if (!VertexAttribI1uiv) VertexAttribI1uiv = (PFNGLVERTEXATTRIBI1UIVPROC_MT)cmgr->getProcAddress("glVertexAttribI1uiv"); + if (!VertexAttribI2uiv) VertexAttribI2uiv = (PFNGLVERTEXATTRIBI2UIVPROC_MT)cmgr->getProcAddress("glVertexAttribI2uiv"); + if (!VertexAttribI3uiv) VertexAttribI3uiv = (PFNGLVERTEXATTRIBI3UIVPROC_MT)cmgr->getProcAddress("glVertexAttribI3uiv"); + if (!VertexAttribI4uiv) VertexAttribI4uiv = (PFNGLVERTEXATTRIBI4UIVPROC_MT)cmgr->getProcAddress("glVertexAttribI4uiv"); + if (!VertexAttribI4bv) VertexAttribI4bv = (PFNGLVERTEXATTRIBI4BVPROC_MT)cmgr->getProcAddress("glVertexAttribI4bv"); + if (!VertexAttribI4sv) VertexAttribI4sv = (PFNGLVERTEXATTRIBI4SVPROC_MT)cmgr->getProcAddress("glVertexAttribI4sv"); + if (!VertexAttribI4ubv) VertexAttribI4ubv = (PFNGLVERTEXATTRIBI4UBVPROC_MT)cmgr->getProcAddress("glVertexAttribI4ubv"); + if (!VertexAttribI4usv) VertexAttribI4usv = (PFNGLVERTEXATTRIBI4USVPROC_MT)cmgr->getProcAddress("glVertexAttribI4usv"); + if (!GetUniformuiv) GetUniformuiv = (PFNGLGETUNIFORMUIVPROC_MT)cmgr->getProcAddress("glGetUniformuiv"); + if (!BindFragDataLocation) BindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC_MT)cmgr->getProcAddress("glBindFragDataLocation"); + if (!GetFragDataLocation) GetFragDataLocation = (PFNGLGETFRAGDATALOCATIONPROC_MT)cmgr->getProcAddress("glGetFragDataLocation"); + if (!Uniform1ui) Uniform1ui = (PFNGLUNIFORM1UIPROC_MT)cmgr->getProcAddress("glUniform1ui"); + if (!Uniform2ui) Uniform2ui = (PFNGLUNIFORM2UIPROC_MT)cmgr->getProcAddress("glUniform2ui"); + if (!Uniform3ui) Uniform3ui = (PFNGLUNIFORM3UIPROC_MT)cmgr->getProcAddress("glUniform3ui"); + if (!Uniform4ui) Uniform4ui = (PFNGLUNIFORM4UIPROC_MT)cmgr->getProcAddress("glUniform4ui"); + if (!Uniform1uiv) Uniform1uiv = (PFNGLUNIFORM1UIVPROC_MT)cmgr->getProcAddress("glUniform1uiv"); + if (!Uniform2uiv) Uniform2uiv = (PFNGLUNIFORM2UIVPROC_MT)cmgr->getProcAddress("glUniform2uiv"); + if (!Uniform3uiv) Uniform3uiv = (PFNGLUNIFORM3UIVPROC_MT)cmgr->getProcAddress("glUniform3uiv"); + if (!Uniform4uiv) Uniform4uiv = (PFNGLUNIFORM4UIVPROC_MT)cmgr->getProcAddress("glUniform4uiv"); + if (!TexParameterIiv) TexParameterIiv = (PFNGLTEXPARAMETERIIVPROC_MT)cmgr->getProcAddress("glTexParameterIiv"); + if (!TexParameterIuiv) TexParameterIuiv = (PFNGLTEXPARAMETERIUIVPROC_MT)cmgr->getProcAddress("glTexParameterIuiv"); + if (!GetTexParameterIiv) GetTexParameterIiv = (PFNGLGETTEXPARAMETERIIVPROC_MT)cmgr->getProcAddress("glGetTexParameterIiv"); + if (!GetTexParameterIuiv) GetTexParameterIuiv = (PFNGLGETTEXPARAMETERIUIVPROC_MT)cmgr->getProcAddress("glGetTexParameterIuiv"); + if (!ClearBufferiv) ClearBufferiv = (PFNGLCLEARBUFFERIVPROC_MT)cmgr->getProcAddress("glClearBufferiv"); + if (!ClearBufferuiv) ClearBufferuiv = (PFNGLCLEARBUFFERUIVPROC_MT)cmgr->getProcAddress("glClearBufferuiv"); + if (!ClearBufferfv) ClearBufferfv = (PFNGLCLEARBUFFERFVPROC_MT)cmgr->getProcAddress("glClearBufferfv"); + if (!ClearBufferfi) ClearBufferfi = (PFNGLCLEARBUFFERFIPROC_MT)cmgr->getProcAddress("glClearBufferfi"); + if (!GetStringi) GetStringi = (PFNGLGETSTRINGIPROC_MT)cmgr->getProcAddress("glGetStringi"); + if (!IsRenderbuffer) IsRenderbuffer = (PFNGLISRENDERBUFFERPROC_MT)cmgr->getProcAddress("glIsRenderbuffer"); + if (!BindRenderbuffer) BindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC_MT)cmgr->getProcAddress("glBindRenderbuffer"); + if (!DeleteRenderbuffers) DeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC_MT)cmgr->getProcAddress("glDeleteRenderbuffers"); + if (!GenRenderbuffers) GenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC_MT)cmgr->getProcAddress("glGenRenderbuffers"); + if (!RenderbufferStorage) RenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC_MT)cmgr->getProcAddress("glRenderbufferStorage"); + if (!GetRenderbufferParameteriv) GetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetRenderbufferParameteriv"); + if (!IsFramebuffer) IsFramebuffer = (PFNGLISFRAMEBUFFERPROC_MT)cmgr->getProcAddress("glIsFramebuffer"); + if (!BindFramebuffer) BindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC_MT)cmgr->getProcAddress("glBindFramebuffer"); + if (!DeleteFramebuffers) DeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC_MT)cmgr->getProcAddress("glDeleteFramebuffers"); + if (!GenFramebuffers) GenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC_MT)cmgr->getProcAddress("glGenFramebuffers"); + if (!CheckFramebufferStatus) CheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC_MT)cmgr->getProcAddress("glCheckFramebufferStatus"); + if (!FramebufferTexture1D) FramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC_MT)cmgr->getProcAddress("glFramebufferTexture1D"); + if (!FramebufferTexture2D) FramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC_MT)cmgr->getProcAddress("glFramebufferTexture2D"); + if (!FramebufferTexture3D) FramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC_MT)cmgr->getProcAddress("glFramebufferTexture3D"); + if (!FramebufferRenderbuffer) FramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC_MT)cmgr->getProcAddress("glFramebufferRenderbuffer"); + if (!GetFramebufferAttachmentParameteriv) GetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetFramebufferAttachmentParameteriv"); + if (!GenerateMipmap) GenerateMipmap = (PFNGLGENERATEMIPMAPPROC_MT)cmgr->getProcAddress("glGenerateMipmap"); + if (!BlitFramebuffer) BlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC_MT)cmgr->getProcAddress("glBlitFramebuffer"); + if (!RenderbufferStorageMultisample) RenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC_MT)cmgr->getProcAddress("glRenderbufferStorageMultisample"); + if (!FramebufferTextureLayer) FramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC_MT)cmgr->getProcAddress("glFramebufferTextureLayer"); + if (!FramebufferTextureLayer) FramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC_MT)cmgr->getProcAddress("glFramebufferTextureLayerARB"); + if (!MapBufferRange) MapBufferRange = (PFNGLMAPBUFFERRANGEPROC_MT)cmgr->getProcAddress("glMapBufferRange"); + if (!FlushMappedBufferRange) FlushMappedBufferRange = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC_MT)cmgr->getProcAddress("glFlushMappedBufferRange"); + if (!BindVertexArray) BindVertexArray = (PFNGLBINDVERTEXARRAYPROC_MT)cmgr->getProcAddress("glBindVertexArray"); + if (!DeleteVertexArrays) DeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC_MT)cmgr->getProcAddress("glDeleteVertexArrays"); + if (!GenVertexArrays) GenVertexArrays = (PFNGLGENVERTEXARRAYSPROC_MT)cmgr->getProcAddress("glGenVertexArrays"); + if (!IsVertexArray) IsVertexArray = (PFNGLISVERTEXARRAYPROC_MT)cmgr->getProcAddress("glIsVertexArray"); + if (!DrawArraysInstanced) DrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC_MT)cmgr->getProcAddress("glDrawArraysInstanced"); + if (!DrawArraysInstanced) DrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC_MT)cmgr->getProcAddress("glDrawArraysInstancedARB"); + if (!DrawElementsInstanced) DrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC_MT)cmgr->getProcAddress("glDrawElementsInstanced"); + if (!DrawElementsInstanced) DrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC_MT)cmgr->getProcAddress("glDrawElementsInstancedARB"); + if (!TexBuffer) TexBuffer = (PFNGLTEXBUFFERPROC_MT)cmgr->getProcAddress("glTexBuffer"); + if (!TexBuffer) TexBuffer = (PFNGLTEXBUFFERPROC_MT)cmgr->getProcAddress("glTexBufferARB"); + if (!PrimitiveRestartIndex) PrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC_MT)cmgr->getProcAddress("glPrimitiveRestartIndex"); + if (!CopyBufferSubData) CopyBufferSubData = (PFNGLCOPYBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glCopyBufferSubData"); + if (!GetUniformIndices) GetUniformIndices = (PFNGLGETUNIFORMINDICESPROC_MT)cmgr->getProcAddress("glGetUniformIndices"); + if (!GetActiveUniformsiv) GetActiveUniformsiv = (PFNGLGETACTIVEUNIFORMSIVPROC_MT)cmgr->getProcAddress("glGetActiveUniformsiv"); + if (!GetActiveUniformName) GetActiveUniformName = (PFNGLGETACTIVEUNIFORMNAMEPROC_MT)cmgr->getProcAddress("glGetActiveUniformName"); + if (!GetUniformBlockIndex) GetUniformBlockIndex = (PFNGLGETUNIFORMBLOCKINDEXPROC_MT)cmgr->getProcAddress("glGetUniformBlockIndex"); + if (!GetActiveUniformBlockiv) GetActiveUniformBlockiv = (PFNGLGETACTIVEUNIFORMBLOCKIVPROC_MT)cmgr->getProcAddress("glGetActiveUniformBlockiv"); + if (!GetActiveUniformBlockName) GetActiveUniformBlockName = (PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC_MT)cmgr->getProcAddress("glGetActiveUniformBlockName"); + if (!UniformBlockBinding) UniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC_MT)cmgr->getProcAddress("glUniformBlockBinding"); + if (!DrawElementsBaseVertex) DrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC_MT)cmgr->getProcAddress("glDrawElementsBaseVertex"); + if (!DrawRangeElementsBaseVertex) DrawRangeElementsBaseVertex = (PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC_MT)cmgr->getProcAddress("glDrawRangeElementsBaseVertex"); + if (!DrawElementsInstancedBaseVertex) DrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC_MT)cmgr->getProcAddress("glDrawElementsInstancedBaseVertex"); + if (!MultiDrawElementsBaseVertex) MultiDrawElementsBaseVertex = (PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC_MT)cmgr->getProcAddress("glMultiDrawElementsBaseVertex"); + if (!ProvokingVertex) ProvokingVertex = (PFNGLPROVOKINGVERTEXPROC_MT)cmgr->getProcAddress("glProvokingVertex"); + if (!FenceSync) FenceSync = (PFNGLFENCESYNCPROC_MT)cmgr->getProcAddress("glFenceSync"); + if (!IsSync) IsSync = (PFNGLISSYNCPROC_MT)cmgr->getProcAddress("glIsSync"); + if (!DeleteSync) DeleteSync = (PFNGLDELETESYNCPROC_MT)cmgr->getProcAddress("glDeleteSync"); + if (!ClientWaitSync) ClientWaitSync = (PFNGLCLIENTWAITSYNCPROC_MT)cmgr->getProcAddress("glClientWaitSync"); + if (!WaitSync) WaitSync = (PFNGLWAITSYNCPROC_MT)cmgr->getProcAddress("glWaitSync"); + if (!GetInteger64v) GetInteger64v = (PFNGLGETINTEGER64VPROC_MT)cmgr->getProcAddress("glGetInteger64v"); + if (!GetSynciv) GetSynciv = (PFNGLGETSYNCIVPROC_MT)cmgr->getProcAddress("glGetSynciv"); + if (!GetBufferParameteri64v) GetBufferParameteri64v = (PFNGLGETBUFFERPARAMETERI64VPROC_MT)cmgr->getProcAddress("glGetBufferParameteri64v"); + if (!FramebufferTexture) FramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC_MT)cmgr->getProcAddress("glFramebufferTexture"); + if (!FramebufferTexture) FramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC_MT)cmgr->getProcAddress("glFramebufferTextureARB"); + if (!TexImage2DMultisample) TexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC_MT)cmgr->getProcAddress("glTexImage2DMultisample"); + if (!TexImage3DMultisample) TexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC_MT)cmgr->getProcAddress("glTexImage3DMultisample"); + if (!GetMultisamplefv) GetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC_MT)cmgr->getProcAddress("glGetMultisamplefv"); + if (!SampleMaski) SampleMaski = (PFNGLSAMPLEMASKIPROC_MT)cmgr->getProcAddress("glSampleMaski"); + if (!BindFragDataLocationIndexed) BindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXEDPROC_MT)cmgr->getProcAddress("glBindFragDataLocationIndexed"); + if (!GetFragDataIndex) GetFragDataIndex = (PFNGLGETFRAGDATAINDEXPROC_MT)cmgr->getProcAddress("glGetFragDataIndex"); + if (!GenSamplers) GenSamplers = (PFNGLGENSAMPLERSPROC_MT)cmgr->getProcAddress("glGenSamplers"); + if (!DeleteSamplers) DeleteSamplers = (PFNGLDELETESAMPLERSPROC_MT)cmgr->getProcAddress("glDeleteSamplers"); + if (!IsSampler) IsSampler = (PFNGLISSAMPLERPROC_MT)cmgr->getProcAddress("glIsSampler"); + if (!BindSampler) BindSampler = (PFNGLBINDSAMPLERPROC_MT)cmgr->getProcAddress("glBindSampler"); + if (!SamplerParameteri) SamplerParameteri = (PFNGLSAMPLERPARAMETERIPROC_MT)cmgr->getProcAddress("glSamplerParameteri"); + if (!SamplerParameteriv) SamplerParameteriv = (PFNGLSAMPLERPARAMETERIVPROC_MT)cmgr->getProcAddress("glSamplerParameteriv"); + if (!SamplerParameterf) SamplerParameterf = (PFNGLSAMPLERPARAMETERFPROC_MT)cmgr->getProcAddress("glSamplerParameterf"); + if (!SamplerParameterfv) SamplerParameterfv = (PFNGLSAMPLERPARAMETERFVPROC_MT)cmgr->getProcAddress("glSamplerParameterfv"); + if (!SamplerParameterIiv) SamplerParameterIiv = (PFNGLSAMPLERPARAMETERIIVPROC_MT)cmgr->getProcAddress("glSamplerParameterIiv"); + if (!SamplerParameterIuiv) SamplerParameterIuiv = (PFNGLSAMPLERPARAMETERIUIVPROC_MT)cmgr->getProcAddress("glSamplerParameterIuiv"); + if (!GetSamplerParameteriv) GetSamplerParameteriv = (PFNGLGETSAMPLERPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetSamplerParameteriv"); + if (!GetSamplerParameterIiv) GetSamplerParameterIiv = (PFNGLGETSAMPLERPARAMETERIIVPROC_MT)cmgr->getProcAddress("glGetSamplerParameterIiv"); + if (!GetSamplerParameterfv) GetSamplerParameterfv = (PFNGLGETSAMPLERPARAMETERFVPROC_MT)cmgr->getProcAddress("glGetSamplerParameterfv"); + if (!GetSamplerParameterIuiv) GetSamplerParameterIuiv = (PFNGLGETSAMPLERPARAMETERIUIVPROC_MT)cmgr->getProcAddress("glGetSamplerParameterIuiv"); + if (!QueryCounter) QueryCounter = (PFNGLQUERYCOUNTERPROC_MT)cmgr->getProcAddress("glQueryCounter"); + if (!GetQueryObjecti64v) GetQueryObjecti64v = (PFNGLGETQUERYOBJECTI64VPROC_MT)cmgr->getProcAddress("glGetQueryObjecti64v"); + if (!GetQueryObjectui64v) GetQueryObjectui64v = (PFNGLGETQUERYOBJECTUI64VPROC_MT)cmgr->getProcAddress("glGetQueryObjectui64v"); + if (!VertexAttribDivisor) VertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC_MT)cmgr->getProcAddress("glVertexAttribDivisor"); + if (!VertexAttribDivisor) VertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC_MT)cmgr->getProcAddress("glVertexAttribDivisorARB"); + if (!VertexAttribP1ui) VertexAttribP1ui = (PFNGLVERTEXATTRIBP1UIPROC_MT)cmgr->getProcAddress("glVertexAttribP1ui"); + if (!VertexAttribP1uiv) VertexAttribP1uiv = (PFNGLVERTEXATTRIBP1UIVPROC_MT)cmgr->getProcAddress("glVertexAttribP1uiv"); + if (!VertexAttribP2ui) VertexAttribP2ui = (PFNGLVERTEXATTRIBP2UIPROC_MT)cmgr->getProcAddress("glVertexAttribP2ui"); + if (!VertexAttribP2uiv) VertexAttribP2uiv = (PFNGLVERTEXATTRIBP2UIVPROC_MT)cmgr->getProcAddress("glVertexAttribP2uiv"); + if (!VertexAttribP3ui) VertexAttribP3ui = (PFNGLVERTEXATTRIBP3UIPROC_MT)cmgr->getProcAddress("glVertexAttribP3ui"); + if (!VertexAttribP3uiv) VertexAttribP3uiv = (PFNGLVERTEXATTRIBP3UIVPROC_MT)cmgr->getProcAddress("glVertexAttribP3uiv"); + if (!VertexAttribP4ui) VertexAttribP4ui = (PFNGLVERTEXATTRIBP4UIPROC_MT)cmgr->getProcAddress("glVertexAttribP4ui"); + if (!VertexAttribP4uiv) VertexAttribP4uiv = (PFNGLVERTEXATTRIBP4UIVPROC_MT)cmgr->getProcAddress("glVertexAttribP4uiv"); + if (!MinSampleShading) MinSampleShading = (PFNGLMINSAMPLESHADINGPROC_MT)cmgr->getProcAddress("glMinSampleShading"); + if (!MinSampleShading) MinSampleShading = (PFNGLMINSAMPLESHADINGPROC_MT)cmgr->getProcAddress("glMinSampleShadingARB"); + if (!BlendEquationi) BlendEquationi = (PFNGLBLENDEQUATIONIPROC_MT)cmgr->getProcAddress("glBlendEquationi"); + if (!BlendEquationi) BlendEquationi = (PFNGLBLENDEQUATIONIPROC_MT)cmgr->getProcAddress("glBlendEquationiARB"); + if (!BlendEquationSeparatei) BlendEquationSeparatei = (PFNGLBLENDEQUATIONSEPARATEIPROC_MT)cmgr->getProcAddress("glBlendEquationSeparatei"); + if (!BlendEquationSeparatei) BlendEquationSeparatei = (PFNGLBLENDEQUATIONSEPARATEIPROC_MT)cmgr->getProcAddress("glBlendEquationSeparateiARB"); + if (!BlendFunci) BlendFunci = (PFNGLBLENDFUNCIPROC_MT)cmgr->getProcAddress("glBlendFunci"); + if (!BlendFunci) BlendFunci = (PFNGLBLENDFUNCIPROC_MT)cmgr->getProcAddress("glBlendFunciARB"); + if (!BlendFuncSeparatei) BlendFuncSeparatei = (PFNGLBLENDFUNCSEPARATEIPROC_MT)cmgr->getProcAddress("glBlendFuncSeparatei"); + if (!BlendFuncSeparatei) BlendFuncSeparatei = (PFNGLBLENDFUNCSEPARATEIPROC_MT)cmgr->getProcAddress("glBlendFuncSeparateiARB"); + if (!DrawArraysIndirect) DrawArraysIndirect = (PFNGLDRAWARRAYSINDIRECTPROC_MT)cmgr->getProcAddress("glDrawArraysIndirect"); + if (!DrawElementsIndirect) DrawElementsIndirect = (PFNGLDRAWELEMENTSINDIRECTPROC_MT)cmgr->getProcAddress("glDrawElementsIndirect"); + if (!Uniform1d) Uniform1d = (PFNGLUNIFORM1DPROC_MT)cmgr->getProcAddress("glUniform1d"); + if (!Uniform2d) Uniform2d = (PFNGLUNIFORM2DPROC_MT)cmgr->getProcAddress("glUniform2d"); + if (!Uniform3d) Uniform3d = (PFNGLUNIFORM3DPROC_MT)cmgr->getProcAddress("glUniform3d"); + if (!Uniform4d) Uniform4d = (PFNGLUNIFORM4DPROC_MT)cmgr->getProcAddress("glUniform4d"); + if (!Uniform1dv) Uniform1dv = (PFNGLUNIFORM1DVPROC_MT)cmgr->getProcAddress("glUniform1dv"); + if (!Uniform2dv) Uniform2dv = (PFNGLUNIFORM2DVPROC_MT)cmgr->getProcAddress("glUniform2dv"); + if (!Uniform3dv) Uniform3dv = (PFNGLUNIFORM3DVPROC_MT)cmgr->getProcAddress("glUniform3dv"); + if (!Uniform4dv) Uniform4dv = (PFNGLUNIFORM4DVPROC_MT)cmgr->getProcAddress("glUniform4dv"); + if (!UniformMatrix2dv) UniformMatrix2dv = (PFNGLUNIFORMMATRIX2DVPROC_MT)cmgr->getProcAddress("glUniformMatrix2dv"); + if (!UniformMatrix3dv) UniformMatrix3dv = (PFNGLUNIFORMMATRIX3DVPROC_MT)cmgr->getProcAddress("glUniformMatrix3dv"); + if (!UniformMatrix4dv) UniformMatrix4dv = (PFNGLUNIFORMMATRIX4DVPROC_MT)cmgr->getProcAddress("glUniformMatrix4dv"); + if (!UniformMatrix2x3dv) UniformMatrix2x3dv = (PFNGLUNIFORMMATRIX2X3DVPROC_MT)cmgr->getProcAddress("glUniformMatrix2x3dv"); + if (!UniformMatrix2x4dv) UniformMatrix2x4dv = (PFNGLUNIFORMMATRIX2X4DVPROC_MT)cmgr->getProcAddress("glUniformMatrix2x4dv"); + if (!UniformMatrix3x2dv) UniformMatrix3x2dv = (PFNGLUNIFORMMATRIX3X2DVPROC_MT)cmgr->getProcAddress("glUniformMatrix3x2dv"); + if (!UniformMatrix3x4dv) UniformMatrix3x4dv = (PFNGLUNIFORMMATRIX3X4DVPROC_MT)cmgr->getProcAddress("glUniformMatrix3x4dv"); + if (!UniformMatrix4x2dv) UniformMatrix4x2dv = (PFNGLUNIFORMMATRIX4X2DVPROC_MT)cmgr->getProcAddress("glUniformMatrix4x2dv"); + if (!UniformMatrix4x3dv) UniformMatrix4x3dv = (PFNGLUNIFORMMATRIX4X3DVPROC_MT)cmgr->getProcAddress("glUniformMatrix4x3dv"); + if (!GetUniformdv) GetUniformdv = (PFNGLGETUNIFORMDVPROC_MT)cmgr->getProcAddress("glGetUniformdv"); + if (!GetSubroutineUniformLocation) GetSubroutineUniformLocation = (PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC_MT)cmgr->getProcAddress("glGetSubroutineUniformLocation"); + if (!GetSubroutineIndex) GetSubroutineIndex = (PFNGLGETSUBROUTINEINDEXPROC_MT)cmgr->getProcAddress("glGetSubroutineIndex"); + if (!GetActiveSubroutineUniformiv) GetActiveSubroutineUniformiv = (PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC_MT)cmgr->getProcAddress("glGetActiveSubroutineUniformiv"); + if (!GetActiveSubroutineUniformName) GetActiveSubroutineUniformName = (PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC_MT)cmgr->getProcAddress("glGetActiveSubroutineUniformName"); + if (!GetActiveSubroutineName) GetActiveSubroutineName = (PFNGLGETACTIVESUBROUTINENAMEPROC_MT)cmgr->getProcAddress("glGetActiveSubroutineName"); + if (!UniformSubroutinesuiv) UniformSubroutinesuiv = (PFNGLUNIFORMSUBROUTINESUIVPROC_MT)cmgr->getProcAddress("glUniformSubroutinesuiv"); + if (!GetUniformSubroutineuiv) GetUniformSubroutineuiv = (PFNGLGETUNIFORMSUBROUTINEUIVPROC_MT)cmgr->getProcAddress("glGetUniformSubroutineuiv"); + if (!GetProgramStageiv) GetProgramStageiv = (PFNGLGETPROGRAMSTAGEIVPROC_MT)cmgr->getProcAddress("glGetProgramStageiv"); + if (!PatchParameteri) PatchParameteri = (PFNGLPATCHPARAMETERIPROC_MT)cmgr->getProcAddress("glPatchParameteri"); + if (!PatchParameterfv) PatchParameterfv = (PFNGLPATCHPARAMETERFVPROC_MT)cmgr->getProcAddress("glPatchParameterfv"); + if (!BindTransformFeedback) BindTransformFeedback = (PFNGLBINDTRANSFORMFEEDBACKPROC_MT)cmgr->getProcAddress("glBindTransformFeedback"); + if (!DeleteTransformFeedbacks) DeleteTransformFeedbacks = (PFNGLDELETETRANSFORMFEEDBACKSPROC_MT)cmgr->getProcAddress("glDeleteTransformFeedbacks"); + if (!GenTransformFeedbacks) GenTransformFeedbacks = (PFNGLGENTRANSFORMFEEDBACKSPROC_MT)cmgr->getProcAddress("glGenTransformFeedbacks"); + if (!IsTransformFeedback) IsTransformFeedback = (PFNGLISTRANSFORMFEEDBACKPROC_MT)cmgr->getProcAddress("glIsTransformFeedback"); + if (!PauseTransformFeedback) PauseTransformFeedback = (PFNGLPAUSETRANSFORMFEEDBACKPROC_MT)cmgr->getProcAddress("glPauseTransformFeedback"); + if (!ResumeTransformFeedback) ResumeTransformFeedback = (PFNGLRESUMETRANSFORMFEEDBACKPROC_MT)cmgr->getProcAddress("glResumeTransformFeedback"); + if (!DrawTransformFeedback) DrawTransformFeedback = (PFNGLDRAWTRANSFORMFEEDBACKPROC_MT)cmgr->getProcAddress("glDrawTransformFeedback"); + if (!DrawTransformFeedbackStream) DrawTransformFeedbackStream = (PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC_MT)cmgr->getProcAddress("glDrawTransformFeedbackStream"); + if (!BeginQueryIndexed) BeginQueryIndexed = (PFNGLBEGINQUERYINDEXEDPROC_MT)cmgr->getProcAddress("glBeginQueryIndexed"); + if (!EndQueryIndexed) EndQueryIndexed = (PFNGLENDQUERYINDEXEDPROC_MT)cmgr->getProcAddress("glEndQueryIndexed"); + if (!GetQueryIndexediv) GetQueryIndexediv = (PFNGLGETQUERYINDEXEDIVPROC_MT)cmgr->getProcAddress("glGetQueryIndexediv"); + if (!ReleaseShaderCompiler) ReleaseShaderCompiler = (PFNGLRELEASESHADERCOMPILERPROC_MT)cmgr->getProcAddress("glReleaseShaderCompiler"); + if (!ShaderBinary) ShaderBinary = (PFNGLSHADERBINARYPROC_MT)cmgr->getProcAddress("glShaderBinary"); + if (!GetShaderPrecisionFormat) GetShaderPrecisionFormat = (PFNGLGETSHADERPRECISIONFORMATPROC_MT)cmgr->getProcAddress("glGetShaderPrecisionFormat"); + if (!DepthRangef) DepthRangef = (PFNGLDEPTHRANGEFPROC_MT)cmgr->getProcAddress("glDepthRangef"); + if (!ClearDepthf) ClearDepthf = (PFNGLCLEARDEPTHFPROC_MT)cmgr->getProcAddress("glClearDepthf"); + if (!GetProgramBinary) GetProgramBinary = (PFNGLGETPROGRAMBINARYPROC_MT)cmgr->getProcAddress("glGetProgramBinary"); + if (!ProgramBinary) ProgramBinary = (PFNGLPROGRAMBINARYPROC_MT)cmgr->getProcAddress("glProgramBinary"); + if (!ProgramParameteri) ProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC_MT)cmgr->getProcAddress("glProgramParameteri"); + if (!ProgramParameteri) ProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC_MT)cmgr->getProcAddress("glProgramParameteriARB"); + if (!UseProgramStages) UseProgramStages = (PFNGLUSEPROGRAMSTAGESPROC_MT)cmgr->getProcAddress("glUseProgramStages"); + if (!ActiveShaderProgram) ActiveShaderProgram = (PFNGLACTIVESHADERPROGRAMPROC_MT)cmgr->getProcAddress("glActiveShaderProgram"); + if (!CreateShaderProgramv) CreateShaderProgramv = (PFNGLCREATESHADERPROGRAMVPROC_MT)cmgr->getProcAddress("glCreateShaderProgramv"); + if (!BindProgramPipeline) BindProgramPipeline = (PFNGLBINDPROGRAMPIPELINEPROC_MT)cmgr->getProcAddress("glBindProgramPipeline"); + if (!DeleteProgramPipelines) DeleteProgramPipelines = (PFNGLDELETEPROGRAMPIPELINESPROC_MT)cmgr->getProcAddress("glDeleteProgramPipelines"); + if (!GenProgramPipelines) GenProgramPipelines = (PFNGLGENPROGRAMPIPELINESPROC_MT)cmgr->getProcAddress("glGenProgramPipelines"); + if (!IsProgramPipeline) IsProgramPipeline = (PFNGLISPROGRAMPIPELINEPROC_MT)cmgr->getProcAddress("glIsProgramPipeline"); + if (!GetProgramPipelineiv) GetProgramPipelineiv = (PFNGLGETPROGRAMPIPELINEIVPROC_MT)cmgr->getProcAddress("glGetProgramPipelineiv"); + if (!ProgramUniform1i) ProgramUniform1i = (PFNGLPROGRAMUNIFORM1IPROC_MT)cmgr->getProcAddress("glProgramUniform1i"); + if (!ProgramUniform1iv) ProgramUniform1iv = (PFNGLPROGRAMUNIFORM1IVPROC_MT)cmgr->getProcAddress("glProgramUniform1iv"); + if (!ProgramUniform1f) ProgramUniform1f = (PFNGLPROGRAMUNIFORM1FPROC_MT)cmgr->getProcAddress("glProgramUniform1f"); + if (!ProgramUniform1fv) ProgramUniform1fv = (PFNGLPROGRAMUNIFORM1FVPROC_MT)cmgr->getProcAddress("glProgramUniform1fv"); + if (!ProgramUniform1d) ProgramUniform1d = (PFNGLPROGRAMUNIFORM1DPROC_MT)cmgr->getProcAddress("glProgramUniform1d"); + if (!ProgramUniform1dv) ProgramUniform1dv = (PFNGLPROGRAMUNIFORM1DVPROC_MT)cmgr->getProcAddress("glProgramUniform1dv"); + if (!ProgramUniform1ui) ProgramUniform1ui = (PFNGLPROGRAMUNIFORM1UIPROC_MT)cmgr->getProcAddress("glProgramUniform1ui"); + if (!ProgramUniform1uiv) ProgramUniform1uiv = (PFNGLPROGRAMUNIFORM1UIVPROC_MT)cmgr->getProcAddress("glProgramUniform1uiv"); + if (!ProgramUniform2i) ProgramUniform2i = (PFNGLPROGRAMUNIFORM2IPROC_MT)cmgr->getProcAddress("glProgramUniform2i"); + if (!ProgramUniform2iv) ProgramUniform2iv = (PFNGLPROGRAMUNIFORM2IVPROC_MT)cmgr->getProcAddress("glProgramUniform2iv"); + if (!ProgramUniform2f) ProgramUniform2f = (PFNGLPROGRAMUNIFORM2FPROC_MT)cmgr->getProcAddress("glProgramUniform2f"); + if (!ProgramUniform2fv) ProgramUniform2fv = (PFNGLPROGRAMUNIFORM2FVPROC_MT)cmgr->getProcAddress("glProgramUniform2fv"); + if (!ProgramUniform2d) ProgramUniform2d = (PFNGLPROGRAMUNIFORM2DPROC_MT)cmgr->getProcAddress("glProgramUniform2d"); + if (!ProgramUniform2dv) ProgramUniform2dv = (PFNGLPROGRAMUNIFORM2DVPROC_MT)cmgr->getProcAddress("glProgramUniform2dv"); + if (!ProgramUniform2ui) ProgramUniform2ui = (PFNGLPROGRAMUNIFORM2UIPROC_MT)cmgr->getProcAddress("glProgramUniform2ui"); + if (!ProgramUniform2uiv) ProgramUniform2uiv = (PFNGLPROGRAMUNIFORM2UIVPROC_MT)cmgr->getProcAddress("glProgramUniform2uiv"); + if (!ProgramUniform3i) ProgramUniform3i = (PFNGLPROGRAMUNIFORM3IPROC_MT)cmgr->getProcAddress("glProgramUniform3i"); + if (!ProgramUniform3iv) ProgramUniform3iv = (PFNGLPROGRAMUNIFORM3IVPROC_MT)cmgr->getProcAddress("glProgramUniform3iv"); + if (!ProgramUniform3f) ProgramUniform3f = (PFNGLPROGRAMUNIFORM3FPROC_MT)cmgr->getProcAddress("glProgramUniform3f"); + if (!ProgramUniform3fv) ProgramUniform3fv = (PFNGLPROGRAMUNIFORM3FVPROC_MT)cmgr->getProcAddress("glProgramUniform3fv"); + if (!ProgramUniform3d) ProgramUniform3d = (PFNGLPROGRAMUNIFORM3DPROC_MT)cmgr->getProcAddress("glProgramUniform3d"); + if (!ProgramUniform3dv) ProgramUniform3dv = (PFNGLPROGRAMUNIFORM3DVPROC_MT)cmgr->getProcAddress("glProgramUniform3dv"); + if (!ProgramUniform3ui) ProgramUniform3ui = (PFNGLPROGRAMUNIFORM3UIPROC_MT)cmgr->getProcAddress("glProgramUniform3ui"); + if (!ProgramUniform3uiv) ProgramUniform3uiv = (PFNGLPROGRAMUNIFORM3UIVPROC_MT)cmgr->getProcAddress("glProgramUniform3uiv"); + if (!ProgramUniform4i) ProgramUniform4i = (PFNGLPROGRAMUNIFORM4IPROC_MT)cmgr->getProcAddress("glProgramUniform4i"); + if (!ProgramUniform4iv) ProgramUniform4iv = (PFNGLPROGRAMUNIFORM4IVPROC_MT)cmgr->getProcAddress("glProgramUniform4iv"); + if (!ProgramUniform4f) ProgramUniform4f = (PFNGLPROGRAMUNIFORM4FPROC_MT)cmgr->getProcAddress("glProgramUniform4f"); + if (!ProgramUniform4fv) ProgramUniform4fv = (PFNGLPROGRAMUNIFORM4FVPROC_MT)cmgr->getProcAddress("glProgramUniform4fv"); + if (!ProgramUniform4d) ProgramUniform4d = (PFNGLPROGRAMUNIFORM4DPROC_MT)cmgr->getProcAddress("glProgramUniform4d"); + if (!ProgramUniform4dv) ProgramUniform4dv = (PFNGLPROGRAMUNIFORM4DVPROC_MT)cmgr->getProcAddress("glProgramUniform4dv"); + if (!ProgramUniform4ui) ProgramUniform4ui = (PFNGLPROGRAMUNIFORM4UIPROC_MT)cmgr->getProcAddress("glProgramUniform4ui"); + if (!ProgramUniform4uiv) ProgramUniform4uiv = (PFNGLPROGRAMUNIFORM4UIVPROC_MT)cmgr->getProcAddress("glProgramUniform4uiv"); + if (!ProgramUniformMatrix2fv) ProgramUniformMatrix2fv = (PFNGLPROGRAMUNIFORMMATRIX2FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix2fv"); + if (!ProgramUniformMatrix3fv) ProgramUniformMatrix3fv = (PFNGLPROGRAMUNIFORMMATRIX3FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix3fv"); + if (!ProgramUniformMatrix4fv) ProgramUniformMatrix4fv = (PFNGLPROGRAMUNIFORMMATRIX4FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix4fv"); + if (!ProgramUniformMatrix2dv) ProgramUniformMatrix2dv = (PFNGLPROGRAMUNIFORMMATRIX2DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix2dv"); + if (!ProgramUniformMatrix3dv) ProgramUniformMatrix3dv = (PFNGLPROGRAMUNIFORMMATRIX3DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix3dv"); + if (!ProgramUniformMatrix4dv) ProgramUniformMatrix4dv = (PFNGLPROGRAMUNIFORMMATRIX4DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix4dv"); + if (!ProgramUniformMatrix2x3fv) ProgramUniformMatrix2x3fv = (PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix2x3fv"); + if (!ProgramUniformMatrix3x2fv) ProgramUniformMatrix3x2fv = (PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix3x2fv"); + if (!ProgramUniformMatrix2x4fv) ProgramUniformMatrix2x4fv = (PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix2x4fv"); + if (!ProgramUniformMatrix4x2fv) ProgramUniformMatrix4x2fv = (PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix4x2fv"); + if (!ProgramUniformMatrix3x4fv) ProgramUniformMatrix3x4fv = (PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix3x4fv"); + if (!ProgramUniformMatrix4x3fv) ProgramUniformMatrix4x3fv = (PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix4x3fv"); + if (!ProgramUniformMatrix2x3dv) ProgramUniformMatrix2x3dv = (PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix2x3dv"); + if (!ProgramUniformMatrix3x2dv) ProgramUniformMatrix3x2dv = (PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix3x2dv"); + if (!ProgramUniformMatrix2x4dv) ProgramUniformMatrix2x4dv = (PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix2x4dv"); + if (!ProgramUniformMatrix4x2dv) ProgramUniformMatrix4x2dv = (PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix4x2dv"); + if (!ProgramUniformMatrix3x4dv) ProgramUniformMatrix3x4dv = (PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix3x4dv"); + if (!ProgramUniformMatrix4x3dv) ProgramUniformMatrix4x3dv = (PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC_MT)cmgr->getProcAddress("glProgramUniformMatrix4x3dv"); + if (!ValidateProgramPipeline) ValidateProgramPipeline = (PFNGLVALIDATEPROGRAMPIPELINEPROC_MT)cmgr->getProcAddress("glValidateProgramPipeline"); + if (!GetProgramPipelineInfoLog) GetProgramPipelineInfoLog = (PFNGLGETPROGRAMPIPELINEINFOLOGPROC_MT)cmgr->getProcAddress("glGetProgramPipelineInfoLog"); + if (!VertexAttribL1d) VertexAttribL1d = (PFNGLVERTEXATTRIBL1DPROC_MT)cmgr->getProcAddress("glVertexAttribL1d"); + if (!VertexAttribL2d) VertexAttribL2d = (PFNGLVERTEXATTRIBL2DPROC_MT)cmgr->getProcAddress("glVertexAttribL2d"); + if (!VertexAttribL3d) VertexAttribL3d = (PFNGLVERTEXATTRIBL3DPROC_MT)cmgr->getProcAddress("glVertexAttribL3d"); + if (!VertexAttribL4d) VertexAttribL4d = (PFNGLVERTEXATTRIBL4DPROC_MT)cmgr->getProcAddress("glVertexAttribL4d"); + if (!VertexAttribL1dv) VertexAttribL1dv = (PFNGLVERTEXATTRIBL1DVPROC_MT)cmgr->getProcAddress("glVertexAttribL1dv"); + if (!VertexAttribL2dv) VertexAttribL2dv = (PFNGLVERTEXATTRIBL2DVPROC_MT)cmgr->getProcAddress("glVertexAttribL2dv"); + if (!VertexAttribL3dv) VertexAttribL3dv = (PFNGLVERTEXATTRIBL3DVPROC_MT)cmgr->getProcAddress("glVertexAttribL3dv"); + if (!VertexAttribL4dv) VertexAttribL4dv = (PFNGLVERTEXATTRIBL4DVPROC_MT)cmgr->getProcAddress("glVertexAttribL4dv"); + if (!VertexAttribLPointer) VertexAttribLPointer = (PFNGLVERTEXATTRIBLPOINTERPROC_MT)cmgr->getProcAddress("glVertexAttribLPointer"); + if (!GetVertexAttribLdv) GetVertexAttribLdv = (PFNGLGETVERTEXATTRIBLDVPROC_MT)cmgr->getProcAddress("glGetVertexAttribLdv"); + if (!ViewportArrayv) ViewportArrayv = (PFNGLVIEWPORTARRAYVPROC_MT)cmgr->getProcAddress("glViewportArrayv"); + if (!ViewportIndexedf) ViewportIndexedf = (PFNGLVIEWPORTINDEXEDFPROC_MT)cmgr->getProcAddress("glViewportIndexedf"); + if (!ViewportIndexedfv) ViewportIndexedfv = (PFNGLVIEWPORTINDEXEDFVPROC_MT)cmgr->getProcAddress("glViewportIndexedfv"); + if (!ScissorArrayv) ScissorArrayv = (PFNGLSCISSORARRAYVPROC_MT)cmgr->getProcAddress("glScissorArrayv"); + if (!ScissorIndexed) ScissorIndexed = (PFNGLSCISSORINDEXEDPROC_MT)cmgr->getProcAddress("glScissorIndexed"); + if (!ScissorIndexedv) ScissorIndexedv = (PFNGLSCISSORINDEXEDVPROC_MT)cmgr->getProcAddress("glScissorIndexedv"); + if (!DepthRangeArrayv) DepthRangeArrayv = (PFNGLDEPTHRANGEARRAYVPROC_MT)cmgr->getProcAddress("glDepthRangeArrayv"); + if (!DepthRangeIndexed) DepthRangeIndexed = (PFNGLDEPTHRANGEINDEXEDPROC_MT)cmgr->getProcAddress("glDepthRangeIndexed"); + if (!DrawArraysInstancedBaseInstance) DrawArraysInstancedBaseInstance = (PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC_MT)cmgr->getProcAddress("glDrawArraysInstancedBaseInstance"); + if (!DrawElementsInstancedBaseInstance) DrawElementsInstancedBaseInstance = (PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC_MT)cmgr->getProcAddress("glDrawElementsInstancedBaseInstance"); + if (!DrawElementsInstancedBaseVertexBaseInstance) DrawElementsInstancedBaseVertexBaseInstance = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC_MT)cmgr->getProcAddress("glDrawElementsInstancedBaseVertexBaseInstance"); + if (!GetInternalformativ) GetInternalformativ = (PFNGLGETINTERNALFORMATIVPROC_MT)cmgr->getProcAddress("glGetInternalformativ"); + if (!GetActiveAtomicCounterBufferiv) GetActiveAtomicCounterBufferiv = (PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC_MT)cmgr->getProcAddress("glGetActiveAtomicCounterBufferiv"); + if (!BindImageTexture) BindImageTexture = (PFNGLBINDIMAGETEXTUREPROC_MT)cmgr->getProcAddress("glBindImageTexture"); + if (!MemoryBarrier) MemoryBarrier = (PFNGLMEMORYBARRIERPROC_MT)cmgr->getProcAddress("glMemoryBarrier"); + if (!TexStorage1D) TexStorage1D = (PFNGLTEXSTORAGE1DPROC_MT)cmgr->getProcAddress("glTexStorage1D"); + if (!TexStorage2D) TexStorage2D = (PFNGLTEXSTORAGE2DPROC_MT)cmgr->getProcAddress("glTexStorage2D"); + if (!TexStorage3D) TexStorage3D = (PFNGLTEXSTORAGE3DPROC_MT)cmgr->getProcAddress("glTexStorage3D"); + if (!DrawTransformFeedbackInstanced) DrawTransformFeedbackInstanced = (PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC_MT)cmgr->getProcAddress("glDrawTransformFeedbackInstanced"); + if (!DrawTransformFeedbackStreamInstanced) DrawTransformFeedbackStreamInstanced = (PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC_MT)cmgr->getProcAddress("glDrawTransformFeedbackStreamInstanced"); + if (!ClearBufferData) ClearBufferData = (PFNGLCLEARBUFFERDATAPROC_MT)cmgr->getProcAddress("glClearBufferData"); + if (!ClearBufferSubData) ClearBufferSubData = (PFNGLCLEARBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glClearBufferSubData"); + if (!DispatchCompute) DispatchCompute = (PFNGLDISPATCHCOMPUTEPROC_MT)cmgr->getProcAddress("glDispatchCompute"); + if (!DispatchComputeIndirect) DispatchComputeIndirect = (PFNGLDISPATCHCOMPUTEINDIRECTPROC_MT)cmgr->getProcAddress("glDispatchComputeIndirect"); + if (!CopyImageSubData) CopyImageSubData = (PFNGLCOPYIMAGESUBDATAPROC_MT)cmgr->getProcAddress("glCopyImageSubData"); + if (!FramebufferParameteri) FramebufferParameteri = (PFNGLFRAMEBUFFERPARAMETERIPROC_MT)cmgr->getProcAddress("glFramebufferParameteri"); + if (!GetFramebufferParameteriv) GetFramebufferParameteriv = (PFNGLGETFRAMEBUFFERPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetFramebufferParameteriv"); + if (!GetInternalformati64v) GetInternalformati64v = (PFNGLGETINTERNALFORMATI64VPROC_MT)cmgr->getProcAddress("glGetInternalformati64v"); + if (!InvalidateTexSubImage) InvalidateTexSubImage = (PFNGLINVALIDATETEXSUBIMAGEPROC_MT)cmgr->getProcAddress("glInvalidateTexSubImage"); + if (!InvalidateTexImage) InvalidateTexImage = (PFNGLINVALIDATETEXIMAGEPROC_MT)cmgr->getProcAddress("glInvalidateTexImage"); + if (!InvalidateBufferSubData) InvalidateBufferSubData = (PFNGLINVALIDATEBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glInvalidateBufferSubData"); + if (!InvalidateBufferData) InvalidateBufferData = (PFNGLINVALIDATEBUFFERDATAPROC_MT)cmgr->getProcAddress("glInvalidateBufferData"); + if (!InvalidateFramebuffer) InvalidateFramebuffer = (PFNGLINVALIDATEFRAMEBUFFERPROC_MT)cmgr->getProcAddress("glInvalidateFramebuffer"); + if (!InvalidateSubFramebuffer) InvalidateSubFramebuffer = (PFNGLINVALIDATESUBFRAMEBUFFERPROC_MT)cmgr->getProcAddress("glInvalidateSubFramebuffer"); + if (!MultiDrawArraysIndirect) MultiDrawArraysIndirect = (PFNGLMULTIDRAWARRAYSINDIRECTPROC_MT)cmgr->getProcAddress("glMultiDrawArraysIndirect"); + if (!MultiDrawElementsIndirect) MultiDrawElementsIndirect = (PFNGLMULTIDRAWELEMENTSINDIRECTPROC_MT)cmgr->getProcAddress("glMultiDrawElementsIndirect"); + if (!GetProgramInterfaceiv) GetProgramInterfaceiv = (PFNGLGETPROGRAMINTERFACEIVPROC_MT)cmgr->getProcAddress("glGetProgramInterfaceiv"); + if (!GetProgramResourceIndex) GetProgramResourceIndex = (PFNGLGETPROGRAMRESOURCEINDEXPROC_MT)cmgr->getProcAddress("glGetProgramResourceIndex"); + if (!GetProgramResourceName) GetProgramResourceName = (PFNGLGETPROGRAMRESOURCENAMEPROC_MT)cmgr->getProcAddress("glGetProgramResourceName"); + if (!GetProgramResourceiv) GetProgramResourceiv = (PFNGLGETPROGRAMRESOURCEIVPROC_MT)cmgr->getProcAddress("glGetProgramResourceiv"); + if (!GetProgramResourceLocation) GetProgramResourceLocation = (PFNGLGETPROGRAMRESOURCELOCATIONPROC_MT)cmgr->getProcAddress("glGetProgramResourceLocation"); + if (!GetProgramResourceLocationIndex) GetProgramResourceLocationIndex = (PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC_MT)cmgr->getProcAddress("glGetProgramResourceLocationIndex"); + if (!ShaderStorageBlockBinding) ShaderStorageBlockBinding = (PFNGLSHADERSTORAGEBLOCKBINDINGPROC_MT)cmgr->getProcAddress("glShaderStorageBlockBinding"); + if (!TexBufferRange) TexBufferRange = (PFNGLTEXBUFFERRANGEPROC_MT)cmgr->getProcAddress("glTexBufferRange"); + if (!TexStorage2DMultisample) TexStorage2DMultisample = (PFNGLTEXSTORAGE2DMULTISAMPLEPROC_MT)cmgr->getProcAddress("glTexStorage2DMultisample"); + if (!TexStorage3DMultisample) TexStorage3DMultisample = (PFNGLTEXSTORAGE3DMULTISAMPLEPROC_MT)cmgr->getProcAddress("glTexStorage3DMultisample"); + if (!TextureView) TextureView = (PFNGLTEXTUREVIEWPROC_MT)cmgr->getProcAddress("glTextureView"); + if (!BindVertexBuffer) BindVertexBuffer = (PFNGLBINDVERTEXBUFFERPROC_MT)cmgr->getProcAddress("glBindVertexBuffer"); + if (!VertexAttribFormat) VertexAttribFormat = (PFNGLVERTEXATTRIBFORMATPROC_MT)cmgr->getProcAddress("glVertexAttribFormat"); + if (!VertexAttribIFormat) VertexAttribIFormat = (PFNGLVERTEXATTRIBIFORMATPROC_MT)cmgr->getProcAddress("glVertexAttribIFormat"); + if (!VertexAttribLFormat) VertexAttribLFormat = (PFNGLVERTEXATTRIBLFORMATPROC_MT)cmgr->getProcAddress("glVertexAttribLFormat"); + if (!VertexAttribBinding) VertexAttribBinding = (PFNGLVERTEXATTRIBBINDINGPROC_MT)cmgr->getProcAddress("glVertexAttribBinding"); + if (!VertexBindingDivisor) VertexBindingDivisor = (PFNGLVERTEXBINDINGDIVISORPROC_MT)cmgr->getProcAddress("glVertexBindingDivisor"); + if (!DebugMessageControl) DebugMessageControl = (PFNGLDEBUGMESSAGECONTROLPROC_MT)cmgr->getProcAddress("glDebugMessageControl"); + if (!DebugMessageControl) DebugMessageControl = (PFNGLDEBUGMESSAGECONTROLPROC_MT)cmgr->getProcAddress("glDebugMessageControlARB"); + if (!DebugMessageInsert) DebugMessageInsert = (PFNGLDEBUGMESSAGEINSERTPROC_MT)cmgr->getProcAddress("glDebugMessageInsert"); + if (!DebugMessageInsert) DebugMessageInsert = (PFNGLDEBUGMESSAGEINSERTPROC_MT)cmgr->getProcAddress("glDebugMessageInsertARB"); + if (!DebugMessageCallback) DebugMessageCallback = (PFNGLDEBUGMESSAGECALLBACKPROC_MT)cmgr->getProcAddress("glDebugMessageCallback"); + if (!DebugMessageCallback) DebugMessageCallback = (PFNGLDEBUGMESSAGECALLBACKPROC_MT)cmgr->getProcAddress("glDebugMessageCallbackARB"); + if (!GetDebugMessageLog) GetDebugMessageLog = (PFNGLGETDEBUGMESSAGELOGPROC_MT)cmgr->getProcAddress("glGetDebugMessageLog"); + if (!GetDebugMessageLog) GetDebugMessageLog = (PFNGLGETDEBUGMESSAGELOGPROC_MT)cmgr->getProcAddress("glGetDebugMessageLogARB"); + if (!PushDebugGroup) PushDebugGroup = (PFNGLPUSHDEBUGGROUPPROC_MT)cmgr->getProcAddress("glPushDebugGroup"); + if (!PopDebugGroup) PopDebugGroup = (PFNGLPOPDEBUGGROUPPROC_MT)cmgr->getProcAddress("glPopDebugGroup"); + if (!ObjectLabel) ObjectLabel = (PFNGLOBJECTLABELPROC_MT)cmgr->getProcAddress("glObjectLabel"); + if (!GetObjectLabel) GetObjectLabel = (PFNGLGETOBJECTLABELPROC_MT)cmgr->getProcAddress("glGetObjectLabel"); + if (!ObjectPtrLabel) ObjectPtrLabel = (PFNGLOBJECTPTRLABELPROC_MT)cmgr->getProcAddress("glObjectPtrLabel"); + if (!GetObjectPtrLabel) GetObjectPtrLabel = (PFNGLGETOBJECTPTRLABELPROC_MT)cmgr->getProcAddress("glGetObjectPtrLabel"); + if (!BufferStorage) BufferStorage = (PFNGLBUFFERSTORAGEPROC_MT)cmgr->getProcAddress("glBufferStorage"); + if (!ClearTexImage) ClearTexImage = (PFNGLCLEARTEXIMAGEPROC_MT)cmgr->getProcAddress("glClearTexImage"); + if (!ClearTexSubImage) ClearTexSubImage = (PFNGLCLEARTEXSUBIMAGEPROC_MT)cmgr->getProcAddress("glClearTexSubImage"); + if (!BindBuffersBase) BindBuffersBase = (PFNGLBINDBUFFERSBASEPROC_MT)cmgr->getProcAddress("glBindBuffersBase"); + if (!BindBuffersRange) BindBuffersRange = (PFNGLBINDBUFFERSRANGEPROC_MT)cmgr->getProcAddress("glBindBuffersRange"); + if (!BindTextures) BindTextures = (PFNGLBINDTEXTURESPROC_MT)cmgr->getProcAddress("glBindTextures"); + if (!BindSamplers) BindSamplers = (PFNGLBINDSAMPLERSPROC_MT)cmgr->getProcAddress("glBindSamplers"); + if (!BindImageTextures) BindImageTextures = (PFNGLBINDIMAGETEXTURESPROC_MT)cmgr->getProcAddress("glBindImageTextures"); + if (!BindVertexBuffers) BindVertexBuffers = (PFNGLBINDVERTEXBUFFERSPROC_MT)cmgr->getProcAddress("glBindVertexBuffers"); + if (!ClipControl) ClipControl = (PFNGLCLIPCONTROLPROC_MT)cmgr->getProcAddress("glClipControl"); + if (!CreateTransformFeedbacks) CreateTransformFeedbacks = (PFNGLCREATETRANSFORMFEEDBACKSPROC_MT)cmgr->getProcAddress("glCreateTransformFeedbacks"); + if (!TransformFeedbackBufferBase) TransformFeedbackBufferBase = (PFNGLTRANSFORMFEEDBACKBUFFERBASEPROC_MT)cmgr->getProcAddress("glTransformFeedbackBufferBase"); + if (!TransformFeedbackBufferRange) TransformFeedbackBufferRange = (PFNGLTRANSFORMFEEDBACKBUFFERRANGEPROC_MT)cmgr->getProcAddress("glTransformFeedbackBufferRange"); + if (!GetTransformFeedbackiv) GetTransformFeedbackiv = (PFNGLGETTRANSFORMFEEDBACKIVPROC_MT)cmgr->getProcAddress("glGetTransformFeedbackiv"); + if (!CreateBuffers) CreateBuffers = (PFNGLCREATEBUFFERSPROC_MT)cmgr->getProcAddress("glCreateBuffers"); + if (!NamedBufferStorage) NamedBufferStorage = (PFNGLNAMEDBUFFERSTORAGEPROC_MT)cmgr->getProcAddress("glNamedBufferStorage"); + if (!NamedBufferData) NamedBufferData = (PFNGLNAMEDBUFFERDATAPROC_MT)cmgr->getProcAddress("glNamedBufferData"); + if (!NamedBufferSubData) NamedBufferSubData = (PFNGLNAMEDBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glNamedBufferSubData"); + if (!CopyNamedBufferSubData) CopyNamedBufferSubData = (PFNGLCOPYNAMEDBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glCopyNamedBufferSubData"); + if (!ClearNamedBufferData) ClearNamedBufferData = (PFNGLCLEARNAMEDBUFFERDATAPROC_MT)cmgr->getProcAddress("glClearNamedBufferData"); + if (!ClearNamedBufferSubData) ClearNamedBufferSubData = (PFNGLCLEARNAMEDBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glClearNamedBufferSubData"); + if (!MapNamedBuffer) MapNamedBuffer = (PFNGLMAPNAMEDBUFFERPROC_MT)cmgr->getProcAddress("glMapNamedBuffer"); + if (!MapNamedBufferRange) MapNamedBufferRange = (PFNGLMAPNAMEDBUFFERRANGEPROC_MT)cmgr->getProcAddress("glMapNamedBufferRange"); + if (!UnmapNamedBuffer) UnmapNamedBuffer = (PFNGLUNMAPNAMEDBUFFERPROC_MT)cmgr->getProcAddress("glUnmapNamedBuffer"); + if (!FlushMappedNamedBufferRange) FlushMappedNamedBufferRange = (PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEPROC_MT)cmgr->getProcAddress("glFlushMappedNamedBufferRange"); + if (!GetNamedBufferParameteriv) GetNamedBufferParameteriv = (PFNGLGETNAMEDBUFFERPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetNamedBufferParameteriv"); + if (!GetNamedBufferParameteri64v) GetNamedBufferParameteri64v = (PFNGLGETNAMEDBUFFERPARAMETERI64VPROC_MT)cmgr->getProcAddress("glGetNamedBufferParameteri64v"); + if (!GetNamedBufferPointerv) GetNamedBufferPointerv = (PFNGLGETNAMEDBUFFERPOINTERVPROC_MT)cmgr->getProcAddress("glGetNamedBufferPointerv"); + if (!GetNamedBufferSubData) GetNamedBufferSubData = (PFNGLGETNAMEDBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glGetNamedBufferSubData"); + if (!CreateFramebuffers) CreateFramebuffers = (PFNGLCREATEFRAMEBUFFERSPROC_MT)cmgr->getProcAddress("glCreateFramebuffers"); + if (!NamedFramebufferRenderbuffer) NamedFramebufferRenderbuffer = (PFNGLNAMEDFRAMEBUFFERRENDERBUFFERPROC_MT)cmgr->getProcAddress("glNamedFramebufferRenderbuffer"); + if (!NamedFramebufferParameteri) NamedFramebufferParameteri = (PFNGLNAMEDFRAMEBUFFERPARAMETERIPROC_MT)cmgr->getProcAddress("glNamedFramebufferParameteri"); + if (!NamedFramebufferTexture) NamedFramebufferTexture = (PFNGLNAMEDFRAMEBUFFERTEXTUREPROC_MT)cmgr->getProcAddress("glNamedFramebufferTexture"); + if (!NamedFramebufferTextureLayer) NamedFramebufferTextureLayer = (PFNGLNAMEDFRAMEBUFFERTEXTURELAYERPROC_MT)cmgr->getProcAddress("glNamedFramebufferTextureLayer"); + if (!NamedFramebufferDrawBuffer) NamedFramebufferDrawBuffer = (PFNGLNAMEDFRAMEBUFFERDRAWBUFFERPROC_MT)cmgr->getProcAddress("glNamedFramebufferDrawBuffer"); + if (!NamedFramebufferDrawBuffers) NamedFramebufferDrawBuffers = (PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC_MT)cmgr->getProcAddress("glNamedFramebufferDrawBuffers"); + if (!NamedFramebufferReadBuffer) NamedFramebufferReadBuffer = (PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC_MT)cmgr->getProcAddress("glNamedFramebufferReadBuffer"); + if (!InvalidateNamedFramebufferData) InvalidateNamedFramebufferData = (PFNGLINVALIDATENAMEDFRAMEBUFFERDATAPROC_MT)cmgr->getProcAddress("glInvalidateNamedFramebufferData"); + if (!InvalidateNamedFramebufferSubData) InvalidateNamedFramebufferSubData = (PFNGLINVALIDATENAMEDFRAMEBUFFERSUBDATAPROC_MT)cmgr->getProcAddress("glInvalidateNamedFramebufferSubData"); + if (!ClearNamedFramebufferiv) ClearNamedFramebufferiv = (PFNGLCLEARNAMEDFRAMEBUFFERIVPROC_MT)cmgr->getProcAddress("glClearNamedFramebufferiv"); + if (!ClearNamedFramebufferuiv) ClearNamedFramebufferuiv = (PFNGLCLEARNAMEDFRAMEBUFFERUIVPROC_MT)cmgr->getProcAddress("glClearNamedFramebufferuiv"); + if (!ClearNamedFramebufferfv) ClearNamedFramebufferfv = (PFNGLCLEARNAMEDFRAMEBUFFERFVPROC_MT)cmgr->getProcAddress("glClearNamedFramebufferfv"); + if (!ClearNamedFramebufferfi) ClearNamedFramebufferfi = (PFNGLCLEARNAMEDFRAMEBUFFERFIPROC_MT)cmgr->getProcAddress("glClearNamedFramebufferfi"); + if (!BlitNamedFramebuffer) BlitNamedFramebuffer = (PFNGLBLITNAMEDFRAMEBUFFERPROC_MT)cmgr->getProcAddress("glBlitNamedFramebuffer"); + if (!CheckNamedFramebufferStatus) CheckNamedFramebufferStatus = (PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC_MT)cmgr->getProcAddress("glCheckNamedFramebufferStatus"); + if (!GetNamedFramebufferParameteriv) GetNamedFramebufferParameteriv = (PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetNamedFramebufferParameteriv"); + if (!GetNamedFramebufferAttachmentParameteriv) GetNamedFramebufferAttachmentParameteriv = (PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetNamedFramebufferAttachmentParameteriv"); + if (!CreateRenderbuffers) CreateRenderbuffers = (PFNGLCREATERENDERBUFFERSPROC_MT)cmgr->getProcAddress("glCreateRenderbuffers"); + if (!NamedRenderbufferStorage) NamedRenderbufferStorage = (PFNGLNAMEDRENDERBUFFERSTORAGEPROC_MT)cmgr->getProcAddress("glNamedRenderbufferStorage"); + if (!NamedRenderbufferStorageMultisample) NamedRenderbufferStorageMultisample = (PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEPROC_MT)cmgr->getProcAddress("glNamedRenderbufferStorageMultisample"); + if (!GetNamedRenderbufferParameteriv) GetNamedRenderbufferParameteriv = (PFNGLGETNAMEDRENDERBUFFERPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetNamedRenderbufferParameteriv"); + if (!CreateTextures) CreateTextures = (PFNGLCREATETEXTURESPROC_MT)cmgr->getProcAddress("glCreateTextures"); + if (!TextureBuffer) TextureBuffer = (PFNGLTEXTUREBUFFERPROC_MT)cmgr->getProcAddress("glTextureBuffer"); + if (!TextureBufferRange) TextureBufferRange = (PFNGLTEXTUREBUFFERRANGEPROC_MT)cmgr->getProcAddress("glTextureBufferRange"); + if (!TextureStorage1D) TextureStorage1D = (PFNGLTEXTURESTORAGE1DPROC_MT)cmgr->getProcAddress("glTextureStorage1D"); + if (!TextureStorage2D) TextureStorage2D = (PFNGLTEXTURESTORAGE2DPROC_MT)cmgr->getProcAddress("glTextureStorage2D"); + if (!TextureStorage3D) TextureStorage3D = (PFNGLTEXTURESTORAGE3DPROC_MT)cmgr->getProcAddress("glTextureStorage3D"); + if (!TextureStorage2DMultisample) TextureStorage2DMultisample = (PFNGLTEXTURESTORAGE2DMULTISAMPLEPROC_MT)cmgr->getProcAddress("glTextureStorage2DMultisample"); + if (!TextureStorage3DMultisample) TextureStorage3DMultisample = (PFNGLTEXTURESTORAGE3DMULTISAMPLEPROC_MT)cmgr->getProcAddress("glTextureStorage3DMultisample"); + if (!TextureSubImage1D) TextureSubImage1D = (PFNGLTEXTURESUBIMAGE1DPROC_MT)cmgr->getProcAddress("glTextureSubImage1D"); + if (!TextureSubImage2D) TextureSubImage2D = (PFNGLTEXTURESUBIMAGE2DPROC_MT)cmgr->getProcAddress("glTextureSubImage2D"); + if (!TextureSubImage3D) TextureSubImage3D = (PFNGLTEXTURESUBIMAGE3DPROC_MT)cmgr->getProcAddress("glTextureSubImage3D"); + if (!CompressedTextureSubImage1D) CompressedTextureSubImage1D = (PFNGLCOMPRESSEDTEXTURESUBIMAGE1DPROC_MT)cmgr->getProcAddress("glCompressedTextureSubImage1D"); + if (!CompressedTextureSubImage2D) CompressedTextureSubImage2D = (PFNGLCOMPRESSEDTEXTURESUBIMAGE2DPROC_MT)cmgr->getProcAddress("glCompressedTextureSubImage2D"); + if (!CompressedTextureSubImage3D) CompressedTextureSubImage3D = (PFNGLCOMPRESSEDTEXTURESUBIMAGE3DPROC_MT)cmgr->getProcAddress("glCompressedTextureSubImage3D"); + if (!CopyTextureSubImage1D) CopyTextureSubImage1D = (PFNGLCOPYTEXTURESUBIMAGE1DPROC_MT)cmgr->getProcAddress("glCopyTextureSubImage1D"); + if (!CopyTextureSubImage2D) CopyTextureSubImage2D = (PFNGLCOPYTEXTURESUBIMAGE2DPROC_MT)cmgr->getProcAddress("glCopyTextureSubImage2D"); + if (!CopyTextureSubImage3D) CopyTextureSubImage3D = (PFNGLCOPYTEXTURESUBIMAGE3DPROC_MT)cmgr->getProcAddress("glCopyTextureSubImage3D"); + if (!TextureParameterf) TextureParameterf = (PFNGLTEXTUREPARAMETERFPROC_MT)cmgr->getProcAddress("glTextureParameterf"); + if (!TextureParameterfv) TextureParameterfv = (PFNGLTEXTUREPARAMETERFVPROC_MT)cmgr->getProcAddress("glTextureParameterfv"); + if (!TextureParameteri) TextureParameteri = (PFNGLTEXTUREPARAMETERIPROC_MT)cmgr->getProcAddress("glTextureParameteri"); + if (!TextureParameterIiv) TextureParameterIiv = (PFNGLTEXTUREPARAMETERIIVPROC_MT)cmgr->getProcAddress("glTextureParameterIiv"); + if (!TextureParameterIuiv) TextureParameterIuiv = (PFNGLTEXTUREPARAMETERIUIVPROC_MT)cmgr->getProcAddress("glTextureParameterIuiv"); + if (!TextureParameteriv) TextureParameteriv = (PFNGLTEXTUREPARAMETERIVPROC_MT)cmgr->getProcAddress("glTextureParameteriv"); + if (!GenerateTextureMipmap) GenerateTextureMipmap = (PFNGLGENERATETEXTUREMIPMAPPROC_MT)cmgr->getProcAddress("glGenerateTextureMipmap"); + if (!BindTextureUnit) BindTextureUnit = (PFNGLBINDTEXTUREUNITPROC_MT)cmgr->getProcAddress("glBindTextureUnit"); + if (!GetTextureImage) GetTextureImage = (PFNGLGETTEXTUREIMAGEPROC_MT)cmgr->getProcAddress("glGetTextureImage"); + if (!GetCompressedTextureImage) GetCompressedTextureImage = (PFNGLGETCOMPRESSEDTEXTUREIMAGEPROC_MT)cmgr->getProcAddress("glGetCompressedTextureImage"); + if (!GetTextureLevelParameterfv) GetTextureLevelParameterfv = (PFNGLGETTEXTURELEVELPARAMETERFVPROC_MT)cmgr->getProcAddress("glGetTextureLevelParameterfv"); + if (!GetTextureLevelParameteriv) GetTextureLevelParameteriv = (PFNGLGETTEXTURELEVELPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetTextureLevelParameteriv"); + if (!GetTextureParameterfv) GetTextureParameterfv = (PFNGLGETTEXTUREPARAMETERFVPROC_MT)cmgr->getProcAddress("glGetTextureParameterfv"); + if (!GetTextureParameterIiv) GetTextureParameterIiv = (PFNGLGETTEXTUREPARAMETERIIVPROC_MT)cmgr->getProcAddress("glGetTextureParameterIiv"); + if (!GetTextureParameterIuiv) GetTextureParameterIuiv = (PFNGLGETTEXTUREPARAMETERIUIVPROC_MT)cmgr->getProcAddress("glGetTextureParameterIuiv"); + if (!GetTextureParameteriv) GetTextureParameteriv = (PFNGLGETTEXTUREPARAMETERIVPROC_MT)cmgr->getProcAddress("glGetTextureParameteriv"); + if (!CreateVertexArrays) CreateVertexArrays = (PFNGLCREATEVERTEXARRAYSPROC_MT)cmgr->getProcAddress("glCreateVertexArrays"); + if (!DisableVertexArrayAttrib) DisableVertexArrayAttrib = (PFNGLDISABLEVERTEXARRAYATTRIBPROC_MT)cmgr->getProcAddress("glDisableVertexArrayAttrib"); + if (!EnableVertexArrayAttrib) EnableVertexArrayAttrib = (PFNGLENABLEVERTEXARRAYATTRIBPROC_MT)cmgr->getProcAddress("glEnableVertexArrayAttrib"); + if (!VertexArrayElementBuffer) VertexArrayElementBuffer = (PFNGLVERTEXARRAYELEMENTBUFFERPROC_MT)cmgr->getProcAddress("glVertexArrayElementBuffer"); + if (!VertexArrayVertexBuffer) VertexArrayVertexBuffer = (PFNGLVERTEXARRAYVERTEXBUFFERPROC_MT)cmgr->getProcAddress("glVertexArrayVertexBuffer"); + if (!VertexArrayVertexBuffers) VertexArrayVertexBuffers = (PFNGLVERTEXARRAYVERTEXBUFFERSPROC_MT)cmgr->getProcAddress("glVertexArrayVertexBuffers"); + if (!VertexArrayAttribBinding) VertexArrayAttribBinding = (PFNGLVERTEXARRAYATTRIBBINDINGPROC_MT)cmgr->getProcAddress("glVertexArrayAttribBinding"); + if (!VertexArrayAttribFormat) VertexArrayAttribFormat = (PFNGLVERTEXARRAYATTRIBFORMATPROC_MT)cmgr->getProcAddress("glVertexArrayAttribFormat"); + if (!VertexArrayAttribIFormat) VertexArrayAttribIFormat = (PFNGLVERTEXARRAYATTRIBIFORMATPROC_MT)cmgr->getProcAddress("glVertexArrayAttribIFormat"); + if (!VertexArrayAttribLFormat) VertexArrayAttribLFormat = (PFNGLVERTEXARRAYATTRIBLFORMATPROC_MT)cmgr->getProcAddress("glVertexArrayAttribLFormat"); + if (!VertexArrayBindingDivisor) VertexArrayBindingDivisor = (PFNGLVERTEXARRAYBINDINGDIVISORPROC_MT)cmgr->getProcAddress("glVertexArrayBindingDivisor"); + if (!GetVertexArrayiv) GetVertexArrayiv = (PFNGLGETVERTEXARRAYIVPROC_MT)cmgr->getProcAddress("glGetVertexArrayiv"); + if (!GetVertexArrayIndexediv) GetVertexArrayIndexediv = (PFNGLGETVERTEXARRAYINDEXEDIVPROC_MT)cmgr->getProcAddress("glGetVertexArrayIndexediv"); + if (!GetVertexArrayIndexed64iv) GetVertexArrayIndexed64iv = (PFNGLGETVERTEXARRAYINDEXED64IVPROC_MT)cmgr->getProcAddress("glGetVertexArrayIndexed64iv"); + if (!CreateSamplers) CreateSamplers = (PFNGLCREATESAMPLERSPROC_MT)cmgr->getProcAddress("glCreateSamplers"); + if (!CreateProgramPipelines) CreateProgramPipelines = (PFNGLCREATEPROGRAMPIPELINESPROC_MT)cmgr->getProcAddress("glCreateProgramPipelines"); + if (!CreateQueries) CreateQueries = (PFNGLCREATEQUERIESPROC_MT)cmgr->getProcAddress("glCreateQueries"); + if (!GetQueryBufferObjecti64v) GetQueryBufferObjecti64v = (PFNGLGETQUERYBUFFEROBJECTI64VPROC_MT)cmgr->getProcAddress("glGetQueryBufferObjecti64v"); + if (!GetQueryBufferObjectiv) GetQueryBufferObjectiv = (PFNGLGETQUERYBUFFEROBJECTIVPROC_MT)cmgr->getProcAddress("glGetQueryBufferObjectiv"); + if (!GetQueryBufferObjectui64v) GetQueryBufferObjectui64v = (PFNGLGETQUERYBUFFEROBJECTUI64VPROC_MT)cmgr->getProcAddress("glGetQueryBufferObjectui64v"); + if (!GetQueryBufferObjectuiv) GetQueryBufferObjectuiv = (PFNGLGETQUERYBUFFEROBJECTUIVPROC_MT)cmgr->getProcAddress("glGetQueryBufferObjectuiv"); + if (!MemoryBarrierByRegion) MemoryBarrierByRegion = (PFNGLMEMORYBARRIERBYREGIONPROC_MT)cmgr->getProcAddress("glMemoryBarrierByRegion"); + if (!GetTextureSubImage) GetTextureSubImage = (PFNGLGETTEXTURESUBIMAGEPROC_MT)cmgr->getProcAddress("glGetTextureSubImage"); + if (!GetCompressedTextureSubImage) GetCompressedTextureSubImage = (PFNGLGETCOMPRESSEDTEXTURESUBIMAGEPROC_MT)cmgr->getProcAddress("glGetCompressedTextureSubImage"); + if (!GetGraphicsResetStatus) GetGraphicsResetStatus = (PFNGLGETGRAPHICSRESETSTATUSPROC_MT)cmgr->getProcAddress("glGetGraphicsResetStatus"); + if (!GetGraphicsResetStatus) GetGraphicsResetStatus = (PFNGLGETGRAPHICSRESETSTATUSPROC_MT)cmgr->getProcAddress("glGetGraphicsResetStatusARB"); + if (!GetnCompressedTexImage) GetnCompressedTexImage = (PFNGLGETNCOMPRESSEDTEXIMAGEPROC_MT)cmgr->getProcAddress("glGetnCompressedTexImage"); + if (!GetnCompressedTexImage) GetnCompressedTexImage = (PFNGLGETNCOMPRESSEDTEXIMAGEPROC_MT)cmgr->getProcAddress("glGetnCompressedTexImageARB"); + if (!GetnTexImage) GetnTexImage = (PFNGLGETNTEXIMAGEPROC_MT)cmgr->getProcAddress("glGetnTexImage"); + if (!GetnTexImage) GetnTexImage = (PFNGLGETNTEXIMAGEPROC_MT)cmgr->getProcAddress("glGetnTexImageARB"); + if (!GetnUniformdv) GetnUniformdv = (PFNGLGETNUNIFORMDVPROC_MT)cmgr->getProcAddress("glGetnUniformdv"); + if (!GetnUniformdv) GetnUniformdv = (PFNGLGETNUNIFORMDVPROC_MT)cmgr->getProcAddress("glGetnUniformdvARB"); + if (!GetnUniformfv) GetnUniformfv = (PFNGLGETNUNIFORMFVPROC_MT)cmgr->getProcAddress("glGetnUniformfv"); + if (!GetnUniformfv) GetnUniformfv = (PFNGLGETNUNIFORMFVPROC_MT)cmgr->getProcAddress("glGetnUniformfvARB"); + if (!GetnUniformiv) GetnUniformiv = (PFNGLGETNUNIFORMIVPROC_MT)cmgr->getProcAddress("glGetnUniformiv"); + if (!GetnUniformiv) GetnUniformiv = (PFNGLGETNUNIFORMIVPROC_MT)cmgr->getProcAddress("glGetnUniformivARB"); + if (!GetnUniformuiv) GetnUniformuiv = (PFNGLGETNUNIFORMUIVPROC_MT)cmgr->getProcAddress("glGetnUniformuiv"); + if (!GetnUniformuiv) GetnUniformuiv = (PFNGLGETNUNIFORMUIVPROC_MT)cmgr->getProcAddress("glGetnUniformuivARB"); + if (!ReadnPixels) ReadnPixels = (PFNGLREADNPIXELSPROC_MT)cmgr->getProcAddress("glReadnPixels"); + if (!ReadnPixels) ReadnPixels = (PFNGLREADNPIXELSPROC_MT)cmgr->getProcAddress("glReadnPixelsARB"); + if (!TextureBarrier) TextureBarrier = (PFNGLTEXTUREBARRIERPROC_MT)cmgr->getProcAddress("glTextureBarrier"); + if (!SpecializeShader) SpecializeShader = (PFNGLSPECIALIZESHADERPROC_MT)cmgr->getProcAddress("glSpecializeShader"); + if (!SpecializeShader) SpecializeShader = (PFNGLSPECIALIZESHADERPROC_MT)cmgr->getProcAddress("glSpecializeShaderARB"); + if (!MultiDrawArraysIndirectCount) MultiDrawArraysIndirectCount = (PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC_MT)cmgr->getProcAddress("glMultiDrawArraysIndirectCount"); + if (!MultiDrawArraysIndirectCount) MultiDrawArraysIndirectCount = (PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC_MT)cmgr->getProcAddress("glMultiDrawArraysIndirectCountARB"); + if (!MultiDrawElementsIndirectCount) MultiDrawElementsIndirectCount = (PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC_MT)cmgr->getProcAddress("glMultiDrawElementsIndirectCount"); + if (!MultiDrawElementsIndirectCount) MultiDrawElementsIndirectCount = (PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC_MT)cmgr->getProcAddress("glMultiDrawElementsIndirectCountARB"); + if (!PolygonOffsetClamp) PolygonOffsetClamp = (PFNGLPOLYGONOFFSETCLAMPPROC_MT)cmgr->getProcAddress("glPolygonOffsetClamp"); + if (!PrimitiveBoundingBox) PrimitiveBoundingBox = (PFNGLPRIMITIVEBOUNDINGBOXPROC_MT)cmgr->getProcAddress("glPrimitiveBoundingBoxARB"); + if (!GetTextureHandle) GetTextureHandle = (PFNGLGETTEXTUREHANDLEPROC_MT)cmgr->getProcAddress("glGetTextureHandleARB"); + if (!GetTextureSamplerHandle) GetTextureSamplerHandle = (PFNGLGETTEXTURESAMPLERHANDLEPROC_MT)cmgr->getProcAddress("glGetTextureSamplerHandleARB"); + if (!MakeTextureHandleResident) MakeTextureHandleResident = (PFNGLMAKETEXTUREHANDLERESIDENTPROC_MT)cmgr->getProcAddress("glMakeTextureHandleResidentARB"); + if (!MakeTextureHandleNonResident) MakeTextureHandleNonResident = (PFNGLMAKETEXTUREHANDLENONRESIDENTPROC_MT)cmgr->getProcAddress("glMakeTextureHandleNonResidentARB"); + if (!GetImageHandle) GetImageHandle = (PFNGLGETIMAGEHANDLEPROC_MT)cmgr->getProcAddress("glGetImageHandleARB"); + if (!MakeImageHandleResident) MakeImageHandleResident = (PFNGLMAKEIMAGEHANDLERESIDENTPROC_MT)cmgr->getProcAddress("glMakeImageHandleResidentARB"); + if (!MakeImageHandleNonResident) MakeImageHandleNonResident = (PFNGLMAKEIMAGEHANDLENONRESIDENTPROC_MT)cmgr->getProcAddress("glMakeImageHandleNonResidentARB"); + if (!UniformHandleui64) UniformHandleui64 = (PFNGLUNIFORMHANDLEUI64PROC_MT)cmgr->getProcAddress("glUniformHandleui64ARB"); + if (!UniformHandleui64v) UniformHandleui64v = (PFNGLUNIFORMHANDLEUI64VPROC_MT)cmgr->getProcAddress("glUniformHandleui64vARB"); + if (!ProgramUniformHandleui64) ProgramUniformHandleui64 = (PFNGLPROGRAMUNIFORMHANDLEUI64PROC_MT)cmgr->getProcAddress("glProgramUniformHandleui64ARB"); + if (!ProgramUniformHandleui64v) ProgramUniformHandleui64v = (PFNGLPROGRAMUNIFORMHANDLEUI64VPROC_MT)cmgr->getProcAddress("glProgramUniformHandleui64vARB"); + if (!IsTextureHandleResident) IsTextureHandleResident = (PFNGLISTEXTUREHANDLERESIDENTPROC_MT)cmgr->getProcAddress("glIsTextureHandleResidentARB"); + if (!IsImageHandleResident) IsImageHandleResident = (PFNGLISIMAGEHANDLERESIDENTPROC_MT)cmgr->getProcAddress("glIsImageHandleResidentARB"); + if (!VertexAttribL1ui64) VertexAttribL1ui64 = (PFNGLVERTEXATTRIBL1UI64PROC_MT)cmgr->getProcAddress("glVertexAttribL1ui64ARB"); + if (!VertexAttribL1ui64v) VertexAttribL1ui64v = (PFNGLVERTEXATTRIBL1UI64VPROC_MT)cmgr->getProcAddress("glVertexAttribL1ui64vARB"); + if (!GetVertexAttribLui64v) GetVertexAttribLui64v = (PFNGLGETVERTEXATTRIBLUI64VPROC_MT)cmgr->getProcAddress("glGetVertexAttribLui64vARB"); + if (!CreateSyncFromCLevent) CreateSyncFromCLevent = (PFNGLCREATESYNCFROMCLEVENTPROC_MT)cmgr->getProcAddress("glCreateSyncFromCLeventARB"); + if (!DispatchComputeGroupSize) DispatchComputeGroupSize = (PFNGLDISPATCHCOMPUTEGROUPSIZEPROC_MT)cmgr->getProcAddress("glDispatchComputeGroupSizeARB"); + if (!FramebufferTextureFace) FramebufferTextureFace = (PFNGLFRAMEBUFFERTEXTUREFACEPROC_MT)cmgr->getProcAddress("glFramebufferTextureFaceARB"); + if (!Uniform1i64) Uniform1i64 = (PFNGLUNIFORM1I64PROC_MT)cmgr->getProcAddress("glUniform1i64ARB"); + if (!Uniform2i64) Uniform2i64 = (PFNGLUNIFORM2I64PROC_MT)cmgr->getProcAddress("glUniform2i64ARB"); + if (!Uniform3i64) Uniform3i64 = (PFNGLUNIFORM3I64PROC_MT)cmgr->getProcAddress("glUniform3i64ARB"); + if (!Uniform4i64) Uniform4i64 = (PFNGLUNIFORM4I64PROC_MT)cmgr->getProcAddress("glUniform4i64ARB"); + if (!Uniform1i64v) Uniform1i64v = (PFNGLUNIFORM1I64VPROC_MT)cmgr->getProcAddress("glUniform1i64vARB"); + if (!Uniform2i64v) Uniform2i64v = (PFNGLUNIFORM2I64VPROC_MT)cmgr->getProcAddress("glUniform2i64vARB"); + if (!Uniform3i64v) Uniform3i64v = (PFNGLUNIFORM3I64VPROC_MT)cmgr->getProcAddress("glUniform3i64vARB"); + if (!Uniform4i64v) Uniform4i64v = (PFNGLUNIFORM4I64VPROC_MT)cmgr->getProcAddress("glUniform4i64vARB"); + if (!Uniform1ui64) Uniform1ui64 = (PFNGLUNIFORM1UI64PROC_MT)cmgr->getProcAddress("glUniform1ui64ARB"); + if (!Uniform2ui64) Uniform2ui64 = (PFNGLUNIFORM2UI64PROC_MT)cmgr->getProcAddress("glUniform2ui64ARB"); + if (!Uniform3ui64) Uniform3ui64 = (PFNGLUNIFORM3UI64PROC_MT)cmgr->getProcAddress("glUniform3ui64ARB"); + if (!Uniform4ui64) Uniform4ui64 = (PFNGLUNIFORM4UI64PROC_MT)cmgr->getProcAddress("glUniform4ui64ARB"); + if (!Uniform1ui64v) Uniform1ui64v = (PFNGLUNIFORM1UI64VPROC_MT)cmgr->getProcAddress("glUniform1ui64vARB"); + if (!Uniform2ui64v) Uniform2ui64v = (PFNGLUNIFORM2UI64VPROC_MT)cmgr->getProcAddress("glUniform2ui64vARB"); + if (!Uniform3ui64v) Uniform3ui64v = (PFNGLUNIFORM3UI64VPROC_MT)cmgr->getProcAddress("glUniform3ui64vARB"); + if (!Uniform4ui64v) Uniform4ui64v = (PFNGLUNIFORM4UI64VPROC_MT)cmgr->getProcAddress("glUniform4ui64vARB"); + if (!GetUniformi64v) GetUniformi64v = (PFNGLGETUNIFORMI64VPROC_MT)cmgr->getProcAddress("glGetUniformi64vARB"); + if (!GetUniformui64v) GetUniformui64v = (PFNGLGETUNIFORMUI64VPROC_MT)cmgr->getProcAddress("glGetUniformui64vARB"); + if (!GetnUniformi64v) GetnUniformi64v = (PFNGLGETNUNIFORMI64VPROC_MT)cmgr->getProcAddress("glGetnUniformi64vARB"); + if (!GetnUniformui64v) GetnUniformui64v = (PFNGLGETNUNIFORMUI64VPROC_MT)cmgr->getProcAddress("glGetnUniformui64vARB"); + if (!ProgramUniform1i64) ProgramUniform1i64 = (PFNGLPROGRAMUNIFORM1I64PROC_MT)cmgr->getProcAddress("glProgramUniform1i64ARB"); + if (!ProgramUniform2i64) ProgramUniform2i64 = (PFNGLPROGRAMUNIFORM2I64PROC_MT)cmgr->getProcAddress("glProgramUniform2i64ARB"); + if (!ProgramUniform3i64) ProgramUniform3i64 = (PFNGLPROGRAMUNIFORM3I64PROC_MT)cmgr->getProcAddress("glProgramUniform3i64ARB"); + if (!ProgramUniform4i64) ProgramUniform4i64 = (PFNGLPROGRAMUNIFORM4I64PROC_MT)cmgr->getProcAddress("glProgramUniform4i64ARB"); + if (!ProgramUniform1i64v) ProgramUniform1i64v = (PFNGLPROGRAMUNIFORM1I64VPROC_MT)cmgr->getProcAddress("glProgramUniform1i64vARB"); + if (!ProgramUniform2i64v) ProgramUniform2i64v = (PFNGLPROGRAMUNIFORM2I64VPROC_MT)cmgr->getProcAddress("glProgramUniform2i64vARB"); + if (!ProgramUniform3i64v) ProgramUniform3i64v = (PFNGLPROGRAMUNIFORM3I64VPROC_MT)cmgr->getProcAddress("glProgramUniform3i64vARB"); + if (!ProgramUniform4i64v) ProgramUniform4i64v = (PFNGLPROGRAMUNIFORM4I64VPROC_MT)cmgr->getProcAddress("glProgramUniform4i64vARB"); + if (!ProgramUniform1ui64) ProgramUniform1ui64 = (PFNGLPROGRAMUNIFORM1UI64PROC_MT)cmgr->getProcAddress("glProgramUniform1ui64ARB"); + if (!ProgramUniform2ui64) ProgramUniform2ui64 = (PFNGLPROGRAMUNIFORM2UI64PROC_MT)cmgr->getProcAddress("glProgramUniform2ui64ARB"); + if (!ProgramUniform3ui64) ProgramUniform3ui64 = (PFNGLPROGRAMUNIFORM3UI64PROC_MT)cmgr->getProcAddress("glProgramUniform3ui64ARB"); + if (!ProgramUniform4ui64) ProgramUniform4ui64 = (PFNGLPROGRAMUNIFORM4UI64PROC_MT)cmgr->getProcAddress("glProgramUniform4ui64ARB"); + if (!ProgramUniform1ui64v) ProgramUniform1ui64v = (PFNGLPROGRAMUNIFORM1UI64VPROC_MT)cmgr->getProcAddress("glProgramUniform1ui64vARB"); + if (!ProgramUniform2ui64v) ProgramUniform2ui64v = (PFNGLPROGRAMUNIFORM2UI64VPROC_MT)cmgr->getProcAddress("glProgramUniform2ui64vARB"); + if (!ProgramUniform3ui64v) ProgramUniform3ui64v = (PFNGLPROGRAMUNIFORM3UI64VPROC_MT)cmgr->getProcAddress("glProgramUniform3ui64vARB"); + if (!ProgramUniform4ui64v) ProgramUniform4ui64v = (PFNGLPROGRAMUNIFORM4UI64VPROC_MT)cmgr->getProcAddress("glProgramUniform4ui64vARB"); + if (!MaxShaderCompilerThreads) MaxShaderCompilerThreads = (PFNGLMAXSHADERCOMPILERTHREADSPROC_MT)cmgr->getProcAddress("glMaxShaderCompilerThreadsARB"); + if (!MaxShaderCompilerThreads) MaxShaderCompilerThreads = (PFNGLMAXSHADERCOMPILERTHREADSPROC_MT)cmgr->getProcAddress("glMaxShaderCompilerThreadsKHR"); + if (!FramebufferSampleLocationsfv) FramebufferSampleLocationsfv = (PFNGLFRAMEBUFFERSAMPLELOCATIONSFVPROC_MT)cmgr->getProcAddress("glFramebufferSampleLocationsfvARB"); + if (!NamedFramebufferSampleLocationsfv) NamedFramebufferSampleLocationsfv = (PFNGLNAMEDFRAMEBUFFERSAMPLELOCATIONSFVPROC_MT)cmgr->getProcAddress("glNamedFramebufferSampleLocationsfvARB"); + if (!EvaluateDepthValues) EvaluateDepthValues = (PFNGLEVALUATEDEPTHVALUESPROC_MT)cmgr->getProcAddress("glEvaluateDepthValuesARB"); + if (!NamedString) NamedString = (PFNGLNAMEDSTRINGPROC_MT)cmgr->getProcAddress("glNamedStringARB"); + if (!DeleteNamedString) DeleteNamedString = (PFNGLDELETENAMEDSTRINGPROC_MT)cmgr->getProcAddress("glDeleteNamedStringARB"); + if (!CompileShaderInclude) CompileShaderInclude = (PFNGLCOMPILESHADERINCLUDEPROC_MT)cmgr->getProcAddress("glCompileShaderIncludeARB"); + if (!IsNamedString) IsNamedString = (PFNGLISNAMEDSTRINGPROC_MT)cmgr->getProcAddress("glIsNamedStringARB"); + if (!GetNamedString) GetNamedString = (PFNGLGETNAMEDSTRINGPROC_MT)cmgr->getProcAddress("glGetNamedStringARB"); + if (!GetNamedStringiv) GetNamedStringiv = (PFNGLGETNAMEDSTRINGIVPROC_MT)cmgr->getProcAddress("glGetNamedStringivARB"); + if (!BufferPageCommitment) BufferPageCommitment = (PFNGLBUFFERPAGECOMMITMENTPROC_MT)cmgr->getProcAddress("glBufferPageCommitmentARB"); + if (!NamedBufferPageCommitment) NamedBufferPageCommitment = (PFNGLNAMEDBUFFERPAGECOMMITMENTPROC_MT)cmgr->getProcAddress("glNamedBufferPageCommitmentARB"); + if (!TexPageCommitment) TexPageCommitment = (PFNGLTEXPAGECOMMITMENTPROC_MT)cmgr->getProcAddress("glTexPageCommitmentARB"); + + // OpenGL 3 way to enumerate extensions + GLint ext_count = 0; + GetIntegerv(NUM_EXTENSIONS, &ext_count); + extensions.reserve(ext_count); + for (GLint k = 0; k < ext_count; k++) { + auto tmp = GetStringi(EXTENSIONS, k); + if (tmp) + extensions.emplace((char*)tmp); + } + if (!extensions.empty()) + return; + + // OpenGL 2 / ES 2 way to enumerate extensions + auto ext_str = GetString(EXTENSIONS); + if (!ext_str) + return; + // get the extension string, chop it up + std::stringstream ext_ss((char*)ext_str); + std::string tmp; + while (std::getline(ext_ss, tmp, ' ')) + extensions.emplace(tmp); + +} diff --git a/irr/src/os.cpp b/irr/src/os.cpp new file mode 100644 index 000000000..96be8dd63 --- /dev/null +++ b/irr/src/os.cpp @@ -0,0 +1,379 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "os.h" +#include "irrString.h" +#include "irrMath.h" + +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#include +#define bswap_16(X) SDL_Swap16(X) +#define bswap_32(X) SDL_Swap32(X) +#define bswap_64(X) SDL_Swap64(X) +#elif defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) +#include +#define bswap_16(X) _byteswap_ushort(X) +#define bswap_32(X) _byteswap_ulong(X) +#define bswap_64(X) _byteswap_uint64(X) +#elif defined(_IRR_OSX_PLATFORM_) +#include +#define bswap_16(X) OSReadSwapInt16(&X, 0) +#define bswap_32(X) OSReadSwapInt32(&X, 0) +#define bswap_64(X) OSReadSwapInt64(&X, 0) +#elif defined(__FreeBSD__) +#include +#define bswap_16(X) bswap16(X) +#define bswap_32(X) bswap32(X) +#define bswap_64(X) bswap64(X) +#elif defined(__OpenBSD__) +#include +#define bswap_16(X) letoh16(X) +#define bswap_32(X) letoh32(X) +#define bswap_64(X) letoh64(X) +#elif !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__PPC__) && !defined(_IRR_WINDOWS_API_) +#include +#else +#define bswap_16(X) ((((X) & 0xFF) << 8) | (((X) & 0xFF00) >> 8)) +#define bswap_32(X) ((((X) & 0x000000FF) << 24) | (((X) & 0xFF000000) >> 24) | (((X) & 0x0000FF00) << 8) | (((X) & 0x00FF0000) >> 8)) +#define bswap_64(X) ((((X) & 0x00000000000000FF) << 56) | (((X) & 0xFF00000000000000) >> 56) | (((X) & 0x000000000000FF00) << 40) | (((X) & 0x00FF000000000000) >> 40) | (((X) & 0x0000000000FF0000) << 24) | (((X) & 0x0000FF0000000000) >> 24) | (((X) & 0x00000000FF000000) << 8) | (((X) & 0x000000FF00000000) >> 8)) +#endif + +namespace irr +{ +namespace os +{ +u16 Byteswap::byteswap(u16 num) +{ + return bswap_16(num); +} +s16 Byteswap::byteswap(s16 num) +{ + return bswap_16(num); +} +u32 Byteswap::byteswap(u32 num) +{ + return bswap_32(num); +} +s32 Byteswap::byteswap(s32 num) +{ + return bswap_32(num); +} +u64 Byteswap::byteswap(u64 num) +{ + return bswap_64(num); +} +s64 Byteswap::byteswap(s64 num) +{ + return bswap_64(num); +} +f32 Byteswap::byteswap(f32 num) +{ + u32 tmp = IR(num); + tmp = bswap_32(tmp); + return (FR(tmp)); +} +} +} + +#if defined(_IRR_WINDOWS_API_) +// ---------------------------------------------------------------- +// Windows specific functions +// ---------------------------------------------------------------- + +#define WIN32_LEAN_AND_MEAN +#include +#include + +namespace irr +{ +namespace os +{ +//! prints a debuginfo string +void Printer::print(const c8 *message, ELOG_LEVEL ll) +{ + core::stringc tmp(message); + tmp += "\n"; + OutputDebugStringA(tmp.c_str()); + printf("%s", tmp.c_str()); +} + +static LARGE_INTEGER HighPerformanceFreq; +static BOOL HighPerformanceTimerSupport = FALSE; + +void Timer::initTimer() +{ + HighPerformanceTimerSupport = QueryPerformanceFrequency(&HighPerformanceFreq); + initVirtualTimer(); +} + +u32 Timer::getRealTime() +{ + if (HighPerformanceTimerSupport) { + LARGE_INTEGER nTime; + BOOL queriedOK = QueryPerformanceCounter(&nTime); + + if (queriedOK) + return u32((nTime.QuadPart) * 1000 / HighPerformanceFreq.QuadPart); + } + + return GetTickCount(); +} + +} // end namespace os + +#elif defined(_IRR_ANDROID_PLATFORM_) + +// ---------------------------------------------------------------- +// Android version +// ---------------------------------------------------------------- + +#include + +namespace irr +{ +namespace os +{ + +//! prints a debuginfo string +void Printer::print(const c8 *message, ELOG_LEVEL ll) +{ + android_LogPriority LogLevel = ANDROID_LOG_UNKNOWN; + + switch (ll) { + case ELL_DEBUG: + LogLevel = ANDROID_LOG_DEBUG; + break; + case ELL_INFORMATION: + LogLevel = ANDROID_LOG_INFO; + break; + case ELL_WARNING: + LogLevel = ANDROID_LOG_WARN; + break; + case ELL_ERROR: + LogLevel = ANDROID_LOG_ERROR; + break; + default: // ELL_NONE + LogLevel = ANDROID_LOG_VERBOSE; + break; + } + + // Android logcat restricts log-output and cuts the rest of the message away. But we want it all. + // On my device max-len is 1023 (+ 0 byte). Some websites claim a limit of 4096 so maybe different numbers on different devices. + const size_t maxLogLen = 1023; + size_t msgLen = strlen(message); + size_t start = 0; + while (msgLen - start > maxLogLen) { + __android_log_print(LogLevel, "Irrlicht", "%.*s\n", maxLogLen, &message[start]); + start += maxLogLen; + } + __android_log_print(LogLevel, "Irrlicht", "%s\n", &message[start]); +} + +void Timer::initTimer() +{ + initVirtualTimer(); +} + +u32 Timer::getRealTime() +{ + timeval tv; + gettimeofday(&tv, 0); + return (u32)(tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} +} // end namespace os + +#elif defined(_IRR_EMSCRIPTEN_PLATFORM_) + +// ---------------------------------------------------------------- +// emscripten version +// ---------------------------------------------------------------- + +#include +#include +#include + +namespace irr +{ +namespace os +{ + +//! prints a debuginfo string +void Printer::print(const c8 *message, ELOG_LEVEL ll) +{ + int log_level; + switch (ll) { + case ELL_DEBUG: + log_level = 0; + break; + case ELL_INFORMATION: + log_level = 0; + break; + case ELL_WARNING: + log_level = EM_LOG_WARN; + break; + case ELL_ERROR: + log_level = EM_LOG_ERROR; + break; + default: // ELL_NONE + log_level = 0; + break; + } + emscripten_log(log_level, "%s", message); // Note: not adding \n as emscripten_log seems to do that already. +} + +void Timer::initTimer() +{ + initVirtualTimer(); +} + +u32 Timer::getRealTime() +{ + double time = emscripten_get_now(); + return (u32)(time); +} +} // end namespace os + +#else + +// ---------------------------------------------------------------- +// linux/ansi version +// ---------------------------------------------------------------- + +#include +#include +#include + +namespace irr +{ +namespace os +{ + +//! prints a debuginfo string +void Printer::print(const c8 *message, ELOG_LEVEL ll) +{ + printf("%s\n", message); +} + +void Timer::initTimer() +{ + initVirtualTimer(); +} + +u32 Timer::getRealTime() +{ + timeval tv; + gettimeofday(&tv, 0); + return (u32)(tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} +} // end namespace os + +#endif // end linux / emscripten / android / windows + +namespace os +{ +// The platform independent implementation of the printer +ILogger *Printer::Logger = 0; + +void Printer::log(const c8 *message, ELOG_LEVEL ll) +{ + if (Logger) + Logger->log(message, ll); +} + +void Printer::log(const c8 *message, const c8 *hint, ELOG_LEVEL ll) +{ + if (Logger) + Logger->log(message, hint, ll); +} + +void Printer::log(const c8 *message, const io::path &hint, ELOG_LEVEL ll) +{ + if (Logger) + Logger->log(message, hint.c_str(), ll); +} + +// ------------------------------------------------------ +// virtual timer implementation + +f32 Timer::VirtualTimerSpeed = 1.0f; +s32 Timer::VirtualTimerStopCounter = 0; +u32 Timer::LastVirtualTime = 0; +u32 Timer::StartRealTime = 0; +u32 Timer::StaticTime = 0; + +//! returns current virtual time +u32 Timer::getTime() +{ + if (isStopped()) + return LastVirtualTime; + + return LastVirtualTime + (u32)((StaticTime - StartRealTime) * VirtualTimerSpeed); +} + +//! ticks, advances the virtual timer +void Timer::tick() +{ + StaticTime = getRealTime(); +} + +//! sets the current virtual time +void Timer::setTime(u32 time) +{ + StaticTime = getRealTime(); + LastVirtualTime = time; + StartRealTime = StaticTime; +} + +//! stops the virtual timer +void Timer::stopTimer() +{ + if (!isStopped()) { + // stop the virtual timer + LastVirtualTime = getTime(); + } + + --VirtualTimerStopCounter; +} + +//! starts the virtual timer +void Timer::startTimer() +{ + ++VirtualTimerStopCounter; + + if (!isStopped()) { + // restart virtual timer + setTime(LastVirtualTime); + } +} + +//! sets the speed of the virtual timer +void Timer::setSpeed(f32 speed) +{ + setTime(getTime()); + + VirtualTimerSpeed = speed; + if (VirtualTimerSpeed < 0.0f) + VirtualTimerSpeed = 0.0f; +} + +//! gets the speed of the virtual timer +f32 Timer::getSpeed() +{ + return VirtualTimerSpeed; +} + +//! returns if the timer currently is stopped +bool Timer::isStopped() +{ + return VirtualTimerStopCounter < 0; +} + +void Timer::initVirtualTimer() +{ + StaticTime = getRealTime(); + StartRealTime = StaticTime; +} + +} // end namespace os +} // end namespace irr diff --git a/irr/src/os.h b/irr/src/os.h new file mode 100644 index 000000000..fcbaeddd5 --- /dev/null +++ b/irr/src/os.h @@ -0,0 +1,91 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "irrTypes.h" +#include "irrString.h" +#include "path.h" +#include "ILogger.h" +#include "ITimer.h" + +namespace irr +{ + +namespace os +{ +class Byteswap +{ +public: + static u16 byteswap(u16 num); + static s16 byteswap(s16 num); + static u32 byteswap(u32 num); + static s32 byteswap(s32 num); + static u64 byteswap(u64 num); + static s64 byteswap(s64 num); + static f32 byteswap(f32 num); + // prevent accidental swapping of chars + static inline u8 byteswap(u8 num) { return num; } + static inline c8 byteswap(c8 num) { return num; } +}; + +class Printer +{ +public: + // prints out a string to the console out stdout or debug log or whatever + static void print(const c8 *message, ELOG_LEVEL ll = ELL_INFORMATION); + static void log(const c8 *message, ELOG_LEVEL ll = ELL_INFORMATION); + static void log(const wchar_t *message, ELOG_LEVEL ll = ELL_INFORMATION); + + // The string ": " is added between message and hint + static void log(const c8 *message, const c8 *hint, ELOG_LEVEL ll = ELL_INFORMATION); + static void log(const c8 *message, const io::path &hint, ELOG_LEVEL ll = ELL_INFORMATION); + static ILogger *Logger; +}; + +class Timer +{ +public: + //! returns the current time in milliseconds + static u32 getTime(); + + //! initializes the real timer + static void initTimer(); + + //! sets the current virtual (game) time + static void setTime(u32 time); + + //! stops the virtual (game) timer + static void stopTimer(); + + //! starts the game timer + static void startTimer(); + + //! sets the speed of the virtual timer + static void setSpeed(f32 speed); + + //! gets the speed of the virtual timer + static f32 getSpeed(); + + //! returns if the timer currently is stopped + static bool isStopped(); + + //! makes the virtual timer update the time value based on the real time + static void tick(); + + //! returns the current real time in milliseconds + static u32 getRealTime(); + +private: + static void initVirtualTimer(); + + static f32 VirtualTimerSpeed; + static s32 VirtualTimerStopCounter; + static u32 StartRealTime; + static u32 LastVirtualTime; + static u32 StaticTime; +}; + +} // end namespace os +} // end namespace irr diff --git a/irr/src/vendor/gl.h b/irr/src/vendor/gl.h new file mode 100644 index 000000000..d1aae08ea --- /dev/null +++ b/irr/src/vendor/gl.h @@ -0,0 +1,2098 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef __gl_h_ +#define __gl_h_ + +/********************************************************************** + * Begin system-specific stuff. + */ + +#if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__) +#define __WIN32__ +#endif + +#if defined(__WIN32__) && !defined(__CYGWIN__) +# define GLAPI extern +# if !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) + /* Win32 but not WinCE */ +# define GLAPIENTRY __stdcall +# else +# define GLAPIENTRY +# endif +#elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */ +# define GLAPI extern +# define GLAPIENTRY __stdcall +#elif (defined(__GNUC__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define GLAPI __attribute__((visibility("default"))) +# define GLAPIENTRY +#endif /* WIN32 && !CYGWIN */ + +/* + * WINDOWS: Include windows.h here to define APIENTRY. + * It is also useful when applications include this file by + * including only glut.h, since glut.h depends on windows.h. + * Applications needing to include windows.h with parms other + * than "WIN32_LEAN_AND_MEAN" may include windows.h before + * glut.h or gl.h. + */ +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#endif + +#ifndef GLAPI +#define GLAPI extern +#endif + +#ifndef GLAPIENTRY +#define GLAPIENTRY +#endif + +#ifndef APIENTRY +#define APIENTRY GLAPIENTRY +#endif + +/* "P" suffix to be used for a pointer to a function */ +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif + +#ifndef GLAPIENTRYP +#define GLAPIENTRYP GLAPIENTRY * +#endif + +/* + * End system-specific stuff. + **********************************************************************/ + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +#define GL_VERSION_1_1 1 +#define GL_VERSION_1_2 1 +#define GL_VERSION_1_3 1 +#define GL_ARB_imaging 1 + + +/* + * Datatypes + */ +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef void GLvoid; +typedef signed char GLbyte; /* 1-byte signed */ +typedef short GLshort; /* 2-byte signed */ +typedef int GLint; /* 4-byte signed */ +typedef unsigned char GLubyte; /* 1-byte unsigned */ +typedef unsigned short GLushort; /* 2-byte unsigned */ +typedef unsigned int GLuint; /* 4-byte unsigned */ +typedef int GLsizei; /* 4-byte signed */ +typedef float GLfloat; /* single precision float */ +typedef float GLclampf; /* single precision float in [0,1] */ +typedef double GLdouble; /* double precision float */ +typedef double GLclampd; /* double precision float in [0,1] */ + + + +/* + * Constants + */ + +/* Boolean values */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* Data types */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_2_BYTES 0x1407 +#define GL_3_BYTES 0x1408 +#define GL_4_BYTES 0x1409 +#define GL_DOUBLE 0x140A + +/* Primitives */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 +#define GL_QUADS 0x0007 +#define GL_QUAD_STRIP 0x0008 +#define GL_POLYGON 0x0009 + +/* Vertex Arrays */ +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_INDEX_ARRAY 0x8077 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_EDGE_FLAG_ARRAY 0x8079 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_INDEX_ARRAY_TYPE 0x8085 +#define GL_INDEX_ARRAY_STRIDE 0x8086 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_INDEX_ARRAY_POINTER 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093 +#define GL_V2F 0x2A20 +#define GL_V3F 0x2A21 +#define GL_C4UB_V2F 0x2A22 +#define GL_C4UB_V3F 0x2A23 +#define GL_C3F_V3F 0x2A24 +#define GL_N3F_V3F 0x2A25 +#define GL_C4F_N3F_V3F 0x2A26 +#define GL_T2F_V3F 0x2A27 +#define GL_T4F_V4F 0x2A28 +#define GL_T2F_C4UB_V3F 0x2A29 +#define GL_T2F_C3F_V3F 0x2A2A +#define GL_T2F_N3F_V3F 0x2A2B +#define GL_T2F_C4F_N3F_V3F 0x2A2C +#define GL_T4F_C4F_N3F_V4F 0x2A2D + +/* Matrix Mode */ +#define GL_MATRIX_MODE 0x0BA0 +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* Points */ +#define GL_POINT_SMOOTH 0x0B10 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_POINT_SIZE_RANGE 0x0B12 + +/* Lines */ +#define GL_LINE_SMOOTH 0x0B20 +#define GL_LINE_STIPPLE 0x0B24 +#define GL_LINE_STIPPLE_PATTERN 0x0B25 +#define GL_LINE_STIPPLE_REPEAT 0x0B26 +#define GL_LINE_WIDTH 0x0B21 +#define GL_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_LINE_WIDTH_RANGE 0x0B22 + +/* Polygons */ +#define GL_POINT 0x1B00 +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 +#define GL_CW 0x0900 +#define GL_CCW 0x0901 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_POLYGON_MODE 0x0B40 +#define GL_POLYGON_SMOOTH 0x0B41 +#define GL_POLYGON_STIPPLE 0x0B42 +#define GL_EDGE_FLAG 0x0B43 +#define GL_CULL_FACE 0x0B44 +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_POINT 0x2A01 +#define GL_POLYGON_OFFSET_LINE 0x2A02 +#define GL_POLYGON_OFFSET_FILL 0x8037 + +/* Display Lists */ +#define GL_COMPILE 0x1300 +#define GL_COMPILE_AND_EXECUTE 0x1301 +#define GL_LIST_BASE 0x0B32 +#define GL_LIST_INDEX 0x0B33 +#define GL_LIST_MODE 0x0B30 + +/* Depth buffer */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 +#define GL_DEPTH_TEST 0x0B71 +#define GL_DEPTH_BITS 0x0D56 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_COMPONENT 0x1902 + +/* Lighting */ +#define GL_LIGHTING 0x0B50 +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_SHININESS 0x1601 +#define GL_EMISSION 0x1600 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +#define GL_COLOR_INDEXES 0x1603 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 +#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51 +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_FRONT_AND_BACK 0x0408 +#define GL_SHADE_MODEL 0x0B54 +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_COLOR_MATERIAL_FACE 0x0B55 +#define GL_COLOR_MATERIAL_PARAMETER 0x0B56 +#define GL_NORMALIZE 0x0BA1 + +/* User clipping planes */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* Accumulation buffer */ +#define GL_ACCUM_RED_BITS 0x0D58 +#define GL_ACCUM_GREEN_BITS 0x0D59 +#define GL_ACCUM_BLUE_BITS 0x0D5A +#define GL_ACCUM_ALPHA_BITS 0x0D5B +#define GL_ACCUM_CLEAR_VALUE 0x0B80 +#define GL_ACCUM 0x0100 +#define GL_ADD 0x0104 +#define GL_LOAD 0x0101 +#define GL_MULT 0x0103 +#define GL_RETURN 0x0102 + +/* Alpha testing */ +#define GL_ALPHA_TEST 0x0BC0 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_ALPHA_TEST_FUNC 0x0BC1 + +/* Blending */ +#define GL_BLEND 0x0BE2 +#define GL_BLEND_SRC 0x0BE1 +#define GL_BLEND_DST 0x0BE0 +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 + +/* Render Mode */ +#define GL_FEEDBACK 0x1C01 +#define GL_RENDER 0x1C00 +#define GL_SELECT 0x1C02 + +/* Feedback */ +#define GL_2D 0x0600 +#define GL_3D 0x0601 +#define GL_3D_COLOR 0x0602 +#define GL_3D_COLOR_TEXTURE 0x0603 +#define GL_4D_COLOR_TEXTURE 0x0604 +#define GL_POINT_TOKEN 0x0701 +#define GL_LINE_TOKEN 0x0702 +#define GL_LINE_RESET_TOKEN 0x0707 +#define GL_POLYGON_TOKEN 0x0703 +#define GL_BITMAP_TOKEN 0x0704 +#define GL_DRAW_PIXEL_TOKEN 0x0705 +#define GL_COPY_PIXEL_TOKEN 0x0706 +#define GL_PASS_THROUGH_TOKEN 0x0700 +#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0 +#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1 +#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2 + +/* Selection */ +#define GL_SELECTION_BUFFER_POINTER 0x0DF3 +#define GL_SELECTION_BUFFER_SIZE 0x0DF4 + +/* Fog */ +#define GL_FOG 0x0B60 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_COLOR 0x0B66 +#define GL_FOG_INDEX 0x0B61 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_LINEAR 0x2601 +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* Logic Ops */ +#define GL_LOGIC_OP 0x0BF1 +#define GL_INDEX_LOGIC_OP 0x0BF1 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_CLEAR 0x1500 +#define GL_SET 0x150F +#define GL_COPY 0x1503 +#define GL_COPY_INVERTED 0x150C +#define GL_NOOP 0x1505 +#define GL_INVERT 0x150A +#define GL_AND 0x1501 +#define GL_NAND 0x150E +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_XOR 0x1506 +#define GL_EQUIV 0x1509 +#define GL_AND_REVERSE 0x1502 +#define GL_AND_INVERTED 0x1504 +#define GL_OR_REVERSE 0x150B +#define GL_OR_INVERTED 0x150D + +/* Stencil */ +#define GL_STENCIL_BITS 0x0D57 +#define GL_STENCIL_TEST 0x0B90 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_INDEX 0x1901 +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 + +/* Buffers, Pixel Drawing/Reading */ +#define GL_NONE 0 +#define GL_LEFT 0x0406 +#define GL_RIGHT 0x0407 +/*GL_FRONT 0x0404 */ +/*GL_BACK 0x0405 */ +/*GL_FRONT_AND_BACK 0x0408 */ +#define GL_FRONT_LEFT 0x0400 +#define GL_FRONT_RIGHT 0x0401 +#define GL_BACK_LEFT 0x0402 +#define GL_BACK_RIGHT 0x0403 +#define GL_AUX0 0x0409 +#define GL_AUX1 0x040A +#define GL_AUX2 0x040B +#define GL_AUX3 0x040C +#define GL_COLOR_INDEX 0x1900 +#define GL_RED 0x1903 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_ALPHA 0x1906 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A +#define GL_ALPHA_BITS 0x0D55 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_INDEX_BITS 0x0D51 +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_AUX_BUFFERS 0x0C00 +#define GL_READ_BUFFER 0x0C02 +#define GL_DRAW_BUFFER 0x0C01 +#define GL_DOUBLEBUFFER 0x0C32 +#define GL_STEREO 0x0C33 +#define GL_BITMAP 0x1A00 +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 +#define GL_DITHER 0x0BD0 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 + +/* Implementation limits */ +#define GL_MAX_LIST_NESTING 0x0B31 +#define GL_MAX_EVAL_ORDER 0x0D30 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_PIXEL_MAP_TABLE 0x0D34 +#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_NAME_STACK_DEPTH 0x0D37 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B + +/* Gets */ +#define GL_ATTRIB_STACK_DEPTH 0x0BB0 +#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_CURRENT_INDEX 0x0B01 +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_RASTER_COLOR 0x0B04 +#define GL_CURRENT_RASTER_DISTANCE 0x0B09 +#define GL_CURRENT_RASTER_INDEX 0x0B05 +#define GL_CURRENT_RASTER_POSITION 0x0B07 +#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06 +#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_INDEX_CLEAR_VALUE 0x0C20 +#define GL_INDEX_MODE 0x0C30 +#define GL_INDEX_WRITEMASK 0x0C21 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_NAME_STACK_DEPTH 0x0D70 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_RENDER_MODE 0x0C40 +#define GL_RGBA_MODE 0x0C31 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_VIEWPORT 0x0BA2 + +/* Evaluators */ +#define GL_AUTO_NORMAL 0x0D80 +#define GL_MAP1_COLOR_4 0x0D90 +#define GL_MAP1_INDEX 0x0D91 +#define GL_MAP1_NORMAL 0x0D92 +#define GL_MAP1_TEXTURE_COORD_1 0x0D93 +#define GL_MAP1_TEXTURE_COORD_2 0x0D94 +#define GL_MAP1_TEXTURE_COORD_3 0x0D95 +#define GL_MAP1_TEXTURE_COORD_4 0x0D96 +#define GL_MAP1_VERTEX_3 0x0D97 +#define GL_MAP1_VERTEX_4 0x0D98 +#define GL_MAP2_COLOR_4 0x0DB0 +#define GL_MAP2_INDEX 0x0DB1 +#define GL_MAP2_NORMAL 0x0DB2 +#define GL_MAP2_TEXTURE_COORD_1 0x0DB3 +#define GL_MAP2_TEXTURE_COORD_2 0x0DB4 +#define GL_MAP2_TEXTURE_COORD_3 0x0DB5 +#define GL_MAP2_TEXTURE_COORD_4 0x0DB6 +#define GL_MAP2_VERTEX_3 0x0DB7 +#define GL_MAP2_VERTEX_4 0x0DB8 +#define GL_MAP1_GRID_DOMAIN 0x0DD0 +#define GL_MAP1_GRID_SEGMENTS 0x0DD1 +#define GL_MAP2_GRID_DOMAIN 0x0DD2 +#define GL_MAP2_GRID_SEGMENTS 0x0DD3 +#define GL_COEFF 0x0A00 +#define GL_ORDER 0x0A01 +#define GL_DOMAIN 0x0A02 + +/* Hints */ +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_POLYGON_SMOOTH_HINT 0x0C53 +#define GL_FOG_HINT 0x0C54 +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* Scissor box */ +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 + +/* Pixel Mode / Transfer */ +#define GL_MAP_COLOR 0x0D10 +#define GL_MAP_STENCIL 0x0D11 +#define GL_INDEX_SHIFT 0x0D12 +#define GL_INDEX_OFFSET 0x0D13 +#define GL_RED_SCALE 0x0D14 +#define GL_RED_BIAS 0x0D15 +#define GL_GREEN_SCALE 0x0D18 +#define GL_GREEN_BIAS 0x0D19 +#define GL_BLUE_SCALE 0x0D1A +#define GL_BLUE_BIAS 0x0D1B +#define GL_ALPHA_SCALE 0x0D1C +#define GL_ALPHA_BIAS 0x0D1D +#define GL_DEPTH_SCALE 0x0D1E +#define GL_DEPTH_BIAS 0x0D1F +#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1 +#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0 +#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2 +#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3 +#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4 +#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5 +#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6 +#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7 +#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8 +#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9 +#define GL_PIXEL_MAP_S_TO_S 0x0C71 +#define GL_PIXEL_MAP_I_TO_I 0x0C70 +#define GL_PIXEL_MAP_I_TO_R 0x0C72 +#define GL_PIXEL_MAP_I_TO_G 0x0C73 +#define GL_PIXEL_MAP_I_TO_B 0x0C74 +#define GL_PIXEL_MAP_I_TO_A 0x0C75 +#define GL_PIXEL_MAP_R_TO_R 0x0C76 +#define GL_PIXEL_MAP_G_TO_G 0x0C77 +#define GL_PIXEL_MAP_B_TO_B 0x0C78 +#define GL_PIXEL_MAP_A_TO_A 0x0C79 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_PACK_LSB_FIRST 0x0D01 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SWAP_BYTES 0x0D00 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_UNPACK_LSB_FIRST 0x0CF1 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SWAP_BYTES 0x0CF0 +#define GL_ZOOM_X 0x0D16 +#define GL_ZOOM_Y 0x0D17 + +/* Texture mapping */ +#define GL_TEXTURE_ENV 0x2300 +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_1D 0x0DE0 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_ENV_COLOR 0x2201 +#define GL_TEXTURE_GEN_S 0x0C60 +#define GL_TEXTURE_GEN_T 0x0C61 +#define GL_TEXTURE_GEN_R 0x0C62 +#define GL_TEXTURE_GEN_Q 0x0C63 +#define GL_TEXTURE_GEN_MODE 0x2500 +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_BORDER 0x1005 +#define GL_TEXTURE_COMPONENTS 0x1003 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE 0x8061 +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 +#define GL_OBJECT_LINEAR 0x2401 +#define GL_OBJECT_PLANE 0x2501 +#define GL_EYE_LINEAR 0x2400 +#define GL_EYE_PLANE 0x2502 +#define GL_SPHERE_MAP 0x2402 +#define GL_DECAL 0x2101 +#define GL_MODULATE 0x2100 +#define GL_NEAREST 0x2600 +#define GL_REPEAT 0x2901 +#define GL_CLAMP 0x2900 +#define GL_S 0x2000 +#define GL_T 0x2001 +#define GL_R 0x2002 +#define GL_Q 0x2003 + +/* Utility */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* Errors */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 + +/* glPush/PopAttrib bits */ +#define GL_CURRENT_BIT 0x00000001 +#define GL_POINT_BIT 0x00000002 +#define GL_LINE_BIT 0x00000004 +#define GL_POLYGON_BIT 0x00000008 +#define GL_POLYGON_STIPPLE_BIT 0x00000010 +#define GL_PIXEL_MODE_BIT 0x00000020 +#define GL_LIGHTING_BIT 0x00000040 +#define GL_FOG_BIT 0x00000080 +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_ACCUM_BUFFER_BIT 0x00000200 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_VIEWPORT_BIT 0x00000800 +#define GL_TRANSFORM_BIT 0x00001000 +#define GL_ENABLE_BIT 0x00002000 +#define GL_COLOR_BUFFER_BIT 0x00004000 +#define GL_HINT_BIT 0x00008000 +#define GL_EVAL_BIT 0x00010000 +#define GL_LIST_BIT 0x00020000 +#define GL_TEXTURE_BIT 0x00040000 +#define GL_SCISSOR_BIT 0x00080000 +#define GL_ALL_ATTRIB_BITS 0xFFFFFFFF + + +/* OpenGL 1.1 */ +#define GL_PROXY_TEXTURE_1D 0x8063 +#define GL_PROXY_TEXTURE_2D 0x8064 +#define GL_TEXTURE_PRIORITY 0x8066 +#define GL_TEXTURE_RESIDENT 0x8067 +#define GL_TEXTURE_BINDING_1D 0x8068 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 +#define GL_ALPHA4 0x803B +#define GL_ALPHA8 0x803C +#define GL_ALPHA12 0x803D +#define GL_ALPHA16 0x803E +#define GL_LUMINANCE4 0x803F +#define GL_LUMINANCE8 0x8040 +#define GL_LUMINANCE12 0x8041 +#define GL_LUMINANCE16 0x8042 +#define GL_LUMINANCE4_ALPHA4 0x8043 +#define GL_LUMINANCE6_ALPHA2 0x8044 +#define GL_LUMINANCE8_ALPHA8 0x8045 +#define GL_LUMINANCE12_ALPHA4 0x8046 +#define GL_LUMINANCE12_ALPHA12 0x8047 +#define GL_LUMINANCE16_ALPHA16 0x8048 +#define GL_INTENSITY 0x8049 +#define GL_INTENSITY4 0x804A +#define GL_INTENSITY8 0x804B +#define GL_INTENSITY12 0x804C +#define GL_INTENSITY16 0x804D +#define GL_R3_G3_B2 0x2A10 +#define GL_RGB4 0x804F +#define GL_RGB5 0x8050 +#define GL_RGB8 0x8051 +#define GL_RGB10 0x8052 +#define GL_RGB12 0x8053 +#define GL_RGB16 0x8054 +#define GL_RGBA2 0x8055 +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGBA8 0x8058 +#define GL_RGB10_A2 0x8059 +#define GL_RGBA12 0x805A +#define GL_RGBA16 0x805B +#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001 +#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 +#define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFFF +#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF + + + +/* + * Miscellaneous + */ + +GLAPI void GLAPIENTRY glClearIndex( GLfloat c ); + +GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); + +GLAPI void GLAPIENTRY glClear( GLbitfield mask ); + +GLAPI void GLAPIENTRY glIndexMask( GLuint mask ); + +GLAPI void GLAPIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ); + +GLAPI void GLAPIENTRY glAlphaFunc( GLenum func, GLclampf ref ); + +GLAPI void GLAPIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor ); + +GLAPI void GLAPIENTRY glLogicOp( GLenum opcode ); + +GLAPI void GLAPIENTRY glCullFace( GLenum mode ); + +GLAPI void GLAPIENTRY glFrontFace( GLenum mode ); + +GLAPI void GLAPIENTRY glPointSize( GLfloat size ); + +GLAPI void GLAPIENTRY glLineWidth( GLfloat width ); + +GLAPI void GLAPIENTRY glLineStipple( GLint factor, GLushort pattern ); + +GLAPI void GLAPIENTRY glPolygonMode( GLenum face, GLenum mode ); + +GLAPI void GLAPIENTRY glPolygonOffset( GLfloat factor, GLfloat units ); + +GLAPI void GLAPIENTRY glPolygonStipple( const GLubyte *mask ); + +GLAPI void GLAPIENTRY glGetPolygonStipple( GLubyte *mask ); + +GLAPI void GLAPIENTRY glEdgeFlag( GLboolean flag ); + +GLAPI void GLAPIENTRY glEdgeFlagv( const GLboolean *flag ); + +GLAPI void GLAPIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height); + +GLAPI void GLAPIENTRY glClipPlane( GLenum plane, const GLdouble *equation ); + +GLAPI void GLAPIENTRY glGetClipPlane( GLenum plane, GLdouble *equation ); + +GLAPI void GLAPIENTRY glDrawBuffer( GLenum mode ); + +GLAPI void GLAPIENTRY glReadBuffer( GLenum mode ); + +GLAPI void GLAPIENTRY glEnable( GLenum cap ); + +GLAPI void GLAPIENTRY glDisable( GLenum cap ); + +GLAPI GLboolean GLAPIENTRY glIsEnabled( GLenum cap ); + + +GLAPI void GLAPIENTRY glEnableClientState( GLenum cap ); /* 1.1 */ + +GLAPI void GLAPIENTRY glDisableClientState( GLenum cap ); /* 1.1 */ + + +GLAPI void GLAPIENTRY glGetBooleanv( GLenum pname, GLboolean *params ); + +GLAPI void GLAPIENTRY glGetDoublev( GLenum pname, GLdouble *params ); + +GLAPI void GLAPIENTRY glGetFloatv( GLenum pname, GLfloat *params ); + +GLAPI void GLAPIENTRY glGetIntegerv( GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glPushAttrib( GLbitfield mask ); + +GLAPI void GLAPIENTRY glPopAttrib( void ); + + +GLAPI void GLAPIENTRY glPushClientAttrib( GLbitfield mask ); /* 1.1 */ + +GLAPI void GLAPIENTRY glPopClientAttrib( void ); /* 1.1 */ + + +GLAPI GLint GLAPIENTRY glRenderMode( GLenum mode ); + +GLAPI GLenum GLAPIENTRY glGetError( void ); + +GLAPI const GLubyte * GLAPIENTRY glGetString( GLenum name ); + +GLAPI void GLAPIENTRY glFinish( void ); + +GLAPI void GLAPIENTRY glFlush( void ); + +GLAPI void GLAPIENTRY glHint( GLenum target, GLenum mode ); + + +/* + * Depth Buffer + */ + +GLAPI void GLAPIENTRY glClearDepth( GLclampd depth ); + +GLAPI void GLAPIENTRY glDepthFunc( GLenum func ); + +GLAPI void GLAPIENTRY glDepthMask( GLboolean flag ); + +GLAPI void GLAPIENTRY glDepthRange( GLclampd near_val, GLclampd far_val ); + + +/* + * Accumulation Buffer + */ + +GLAPI void GLAPIENTRY glClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ); + +GLAPI void GLAPIENTRY glAccum( GLenum op, GLfloat value ); + + +/* + * Transformation + */ + +GLAPI void GLAPIENTRY glMatrixMode( GLenum mode ); + +GLAPI void GLAPIENTRY glOrtho( GLdouble left, GLdouble right, + GLdouble bottom, GLdouble top, + GLdouble near_val, GLdouble far_val ); + +GLAPI void GLAPIENTRY glFrustum( GLdouble left, GLdouble right, + GLdouble bottom, GLdouble top, + GLdouble near_val, GLdouble far_val ); + +GLAPI void GLAPIENTRY glViewport( GLint x, GLint y, + GLsizei width, GLsizei height ); + +GLAPI void GLAPIENTRY glPushMatrix( void ); + +GLAPI void GLAPIENTRY glPopMatrix( void ); + +GLAPI void GLAPIENTRY glLoadIdentity( void ); + +GLAPI void GLAPIENTRY glLoadMatrixd( const GLdouble *m ); +GLAPI void GLAPIENTRY glLoadMatrixf( const GLfloat *m ); + +GLAPI void GLAPIENTRY glMultMatrixd( const GLdouble *m ); +GLAPI void GLAPIENTRY glMultMatrixf( const GLfloat *m ); + +GLAPI void GLAPIENTRY glRotated( GLdouble angle, + GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glRotatef( GLfloat angle, + GLfloat x, GLfloat y, GLfloat z ); + +GLAPI void GLAPIENTRY glScaled( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z ); + +GLAPI void GLAPIENTRY glTranslated( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z ); + + +/* + * Display Lists + */ + +GLAPI GLboolean GLAPIENTRY glIsList( GLuint list ); + +GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range ); + +GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range ); + +GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode ); + +GLAPI void GLAPIENTRY glEndList( void ); + +GLAPI void GLAPIENTRY glCallList( GLuint list ); + +GLAPI void GLAPIENTRY glCallLists( GLsizei n, GLenum type, + const GLvoid *lists ); + +GLAPI void GLAPIENTRY glListBase( GLuint base ); + + +/* + * Drawing Functions + */ + +GLAPI void GLAPIENTRY glBegin( GLenum mode ); + +GLAPI void GLAPIENTRY glEnd( void ); + + +GLAPI void GLAPIENTRY glVertex2d( GLdouble x, GLdouble y ); +GLAPI void GLAPIENTRY glVertex2f( GLfloat x, GLfloat y ); +GLAPI void GLAPIENTRY glVertex2i( GLint x, GLint y ); +GLAPI void GLAPIENTRY glVertex2s( GLshort x, GLshort y ); + +GLAPI void GLAPIENTRY glVertex3d( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glVertex3f( GLfloat x, GLfloat y, GLfloat z ); +GLAPI void GLAPIENTRY glVertex3i( GLint x, GLint y, GLint z ); +GLAPI void GLAPIENTRY glVertex3s( GLshort x, GLshort y, GLshort z ); + +GLAPI void GLAPIENTRY glVertex4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w ); +GLAPI void GLAPIENTRY glVertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w ); +GLAPI void GLAPIENTRY glVertex4i( GLint x, GLint y, GLint z, GLint w ); +GLAPI void GLAPIENTRY glVertex4s( GLshort x, GLshort y, GLshort z, GLshort w ); + +GLAPI void GLAPIENTRY glVertex2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex2iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glVertex3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex3iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glVertex4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex4iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glNormal3b( GLbyte nx, GLbyte ny, GLbyte nz ); +GLAPI void GLAPIENTRY glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz ); +GLAPI void GLAPIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz ); +GLAPI void GLAPIENTRY glNormal3i( GLint nx, GLint ny, GLint nz ); +GLAPI void GLAPIENTRY glNormal3s( GLshort nx, GLshort ny, GLshort nz ); + +GLAPI void GLAPIENTRY glNormal3bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glNormal3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glNormal3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glNormal3iv( const GLint *v ); +GLAPI void GLAPIENTRY glNormal3sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glIndexd( GLdouble c ); +GLAPI void GLAPIENTRY glIndexf( GLfloat c ); +GLAPI void GLAPIENTRY glIndexi( GLint c ); +GLAPI void GLAPIENTRY glIndexs( GLshort c ); +GLAPI void GLAPIENTRY glIndexub( GLubyte c ); /* 1.1 */ + +GLAPI void GLAPIENTRY glIndexdv( const GLdouble *c ); +GLAPI void GLAPIENTRY glIndexfv( const GLfloat *c ); +GLAPI void GLAPIENTRY glIndexiv( const GLint *c ); +GLAPI void GLAPIENTRY glIndexsv( const GLshort *c ); +GLAPI void GLAPIENTRY glIndexubv( const GLubyte *c ); /* 1.1 */ + +GLAPI void GLAPIENTRY glColor3b( GLbyte red, GLbyte green, GLbyte blue ); +GLAPI void GLAPIENTRY glColor3d( GLdouble red, GLdouble green, GLdouble blue ); +GLAPI void GLAPIENTRY glColor3f( GLfloat red, GLfloat green, GLfloat blue ); +GLAPI void GLAPIENTRY glColor3i( GLint red, GLint green, GLint blue ); +GLAPI void GLAPIENTRY glColor3s( GLshort red, GLshort green, GLshort blue ); +GLAPI void GLAPIENTRY glColor3ub( GLubyte red, GLubyte green, GLubyte blue ); +GLAPI void GLAPIENTRY glColor3ui( GLuint red, GLuint green, GLuint blue ); +GLAPI void GLAPIENTRY glColor3us( GLushort red, GLushort green, GLushort blue ); + +GLAPI void GLAPIENTRY glColor4b( GLbyte red, GLbyte green, + GLbyte blue, GLbyte alpha ); +GLAPI void GLAPIENTRY glColor4d( GLdouble red, GLdouble green, + GLdouble blue, GLdouble alpha ); +GLAPI void GLAPIENTRY glColor4f( GLfloat red, GLfloat green, + GLfloat blue, GLfloat alpha ); +GLAPI void GLAPIENTRY glColor4i( GLint red, GLint green, + GLint blue, GLint alpha ); +GLAPI void GLAPIENTRY glColor4s( GLshort red, GLshort green, + GLshort blue, GLshort alpha ); +GLAPI void GLAPIENTRY glColor4ub( GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha ); +GLAPI void GLAPIENTRY glColor4ui( GLuint red, GLuint green, + GLuint blue, GLuint alpha ); +GLAPI void GLAPIENTRY glColor4us( GLushort red, GLushort green, + GLushort blue, GLushort alpha ); + + +GLAPI void GLAPIENTRY glColor3bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glColor3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glColor3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glColor3iv( const GLint *v ); +GLAPI void GLAPIENTRY glColor3sv( const GLshort *v ); +GLAPI void GLAPIENTRY glColor3ubv( const GLubyte *v ); +GLAPI void GLAPIENTRY glColor3uiv( const GLuint *v ); +GLAPI void GLAPIENTRY glColor3usv( const GLushort *v ); + +GLAPI void GLAPIENTRY glColor4bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glColor4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glColor4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glColor4iv( const GLint *v ); +GLAPI void GLAPIENTRY glColor4sv( const GLshort *v ); +GLAPI void GLAPIENTRY glColor4ubv( const GLubyte *v ); +GLAPI void GLAPIENTRY glColor4uiv( const GLuint *v ); +GLAPI void GLAPIENTRY glColor4usv( const GLushort *v ); + + +GLAPI void GLAPIENTRY glTexCoord1d( GLdouble s ); +GLAPI void GLAPIENTRY glTexCoord1f( GLfloat s ); +GLAPI void GLAPIENTRY glTexCoord1i( GLint s ); +GLAPI void GLAPIENTRY glTexCoord1s( GLshort s ); + +GLAPI void GLAPIENTRY glTexCoord2d( GLdouble s, GLdouble t ); +GLAPI void GLAPIENTRY glTexCoord2f( GLfloat s, GLfloat t ); +GLAPI void GLAPIENTRY glTexCoord2i( GLint s, GLint t ); +GLAPI void GLAPIENTRY glTexCoord2s( GLshort s, GLshort t ); + +GLAPI void GLAPIENTRY glTexCoord3d( GLdouble s, GLdouble t, GLdouble r ); +GLAPI void GLAPIENTRY glTexCoord3f( GLfloat s, GLfloat t, GLfloat r ); +GLAPI void GLAPIENTRY glTexCoord3i( GLint s, GLint t, GLint r ); +GLAPI void GLAPIENTRY glTexCoord3s( GLshort s, GLshort t, GLshort r ); + +GLAPI void GLAPIENTRY glTexCoord4d( GLdouble s, GLdouble t, GLdouble r, GLdouble q ); +GLAPI void GLAPIENTRY glTexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q ); +GLAPI void GLAPIENTRY glTexCoord4i( GLint s, GLint t, GLint r, GLint q ); +GLAPI void GLAPIENTRY glTexCoord4s( GLshort s, GLshort t, GLshort r, GLshort q ); + +GLAPI void GLAPIENTRY glTexCoord1dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord1fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord1iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord1sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord2iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord3iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord4iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glRasterPos2d( GLdouble x, GLdouble y ); +GLAPI void GLAPIENTRY glRasterPos2f( GLfloat x, GLfloat y ); +GLAPI void GLAPIENTRY glRasterPos2i( GLint x, GLint y ); +GLAPI void GLAPIENTRY glRasterPos2s( GLshort x, GLshort y ); + +GLAPI void GLAPIENTRY glRasterPos3d( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glRasterPos3f( GLfloat x, GLfloat y, GLfloat z ); +GLAPI void GLAPIENTRY glRasterPos3i( GLint x, GLint y, GLint z ); +GLAPI void GLAPIENTRY glRasterPos3s( GLshort x, GLshort y, GLshort z ); + +GLAPI void GLAPIENTRY glRasterPos4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w ); +GLAPI void GLAPIENTRY glRasterPos4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w ); +GLAPI void GLAPIENTRY glRasterPos4i( GLint x, GLint y, GLint z, GLint w ); +GLAPI void GLAPIENTRY glRasterPos4s( GLshort x, GLshort y, GLshort z, GLshort w ); + +GLAPI void GLAPIENTRY glRasterPos2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos2iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glRasterPos3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos3iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glRasterPos4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos4iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glRectd( GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2 ); +GLAPI void GLAPIENTRY glRectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ); +GLAPI void GLAPIENTRY glRecti( GLint x1, GLint y1, GLint x2, GLint y2 ); +GLAPI void GLAPIENTRY glRects( GLshort x1, GLshort y1, GLshort x2, GLshort y2 ); + + +GLAPI void GLAPIENTRY glRectdv( const GLdouble *v1, const GLdouble *v2 ); +GLAPI void GLAPIENTRY glRectfv( const GLfloat *v1, const GLfloat *v2 ); +GLAPI void GLAPIENTRY glRectiv( const GLint *v1, const GLint *v2 ); +GLAPI void GLAPIENTRY glRectsv( const GLshort *v1, const GLshort *v2 ); + + +/* + * Vertex Arrays (1.1) + */ + +GLAPI void GLAPIENTRY glVertexPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glNormalPointer( GLenum type, GLsizei stride, + const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glColorPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glIndexPointer( GLenum type, GLsizei stride, + const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glTexCoordPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glEdgeFlagPointer( GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glGetPointerv( GLenum pname, GLvoid **params ); + +GLAPI void GLAPIENTRY glArrayElement( GLint i ); + +GLAPI void GLAPIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ); + +GLAPI void GLAPIENTRY glDrawElements( GLenum mode, GLsizei count, + GLenum type, const GLvoid *indices ); + +GLAPI void GLAPIENTRY glInterleavedArrays( GLenum format, GLsizei stride, + const GLvoid *pointer ); + +/* + * Lighting + */ + +GLAPI void GLAPIENTRY glShadeModel( GLenum mode ); + +GLAPI void GLAPIENTRY glLightf( GLenum light, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glLighti( GLenum light, GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glLightfv( GLenum light, GLenum pname, + const GLfloat *params ); +GLAPI void GLAPIENTRY glLightiv( GLenum light, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glGetLightfv( GLenum light, GLenum pname, + GLfloat *params ); +GLAPI void GLAPIENTRY glGetLightiv( GLenum light, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glLightModelf( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glLightModeli( GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glLightModelfv( GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glLightModeliv( GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glMateriali( GLenum face, GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glMaterialiv( GLenum face, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetMaterialiv( GLenum face, GLenum pname, GLint *params ); + +GLAPI void GLAPIENTRY glColorMaterial( GLenum face, GLenum mode ); + + +/* + * Raster functions + */ + +GLAPI void GLAPIENTRY glPixelZoom( GLfloat xfactor, GLfloat yfactor ); + +GLAPI void GLAPIENTRY glPixelStoref( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glPixelStorei( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glPixelTransferf( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glPixelTransferi( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glPixelMapfv( GLenum map, GLsizei mapsize, + const GLfloat *values ); +GLAPI void GLAPIENTRY glPixelMapuiv( GLenum map, GLsizei mapsize, + const GLuint *values ); +GLAPI void GLAPIENTRY glPixelMapusv( GLenum map, GLsizei mapsize, + const GLushort *values ); + +GLAPI void GLAPIENTRY glGetPixelMapfv( GLenum map, GLfloat *values ); +GLAPI void GLAPIENTRY glGetPixelMapuiv( GLenum map, GLuint *values ); +GLAPI void GLAPIENTRY glGetPixelMapusv( GLenum map, GLushort *values ); + +GLAPI void GLAPIENTRY glBitmap( GLsizei width, GLsizei height, + GLfloat xorig, GLfloat yorig, + GLfloat xmove, GLfloat ymove, + const GLubyte *bitmap ); + +GLAPI void GLAPIENTRY glReadPixels( GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + GLvoid *pixels ); + +GLAPI void GLAPIENTRY glDrawPixels( GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glCopyPixels( GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type ); + +/* + * Stenciling + */ + +GLAPI void GLAPIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask ); + +GLAPI void GLAPIENTRY glStencilMask( GLuint mask ); + +GLAPI void GLAPIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass ); + +GLAPI void GLAPIENTRY glClearStencil( GLint s ); + + + +/* + * Texture mapping + */ + +GLAPI void GLAPIENTRY glTexGend( GLenum coord, GLenum pname, GLdouble param ); +GLAPI void GLAPIENTRY glTexGenf( GLenum coord, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexGeni( GLenum coord, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexGendv( GLenum coord, GLenum pname, const GLdouble *params ); +GLAPI void GLAPIENTRY glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glTexGeniv( GLenum coord, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexGendv( GLenum coord, GLenum pname, GLdouble *params ); +GLAPI void GLAPIENTRY glGetTexGenfv( GLenum coord, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexGeniv( GLenum coord, GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexEnviv( GLenum target, GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexParameterfv( GLenum target, GLenum pname, + const GLfloat *params ); +GLAPI void GLAPIENTRY glTexParameteriv( GLenum target, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexParameterfv( GLenum target, + GLenum pname, GLfloat *params); +GLAPI void GLAPIENTRY glGetTexParameteriv( GLenum target, + GLenum pname, GLint *params ); + +GLAPI void GLAPIENTRY glGetTexLevelParameterfv( GLenum target, GLint level, + GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexLevelParameteriv( GLenum target, GLint level, + GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexImage1D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glTexImage2D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLsizei height, + GLint border, GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glGetTexImage( GLenum target, GLint level, + GLenum format, GLenum type, + GLvoid *pixels ); + + +/* 1.1 functions */ + +GLAPI void GLAPIENTRY glGenTextures( GLsizei n, GLuint *textures ); + +GLAPI void GLAPIENTRY glDeleteTextures( GLsizei n, const GLuint *textures); + +GLAPI void GLAPIENTRY glBindTexture( GLenum target, GLuint texture ); + +GLAPI void GLAPIENTRY glPrioritizeTextures( GLsizei n, + const GLuint *textures, + const GLclampf *priorities ); + +GLAPI GLboolean GLAPIENTRY glAreTexturesResident( GLsizei n, + const GLuint *textures, + GLboolean *residences ); + +GLAPI GLboolean GLAPIENTRY glIsTexture( GLuint texture ); + + +GLAPI void GLAPIENTRY glTexSubImage1D( GLenum target, GLint level, + GLint xoffset, + GLsizei width, GLenum format, + GLenum type, const GLvoid *pixels ); + + +GLAPI void GLAPIENTRY glTexSubImage2D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels ); + + +GLAPI void GLAPIENTRY glCopyTexImage1D( GLenum target, GLint level, + GLenum internalformat, + GLint x, GLint y, + GLsizei width, GLint border ); + + +GLAPI void GLAPIENTRY glCopyTexImage2D( GLenum target, GLint level, + GLenum internalformat, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLint border ); + + +GLAPI void GLAPIENTRY glCopyTexSubImage1D( GLenum target, GLint level, + GLint xoffset, GLint x, GLint y, + GLsizei width ); + + +GLAPI void GLAPIENTRY glCopyTexSubImage2D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, + GLsizei width, GLsizei height ); + + +/* + * Evaluators + */ + +GLAPI void GLAPIENTRY glMap1d( GLenum target, GLdouble u1, GLdouble u2, + GLint stride, + GLint order, const GLdouble *points ); +GLAPI void GLAPIENTRY glMap1f( GLenum target, GLfloat u1, GLfloat u2, + GLint stride, + GLint order, const GLfloat *points ); + +GLAPI void GLAPIENTRY glMap2d( GLenum target, + GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, + GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, + const GLdouble *points ); +GLAPI void GLAPIENTRY glMap2f( GLenum target, + GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, + GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, + const GLfloat *points ); + +GLAPI void GLAPIENTRY glGetMapdv( GLenum target, GLenum query, GLdouble *v ); +GLAPI void GLAPIENTRY glGetMapfv( GLenum target, GLenum query, GLfloat *v ); +GLAPI void GLAPIENTRY glGetMapiv( GLenum target, GLenum query, GLint *v ); + +GLAPI void GLAPIENTRY glEvalCoord1d( GLdouble u ); +GLAPI void GLAPIENTRY glEvalCoord1f( GLfloat u ); + +GLAPI void GLAPIENTRY glEvalCoord1dv( const GLdouble *u ); +GLAPI void GLAPIENTRY glEvalCoord1fv( const GLfloat *u ); + +GLAPI void GLAPIENTRY glEvalCoord2d( GLdouble u, GLdouble v ); +GLAPI void GLAPIENTRY glEvalCoord2f( GLfloat u, GLfloat v ); + +GLAPI void GLAPIENTRY glEvalCoord2dv( const GLdouble *u ); +GLAPI void GLAPIENTRY glEvalCoord2fv( const GLfloat *u ); + +GLAPI void GLAPIENTRY glMapGrid1d( GLint un, GLdouble u1, GLdouble u2 ); +GLAPI void GLAPIENTRY glMapGrid1f( GLint un, GLfloat u1, GLfloat u2 ); + +GLAPI void GLAPIENTRY glMapGrid2d( GLint un, GLdouble u1, GLdouble u2, + GLint vn, GLdouble v1, GLdouble v2 ); +GLAPI void GLAPIENTRY glMapGrid2f( GLint un, GLfloat u1, GLfloat u2, + GLint vn, GLfloat v1, GLfloat v2 ); + +GLAPI void GLAPIENTRY glEvalPoint1( GLint i ); + +GLAPI void GLAPIENTRY glEvalPoint2( GLint i, GLint j ); + +GLAPI void GLAPIENTRY glEvalMesh1( GLenum mode, GLint i1, GLint i2 ); + +GLAPI void GLAPIENTRY glEvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 ); + + +/* + * Fog + */ + +GLAPI void GLAPIENTRY glFogf( GLenum pname, GLfloat param ); + +GLAPI void GLAPIENTRY glFogi( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glFogfv( GLenum pname, const GLfloat *params ); + +GLAPI void GLAPIENTRY glFogiv( GLenum pname, const GLint *params ); + + +/* + * Selection and Feedback + */ + +GLAPI void GLAPIENTRY glFeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer ); + +GLAPI void GLAPIENTRY glPassThrough( GLfloat token ); + +GLAPI void GLAPIENTRY glSelectBuffer( GLsizei size, GLuint *buffer ); + +GLAPI void GLAPIENTRY glInitNames( void ); + +GLAPI void GLAPIENTRY glLoadName( GLuint name ); + +GLAPI void GLAPIENTRY glPushName( GLuint name ); + +GLAPI void GLAPIENTRY glPopName( void ); + + + +/* + * OpenGL 1.2 + */ + +#define GL_RESCALE_NORMAL 0x803A +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_TEXTURE_BINDING_3D 0x806A + +GLAPI void GLAPIENTRY glDrawRangeElements( GLenum mode, GLuint start, + GLuint end, GLsizei count, GLenum type, const GLvoid *indices ); + +GLAPI void GLAPIENTRY glTexImage3D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glTexSubImage3D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint zoffset, GLsizei width, + GLsizei height, GLsizei depth, + GLenum format, + GLenum type, const GLvoid *pixels); + +GLAPI void GLAPIENTRY glCopyTexSubImage3D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint zoffset, GLint x, + GLint y, GLsizei width, + GLsizei height ); + +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + + +/* + * GL_ARB_imaging + */ + +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_BLEND_EQUATION 0x8009 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_FUNC_ADD 0x8006 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#define GL_BLEND_COLOR 0x8005 + + +GLAPI void GLAPIENTRY glColorTable( GLenum target, GLenum internalformat, + GLsizei width, GLenum format, + GLenum type, const GLvoid *table ); + +GLAPI void GLAPIENTRY glColorSubTable( GLenum target, + GLsizei start, GLsizei count, + GLenum format, GLenum type, + const GLvoid *data ); + +GLAPI void GLAPIENTRY glColorTableParameteriv(GLenum target, GLenum pname, + const GLint *params); + +GLAPI void GLAPIENTRY glColorTableParameterfv(GLenum target, GLenum pname, + const GLfloat *params); + +GLAPI void GLAPIENTRY glCopyColorSubTable( GLenum target, GLsizei start, + GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glCopyColorTable( GLenum target, GLenum internalformat, + GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glGetColorTable( GLenum target, GLenum format, + GLenum type, GLvoid *table ); + +GLAPI void GLAPIENTRY glGetColorTableParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetColorTableParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glBlendEquation( GLenum mode ); + +GLAPI void GLAPIENTRY glBlendColor( GLclampf red, GLclampf green, + GLclampf blue, GLclampf alpha ); + +GLAPI void GLAPIENTRY glHistogram( GLenum target, GLsizei width, + GLenum internalformat, GLboolean sink ); + +GLAPI void GLAPIENTRY glResetHistogram( GLenum target ); + +GLAPI void GLAPIENTRY glGetHistogram( GLenum target, GLboolean reset, + GLenum format, GLenum type, + GLvoid *values ); + +GLAPI void GLAPIENTRY glGetHistogramParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetHistogramParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glMinmax( GLenum target, GLenum internalformat, + GLboolean sink ); + +GLAPI void GLAPIENTRY glResetMinmax( GLenum target ); + +GLAPI void GLAPIENTRY glGetMinmax( GLenum target, GLboolean reset, + GLenum format, GLenum types, + GLvoid *values ); + +GLAPI void GLAPIENTRY glGetMinmaxParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetMinmaxParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glConvolutionFilter1D( GLenum target, + GLenum internalformat, GLsizei width, GLenum format, GLenum type, + const GLvoid *image ); + +GLAPI void GLAPIENTRY glConvolutionFilter2D( GLenum target, + GLenum internalformat, GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid *image ); + +GLAPI void GLAPIENTRY glConvolutionParameterf( GLenum target, GLenum pname, + GLfloat params ); + +GLAPI void GLAPIENTRY glConvolutionParameterfv( GLenum target, GLenum pname, + const GLfloat *params ); + +GLAPI void GLAPIENTRY glConvolutionParameteri( GLenum target, GLenum pname, + GLint params ); + +GLAPI void GLAPIENTRY glConvolutionParameteriv( GLenum target, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glCopyConvolutionFilter1D( GLenum target, + GLenum internalformat, GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glCopyConvolutionFilter2D( GLenum target, + GLenum internalformat, GLint x, GLint y, GLsizei width, + GLsizei height); + +GLAPI void GLAPIENTRY glGetConvolutionFilter( GLenum target, GLenum format, + GLenum type, GLvoid *image ); + +GLAPI void GLAPIENTRY glGetConvolutionParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetConvolutionParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glSeparableFilter2D( GLenum target, + GLenum internalformat, GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid *row, const GLvoid *column ); + +GLAPI void GLAPIENTRY glGetSeparableFilter( GLenum target, GLenum format, + GLenum type, GLvoid *row, GLvoid *column, GLvoid *span ); + + + + +/* + * OpenGL 1.3 + */ + +/* multitexture */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +/* texture_cube_map */ +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +/* texture_compression */ +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +/* multisample */ +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_MULTISAMPLE_BIT 0x20000000 +/* transpose_matrix */ +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +/* texture_env_combine */ +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +/* texture_env_dot3 */ +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +/* texture_border_clamp */ +#define GL_CLAMP_TO_BORDER 0x812D + +GLAPI void GLAPIENTRY glActiveTexture( GLenum texture ); + +GLAPI void GLAPIENTRY glClientActiveTexture( GLenum texture ); + +GLAPI void GLAPIENTRY glCompressedTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glGetCompressedTexImage( GLenum target, GLint lod, GLvoid *img ); + +GLAPI void GLAPIENTRY glMultiTexCoord1d( GLenum target, GLdouble s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1f( GLenum target, GLfloat s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1i( GLenum target, GLint s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1s( GLenum target, GLshort s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2d( GLenum target, GLdouble s, GLdouble t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2f( GLenum target, GLfloat s, GLfloat t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2i( GLenum target, GLint s, GLint t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2s( GLenum target, GLshort s, GLshort t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3d( GLenum target, GLdouble s, GLdouble t, GLdouble r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3f( GLenum target, GLfloat s, GLfloat t, GLfloat r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3i( GLenum target, GLint s, GLint t, GLint r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3s( GLenum target, GLshort s, GLshort t, GLshort r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4d( GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4i( GLenum target, GLint s, GLint t, GLint r, GLint q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4s( GLenum target, GLshort s, GLshort t, GLshort r, GLshort q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4sv( GLenum target, const GLshort *v ); + + +GLAPI void GLAPIENTRY glLoadTransposeMatrixd( const GLdouble * m ); + +GLAPI void GLAPIENTRY glLoadTransposeMatrixf( const GLfloat * m ); + +GLAPI void GLAPIENTRY glMultTransposeMatrixd( const GLdouble * m ); + +GLAPI void GLAPIENTRY glMultTransposeMatrixf( const GLfloat * m ); + +GLAPI void GLAPIENTRY glSampleCoverage( GLclampf value, GLboolean invert ); + + +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); + + + +/* + * GL_ARB_multitexture (ARB extension 1 and OpenGL 1.2.1) + */ +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 + +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 + +GLAPI void GLAPIENTRY glActiveTextureARB(GLenum texture); +GLAPI void GLAPIENTRY glClientActiveTextureARB(GLenum texture); +GLAPI void GLAPIENTRY glMultiTexCoord1dARB(GLenum target, GLdouble s); +GLAPI void GLAPIENTRY glMultiTexCoord1dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord1fARB(GLenum target, GLfloat s); +GLAPI void GLAPIENTRY glMultiTexCoord1fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord1iARB(GLenum target, GLint s); +GLAPI void GLAPIENTRY glMultiTexCoord1ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord1sARB(GLenum target, GLshort s); +GLAPI void GLAPIENTRY glMultiTexCoord1svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord2dARB(GLenum target, GLdouble s, GLdouble t); +GLAPI void GLAPIENTRY glMultiTexCoord2dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t); +GLAPI void GLAPIENTRY glMultiTexCoord2fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord2iARB(GLenum target, GLint s, GLint t); +GLAPI void GLAPIENTRY glMultiTexCoord2ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord2sARB(GLenum target, GLshort s, GLshort t); +GLAPI void GLAPIENTRY glMultiTexCoord2svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord3dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void GLAPIENTRY glMultiTexCoord3dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void GLAPIENTRY glMultiTexCoord3fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord3iARB(GLenum target, GLint s, GLint t, GLint r); +GLAPI void GLAPIENTRY glMultiTexCoord3ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord3sARB(GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void GLAPIENTRY glMultiTexCoord3svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord4dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void GLAPIENTRY glMultiTexCoord4dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void GLAPIENTRY glMultiTexCoord4fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord4iARB(GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void GLAPIENTRY glMultiTexCoord4ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord4sARB(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void GLAPIENTRY glMultiTexCoord4svARB(GLenum target, const GLshort *v); + +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); + +#endif /* GL_ARB_multitexture */ + + + +/* + * Define this token if you want "old-style" header file behaviour (extensions + * defined in gl.h). Otherwise, extensions will be included from glext.h. + */ +#if defined(GL_GLEXT_LEGACY) + +/* All extensions that used to be here are now found in glext.h */ + +#else /* GL_GLEXT_LEGACY */ + +#include "vendor/glext.h" + +#endif /* GL_GLEXT_LEGACY */ + + + +/* + * ???. GL_MESA_packed_depth_stencil + * XXX obsolete + */ +#ifndef GL_MESA_packed_depth_stencil +#define GL_MESA_packed_depth_stencil 1 + +#define GL_DEPTH_STENCIL_MESA 0x8750 +#define GL_UNSIGNED_INT_24_8_MESA 0x8751 +#define GL_UNSIGNED_INT_8_24_REV_MESA 0x8752 +#define GL_UNSIGNED_SHORT_15_1_MESA 0x8753 +#define GL_UNSIGNED_SHORT_1_15_REV_MESA 0x8754 + +#endif /* GL_MESA_packed_depth_stencil */ + + +#ifndef GL_ATI_blend_equation_separate +#define GL_ATI_blend_equation_separate 1 + +#define GL_ALPHA_BLEND_EQUATION_ATI 0x883D + +GLAPI void GLAPIENTRY glBlendEquationSeparateATI( GLenum modeRGB, GLenum modeA ); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEATIPROC) (GLenum modeRGB, GLenum modeA); + +#endif /* GL_ATI_blend_equation_separate */ + + +/* GL_OES_EGL_image */ +#if !defined(GL_OES_EGL_image) && !defined(GL_EXT_EGL_image_storage) +typedef void* GLeglImageOES; +#endif + +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GLAPI void APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* __gl_h_ */ diff --git a/irr/src/vendor/glext.h b/irr/src/vendor/glext.h new file mode 100644 index 000000000..480d4dada --- /dev/null +++ b/irr/src/vendor/glext.h @@ -0,0 +1,12912 @@ +#ifndef __gl_glext_h_ +#define __gl_glext_h_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright 2013-2020 The Khronos Group Inc. +** SPDX-License-Identifier: MIT +** +** This header is generated from the Khronos OpenGL / OpenGL ES XML +** API Registry. The current version of the Registry, generator scripts +** used to make the header, and the header can be found at +** https://github.com/KhronosGroup/OpenGL-Registry +*/ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +#define GL_GLEXT_VERSION 20231129 + +#include + +/* Generated C header for: + * API: gl + * Profile: compatibility + * Versions considered: .* + * Versions emitted: 1\.[2-9]|[234]\.[0-9] + * Default extensions included: gl + * Additional extensions included: _nomatch_^ + * Extensions removed: _nomatch_^ + */ + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_RESCALE_NORMAL 0x803A +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices); +GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif +#endif /* GL_VERSION_1_2 */ + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_CLAMP_TO_BORDER 0x812D +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +#define GL_MULTISAMPLE_BIT 0x20000000 +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, void *img); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum texture); +GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, void *img); +GLAPI void APIENTRY glClientActiveTexture (GLenum texture); +GLAPI void APIENTRY glMultiTexCoord1d (GLenum target, GLdouble s); +GLAPI void APIENTRY glMultiTexCoord1dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord1f (GLenum target, GLfloat s); +GLAPI void APIENTRY glMultiTexCoord1fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord1i (GLenum target, GLint s); +GLAPI void APIENTRY glMultiTexCoord1iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord1s (GLenum target, GLshort s); +GLAPI void APIENTRY glMultiTexCoord1sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord2d (GLenum target, GLdouble s, GLdouble t); +GLAPI void APIENTRY glMultiTexCoord2dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord2f (GLenum target, GLfloat s, GLfloat t); +GLAPI void APIENTRY glMultiTexCoord2fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord2i (GLenum target, GLint s, GLint t); +GLAPI void APIENTRY glMultiTexCoord2iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord2s (GLenum target, GLshort s, GLshort t); +GLAPI void APIENTRY glMultiTexCoord2sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord3d (GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void APIENTRY glMultiTexCoord3dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord3f (GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void APIENTRY glMultiTexCoord3fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord3i (GLenum target, GLint s, GLint t, GLint r); +GLAPI void APIENTRY glMultiTexCoord3iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord3s (GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void APIENTRY glMultiTexCoord3sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord4d (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void APIENTRY glMultiTexCoord4dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void APIENTRY glMultiTexCoord4fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord4i (GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void APIENTRY glMultiTexCoord4iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord4s (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void APIENTRY glMultiTexCoord4sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *m); +GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *m); +GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *m); +GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *m); +#endif +#endif /* GL_VERSION_1_3 */ + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_MIRRORED_REPEAT 0x8370 +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_GENERATE_MIPMAP 0x8191 +#define GL_GENERATE_MIPMAP_HINT 0x8192 +#define GL_FOG_COORDINATE_SOURCE 0x8450 +#define GL_FOG_COORDINATE 0x8451 +#define GL_FRAGMENT_DEPTH 0x8452 +#define GL_CURRENT_FOG_COORDINATE 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 +#define GL_FOG_COORDINATE_ARRAY 0x8457 +#define GL_COLOR_SUM 0x8458 +#define GL_CURRENT_SECONDARY_COLOR 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D +#define GL_SECONDARY_COLOR_ARRAY 0x845E +#define GL_TEXTURE_FILTER_CONTROL 0x8500 +#define GL_DEPTH_TEXTURE_MODE 0x884B +#define GL_COMPARE_R_TO_TEXTURE 0x884E +#define GL_BLEND_COLOR 0x8005 +#define GL_BLEND_EQUATION 0x8009 +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_FUNC_ADD 0x8006 +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#define GL_FUNC_SUBTRACT 0x800A +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount); +GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); +GLAPI void APIENTRY glFogCoordf (GLfloat coord); +GLAPI void APIENTRY glFogCoordfv (const GLfloat *coord); +GLAPI void APIENTRY glFogCoordd (GLdouble coord); +GLAPI void APIENTRY glFogCoorddv (const GLdouble *coord); +GLAPI void APIENTRY glFogCoordPointer (GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glSecondaryColor3b (GLbyte red, GLbyte green, GLbyte blue); +GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *v); +GLAPI void APIENTRY glSecondaryColor3d (GLdouble red, GLdouble green, GLdouble blue); +GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *v); +GLAPI void APIENTRY glSecondaryColor3f (GLfloat red, GLfloat green, GLfloat blue); +GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *v); +GLAPI void APIENTRY glSecondaryColor3i (GLint red, GLint green, GLint blue); +GLAPI void APIENTRY glSecondaryColor3iv (const GLint *v); +GLAPI void APIENTRY glSecondaryColor3s (GLshort red, GLshort green, GLshort blue); +GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *v); +GLAPI void APIENTRY glSecondaryColor3ub (GLubyte red, GLubyte green, GLubyte blue); +GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *v); +GLAPI void APIENTRY glSecondaryColor3ui (GLuint red, GLuint green, GLuint blue); +GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *v); +GLAPI void APIENTRY glSecondaryColor3us (GLushort red, GLushort green, GLushort blue); +GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *v); +GLAPI void APIENTRY glSecondaryColorPointer (GLint size, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glWindowPos2d (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dv (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2f (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fv (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2i (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2iv (const GLint *v); +GLAPI void APIENTRY glWindowPos2s (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2sv (const GLshort *v); +GLAPI void APIENTRY glWindowPos3d (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dv (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3f (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fv (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3i (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3iv (const GLint *v); +GLAPI void APIENTRY glWindowPos3s (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3sv (const GLshort *v); +GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GLAPI void APIENTRY glBlendEquation (GLenum mode); +#endif +#endif /* GL_VERSION_1_4 */ + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +typedef khronos_ssize_t GLsizeiptr; +typedef khronos_intptr_t GLintptr; +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#define GL_SRC1_ALPHA 0x8589 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_FOG_COORD_SRC 0x8450 +#define GL_FOG_COORD 0x8451 +#define GL_CURRENT_FOG_COORD 0x8453 +#define GL_FOG_COORD_ARRAY_TYPE 0x8454 +#define GL_FOG_COORD_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORD_ARRAY_POINTER 0x8456 +#define GL_FOG_COORD_ARRAY 0x8457 +#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC2_ALPHA 0x858A +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, void *data); +typedef void *(APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, void **params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQuery (GLuint id); +GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQuery (GLenum target); +GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params); +GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer); +GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage); +GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); +GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, void *data); +GLAPI void *APIENTRY glMapBuffer (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, void **params); +#endif +#endif /* GL_VERSION_1_5 */ + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +typedef char GLchar; +#define GL_BLEND_EQUATION_RGB 0x8009 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_MAX_VARYING_FLOATS 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_SHADER_TYPE 0x8B4F +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_1D 0x8B5D +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_CUBE 0x8B60 +#define GL_SAMPLER_1D_SHADOW 0x8B61 +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_DELETE_STATUS 0x8B80 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 +#define GL_POINT_SPRITE 0x8861 +#define GL_COORD_REPLACE 0x8862 +#define GL_MAX_TEXTURE_COORDS 0x8871 +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name); +GLAPI void APIENTRY glCompileShader (GLuint shader); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum type); +GLAPI void APIENTRY glDeleteProgram (GLuint program); +GLAPI void APIENTRY glDeleteShader (GLuint shader); +GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer); +GLAPI GLboolean APIENTRY glIsProgram (GLuint program); +GLAPI GLboolean APIENTRY glIsShader (GLuint shader); +GLAPI void APIENTRY glLinkProgram (GLuint program); +GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); +GLAPI void APIENTRY glUseProgram (GLuint program); +GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glValidateProgram (GLuint program); +GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); +#endif +#endif /* GL_VERSION_2_0 */ + +#ifndef GL_VERSION_2_1 +#define GL_VERSION_2_1 1 +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_FLOAT_MAT2x3 0x8B65 +#define GL_FLOAT_MAT2x4 0x8B66 +#define GL_FLOAT_MAT3x2 0x8B67 +#define GL_FLOAT_MAT3x4 0x8B68 +#define GL_FLOAT_MAT4x2 0x8B69 +#define GL_FLOAT_MAT4x3 0x8B6A +#define GL_SRGB 0x8C40 +#define GL_SRGB8 0x8C41 +#define GL_SRGB_ALPHA 0x8C42 +#define GL_SRGB8_ALPHA8 0x8C43 +#define GL_COMPRESSED_SRGB 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 +#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F +#define GL_SLUMINANCE_ALPHA 0x8C44 +#define GL_SLUMINANCE8_ALPHA8 0x8C45 +#define GL_SLUMINANCE 0x8C46 +#define GL_SLUMINANCE8 0x8C47 +#define GL_COMPRESSED_SLUMINANCE 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif +#endif /* GL_VERSION_2_1 */ + +#ifndef GL_VERSION_3_0 +#define GL_VERSION_3_0 1 +typedef khronos_uint16_t GLhalf; +#define GL_COMPARE_REF_TO_TEXTURE 0x884E +#define GL_CLIP_DISTANCE0 0x3000 +#define GL_CLIP_DISTANCE1 0x3001 +#define GL_CLIP_DISTANCE2 0x3002 +#define GL_CLIP_DISTANCE3 0x3003 +#define GL_CLIP_DISTANCE4 0x3004 +#define GL_CLIP_DISTANCE5 0x3005 +#define GL_CLIP_DISTANCE6 0x3006 +#define GL_CLIP_DISTANCE7 0x3007 +#define GL_MAX_CLIP_DISTANCES 0x0D32 +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_NUM_EXTENSIONS 0x821D +#define GL_CONTEXT_FLAGS 0x821E +#define GL_COMPRESSED_RED 0x8225 +#define GL_COMPRESSED_RG 0x8226 +#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001 +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD +#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF +#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 +#define GL_CLAMP_READ_COLOR 0x891C +#define GL_FIXED_ONLY 0x891D +#define GL_MAX_VARYING_COMPONENTS 0x8B4B +#define GL_TEXTURE_1D_ARRAY 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 +#define GL_TEXTURE_2D_ARRAY 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_R11F_G11F_B10F 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B +#define GL_RGB9_E5 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E +#define GL_TEXTURE_SHARED_SIZE 0x8C3F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 +#define GL_PRIMITIVES_GENERATED 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 +#define GL_RASTERIZER_DISCARD 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B +#define GL_INTERLEAVED_ATTRIBS 0x8C8C +#define GL_SEPARATE_ATTRIBS 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F +#define GL_RGBA32UI 0x8D70 +#define GL_RGB32UI 0x8D71 +#define GL_RGBA16UI 0x8D76 +#define GL_RGB16UI 0x8D77 +#define GL_RGBA8UI 0x8D7C +#define GL_RGB8UI 0x8D7D +#define GL_RGBA32I 0x8D82 +#define GL_RGB32I 0x8D83 +#define GL_RGBA16I 0x8D88 +#define GL_RGB16I 0x8D89 +#define GL_RGBA8I 0x8D8E +#define GL_RGB8I 0x8D8F +#define GL_RED_INTEGER 0x8D94 +#define GL_GREEN_INTEGER 0x8D95 +#define GL_BLUE_INTEGER 0x8D96 +#define GL_RGB_INTEGER 0x8D98 +#define GL_RGBA_INTEGER 0x8D99 +#define GL_BGR_INTEGER 0x8D9A +#define GL_BGRA_INTEGER 0x8D9B +#define GL_SAMPLER_1D_ARRAY 0x8DC0 +#define GL_SAMPLER_2D_ARRAY 0x8DC1 +#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 +#define GL_UNSIGNED_INT_VEC2 0x8DC6 +#define GL_UNSIGNED_INT_VEC3 0x8DC7 +#define GL_UNSIGNED_INT_VEC4 0x8DC8 +#define GL_INT_SAMPLER_1D 0x8DC9 +#define GL_INT_SAMPLER_2D 0x8DCA +#define GL_INT_SAMPLER_3D 0x8DCB +#define GL_INT_SAMPLER_CUBE 0x8DCC +#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#define GL_QUERY_WAIT 0x8E13 +#define GL_QUERY_NO_WAIT 0x8E14 +#define GL_QUERY_BY_REGION_WAIT 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE 0x88F1 +#define GL_TEXTURE_RED_TYPE 0x8C10 +#define GL_TEXTURE_GREEN_TYPE 0x8C11 +#define GL_TEXTURE_BLUE_TYPE 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE 0x8C13 +#define GL_TEXTURE_DEPTH_TYPE 0x8C16 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_DRAW_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_COLOR_ATTACHMENT16 0x8CF0 +#define GL_COLOR_ATTACHMENT17 0x8CF1 +#define GL_COLOR_ATTACHMENT18 0x8CF2 +#define GL_COLOR_ATTACHMENT19 0x8CF3 +#define GL_COLOR_ATTACHMENT20 0x8CF4 +#define GL_COLOR_ATTACHMENT21 0x8CF5 +#define GL_COLOR_ATTACHMENT22 0x8CF6 +#define GL_COLOR_ATTACHMENT23 0x8CF7 +#define GL_COLOR_ATTACHMENT24 0x8CF8 +#define GL_COLOR_ATTACHMENT25 0x8CF9 +#define GL_COLOR_ATTACHMENT26 0x8CFA +#define GL_COLOR_ATTACHMENT27 0x8CFB +#define GL_COLOR_ATTACHMENT28 0x8CFC +#define GL_COLOR_ATTACHMENT29 0x8CFD +#define GL_COLOR_ATTACHMENT30 0x8CFE +#define GL_COLOR_ATTACHMENT31 0x8CFF +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_STENCIL_INDEX1 0x8D46 +#define GL_STENCIL_INDEX4 0x8D47 +#define GL_STENCIL_INDEX8 0x8D48 +#define GL_STENCIL_INDEX16 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#define GL_INDEX 0x8222 +#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE 0x8C15 +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#define GL_HALF_FLOAT 0x140B +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#define GL_COMPRESSED_RED_RGTC1 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC +#define GL_COMPRESSED_RG_RGTC2 0x8DBD +#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE +#define GL_RG 0x8227 +#define GL_RG_INTEGER 0x8228 +#define GL_R8 0x8229 +#define GL_R16 0x822A +#define GL_RG8 0x822B +#define GL_RG16 0x822C +#define GL_R16F 0x822D +#define GL_R32F 0x822E +#define GL_RG16F 0x822F +#define GL_RG32F 0x8230 +#define GL_R8I 0x8231 +#define GL_R8UI 0x8232 +#define GL_R16I 0x8233 +#define GL_R16UI 0x8234 +#define GL_R32I 0x8235 +#define GL_R32UI 0x8236 +#define GL_RG8I 0x8237 +#define GL_RG8UI 0x8238 +#define GL_RG16I 0x8239 +#define GL_RG16UI 0x823A +#define GL_RG32I 0x823B +#define GL_RG32UI 0x823C +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#define GL_CLAMP_VERTEX_COLOR 0x891A +#define GL_CLAMP_FRAGMENT_COLOR 0x891B +#define GL_ALPHA_INTEGER 0x8D97 +typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void *(APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glEnablei (GLenum target, GLuint index); +GLAPI void APIENTRY glDisablei (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index); +GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedback (void); +GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp); +GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRender (void); +GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params); +GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value); +GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value); +GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); +GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index); +GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmap (GLenum target); +GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void *APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glBindVertexArray (GLuint array); +GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); +#endif +#endif /* GL_VERSION_3_0 */ + +#ifndef GL_VERSION_3_1 +#define GL_VERSION_3_1 1 +#define GL_SAMPLER_2D_RECT 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 +#define GL_SAMPLER_BUFFER 0x8DC2 +#define GL_INT_SAMPLER_2D_RECT 0x8DCD +#define GL_INT_SAMPLER_BUFFER 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 +#define GL_TEXTURE_BUFFER 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D +#define GL_TEXTURE_RECTANGLE 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 +#define GL_R8_SNORM 0x8F94 +#define GL_RG8_SNORM 0x8F95 +#define GL_RGB8_SNORM 0x8F96 +#define GL_RGBA8_SNORM 0x8F97 +#define GL_R16_SNORM 0x8F98 +#define GL_RG16_SNORM 0x8F99 +#define GL_RGB16_SNORM 0x8F9A +#define GL_RGBA16_SNORM 0x8F9B +#define GL_SIGNED_NORMALIZED 0x8F9C +#define GL_PRIMITIVE_RESTART 0x8F9D +#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E +#define GL_COPY_READ_BUFFER 0x8F36 +#define GL_COPY_WRITE_BUFFER 0x8F37 +#define GL_UNIFORM_BUFFER 0x8A11 +#define GL_UNIFORM_BUFFER_BINDING 0x8A28 +#define GL_UNIFORM_BUFFER_START 0x8A29 +#define GL_UNIFORM_BUFFER_SIZE 0x8A2A +#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B +#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C +#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D +#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E +#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F +#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 +#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 +#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 +#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 +#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 +#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 +#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 +#define GL_UNIFORM_TYPE 0x8A37 +#define GL_UNIFORM_SIZE 0x8A38 +#define GL_UNIFORM_NAME_LENGTH 0x8A39 +#define GL_UNIFORM_BLOCK_INDEX 0x8A3A +#define GL_UNIFORM_OFFSET 0x8A3B +#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C +#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D +#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E +#define GL_UNIFORM_BLOCK_BINDING 0x8A3F +#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 +#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 +#define GL_INVALID_INDEX 0xFFFFFFFFu +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount); +typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); +typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount); +GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); +GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices); +GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName); +GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif +#endif /* GL_VERSION_3_1 */ + +#ifndef GL_VERSION_3_2 +#define GL_VERSION_3_2 1 +typedef struct __GLsync *GLsync; +typedef khronos_uint64_t GLuint64; +typedef khronos_int64_t GLint64; +#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_LINES_ADJACENCY 0x000A +#define GL_LINE_STRIP_ADJACENCY 0x000B +#define GL_TRIANGLES_ADJACENCY 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D +#define GL_PROGRAM_POINT_SIZE 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 +#define GL_GEOMETRY_SHADER 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT 0x8916 +#define GL_GEOMETRY_INPUT_TYPE 0x8917 +#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 +#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 +#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 +#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 +#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 +#define GL_CONTEXT_PROFILE_MASK 0x9126 +#define GL_DEPTH_CLAMP 0x864F +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION 0x8E4D +#define GL_LAST_VERTEX_CONVENTION 0x8E4E +#define GL_PROVOKING_VERTEX 0x8E4F +#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_SAMPLE_POSITION 0x8E50 +#define GL_SAMPLE_MASK 0x8E51 +#define GL_SAMPLE_MASK_VALUE 0x8E52 +#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 +#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 +#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 +#define GL_TEXTURE_SAMPLES 0x9106 +#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 +#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 +#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A +#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B +#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D +#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E +#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F +#define GL_MAX_INTEGER_SAMPLES 0x9110 +typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount, const GLint *basevertex); +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); +typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); +typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); +typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *data); +typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei count, GLsizei *length, GLint *values); +typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint maskNumber, GLbitfield mask); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); +GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount, const GLint *basevertex); +GLAPI void APIENTRY glProvokingVertex (GLenum mode); +GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GLAPI GLboolean APIENTRY glIsSync (GLsync sync); +GLAPI void APIENTRY glDeleteSync (GLsync sync); +GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *data); +GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei count, GLsizei *length, GLint *values); +GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); +GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaski (GLuint maskNumber, GLbitfield mask); +#endif +#endif /* GL_VERSION_3_2 */ + +#ifndef GL_VERSION_3_3 +#define GL_VERSION_3_3 1 +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE +#define GL_SRC1_COLOR 0x88F9 +#define GL_ONE_MINUS_SRC1_COLOR 0x88FA +#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB +#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC +#define GL_ANY_SAMPLES_PASSED 0x8C2F +#define GL_SAMPLER_BINDING 0x8919 +#define GL_RGB10_A2UI 0x906F +#define GL_TEXTURE_SWIZZLE_R 0x8E42 +#define GL_TEXTURE_SWIZZLE_G 0x8E43 +#define GL_TEXTURE_SWIZZLE_B 0x8E44 +#define GL_TEXTURE_SWIZZLE_A 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 +#define GL_TIME_ELAPSED 0x88BF +#define GL_TIMESTAMP 0x8E28 +#define GL_INT_2_10_10_10_REV 0x8D9F +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); +typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); +typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); +typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); +GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); +GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); +GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); +GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); +GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); +GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param); +GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); +GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); +GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); +GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); +GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color); +#endif +#endif /* GL_VERSION_3_3 */ + +#ifndef GL_VERSION_4_0 +#define GL_VERSION_4_0 1 +#define GL_SAMPLE_SHADING 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F +#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F +#define GL_DRAW_INDIRECT_BUFFER 0x8F3F +#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 +#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F +#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A +#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B +#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C +#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D +#define GL_MAX_VERTEX_STREAMS 0x8E71 +#define GL_DOUBLE_VEC2 0x8FFC +#define GL_DOUBLE_VEC3 0x8FFD +#define GL_DOUBLE_VEC4 0x8FFE +#define GL_DOUBLE_MAT2 0x8F46 +#define GL_DOUBLE_MAT3 0x8F47 +#define GL_DOUBLE_MAT4 0x8F48 +#define GL_DOUBLE_MAT2x3 0x8F49 +#define GL_DOUBLE_MAT2x4 0x8F4A +#define GL_DOUBLE_MAT3x2 0x8F4B +#define GL_DOUBLE_MAT3x4 0x8F4C +#define GL_DOUBLE_MAT4x2 0x8F4D +#define GL_DOUBLE_MAT4x3 0x8F4E +#define GL_ACTIVE_SUBROUTINES 0x8DE5 +#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47 +#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49 +#define GL_MAX_SUBROUTINES 0x8DE7 +#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8 +#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A +#define GL_COMPATIBLE_SUBROUTINES 0x8E4B +#define GL_PATCHES 0x000E +#define GL_PATCH_VERTICES 0x8E72 +#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 +#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74 +#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75 +#define GL_TESS_GEN_MODE 0x8E76 +#define GL_TESS_GEN_SPACING 0x8E77 +#define GL_TESS_GEN_VERTEX_ORDER 0x8E78 +#define GL_TESS_GEN_POINT_MODE 0x8E79 +#define GL_ISOLINES 0x8E7A +#define GL_FRACTIONAL_ODD 0x8E7B +#define GL_FRACTIONAL_EVEN 0x8E7C +#define GL_MAX_PATCH_VERTICES 0x8E7D +#define GL_MAX_TESS_GEN_LEVEL 0x8E7E +#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F +#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80 +#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81 +#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82 +#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83 +#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84 +#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85 +#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86 +#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89 +#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A +#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C +#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D +#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E +#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1 +#define GL_TESS_EVALUATION_SHADER 0x8E87 +#define GL_TESS_CONTROL_SHADER 0x8E88 +#define GL_TRANSFORM_FEEDBACK 0x8E22 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 +#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value); +typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect); +typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params); +typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices); +typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); +typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMinSampleShading (GLfloat value); +GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const void *indirect); +GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect); +GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); +GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); +GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); +GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); +GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); +GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); +GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedback (void); +GLAPI void APIENTRY glResumeTransformFeedback (void); +GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); +GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); +GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); +GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); +GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif +#endif /* GL_VERSION_4_0 */ + +#ifndef GL_VERSION_4_1 +#define GL_VERSION_4_1 1 +#define GL_FIXED 0x140C +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 +#define GL_SHADER_COMPILER 0x8DFA +#define GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_RGB565 0x8D62 +#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 +#define GL_PROGRAM_BINARY_LENGTH 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE +#define GL_PROGRAM_BINARY_FORMATS 0x87FF +#define GL_VERTEX_SHADER_BIT 0x00000001 +#define GL_FRAGMENT_SHADER_BIT 0x00000002 +#define GL_GEOMETRY_SHADER_BIT 0x00000004 +#define GL_TESS_CONTROL_SHADER_BIT 0x00000008 +#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010 +#define GL_ALL_SHADER_BITS 0xFFFFFFFF +#define GL_PROGRAM_SEPARABLE 0x8258 +#define GL_ACTIVE_PROGRAM 0x8259 +#define GL_PROGRAM_PIPELINE_BINDING 0x825A +#define GL_MAX_VIEWPORTS 0x825B +#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C +#define GL_VIEWPORT_BOUNDS_RANGE 0x825D +#define GL_LAYER_PROVOKING_VERTEX 0x825E +#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F +#define GL_UNDEFINED_VERTEX 0x8260 +typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); +typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryFormat, const void *binary, GLsizei length); +typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f); +typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d); +typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary); +typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const void *binary, GLsizei length); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); +typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar *const*strings); +typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines); +typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLdouble n, GLdouble f); +typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReleaseShaderCompiler (void); +GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryFormat, const void *binary, GLsizei length); +GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f); +GLAPI void APIENTRY glClearDepthf (GLfloat d); +GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary); +GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const void *binary, GLsizei length); +GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); +GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); +GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar *const*strings); +GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines); +GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines); +GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params); +GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0); +GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1); +GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v); +GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v); +GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f); +GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); +#endif +#endif /* GL_VERSION_4_1 */ + +#ifndef GL_VERSION_4_2 +#define GL_VERSION_4_2 1 +#define GL_COPY_READ_BUFFER_BINDING 0x8F36 +#define GL_COPY_WRITE_BUFFER_BINDING 0x8F37 +#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 +#define GL_UNPACK_COMPRESSED_BLOCK_WIDTH 0x9127 +#define GL_UNPACK_COMPRESSED_BLOCK_HEIGHT 0x9128 +#define GL_UNPACK_COMPRESSED_BLOCK_DEPTH 0x9129 +#define GL_UNPACK_COMPRESSED_BLOCK_SIZE 0x912A +#define GL_PACK_COMPRESSED_BLOCK_WIDTH 0x912B +#define GL_PACK_COMPRESSED_BLOCK_HEIGHT 0x912C +#define GL_PACK_COMPRESSED_BLOCK_DEPTH 0x912D +#define GL_PACK_COMPRESSED_BLOCK_SIZE 0x912E +#define GL_NUM_SAMPLE_COUNTS 0x9380 +#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC +#define GL_ATOMIC_COUNTER_BUFFER 0x92C0 +#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1 +#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2 +#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3 +#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB +#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE +#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF +#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0 +#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1 +#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2 +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3 +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4 +#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5 +#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6 +#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC +#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9 +#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA +#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB +#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001 +#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002 +#define GL_UNIFORM_BARRIER_BIT 0x00000004 +#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008 +#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020 +#define GL_COMMAND_BARRIER_BIT 0x00000040 +#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080 +#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100 +#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200 +#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400 +#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800 +#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000 +#define GL_ALL_BARRIER_BITS 0xFFFFFFFF +#define GL_MAX_IMAGE_UNITS 0x8F38 +#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39 +#define GL_IMAGE_BINDING_NAME 0x8F3A +#define GL_IMAGE_BINDING_LEVEL 0x8F3B +#define GL_IMAGE_BINDING_LAYERED 0x8F3C +#define GL_IMAGE_BINDING_LAYER 0x8F3D +#define GL_IMAGE_BINDING_ACCESS 0x8F3E +#define GL_IMAGE_1D 0x904C +#define GL_IMAGE_2D 0x904D +#define GL_IMAGE_3D 0x904E +#define GL_IMAGE_2D_RECT 0x904F +#define GL_IMAGE_CUBE 0x9050 +#define GL_IMAGE_BUFFER 0x9051 +#define GL_IMAGE_1D_ARRAY 0x9052 +#define GL_IMAGE_2D_ARRAY 0x9053 +#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054 +#define GL_IMAGE_2D_MULTISAMPLE 0x9055 +#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056 +#define GL_INT_IMAGE_1D 0x9057 +#define GL_INT_IMAGE_2D 0x9058 +#define GL_INT_IMAGE_3D 0x9059 +#define GL_INT_IMAGE_2D_RECT 0x905A +#define GL_INT_IMAGE_CUBE 0x905B +#define GL_INT_IMAGE_BUFFER 0x905C +#define GL_INT_IMAGE_1D_ARRAY 0x905D +#define GL_INT_IMAGE_2D_ARRAY 0x905E +#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F +#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060 +#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061 +#define GL_UNSIGNED_INT_IMAGE_1D 0x9062 +#define GL_UNSIGNED_INT_IMAGE_2D 0x9063 +#define GL_UNSIGNED_INT_IMAGE_3D 0x9064 +#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065 +#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066 +#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067 +#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068 +#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069 +#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C +#define GL_MAX_IMAGE_SAMPLES 0x906D +#define GL_IMAGE_BINDING_FORMAT 0x906E +#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7 +#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8 +#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9 +#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA +#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB +#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC +#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD +#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE +#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF +#define GL_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C +#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D +#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E +#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F +#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); +typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei count, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); +typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); +typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); +GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei count, GLint *params); +GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); +GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); +GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers); +GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount); +GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); +#endif +#endif /* GL_VERSION_4_2 */ + +#ifndef GL_VERSION_4_3 +#define GL_VERSION_4_3 1 +typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); +#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9 +#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E +#define GL_COMPRESSED_RGB8_ETC2 0x9274 +#define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 +#define GL_COMPRESSED_R11_EAC 0x9270 +#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define GL_COMPRESSED_RG11_EAC 0x9272 +#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A +#define GL_MAX_ELEMENT_INDEX 0x8D6B +#define GL_COMPUTE_SHADER 0x91B9 +#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB +#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC +#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD +#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262 +#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263 +#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264 +#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265 +#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266 +#define GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS 0x90EB +#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE +#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF +#define GL_COMPUTE_WORK_GROUP_SIZE 0x8267 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED +#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE +#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF +#define GL_COMPUTE_SHADER_BIT 0x00000020 +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES 0x9145 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 +#define GL_DEBUG_TYPE_POP_GROUP 0x826A +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C +#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D +#define GL_BUFFER 0x82E0 +#define GL_SHADER 0x82E1 +#define GL_PROGRAM 0x82E2 +#define GL_QUERY 0x82E3 +#define GL_PROGRAM_PIPELINE 0x82E4 +#define GL_SAMPLER 0x82E6 +#define GL_MAX_LABEL_LENGTH 0x82E8 +#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 +#define GL_MAX_UNIFORM_LOCATIONS 0x826E +#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310 +#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311 +#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312 +#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313 +#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314 +#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315 +#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316 +#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317 +#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318 +#define GL_INTERNALFORMAT_SUPPORTED 0x826F +#define GL_INTERNALFORMAT_PREFERRED 0x8270 +#define GL_INTERNALFORMAT_RED_SIZE 0x8271 +#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272 +#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273 +#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274 +#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275 +#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276 +#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277 +#define GL_INTERNALFORMAT_RED_TYPE 0x8278 +#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279 +#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A +#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B +#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C +#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D +#define GL_MAX_WIDTH 0x827E +#define GL_MAX_HEIGHT 0x827F +#define GL_MAX_DEPTH 0x8280 +#define GL_MAX_LAYERS 0x8281 +#define GL_MAX_COMBINED_DIMENSIONS 0x8282 +#define GL_COLOR_COMPONENTS 0x8283 +#define GL_DEPTH_COMPONENTS 0x8284 +#define GL_STENCIL_COMPONENTS 0x8285 +#define GL_COLOR_RENDERABLE 0x8286 +#define GL_DEPTH_RENDERABLE 0x8287 +#define GL_STENCIL_RENDERABLE 0x8288 +#define GL_FRAMEBUFFER_RENDERABLE 0x8289 +#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A +#define GL_FRAMEBUFFER_BLEND 0x828B +#define GL_READ_PIXELS 0x828C +#define GL_READ_PIXELS_FORMAT 0x828D +#define GL_READ_PIXELS_TYPE 0x828E +#define GL_TEXTURE_IMAGE_FORMAT 0x828F +#define GL_TEXTURE_IMAGE_TYPE 0x8290 +#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291 +#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292 +#define GL_MIPMAP 0x8293 +#define GL_MANUAL_GENERATE_MIPMAP 0x8294 +#define GL_AUTO_GENERATE_MIPMAP 0x8295 +#define GL_COLOR_ENCODING 0x8296 +#define GL_SRGB_READ 0x8297 +#define GL_SRGB_WRITE 0x8298 +#define GL_FILTER 0x829A +#define GL_VERTEX_TEXTURE 0x829B +#define GL_TESS_CONTROL_TEXTURE 0x829C +#define GL_TESS_EVALUATION_TEXTURE 0x829D +#define GL_GEOMETRY_TEXTURE 0x829E +#define GL_FRAGMENT_TEXTURE 0x829F +#define GL_COMPUTE_TEXTURE 0x82A0 +#define GL_TEXTURE_SHADOW 0x82A1 +#define GL_TEXTURE_GATHER 0x82A2 +#define GL_TEXTURE_GATHER_SHADOW 0x82A3 +#define GL_SHADER_IMAGE_LOAD 0x82A4 +#define GL_SHADER_IMAGE_STORE 0x82A5 +#define GL_SHADER_IMAGE_ATOMIC 0x82A6 +#define GL_IMAGE_TEXEL_SIZE 0x82A7 +#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8 +#define GL_IMAGE_PIXEL_FORMAT 0x82A9 +#define GL_IMAGE_PIXEL_TYPE 0x82AA +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF +#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1 +#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2 +#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3 +#define GL_CLEAR_BUFFER 0x82B4 +#define GL_TEXTURE_VIEW 0x82B5 +#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6 +#define GL_FULL_SUPPORT 0x82B7 +#define GL_CAVEAT_SUPPORT 0x82B8 +#define GL_IMAGE_CLASS_4_X_32 0x82B9 +#define GL_IMAGE_CLASS_2_X_32 0x82BA +#define GL_IMAGE_CLASS_1_X_32 0x82BB +#define GL_IMAGE_CLASS_4_X_16 0x82BC +#define GL_IMAGE_CLASS_2_X_16 0x82BD +#define GL_IMAGE_CLASS_1_X_16 0x82BE +#define GL_IMAGE_CLASS_4_X_8 0x82BF +#define GL_IMAGE_CLASS_2_X_8 0x82C0 +#define GL_IMAGE_CLASS_1_X_8 0x82C1 +#define GL_IMAGE_CLASS_11_11_10 0x82C2 +#define GL_IMAGE_CLASS_10_10_10_2 0x82C3 +#define GL_VIEW_CLASS_128_BITS 0x82C4 +#define GL_VIEW_CLASS_96_BITS 0x82C5 +#define GL_VIEW_CLASS_64_BITS 0x82C6 +#define GL_VIEW_CLASS_48_BITS 0x82C7 +#define GL_VIEW_CLASS_32_BITS 0x82C8 +#define GL_VIEW_CLASS_24_BITS 0x82C9 +#define GL_VIEW_CLASS_16_BITS 0x82CA +#define GL_VIEW_CLASS_8_BITS 0x82CB +#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC +#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD +#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE +#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF +#define GL_VIEW_CLASS_RGTC1_RED 0x82D0 +#define GL_VIEW_CLASS_RGTC2_RG 0x82D1 +#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2 +#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3 +#define GL_UNIFORM 0x92E1 +#define GL_UNIFORM_BLOCK 0x92E2 +#define GL_PROGRAM_INPUT 0x92E3 +#define GL_PROGRAM_OUTPUT 0x92E4 +#define GL_BUFFER_VARIABLE 0x92E5 +#define GL_SHADER_STORAGE_BLOCK 0x92E6 +#define GL_VERTEX_SUBROUTINE 0x92E8 +#define GL_TESS_CONTROL_SUBROUTINE 0x92E9 +#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA +#define GL_GEOMETRY_SUBROUTINE 0x92EB +#define GL_FRAGMENT_SUBROUTINE 0x92EC +#define GL_COMPUTE_SUBROUTINE 0x92ED +#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE +#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF +#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0 +#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1 +#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2 +#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3 +#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4 +#define GL_ACTIVE_RESOURCES 0x92F5 +#define GL_MAX_NAME_LENGTH 0x92F6 +#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7 +#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8 +#define GL_NAME_LENGTH 0x92F9 +#define GL_TYPE 0x92FA +#define GL_ARRAY_SIZE 0x92FB +#define GL_OFFSET 0x92FC +#define GL_BLOCK_INDEX 0x92FD +#define GL_ARRAY_STRIDE 0x92FE +#define GL_MATRIX_STRIDE 0x92FF +#define GL_IS_ROW_MAJOR 0x9300 +#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301 +#define GL_BUFFER_BINDING 0x9302 +#define GL_BUFFER_DATA_SIZE 0x9303 +#define GL_NUM_ACTIVE_VARIABLES 0x9304 +#define GL_ACTIVE_VARIABLES 0x9305 +#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306 +#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307 +#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308 +#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309 +#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A +#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B +#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C +#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D +#define GL_LOCATION 0x930E +#define GL_LOCATION_INDEX 0x930F +#define GL_IS_PER_PATCH 0x92E7 +#define GL_SHADER_STORAGE_BUFFER 0x90D2 +#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3 +#define GL_SHADER_STORAGE_BUFFER_START 0x90D4 +#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5 +#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6 +#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7 +#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8 +#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9 +#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA +#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB +#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC +#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD +#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE +#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF +#define GL_SHADER_STORAGE_BARRIER_BIT 0x00002000 +#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES 0x8F39 +#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA +#define GL_TEXTURE_BUFFER_OFFSET 0x919D +#define GL_TEXTURE_BUFFER_SIZE 0x919E +#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F +#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB +#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC +#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD +#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF +#define GL_VERTEX_ATTRIB_BINDING 0x82D4 +#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 +#define GL_VERTEX_BINDING_DIVISOR 0x82D6 +#define GL_VERTEX_BINDING_OFFSET 0x82D7 +#define GL_VERTEX_BINDING_STRIDE 0x82D8 +#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9 +#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA +#define GL_VERTEX_BINDING_BUFFER 0x8F4F +#define GL_DISPLAY_LIST 0x82E7 +typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei count, GLint64 *params); +typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei count, GLsizei *length, GLint *params); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); +typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); +typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect); +GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei count, GLint64 *params); +GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level); +GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer); +GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments); +GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei count, GLsizei *length, GLint *params); +GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor); +GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); +GLAPI void APIENTRY glPopDebugGroup (void); +GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif +#endif /* GL_VERSION_4_3 */ + +#ifndef GL_VERSION_4_4 +#define GL_VERSION_4_4 1 +#define GL_MAX_VERTEX_ATTRIB_STRIDE 0x82E5 +#define GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED 0x8221 +#define GL_TEXTURE_BUFFER_BINDING 0x8C2A +#define GL_MAP_PERSISTENT_BIT 0x0040 +#define GL_MAP_COHERENT_BIT 0x0080 +#define GL_DYNAMIC_STORAGE_BIT 0x0100 +#define GL_CLIENT_STORAGE_BIT 0x0200 +#define GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT 0x00004000 +#define GL_BUFFER_IMMUTABLE_STORAGE 0x821F +#define GL_BUFFER_STORAGE_FLAGS 0x8220 +#define GL_CLEAR_TEXTURE 0x9365 +#define GL_LOCATION_COMPONENT 0x934A +#define GL_TRANSFORM_FEEDBACK_BUFFER_INDEX 0x934B +#define GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE 0x934C +#define GL_QUERY_BUFFER 0x9192 +#define GL_QUERY_BUFFER_BARRIER_BIT 0x00008000 +#define GL_QUERY_BUFFER_BINDING 0x9193 +#define GL_QUERY_RESULT_NO_WAIT 0x9194 +#define GL_MIRROR_CLAMP_TO_EDGE 0x8743 +typedef void (APIENTRYP PFNGLBUFFERSTORAGEPROC) (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags); +typedef void (APIENTRYP PFNGLCLEARTEXIMAGEPROC) (GLuint texture, GLint level, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARTEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLBINDBUFFERSBASEPROC) (GLenum target, GLuint first, GLsizei count, const GLuint *buffers); +typedef void (APIENTRYP PFNGLBINDBUFFERSRANGEPROC) (GLenum target, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizeiptr *sizes); +typedef void (APIENTRYP PFNGLBINDTEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures); +typedef void (APIENTRYP PFNGLBINDSAMPLERSPROC) (GLuint first, GLsizei count, const GLuint *samplers); +typedef void (APIENTRYP PFNGLBINDIMAGETEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures); +typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERSPROC) (GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferStorage (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags); +GLAPI void APIENTRY glClearTexImage (GLuint texture, GLint level, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glBindBuffersBase (GLenum target, GLuint first, GLsizei count, const GLuint *buffers); +GLAPI void APIENTRY glBindBuffersRange (GLenum target, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizeiptr *sizes); +GLAPI void APIENTRY glBindTextures (GLuint first, GLsizei count, const GLuint *textures); +GLAPI void APIENTRY glBindSamplers (GLuint first, GLsizei count, const GLuint *samplers); +GLAPI void APIENTRY glBindImageTextures (GLuint first, GLsizei count, const GLuint *textures); +GLAPI void APIENTRY glBindVertexBuffers (GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides); +#endif +#endif /* GL_VERSION_4_4 */ + +#ifndef GL_VERSION_4_5 +#define GL_VERSION_4_5 1 +#define GL_CONTEXT_LOST 0x0507 +#define GL_NEGATIVE_ONE_TO_ONE 0x935E +#define GL_ZERO_TO_ONE 0x935F +#define GL_CLIP_ORIGIN 0x935C +#define GL_CLIP_DEPTH_MODE 0x935D +#define GL_QUERY_WAIT_INVERTED 0x8E17 +#define GL_QUERY_NO_WAIT_INVERTED 0x8E18 +#define GL_QUERY_BY_REGION_WAIT_INVERTED 0x8E19 +#define GL_QUERY_BY_REGION_NO_WAIT_INVERTED 0x8E1A +#define GL_MAX_CULL_DISTANCES 0x82F9 +#define GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES 0x82FA +#define GL_TEXTURE_TARGET 0x1006 +#define GL_QUERY_TARGET 0x82EA +#define GL_GUILTY_CONTEXT_RESET 0x8253 +#define GL_INNOCENT_CONTEXT_RESET 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET 0x8255 +#define GL_RESET_NOTIFICATION_STRATEGY 0x8256 +#define GL_LOSE_CONTEXT_ON_RESET 0x8252 +#define GL_NO_RESET_NOTIFICATION 0x8261 +#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT 0x00000004 +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_MINMAX 0x802E +#define GL_CONTEXT_RELEASE_BEHAVIOR 0x82FB +#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC +typedef void (APIENTRYP PFNGLCLIPCONTROLPROC) (GLenum origin, GLenum depth); +typedef void (APIENTRYP PFNGLCREATETRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKBUFFERBASEPROC) (GLuint xfb, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKBUFFERRANGEPROC) (GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKIVPROC) (GLuint xfb, GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param); +typedef void (APIENTRYP PFNGLCREATEBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSTORAGEPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags); +typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +typedef void (APIENTRYP PFNGLCOPYNAMEDBUFFERSUBDATAPROC) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAPROC) (GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFERPROC) (GLuint buffer, GLenum access); +typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFERRANGEPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERI64VPROC) (GLuint buffer, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVPROC) (GLuint buffer, GLenum pname, void **params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data); +typedef void (APIENTRYP PFNGLCREATEFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFERPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIPROC) (GLuint framebuffer, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYERPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERDRAWBUFFERPROC) (GLuint framebuffer, GLenum buf); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC) (GLuint framebuffer, GLenum src); +typedef void (APIENTRYP PFNGLINVALIDATENAMEDFRAMEBUFFERDATAPROC) (GLuint framebuffer, GLsizei numAttachments, const GLenum *attachments); +typedef void (APIENTRYP PFNGLINVALIDATENAMEDFRAMEBUFFERSUBDATAPROC) (GLuint framebuffer, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERIVPROC) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value); +typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERUIVPROC) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value); +typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERFVPROC) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value); +typedef void (APIENTRYP PFNGLCLEARNAMEDFRAMEBUFFERFIPROC) (GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +typedef void (APIENTRYP PFNGLBLITNAMEDFRAMEBUFFERPROC) (GLuint readFramebuffer, GLuint drawFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC) (GLuint framebuffer, GLenum target); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVPROC) (GLuint framebuffer, GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCREATERENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVPROC) (GLuint renderbuffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCREATETEXTURESPROC) (GLenum target, GLsizei n, GLuint *textures); +typedef void (APIENTRYP PFNGLTEXTUREBUFFERPROC) (GLuint texture, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEPROC) (GLuint texture, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DPROC) (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DPROC) (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DPROC) (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEPROC) (GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEPROC) (GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DPROC) (GLuint texture, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DPROC) (GLuint texture, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DPROC) (GLuint texture, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFPROC) (GLuint texture, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVPROC) (GLuint texture, GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIPROC) (GLuint texture, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVPROC) (GLuint texture, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVPROC) (GLuint texture, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVPROC) (GLuint texture, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLBINDTEXTUREUNITPROC) (GLuint unit, GLuint texture); +typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEPROC) (GLuint texture, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *pixels); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEPROC) (GLuint texture, GLint level, GLsizei bufSize, void *pixels); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVPROC) (GLuint texture, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVPROC) (GLuint texture, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVPROC) (GLuint texture, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVPROC) (GLuint texture, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVPROC) (GLuint texture, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVPROC) (GLuint texture, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCREATEVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); +typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYATTRIBPROC) (GLuint vaobj, GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYATTRIBPROC) (GLuint vaobj, GLuint index); +typedef void (APIENTRYP PFNGLVERTEXARRAYELEMENTBUFFERPROC) (GLuint vaobj, GLuint buffer); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBUFFERPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBUFFERSPROC) (GLuint vaobj, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides); +typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBBINDINGPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBFORMATPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBIFORMATPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYATTRIBLFORMATPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYBINDINGDIVISORPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); +typedef void (APIENTRYP PFNGLGETVERTEXARRAYIVPROC) (GLuint vaobj, GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETVERTEXARRAYINDEXEDIVPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETVERTEXARRAYINDEXED64IVPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint64 *param); +typedef void (APIENTRYP PFNGLCREATESAMPLERSPROC) (GLsizei n, GLuint *samplers); +typedef void (APIENTRYP PFNGLCREATEPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); +typedef void (APIENTRYP PFNGLCREATEQUERIESPROC) (GLenum target, GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTI64VPROC) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTIVPROC) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTUI64VPROC) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +typedef void (APIENTRYP PFNGLGETQUERYBUFFEROBJECTUIVPROC) (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +typedef void (APIENTRYP PFNGLMEMORYBARRIERBYREGIONPROC) (GLbitfield barriers); +typedef void (APIENTRYP PFNGLGETTEXTURESUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLsizei bufSize, void *pixels); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTURESUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei bufSize, void *pixels); +typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSPROC) (void); +typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint lod, GLsizei bufSize, void *pixels); +typedef void (APIENTRYP PFNGLGETNTEXIMAGEPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *pixels); +typedef void (APIENTRYP PFNGLGETNUNIFORMDVPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMFVPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMIVPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMUIVPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +typedef void (APIENTRYP PFNGLREADNPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +typedef void (APIENTRYP PFNGLGETNMAPDVPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +typedef void (APIENTRYP PFNGLGETNMAPFVPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +typedef void (APIENTRYP PFNGLGETNMAPIVPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +typedef void (APIENTRYP PFNGLGETNPIXELMAPFVPROC) (GLenum map, GLsizei bufSize, GLfloat *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVPROC) (GLenum map, GLsizei bufSize, GLuint *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVPROC) (GLenum map, GLsizei bufSize, GLushort *values); +typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEPROC) (GLsizei bufSize, GLubyte *pattern); +typedef void (APIENTRYP PFNGLGETNCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table); +typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image); +typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span); +typedef void (APIENTRYP PFNGLGETNHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +typedef void (APIENTRYP PFNGLGETNMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +typedef void (APIENTRYP PFNGLTEXTUREBARRIERPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClipControl (GLenum origin, GLenum depth); +GLAPI void APIENTRY glCreateTransformFeedbacks (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glTransformFeedbackBufferBase (GLuint xfb, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackBufferRange (GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glGetTransformFeedbackiv (GLuint xfb, GLenum pname, GLint *param); +GLAPI void APIENTRY glGetTransformFeedbacki_v (GLuint xfb, GLenum pname, GLuint index, GLint *param); +GLAPI void APIENTRY glGetTransformFeedbacki64_v (GLuint xfb, GLenum pname, GLuint index, GLint64 *param); +GLAPI void APIENTRY glCreateBuffers (GLsizei n, GLuint *buffers); +GLAPI void APIENTRY glNamedBufferStorage (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags); +GLAPI void APIENTRY glNamedBufferData (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage); +GLAPI void APIENTRY glNamedBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +GLAPI void APIENTRY glCopyNamedBufferSubData (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GLAPI void APIENTRY glClearNamedBufferData (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferSubData (GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +GLAPI void *APIENTRY glMapNamedBuffer (GLuint buffer, GLenum access); +GLAPI void *APIENTRY glMapNamedBufferRange (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI GLboolean APIENTRY glUnmapNamedBuffer (GLuint buffer); +GLAPI void APIENTRY glFlushMappedNamedBufferRange (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glGetNamedBufferParameteriv (GLuint buffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetNamedBufferParameteri64v (GLuint buffer, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetNamedBufferPointerv (GLuint buffer, GLenum pname, void **params); +GLAPI void APIENTRY glGetNamedBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data); +GLAPI void APIENTRY glCreateFramebuffers (GLsizei n, GLuint *framebuffers); +GLAPI void APIENTRY glNamedFramebufferRenderbuffer (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glNamedFramebufferParameteri (GLuint framebuffer, GLenum pname, GLint param); +GLAPI void APIENTRY glNamedFramebufferTexture (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTextureLayer (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glNamedFramebufferDrawBuffer (GLuint framebuffer, GLenum buf); +GLAPI void APIENTRY glNamedFramebufferDrawBuffers (GLuint framebuffer, GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glNamedFramebufferReadBuffer (GLuint framebuffer, GLenum src); +GLAPI void APIENTRY glInvalidateNamedFramebufferData (GLuint framebuffer, GLsizei numAttachments, const GLenum *attachments); +GLAPI void APIENTRY glInvalidateNamedFramebufferSubData (GLuint framebuffer, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glClearNamedFramebufferiv (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value); +GLAPI void APIENTRY glClearNamedFramebufferuiv (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value); +GLAPI void APIENTRY glClearNamedFramebufferfv (GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value); +GLAPI void APIENTRY glClearNamedFramebufferfi (GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GLAPI void APIENTRY glBlitNamedFramebuffer (GLuint readFramebuffer, GLuint drawFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI GLenum APIENTRY glCheckNamedFramebufferStatus (GLuint framebuffer, GLenum target); +GLAPI void APIENTRY glGetNamedFramebufferParameteriv (GLuint framebuffer, GLenum pname, GLint *param); +GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameteriv (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glCreateRenderbuffers (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glNamedRenderbufferStorage (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisample (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetNamedRenderbufferParameteriv (GLuint renderbuffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glCreateTextures (GLenum target, GLsizei n, GLuint *textures); +GLAPI void APIENTRY glTextureBuffer (GLuint texture, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glTextureBufferRange (GLuint texture, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glTextureStorage1D (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTextureStorage2D (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTextureStorage3D (GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glTextureStorage2DMultisample (GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage3DMultisample (GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureSubImage1D (GLuint texture, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTextureSubImage2D (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTextureSubImage3D (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glCompressedTextureSubImage1D (GLuint texture, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTextureSubImage2D (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTextureSubImage3D (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCopyTextureSubImage1D (GLuint texture, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTextureSubImage2D (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glCopyTextureSubImage3D (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTextureParameterf (GLuint texture, GLenum pname, GLfloat param); +GLAPI void APIENTRY glTextureParameterfv (GLuint texture, GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glTextureParameteri (GLuint texture, GLenum pname, GLint param); +GLAPI void APIENTRY glTextureParameterIiv (GLuint texture, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTextureParameterIuiv (GLuint texture, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glTextureParameteriv (GLuint texture, GLenum pname, const GLint *param); +GLAPI void APIENTRY glGenerateTextureMipmap (GLuint texture); +GLAPI void APIENTRY glBindTextureUnit (GLuint unit, GLuint texture); +GLAPI void APIENTRY glGetTextureImage (GLuint texture, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *pixels); +GLAPI void APIENTRY glGetCompressedTextureImage (GLuint texture, GLint level, GLsizei bufSize, void *pixels); +GLAPI void APIENTRY glGetTextureLevelParameterfv (GLuint texture, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureLevelParameteriv (GLuint texture, GLint level, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureParameterfv (GLuint texture, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureParameterIiv (GLuint texture, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureParameterIuiv (GLuint texture, GLenum pname, GLuint *params); +GLAPI void APIENTRY glGetTextureParameteriv (GLuint texture, GLenum pname, GLint *params); +GLAPI void APIENTRY glCreateVertexArrays (GLsizei n, GLuint *arrays); +GLAPI void APIENTRY glDisableVertexArrayAttrib (GLuint vaobj, GLuint index); +GLAPI void APIENTRY glEnableVertexArrayAttrib (GLuint vaobj, GLuint index); +GLAPI void APIENTRY glVertexArrayElementBuffer (GLuint vaobj, GLuint buffer); +GLAPI void APIENTRY glVertexArrayVertexBuffer (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexArrayVertexBuffers (GLuint vaobj, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides); +GLAPI void APIENTRY glVertexArrayAttribBinding (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexArrayAttribFormat (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayAttribIFormat (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayAttribLFormat (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayBindingDivisor (GLuint vaobj, GLuint bindingindex, GLuint divisor); +GLAPI void APIENTRY glGetVertexArrayiv (GLuint vaobj, GLenum pname, GLint *param); +GLAPI void APIENTRY glGetVertexArrayIndexediv (GLuint vaobj, GLuint index, GLenum pname, GLint *param); +GLAPI void APIENTRY glGetVertexArrayIndexed64iv (GLuint vaobj, GLuint index, GLenum pname, GLint64 *param); +GLAPI void APIENTRY glCreateSamplers (GLsizei n, GLuint *samplers); +GLAPI void APIENTRY glCreateProgramPipelines (GLsizei n, GLuint *pipelines); +GLAPI void APIENTRY glCreateQueries (GLenum target, GLsizei n, GLuint *ids); +GLAPI void APIENTRY glGetQueryBufferObjecti64v (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +GLAPI void APIENTRY glGetQueryBufferObjectiv (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +GLAPI void APIENTRY glGetQueryBufferObjectui64v (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +GLAPI void APIENTRY glGetQueryBufferObjectuiv (GLuint id, GLuint buffer, GLenum pname, GLintptr offset); +GLAPI void APIENTRY glMemoryBarrierByRegion (GLbitfield barriers); +GLAPI void APIENTRY glGetTextureSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLsizei bufSize, void *pixels); +GLAPI void APIENTRY glGetCompressedTextureSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei bufSize, void *pixels); +GLAPI GLenum APIENTRY glGetGraphicsResetStatus (void); +GLAPI void APIENTRY glGetnCompressedTexImage (GLenum target, GLint lod, GLsizei bufSize, void *pixels); +GLAPI void APIENTRY glGetnTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *pixels); +GLAPI void APIENTRY glGetnUniformdv (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +GLAPI void APIENTRY glGetnUniformfv (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +GLAPI void APIENTRY glGetnUniformiv (GLuint program, GLint location, GLsizei bufSize, GLint *params); +GLAPI void APIENTRY glGetnUniformuiv (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +GLAPI void APIENTRY glReadnPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +GLAPI void APIENTRY glGetnMapdv (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +GLAPI void APIENTRY glGetnMapfv (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +GLAPI void APIENTRY glGetnMapiv (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +GLAPI void APIENTRY glGetnPixelMapfv (GLenum map, GLsizei bufSize, GLfloat *values); +GLAPI void APIENTRY glGetnPixelMapuiv (GLenum map, GLsizei bufSize, GLuint *values); +GLAPI void APIENTRY glGetnPixelMapusv (GLenum map, GLsizei bufSize, GLushort *values); +GLAPI void APIENTRY glGetnPolygonStipple (GLsizei bufSize, GLubyte *pattern); +GLAPI void APIENTRY glGetnColorTable (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table); +GLAPI void APIENTRY glGetnConvolutionFilter (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image); +GLAPI void APIENTRY glGetnSeparableFilter (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span); +GLAPI void APIENTRY glGetnHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +GLAPI void APIENTRY glGetnMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +GLAPI void APIENTRY glTextureBarrier (void); +#endif +#endif /* GL_VERSION_4_5 */ + +#ifndef GL_VERSION_4_6 +#define GL_VERSION_4_6 1 +#define GL_SHADER_BINARY_FORMAT_SPIR_V 0x9551 +#define GL_SPIR_V_BINARY 0x9552 +#define GL_PARAMETER_BUFFER 0x80EE +#define GL_PARAMETER_BUFFER_BINDING 0x80EF +#define GL_CONTEXT_FLAG_NO_ERROR_BIT 0x00000008 +#define GL_VERTICES_SUBMITTED 0x82EE +#define GL_PRIMITIVES_SUBMITTED 0x82EF +#define GL_VERTEX_SHADER_INVOCATIONS 0x82F0 +#define GL_TESS_CONTROL_SHADER_PATCHES 0x82F1 +#define GL_TESS_EVALUATION_SHADER_INVOCATIONS 0x82F2 +#define GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED 0x82F3 +#define GL_FRAGMENT_SHADER_INVOCATIONS 0x82F4 +#define GL_COMPUTE_SHADER_INVOCATIONS 0x82F5 +#define GL_CLIPPING_INPUT_PRIMITIVES 0x82F6 +#define GL_CLIPPING_OUTPUT_PRIMITIVES 0x82F7 +#define GL_POLYGON_OFFSET_CLAMP 0x8E1B +#define GL_SPIR_V_EXTENSIONS 0x9553 +#define GL_NUM_SPIR_V_EXTENSIONS 0x9554 +#define GL_TEXTURE_MAX_ANISOTROPY 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF +#define GL_TRANSFORM_FEEDBACK_OVERFLOW 0x82EC +#define GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW 0x82ED +typedef void (APIENTRYP PFNGLSPECIALIZESHADERPROC) (GLuint shader, const GLchar *pEntryPoint, GLuint numSpecializationConstants, const GLuint *pConstantIndex, const GLuint *pConstantValue); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC) (GLenum mode, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC) (GLenum mode, GLenum type, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLPOLYGONOFFSETCLAMPPROC) (GLfloat factor, GLfloat units, GLfloat clamp); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpecializeShader (GLuint shader, const GLchar *pEntryPoint, GLuint numSpecializationConstants, const GLuint *pConstantIndex, const GLuint *pConstantValue); +GLAPI void APIENTRY glMultiDrawArraysIndirectCount (GLenum mode, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirectCount (GLenum mode, GLenum type, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +GLAPI void APIENTRY glPolygonOffsetClamp (GLfloat factor, GLfloat units, GLfloat clamp); +#endif +#endif /* GL_VERSION_4_6 */ + +#ifndef GL_ARB_ES2_compatibility +#define GL_ARB_ES2_compatibility 1 +#endif /* GL_ARB_ES2_compatibility */ + +#ifndef GL_ARB_ES3_1_compatibility +#define GL_ARB_ES3_1_compatibility 1 +#endif /* GL_ARB_ES3_1_compatibility */ + +#ifndef GL_ARB_ES3_2_compatibility +#define GL_ARB_ES3_2_compatibility 1 +#define GL_PRIMITIVE_BOUNDING_BOX_ARB 0x92BE +#define GL_MULTISAMPLE_LINE_WIDTH_RANGE_ARB 0x9381 +#define GL_MULTISAMPLE_LINE_WIDTH_GRANULARITY_ARB 0x9382 +typedef void (APIENTRYP PFNGLPRIMITIVEBOUNDINGBOXARBPROC) (GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPrimitiveBoundingBoxARB (GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW); +#endif +#endif /* GL_ARB_ES3_2_compatibility */ + +#ifndef GL_ARB_ES3_compatibility +#define GL_ARB_ES3_compatibility 1 +#endif /* GL_ARB_ES3_compatibility */ + +#ifndef GL_ARB_arrays_of_arrays +#define GL_ARB_arrays_of_arrays 1 +#endif /* GL_ARB_arrays_of_arrays */ + +#ifndef GL_ARB_base_instance +#define GL_ARB_base_instance 1 +#endif /* GL_ARB_base_instance */ + +#ifndef GL_ARB_bindless_texture +#define GL_ARB_bindless_texture 1 +typedef khronos_uint64_t GLuint64EXT; +#define GL_UNSIGNED_INT64_ARB 0x140F +typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLEARBPROC) (GLuint texture); +typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLEARBPROC) (GLuint texture, GLuint sampler); +typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTARBPROC) (GLuint64 handle); +typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTARBPROC) (GLuint64 handle); +typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLEARBPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); +typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTARBPROC) (GLuint64 handle, GLenum access); +typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTARBPROC) (GLuint64 handle); +typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64ARBPROC) (GLint location, GLuint64 value); +typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VARBPROC) (GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64ARBPROC) (GLuint program, GLint location, GLuint64 value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTARBPROC) (GLuint64 handle); +typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTARBPROC) (GLuint64 handle); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64ARBPROC) (GLuint index, GLuint64EXT x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VARBPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VARBPROC) (GLuint index, GLenum pname, GLuint64EXT *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint64 APIENTRY glGetTextureHandleARB (GLuint texture); +GLAPI GLuint64 APIENTRY glGetTextureSamplerHandleARB (GLuint texture, GLuint sampler); +GLAPI void APIENTRY glMakeTextureHandleResidentARB (GLuint64 handle); +GLAPI void APIENTRY glMakeTextureHandleNonResidentARB (GLuint64 handle); +GLAPI GLuint64 APIENTRY glGetImageHandleARB (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); +GLAPI void APIENTRY glMakeImageHandleResidentARB (GLuint64 handle, GLenum access); +GLAPI void APIENTRY glMakeImageHandleNonResidentARB (GLuint64 handle); +GLAPI void APIENTRY glUniformHandleui64ARB (GLint location, GLuint64 value); +GLAPI void APIENTRY glUniformHandleui64vARB (GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glProgramUniformHandleui64ARB (GLuint program, GLint location, GLuint64 value); +GLAPI void APIENTRY glProgramUniformHandleui64vARB (GLuint program, GLint location, GLsizei count, const GLuint64 *values); +GLAPI GLboolean APIENTRY glIsTextureHandleResidentARB (GLuint64 handle); +GLAPI GLboolean APIENTRY glIsImageHandleResidentARB (GLuint64 handle); +GLAPI void APIENTRY glVertexAttribL1ui64ARB (GLuint index, GLuint64EXT x); +GLAPI void APIENTRY glVertexAttribL1ui64vARB (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glGetVertexAttribLui64vARB (GLuint index, GLenum pname, GLuint64EXT *params); +#endif +#endif /* GL_ARB_bindless_texture */ + +#ifndef GL_ARB_blend_func_extended +#define GL_ARB_blend_func_extended 1 +#endif /* GL_ARB_blend_func_extended */ + +#ifndef GL_ARB_buffer_storage +#define GL_ARB_buffer_storage 1 +#endif /* GL_ARB_buffer_storage */ + +#ifndef GL_ARB_cl_event +#define GL_ARB_cl_event 1 +struct _cl_context; +struct _cl_event; +#define GL_SYNC_CL_EVENT_ARB 0x8240 +#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241 +typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context *context, struct _cl_event *event, GLbitfield flags); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context *context, struct _cl_event *event, GLbitfield flags); +#endif +#endif /* GL_ARB_cl_event */ + +#ifndef GL_ARB_clear_buffer_object +#define GL_ARB_clear_buffer_object 1 +#endif /* GL_ARB_clear_buffer_object */ + +#ifndef GL_ARB_clear_texture +#define GL_ARB_clear_texture 1 +#endif /* GL_ARB_clear_texture */ + +#ifndef GL_ARB_clip_control +#define GL_ARB_clip_control 1 +#endif /* GL_ARB_clip_control */ + +#ifndef GL_ARB_color_buffer_float +#define GL_ARB_color_buffer_float 1 +#define GL_RGBA_FLOAT_MODE_ARB 0x8820 +#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A +#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B +#define GL_CLAMP_READ_COLOR_ARB 0x891C +#define GL_FIXED_ONLY_ARB 0x891D +typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClampColorARB (GLenum target, GLenum clamp); +#endif +#endif /* GL_ARB_color_buffer_float */ + +#ifndef GL_ARB_compatibility +#define GL_ARB_compatibility 1 +#endif /* GL_ARB_compatibility */ + +#ifndef GL_ARB_compressed_texture_pixel_storage +#define GL_ARB_compressed_texture_pixel_storage 1 +#endif /* GL_ARB_compressed_texture_pixel_storage */ + +#ifndef GL_ARB_compute_shader +#define GL_ARB_compute_shader 1 +#endif /* GL_ARB_compute_shader */ + +#ifndef GL_ARB_compute_variable_group_size +#define GL_ARB_compute_variable_group_size 1 +#define GL_MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB 0x9344 +#define GL_MAX_COMPUTE_FIXED_GROUP_INVOCATIONS_ARB 0x90EB +#define GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB 0x9345 +#define GL_MAX_COMPUTE_FIXED_GROUP_SIZE_ARB 0x91BF +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEGROUPSIZEARBPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDispatchComputeGroupSizeARB (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z); +#endif +#endif /* GL_ARB_compute_variable_group_size */ + +#ifndef GL_ARB_conditional_render_inverted +#define GL_ARB_conditional_render_inverted 1 +#endif /* GL_ARB_conditional_render_inverted */ + +#ifndef GL_ARB_conservative_depth +#define GL_ARB_conservative_depth 1 +#endif /* GL_ARB_conservative_depth */ + +#ifndef GL_ARB_copy_buffer +#define GL_ARB_copy_buffer 1 +#endif /* GL_ARB_copy_buffer */ + +#ifndef GL_ARB_copy_image +#define GL_ARB_copy_image 1 +#endif /* GL_ARB_copy_image */ + +#ifndef GL_ARB_cull_distance +#define GL_ARB_cull_distance 1 +#endif /* GL_ARB_cull_distance */ + +#ifndef GL_ARB_debug_output +#define GL_ARB_debug_output 1 +typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); +#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245 +#define GL_DEBUG_SOURCE_API_ARB 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A +#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B +#define GL_DEBUG_TYPE_ERROR_ARB 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E +#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250 +#define GL_DEBUG_TYPE_OTHER_ARB 0x8251 +#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147 +#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148 +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const void *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const void *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif +#endif /* GL_ARB_debug_output */ + +#ifndef GL_ARB_depth_buffer_float +#define GL_ARB_depth_buffer_float 1 +#endif /* GL_ARB_depth_buffer_float */ + +#ifndef GL_ARB_depth_clamp +#define GL_ARB_depth_clamp 1 +#endif /* GL_ARB_depth_clamp */ + +#ifndef GL_ARB_depth_texture +#define GL_ARB_depth_texture 1 +#define GL_DEPTH_COMPONENT16_ARB 0x81A5 +#define GL_DEPTH_COMPONENT24_ARB 0x81A6 +#define GL_DEPTH_COMPONENT32_ARB 0x81A7 +#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A +#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B +#endif /* GL_ARB_depth_texture */ + +#ifndef GL_ARB_derivative_control +#define GL_ARB_derivative_control 1 +#endif /* GL_ARB_derivative_control */ + +#ifndef GL_ARB_direct_state_access +#define GL_ARB_direct_state_access 1 +#endif /* GL_ARB_direct_state_access */ + +#ifndef GL_ARB_draw_buffers +#define GL_ARB_draw_buffers 1 +#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 +#define GL_DRAW_BUFFER0_ARB 0x8825 +#define GL_DRAW_BUFFER1_ARB 0x8826 +#define GL_DRAW_BUFFER2_ARB 0x8827 +#define GL_DRAW_BUFFER3_ARB 0x8828 +#define GL_DRAW_BUFFER4_ARB 0x8829 +#define GL_DRAW_BUFFER5_ARB 0x882A +#define GL_DRAW_BUFFER6_ARB 0x882B +#define GL_DRAW_BUFFER7_ARB 0x882C +#define GL_DRAW_BUFFER8_ARB 0x882D +#define GL_DRAW_BUFFER9_ARB 0x882E +#define GL_DRAW_BUFFER10_ARB 0x882F +#define GL_DRAW_BUFFER11_ARB 0x8830 +#define GL_DRAW_BUFFER12_ARB 0x8831 +#define GL_DRAW_BUFFER13_ARB 0x8832 +#define GL_DRAW_BUFFER14_ARB 0x8833 +#define GL_DRAW_BUFFER15_ARB 0x8834 +typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersARB (GLsizei n, const GLenum *bufs); +#endif +#endif /* GL_ARB_draw_buffers */ + +#ifndef GL_ARB_draw_buffers_blend +#define GL_ARB_draw_buffers_blend 1 +typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif +#endif /* GL_ARB_draw_buffers_blend */ + +#ifndef GL_ARB_draw_elements_base_vertex +#define GL_ARB_draw_elements_base_vertex 1 +#endif /* GL_ARB_draw_elements_base_vertex */ + +#ifndef GL_ARB_draw_indirect +#define GL_ARB_draw_indirect 1 +#endif /* GL_ARB_draw_indirect */ + +#ifndef GL_ARB_draw_instanced +#define GL_ARB_draw_instanced 1 +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDARBPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedARB (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstancedARB (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +#endif +#endif /* GL_ARB_draw_instanced */ + +#ifndef GL_ARB_enhanced_layouts +#define GL_ARB_enhanced_layouts 1 +#endif /* GL_ARB_enhanced_layouts */ + +#ifndef GL_ARB_explicit_attrib_location +#define GL_ARB_explicit_attrib_location 1 +#endif /* GL_ARB_explicit_attrib_location */ + +#ifndef GL_ARB_explicit_uniform_location +#define GL_ARB_explicit_uniform_location 1 +#endif /* GL_ARB_explicit_uniform_location */ + +#ifndef GL_ARB_fragment_coord_conventions +#define GL_ARB_fragment_coord_conventions 1 +#endif /* GL_ARB_fragment_coord_conventions */ + +#ifndef GL_ARB_fragment_layer_viewport +#define GL_ARB_fragment_layer_viewport 1 +#endif /* GL_ARB_fragment_layer_viewport */ + +#ifndef GL_ARB_fragment_program +#define GL_ARB_fragment_program 1 +#define GL_FRAGMENT_PROGRAM_ARB 0x8804 +#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 +#define GL_PROGRAM_LENGTH_ARB 0x8627 +#define GL_PROGRAM_FORMAT_ARB 0x8876 +#define GL_PROGRAM_BINDING_ARB 0x8677 +#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 +#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 +#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 +#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 +#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 +#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 +#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 +#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 +#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 +#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 +#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA +#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB +#define GL_PROGRAM_ATTRIBS_ARB 0x88AC +#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD +#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE +#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF +#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 +#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 +#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 +#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 +#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 +#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 +#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 +#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 +#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A +#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B +#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C +#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D +#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E +#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F +#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 +#define GL_PROGRAM_STRING_ARB 0x8628 +#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B +#define GL_CURRENT_MATRIX_ARB 0x8641 +#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 +#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 +#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F +#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E +#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 +#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 +#define GL_MATRIX0_ARB 0x88C0 +#define GL_MATRIX1_ARB 0x88C1 +#define GL_MATRIX2_ARB 0x88C2 +#define GL_MATRIX3_ARB 0x88C3 +#define GL_MATRIX4_ARB 0x88C4 +#define GL_MATRIX5_ARB 0x88C5 +#define GL_MATRIX6_ARB 0x88C6 +#define GL_MATRIX7_ARB 0x88C7 +#define GL_MATRIX8_ARB 0x88C8 +#define GL_MATRIX9_ARB 0x88C9 +#define GL_MATRIX10_ARB 0x88CA +#define GL_MATRIX11_ARB 0x88CB +#define GL_MATRIX12_ARB 0x88CC +#define GL_MATRIX13_ARB 0x88CD +#define GL_MATRIX14_ARB 0x88CE +#define GL_MATRIX15_ARB 0x88CF +#define GL_MATRIX16_ARB 0x88D0 +#define GL_MATRIX17_ARB 0x88D1 +#define GL_MATRIX18_ARB 0x88D2 +#define GL_MATRIX19_ARB 0x88D3 +#define GL_MATRIX20_ARB 0x88D4 +#define GL_MATRIX21_ARB 0x88D5 +#define GL_MATRIX22_ARB 0x88D6 +#define GL_MATRIX23_ARB 0x88D7 +#define GL_MATRIX24_ARB 0x88D8 +#define GL_MATRIX25_ARB 0x88D9 +#define GL_MATRIX26_ARB 0x88DA +#define GL_MATRIX27_ARB 0x88DB +#define GL_MATRIX28_ARB 0x88DC +#define GL_MATRIX29_ARB 0x88DD +#define GL_MATRIX30_ARB 0x88DE +#define GL_MATRIX31_ARB 0x88DF +typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const void *string); +typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, void *string); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramStringARB (GLenum target, GLenum format, GLsizei len, const void *string); +GLAPI void APIENTRY glBindProgramARB (GLenum target, GLuint program); +GLAPI void APIENTRY glDeleteProgramsARB (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glGenProgramsARB (GLsizei n, GLuint *programs); +GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetProgramivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramStringARB (GLenum target, GLenum pname, void *string); +GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program); +#endif +#endif /* GL_ARB_fragment_program */ + +#ifndef GL_ARB_fragment_program_shadow +#define GL_ARB_fragment_program_shadow 1 +#endif /* GL_ARB_fragment_program_shadow */ + +#ifndef GL_ARB_fragment_shader +#define GL_ARB_fragment_shader 1 +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B +#endif /* GL_ARB_fragment_shader */ + +#ifndef GL_ARB_fragment_shader_interlock +#define GL_ARB_fragment_shader_interlock 1 +#endif /* GL_ARB_fragment_shader_interlock */ + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_ARB_framebuffer_no_attachments 1 +#endif /* GL_ARB_framebuffer_no_attachments */ + +#ifndef GL_ARB_framebuffer_object +#define GL_ARB_framebuffer_object 1 +#endif /* GL_ARB_framebuffer_object */ + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_ARB_framebuffer_sRGB 1 +#endif /* GL_ARB_framebuffer_sRGB */ + +#ifndef GL_ARB_geometry_shader4 +#define GL_ARB_geometry_shader4 1 +#define GL_LINES_ADJACENCY_ARB 0x000A +#define GL_LINE_STRIP_ADJACENCY_ARB 0x000B +#define GL_TRIANGLES_ADJACENCY_ARB 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_ARB 0x000D +#define GL_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9 +#define GL_GEOMETRY_SHADER_ARB 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT_ARB 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_ARB 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_ARB 0x8DDC +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1 +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIARBPROC) (GLuint program, GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriARB (GLuint program, GLenum pname, GLint value); +GLAPI void APIENTRY glFramebufferTextureARB (GLenum target, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTextureLayerARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glFramebufferTextureFaceARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif +#endif /* GL_ARB_geometry_shader4 */ + +#ifndef GL_ARB_get_program_binary +#define GL_ARB_get_program_binary 1 +#endif /* GL_ARB_get_program_binary */ + +#ifndef GL_ARB_get_texture_sub_image +#define GL_ARB_get_texture_sub_image 1 +#endif /* GL_ARB_get_texture_sub_image */ + +#ifndef GL_ARB_gl_spirv +#define GL_ARB_gl_spirv 1 +#define GL_SHADER_BINARY_FORMAT_SPIR_V_ARB 0x9551 +#define GL_SPIR_V_BINARY_ARB 0x9552 +typedef void (APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const GLchar *pEntryPoint, GLuint numSpecializationConstants, const GLuint *pConstantIndex, const GLuint *pConstantValue); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpecializeShaderARB (GLuint shader, const GLchar *pEntryPoint, GLuint numSpecializationConstants, const GLuint *pConstantIndex, const GLuint *pConstantValue); +#endif +#endif /* GL_ARB_gl_spirv */ + +#ifndef GL_ARB_gpu_shader5 +#define GL_ARB_gpu_shader5 1 +#endif /* GL_ARB_gpu_shader5 */ + +#ifndef GL_ARB_gpu_shader_fp64 +#define GL_ARB_gpu_shader_fp64 1 +#endif /* GL_ARB_gpu_shader_fp64 */ + +#ifndef GL_ARB_gpu_shader_int64 +#define GL_ARB_gpu_shader_int64 1 +#define GL_INT64_ARB 0x140E +#define GL_INT64_VEC2_ARB 0x8FE9 +#define GL_INT64_VEC3_ARB 0x8FEA +#define GL_INT64_VEC4_ARB 0x8FEB +#define GL_UNSIGNED_INT64_VEC2_ARB 0x8FF5 +#define GL_UNSIGNED_INT64_VEC3_ARB 0x8FF6 +#define GL_UNSIGNED_INT64_VEC4_ARB 0x8FF7 +typedef void (APIENTRYP PFNGLUNIFORM1I64ARBPROC) (GLint location, GLint64 x); +typedef void (APIENTRYP PFNGLUNIFORM2I64ARBPROC) (GLint location, GLint64 x, GLint64 y); +typedef void (APIENTRYP PFNGLUNIFORM3I64ARBPROC) (GLint location, GLint64 x, GLint64 y, GLint64 z); +typedef void (APIENTRYP PFNGLUNIFORM4I64ARBPROC) (GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w); +typedef void (APIENTRYP PFNGLUNIFORM1I64VARBPROC) (GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLUNIFORM2I64VARBPROC) (GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLUNIFORM3I64VARBPROC) (GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLUNIFORM4I64VARBPROC) (GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLUNIFORM1UI64ARBPROC) (GLint location, GLuint64 x); +typedef void (APIENTRYP PFNGLUNIFORM2UI64ARBPROC) (GLint location, GLuint64 x, GLuint64 y); +typedef void (APIENTRYP PFNGLUNIFORM3UI64ARBPROC) (GLint location, GLuint64 x, GLuint64 y, GLuint64 z); +typedef void (APIENTRYP PFNGLUNIFORM4UI64ARBPROC) (GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w); +typedef void (APIENTRYP PFNGLUNIFORM1UI64VARBPROC) (GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLUNIFORM2UI64VARBPROC) (GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLUNIFORM3UI64VARBPROC) (GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLUNIFORM4UI64VARBPROC) (GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLGETUNIFORMI64VARBPROC) (GLuint program, GLint location, GLint64 *params); +typedef void (APIENTRYP PFNGLGETUNIFORMUI64VARBPROC) (GLuint program, GLint location, GLuint64 *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMI64VARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint64 *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMUI64VARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint64 *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64ARBPROC) (GLuint program, GLint location, GLint64 x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64ARBPROC) (GLuint program, GLint location, GLint64 x, GLint64 y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64ARBPROC) (GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64ARBPROC) (GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64ARBPROC) (GLuint program, GLint location, GLuint64 x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64ARBPROC) (GLuint program, GLint location, GLuint64 x, GLuint64 y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64ARBPROC) (GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64ARBPROC) (GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniform1i64ARB (GLint location, GLint64 x); +GLAPI void APIENTRY glUniform2i64ARB (GLint location, GLint64 x, GLint64 y); +GLAPI void APIENTRY glUniform3i64ARB (GLint location, GLint64 x, GLint64 y, GLint64 z); +GLAPI void APIENTRY glUniform4i64ARB (GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w); +GLAPI void APIENTRY glUniform1i64vARB (GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glUniform2i64vARB (GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glUniform3i64vARB (GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glUniform4i64vARB (GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glUniform1ui64ARB (GLint location, GLuint64 x); +GLAPI void APIENTRY glUniform2ui64ARB (GLint location, GLuint64 x, GLuint64 y); +GLAPI void APIENTRY glUniform3ui64ARB (GLint location, GLuint64 x, GLuint64 y, GLuint64 z); +GLAPI void APIENTRY glUniform4ui64ARB (GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w); +GLAPI void APIENTRY glUniform1ui64vARB (GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glUniform2ui64vARB (GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glUniform3ui64vARB (GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glUniform4ui64vARB (GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glGetUniformi64vARB (GLuint program, GLint location, GLint64 *params); +GLAPI void APIENTRY glGetUniformui64vARB (GLuint program, GLint location, GLuint64 *params); +GLAPI void APIENTRY glGetnUniformi64vARB (GLuint program, GLint location, GLsizei bufSize, GLint64 *params); +GLAPI void APIENTRY glGetnUniformui64vARB (GLuint program, GLint location, GLsizei bufSize, GLuint64 *params); +GLAPI void APIENTRY glProgramUniform1i64ARB (GLuint program, GLint location, GLint64 x); +GLAPI void APIENTRY glProgramUniform2i64ARB (GLuint program, GLint location, GLint64 x, GLint64 y); +GLAPI void APIENTRY glProgramUniform3i64ARB (GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z); +GLAPI void APIENTRY glProgramUniform4i64ARB (GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w); +GLAPI void APIENTRY glProgramUniform1i64vARB (GLuint program, GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glProgramUniform2i64vARB (GLuint program, GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glProgramUniform3i64vARB (GLuint program, GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glProgramUniform4i64vARB (GLuint program, GLint location, GLsizei count, const GLint64 *value); +GLAPI void APIENTRY glProgramUniform1ui64ARB (GLuint program, GLint location, GLuint64 x); +GLAPI void APIENTRY glProgramUniform2ui64ARB (GLuint program, GLint location, GLuint64 x, GLuint64 y); +GLAPI void APIENTRY glProgramUniform3ui64ARB (GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z); +GLAPI void APIENTRY glProgramUniform4ui64ARB (GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w); +GLAPI void APIENTRY glProgramUniform1ui64vARB (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glProgramUniform2ui64vARB (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glProgramUniform3ui64vARB (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glProgramUniform4ui64vARB (GLuint program, GLint location, GLsizei count, const GLuint64 *value); +#endif +#endif /* GL_ARB_gpu_shader_int64 */ + +#ifndef GL_ARB_half_float_pixel +#define GL_ARB_half_float_pixel 1 +typedef khronos_uint16_t GLhalfARB; +#define GL_HALF_FLOAT_ARB 0x140B +#endif /* GL_ARB_half_float_pixel */ + +#ifndef GL_ARB_half_float_vertex +#define GL_ARB_half_float_vertex 1 +#endif /* GL_ARB_half_float_vertex */ + +#ifndef GL_ARB_imaging +#define GL_ARB_imaging 1 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, void *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, void *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table); +GLAPI void APIENTRY glColorTableParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glColorTableParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyColorTable (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glGetColorTable (GLenum target, GLenum format, GLenum type, void *table); +GLAPI void APIENTRY glGetColorTableParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetColorTableParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glCopyColorSubTable (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glConvolutionFilter1D (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image); +GLAPI void APIENTRY glConvolutionFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image); +GLAPI void APIENTRY glConvolutionParameterf (GLenum target, GLenum pname, GLfloat params); +GLAPI void APIENTRY glConvolutionParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glConvolutionParameteri (GLenum target, GLenum pname, GLint params); +GLAPI void APIENTRY glConvolutionParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetConvolutionFilter (GLenum target, GLenum format, GLenum type, void *image); +GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSeparableFilter (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span); +GLAPI void APIENTRY glSeparableFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column); +GLAPI void APIENTRY glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +GLAPI void APIENTRY glGetHistogramParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetHistogramParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glHistogram (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glMinmax (GLenum target, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glResetHistogram (GLenum target); +GLAPI void APIENTRY glResetMinmax (GLenum target); +#endif +#endif /* GL_ARB_imaging */ + +#ifndef GL_ARB_indirect_parameters +#define GL_ARB_indirect_parameters 1 +#define GL_PARAMETER_BUFFER_ARB 0x80EE +#define GL_PARAMETER_BUFFER_BINDING_ARB 0x80EF +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTCOUNTARBPROC) (GLenum mode, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTARBPROC) (GLenum mode, GLenum type, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirectCountARB (GLenum mode, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirectCountARB (GLenum mode, GLenum type, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +#endif +#endif /* GL_ARB_indirect_parameters */ + +#ifndef GL_ARB_instanced_arrays +#define GL_ARB_instanced_arrays 1 +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB 0x88FE +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisorARB (GLuint index, GLuint divisor); +#endif +#endif /* GL_ARB_instanced_arrays */ + +#ifndef GL_ARB_internalformat_query +#define GL_ARB_internalformat_query 1 +#endif /* GL_ARB_internalformat_query */ + +#ifndef GL_ARB_internalformat_query2 +#define GL_ARB_internalformat_query2 1 +#define GL_SRGB_DECODE_ARB 0x8299 +#define GL_VIEW_CLASS_EAC_R11 0x9383 +#define GL_VIEW_CLASS_EAC_RG11 0x9384 +#define GL_VIEW_CLASS_ETC2_RGB 0x9385 +#define GL_VIEW_CLASS_ETC2_RGBA 0x9386 +#define GL_VIEW_CLASS_ETC2_EAC_RGBA 0x9387 +#define GL_VIEW_CLASS_ASTC_4x4_RGBA 0x9388 +#define GL_VIEW_CLASS_ASTC_5x4_RGBA 0x9389 +#define GL_VIEW_CLASS_ASTC_5x5_RGBA 0x938A +#define GL_VIEW_CLASS_ASTC_6x5_RGBA 0x938B +#define GL_VIEW_CLASS_ASTC_6x6_RGBA 0x938C +#define GL_VIEW_CLASS_ASTC_8x5_RGBA 0x938D +#define GL_VIEW_CLASS_ASTC_8x6_RGBA 0x938E +#define GL_VIEW_CLASS_ASTC_8x8_RGBA 0x938F +#define GL_VIEW_CLASS_ASTC_10x5_RGBA 0x9390 +#define GL_VIEW_CLASS_ASTC_10x6_RGBA 0x9391 +#define GL_VIEW_CLASS_ASTC_10x8_RGBA 0x9392 +#define GL_VIEW_CLASS_ASTC_10x10_RGBA 0x9393 +#define GL_VIEW_CLASS_ASTC_12x10_RGBA 0x9394 +#define GL_VIEW_CLASS_ASTC_12x12_RGBA 0x9395 +#endif /* GL_ARB_internalformat_query2 */ + +#ifndef GL_ARB_invalidate_subdata +#define GL_ARB_invalidate_subdata 1 +#endif /* GL_ARB_invalidate_subdata */ + +#ifndef GL_ARB_map_buffer_alignment +#define GL_ARB_map_buffer_alignment 1 +#endif /* GL_ARB_map_buffer_alignment */ + +#ifndef GL_ARB_map_buffer_range +#define GL_ARB_map_buffer_range 1 +#endif /* GL_ARB_map_buffer_range */ + +#ifndef GL_ARB_matrix_palette +#define GL_ARB_matrix_palette 1 +#define GL_MATRIX_PALETTE_ARB 0x8840 +#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841 +#define GL_MAX_PALETTE_MATRICES_ARB 0x8842 +#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843 +#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844 +#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845 +#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849 +typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); +typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint index); +GLAPI void APIENTRY glMatrixIndexubvARB (GLint size, const GLubyte *indices); +GLAPI void APIENTRY glMatrixIndexusvARB (GLint size, const GLushort *indices); +GLAPI void APIENTRY glMatrixIndexuivARB (GLint size, const GLuint *indices); +GLAPI void APIENTRY glMatrixIndexPointerARB (GLint size, GLenum type, GLsizei stride, const void *pointer); +#endif +#endif /* GL_ARB_matrix_palette */ + +#ifndef GL_ARB_multi_bind +#define GL_ARB_multi_bind 1 +#endif /* GL_ARB_multi_bind */ + +#ifndef GL_ARB_multi_draw_indirect +#define GL_ARB_multi_draw_indirect 1 +#endif /* GL_ARB_multi_draw_indirect */ + +#ifndef GL_ARB_multisample +#define GL_ARB_multisample 1 +#define GL_MULTISAMPLE_ARB 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F +#define GL_SAMPLE_COVERAGE_ARB 0x80A0 +#define GL_SAMPLE_BUFFERS_ARB 0x80A8 +#define GL_SAMPLES_ARB 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB +#define GL_MULTISAMPLE_BIT_ARB 0x20000000 +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLfloat value, GLboolean invert); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleCoverageARB (GLfloat value, GLboolean invert); +#endif +#endif /* GL_ARB_multisample */ + +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTextureARB (GLenum texture); +GLAPI void APIENTRY glClientActiveTextureARB (GLenum texture); +GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum target, GLdouble s); +GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum target, GLfloat s); +GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum target, GLint s); +GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum target, GLshort s); +GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum target, GLdouble s, GLdouble t); +GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum target, GLfloat s, GLfloat t); +GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum target, GLint s, GLint t); +GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum target, GLshort s, GLshort t); +GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum target, GLint s, GLint t, GLint r); +GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum target, const GLshort *v); +#endif +#endif /* GL_ARB_multitexture */ + +#ifndef GL_ARB_occlusion_query +#define GL_ARB_occlusion_query 1 +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#define GL_SAMPLES_PASSED_ARB 0x8914 +typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueriesARB (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueriesARB (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQueryARB (GLuint id); +GLAPI void APIENTRY glBeginQueryARB (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQueryARB (GLenum target); +GLAPI void APIENTRY glGetQueryivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectivARB (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint id, GLenum pname, GLuint *params); +#endif +#endif /* GL_ARB_occlusion_query */ + +#ifndef GL_ARB_occlusion_query2 +#define GL_ARB_occlusion_query2 1 +#endif /* GL_ARB_occlusion_query2 */ + +#ifndef GL_ARB_parallel_shader_compile +#define GL_ARB_parallel_shader_compile 1 +#define GL_MAX_SHADER_COMPILER_THREADS_ARB 0x91B0 +#define GL_COMPLETION_STATUS_ARB 0x91B1 +typedef void (APIENTRYP PFNGLMAXSHADERCOMPILERTHREADSARBPROC) (GLuint count); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMaxShaderCompilerThreadsARB (GLuint count); +#endif +#endif /* GL_ARB_parallel_shader_compile */ + +#ifndef GL_ARB_pipeline_statistics_query +#define GL_ARB_pipeline_statistics_query 1 +#define GL_VERTICES_SUBMITTED_ARB 0x82EE +#define GL_PRIMITIVES_SUBMITTED_ARB 0x82EF +#define GL_VERTEX_SHADER_INVOCATIONS_ARB 0x82F0 +#define GL_TESS_CONTROL_SHADER_PATCHES_ARB 0x82F1 +#define GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB 0x82F2 +#define GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB 0x82F3 +#define GL_FRAGMENT_SHADER_INVOCATIONS_ARB 0x82F4 +#define GL_COMPUTE_SHADER_INVOCATIONS_ARB 0x82F5 +#define GL_CLIPPING_INPUT_PRIMITIVES_ARB 0x82F6 +#define GL_CLIPPING_OUTPUT_PRIMITIVES_ARB 0x82F7 +#endif /* GL_ARB_pipeline_statistics_query */ + +#ifndef GL_ARB_pixel_buffer_object +#define GL_ARB_pixel_buffer_object 1 +#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF +#endif /* GL_ARB_pixel_buffer_object */ + +#ifndef GL_ARB_point_parameters +#define GL_ARB_point_parameters 1 +#define GL_POINT_SIZE_MIN_ARB 0x8126 +#define GL_POINT_SIZE_MAX_ARB 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129 +typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfARB (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvARB (GLenum pname, const GLfloat *params); +#endif +#endif /* GL_ARB_point_parameters */ + +#ifndef GL_ARB_point_sprite +#define GL_ARB_point_sprite 1 +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif /* GL_ARB_point_sprite */ + +#ifndef GL_ARB_polygon_offset_clamp +#define GL_ARB_polygon_offset_clamp 1 +#endif /* GL_ARB_polygon_offset_clamp */ + +#ifndef GL_ARB_post_depth_coverage +#define GL_ARB_post_depth_coverage 1 +#endif /* GL_ARB_post_depth_coverage */ + +#ifndef GL_ARB_program_interface_query +#define GL_ARB_program_interface_query 1 +#endif /* GL_ARB_program_interface_query */ + +#ifndef GL_ARB_provoking_vertex +#define GL_ARB_provoking_vertex 1 +#endif /* GL_ARB_provoking_vertex */ + +#ifndef GL_ARB_query_buffer_object +#define GL_ARB_query_buffer_object 1 +#endif /* GL_ARB_query_buffer_object */ + +#ifndef GL_ARB_robust_buffer_access_behavior +#define GL_ARB_robust_buffer_access_behavior 1 +#endif /* GL_ARB_robust_buffer_access_behavior */ + +#ifndef GL_ARB_robustness +#define GL_ARB_robustness 1 +#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 +#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define GL_NO_RESET_NOTIFICATION_ARB 0x8261 +typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); +typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *img); +typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, void *img); +typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values); +typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern); +typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table); +typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image); +typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span); +typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); +GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *img); +GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, void *img); +GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); +GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values); +GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values); +GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values); +GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern); +GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table); +GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image); +GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span); +GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values); +#endif +#endif /* GL_ARB_robustness */ + +#ifndef GL_ARB_robustness_isolation +#define GL_ARB_robustness_isolation 1 +#endif /* GL_ARB_robustness_isolation */ + +#ifndef GL_ARB_sample_locations +#define GL_ARB_sample_locations 1 +#define GL_SAMPLE_LOCATION_SUBPIXEL_BITS_ARB 0x933D +#define GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_ARB 0x933E +#define GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_ARB 0x933F +#define GL_PROGRAMMABLE_SAMPLE_LOCATION_TABLE_SIZE_ARB 0x9340 +#define GL_SAMPLE_LOCATION_ARB 0x8E50 +#define GL_PROGRAMMABLE_SAMPLE_LOCATION_ARB 0x9341 +#define GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB 0x9342 +#define GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB 0x9343 +typedef void (APIENTRYP PFNGLFRAMEBUFFERSAMPLELOCATIONSFVARBPROC) (GLenum target, GLuint start, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERSAMPLELOCATIONSFVARBPROC) (GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLEVALUATEDEPTHVALUESARBPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferSampleLocationsfvARB (GLenum target, GLuint start, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glNamedFramebufferSampleLocationsfvARB (GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glEvaluateDepthValuesARB (void); +#endif +#endif /* GL_ARB_sample_locations */ + +#ifndef GL_ARB_sample_shading +#define GL_ARB_sample_shading 1 +#define GL_SAMPLE_SHADING_ARB 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37 +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value); +#endif +#endif /* GL_ARB_sample_shading */ + +#ifndef GL_ARB_sampler_objects +#define GL_ARB_sampler_objects 1 +#endif /* GL_ARB_sampler_objects */ + +#ifndef GL_ARB_seamless_cube_map +#define GL_ARB_seamless_cube_map 1 +#endif /* GL_ARB_seamless_cube_map */ + +#ifndef GL_ARB_seamless_cubemap_per_texture +#define GL_ARB_seamless_cubemap_per_texture 1 +#endif /* GL_ARB_seamless_cubemap_per_texture */ + +#ifndef GL_ARB_separate_shader_objects +#define GL_ARB_separate_shader_objects 1 +#endif /* GL_ARB_separate_shader_objects */ + +#ifndef GL_ARB_shader_atomic_counter_ops +#define GL_ARB_shader_atomic_counter_ops 1 +#endif /* GL_ARB_shader_atomic_counter_ops */ + +#ifndef GL_ARB_shader_atomic_counters +#define GL_ARB_shader_atomic_counters 1 +#endif /* GL_ARB_shader_atomic_counters */ + +#ifndef GL_ARB_shader_ballot +#define GL_ARB_shader_ballot 1 +#endif /* GL_ARB_shader_ballot */ + +#ifndef GL_ARB_shader_bit_encoding +#define GL_ARB_shader_bit_encoding 1 +#endif /* GL_ARB_shader_bit_encoding */ + +#ifndef GL_ARB_shader_clock +#define GL_ARB_shader_clock 1 +#endif /* GL_ARB_shader_clock */ + +#ifndef GL_ARB_shader_draw_parameters +#define GL_ARB_shader_draw_parameters 1 +#endif /* GL_ARB_shader_draw_parameters */ + +#ifndef GL_ARB_shader_group_vote +#define GL_ARB_shader_group_vote 1 +#endif /* GL_ARB_shader_group_vote */ + +#ifndef GL_ARB_shader_image_load_store +#define GL_ARB_shader_image_load_store 1 +#endif /* GL_ARB_shader_image_load_store */ + +#ifndef GL_ARB_shader_image_size +#define GL_ARB_shader_image_size 1 +#endif /* GL_ARB_shader_image_size */ + +#ifndef GL_ARB_shader_objects +#define GL_ARB_shader_objects 1 +#ifdef __APPLE__ +typedef void *GLhandleARB; +#else +typedef unsigned int GLhandleARB; +#endif +typedef char GLcharARB; +#define GL_PROGRAM_OBJECT_ARB 0x8B40 +#define GL_SHADER_OBJECT_ARB 0x8B48 +#define GL_OBJECT_TYPE_ARB 0x8B4E +#define GL_OBJECT_SUBTYPE_ARB 0x8B4F +#define GL_FLOAT_VEC2_ARB 0x8B50 +#define GL_FLOAT_VEC3_ARB 0x8B51 +#define GL_FLOAT_VEC4_ARB 0x8B52 +#define GL_INT_VEC2_ARB 0x8B53 +#define GL_INT_VEC3_ARB 0x8B54 +#define GL_INT_VEC4_ARB 0x8B55 +#define GL_BOOL_ARB 0x8B56 +#define GL_BOOL_VEC2_ARB 0x8B57 +#define GL_BOOL_VEC3_ARB 0x8B58 +#define GL_BOOL_VEC4_ARB 0x8B59 +#define GL_FLOAT_MAT2_ARB 0x8B5A +#define GL_FLOAT_MAT3_ARB 0x8B5B +#define GL_FLOAT_MAT4_ARB 0x8B5C +#define GL_SAMPLER_1D_ARB 0x8B5D +#define GL_SAMPLER_2D_ARB 0x8B5E +#define GL_SAMPLER_3D_ARB 0x8B5F +#define GL_SAMPLER_CUBE_ARB 0x8B60 +#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 +#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 +#define GL_SAMPLER_2D_RECT_ARB 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 +#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 +#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 +#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 +#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 +#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 +#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 +#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 +typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); +typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB obj); +GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum pname); +GLAPI void APIENTRY glDetachObjectARB (GLhandleARB containerObj, GLhandleARB attachedObj); +GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum shaderType); +GLAPI void APIENTRY glShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length); +GLAPI void APIENTRY glCompileShaderARB (GLhandleARB shaderObj); +GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); +GLAPI void APIENTRY glAttachObjectARB (GLhandleARB containerObj, GLhandleARB obj); +GLAPI void APIENTRY glLinkProgramARB (GLhandleARB programObj); +GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB programObj); +GLAPI void APIENTRY glValidateProgramARB (GLhandleARB programObj); +GLAPI void APIENTRY glUniform1fARB (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2fARB (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1iARB (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2iARB (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3iARB (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4iARB (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB obj, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB obj, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name); +GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB programObj, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformivARB (GLhandleARB programObj, GLint location, GLint *params); +GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif +#endif /* GL_ARB_shader_objects */ + +#ifndef GL_ARB_shader_precision +#define GL_ARB_shader_precision 1 +#endif /* GL_ARB_shader_precision */ + +#ifndef GL_ARB_shader_stencil_export +#define GL_ARB_shader_stencil_export 1 +#endif /* GL_ARB_shader_stencil_export */ + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_ARB_shader_storage_buffer_object 1 +#endif /* GL_ARB_shader_storage_buffer_object */ + +#ifndef GL_ARB_shader_subroutine +#define GL_ARB_shader_subroutine 1 +#endif /* GL_ARB_shader_subroutine */ + +#ifndef GL_ARB_shader_texture_image_samples +#define GL_ARB_shader_texture_image_samples 1 +#endif /* GL_ARB_shader_texture_image_samples */ + +#ifndef GL_ARB_shader_texture_lod +#define GL_ARB_shader_texture_lod 1 +#endif /* GL_ARB_shader_texture_lod */ + +#ifndef GL_ARB_shader_viewport_layer_array +#define GL_ARB_shader_viewport_layer_array 1 +#endif /* GL_ARB_shader_viewport_layer_array */ + +#ifndef GL_ARB_shading_language_100 +#define GL_ARB_shading_language_100 1 +#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C +#endif /* GL_ARB_shading_language_100 */ + +#ifndef GL_ARB_shading_language_420pack +#define GL_ARB_shading_language_420pack 1 +#endif /* GL_ARB_shading_language_420pack */ + +#ifndef GL_ARB_shading_language_include +#define GL_ARB_shading_language_include 1 +#define GL_SHADER_INCLUDE_ARB 0x8DAE +#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9 +#define GL_NAMED_STRING_TYPE_ARB 0x8DEA +typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar *const*path, const GLint *length); +typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar *const*path, const GLint *length); +GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif +#endif /* GL_ARB_shading_language_include */ + +#ifndef GL_ARB_shading_language_packing +#define GL_ARB_shading_language_packing 1 +#endif /* GL_ARB_shading_language_packing */ + +#ifndef GL_ARB_shadow +#define GL_ARB_shadow 1 +#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C +#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D +#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E +#endif /* GL_ARB_shadow */ + +#ifndef GL_ARB_shadow_ambient +#define GL_ARB_shadow_ambient 1 +#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF +#endif /* GL_ARB_shadow_ambient */ + +#ifndef GL_ARB_sparse_buffer +#define GL_ARB_sparse_buffer 1 +#define GL_SPARSE_STORAGE_BIT_ARB 0x0400 +#define GL_SPARSE_BUFFER_PAGE_SIZE_ARB 0x82F8 +typedef void (APIENTRYP PFNGLBUFFERPAGECOMMITMENTARBPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLboolean commit); +typedef void (APIENTRYP PFNGLNAMEDBUFFERPAGECOMMITMENTEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit); +typedef void (APIENTRYP PFNGLNAMEDBUFFERPAGECOMMITMENTARBPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferPageCommitmentARB (GLenum target, GLintptr offset, GLsizeiptr size, GLboolean commit); +GLAPI void APIENTRY glNamedBufferPageCommitmentEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit); +GLAPI void APIENTRY glNamedBufferPageCommitmentARB (GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit); +#endif +#endif /* GL_ARB_sparse_buffer */ + +#ifndef GL_ARB_sparse_texture +#define GL_ARB_sparse_texture 1 +#define GL_TEXTURE_SPARSE_ARB 0x91A6 +#define GL_VIRTUAL_PAGE_SIZE_INDEX_ARB 0x91A7 +#define GL_NUM_SPARSE_LEVELS_ARB 0x91AA +#define GL_NUM_VIRTUAL_PAGE_SIZES_ARB 0x91A8 +#define GL_VIRTUAL_PAGE_SIZE_X_ARB 0x9195 +#define GL_VIRTUAL_PAGE_SIZE_Y_ARB 0x9196 +#define GL_VIRTUAL_PAGE_SIZE_Z_ARB 0x9197 +#define GL_MAX_SPARSE_TEXTURE_SIZE_ARB 0x9198 +#define GL_MAX_SPARSE_3D_TEXTURE_SIZE_ARB 0x9199 +#define GL_MAX_SPARSE_ARRAY_TEXTURE_LAYERS_ARB 0x919A +#define GL_SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS_ARB 0x91A9 +typedef void (APIENTRYP PFNGLTEXPAGECOMMITMENTARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexPageCommitmentARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit); +#endif +#endif /* GL_ARB_sparse_texture */ + +#ifndef GL_ARB_sparse_texture2 +#define GL_ARB_sparse_texture2 1 +#endif /* GL_ARB_sparse_texture2 */ + +#ifndef GL_ARB_sparse_texture_clamp +#define GL_ARB_sparse_texture_clamp 1 +#endif /* GL_ARB_sparse_texture_clamp */ + +#ifndef GL_ARB_spirv_extensions +#define GL_ARB_spirv_extensions 1 +#endif /* GL_ARB_spirv_extensions */ + +#ifndef GL_ARB_stencil_texturing +#define GL_ARB_stencil_texturing 1 +#endif /* GL_ARB_stencil_texturing */ + +#ifndef GL_ARB_sync +#define GL_ARB_sync 1 +#endif /* GL_ARB_sync */ + +#ifndef GL_ARB_tessellation_shader +#define GL_ARB_tessellation_shader 1 +#endif /* GL_ARB_tessellation_shader */ + +#ifndef GL_ARB_texture_barrier +#define GL_ARB_texture_barrier 1 +#endif /* GL_ARB_texture_barrier */ + +#ifndef GL_ARB_texture_border_clamp +#define GL_ARB_texture_border_clamp 1 +#define GL_CLAMP_TO_BORDER_ARB 0x812D +#endif /* GL_ARB_texture_border_clamp */ + +#ifndef GL_ARB_texture_buffer_object +#define GL_ARB_texture_buffer_object 1 +#define GL_TEXTURE_BUFFER_ARB 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_ARB 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_ARB 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_ARB 0x8C2E +typedef void (APIENTRYP PFNGLTEXBUFFERARBPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferARB (GLenum target, GLenum internalformat, GLuint buffer); +#endif +#endif /* GL_ARB_texture_buffer_object */ + +#ifndef GL_ARB_texture_buffer_object_rgb32 +#define GL_ARB_texture_buffer_object_rgb32 1 +#endif /* GL_ARB_texture_buffer_object_rgb32 */ + +#ifndef GL_ARB_texture_buffer_range +#define GL_ARB_texture_buffer_range 1 +#endif /* GL_ARB_texture_buffer_range */ + +#ifndef GL_ARB_texture_compression +#define GL_ARB_texture_compression 1 +#define GL_COMPRESSED_ALPHA_ARB 0x84E9 +#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB +#define GL_COMPRESSED_INTENSITY_ARB 0x84EC +#define GL_COMPRESSED_RGB_ARB 0x84ED +#define GL_COMPRESSED_RGBA_ARB 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 +#define GL_TEXTURE_COMPRESSED_ARB 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, void *img); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); +GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum target, GLint level, void *img); +#endif +#endif /* GL_ARB_texture_compression */ + +#ifndef GL_ARB_texture_compression_bptc +#define GL_ARB_texture_compression_bptc 1 +#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C +#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D +#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E +#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F +#endif /* GL_ARB_texture_compression_bptc */ + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_ARB_texture_compression_rgtc 1 +#endif /* GL_ARB_texture_compression_rgtc */ + +#ifndef GL_ARB_texture_cube_map +#define GL_ARB_texture_cube_map 1 +#define GL_NORMAL_MAP_ARB 0x8511 +#define GL_REFLECTION_MAP_ARB 0x8512 +#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C +#endif /* GL_ARB_texture_cube_map */ + +#ifndef GL_ARB_texture_cube_map_array +#define GL_ARB_texture_cube_map_array 1 +#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F +#endif /* GL_ARB_texture_cube_map_array */ + +#ifndef GL_ARB_texture_env_add +#define GL_ARB_texture_env_add 1 +#endif /* GL_ARB_texture_env_add */ + +#ifndef GL_ARB_texture_env_combine +#define GL_ARB_texture_env_combine 1 +#define GL_COMBINE_ARB 0x8570 +#define GL_COMBINE_RGB_ARB 0x8571 +#define GL_COMBINE_ALPHA_ARB 0x8572 +#define GL_SOURCE0_RGB_ARB 0x8580 +#define GL_SOURCE1_RGB_ARB 0x8581 +#define GL_SOURCE2_RGB_ARB 0x8582 +#define GL_SOURCE0_ALPHA_ARB 0x8588 +#define GL_SOURCE1_ALPHA_ARB 0x8589 +#define GL_SOURCE2_ALPHA_ARB 0x858A +#define GL_OPERAND0_RGB_ARB 0x8590 +#define GL_OPERAND1_RGB_ARB 0x8591 +#define GL_OPERAND2_RGB_ARB 0x8592 +#define GL_OPERAND0_ALPHA_ARB 0x8598 +#define GL_OPERAND1_ALPHA_ARB 0x8599 +#define GL_OPERAND2_ALPHA_ARB 0x859A +#define GL_RGB_SCALE_ARB 0x8573 +#define GL_ADD_SIGNED_ARB 0x8574 +#define GL_INTERPOLATE_ARB 0x8575 +#define GL_SUBTRACT_ARB 0x84E7 +#define GL_CONSTANT_ARB 0x8576 +#define GL_PRIMARY_COLOR_ARB 0x8577 +#define GL_PREVIOUS_ARB 0x8578 +#endif /* GL_ARB_texture_env_combine */ + +#ifndef GL_ARB_texture_env_crossbar +#define GL_ARB_texture_env_crossbar 1 +#endif /* GL_ARB_texture_env_crossbar */ + +#ifndef GL_ARB_texture_env_dot3 +#define GL_ARB_texture_env_dot3 1 +#define GL_DOT3_RGB_ARB 0x86AE +#define GL_DOT3_RGBA_ARB 0x86AF +#endif /* GL_ARB_texture_env_dot3 */ + +#ifndef GL_ARB_texture_filter_anisotropic +#define GL_ARB_texture_filter_anisotropic 1 +#endif /* GL_ARB_texture_filter_anisotropic */ + +#ifndef GL_ARB_texture_filter_minmax +#define GL_ARB_texture_filter_minmax 1 +#define GL_TEXTURE_REDUCTION_MODE_ARB 0x9366 +#define GL_WEIGHTED_AVERAGE_ARB 0x9367 +#endif /* GL_ARB_texture_filter_minmax */ + +#ifndef GL_ARB_texture_float +#define GL_ARB_texture_float 1 +#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 +#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 +#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 +#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 +#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 +#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 +#define GL_RGBA32F_ARB 0x8814 +#define GL_RGB32F_ARB 0x8815 +#define GL_ALPHA32F_ARB 0x8816 +#define GL_INTENSITY32F_ARB 0x8817 +#define GL_LUMINANCE32F_ARB 0x8818 +#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 +#define GL_RGBA16F_ARB 0x881A +#define GL_RGB16F_ARB 0x881B +#define GL_ALPHA16F_ARB 0x881C +#define GL_INTENSITY16F_ARB 0x881D +#define GL_LUMINANCE16F_ARB 0x881E +#define GL_LUMINANCE_ALPHA16F_ARB 0x881F +#endif /* GL_ARB_texture_float */ + +#ifndef GL_ARB_texture_gather +#define GL_ARB_texture_gather 1 +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F +#define GL_MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS_ARB 0x8F9F +#endif /* GL_ARB_texture_gather */ + +#ifndef GL_ARB_texture_mirror_clamp_to_edge +#define GL_ARB_texture_mirror_clamp_to_edge 1 +#endif /* GL_ARB_texture_mirror_clamp_to_edge */ + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_ARB_texture_mirrored_repeat 1 +#define GL_MIRRORED_REPEAT_ARB 0x8370 +#endif /* GL_ARB_texture_mirrored_repeat */ + +#ifndef GL_ARB_texture_multisample +#define GL_ARB_texture_multisample 1 +#endif /* GL_ARB_texture_multisample */ + +#ifndef GL_ARB_texture_non_power_of_two +#define GL_ARB_texture_non_power_of_two 1 +#endif /* GL_ARB_texture_non_power_of_two */ + +#ifndef GL_ARB_texture_query_levels +#define GL_ARB_texture_query_levels 1 +#endif /* GL_ARB_texture_query_levels */ + +#ifndef GL_ARB_texture_query_lod +#define GL_ARB_texture_query_lod 1 +#endif /* GL_ARB_texture_query_lod */ + +#ifndef GL_ARB_texture_rectangle +#define GL_ARB_texture_rectangle 1 +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 +#endif /* GL_ARB_texture_rectangle */ + +#ifndef GL_ARB_texture_rg +#define GL_ARB_texture_rg 1 +#endif /* GL_ARB_texture_rg */ + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_ARB_texture_rgb10_a2ui 1 +#endif /* GL_ARB_texture_rgb10_a2ui */ + +#ifndef GL_ARB_texture_stencil8 +#define GL_ARB_texture_stencil8 1 +#endif /* GL_ARB_texture_stencil8 */ + +#ifndef GL_ARB_texture_storage +#define GL_ARB_texture_storage 1 +#endif /* GL_ARB_texture_storage */ + +#ifndef GL_ARB_texture_storage_multisample +#define GL_ARB_texture_storage_multisample 1 +#endif /* GL_ARB_texture_storage_multisample */ + +#ifndef GL_ARB_texture_swizzle +#define GL_ARB_texture_swizzle 1 +#endif /* GL_ARB_texture_swizzle */ + +#ifndef GL_ARB_texture_view +#define GL_ARB_texture_view 1 +#endif /* GL_ARB_texture_view */ + +#ifndef GL_ARB_timer_query +#define GL_ARB_timer_query 1 +#endif /* GL_ARB_timer_query */ + +#ifndef GL_ARB_transform_feedback2 +#define GL_ARB_transform_feedback2 1 +#endif /* GL_ARB_transform_feedback2 */ + +#ifndef GL_ARB_transform_feedback3 +#define GL_ARB_transform_feedback3 1 +#endif /* GL_ARB_transform_feedback3 */ + +#ifndef GL_ARB_transform_feedback_instanced +#define GL_ARB_transform_feedback_instanced 1 +#endif /* GL_ARB_transform_feedback_instanced */ + +#ifndef GL_ARB_transform_feedback_overflow_query +#define GL_ARB_transform_feedback_overflow_query 1 +#define GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB 0x82EC +#define GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB 0x82ED +#endif /* GL_ARB_transform_feedback_overflow_query */ + +#ifndef GL_ARB_transpose_matrix +#define GL_ARB_transpose_matrix 1 +#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6 +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *m); +GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *m); +GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *m); +GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *m); +#endif +#endif /* GL_ARB_transpose_matrix */ + +#ifndef GL_ARB_uniform_buffer_object +#define GL_ARB_uniform_buffer_object 1 +#endif /* GL_ARB_uniform_buffer_object */ + +#ifndef GL_ARB_vertex_array_bgra +#define GL_ARB_vertex_array_bgra 1 +#endif /* GL_ARB_vertex_array_bgra */ + +#ifndef GL_ARB_vertex_array_object +#define GL_ARB_vertex_array_object 1 +#endif /* GL_ARB_vertex_array_object */ + +#ifndef GL_ARB_vertex_attrib_64bit +#define GL_ARB_vertex_attrib_64bit 1 +#endif /* GL_ARB_vertex_attrib_64bit */ + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_ARB_vertex_attrib_binding 1 +#endif /* GL_ARB_vertex_attrib_binding */ + +#ifndef GL_ARB_vertex_blend +#define GL_ARB_vertex_blend 1 +#define GL_MAX_VERTEX_UNITS_ARB 0x86A4 +#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5 +#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6 +#define GL_VERTEX_BLEND_ARB 0x86A7 +#define GL_CURRENT_WEIGHT_ARB 0x86A8 +#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA +#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB +#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC +#define GL_WEIGHT_ARRAY_ARB 0x86AD +#define GL_MODELVIEW0_ARB 0x1700 +#define GL_MODELVIEW1_ARB 0x850A +#define GL_MODELVIEW2_ARB 0x8722 +#define GL_MODELVIEW3_ARB 0x8723 +#define GL_MODELVIEW4_ARB 0x8724 +#define GL_MODELVIEW5_ARB 0x8725 +#define GL_MODELVIEW6_ARB 0x8726 +#define GL_MODELVIEW7_ARB 0x8727 +#define GL_MODELVIEW8_ARB 0x8728 +#define GL_MODELVIEW9_ARB 0x8729 +#define GL_MODELVIEW10_ARB 0x872A +#define GL_MODELVIEW11_ARB 0x872B +#define GL_MODELVIEW12_ARB 0x872C +#define GL_MODELVIEW13_ARB 0x872D +#define GL_MODELVIEW14_ARB 0x872E +#define GL_MODELVIEW15_ARB 0x872F +#define GL_MODELVIEW16_ARB 0x8730 +#define GL_MODELVIEW17_ARB 0x8731 +#define GL_MODELVIEW18_ARB 0x8732 +#define GL_MODELVIEW19_ARB 0x8733 +#define GL_MODELVIEW20_ARB 0x8734 +#define GL_MODELVIEW21_ARB 0x8735 +#define GL_MODELVIEW22_ARB 0x8736 +#define GL_MODELVIEW23_ARB 0x8737 +#define GL_MODELVIEW24_ARB 0x8738 +#define GL_MODELVIEW25_ARB 0x8739 +#define GL_MODELVIEW26_ARB 0x873A +#define GL_MODELVIEW27_ARB 0x873B +#define GL_MODELVIEW28_ARB 0x873C +#define GL_MODELVIEW29_ARB 0x873D +#define GL_MODELVIEW30_ARB 0x873E +#define GL_MODELVIEW31_ARB 0x873F +typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); +typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); +typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); +typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); +typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); +typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); +typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWeightbvARB (GLint size, const GLbyte *weights); +GLAPI void APIENTRY glWeightsvARB (GLint size, const GLshort *weights); +GLAPI void APIENTRY glWeightivARB (GLint size, const GLint *weights); +GLAPI void APIENTRY glWeightfvARB (GLint size, const GLfloat *weights); +GLAPI void APIENTRY glWeightdvARB (GLint size, const GLdouble *weights); +GLAPI void APIENTRY glWeightubvARB (GLint size, const GLubyte *weights); +GLAPI void APIENTRY glWeightusvARB (GLint size, const GLushort *weights); +GLAPI void APIENTRY glWeightuivARB (GLint size, const GLuint *weights); +GLAPI void APIENTRY glWeightPointerARB (GLint size, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glVertexBlendARB (GLint count); +#endif +#endif /* GL_ARB_vertex_blend */ + +#ifndef GL_ARB_vertex_buffer_object +#define GL_ARB_vertex_buffer_object 1 +typedef khronos_ssize_t GLsizeiptrARB; +typedef khronos_intptr_t GLintptrARB; +#define GL_BUFFER_SIZE_ARB 0x8764 +#define GL_BUFFER_USAGE_ARB 0x8765 +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 +#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F +#define GL_READ_ONLY_ARB 0x88B8 +#define GL_WRITE_ONLY_ARB 0x88B9 +#define GL_READ_WRITE_ARB 0x88BA +#define GL_BUFFER_ACCESS_ARB 0x88BB +#define GL_BUFFER_MAPPED_ARB 0x88BC +#define GL_BUFFER_MAP_POINTER_ARB 0x88BD +#define GL_STREAM_DRAW_ARB 0x88E0 +#define GL_STREAM_READ_ARB 0x88E1 +#define GL_STREAM_COPY_ARB 0x88E2 +#define GL_STATIC_DRAW_ARB 0x88E4 +#define GL_STATIC_READ_ARB 0x88E5 +#define GL_STATIC_COPY_ARB 0x88E6 +#define GL_DYNAMIC_DRAW_ARB 0x88E8 +#define GL_DYNAMIC_READ_ARB 0x88E9 +#define GL_DYNAMIC_COPY_ARB 0x88EA +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const void *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const void *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, void *data); +typedef void *(APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, void **params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffersARB (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBufferARB (GLuint buffer); +GLAPI void APIENTRY glBufferDataARB (GLenum target, GLsizeiptrARB size, const void *data, GLenum usage); +GLAPI void APIENTRY glBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const void *data); +GLAPI void APIENTRY glGetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, void *data); +GLAPI void *APIENTRY glMapBufferARB (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum target); +GLAPI void APIENTRY glGetBufferParameterivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointervARB (GLenum target, GLenum pname, void **params); +#endif +#endif /* GL_ARB_vertex_buffer_object */ + +#ifndef GL_ARB_vertex_program +#define GL_ARB_vertex_program 1 +#define GL_COLOR_SUM_ARB 0x8458 +#define GL_VERTEX_PROGRAM_ARB 0x8620 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 +#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A +#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 +#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 +#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 +#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, void **pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttrib1dARB (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1fARB (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1sARB (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2dARB (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2fARB (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2sARB (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3sARB (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4sARB (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointerARB (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint index); +GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint index); +GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribivARB (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint index, GLenum pname, void **pointer); +#endif +#endif /* GL_ARB_vertex_program */ + +#ifndef GL_ARB_vertex_shader +#define GL_ARB_vertex_shader 1 +#define GL_VERTEX_SHADER_ARB 0x8B31 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A +#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D +#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 +#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name); +GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name); +#endif +#endif /* GL_ARB_vertex_shader */ + +#ifndef GL_ARB_vertex_type_10f_11f_11f_rev +#define GL_ARB_vertex_type_10f_11f_11f_rev 1 +#endif /* GL_ARB_vertex_type_10f_11f_11f_rev */ + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +#define GL_ARB_vertex_type_2_10_10_10_rev 1 +#endif /* GL_ARB_vertex_type_2_10_10_10_rev */ + +#ifndef GL_ARB_viewport_array +#define GL_ARB_viewport_array 1 +typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYDVNVPROC) (GLuint first, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDDNVPROC) (GLuint index, GLdouble n, GLdouble f); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthRangeArraydvNV (GLuint first, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glDepthRangeIndexeddNV (GLuint index, GLdouble n, GLdouble f); +#endif +#endif /* GL_ARB_viewport_array */ + +#ifndef GL_ARB_window_pos +#define GL_ARB_window_pos 1 +typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dARB (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2fARB (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2iARB (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2ivARB (const GLint *v); +GLAPI void APIENTRY glWindowPos2sARB (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2svARB (const GLshort *v); +GLAPI void APIENTRY glWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3iARB (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3ivARB (const GLint *v); +GLAPI void APIENTRY glWindowPos3sARB (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3svARB (const GLshort *v); +#endif +#endif /* GL_ARB_window_pos */ + +#ifndef GL_KHR_blend_equation_advanced +#define GL_KHR_blend_equation_advanced 1 +#define GL_MULTIPLY_KHR 0x9294 +#define GL_SCREEN_KHR 0x9295 +#define GL_OVERLAY_KHR 0x9296 +#define GL_DARKEN_KHR 0x9297 +#define GL_LIGHTEN_KHR 0x9298 +#define GL_COLORDODGE_KHR 0x9299 +#define GL_COLORBURN_KHR 0x929A +#define GL_HARDLIGHT_KHR 0x929B +#define GL_SOFTLIGHT_KHR 0x929C +#define GL_DIFFERENCE_KHR 0x929E +#define GL_EXCLUSION_KHR 0x92A0 +#define GL_HSL_HUE_KHR 0x92AD +#define GL_HSL_SATURATION_KHR 0x92AE +#define GL_HSL_COLOR_KHR 0x92AF +#define GL_HSL_LUMINOSITY_KHR 0x92B0 +typedef void (APIENTRYP PFNGLBLENDBARRIERKHRPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendBarrierKHR (void); +#endif +#endif /* GL_KHR_blend_equation_advanced */ + +#ifndef GL_KHR_blend_equation_advanced_coherent +#define GL_KHR_blend_equation_advanced_coherent 1 +#define GL_BLEND_ADVANCED_COHERENT_KHR 0x9285 +#endif /* GL_KHR_blend_equation_advanced_coherent */ + +#ifndef GL_KHR_context_flush_control +#define GL_KHR_context_flush_control 1 +#endif /* GL_KHR_context_flush_control */ + +#ifndef GL_KHR_debug +#define GL_KHR_debug 1 +#endif /* GL_KHR_debug */ + +#ifndef GL_KHR_no_error +#define GL_KHR_no_error 1 +#define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008 +#endif /* GL_KHR_no_error */ + +#ifndef GL_KHR_parallel_shader_compile +#define GL_KHR_parallel_shader_compile 1 +#define GL_MAX_SHADER_COMPILER_THREADS_KHR 0x91B0 +#define GL_COMPLETION_STATUS_KHR 0x91B1 +typedef void (APIENTRYP PFNGLMAXSHADERCOMPILERTHREADSKHRPROC) (GLuint count); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMaxShaderCompilerThreadsKHR (GLuint count); +#endif +#endif /* GL_KHR_parallel_shader_compile */ + +#ifndef GL_KHR_robust_buffer_access_behavior +#define GL_KHR_robust_buffer_access_behavior 1 +#endif /* GL_KHR_robust_buffer_access_behavior */ + +#ifndef GL_KHR_robustness +#define GL_KHR_robustness 1 +#define GL_CONTEXT_ROBUST_ACCESS 0x90F3 +#endif /* GL_KHR_robustness */ + +#ifndef GL_KHR_shader_subgroup +#define GL_KHR_shader_subgroup 1 +#define GL_SUBGROUP_SIZE_KHR 0x9532 +#define GL_SUBGROUP_SUPPORTED_STAGES_KHR 0x9533 +#define GL_SUBGROUP_SUPPORTED_FEATURES_KHR 0x9534 +#define GL_SUBGROUP_QUAD_ALL_STAGES_KHR 0x9535 +#define GL_SUBGROUP_FEATURE_BASIC_BIT_KHR 0x00000001 +#define GL_SUBGROUP_FEATURE_VOTE_BIT_KHR 0x00000002 +#define GL_SUBGROUP_FEATURE_ARITHMETIC_BIT_KHR 0x00000004 +#define GL_SUBGROUP_FEATURE_BALLOT_BIT_KHR 0x00000008 +#define GL_SUBGROUP_FEATURE_SHUFFLE_BIT_KHR 0x00000010 +#define GL_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT_KHR 0x00000020 +#define GL_SUBGROUP_FEATURE_CLUSTERED_BIT_KHR 0x00000040 +#define GL_SUBGROUP_FEATURE_QUAD_BIT_KHR 0x00000080 +#endif /* GL_KHR_shader_subgroup */ + +#ifndef GL_KHR_texture_compression_astc_hdr +#define GL_KHR_texture_compression_astc_hdr 1 +#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 +#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 +#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD +#endif /* GL_KHR_texture_compression_astc_hdr */ + +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_KHR_texture_compression_astc_ldr 1 +#endif /* GL_KHR_texture_compression_astc_ldr */ + +#ifndef GL_KHR_texture_compression_astc_sliced_3d +#define GL_KHR_texture_compression_astc_sliced_3d 1 +#endif /* GL_KHR_texture_compression_astc_sliced_3d */ + +#ifndef GL_OES_byte_coordinates +#define GL_OES_byte_coordinates 1 +typedef void (APIENTRYP PFNGLMULTITEXCOORD1BOESPROC) (GLenum texture, GLbyte s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1BVOESPROC) (GLenum texture, const GLbyte *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2BOESPROC) (GLenum texture, GLbyte s, GLbyte t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2BVOESPROC) (GLenum texture, const GLbyte *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3BOESPROC) (GLenum texture, GLbyte s, GLbyte t, GLbyte r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3BVOESPROC) (GLenum texture, const GLbyte *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4BOESPROC) (GLenum texture, GLbyte s, GLbyte t, GLbyte r, GLbyte q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4BVOESPROC) (GLenum texture, const GLbyte *coords); +typedef void (APIENTRYP PFNGLTEXCOORD1BOESPROC) (GLbyte s); +typedef void (APIENTRYP PFNGLTEXCOORD1BVOESPROC) (const GLbyte *coords); +typedef void (APIENTRYP PFNGLTEXCOORD2BOESPROC) (GLbyte s, GLbyte t); +typedef void (APIENTRYP PFNGLTEXCOORD2BVOESPROC) (const GLbyte *coords); +typedef void (APIENTRYP PFNGLTEXCOORD3BOESPROC) (GLbyte s, GLbyte t, GLbyte r); +typedef void (APIENTRYP PFNGLTEXCOORD3BVOESPROC) (const GLbyte *coords); +typedef void (APIENTRYP PFNGLTEXCOORD4BOESPROC) (GLbyte s, GLbyte t, GLbyte r, GLbyte q); +typedef void (APIENTRYP PFNGLTEXCOORD4BVOESPROC) (const GLbyte *coords); +typedef void (APIENTRYP PFNGLVERTEX2BOESPROC) (GLbyte x, GLbyte y); +typedef void (APIENTRYP PFNGLVERTEX2BVOESPROC) (const GLbyte *coords); +typedef void (APIENTRYP PFNGLVERTEX3BOESPROC) (GLbyte x, GLbyte y, GLbyte z); +typedef void (APIENTRYP PFNGLVERTEX3BVOESPROC) (const GLbyte *coords); +typedef void (APIENTRYP PFNGLVERTEX4BOESPROC) (GLbyte x, GLbyte y, GLbyte z, GLbyte w); +typedef void (APIENTRYP PFNGLVERTEX4BVOESPROC) (const GLbyte *coords); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiTexCoord1bOES (GLenum texture, GLbyte s); +GLAPI void APIENTRY glMultiTexCoord1bvOES (GLenum texture, const GLbyte *coords); +GLAPI void APIENTRY glMultiTexCoord2bOES (GLenum texture, GLbyte s, GLbyte t); +GLAPI void APIENTRY glMultiTexCoord2bvOES (GLenum texture, const GLbyte *coords); +GLAPI void APIENTRY glMultiTexCoord3bOES (GLenum texture, GLbyte s, GLbyte t, GLbyte r); +GLAPI void APIENTRY glMultiTexCoord3bvOES (GLenum texture, const GLbyte *coords); +GLAPI void APIENTRY glMultiTexCoord4bOES (GLenum texture, GLbyte s, GLbyte t, GLbyte r, GLbyte q); +GLAPI void APIENTRY glMultiTexCoord4bvOES (GLenum texture, const GLbyte *coords); +GLAPI void APIENTRY glTexCoord1bOES (GLbyte s); +GLAPI void APIENTRY glTexCoord1bvOES (const GLbyte *coords); +GLAPI void APIENTRY glTexCoord2bOES (GLbyte s, GLbyte t); +GLAPI void APIENTRY glTexCoord2bvOES (const GLbyte *coords); +GLAPI void APIENTRY glTexCoord3bOES (GLbyte s, GLbyte t, GLbyte r); +GLAPI void APIENTRY glTexCoord3bvOES (const GLbyte *coords); +GLAPI void APIENTRY glTexCoord4bOES (GLbyte s, GLbyte t, GLbyte r, GLbyte q); +GLAPI void APIENTRY glTexCoord4bvOES (const GLbyte *coords); +GLAPI void APIENTRY glVertex2bOES (GLbyte x, GLbyte y); +GLAPI void APIENTRY glVertex2bvOES (const GLbyte *coords); +GLAPI void APIENTRY glVertex3bOES (GLbyte x, GLbyte y, GLbyte z); +GLAPI void APIENTRY glVertex3bvOES (const GLbyte *coords); +GLAPI void APIENTRY glVertex4bOES (GLbyte x, GLbyte y, GLbyte z, GLbyte w); +GLAPI void APIENTRY glVertex4bvOES (const GLbyte *coords); +#endif +#endif /* GL_OES_byte_coordinates */ + +#ifndef GL_OES_compressed_paletted_texture +#define GL_OES_compressed_paletted_texture 1 +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif /* GL_OES_compressed_paletted_texture */ + +#ifndef GL_OES_fixed_point +#define GL_OES_fixed_point 1 +typedef khronos_int32_t GLfixed; +#define GL_FIXED_OES 0x140C +typedef void (APIENTRYP PFNGLALPHAFUNCXOESPROC) (GLenum func, GLfixed ref); +typedef void (APIENTRYP PFNGLCLEARCOLORXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef void (APIENTRYP PFNGLCLEARDEPTHXOESPROC) (GLfixed depth); +typedef void (APIENTRYP PFNGLCLIPPLANEXOESPROC) (GLenum plane, const GLfixed *equation); +typedef void (APIENTRYP PFNGLCOLOR4XOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef void (APIENTRYP PFNGLDEPTHRANGEXOESPROC) (GLfixed n, GLfixed f); +typedef void (APIENTRYP PFNGLFOGXOESPROC) (GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLFOGXVOESPROC) (GLenum pname, const GLfixed *param); +typedef void (APIENTRYP PFNGLFRUSTUMXOESPROC) (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f); +typedef void (APIENTRYP PFNGLGETCLIPPLANEXOESPROC) (GLenum plane, GLfixed *equation); +typedef void (APIENTRYP PFNGLGETFIXEDVOESPROC) (GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLGETTEXENVXVOESPROC) (GLenum target, GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLLIGHTMODELXOESPROC) (GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLLIGHTMODELXVOESPROC) (GLenum pname, const GLfixed *param); +typedef void (APIENTRYP PFNGLLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLLIGHTXVOESPROC) (GLenum light, GLenum pname, const GLfixed *params); +typedef void (APIENTRYP PFNGLLINEWIDTHXOESPROC) (GLfixed width); +typedef void (APIENTRYP PFNGLLOADMATRIXXOESPROC) (const GLfixed *m); +typedef void (APIENTRYP PFNGLMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLMATERIALXVOESPROC) (GLenum face, GLenum pname, const GLfixed *param); +typedef void (APIENTRYP PFNGLMULTMATRIXXOESPROC) (const GLfixed *m); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4XOESPROC) (GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +typedef void (APIENTRYP PFNGLNORMAL3XOESPROC) (GLfixed nx, GLfixed ny, GLfixed nz); +typedef void (APIENTRYP PFNGLORTHOXOESPROC) (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f); +typedef void (APIENTRYP PFNGLPOINTPARAMETERXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (APIENTRYP PFNGLPOINTSIZEXOESPROC) (GLfixed size); +typedef void (APIENTRYP PFNGLPOLYGONOFFSETXOESPROC) (GLfixed factor, GLfixed units); +typedef void (APIENTRYP PFNGLROTATEXOESPROC) (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +typedef void (APIENTRYP PFNGLSCALEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +typedef void (APIENTRYP PFNGLTEXENVXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLTEXENVXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (APIENTRYP PFNGLTRANSLATEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +typedef void (APIENTRYP PFNGLACCUMXOESPROC) (GLenum op, GLfixed value); +typedef void (APIENTRYP PFNGLBITMAPXOESPROC) (GLsizei width, GLsizei height, GLfixed xorig, GLfixed yorig, GLfixed xmove, GLfixed ymove, const GLubyte *bitmap); +typedef void (APIENTRYP PFNGLBLENDCOLORXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef void (APIENTRYP PFNGLCLEARACCUMXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef void (APIENTRYP PFNGLCOLOR3XOESPROC) (GLfixed red, GLfixed green, GLfixed blue); +typedef void (APIENTRYP PFNGLCOLOR3XVOESPROC) (const GLfixed *components); +typedef void (APIENTRYP PFNGLCOLOR4XVOESPROC) (const GLfixed *components); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (APIENTRYP PFNGLEVALCOORD1XOESPROC) (GLfixed u); +typedef void (APIENTRYP PFNGLEVALCOORD1XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLEVALCOORD2XOESPROC) (GLfixed u, GLfixed v); +typedef void (APIENTRYP PFNGLEVALCOORD2XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLFEEDBACKBUFFERXOESPROC) (GLsizei n, GLenum type, const GLfixed *buffer); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLGETLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLGETMAPXVOESPROC) (GLenum target, GLenum query, GLfixed *v); +typedef void (APIENTRYP PFNGLGETMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLGETPIXELMAPXVPROC) (GLenum map, GLint size, GLfixed *values); +typedef void (APIENTRYP PFNGLGETTEXGENXVOESPROC) (GLenum coord, GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERXVOESPROC) (GLenum target, GLint level, GLenum pname, GLfixed *params); +typedef void (APIENTRYP PFNGLINDEXXOESPROC) (GLfixed component); +typedef void (APIENTRYP PFNGLINDEXXVOESPROC) (const GLfixed *component); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXXOESPROC) (const GLfixed *m); +typedef void (APIENTRYP PFNGLMAP1XOESPROC) (GLenum target, GLfixed u1, GLfixed u2, GLint stride, GLint order, GLfixed points); +typedef void (APIENTRYP PFNGLMAP2XOESPROC) (GLenum target, GLfixed u1, GLfixed u2, GLint ustride, GLint uorder, GLfixed v1, GLfixed v2, GLint vstride, GLint vorder, GLfixed points); +typedef void (APIENTRYP PFNGLMAPGRID1XOESPROC) (GLint n, GLfixed u1, GLfixed u2); +typedef void (APIENTRYP PFNGLMAPGRID2XOESPROC) (GLint n, GLfixed u1, GLfixed u2, GLfixed v1, GLfixed v2); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXXOESPROC) (const GLfixed *m); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1XOESPROC) (GLenum texture, GLfixed s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1XVOESPROC) (GLenum texture, const GLfixed *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2XOESPROC) (GLenum texture, GLfixed s, GLfixed t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2XVOESPROC) (GLenum texture, const GLfixed *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3XOESPROC) (GLenum texture, GLfixed s, GLfixed t, GLfixed r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3XVOESPROC) (GLenum texture, const GLfixed *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4XVOESPROC) (GLenum texture, const GLfixed *coords); +typedef void (APIENTRYP PFNGLNORMAL3XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLPASSTHROUGHXOESPROC) (GLfixed token); +typedef void (APIENTRYP PFNGLPIXELMAPXPROC) (GLenum map, GLint size, const GLfixed *values); +typedef void (APIENTRYP PFNGLPIXELSTOREXPROC) (GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLPIXELTRANSFERXOESPROC) (GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLPIXELZOOMXOESPROC) (GLfixed xfactor, GLfixed yfactor); +typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESXOESPROC) (GLsizei n, const GLuint *textures, const GLfixed *priorities); +typedef void (APIENTRYP PFNGLRASTERPOS2XOESPROC) (GLfixed x, GLfixed y); +typedef void (APIENTRYP PFNGLRASTERPOS2XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLRASTERPOS3XOESPROC) (GLfixed x, GLfixed y, GLfixed z); +typedef void (APIENTRYP PFNGLRASTERPOS3XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLRASTERPOS4XOESPROC) (GLfixed x, GLfixed y, GLfixed z, GLfixed w); +typedef void (APIENTRYP PFNGLRASTERPOS4XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLRECTXOESPROC) (GLfixed x1, GLfixed y1, GLfixed x2, GLfixed y2); +typedef void (APIENTRYP PFNGLRECTXVOESPROC) (const GLfixed *v1, const GLfixed *v2); +typedef void (APIENTRYP PFNGLTEXCOORD1XOESPROC) (GLfixed s); +typedef void (APIENTRYP PFNGLTEXCOORD1XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLTEXCOORD2XOESPROC) (GLfixed s, GLfixed t); +typedef void (APIENTRYP PFNGLTEXCOORD2XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLTEXCOORD3XOESPROC) (GLfixed s, GLfixed t, GLfixed r); +typedef void (APIENTRYP PFNGLTEXCOORD3XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLTEXCOORD4XOESPROC) (GLfixed s, GLfixed t, GLfixed r, GLfixed q); +typedef void (APIENTRYP PFNGLTEXCOORD4XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLTEXGENXOESPROC) (GLenum coord, GLenum pname, GLfixed param); +typedef void (APIENTRYP PFNGLTEXGENXVOESPROC) (GLenum coord, GLenum pname, const GLfixed *params); +typedef void (APIENTRYP PFNGLVERTEX2XOESPROC) (GLfixed x); +typedef void (APIENTRYP PFNGLVERTEX2XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLVERTEX3XOESPROC) (GLfixed x, GLfixed y); +typedef void (APIENTRYP PFNGLVERTEX3XVOESPROC) (const GLfixed *coords); +typedef void (APIENTRYP PFNGLVERTEX4XOESPROC) (GLfixed x, GLfixed y, GLfixed z); +typedef void (APIENTRYP PFNGLVERTEX4XVOESPROC) (const GLfixed *coords); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAlphaFuncxOES (GLenum func, GLfixed ref); +GLAPI void APIENTRY glClearColorxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GLAPI void APIENTRY glClearDepthxOES (GLfixed depth); +GLAPI void APIENTRY glClipPlanexOES (GLenum plane, const GLfixed *equation); +GLAPI void APIENTRY glColor4xOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GLAPI void APIENTRY glDepthRangexOES (GLfixed n, GLfixed f); +GLAPI void APIENTRY glFogxOES (GLenum pname, GLfixed param); +GLAPI void APIENTRY glFogxvOES (GLenum pname, const GLfixed *param); +GLAPI void APIENTRY glFrustumxOES (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f); +GLAPI void APIENTRY glGetClipPlanexOES (GLenum plane, GLfixed *equation); +GLAPI void APIENTRY glGetFixedvOES (GLenum pname, GLfixed *params); +GLAPI void APIENTRY glGetTexEnvxvOES (GLenum target, GLenum pname, GLfixed *params); +GLAPI void APIENTRY glGetTexParameterxvOES (GLenum target, GLenum pname, GLfixed *params); +GLAPI void APIENTRY glLightModelxOES (GLenum pname, GLfixed param); +GLAPI void APIENTRY glLightModelxvOES (GLenum pname, const GLfixed *param); +GLAPI void APIENTRY glLightxOES (GLenum light, GLenum pname, GLfixed param); +GLAPI void APIENTRY glLightxvOES (GLenum light, GLenum pname, const GLfixed *params); +GLAPI void APIENTRY glLineWidthxOES (GLfixed width); +GLAPI void APIENTRY glLoadMatrixxOES (const GLfixed *m); +GLAPI void APIENTRY glMaterialxOES (GLenum face, GLenum pname, GLfixed param); +GLAPI void APIENTRY glMaterialxvOES (GLenum face, GLenum pname, const GLfixed *param); +GLAPI void APIENTRY glMultMatrixxOES (const GLfixed *m); +GLAPI void APIENTRY glMultiTexCoord4xOES (GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GLAPI void APIENTRY glNormal3xOES (GLfixed nx, GLfixed ny, GLfixed nz); +GLAPI void APIENTRY glOrthoxOES (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f); +GLAPI void APIENTRY glPointParameterxvOES (GLenum pname, const GLfixed *params); +GLAPI void APIENTRY glPointSizexOES (GLfixed size); +GLAPI void APIENTRY glPolygonOffsetxOES (GLfixed factor, GLfixed units); +GLAPI void APIENTRY glRotatexOES (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +GLAPI void APIENTRY glScalexOES (GLfixed x, GLfixed y, GLfixed z); +GLAPI void APIENTRY glTexEnvxOES (GLenum target, GLenum pname, GLfixed param); +GLAPI void APIENTRY glTexEnvxvOES (GLenum target, GLenum pname, const GLfixed *params); +GLAPI void APIENTRY glTexParameterxOES (GLenum target, GLenum pname, GLfixed param); +GLAPI void APIENTRY glTexParameterxvOES (GLenum target, GLenum pname, const GLfixed *params); +GLAPI void APIENTRY glTranslatexOES (GLfixed x, GLfixed y, GLfixed z); +GLAPI void APIENTRY glAccumxOES (GLenum op, GLfixed value); +GLAPI void APIENTRY glBitmapxOES (GLsizei width, GLsizei height, GLfixed xorig, GLfixed yorig, GLfixed xmove, GLfixed ymove, const GLubyte *bitmap); +GLAPI void APIENTRY glBlendColorxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GLAPI void APIENTRY glClearAccumxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GLAPI void APIENTRY glColor3xOES (GLfixed red, GLfixed green, GLfixed blue); +GLAPI void APIENTRY glColor3xvOES (const GLfixed *components); +GLAPI void APIENTRY glColor4xvOES (const GLfixed *components); +GLAPI void APIENTRY glConvolutionParameterxOES (GLenum target, GLenum pname, GLfixed param); +GLAPI void APIENTRY glConvolutionParameterxvOES (GLenum target, GLenum pname, const GLfixed *params); +GLAPI void APIENTRY glEvalCoord1xOES (GLfixed u); +GLAPI void APIENTRY glEvalCoord1xvOES (const GLfixed *coords); +GLAPI void APIENTRY glEvalCoord2xOES (GLfixed u, GLfixed v); +GLAPI void APIENTRY glEvalCoord2xvOES (const GLfixed *coords); +GLAPI void APIENTRY glFeedbackBufferxOES (GLsizei n, GLenum type, const GLfixed *buffer); +GLAPI void APIENTRY glGetConvolutionParameterxvOES (GLenum target, GLenum pname, GLfixed *params); +GLAPI void APIENTRY glGetHistogramParameterxvOES (GLenum target, GLenum pname, GLfixed *params); +GLAPI void APIENTRY glGetLightxOES (GLenum light, GLenum pname, GLfixed *params); +GLAPI void APIENTRY glGetMapxvOES (GLenum target, GLenum query, GLfixed *v); +GLAPI void APIENTRY glGetMaterialxOES (GLenum face, GLenum pname, GLfixed param); +GLAPI void APIENTRY glGetPixelMapxv (GLenum map, GLint size, GLfixed *values); +GLAPI void APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params); +GLAPI void APIENTRY glGetTexLevelParameterxvOES (GLenum target, GLint level, GLenum pname, GLfixed *params); +GLAPI void APIENTRY glIndexxOES (GLfixed component); +GLAPI void APIENTRY glIndexxvOES (const GLfixed *component); +GLAPI void APIENTRY glLoadTransposeMatrixxOES (const GLfixed *m); +GLAPI void APIENTRY glMap1xOES (GLenum target, GLfixed u1, GLfixed u2, GLint stride, GLint order, GLfixed points); +GLAPI void APIENTRY glMap2xOES (GLenum target, GLfixed u1, GLfixed u2, GLint ustride, GLint uorder, GLfixed v1, GLfixed v2, GLint vstride, GLint vorder, GLfixed points); +GLAPI void APIENTRY glMapGrid1xOES (GLint n, GLfixed u1, GLfixed u2); +GLAPI void APIENTRY glMapGrid2xOES (GLint n, GLfixed u1, GLfixed u2, GLfixed v1, GLfixed v2); +GLAPI void APIENTRY glMultTransposeMatrixxOES (const GLfixed *m); +GLAPI void APIENTRY glMultiTexCoord1xOES (GLenum texture, GLfixed s); +GLAPI void APIENTRY glMultiTexCoord1xvOES (GLenum texture, const GLfixed *coords); +GLAPI void APIENTRY glMultiTexCoord2xOES (GLenum texture, GLfixed s, GLfixed t); +GLAPI void APIENTRY glMultiTexCoord2xvOES (GLenum texture, const GLfixed *coords); +GLAPI void APIENTRY glMultiTexCoord3xOES (GLenum texture, GLfixed s, GLfixed t, GLfixed r); +GLAPI void APIENTRY glMultiTexCoord3xvOES (GLenum texture, const GLfixed *coords); +GLAPI void APIENTRY glMultiTexCoord4xvOES (GLenum texture, const GLfixed *coords); +GLAPI void APIENTRY glNormal3xvOES (const GLfixed *coords); +GLAPI void APIENTRY glPassThroughxOES (GLfixed token); +GLAPI void APIENTRY glPixelMapx (GLenum map, GLint size, const GLfixed *values); +GLAPI void APIENTRY glPixelStorex (GLenum pname, GLfixed param); +GLAPI void APIENTRY glPixelTransferxOES (GLenum pname, GLfixed param); +GLAPI void APIENTRY glPixelZoomxOES (GLfixed xfactor, GLfixed yfactor); +GLAPI void APIENTRY glPrioritizeTexturesxOES (GLsizei n, const GLuint *textures, const GLfixed *priorities); +GLAPI void APIENTRY glRasterPos2xOES (GLfixed x, GLfixed y); +GLAPI void APIENTRY glRasterPos2xvOES (const GLfixed *coords); +GLAPI void APIENTRY glRasterPos3xOES (GLfixed x, GLfixed y, GLfixed z); +GLAPI void APIENTRY glRasterPos3xvOES (const GLfixed *coords); +GLAPI void APIENTRY glRasterPos4xOES (GLfixed x, GLfixed y, GLfixed z, GLfixed w); +GLAPI void APIENTRY glRasterPos4xvOES (const GLfixed *coords); +GLAPI void APIENTRY glRectxOES (GLfixed x1, GLfixed y1, GLfixed x2, GLfixed y2); +GLAPI void APIENTRY glRectxvOES (const GLfixed *v1, const GLfixed *v2); +GLAPI void APIENTRY glTexCoord1xOES (GLfixed s); +GLAPI void APIENTRY glTexCoord1xvOES (const GLfixed *coords); +GLAPI void APIENTRY glTexCoord2xOES (GLfixed s, GLfixed t); +GLAPI void APIENTRY glTexCoord2xvOES (const GLfixed *coords); +GLAPI void APIENTRY glTexCoord3xOES (GLfixed s, GLfixed t, GLfixed r); +GLAPI void APIENTRY glTexCoord3xvOES (const GLfixed *coords); +GLAPI void APIENTRY glTexCoord4xOES (GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GLAPI void APIENTRY glTexCoord4xvOES (const GLfixed *coords); +GLAPI void APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param); +GLAPI void APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params); +GLAPI void APIENTRY glVertex2xOES (GLfixed x); +GLAPI void APIENTRY glVertex2xvOES (const GLfixed *coords); +GLAPI void APIENTRY glVertex3xOES (GLfixed x, GLfixed y); +GLAPI void APIENTRY glVertex3xvOES (const GLfixed *coords); +GLAPI void APIENTRY glVertex4xOES (GLfixed x, GLfixed y, GLfixed z); +GLAPI void APIENTRY glVertex4xvOES (const GLfixed *coords); +#endif +#endif /* GL_OES_fixed_point */ + +#ifndef GL_OES_query_matrix +#define GL_OES_query_matrix 1 +typedef GLbitfield (APIENTRYP PFNGLQUERYMATRIXXOESPROC) (GLfixed *mantissa, GLint *exponent); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLbitfield APIENTRY glQueryMatrixxOES (GLfixed *mantissa, GLint *exponent); +#endif +#endif /* GL_OES_query_matrix */ + +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif /* GL_OES_read_format */ + +#ifndef GL_OES_single_precision +#define GL_OES_single_precision 1 +typedef void (APIENTRYP PFNGLCLEARDEPTHFOESPROC) (GLclampf depth); +typedef void (APIENTRYP PFNGLCLIPPLANEFOESPROC) (GLenum plane, const GLfloat *equation); +typedef void (APIENTRYP PFNGLDEPTHRANGEFOESPROC) (GLclampf n, GLclampf f); +typedef void (APIENTRYP PFNGLFRUSTUMFOESPROC) (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f); +typedef void (APIENTRYP PFNGLGETCLIPPLANEFOESPROC) (GLenum plane, GLfloat *equation); +typedef void (APIENTRYP PFNGLORTHOFOESPROC) (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClearDepthfOES (GLclampf depth); +GLAPI void APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation); +GLAPI void APIENTRY glDepthRangefOES (GLclampf n, GLclampf f); +GLAPI void APIENTRY glFrustumfOES (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f); +GLAPI void APIENTRY glGetClipPlanefOES (GLenum plane, GLfloat *equation); +GLAPI void APIENTRY glOrthofOES (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f); +#endif +#endif /* GL_OES_single_precision */ + +#ifndef GL_3DFX_multisample +#define GL_3DFX_multisample 1 +#define GL_MULTISAMPLE_3DFX 0x86B2 +#define GL_SAMPLE_BUFFERS_3DFX 0x86B3 +#define GL_SAMPLES_3DFX 0x86B4 +#define GL_MULTISAMPLE_BIT_3DFX 0x20000000 +#endif /* GL_3DFX_multisample */ + +#ifndef GL_3DFX_tbuffer +#define GL_3DFX_tbuffer 1 +typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTbufferMask3DFX (GLuint mask); +#endif +#endif /* GL_3DFX_tbuffer */ + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_3DFX_texture_compression_FXT1 1 +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 +#endif /* GL_3DFX_texture_compression_FXT1 */ + +#ifndef GL_AMD_blend_minmax_factor +#define GL_AMD_blend_minmax_factor 1 +#define GL_FACTOR_MIN_AMD 0x901C +#define GL_FACTOR_MAX_AMD 0x901D +#endif /* GL_AMD_blend_minmax_factor */ + +#ifndef GL_AMD_conservative_depth +#define GL_AMD_conservative_depth 1 +#endif /* GL_AMD_conservative_depth */ + +#ifndef GL_AMD_debug_output +#define GL_AMD_debug_output 1 +typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,void *userParam); +#define GL_MAX_DEBUG_MESSAGE_LENGTH_AMD 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES_AMD 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_AMD 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_AMD 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_AMD 0x9147 +#define GL_DEBUG_SEVERITY_LOW_AMD 0x9148 +#define GL_DEBUG_CATEGORY_API_ERROR_AMD 0x9149 +#define GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD 0x914A +#define GL_DEBUG_CATEGORY_DEPRECATION_AMD 0x914B +#define GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD 0x914C +#define GL_DEBUG_CATEGORY_PERFORMANCE_AMD 0x914D +#define GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD 0x914E +#define GL_DEBUG_CATEGORY_APPLICATION_AMD 0x914F +#define GL_DEBUG_CATEGORY_OTHER_AMD 0x9150 +typedef void (APIENTRYP PFNGLDEBUGMESSAGEENABLEAMDPROC) (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTAMDPROC) (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, void *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGAMDPROC) (GLuint count, GLsizei bufSize, GLenum *categories, GLenum *severities, GLuint *ids, GLsizei *lengths, GLchar *message); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDebugMessageEnableAMD (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertAMD (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackAMD (GLDEBUGPROCAMD callback, void *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogAMD (GLuint count, GLsizei bufSize, GLenum *categories, GLenum *severities, GLuint *ids, GLsizei *lengths, GLchar *message); +#endif +#endif /* GL_AMD_debug_output */ + +#ifndef GL_AMD_depth_clamp_separate +#define GL_AMD_depth_clamp_separate 1 +#define GL_DEPTH_CLAMP_NEAR_AMD 0x901E +#define GL_DEPTH_CLAMP_FAR_AMD 0x901F +#endif /* GL_AMD_depth_clamp_separate */ + +#ifndef GL_AMD_draw_buffers_blend +#define GL_AMD_draw_buffers_blend 1 +typedef void (APIENTRYP PFNGLBLENDFUNCINDEXEDAMDPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONINDEXEDAMDPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncIndexedAMD (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateIndexedAMD (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GLAPI void APIENTRY glBlendEquationIndexedAMD (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateIndexedAMD (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +#endif +#endif /* GL_AMD_draw_buffers_blend */ + +#ifndef GL_AMD_framebuffer_multisample_advanced +#define GL_AMD_framebuffer_multisample_advanced 1 +#define GL_RENDERBUFFER_STORAGE_SAMPLES_AMD 0x91B2 +#define GL_MAX_COLOR_FRAMEBUFFER_SAMPLES_AMD 0x91B3 +#define GL_MAX_COLOR_FRAMEBUFFER_STORAGE_SAMPLES_AMD 0x91B4 +#define GL_MAX_DEPTH_STENCIL_FRAMEBUFFER_SAMPLES_AMD 0x91B5 +#define GL_NUM_SUPPORTED_MULTISAMPLE_MODES_AMD 0x91B6 +#define GL_SUPPORTED_MULTISAMPLE_MODES_AMD 0x91B7 +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEADVANCEDAMDPROC) (GLenum target, GLsizei samples, GLsizei storageSamples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEADVANCEDAMDPROC) (GLuint renderbuffer, GLsizei samples, GLsizei storageSamples, GLenum internalformat, GLsizei width, GLsizei height); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleAdvancedAMD (GLenum target, GLsizei samples, GLsizei storageSamples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleAdvancedAMD (GLuint renderbuffer, GLsizei samples, GLsizei storageSamples, GLenum internalformat, GLsizei width, GLsizei height); +#endif +#endif /* GL_AMD_framebuffer_multisample_advanced */ + +#ifndef GL_AMD_framebuffer_sample_positions +#define GL_AMD_framebuffer_sample_positions 1 +#define GL_SUBSAMPLE_DISTANCE_AMD 0x883F +#define GL_PIXELS_PER_SAMPLE_PATTERN_X_AMD 0x91AE +#define GL_PIXELS_PER_SAMPLE_PATTERN_Y_AMD 0x91AF +#define GL_ALL_PIXELS_AMD 0xFFFFFFFF +typedef void (APIENTRYP PFNGLFRAMEBUFFERSAMPLEPOSITIONSFVAMDPROC) (GLenum target, GLuint numsamples, GLuint pixelindex, const GLfloat *values); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERSAMPLEPOSITIONSFVAMDPROC) (GLuint framebuffer, GLuint numsamples, GLuint pixelindex, const GLfloat *values); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERFVAMDPROC) (GLenum target, GLenum pname, GLuint numsamples, GLuint pixelindex, GLsizei size, GLfloat *values); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERFVAMDPROC) (GLuint framebuffer, GLenum pname, GLuint numsamples, GLuint pixelindex, GLsizei size, GLfloat *values); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferSamplePositionsfvAMD (GLenum target, GLuint numsamples, GLuint pixelindex, const GLfloat *values); +GLAPI void APIENTRY glNamedFramebufferSamplePositionsfvAMD (GLuint framebuffer, GLuint numsamples, GLuint pixelindex, const GLfloat *values); +GLAPI void APIENTRY glGetFramebufferParameterfvAMD (GLenum target, GLenum pname, GLuint numsamples, GLuint pixelindex, GLsizei size, GLfloat *values); +GLAPI void APIENTRY glGetNamedFramebufferParameterfvAMD (GLuint framebuffer, GLenum pname, GLuint numsamples, GLuint pixelindex, GLsizei size, GLfloat *values); +#endif +#endif /* GL_AMD_framebuffer_sample_positions */ + +#ifndef GL_AMD_gcn_shader +#define GL_AMD_gcn_shader 1 +#endif /* GL_AMD_gcn_shader */ + +#ifndef GL_AMD_gpu_shader_half_float +#define GL_AMD_gpu_shader_half_float 1 +#define GL_FLOAT16_NV 0x8FF8 +#define GL_FLOAT16_VEC2_NV 0x8FF9 +#define GL_FLOAT16_VEC3_NV 0x8FFA +#define GL_FLOAT16_VEC4_NV 0x8FFB +#define GL_FLOAT16_MAT2_AMD 0x91C5 +#define GL_FLOAT16_MAT3_AMD 0x91C6 +#define GL_FLOAT16_MAT4_AMD 0x91C7 +#define GL_FLOAT16_MAT2x3_AMD 0x91C8 +#define GL_FLOAT16_MAT2x4_AMD 0x91C9 +#define GL_FLOAT16_MAT3x2_AMD 0x91CA +#define GL_FLOAT16_MAT3x4_AMD 0x91CB +#define GL_FLOAT16_MAT4x2_AMD 0x91CC +#define GL_FLOAT16_MAT4x3_AMD 0x91CD +#endif /* GL_AMD_gpu_shader_half_float */ + +#ifndef GL_AMD_gpu_shader_int16 +#define GL_AMD_gpu_shader_int16 1 +#endif /* GL_AMD_gpu_shader_int16 */ + +#ifndef GL_AMD_gpu_shader_int64 +#define GL_AMD_gpu_shader_int64 1 +typedef khronos_int64_t GLint64EXT; +#define GL_INT64_NV 0x140E +#define GL_UNSIGNED_INT64_NV 0x140F +#define GL_INT8_NV 0x8FE0 +#define GL_INT8_VEC2_NV 0x8FE1 +#define GL_INT8_VEC3_NV 0x8FE2 +#define GL_INT8_VEC4_NV 0x8FE3 +#define GL_INT16_NV 0x8FE4 +#define GL_INT16_VEC2_NV 0x8FE5 +#define GL_INT16_VEC3_NV 0x8FE6 +#define GL_INT16_VEC4_NV 0x8FE7 +#define GL_INT64_VEC2_NV 0x8FE9 +#define GL_INT64_VEC3_NV 0x8FEA +#define GL_INT64_VEC4_NV 0x8FEB +#define GL_UNSIGNED_INT8_NV 0x8FEC +#define GL_UNSIGNED_INT8_VEC2_NV 0x8FED +#define GL_UNSIGNED_INT8_VEC3_NV 0x8FEE +#define GL_UNSIGNED_INT8_VEC4_NV 0x8FEF +#define GL_UNSIGNED_INT16_NV 0x8FF0 +#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1 +#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2 +#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3 +#define GL_UNSIGNED_INT64_VEC2_NV 0x8FF5 +#define GL_UNSIGNED_INT64_VEC3_NV 0x8FF6 +#define GL_UNSIGNED_INT64_VEC4_NV 0x8FF7 +typedef void (APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x); +typedef void (APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM1UI64NVPROC) (GLint location, GLuint64EXT x); +typedef void (APIENTRYP PFNGLUNIFORM2UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLUNIFORM3UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLUNIFORM4UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLUNIFORM1UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM2UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM3UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM4UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLGETUNIFORMI64VNVPROC) (GLuint program, GLint location, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64NVPROC) (GLuint program, GLint location, GLint64EXT x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniform1i64NV (GLint location, GLint64EXT x); +GLAPI void APIENTRY glUniform2i64NV (GLint location, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glUniform3i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glUniform4i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glUniform1i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform2i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform3i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform4i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform1ui64NV (GLint location, GLuint64EXT x); +GLAPI void APIENTRY glUniform2ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glUniform3ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glUniform4ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glUniform1ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform2ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform3ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform4ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glGetUniformi64vNV (GLuint program, GLint location, GLint64EXT *params); +GLAPI void APIENTRY glGetUniformui64vNV (GLuint program, GLint location, GLuint64EXT *params); +GLAPI void APIENTRY glProgramUniform1i64NV (GLuint program, GLint location, GLint64EXT x); +GLAPI void APIENTRY glProgramUniform2i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glProgramUniform3i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glProgramUniform4i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glProgramUniform1i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform2i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform3i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform4i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform1ui64NV (GLuint program, GLint location, GLuint64EXT x); +GLAPI void APIENTRY glProgramUniform2ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glProgramUniform3ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glProgramUniform4ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glProgramUniform1ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform2ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform3ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform4ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif +#endif /* GL_AMD_gpu_shader_int64 */ + +#ifndef GL_AMD_interleaved_elements +#define GL_AMD_interleaved_elements 1 +#define GL_VERTEX_ELEMENT_SWIZZLE_AMD 0x91A4 +#define GL_VERTEX_ID_SWIZZLE_AMD 0x91A5 +typedef void (APIENTRYP PFNGLVERTEXATTRIBPARAMETERIAMDPROC) (GLuint index, GLenum pname, GLint param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribParameteriAMD (GLuint index, GLenum pname, GLint param); +#endif +#endif /* GL_AMD_interleaved_elements */ + +#ifndef GL_AMD_multi_draw_indirect +#define GL_AMD_multi_draw_indirect 1 +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTAMDPROC) (GLenum mode, const void *indirect, GLsizei primcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTAMDPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei primcount, GLsizei stride); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirectAMD (GLenum mode, const void *indirect, GLsizei primcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirectAMD (GLenum mode, GLenum type, const void *indirect, GLsizei primcount, GLsizei stride); +#endif +#endif /* GL_AMD_multi_draw_indirect */ + +#ifndef GL_AMD_name_gen_delete +#define GL_AMD_name_gen_delete 1 +#define GL_DATA_BUFFER_AMD 0x9151 +#define GL_PERFORMANCE_MONITOR_AMD 0x9152 +#define GL_QUERY_OBJECT_AMD 0x9153 +#define GL_VERTEX_ARRAY_OBJECT_AMD 0x9154 +#define GL_SAMPLER_OBJECT_AMD 0x9155 +typedef void (APIENTRYP PFNGLGENNAMESAMDPROC) (GLenum identifier, GLuint num, GLuint *names); +typedef void (APIENTRYP PFNGLDELETENAMESAMDPROC) (GLenum identifier, GLuint num, const GLuint *names); +typedef GLboolean (APIENTRYP PFNGLISNAMEAMDPROC) (GLenum identifier, GLuint name); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenNamesAMD (GLenum identifier, GLuint num, GLuint *names); +GLAPI void APIENTRY glDeleteNamesAMD (GLenum identifier, GLuint num, const GLuint *names); +GLAPI GLboolean APIENTRY glIsNameAMD (GLenum identifier, GLuint name); +#endif +#endif /* GL_AMD_name_gen_delete */ + +#ifndef GL_AMD_occlusion_query_event +#define GL_AMD_occlusion_query_event 1 +#define GL_OCCLUSION_QUERY_EVENT_MASK_AMD 0x874F +#define GL_QUERY_DEPTH_PASS_EVENT_BIT_AMD 0x00000001 +#define GL_QUERY_DEPTH_FAIL_EVENT_BIT_AMD 0x00000002 +#define GL_QUERY_STENCIL_FAIL_EVENT_BIT_AMD 0x00000004 +#define GL_QUERY_DEPTH_BOUNDS_FAIL_EVENT_BIT_AMD 0x00000008 +#define GL_QUERY_ALL_EVENT_BITS_AMD 0xFFFFFFFF +typedef void (APIENTRYP PFNGLQUERYOBJECTPARAMETERUIAMDPROC) (GLenum target, GLuint id, GLenum pname, GLuint param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glQueryObjectParameteruiAMD (GLenum target, GLuint id, GLenum pname, GLuint param); +#endif +#endif /* GL_AMD_occlusion_query_event */ + +#ifndef GL_AMD_performance_monitor +#define GL_AMD_performance_monitor 1 +#define GL_COUNTER_TYPE_AMD 0x8BC0 +#define GL_COUNTER_RANGE_AMD 0x8BC1 +#define GL_UNSIGNED_INT64_AMD 0x8BC2 +#define GL_PERCENTAGE_AMD 0x8BC3 +#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 +#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 +#define GL_PERFMON_RESULT_AMD 0x8BC6 +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, void *data); +typedef void (APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); +typedef void (APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +GLAPI void APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +GLAPI void APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +GLAPI void APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +GLAPI void APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, void *data); +GLAPI void APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors); +GLAPI void APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors); +GLAPI void APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); +GLAPI void APIENTRY glBeginPerfMonitorAMD (GLuint monitor); +GLAPI void APIENTRY glEndPerfMonitorAMD (GLuint monitor); +GLAPI void APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif +#endif /* GL_AMD_performance_monitor */ + +#ifndef GL_AMD_pinned_memory +#define GL_AMD_pinned_memory 1 +#define GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD 0x9160 +#endif /* GL_AMD_pinned_memory */ + +#ifndef GL_AMD_query_buffer_object +#define GL_AMD_query_buffer_object 1 +#define GL_QUERY_BUFFER_AMD 0x9192 +#define GL_QUERY_BUFFER_BINDING_AMD 0x9193 +#define GL_QUERY_RESULT_NO_WAIT_AMD 0x9194 +#endif /* GL_AMD_query_buffer_object */ + +#ifndef GL_AMD_sample_positions +#define GL_AMD_sample_positions 1 +typedef void (APIENTRYP PFNGLSETMULTISAMPLEFVAMDPROC) (GLenum pname, GLuint index, const GLfloat *val); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSetMultisamplefvAMD (GLenum pname, GLuint index, const GLfloat *val); +#endif +#endif /* GL_AMD_sample_positions */ + +#ifndef GL_AMD_seamless_cubemap_per_texture +#define GL_AMD_seamless_cubemap_per_texture 1 +#endif /* GL_AMD_seamless_cubemap_per_texture */ + +#ifndef GL_AMD_shader_atomic_counter_ops +#define GL_AMD_shader_atomic_counter_ops 1 +#endif /* GL_AMD_shader_atomic_counter_ops */ + +#ifndef GL_AMD_shader_ballot +#define GL_AMD_shader_ballot 1 +#endif /* GL_AMD_shader_ballot */ + +#ifndef GL_AMD_shader_explicit_vertex_parameter +#define GL_AMD_shader_explicit_vertex_parameter 1 +#endif /* GL_AMD_shader_explicit_vertex_parameter */ + +#ifndef GL_AMD_shader_gpu_shader_half_float_fetch +#define GL_AMD_shader_gpu_shader_half_float_fetch 1 +#endif /* GL_AMD_shader_gpu_shader_half_float_fetch */ + +#ifndef GL_AMD_shader_image_load_store_lod +#define GL_AMD_shader_image_load_store_lod 1 +#endif /* GL_AMD_shader_image_load_store_lod */ + +#ifndef GL_AMD_shader_stencil_export +#define GL_AMD_shader_stencil_export 1 +#endif /* GL_AMD_shader_stencil_export */ + +#ifndef GL_AMD_shader_trinary_minmax +#define GL_AMD_shader_trinary_minmax 1 +#endif /* GL_AMD_shader_trinary_minmax */ + +#ifndef GL_AMD_sparse_texture +#define GL_AMD_sparse_texture 1 +#define GL_VIRTUAL_PAGE_SIZE_X_AMD 0x9195 +#define GL_VIRTUAL_PAGE_SIZE_Y_AMD 0x9196 +#define GL_VIRTUAL_PAGE_SIZE_Z_AMD 0x9197 +#define GL_MAX_SPARSE_TEXTURE_SIZE_AMD 0x9198 +#define GL_MAX_SPARSE_3D_TEXTURE_SIZE_AMD 0x9199 +#define GL_MAX_SPARSE_ARRAY_TEXTURE_LAYERS 0x919A +#define GL_MIN_SPARSE_LEVEL_AMD 0x919B +#define GL_MIN_LOD_WARNING_AMD 0x919C +#define GL_TEXTURE_STORAGE_SPARSE_BIT_AMD 0x00000001 +typedef void (APIENTRYP PFNGLTEXSTORAGESPARSEAMDPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags); +typedef void (APIENTRYP PFNGLTEXTURESTORAGESPARSEAMDPROC) (GLuint texture, GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexStorageSparseAMD (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags); +GLAPI void APIENTRY glTextureStorageSparseAMD (GLuint texture, GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags); +#endif +#endif /* GL_AMD_sparse_texture */ + +#ifndef GL_AMD_stencil_operation_extended +#define GL_AMD_stencil_operation_extended 1 +#define GL_SET_AMD 0x874A +#define GL_REPLACE_VALUE_AMD 0x874B +#define GL_STENCIL_OP_VALUE_AMD 0x874C +#define GL_STENCIL_BACK_OP_VALUE_AMD 0x874D +typedef void (APIENTRYP PFNGLSTENCILOPVALUEAMDPROC) (GLenum face, GLuint value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilOpValueAMD (GLenum face, GLuint value); +#endif +#endif /* GL_AMD_stencil_operation_extended */ + +#ifndef GL_AMD_texture_gather_bias_lod +#define GL_AMD_texture_gather_bias_lod 1 +#endif /* GL_AMD_texture_gather_bias_lod */ + +#ifndef GL_AMD_texture_texture4 +#define GL_AMD_texture_texture4 1 +#endif /* GL_AMD_texture_texture4 */ + +#ifndef GL_AMD_transform_feedback3_lines_triangles +#define GL_AMD_transform_feedback3_lines_triangles 1 +#endif /* GL_AMD_transform_feedback3_lines_triangles */ + +#ifndef GL_AMD_transform_feedback4 +#define GL_AMD_transform_feedback4 1 +#define GL_STREAM_RASTERIZATION_AMD 0x91A0 +#endif /* GL_AMD_transform_feedback4 */ + +#ifndef GL_AMD_vertex_shader_layer +#define GL_AMD_vertex_shader_layer 1 +#endif /* GL_AMD_vertex_shader_layer */ + +#ifndef GL_AMD_vertex_shader_tessellator +#define GL_AMD_vertex_shader_tessellator 1 +#define GL_SAMPLER_BUFFER_AMD 0x9001 +#define GL_INT_SAMPLER_BUFFER_AMD 0x9002 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003 +#define GL_TESSELLATION_MODE_AMD 0x9004 +#define GL_TESSELLATION_FACTOR_AMD 0x9005 +#define GL_DISCRETE_AMD 0x9006 +#define GL_CONTINUOUS_AMD 0x9007 +typedef void (APIENTRYP PFNGLTESSELLATIONFACTORAMDPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLTESSELLATIONMODEAMDPROC) (GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTessellationFactorAMD (GLfloat factor); +GLAPI void APIENTRY glTessellationModeAMD (GLenum mode); +#endif +#endif /* GL_AMD_vertex_shader_tessellator */ + +#ifndef GL_AMD_vertex_shader_viewport_index +#define GL_AMD_vertex_shader_viewport_index 1 +#endif /* GL_AMD_vertex_shader_viewport_index */ + +#ifndef GL_APPLE_aux_depth_stencil +#define GL_APPLE_aux_depth_stencil 1 +#define GL_AUX_DEPTH_STENCIL_APPLE 0x8A14 +#endif /* GL_APPLE_aux_depth_stencil */ + +#ifndef GL_APPLE_client_storage +#define GL_APPLE_client_storage 1 +#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 +#endif /* GL_APPLE_client_storage */ + +#ifndef GL_APPLE_element_array +#define GL_APPLE_element_array 1 +#define GL_ELEMENT_ARRAY_APPLE 0x8A0C +#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8A0D +#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x8A0E +typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const void *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerAPPLE (GLenum type, const void *pointer); +GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif +#endif /* GL_APPLE_element_array */ + +#ifndef GL_APPLE_fence +#define GL_APPLE_fence 1 +#define GL_DRAW_PIXELS_APPLE 0x8A0A +#define GL_FENCE_APPLE 0x8A0B +typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); +typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); +typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenFencesAPPLE (GLsizei n, GLuint *fences); +GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei n, const GLuint *fences); +GLAPI void APIENTRY glSetFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint fence); +GLAPI void APIENTRY glFinishFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum object, GLuint name); +GLAPI void APIENTRY glFinishObjectAPPLE (GLenum object, GLint name); +#endif +#endif /* GL_APPLE_fence */ + +#ifndef GL_APPLE_float_pixels +#define GL_APPLE_float_pixels 1 +#define GL_HALF_APPLE 0x140B +#define GL_RGBA_FLOAT32_APPLE 0x8814 +#define GL_RGB_FLOAT32_APPLE 0x8815 +#define GL_ALPHA_FLOAT32_APPLE 0x8816 +#define GL_INTENSITY_FLOAT32_APPLE 0x8817 +#define GL_LUMINANCE_FLOAT32_APPLE 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819 +#define GL_RGBA_FLOAT16_APPLE 0x881A +#define GL_RGB_FLOAT16_APPLE 0x881B +#define GL_ALPHA_FLOAT16_APPLE 0x881C +#define GL_INTENSITY_FLOAT16_APPLE 0x881D +#define GL_LUMINANCE_FLOAT16_APPLE 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F +#define GL_COLOR_FLOAT_APPLE 0x8A0F +#endif /* GL_APPLE_float_pixels */ + +#ifndef GL_APPLE_flush_buffer_range +#define GL_APPLE_flush_buffer_range 1 +#define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8A12 +#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13 +typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferParameteriAPPLE (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glFlushMappedBufferRangeAPPLE (GLenum target, GLintptr offset, GLsizeiptr size); +#endif +#endif /* GL_APPLE_flush_buffer_range */ + +#ifndef GL_APPLE_object_purgeable +#define GL_APPLE_object_purgeable 1 +#define GL_BUFFER_OBJECT_APPLE 0x85B3 +#define GL_RELEASED_APPLE 0x8A19 +#define GL_VOLATILE_APPLE 0x8A1A +#define GL_RETAINED_APPLE 0x8A1B +#define GL_UNDEFINED_APPLE 0x8A1C +#define GL_PURGEABLE_APPLE 0x8A1D +typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLenum APIENTRY glObjectPurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); +GLAPI GLenum APIENTRY glObjectUnpurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); +GLAPI void APIENTRY glGetObjectParameterivAPPLE (GLenum objectType, GLuint name, GLenum pname, GLint *params); +#endif +#endif /* GL_APPLE_object_purgeable */ + +#ifndef GL_APPLE_rgb_422 +#define GL_APPLE_rgb_422 1 +#define GL_RGB_422_APPLE 0x8A1F +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#define GL_RGB_RAW_422_APPLE 0x8A51 +#endif /* GL_APPLE_rgb_422 */ + +#ifndef GL_APPLE_row_bytes +#define GL_APPLE_row_bytes 1 +#define GL_PACK_ROW_BYTES_APPLE 0x8A15 +#define GL_UNPACK_ROW_BYTES_APPLE 0x8A16 +#endif /* GL_APPLE_row_bytes */ + +#ifndef GL_APPLE_specular_vector +#define GL_APPLE_specular_vector 1 +#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0 +#endif /* GL_APPLE_specular_vector */ + +#ifndef GL_APPLE_texture_range +#define GL_APPLE_texture_range 1 +#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7 +#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8 +#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC +#define GL_STORAGE_PRIVATE_APPLE 0x85BD +#define GL_STORAGE_CACHED_APPLE 0x85BE +#define GL_STORAGE_SHARED_APPLE 0x85BF +typedef void (APIENTRYP PFNGLTEXTURERANGEAPPLEPROC) (GLenum target, GLsizei length, const void *pointer); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERPOINTERVAPPLEPROC) (GLenum target, GLenum pname, void **params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureRangeAPPLE (GLenum target, GLsizei length, const void *pointer); +GLAPI void APIENTRY glGetTexParameterPointervAPPLE (GLenum target, GLenum pname, void **params); +#endif +#endif /* GL_APPLE_texture_range */ + +#ifndef GL_APPLE_transform_hint +#define GL_APPLE_transform_hint 1 +#define GL_TRANSFORM_HINT_APPLE 0x85B1 +#endif /* GL_APPLE_transform_hint */ + +#ifndef GL_APPLE_vertex_array_object +#define GL_APPLE_vertex_array_object 1 +#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5 +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint array); +GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint array); +#endif +#endif /* GL_APPLE_vertex_array_object */ + +#ifndef GL_APPLE_vertex_array_range +#define GL_APPLE_vertex_array_range 1 +#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E +#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F +#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 +#define GL_STORAGE_CLIENT_APPLE 0x85B4 +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, void *pointer); +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, void *pointer); +typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei length, void *pointer); +GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei length, void *pointer); +GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum pname, GLint param); +#endif +#endif /* GL_APPLE_vertex_array_range */ + +#ifndef GL_APPLE_vertex_program_evaluators +#define GL_APPLE_vertex_program_evaluators 1 +#define GL_VERTEX_ATTRIB_MAP1_APPLE 0x8A00 +#define GL_VERTEX_ATTRIB_MAP2_APPLE 0x8A01 +#define GL_VERTEX_ATTRIB_MAP1_SIZE_APPLE 0x8A02 +#define GL_VERTEX_ATTRIB_MAP1_COEFF_APPLE 0x8A03 +#define GL_VERTEX_ATTRIB_MAP1_ORDER_APPLE 0x8A04 +#define GL_VERTEX_ATTRIB_MAP1_DOMAIN_APPLE 0x8A05 +#define GL_VERTEX_ATTRIB_MAP2_SIZE_APPLE 0x8A06 +#define GL_VERTEX_ATTRIB_MAP2_COEFF_APPLE 0x8A07 +#define GL_VERTEX_ATTRIB_MAP2_ORDER_APPLE 0x8A08 +#define GL_VERTEX_ATTRIB_MAP2_DOMAIN_APPLE 0x8A09 +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef GLboolean (APIENTRYP PFNGLISVERTEXATTRIBENABLEDAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEnableVertexAttribAPPLE (GLuint index, GLenum pname); +GLAPI void APIENTRY glDisableVertexAttribAPPLE (GLuint index, GLenum pname); +GLAPI GLboolean APIENTRY glIsVertexAttribEnabledAPPLE (GLuint index, GLenum pname); +GLAPI void APIENTRY glMapVertexAttrib1dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +GLAPI void APIENTRY glMapVertexAttrib1fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +GLAPI void APIENTRY glMapVertexAttrib2dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +GLAPI void APIENTRY glMapVertexAttrib2fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +#endif +#endif /* GL_APPLE_vertex_program_evaluators */ + +#ifndef GL_APPLE_ycbcr_422 +#define GL_APPLE_ycbcr_422 1 +#define GL_YCBCR_422_APPLE 0x85B9 +#endif /* GL_APPLE_ycbcr_422 */ + +#ifndef GL_ATI_draw_buffers +#define GL_ATI_draw_buffers 1 +#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 +#define GL_DRAW_BUFFER0_ATI 0x8825 +#define GL_DRAW_BUFFER1_ATI 0x8826 +#define GL_DRAW_BUFFER2_ATI 0x8827 +#define GL_DRAW_BUFFER3_ATI 0x8828 +#define GL_DRAW_BUFFER4_ATI 0x8829 +#define GL_DRAW_BUFFER5_ATI 0x882A +#define GL_DRAW_BUFFER6_ATI 0x882B +#define GL_DRAW_BUFFER7_ATI 0x882C +#define GL_DRAW_BUFFER8_ATI 0x882D +#define GL_DRAW_BUFFER9_ATI 0x882E +#define GL_DRAW_BUFFER10_ATI 0x882F +#define GL_DRAW_BUFFER11_ATI 0x8830 +#define GL_DRAW_BUFFER12_ATI 0x8831 +#define GL_DRAW_BUFFER13_ATI 0x8832 +#define GL_DRAW_BUFFER14_ATI 0x8833 +#define GL_DRAW_BUFFER15_ATI 0x8834 +typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersATI (GLsizei n, const GLenum *bufs); +#endif +#endif /* GL_ATI_draw_buffers */ + +#ifndef GL_ATI_element_array +#define GL_ATI_element_array 1 +#define GL_ELEMENT_ARRAY_ATI 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A +typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const void *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerATI (GLenum type, const void *pointer); +GLAPI void APIENTRY glDrawElementArrayATI (GLenum mode, GLsizei count); +GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif +#endif /* GL_ATI_element_array */ + +#ifndef GL_ATI_envmap_bumpmap +#define GL_ATI_envmap_bumpmap 1 +#define GL_BUMP_ROT_MATRIX_ATI 0x8775 +#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776 +#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777 +#define GL_BUMP_TEX_UNITS_ATI 0x8778 +#define GL_DUDV_ATI 0x8779 +#define GL_DU8DV8_ATI 0x877A +#define GL_BUMP_ENVMAP_ATI 0x877B +#define GL_BUMP_TARGET_ATI 0x877C +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBumpParameterivATI (GLenum pname, const GLint *param); +GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum pname, GLint *param); +GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum pname, GLfloat *param); +#endif +#endif /* GL_ATI_envmap_bumpmap */ + +#ifndef GL_ATI_fragment_shader +#define GL_ATI_fragment_shader 1 +#define GL_FRAGMENT_SHADER_ATI 0x8920 +#define GL_REG_0_ATI 0x8921 +#define GL_REG_1_ATI 0x8922 +#define GL_REG_2_ATI 0x8923 +#define GL_REG_3_ATI 0x8924 +#define GL_REG_4_ATI 0x8925 +#define GL_REG_5_ATI 0x8926 +#define GL_REG_6_ATI 0x8927 +#define GL_REG_7_ATI 0x8928 +#define GL_REG_8_ATI 0x8929 +#define GL_REG_9_ATI 0x892A +#define GL_REG_10_ATI 0x892B +#define GL_REG_11_ATI 0x892C +#define GL_REG_12_ATI 0x892D +#define GL_REG_13_ATI 0x892E +#define GL_REG_14_ATI 0x892F +#define GL_REG_15_ATI 0x8930 +#define GL_REG_16_ATI 0x8931 +#define GL_REG_17_ATI 0x8932 +#define GL_REG_18_ATI 0x8933 +#define GL_REG_19_ATI 0x8934 +#define GL_REG_20_ATI 0x8935 +#define GL_REG_21_ATI 0x8936 +#define GL_REG_22_ATI 0x8937 +#define GL_REG_23_ATI 0x8938 +#define GL_REG_24_ATI 0x8939 +#define GL_REG_25_ATI 0x893A +#define GL_REG_26_ATI 0x893B +#define GL_REG_27_ATI 0x893C +#define GL_REG_28_ATI 0x893D +#define GL_REG_29_ATI 0x893E +#define GL_REG_30_ATI 0x893F +#define GL_REG_31_ATI 0x8940 +#define GL_CON_0_ATI 0x8941 +#define GL_CON_1_ATI 0x8942 +#define GL_CON_2_ATI 0x8943 +#define GL_CON_3_ATI 0x8944 +#define GL_CON_4_ATI 0x8945 +#define GL_CON_5_ATI 0x8946 +#define GL_CON_6_ATI 0x8947 +#define GL_CON_7_ATI 0x8948 +#define GL_CON_8_ATI 0x8949 +#define GL_CON_9_ATI 0x894A +#define GL_CON_10_ATI 0x894B +#define GL_CON_11_ATI 0x894C +#define GL_CON_12_ATI 0x894D +#define GL_CON_13_ATI 0x894E +#define GL_CON_14_ATI 0x894F +#define GL_CON_15_ATI 0x8950 +#define GL_CON_16_ATI 0x8951 +#define GL_CON_17_ATI 0x8952 +#define GL_CON_18_ATI 0x8953 +#define GL_CON_19_ATI 0x8954 +#define GL_CON_20_ATI 0x8955 +#define GL_CON_21_ATI 0x8956 +#define GL_CON_22_ATI 0x8957 +#define GL_CON_23_ATI 0x8958 +#define GL_CON_24_ATI 0x8959 +#define GL_CON_25_ATI 0x895A +#define GL_CON_26_ATI 0x895B +#define GL_CON_27_ATI 0x895C +#define GL_CON_28_ATI 0x895D +#define GL_CON_29_ATI 0x895E +#define GL_CON_30_ATI 0x895F +#define GL_CON_31_ATI 0x8960 +#define GL_MOV_ATI 0x8961 +#define GL_ADD_ATI 0x8963 +#define GL_MUL_ATI 0x8964 +#define GL_SUB_ATI 0x8965 +#define GL_DOT3_ATI 0x8966 +#define GL_DOT4_ATI 0x8967 +#define GL_MAD_ATI 0x8968 +#define GL_LERP_ATI 0x8969 +#define GL_CND_ATI 0x896A +#define GL_CND0_ATI 0x896B +#define GL_DOT2_ADD_ATI 0x896C +#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D +#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E +#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F +#define GL_NUM_PASSES_ATI 0x8970 +#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971 +#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972 +#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973 +#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974 +#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975 +#define GL_SWIZZLE_STR_ATI 0x8976 +#define GL_SWIZZLE_STQ_ATI 0x8977 +#define GL_SWIZZLE_STR_DR_ATI 0x8978 +#define GL_SWIZZLE_STQ_DQ_ATI 0x8979 +#define GL_SWIZZLE_STRQ_ATI 0x897A +#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B +#define GL_RED_BIT_ATI 0x00000001 +#define GL_GREEN_BIT_ATI 0x00000002 +#define GL_BLUE_BIT_ATI 0x00000004 +#define GL_2X_BIT_ATI 0x00000001 +#define GL_4X_BIT_ATI 0x00000002 +#define GL_8X_BIT_ATI 0x00000004 +#define GL_HALF_BIT_ATI 0x00000008 +#define GL_QUARTER_BIT_ATI 0x00000010 +#define GL_EIGHTH_BIT_ATI 0x00000020 +#define GL_SATURATE_BIT_ATI 0x00000040 +#define GL_COMP_BIT_ATI 0x00000002 +#define GL_NEGATE_BIT_ATI 0x00000004 +#define GL_BIAS_BIT_ATI 0x00000008 +typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); +typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); +typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint range); +GLAPI void APIENTRY glBindFragmentShaderATI (GLuint id); +GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint id); +GLAPI void APIENTRY glBeginFragmentShaderATI (void); +GLAPI void APIENTRY glEndFragmentShaderATI (void); +GLAPI void APIENTRY glPassTexCoordATI (GLuint dst, GLuint coord, GLenum swizzle); +GLAPI void APIENTRY glSampleMapATI (GLuint dst, GLuint interp, GLenum swizzle); +GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint dst, const GLfloat *value); +#endif +#endif /* GL_ATI_fragment_shader */ + +#ifndef GL_ATI_map_object_buffer +#define GL_ATI_map_object_buffer 1 +typedef void *(APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void *APIENTRY glMapObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint buffer); +#endif +#endif /* GL_ATI_map_object_buffer */ + +#ifndef GL_ATI_meminfo +#define GL_ATI_meminfo 1 +#define GL_VBO_FREE_MEMORY_ATI 0x87FB +#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC +#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD +#endif /* GL_ATI_meminfo */ + +#ifndef GL_ATI_pixel_format_float +#define GL_ATI_pixel_format_float 1 +#define GL_RGBA_FLOAT_MODE_ATI 0x8820 +#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 +#endif /* GL_ATI_pixel_format_float */ + +#ifndef GL_ATI_pn_triangles +#define GL_ATI_pn_triangles 1 +#define GL_PN_TRIANGLES_ATI 0x87F0 +#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1 +#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2 +#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3 +#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4 +#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5 +#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6 +#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7 +#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8 +typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPNTrianglesiATI (GLenum pname, GLint param); +GLAPI void APIENTRY glPNTrianglesfATI (GLenum pname, GLfloat param); +#endif +#endif /* GL_ATI_pn_triangles */ + +#ifndef GL_ATI_separate_stencil +#define GL_ATI_separate_stencil 1 +#define GL_STENCIL_BACK_FUNC_ATI 0x8800 +#define GL_STENCIL_BACK_FAIL_ATI 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803 +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilOpSeparateATI (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif +#endif /* GL_ATI_separate_stencil */ + +#ifndef GL_ATI_text_fragment_shader +#define GL_ATI_text_fragment_shader 1 +#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200 +#endif /* GL_ATI_text_fragment_shader */ + +#ifndef GL_ATI_texture_env_combine3 +#define GL_ATI_texture_env_combine3 1 +#define GL_MODULATE_ADD_ATI 0x8744 +#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 +#define GL_MODULATE_SUBTRACT_ATI 0x8746 +#endif /* GL_ATI_texture_env_combine3 */ + +#ifndef GL_ATI_texture_float +#define GL_ATI_texture_float 1 +#define GL_RGBA_FLOAT32_ATI 0x8814 +#define GL_RGB_FLOAT32_ATI 0x8815 +#define GL_ALPHA_FLOAT32_ATI 0x8816 +#define GL_INTENSITY_FLOAT32_ATI 0x8817 +#define GL_LUMINANCE_FLOAT32_ATI 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 +#define GL_RGBA_FLOAT16_ATI 0x881A +#define GL_RGB_FLOAT16_ATI 0x881B +#define GL_ALPHA_FLOAT16_ATI 0x881C +#define GL_INTENSITY_FLOAT16_ATI 0x881D +#define GL_LUMINANCE_FLOAT16_ATI 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F +#endif /* GL_ATI_texture_float */ + +#ifndef GL_ATI_texture_mirror_once +#define GL_ATI_texture_mirror_once 1 +#define GL_MIRROR_CLAMP_ATI 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743 +#endif /* GL_ATI_texture_mirror_once */ + +#ifndef GL_ATI_vertex_array_object +#define GL_ATI_vertex_array_object 1 +#define GL_STATIC_ATI 0x8760 +#define GL_DYNAMIC_ATI 0x8761 +#define GL_PRESERVE_ATI 0x8762 +#define GL_DISCARD_ATI 0x8763 +#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764 +#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765 +#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766 +#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767 +typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const void *pointer, GLenum usage); +typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const void *pointer, GLenum preserve); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei size, const void *pointer, GLenum usage); +GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint buffer, GLuint offset, GLsizei size, const void *pointer, GLenum preserve); +GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint buffer, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetObjectBufferivATI (GLuint buffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glFreeObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glArrayObjectATI (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum array, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetArrayObjectivATI (GLenum array, GLenum pname, GLint *params); +GLAPI void APIENTRY glVariantArrayObjectATI (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint id, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint id, GLenum pname, GLint *params); +#endif +#endif /* GL_ATI_vertex_array_object */ + +#ifndef GL_ATI_vertex_attrib_array_object +#define GL_ATI_vertex_attrib_array_object 1 +typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint index, GLenum pname, GLint *params); +#endif +#endif /* GL_ATI_vertex_attrib_array_object */ + +#ifndef GL_ATI_vertex_streams +#define GL_ATI_vertex_streams 1 +#define GL_MAX_VERTEX_STREAMS_ATI 0x876B +#define GL_VERTEX_STREAM0_ATI 0x876C +#define GL_VERTEX_STREAM1_ATI 0x876D +#define GL_VERTEX_STREAM2_ATI 0x876E +#define GL_VERTEX_STREAM3_ATI 0x876F +#define GL_VERTEX_STREAM4_ATI 0x8770 +#define GL_VERTEX_STREAM5_ATI 0x8771 +#define GL_VERTEX_STREAM6_ATI 0x8772 +#define GL_VERTEX_STREAM7_ATI 0x8773 +#define GL_VERTEX_SOURCE_ATI 0x8774 +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexStream1sATI (GLenum stream, GLshort x); +GLAPI void APIENTRY glVertexStream1svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream1iATI (GLenum stream, GLint x); +GLAPI void APIENTRY glVertexStream1ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream1fATI (GLenum stream, GLfloat x); +GLAPI void APIENTRY glVertexStream1fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream1dATI (GLenum stream, GLdouble x); +GLAPI void APIENTRY glVertexStream1dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream2sATI (GLenum stream, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexStream2svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream2iATI (GLenum stream, GLint x, GLint y); +GLAPI void APIENTRY glVertexStream2ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream2fATI (GLenum stream, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexStream2fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream2dATI (GLenum stream, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexStream2dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream3sATI (GLenum stream, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexStream3svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream3iATI (GLenum stream, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexStream3ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream3fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexStream3fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream3dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexStream3dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream4sATI (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexStream4svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream4iATI (GLenum stream, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexStream4ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream4fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexStream4fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream4dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexStream4dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glNormalStream3bATI (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +GLAPI void APIENTRY glNormalStream3bvATI (GLenum stream, const GLbyte *coords); +GLAPI void APIENTRY glNormalStream3sATI (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +GLAPI void APIENTRY glNormalStream3svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glNormalStream3iATI (GLenum stream, GLint nx, GLint ny, GLint nz); +GLAPI void APIENTRY glNormalStream3ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glNormalStream3fATI (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +GLAPI void APIENTRY glNormalStream3fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glNormalStream3dATI (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +GLAPI void APIENTRY glNormalStream3dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum stream); +GLAPI void APIENTRY glVertexBlendEnviATI (GLenum pname, GLint param); +GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum pname, GLfloat param); +#endif +#endif /* GL_ATI_vertex_streams */ + +#ifndef GL_EXT_422_pixels +#define GL_EXT_422_pixels 1 +#define GL_422_EXT 0x80CC +#define GL_422_REV_EXT 0x80CD +#define GL_422_AVERAGE_EXT 0x80CE +#define GL_422_REV_AVERAGE_EXT 0x80CF +#endif /* GL_EXT_422_pixels */ + +#ifndef GL_EXT_EGL_image_storage +#define GL_EXT_EGL_image_storage 1 +typedef void *GLeglImageOES; +typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXSTORAGEEXTPROC) (GLenum target, GLeglImageOES image, const GLint* attrib_list); +typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXTURESTORAGEEXTPROC) (GLuint texture, GLeglImageOES image, const GLint* attrib_list); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEGLImageTargetTexStorageEXT (GLenum target, GLeglImageOES image, const GLint* attrib_list); +GLAPI void APIENTRY glEGLImageTargetTextureStorageEXT (GLuint texture, GLeglImageOES image, const GLint* attrib_list); +#endif +#endif /* GL_EXT_EGL_image_storage */ + +#ifndef GL_EXT_EGL_sync +#define GL_EXT_EGL_sync 1 +#endif /* GL_EXT_EGL_sync */ + +#ifndef GL_EXT_abgr +#define GL_EXT_abgr 1 +#define GL_ABGR_EXT 0x8000 +#endif /* GL_EXT_abgr */ + +#ifndef GL_EXT_bgra +#define GL_EXT_bgra 1 +#define GL_BGR_EXT 0x80E0 +#define GL_BGRA_EXT 0x80E1 +#endif /* GL_EXT_bgra */ + +#ifndef GL_EXT_bindable_uniform +#define GL_EXT_bindable_uniform 1 +#define GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT 0x8DE2 +#define GL_MAX_FRAGMENT_BINDABLE_UNIFORMS_EXT 0x8DE3 +#define GL_MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT 0x8DE4 +#define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED +#define GL_UNIFORM_BUFFER_EXT 0x8DEE +#define GL_UNIFORM_BUFFER_BINDING_EXT 0x8DEF +typedef void (APIENTRYP PFNGLUNIFORMBUFFEREXTPROC) (GLuint program, GLint location, GLuint buffer); +typedef GLint (APIENTRYP PFNGLGETUNIFORMBUFFERSIZEEXTPROC) (GLuint program, GLint location); +typedef GLintptr (APIENTRYP PFNGLGETUNIFORMOFFSETEXTPROC) (GLuint program, GLint location); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformBufferEXT (GLuint program, GLint location, GLuint buffer); +GLAPI GLint APIENTRY glGetUniformBufferSizeEXT (GLuint program, GLint location); +GLAPI GLintptr APIENTRY glGetUniformOffsetEXT (GLuint program, GLint location); +#endif +#endif /* GL_EXT_bindable_uniform */ + +#ifndef GL_EXT_blend_color +#define GL_EXT_blend_color 1 +#define GL_CONSTANT_COLOR_EXT 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 +#define GL_CONSTANT_ALPHA_EXT 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 +#define GL_BLEND_COLOR_EXT 0x8005 +typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColorEXT (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +#endif +#endif /* GL_EXT_blend_color */ + +#ifndef GL_EXT_blend_equation_separate +#define GL_EXT_blend_equation_separate 1 +#define GL_BLEND_EQUATION_RGB_EXT 0x8009 +#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum modeRGB, GLenum modeAlpha); +#endif +#endif /* GL_EXT_blend_equation_separate */ + +#ifndef GL_EXT_blend_func_separate +#define GL_EXT_blend_func_separate 1 +#define GL_BLEND_DST_RGB_EXT 0x80C8 +#define GL_BLEND_SRC_RGB_EXT 0x80C9 +#define GL_BLEND_DST_ALPHA_EXT 0x80CA +#define GL_BLEND_SRC_ALPHA_EXT 0x80CB +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif +#endif /* GL_EXT_blend_func_separate */ + +#ifndef GL_EXT_blend_logic_op +#define GL_EXT_blend_logic_op 1 +#endif /* GL_EXT_blend_logic_op */ + +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#define GL_FUNC_ADD_EXT 0x8006 +#define GL_BLEND_EQUATION_EXT 0x8009 +typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationEXT (GLenum mode); +#endif +#endif /* GL_EXT_blend_minmax */ + +#ifndef GL_EXT_blend_subtract +#define GL_EXT_blend_subtract 1 +#define GL_FUNC_SUBTRACT_EXT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B +#endif /* GL_EXT_blend_subtract */ + +#ifndef GL_EXT_clip_volume_hint +#define GL_EXT_clip_volume_hint 1 +#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0 +#endif /* GL_EXT_clip_volume_hint */ + +#ifndef GL_EXT_cmyka +#define GL_EXT_cmyka 1 +#define GL_CMYK_EXT 0x800C +#define GL_CMYKA_EXT 0x800D +#define GL_PACK_CMYK_HINT_EXT 0x800E +#define GL_UNPACK_CMYK_HINT_EXT 0x800F +#endif /* GL_EXT_cmyka */ + +#ifndef GL_EXT_color_subtable +#define GL_EXT_color_subtable 1 +typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorSubTableEXT (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif +#endif /* GL_EXT_color_subtable */ + +#ifndef GL_EXT_compiled_vertex_array +#define GL_EXT_compiled_vertex_array 1 +#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8 +#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9 +typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLockArraysEXT (GLint first, GLsizei count); +GLAPI void APIENTRY glUnlockArraysEXT (void); +#endif +#endif /* GL_EXT_compiled_vertex_array */ + +#ifndef GL_EXT_convolution +#define GL_EXT_convolution 1 +#define GL_CONVOLUTION_1D_EXT 0x8010 +#define GL_CONVOLUTION_2D_EXT 0x8011 +#define GL_SEPARABLE_2D_EXT 0x8012 +#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015 +#define GL_REDUCE_EXT 0x8016 +#define GL_CONVOLUTION_FORMAT_EXT 0x8017 +#define GL_CONVOLUTION_WIDTH_EXT 0x8018 +#define GL_CONVOLUTION_HEIGHT_EXT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023 +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, void *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image); +GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image); +GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum target, GLenum pname, GLfloat params); +GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum target, GLenum pname, GLint params); +GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum target, GLenum format, GLenum type, void *image); +GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span); +GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column); +#endif +#endif /* GL_EXT_convolution */ + +#ifndef GL_EXT_coordinate_frame +#define GL_EXT_coordinate_frame 1 +#define GL_TANGENT_ARRAY_EXT 0x8439 +#define GL_BINORMAL_ARRAY_EXT 0x843A +#define GL_CURRENT_TANGENT_EXT 0x843B +#define GL_CURRENT_BINORMAL_EXT 0x843C +#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E +#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F +#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440 +#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441 +#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442 +#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443 +#define GL_MAP1_TANGENT_EXT 0x8444 +#define GL_MAP2_TANGENT_EXT 0x8445 +#define GL_MAP1_BINORMAL_EXT 0x8446 +#define GL_MAP2_BINORMAL_EXT 0x8447 +typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); +typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); +typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); +typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); +typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); +typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); +typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); +typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); +typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); +typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); +typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTangent3bEXT (GLbyte tx, GLbyte ty, GLbyte tz); +GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glTangent3dEXT (GLdouble tx, GLdouble ty, GLdouble tz); +GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glTangent3fEXT (GLfloat tx, GLfloat ty, GLfloat tz); +GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glTangent3iEXT (GLint tx, GLint ty, GLint tz); +GLAPI void APIENTRY glTangent3ivEXT (const GLint *v); +GLAPI void APIENTRY glTangent3sEXT (GLshort tx, GLshort ty, GLshort tz); +GLAPI void APIENTRY glTangent3svEXT (const GLshort *v); +GLAPI void APIENTRY glBinormal3bEXT (GLbyte bx, GLbyte by, GLbyte bz); +GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glBinormal3dEXT (GLdouble bx, GLdouble by, GLdouble bz); +GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glBinormal3fEXT (GLfloat bx, GLfloat by, GLfloat bz); +GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glBinormal3iEXT (GLint bx, GLint by, GLint bz); +GLAPI void APIENTRY glBinormal3ivEXT (const GLint *v); +GLAPI void APIENTRY glBinormal3sEXT (GLshort bx, GLshort by, GLshort bz); +GLAPI void APIENTRY glBinormal3svEXT (const GLshort *v); +GLAPI void APIENTRY glTangentPointerEXT (GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glBinormalPointerEXT (GLenum type, GLsizei stride, const void *pointer); +#endif +#endif /* GL_EXT_coordinate_frame */ + +#ifndef GL_EXT_copy_texture +#define GL_EXT_copy_texture 1 +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif +#endif /* GL_EXT_copy_texture */ + +#ifndef GL_EXT_cull_vertex +#define GL_EXT_cull_vertex 1 +#define GL_CULL_VERTEX_EXT 0x81AA +#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB +#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC +typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCullParameterdvEXT (GLenum pname, GLdouble *params); +GLAPI void APIENTRY glCullParameterfvEXT (GLenum pname, GLfloat *params); +#endif +#endif /* GL_EXT_cull_vertex */ + +#ifndef GL_EXT_debug_label +#define GL_EXT_debug_label 1 +#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F +#define GL_PROGRAM_OBJECT_EXT 0x8B40 +#define GL_SHADER_OBJECT_EXT 0x8B48 +#define GL_BUFFER_OBJECT_EXT 0x9151 +#define GL_QUERY_OBJECT_EXT 0x9153 +#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154 +typedef void (APIENTRYP PFNGLLABELOBJECTEXTPROC) (GLenum type, GLuint object, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTLABELEXTPROC) (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLabelObjectEXT (GLenum type, GLuint object, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectLabelEXT (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif +#endif /* GL_EXT_debug_label */ + +#ifndef GL_EXT_debug_marker +#define GL_EXT_debug_marker 1 +typedef void (APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker); +typedef void (APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker); +typedef void (APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glInsertEventMarkerEXT (GLsizei length, const GLchar *marker); +GLAPI void APIENTRY glPushGroupMarkerEXT (GLsizei length, const GLchar *marker); +GLAPI void APIENTRY glPopGroupMarkerEXT (void); +#endif +#endif /* GL_EXT_debug_marker */ + +#ifndef GL_EXT_depth_bounds_test +#define GL_EXT_depth_bounds_test 1 +#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 +#define GL_DEPTH_BOUNDS_EXT 0x8891 +typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthBoundsEXT (GLclampd zmin, GLclampd zmax); +#endif +#endif /* GL_EXT_depth_bounds_test */ + +#ifndef GL_EXT_direct_state_access +#define GL_EXT_direct_state_access 1 +#define GL_PROGRAM_MATRIX_EXT 0x8E2D +#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E +#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F +typedef void (APIENTRYP PFNGLMATRIXLOADFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXLOADIDENTITYEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXROTATEFEXTPROC) (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXROTATEDEXTPROC) (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXSCALEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXSCALEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXFRUSTUMEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXORTHOEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXPOPEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXPUSHEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, void *pixels); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLBINDMULTITEXTUREEXTPROC) (GLenum texunit, GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORDPOINTEREXTPROC) (GLenum texunit, GLint size, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLMULTITEXENVFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXENVIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXGENDEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +typedef void (APIENTRYP PFNGLMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +typedef void (APIENTRYP PFNGLMULTITEXGENFEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXGENIEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, void *pixels); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLENABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLGETFLOATINDEXEDVEXTPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEINDEXEDVEXTPROC) (GLenum target, GLuint index, GLdouble *data); +typedef void (APIENTRYP PFNGLGETPOINTERINDEXEDVEXTPROC) (GLenum target, GLuint index, void **data); +typedef void (APIENTRYP PFNGLENABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLGETINTEGERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLGETBOOLEANINDEXEDVEXTPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint lod, void *img); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint lod, void *img); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFEREXTPROC) (GLuint buffer, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFEREXTPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVEXTPROC) (GLuint buffer, GLenum pname, void **params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLTEXTUREBUFFEREXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLMULTITEXBUFFEREXTPROC) (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IEXTPROC) (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIUIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLENABLECLIENTSTATEIEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEIEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum format, GLsizei len, const void *string); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERDVEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERFVEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMIVEXTPROC) (GLuint program, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum pname, void *string); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVEXTPROC) (GLuint renderbuffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLECOVERAGEEXTPROC) (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC) (GLuint framebuffer, GLenum target); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE1DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE3DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPEXTPROC) (GLuint texture, GLenum target); +typedef void (APIENTRYP PFNGLGENERATEMULTITEXMIPMAPEXTPROC) (GLenum texunit, GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLFRAMEBUFFERREADBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREFACEEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); +typedef void (APIENTRYP PFNGLTEXTURERENDERBUFFEREXTPROC) (GLuint texture, GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLMULTITEXRENDERBUFFEREXTPROC) (GLenum texunit, GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYCOLOROFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYEDGEFLAGOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYINDEXOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYNORMALOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYTEXCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYMULTITEXCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYFOGCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYSECONDARYCOLOROFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYEXTPROC) (GLuint vaobj, GLenum array); +typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYEXTPROC) (GLuint vaobj, GLenum array); +typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYATTRIBEXTPROC) (GLuint vaobj, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYATTRIBEXTPROC) (GLuint vaobj, GLuint index); +typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERVEXTPROC) (GLuint vaobj, GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERVEXTPROC) (GLuint vaobj, GLenum pname, void **param); +typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param); +typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSTORAGEEXTPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLsizeiptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DEXTPROC) (GLuint program, GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +typedef void (APIENTRYP PFNGLTEXTUREPAGECOMMITMENTEXTPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBDIVISOREXTPROC) (GLuint vaobj, GLuint index, GLuint divisor); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMatrixLoadfEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoaddEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixMultfEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMultdEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixLoadIdentityEXT (GLenum mode); +GLAPI void APIENTRY glMatrixRotatefEXT (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixRotatedEXT (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixScalefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixScaledEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixTranslatefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixTranslatedEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixFrustumEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glMatrixOrthoEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glMatrixPopEXT (GLenum mode); +GLAPI void APIENTRY glMatrixPushEXT (GLenum mode); +GLAPI void APIENTRY glClientAttribDefaultEXT (GLbitfield mask); +GLAPI void APIENTRY glPushClientAttribDefaultEXT (GLbitfield mask); +GLAPI void APIENTRY glTextureParameterfEXT (GLuint texture, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glTextureParameteriEXT (GLuint texture, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glCopyTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetTextureImageEXT (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, void *pixels); +GLAPI void APIENTRY glGetTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureLevelParameterfvEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureLevelParameterivEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI void APIENTRY glTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glCopyTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glBindMultiTextureEXT (GLenum texunit, GLenum target, GLuint texture); +GLAPI void APIENTRY glMultiTexCoordPointerEXT (GLenum texunit, GLint size, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glMultiTexEnvfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexEnviEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexGendEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +GLAPI void APIENTRY glMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +GLAPI void APIENTRY glMultiTexGenfEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexGeniEXT (GLenum texunit, GLenum coord, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, GLint *params); +GLAPI void APIENTRY glMultiTexParameteriEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexParameterfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glCopyMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetMultiTexImageEXT (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, void *pixels); +GLAPI void APIENTRY glGetMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexLevelParameterfvEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexLevelParameterivEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI void APIENTRY glMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glCopyMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glEnableClientStateIndexedEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glDisableClientStateIndexedEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glGetFloatIndexedvEXT (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoubleIndexedvEXT (GLenum target, GLuint index, GLdouble *data); +GLAPI void APIENTRY glGetPointerIndexedvEXT (GLenum target, GLuint index, void **data); +GLAPI void APIENTRY glEnableIndexedEXT (GLenum target, GLuint index); +GLAPI void APIENTRY glDisableIndexedEXT (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledIndexedEXT (GLenum target, GLuint index); +GLAPI void APIENTRY glGetIntegerIndexedvEXT (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glGetBooleanIndexedvEXT (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glCompressedTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glGetCompressedTextureImageEXT (GLuint texture, GLenum target, GLint lod, void *img); +GLAPI void APIENTRY glCompressedMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits); +GLAPI void APIENTRY glGetCompressedMultiTexImageEXT (GLenum texunit, GLenum target, GLint lod, void *img); +GLAPI void APIENTRY glMatrixLoadTransposefEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoadTransposedEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixMultTransposefEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMultTransposedEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glNamedBufferDataEXT (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage); +GLAPI void APIENTRY glNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +GLAPI void *APIENTRY glMapNamedBufferEXT (GLuint buffer, GLenum access); +GLAPI GLboolean APIENTRY glUnmapNamedBufferEXT (GLuint buffer); +GLAPI void APIENTRY glGetNamedBufferParameterivEXT (GLuint buffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetNamedBufferPointervEXT (GLuint buffer, GLenum pname, void **params); +GLAPI void APIENTRY glGetNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data); +GLAPI void APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glTextureBufferEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glMultiTexBufferEXT (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glProgramUniform1uiEXT (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform2uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform3uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform4uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform1uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glNamedProgramLocalParameters4fvEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glNamedProgramLocalParameterI4iEXT (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glNamedProgramLocalParameterI4ivEXT (GLuint program, GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glNamedProgramLocalParametersI4ivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uiEXT (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uivEXT (GLuint program, GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glNamedProgramLocalParametersI4uivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIivEXT (GLuint program, GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIuivEXT (GLuint program, GLenum target, GLuint index, GLuint *params); +GLAPI void APIENTRY glEnableClientStateiEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glDisableClientStateiEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glGetFloati_vEXT (GLenum pname, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetDoublei_vEXT (GLenum pname, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetPointeri_vEXT (GLenum pname, GLuint index, void **params); +GLAPI void APIENTRY glNamedProgramStringEXT (GLuint program, GLenum target, GLenum format, GLsizei len, const void *string); +GLAPI void APIENTRY glNamedProgramLocalParameter4dEXT (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glNamedProgramLocalParameter4dvEXT (GLuint program, GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glNamedProgramLocalParameter4fEXT (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glNamedProgramLocalParameter4fvEXT (GLuint program, GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterdvEXT (GLuint program, GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterfvEXT (GLuint program, GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetNamedProgramivEXT (GLuint program, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetNamedProgramStringEXT (GLuint program, GLenum target, GLenum pname, void *string); +GLAPI void APIENTRY glNamedRenderbufferStorageEXT (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetNamedRenderbufferParameterivEXT (GLuint renderbuffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleEXT (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleCoverageEXT (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI GLenum APIENTRY glCheckNamedFramebufferStatusEXT (GLuint framebuffer, GLenum target); +GLAPI void APIENTRY glNamedFramebufferTexture1DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTexture2DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTexture3DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glNamedFramebufferRenderbufferEXT (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameterivEXT (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateTextureMipmapEXT (GLuint texture, GLenum target); +GLAPI void APIENTRY glGenerateMultiTexMipmapEXT (GLenum texunit, GLenum target); +GLAPI void APIENTRY glFramebufferDrawBufferEXT (GLuint framebuffer, GLenum mode); +GLAPI void APIENTRY glFramebufferDrawBuffersEXT (GLuint framebuffer, GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glFramebufferReadBufferEXT (GLuint framebuffer, GLenum mode); +GLAPI void APIENTRY glGetFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedCopyBufferSubDataEXT (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GLAPI void APIENTRY glNamedFramebufferTextureEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTextureLayerEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glNamedFramebufferTextureFaceEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); +GLAPI void APIENTRY glTextureRenderbufferEXT (GLuint texture, GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glMultiTexRenderbufferEXT (GLenum texunit, GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glVertexArrayVertexOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayColorOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayEdgeFlagOffsetEXT (GLuint vaobj, GLuint buffer, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayIndexOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayNormalOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayTexCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayMultiTexCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLenum texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayFogCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArraySecondaryColorOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayVertexAttribOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glVertexArrayVertexAttribIOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glEnableVertexArrayEXT (GLuint vaobj, GLenum array); +GLAPI void APIENTRY glDisableVertexArrayEXT (GLuint vaobj, GLenum array); +GLAPI void APIENTRY glEnableVertexArrayAttribEXT (GLuint vaobj, GLuint index); +GLAPI void APIENTRY glDisableVertexArrayAttribEXT (GLuint vaobj, GLuint index); +GLAPI void APIENTRY glGetVertexArrayIntegervEXT (GLuint vaobj, GLenum pname, GLint *param); +GLAPI void APIENTRY glGetVertexArrayPointervEXT (GLuint vaobj, GLenum pname, void **param); +GLAPI void APIENTRY glGetVertexArrayIntegeri_vEXT (GLuint vaobj, GLuint index, GLenum pname, GLint *param); +GLAPI void APIENTRY glGetVertexArrayPointeri_vEXT (GLuint vaobj, GLuint index, GLenum pname, void **param); +GLAPI void *APIENTRY glMapNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glNamedBufferStorageEXT (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags); +GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLsizeiptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param); +GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glProgramUniform1dEXT (GLuint program, GLint location, GLdouble x); +GLAPI void APIENTRY glProgramUniform2dEXT (GLuint program, GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glProgramUniform3dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glProgramUniform4dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramUniform1dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor); +GLAPI void APIENTRY glVertexArrayVertexAttribLOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +GLAPI void APIENTRY glTexturePageCommitmentEXT (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit); +GLAPI void APIENTRY glVertexArrayVertexAttribDivisorEXT (GLuint vaobj, GLuint index, GLuint divisor); +#endif +#endif /* GL_EXT_direct_state_access */ + +#ifndef GL_EXT_draw_buffers2 +#define GL_EXT_draw_buffers2 1 +typedef void (APIENTRYP PFNGLCOLORMASKINDEXEDEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaskIndexedEXT (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +#endif +#endif /* GL_EXT_draw_buffers2 */ + +#ifndef GL_EXT_draw_instanced +#define GL_EXT_draw_instanced 1 +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedEXT (GLenum mode, GLint start, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstancedEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +#endif +#endif /* GL_EXT_draw_instanced */ + +#ifndef GL_EXT_draw_range_elements +#define GL_EXT_draw_range_elements 1 +#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8 +#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9 +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices); +#endif +#endif /* GL_EXT_draw_range_elements */ + +#ifndef GL_EXT_external_buffer +#define GL_EXT_external_buffer 1 +typedef void *GLeglClientBufferEXT; +typedef void (APIENTRYP PFNGLBUFFERSTORAGEEXTERNALEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSTORAGEEXTERNALEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferStorageExternalEXT (GLenum target, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags); +GLAPI void APIENTRY glNamedBufferStorageExternalEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags); +#endif +#endif /* GL_EXT_external_buffer */ + +#ifndef GL_EXT_fog_coord +#define GL_EXT_fog_coord 1 +#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 +#define GL_FOG_COORDINATE_EXT 0x8451 +#define GL_FRAGMENT_DEPTH_EXT 0x8452 +#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456 +#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457 +typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordfEXT (GLfloat coord); +GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *coord); +GLAPI void APIENTRY glFogCoorddEXT (GLdouble coord); +GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *coord); +GLAPI void APIENTRY glFogCoordPointerEXT (GLenum type, GLsizei stride, const void *pointer); +#endif +#endif /* GL_EXT_fog_coord */ + +#ifndef GL_EXT_framebuffer_blit +#define GL_EXT_framebuffer_blit 1 +#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlitFramebufferEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif +#endif /* GL_EXT_framebuffer_blit */ + +#ifndef GL_EXT_framebuffer_blit_layers +#define GL_EXT_framebuffer_blit_layers 1 +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERLAYERSEXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERLAYEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint srcLayer, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstLayer, GLbitfield mask, GLenum filter); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlitFramebufferLayersEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI void APIENTRY glBlitFramebufferLayerEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint srcLayer, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstLayer, GLbitfield mask, GLenum filter); +#endif +#endif /* GL_EXT_framebuffer_blit_layers */ + +#ifndef GL_EXT_framebuffer_multisample +#define GL_EXT_framebuffer_multisample 1 +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif +#endif /* GL_EXT_framebuffer_multisample */ + +#ifndef GL_EXT_framebuffer_multisample_blit_scaled +#define GL_EXT_framebuffer_multisample_blit_scaled 1 +#define GL_SCALED_RESOLVE_FASTEST_EXT 0x90BA +#define GL_SCALED_RESOLVE_NICEST_EXT 0x90BB +#endif /* GL_EXT_framebuffer_multisample_blit_scaled */ + +#ifndef GL_EXT_framebuffer_object +#define GL_EXT_framebuffer_object 1 +#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 +#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 +#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF +#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 +#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 +#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 +#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 +#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 +#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 +#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 +#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 +#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 +#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 +#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA +#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB +#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC +#define GL_COLOR_ATTACHMENT13_EXT 0x8CED +#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE +#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF +#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 +#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_RENDERBUFFER_EXT 0x8D41 +#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 +#define GL_STENCIL_INDEX1_EXT 0x8D46 +#define GL_STENCIL_INDEX4_EXT 0x8D47 +#define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_STENCIL_INDEX16_EXT 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbufferEXT (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebufferEXT (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmapEXT (GLenum target); +#endif +#endif /* GL_EXT_framebuffer_object */ + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_EXT_framebuffer_sRGB 1 +#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 +#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA +#endif /* GL_EXT_framebuffer_sRGB */ + +#ifndef GL_EXT_geometry_shader4 +#define GL_EXT_geometry_shader4 1 +#define GL_GEOMETRY_SHADER_EXT 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29 +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE +#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1 +#define GL_LINES_ADJACENCY_EXT 0x000A +#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B +#define GL_TRIANGLES_ADJACENCY_EXT 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 +#define GL_PROGRAM_POINT_SIZE_EXT 0x8642 +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value); +#endif +#endif /* GL_EXT_geometry_shader4 */ + +#ifndef GL_EXT_gpu_program_parameters +#define GL_EXT_gpu_program_parameters 1 +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramEnvParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glProgramLocalParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +#endif +#endif /* GL_EXT_gpu_program_parameters */ + +#ifndef GL_EXT_gpu_shader4 +#define GL_EXT_gpu_shader4 1 +#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0 +#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1 +#define GL_SAMPLER_BUFFER_EXT 0x8DC2 +#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5 +#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6 +#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7 +#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8 +#define GL_INT_SAMPLER_1D_EXT 0x8DC9 +#define GL_INT_SAMPLER_2D_EXT 0x8DCA +#define GL_INT_SAMPLER_3D_EXT 0x8DCB +#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC +#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD +#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF +#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8 +#define GL_MIN_PROGRAM_TEXEL_OFFSET_EXT 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET_EXT 0x8905 +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_EXT 0x88FD +typedef void (APIENTRYP PFNGLGETUNIFORMUIVEXTPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONEXTPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIEXTPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIEXTPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IEXTPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IEXTPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IEXTPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IEXTPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIEXTPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIEXTPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVEXTPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVEXTPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVEXTPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVEXTPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVEXTPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVEXTPROC) (GLuint index, GLenum pname, GLuint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUniformuivEXT (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocationEXT (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocationEXT (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1uiEXT (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2uiEXT (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glVertexAttribI1iEXT (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2iEXT (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3iEXT (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4iEXT (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1uiEXT (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2uiEXT (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3uiEXT (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4uiEXT (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bvEXT (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4svEXT (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubvEXT (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usvEXT (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribIPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glGetVertexAttribIivEXT (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuivEXT (GLuint index, GLenum pname, GLuint *params); +#endif +#endif /* GL_EXT_gpu_shader4 */ + +#ifndef GL_EXT_histogram +#define GL_EXT_histogram 1 +#define GL_HISTOGRAM_EXT 0x8024 +#define GL_PROXY_HISTOGRAM_EXT 0x8025 +#define GL_HISTOGRAM_WIDTH_EXT 0x8026 +#define GL_HISTOGRAM_FORMAT_EXT 0x8027 +#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C +#define GL_HISTOGRAM_SINK_EXT 0x802D +#define GL_MINMAX_EXT 0x802E +#define GL_MINMAX_FORMAT_EXT 0x802F +#define GL_MINMAX_SINK_EXT 0x8030 +#define GL_TABLE_TOO_LARGE_EXT 0x8031 +typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetHistogramEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMinmaxEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values); +GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glHistogramEXT (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glMinmaxEXT (GLenum target, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glResetHistogramEXT (GLenum target); +GLAPI void APIENTRY glResetMinmaxEXT (GLenum target); +#endif +#endif /* GL_EXT_histogram */ + +#ifndef GL_EXT_index_array_formats +#define GL_EXT_index_array_formats 1 +#define GL_IUI_V2F_EXT 0x81AD +#define GL_IUI_V3F_EXT 0x81AE +#define GL_IUI_N3F_V2F_EXT 0x81AF +#define GL_IUI_N3F_V3F_EXT 0x81B0 +#define GL_T2F_IUI_V2F_EXT 0x81B1 +#define GL_T2F_IUI_V3F_EXT 0x81B2 +#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3 +#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4 +#endif /* GL_EXT_index_array_formats */ + +#ifndef GL_EXT_index_func +#define GL_EXT_index_func 1 +#define GL_INDEX_TEST_EXT 0x81B5 +#define GL_INDEX_TEST_FUNC_EXT 0x81B6 +#define GL_INDEX_TEST_REF_EXT 0x81B7 +typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexFuncEXT (GLenum func, GLclampf ref); +#endif +#endif /* GL_EXT_index_func */ + +#ifndef GL_EXT_index_material +#define GL_EXT_index_material 1 +#define GL_INDEX_MATERIAL_EXT 0x81B8 +#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9 +#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA +typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexMaterialEXT (GLenum face, GLenum mode); +#endif +#endif /* GL_EXT_index_material */ + +#ifndef GL_EXT_index_texture +#define GL_EXT_index_texture 1 +#endif /* GL_EXT_index_texture */ + +#ifndef GL_EXT_light_texture +#define GL_EXT_light_texture 1 +#define GL_FRAGMENT_MATERIAL_EXT 0x8349 +#define GL_FRAGMENT_NORMAL_EXT 0x834A +#define GL_FRAGMENT_COLOR_EXT 0x834C +#define GL_ATTENUATION_EXT 0x834D +#define GL_SHADOW_ATTENUATION_EXT 0x834E +#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F +#define GL_TEXTURE_LIGHT_EXT 0x8350 +#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351 +#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352 +typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glApplyTextureEXT (GLenum mode); +GLAPI void APIENTRY glTextureLightEXT (GLenum pname); +GLAPI void APIENTRY glTextureMaterialEXT (GLenum face, GLenum mode); +#endif +#endif /* GL_EXT_light_texture */ + +#ifndef GL_EXT_memory_object +#define GL_EXT_memory_object 1 +#define GL_TEXTURE_TILING_EXT 0x9580 +#define GL_DEDICATED_MEMORY_OBJECT_EXT 0x9581 +#define GL_PROTECTED_MEMORY_OBJECT_EXT 0x959B +#define GL_NUM_TILING_TYPES_EXT 0x9582 +#define GL_TILING_TYPES_EXT 0x9583 +#define GL_OPTIMAL_TILING_EXT 0x9584 +#define GL_LINEAR_TILING_EXT 0x9585 +#define GL_NUM_DEVICE_UUIDS_EXT 0x9596 +#define GL_DEVICE_UUID_EXT 0x9597 +#define GL_DRIVER_UUID_EXT 0x9598 +#define GL_UUID_SIZE_EXT 16 +typedef void (APIENTRYP PFNGLGETUNSIGNEDBYTEVEXTPROC) (GLenum pname, GLubyte *data); +typedef void (APIENTRYP PFNGLGETUNSIGNEDBYTEI_VEXTPROC) (GLenum target, GLuint index, GLubyte *data); +typedef void (APIENTRYP PFNGLDELETEMEMORYOBJECTSEXTPROC) (GLsizei n, const GLuint *memoryObjects); +typedef GLboolean (APIENTRYP PFNGLISMEMORYOBJECTEXTPROC) (GLuint memoryObject); +typedef void (APIENTRYP PFNGLCREATEMEMORYOBJECTSEXTPROC) (GLsizei n, GLuint *memoryObjects); +typedef void (APIENTRYP PFNGLMEMORYOBJECTPARAMETERIVEXTPROC) (GLuint memoryObject, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETMEMORYOBJECTPARAMETERIVEXTPROC) (GLuint memoryObject, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLTEXSTORAGEMEM2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXSTORAGEMEM2DMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXSTORAGEMEM3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXSTORAGEMEM3DMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLBUFFERSTORAGEMEMEXTPROC) (GLenum target, GLsizeiptr size, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXTURESTORAGEMEM2DEXTPROC) (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXTURESTORAGEMEM2DMULTISAMPLEEXTPROC) (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXTURESTORAGEMEM3DEXTPROC) (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXTURESTORAGEMEM3DMULTISAMPLEEXTPROC) (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSTORAGEMEMEXTPROC) (GLuint buffer, GLsizeiptr size, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXSTORAGEMEM1DEXTPROC) (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXTURESTORAGEMEM1DEXTPROC) (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLuint memory, GLuint64 offset); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUnsignedBytevEXT (GLenum pname, GLubyte *data); +GLAPI void APIENTRY glGetUnsignedBytei_vEXT (GLenum target, GLuint index, GLubyte *data); +GLAPI void APIENTRY glDeleteMemoryObjectsEXT (GLsizei n, const GLuint *memoryObjects); +GLAPI GLboolean APIENTRY glIsMemoryObjectEXT (GLuint memoryObject); +GLAPI void APIENTRY glCreateMemoryObjectsEXT (GLsizei n, GLuint *memoryObjects); +GLAPI void APIENTRY glMemoryObjectParameterivEXT (GLuint memoryObject, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetMemoryObjectParameterivEXT (GLuint memoryObject, GLenum pname, GLint *params); +GLAPI void APIENTRY glTexStorageMem2DEXT (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTexStorageMem2DMultisampleEXT (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTexStorageMem3DEXT (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTexStorageMem3DMultisampleEXT (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glBufferStorageMemEXT (GLenum target, GLsizeiptr size, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTextureStorageMem2DEXT (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTextureStorageMem2DMultisampleEXT (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTextureStorageMem3DEXT (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTextureStorageMem3DMultisampleEXT (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glNamedBufferStorageMemEXT (GLuint buffer, GLsizeiptr size, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTexStorageMem1DEXT (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTextureStorageMem1DEXT (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLuint memory, GLuint64 offset); +#endif +#endif /* GL_EXT_memory_object */ + +#ifndef GL_EXT_memory_object_fd +#define GL_EXT_memory_object_fd 1 +#define GL_HANDLE_TYPE_OPAQUE_FD_EXT 0x9586 +typedef void (APIENTRYP PFNGLIMPORTMEMORYFDEXTPROC) (GLuint memory, GLuint64 size, GLenum handleType, GLint fd); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImportMemoryFdEXT (GLuint memory, GLuint64 size, GLenum handleType, GLint fd); +#endif +#endif /* GL_EXT_memory_object_fd */ + +#ifndef GL_EXT_memory_object_win32 +#define GL_EXT_memory_object_win32 1 +#define GL_HANDLE_TYPE_OPAQUE_WIN32_EXT 0x9587 +#define GL_HANDLE_TYPE_OPAQUE_WIN32_KMT_EXT 0x9588 +#define GL_DEVICE_LUID_EXT 0x9599 +#define GL_DEVICE_NODE_MASK_EXT 0x959A +#define GL_LUID_SIZE_EXT 8 +#define GL_HANDLE_TYPE_D3D12_TILEPOOL_EXT 0x9589 +#define GL_HANDLE_TYPE_D3D12_RESOURCE_EXT 0x958A +#define GL_HANDLE_TYPE_D3D11_IMAGE_EXT 0x958B +#define GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT 0x958C +typedef void (APIENTRYP PFNGLIMPORTMEMORYWIN32HANDLEEXTPROC) (GLuint memory, GLuint64 size, GLenum handleType, void *handle); +typedef void (APIENTRYP PFNGLIMPORTMEMORYWIN32NAMEEXTPROC) (GLuint memory, GLuint64 size, GLenum handleType, const void *name); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImportMemoryWin32HandleEXT (GLuint memory, GLuint64 size, GLenum handleType, void *handle); +GLAPI void APIENTRY glImportMemoryWin32NameEXT (GLuint memory, GLuint64 size, GLenum handleType, const void *name); +#endif +#endif /* GL_EXT_memory_object_win32 */ + +#ifndef GL_EXT_misc_attribute +#define GL_EXT_misc_attribute 1 +#endif /* GL_EXT_misc_attribute */ + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount); +#endif +#endif /* GL_EXT_multi_draw_arrays */ + +#ifndef GL_EXT_multisample +#define GL_EXT_multisample 1 +#define GL_MULTISAMPLE_EXT 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F +#define GL_SAMPLE_MASK_EXT 0x80A0 +#define GL_1PASS_EXT 0x80A1 +#define GL_2PASS_0_EXT 0x80A2 +#define GL_2PASS_1_EXT 0x80A3 +#define GL_4PASS_0_EXT 0x80A4 +#define GL_4PASS_1_EXT 0x80A5 +#define GL_4PASS_2_EXT 0x80A6 +#define GL_4PASS_3_EXT 0x80A7 +#define GL_SAMPLE_BUFFERS_EXT 0x80A8 +#define GL_SAMPLES_EXT 0x80A9 +#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA +#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB +#define GL_SAMPLE_PATTERN_EXT 0x80AC +#define GL_MULTISAMPLE_BIT_EXT 0x20000000 +typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskEXT (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glSamplePatternEXT (GLenum pattern); +#endif +#endif /* GL_EXT_multisample */ + +#ifndef GL_EXT_multiview_tessellation_geometry_shader +#define GL_EXT_multiview_tessellation_geometry_shader 1 +#endif /* GL_EXT_multiview_tessellation_geometry_shader */ + +#ifndef GL_EXT_multiview_texture_multisample +#define GL_EXT_multiview_texture_multisample 1 +#endif /* GL_EXT_multiview_texture_multisample */ + +#ifndef GL_EXT_multiview_timer_query +#define GL_EXT_multiview_timer_query 1 +#endif /* GL_EXT_multiview_timer_query */ + +#ifndef GL_EXT_packed_depth_stencil +#define GL_EXT_packed_depth_stencil 1 +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#define GL_UNSIGNED_INT_24_8_EXT 0x84FA +#define GL_DEPTH24_STENCIL8_EXT 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 +#endif /* GL_EXT_packed_depth_stencil */ + +#ifndef GL_EXT_packed_float +#define GL_EXT_packed_float 1 +#define GL_R11F_G11F_B10F_EXT 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV_EXT 0x8C3B +#define GL_RGBA_SIGNED_COMPONENTS_EXT 0x8C3C +#endif /* GL_EXT_packed_float */ + +#ifndef GL_EXT_packed_pixels +#define GL_EXT_packed_pixels 1 +#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036 +#endif /* GL_EXT_packed_pixels */ + +#ifndef GL_EXT_paletted_texture +#define GL_EXT_paletted_texture 1 +#define GL_COLOR_INDEX1_EXT 0x80E2 +#define GL_COLOR_INDEX2_EXT 0x80E3 +#define GL_COLOR_INDEX4_EXT 0x80E4 +#define GL_COLOR_INDEX8_EXT 0x80E5 +#define GL_COLOR_INDEX12_EXT 0x80E6 +#define GL_COLOR_INDEX16_EXT 0x80E7 +#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED +typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const void *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, void *data); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableEXT (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const void *table); +GLAPI void APIENTRY glGetColorTableEXT (GLenum target, GLenum format, GLenum type, void *data); +GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +#endif +#endif /* GL_EXT_paletted_texture */ + +#ifndef GL_EXT_pixel_buffer_object +#define GL_EXT_pixel_buffer_object 1 +#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF +#endif /* GL_EXT_pixel_buffer_object */ + +#ifndef GL_EXT_pixel_transform +#define GL_EXT_pixel_transform 1 +#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330 +#define GL_PIXEL_MAG_FILTER_EXT 0x8331 +#define GL_PIXEL_MIN_FILTER_EXT 0x8332 +#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333 +#define GL_CUBIC_EXT 0x8334 +#define GL_AVERAGE_EXT 0x8335 +#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336 +#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337 +#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338 +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetPixelTransformParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetPixelTransformParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +#endif +#endif /* GL_EXT_pixel_transform */ + +#ifndef GL_EXT_pixel_transform_color_table +#define GL_EXT_pixel_transform_color_table 1 +#endif /* GL_EXT_pixel_transform_color_table */ + +#ifndef GL_EXT_point_parameters +#define GL_EXT_point_parameters 1 +#define GL_POINT_SIZE_MIN_EXT 0x8126 +#define GL_POINT_SIZE_MAX_EXT 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 +#define GL_DISTANCE_ATTENUATION_EXT 0x8129 +typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfEXT (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvEXT (GLenum pname, const GLfloat *params); +#endif +#endif /* GL_EXT_point_parameters */ + +#ifndef GL_EXT_polygon_offset +#define GL_EXT_polygon_offset 1 +#define GL_POLYGON_OFFSET_EXT 0x8037 +#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038 +#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039 +typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat factor, GLfloat bias); +#endif +#endif /* GL_EXT_polygon_offset */ + +#ifndef GL_EXT_polygon_offset_clamp +#define GL_EXT_polygon_offset_clamp 1 +#define GL_POLYGON_OFFSET_CLAMP_EXT 0x8E1B +typedef void (APIENTRYP PFNGLPOLYGONOFFSETCLAMPEXTPROC) (GLfloat factor, GLfloat units, GLfloat clamp); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPolygonOffsetClampEXT (GLfloat factor, GLfloat units, GLfloat clamp); +#endif +#endif /* GL_EXT_polygon_offset_clamp */ + +#ifndef GL_EXT_post_depth_coverage +#define GL_EXT_post_depth_coverage 1 +#endif /* GL_EXT_post_depth_coverage */ + +#ifndef GL_EXT_provoking_vertex +#define GL_EXT_provoking_vertex 1 +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D +#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E +#define GL_PROVOKING_VERTEX_EXT 0x8E4F +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXEXTPROC) (GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProvokingVertexEXT (GLenum mode); +#endif +#endif /* GL_EXT_provoking_vertex */ + +#ifndef GL_EXT_raster_multisample +#define GL_EXT_raster_multisample 1 +#define GL_RASTER_MULTISAMPLE_EXT 0x9327 +#define GL_RASTER_SAMPLES_EXT 0x9328 +#define GL_MAX_RASTER_SAMPLES_EXT 0x9329 +#define GL_RASTER_FIXED_SAMPLE_LOCATIONS_EXT 0x932A +#define GL_MULTISAMPLE_RASTERIZATION_ALLOWED_EXT 0x932B +#define GL_EFFECTIVE_RASTER_SAMPLES_EXT 0x932C +typedef void (APIENTRYP PFNGLRASTERSAMPLESEXTPROC) (GLuint samples, GLboolean fixedsamplelocations); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRasterSamplesEXT (GLuint samples, GLboolean fixedsamplelocations); +#endif +#endif /* GL_EXT_raster_multisample */ + +#ifndef GL_EXT_rescale_normal +#define GL_EXT_rescale_normal 1 +#define GL_RESCALE_NORMAL_EXT 0x803A +#endif /* GL_EXT_rescale_normal */ + +#ifndef GL_EXT_secondary_color +#define GL_EXT_secondary_color 1 +#define GL_COLOR_SUM_EXT 0x8458 +#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D +#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte red, GLbyte green, GLbyte blue); +GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble red, GLdouble green, GLdouble blue); +GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat red, GLfloat green, GLfloat blue); +GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glSecondaryColor3iEXT (GLint red, GLint green, GLint blue); +GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *v); +GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort red, GLshort green, GLshort blue); +GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *v); +GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte red, GLubyte green, GLubyte blue); +GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *v); +GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint red, GLuint green, GLuint blue); +GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *v); +GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort red, GLushort green, GLushort blue); +GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *v); +GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, const void *pointer); +#endif +#endif /* GL_EXT_secondary_color */ + +#ifndef GL_EXT_semaphore +#define GL_EXT_semaphore 1 +#define GL_LAYOUT_GENERAL_EXT 0x958D +#define GL_LAYOUT_COLOR_ATTACHMENT_EXT 0x958E +#define GL_LAYOUT_DEPTH_STENCIL_ATTACHMENT_EXT 0x958F +#define GL_LAYOUT_DEPTH_STENCIL_READ_ONLY_EXT 0x9590 +#define GL_LAYOUT_SHADER_READ_ONLY_EXT 0x9591 +#define GL_LAYOUT_TRANSFER_SRC_EXT 0x9592 +#define GL_LAYOUT_TRANSFER_DST_EXT 0x9593 +#define GL_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_EXT 0x9530 +#define GL_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_EXT 0x9531 +typedef void (APIENTRYP PFNGLGENSEMAPHORESEXTPROC) (GLsizei n, GLuint *semaphores); +typedef void (APIENTRYP PFNGLDELETESEMAPHORESEXTPROC) (GLsizei n, const GLuint *semaphores); +typedef GLboolean (APIENTRYP PFNGLISSEMAPHOREEXTPROC) (GLuint semaphore); +typedef void (APIENTRYP PFNGLSEMAPHOREPARAMETERUI64VEXTPROC) (GLuint semaphore, GLenum pname, const GLuint64 *params); +typedef void (APIENTRYP PFNGLGETSEMAPHOREPARAMETERUI64VEXTPROC) (GLuint semaphore, GLenum pname, GLuint64 *params); +typedef void (APIENTRYP PFNGLWAITSEMAPHOREEXTPROC) (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *srcLayouts); +typedef void (APIENTRYP PFNGLSIGNALSEMAPHOREEXTPROC) (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *dstLayouts); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenSemaphoresEXT (GLsizei n, GLuint *semaphores); +GLAPI void APIENTRY glDeleteSemaphoresEXT (GLsizei n, const GLuint *semaphores); +GLAPI GLboolean APIENTRY glIsSemaphoreEXT (GLuint semaphore); +GLAPI void APIENTRY glSemaphoreParameterui64vEXT (GLuint semaphore, GLenum pname, const GLuint64 *params); +GLAPI void APIENTRY glGetSemaphoreParameterui64vEXT (GLuint semaphore, GLenum pname, GLuint64 *params); +GLAPI void APIENTRY glWaitSemaphoreEXT (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *srcLayouts); +GLAPI void APIENTRY glSignalSemaphoreEXT (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *dstLayouts); +#endif +#endif /* GL_EXT_semaphore */ + +#ifndef GL_EXT_semaphore_fd +#define GL_EXT_semaphore_fd 1 +typedef void (APIENTRYP PFNGLIMPORTSEMAPHOREFDEXTPROC) (GLuint semaphore, GLenum handleType, GLint fd); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImportSemaphoreFdEXT (GLuint semaphore, GLenum handleType, GLint fd); +#endif +#endif /* GL_EXT_semaphore_fd */ + +#ifndef GL_EXT_semaphore_win32 +#define GL_EXT_semaphore_win32 1 +#define GL_HANDLE_TYPE_D3D12_FENCE_EXT 0x9594 +#define GL_D3D12_FENCE_VALUE_EXT 0x9595 +typedef void (APIENTRYP PFNGLIMPORTSEMAPHOREWIN32HANDLEEXTPROC) (GLuint semaphore, GLenum handleType, void *handle); +typedef void (APIENTRYP PFNGLIMPORTSEMAPHOREWIN32NAMEEXTPROC) (GLuint semaphore, GLenum handleType, const void *name); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImportSemaphoreWin32HandleEXT (GLuint semaphore, GLenum handleType, void *handle); +GLAPI void APIENTRY glImportSemaphoreWin32NameEXT (GLuint semaphore, GLenum handleType, const void *name); +#endif +#endif /* GL_EXT_semaphore_win32 */ + +#ifndef GL_EXT_separate_shader_objects +#define GL_EXT_separate_shader_objects 1 +#define GL_ACTIVE_PROGRAM_EXT 0x8B8D +typedef void (APIENTRYP PFNGLUSESHADERPROGRAMEXTPROC) (GLenum type, GLuint program); +typedef void (APIENTRYP PFNGLACTIVEPROGRAMEXTPROC) (GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMEXTPROC) (GLenum type, const GLchar *string); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUseShaderProgramEXT (GLenum type, GLuint program); +GLAPI void APIENTRY glActiveProgramEXT (GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramEXT (GLenum type, const GLchar *string); +#endif +#endif /* GL_EXT_separate_shader_objects */ + +#ifndef GL_EXT_separate_specular_color +#define GL_EXT_separate_specular_color 1 +#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8 +#define GL_SINGLE_COLOR_EXT 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA +#endif /* GL_EXT_separate_specular_color */ + +#ifndef GL_EXT_shader_framebuffer_fetch +#define GL_EXT_shader_framebuffer_fetch 1 +#define GL_FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT 0x8A52 +#endif /* GL_EXT_shader_framebuffer_fetch */ + +#ifndef GL_EXT_shader_framebuffer_fetch_non_coherent +#define GL_EXT_shader_framebuffer_fetch_non_coherent 1 +typedef void (APIENTRYP PFNGLFRAMEBUFFERFETCHBARRIEREXTPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferFetchBarrierEXT (void); +#endif +#endif /* GL_EXT_shader_framebuffer_fetch_non_coherent */ + +#ifndef GL_EXT_shader_image_load_formatted +#define GL_EXT_shader_image_load_formatted 1 +#endif /* GL_EXT_shader_image_load_formatted */ + +#ifndef GL_EXT_shader_image_load_store +#define GL_EXT_shader_image_load_store 1 +#define GL_MAX_IMAGE_UNITS_EXT 0x8F38 +#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS_EXT 0x8F39 +#define GL_IMAGE_BINDING_NAME_EXT 0x8F3A +#define GL_IMAGE_BINDING_LEVEL_EXT 0x8F3B +#define GL_IMAGE_BINDING_LAYERED_EXT 0x8F3C +#define GL_IMAGE_BINDING_LAYER_EXT 0x8F3D +#define GL_IMAGE_BINDING_ACCESS_EXT 0x8F3E +#define GL_IMAGE_1D_EXT 0x904C +#define GL_IMAGE_2D_EXT 0x904D +#define GL_IMAGE_3D_EXT 0x904E +#define GL_IMAGE_2D_RECT_EXT 0x904F +#define GL_IMAGE_CUBE_EXT 0x9050 +#define GL_IMAGE_BUFFER_EXT 0x9051 +#define GL_IMAGE_1D_ARRAY_EXT 0x9052 +#define GL_IMAGE_2D_ARRAY_EXT 0x9053 +#define GL_IMAGE_CUBE_MAP_ARRAY_EXT 0x9054 +#define GL_IMAGE_2D_MULTISAMPLE_EXT 0x9055 +#define GL_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9056 +#define GL_INT_IMAGE_1D_EXT 0x9057 +#define GL_INT_IMAGE_2D_EXT 0x9058 +#define GL_INT_IMAGE_3D_EXT 0x9059 +#define GL_INT_IMAGE_2D_RECT_EXT 0x905A +#define GL_INT_IMAGE_CUBE_EXT 0x905B +#define GL_INT_IMAGE_BUFFER_EXT 0x905C +#define GL_INT_IMAGE_1D_ARRAY_EXT 0x905D +#define GL_INT_IMAGE_2D_ARRAY_EXT 0x905E +#define GL_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x905F +#define GL_INT_IMAGE_2D_MULTISAMPLE_EXT 0x9060 +#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9061 +#define GL_UNSIGNED_INT_IMAGE_1D_EXT 0x9062 +#define GL_UNSIGNED_INT_IMAGE_2D_EXT 0x9063 +#define GL_UNSIGNED_INT_IMAGE_3D_EXT 0x9064 +#define GL_UNSIGNED_INT_IMAGE_2D_RECT_EXT 0x9065 +#define GL_UNSIGNED_INT_IMAGE_CUBE_EXT 0x9066 +#define GL_UNSIGNED_INT_IMAGE_BUFFER_EXT 0x9067 +#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY_EXT 0x9068 +#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY_EXT 0x9069 +#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x906A +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_EXT 0x906B +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x906C +#define GL_MAX_IMAGE_SAMPLES_EXT 0x906D +#define GL_IMAGE_BINDING_FORMAT_EXT 0x906E +#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT_EXT 0x00000001 +#define GL_ELEMENT_ARRAY_BARRIER_BIT_EXT 0x00000002 +#define GL_UNIFORM_BARRIER_BIT_EXT 0x00000004 +#define GL_TEXTURE_FETCH_BARRIER_BIT_EXT 0x00000008 +#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT_EXT 0x00000020 +#define GL_COMMAND_BARRIER_BIT_EXT 0x00000040 +#define GL_PIXEL_BUFFER_BARRIER_BIT_EXT 0x00000080 +#define GL_TEXTURE_UPDATE_BARRIER_BIT_EXT 0x00000100 +#define GL_BUFFER_UPDATE_BARRIER_BIT_EXT 0x00000200 +#define GL_FRAMEBUFFER_BARRIER_BIT_EXT 0x00000400 +#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT_EXT 0x00000800 +#define GL_ATOMIC_COUNTER_BARRIER_BIT_EXT 0x00001000 +#define GL_ALL_BARRIER_BITS_EXT 0xFFFFFFFF +typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREEXTPROC) (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); +typedef void (APIENTRYP PFNGLMEMORYBARRIEREXTPROC) (GLbitfield barriers); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindImageTextureEXT (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); +GLAPI void APIENTRY glMemoryBarrierEXT (GLbitfield barriers); +#endif +#endif /* GL_EXT_shader_image_load_store */ + +#ifndef GL_EXT_shader_integer_mix +#define GL_EXT_shader_integer_mix 1 +#endif /* GL_EXT_shader_integer_mix */ + +#ifndef GL_EXT_shader_samples_identical +#define GL_EXT_shader_samples_identical 1 +#endif /* GL_EXT_shader_samples_identical */ + +#ifndef GL_EXT_shadow_funcs +#define GL_EXT_shadow_funcs 1 +#endif /* GL_EXT_shadow_funcs */ + +#ifndef GL_EXT_shared_texture_palette +#define GL_EXT_shared_texture_palette 1 +#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB +#endif /* GL_EXT_shared_texture_palette */ + +#ifndef GL_EXT_sparse_texture2 +#define GL_EXT_sparse_texture2 1 +#endif /* GL_EXT_sparse_texture2 */ + +#ifndef GL_EXT_stencil_clear_tag +#define GL_EXT_stencil_clear_tag 1 +#define GL_STENCIL_TAG_BITS_EXT 0x88F2 +#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3 +typedef void (APIENTRYP PFNGLSTENCILCLEARTAGEXTPROC) (GLsizei stencilTagBits, GLuint stencilClearTag); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilClearTagEXT (GLsizei stencilTagBits, GLuint stencilClearTag); +#endif +#endif /* GL_EXT_stencil_clear_tag */ + +#ifndef GL_EXT_stencil_two_side +#define GL_EXT_stencil_two_side 1 +#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 +#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 +typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum face); +#endif +#endif /* GL_EXT_stencil_two_side */ + +#ifndef GL_EXT_stencil_wrap +#define GL_EXT_stencil_wrap 1 +#define GL_INCR_WRAP_EXT 0x8507 +#define GL_DECR_WRAP_EXT 0x8508 +#endif /* GL_EXT_stencil_wrap */ + +#ifndef GL_EXT_subtexture +#define GL_EXT_subtexture 1 +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +#endif +#endif /* GL_EXT_subtexture */ + +#ifndef GL_EXT_texture +#define GL_EXT_texture 1 +#define GL_ALPHA4_EXT 0x803B +#define GL_ALPHA8_EXT 0x803C +#define GL_ALPHA12_EXT 0x803D +#define GL_ALPHA16_EXT 0x803E +#define GL_LUMINANCE4_EXT 0x803F +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE12_EXT 0x8041 +#define GL_LUMINANCE16_EXT 0x8042 +#define GL_LUMINANCE4_ALPHA4_EXT 0x8043 +#define GL_LUMINANCE6_ALPHA2_EXT 0x8044 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_LUMINANCE12_ALPHA4_EXT 0x8046 +#define GL_LUMINANCE12_ALPHA12_EXT 0x8047 +#define GL_LUMINANCE16_ALPHA16_EXT 0x8048 +#define GL_INTENSITY_EXT 0x8049 +#define GL_INTENSITY4_EXT 0x804A +#define GL_INTENSITY8_EXT 0x804B +#define GL_INTENSITY12_EXT 0x804C +#define GL_INTENSITY16_EXT 0x804D +#define GL_RGB2_EXT 0x804E +#define GL_RGB4_EXT 0x804F +#define GL_RGB5_EXT 0x8050 +#define GL_RGB8_EXT 0x8051 +#define GL_RGB10_EXT 0x8052 +#define GL_RGB12_EXT 0x8053 +#define GL_RGB16_EXT 0x8054 +#define GL_RGBA2_EXT 0x8055 +#define GL_RGBA4_EXT 0x8056 +#define GL_RGB5_A1_EXT 0x8057 +#define GL_RGBA8_EXT 0x8058 +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGBA12_EXT 0x805A +#define GL_RGBA16_EXT 0x805B +#define GL_TEXTURE_RED_SIZE_EXT 0x805C +#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D +#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E +#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061 +#define GL_REPLACE_EXT 0x8062 +#define GL_PROXY_TEXTURE_1D_EXT 0x8063 +#define GL_PROXY_TEXTURE_2D_EXT 0x8064 +#define GL_TEXTURE_TOO_LARGE_EXT 0x8065 +#endif /* GL_EXT_texture */ + +#ifndef GL_EXT_texture3D +#define GL_EXT_texture3D 1 +#define GL_PACK_SKIP_IMAGES_EXT 0x806B +#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C +#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D +#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E +#define GL_TEXTURE_3D_EXT 0x806F +#define GL_PROXY_TEXTURE_3D_EXT 0x8070 +#define GL_TEXTURE_DEPTH_EXT 0x8071 +#define GL_TEXTURE_WRAP_R_EXT 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 +typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage3DEXT (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); +#endif +#endif /* GL_EXT_texture3D */ + +#ifndef GL_EXT_texture_array +#define GL_EXT_texture_array 1 +#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 +#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D +#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF +#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferTextureLayerEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif +#endif /* GL_EXT_texture_array */ + +#ifndef GL_EXT_texture_buffer_object +#define GL_EXT_texture_buffer_object 1 +#define GL_TEXTURE_BUFFER_EXT 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E +typedef void (APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferEXT (GLenum target, GLenum internalformat, GLuint buffer); +#endif +#endif /* GL_EXT_texture_buffer_object */ + +#ifndef GL_EXT_texture_compression_latc +#define GL_EXT_texture_compression_latc 1 +#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70 +#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71 +#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72 +#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73 +#endif /* GL_EXT_texture_compression_latc */ + +#ifndef GL_EXT_texture_compression_rgtc +#define GL_EXT_texture_compression_rgtc 1 +#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC +#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD +#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE +#endif /* GL_EXT_texture_compression_rgtc */ + +#ifndef GL_EXT_texture_compression_s3tc +#define GL_EXT_texture_compression_s3tc 1 +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif /* GL_EXT_texture_compression_s3tc */ + +#ifndef GL_EXT_texture_cube_map +#define GL_EXT_texture_cube_map 1 +#define GL_NORMAL_MAP_EXT 0x8511 +#define GL_REFLECTION_MAP_EXT 0x8512 +#define GL_TEXTURE_CUBE_MAP_EXT 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C +#endif /* GL_EXT_texture_cube_map */ + +#ifndef GL_EXT_texture_env_add +#define GL_EXT_texture_env_add 1 +#endif /* GL_EXT_texture_env_add */ + +#ifndef GL_EXT_texture_env_combine +#define GL_EXT_texture_env_combine 1 +#define GL_COMBINE_EXT 0x8570 +#define GL_COMBINE_RGB_EXT 0x8571 +#define GL_COMBINE_ALPHA_EXT 0x8572 +#define GL_RGB_SCALE_EXT 0x8573 +#define GL_ADD_SIGNED_EXT 0x8574 +#define GL_INTERPOLATE_EXT 0x8575 +#define GL_CONSTANT_EXT 0x8576 +#define GL_PRIMARY_COLOR_EXT 0x8577 +#define GL_PREVIOUS_EXT 0x8578 +#define GL_SOURCE0_RGB_EXT 0x8580 +#define GL_SOURCE1_RGB_EXT 0x8581 +#define GL_SOURCE2_RGB_EXT 0x8582 +#define GL_SOURCE0_ALPHA_EXT 0x8588 +#define GL_SOURCE1_ALPHA_EXT 0x8589 +#define GL_SOURCE2_ALPHA_EXT 0x858A +#define GL_OPERAND0_RGB_EXT 0x8590 +#define GL_OPERAND1_RGB_EXT 0x8591 +#define GL_OPERAND2_RGB_EXT 0x8592 +#define GL_OPERAND0_ALPHA_EXT 0x8598 +#define GL_OPERAND1_ALPHA_EXT 0x8599 +#define GL_OPERAND2_ALPHA_EXT 0x859A +#endif /* GL_EXT_texture_env_combine */ + +#ifndef GL_EXT_texture_env_dot3 +#define GL_EXT_texture_env_dot3 1 +#define GL_DOT3_RGB_EXT 0x8740 +#define GL_DOT3_RGBA_EXT 0x8741 +#endif /* GL_EXT_texture_env_dot3 */ + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif /* GL_EXT_texture_filter_anisotropic */ + +#ifndef GL_EXT_texture_filter_minmax +#define GL_EXT_texture_filter_minmax 1 +#define GL_TEXTURE_REDUCTION_MODE_EXT 0x9366 +#define GL_WEIGHTED_AVERAGE_EXT 0x9367 +#endif /* GL_EXT_texture_filter_minmax */ + +#ifndef GL_EXT_texture_integer +#define GL_EXT_texture_integer 1 +#define GL_RGBA32UI_EXT 0x8D70 +#define GL_RGB32UI_EXT 0x8D71 +#define GL_ALPHA32UI_EXT 0x8D72 +#define GL_INTENSITY32UI_EXT 0x8D73 +#define GL_LUMINANCE32UI_EXT 0x8D74 +#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75 +#define GL_RGBA16UI_EXT 0x8D76 +#define GL_RGB16UI_EXT 0x8D77 +#define GL_ALPHA16UI_EXT 0x8D78 +#define GL_INTENSITY16UI_EXT 0x8D79 +#define GL_LUMINANCE16UI_EXT 0x8D7A +#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B +#define GL_RGBA8UI_EXT 0x8D7C +#define GL_RGB8UI_EXT 0x8D7D +#define GL_ALPHA8UI_EXT 0x8D7E +#define GL_INTENSITY8UI_EXT 0x8D7F +#define GL_LUMINANCE8UI_EXT 0x8D80 +#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81 +#define GL_RGBA32I_EXT 0x8D82 +#define GL_RGB32I_EXT 0x8D83 +#define GL_ALPHA32I_EXT 0x8D84 +#define GL_INTENSITY32I_EXT 0x8D85 +#define GL_LUMINANCE32I_EXT 0x8D86 +#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87 +#define GL_RGBA16I_EXT 0x8D88 +#define GL_RGB16I_EXT 0x8D89 +#define GL_ALPHA16I_EXT 0x8D8A +#define GL_INTENSITY16I_EXT 0x8D8B +#define GL_LUMINANCE16I_EXT 0x8D8C +#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D +#define GL_RGBA8I_EXT 0x8D8E +#define GL_RGB8I_EXT 0x8D8F +#define GL_ALPHA8I_EXT 0x8D90 +#define GL_INTENSITY8I_EXT 0x8D91 +#define GL_LUMINANCE8I_EXT 0x8D92 +#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93 +#define GL_RED_INTEGER_EXT 0x8D94 +#define GL_GREEN_INTEGER_EXT 0x8D95 +#define GL_BLUE_INTEGER_EXT 0x8D96 +#define GL_ALPHA_INTEGER_EXT 0x8D97 +#define GL_RGB_INTEGER_EXT 0x8D98 +#define GL_RGBA_INTEGER_EXT 0x8D99 +#define GL_BGR_INTEGER_EXT 0x8D9A +#define GL_BGRA_INTEGER_EXT 0x8D9B +#define GL_LUMINANCE_INTEGER_EXT 0x8D9C +#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D +#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARCOLORIIEXTPROC) (GLint red, GLint green, GLint blue, GLint alpha); +typedef void (APIENTRYP PFNGLCLEARCOLORIUIEXTPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexParameterIivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuivEXT (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuivEXT (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearColorIiEXT (GLint red, GLint green, GLint blue, GLint alpha); +GLAPI void APIENTRY glClearColorIuiEXT (GLuint red, GLuint green, GLuint blue, GLuint alpha); +#endif +#endif /* GL_EXT_texture_integer */ + +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif /* GL_EXT_texture_lod_bias */ + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_EXT_texture_mirror_clamp 1 +#define GL_MIRROR_CLAMP_EXT 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 +#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 +#endif /* GL_EXT_texture_mirror_clamp */ + +#ifndef GL_EXT_texture_object +#define GL_EXT_texture_object 1 +#define GL_TEXTURE_PRIORITY_EXT 0x8066 +#define GL_TEXTURE_RESIDENT_EXT 0x8067 +#define GL_TEXTURE_1D_BINDING_EXT 0x8068 +#define GL_TEXTURE_2D_BINDING_EXT 0x8069 +#define GL_TEXTURE_3D_BINDING_EXT 0x806A +typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei n, const GLuint *textures, GLboolean *residences); +GLAPI void APIENTRY glBindTextureEXT (GLenum target, GLuint texture); +GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei n, const GLuint *textures); +GLAPI void APIENTRY glGenTexturesEXT (GLsizei n, GLuint *textures); +GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint texture); +GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif +#endif /* GL_EXT_texture_object */ + +#ifndef GL_EXT_texture_perturb_normal +#define GL_EXT_texture_perturb_normal 1 +#define GL_PERTURB_EXT 0x85AE +#define GL_TEXTURE_NORMAL_EXT 0x85AF +typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureNormalEXT (GLenum mode); +#endif +#endif /* GL_EXT_texture_perturb_normal */ + +#ifndef GL_EXT_texture_sRGB +#define GL_EXT_texture_sRGB 1 +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB8_EXT 0x8C41 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_SLUMINANCE_ALPHA_EXT 0x8C44 +#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45 +#define GL_SLUMINANCE_EXT 0x8C46 +#define GL_SLUMINANCE8_EXT 0x8C47 +#define GL_COMPRESSED_SRGB_EXT 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 +#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B +#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F +#endif /* GL_EXT_texture_sRGB */ + +#ifndef GL_EXT_texture_sRGB_R8 +#define GL_EXT_texture_sRGB_R8 1 +#define GL_SR8_EXT 0x8FBD +#endif /* GL_EXT_texture_sRGB_R8 */ + +#ifndef GL_EXT_texture_sRGB_RG8 +#define GL_EXT_texture_sRGB_RG8 1 +#define GL_SRG8_EXT 0x8FBE +#endif /* GL_EXT_texture_sRGB_RG8 */ + +#ifndef GL_EXT_texture_sRGB_decode +#define GL_EXT_texture_sRGB_decode 1 +#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48 +#define GL_DECODE_EXT 0x8A49 +#define GL_SKIP_DECODE_EXT 0x8A4A +#endif /* GL_EXT_texture_sRGB_decode */ + +#ifndef GL_EXT_texture_shadow_lod +#define GL_EXT_texture_shadow_lod 1 +#endif /* GL_EXT_texture_shadow_lod */ + +#ifndef GL_EXT_texture_shared_exponent +#define GL_EXT_texture_shared_exponent 1 +#define GL_RGB9_E5_EXT 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV_EXT 0x8C3E +#define GL_TEXTURE_SHARED_SIZE_EXT 0x8C3F +#endif /* GL_EXT_texture_shared_exponent */ + +#ifndef GL_EXT_texture_snorm +#define GL_EXT_texture_snorm 1 +#define GL_ALPHA_SNORM 0x9010 +#define GL_LUMINANCE_SNORM 0x9011 +#define GL_LUMINANCE_ALPHA_SNORM 0x9012 +#define GL_INTENSITY_SNORM 0x9013 +#define GL_ALPHA8_SNORM 0x9014 +#define GL_LUMINANCE8_SNORM 0x9015 +#define GL_LUMINANCE8_ALPHA8_SNORM 0x9016 +#define GL_INTENSITY8_SNORM 0x9017 +#define GL_ALPHA16_SNORM 0x9018 +#define GL_LUMINANCE16_SNORM 0x9019 +#define GL_LUMINANCE16_ALPHA16_SNORM 0x901A +#define GL_INTENSITY16_SNORM 0x901B +#define GL_RED_SNORM 0x8F90 +#define GL_RG_SNORM 0x8F91 +#define GL_RGB_SNORM 0x8F92 +#define GL_RGBA_SNORM 0x8F93 +#endif /* GL_EXT_texture_snorm */ + +#ifndef GL_EXT_texture_storage +#define GL_EXT_texture_storage 1 +#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F +#define GL_RGBA32F_EXT 0x8814 +#define GL_RGB32F_EXT 0x8815 +#define GL_ALPHA32F_EXT 0x8816 +#define GL_LUMINANCE32F_EXT 0x8818 +#define GL_LUMINANCE_ALPHA32F_EXT 0x8819 +#define GL_RGBA16F_EXT 0x881A +#define GL_RGB16F_EXT 0x881B +#define GL_ALPHA16F_EXT 0x881C +#define GL_LUMINANCE16F_EXT 0x881E +#define GL_LUMINANCE_ALPHA16F_EXT 0x881F +#define GL_BGRA8_EXT 0x93A1 +#define GL_R8_EXT 0x8229 +#define GL_RG8_EXT 0x822B +#define GL_R32F_EXT 0x822E +#define GL_RG32F_EXT 0x8230 +#define GL_R16F_EXT 0x822D +#define GL_RG16F_EXT 0x822F +typedef void (APIENTRYP PFNGLTEXSTORAGE1DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXSTORAGE2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexStorage1DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTexStorage2DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexStorage3DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif +#endif /* GL_EXT_texture_storage */ + +#ifndef GL_EXT_texture_swizzle +#define GL_EXT_texture_swizzle 1 +#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42 +#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43 +#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44 +#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46 +#endif /* GL_EXT_texture_swizzle */ + +#ifndef GL_EXT_timer_query +#define GL_EXT_timer_query 1 +#define GL_TIME_ELAPSED_EXT 0x88BF +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64 *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64 *params); +#endif +#endif /* GL_EXT_timer_query */ + +#ifndef GL_EXT_transform_feedback +#define GL_EXT_transform_feedback 1 +#define GL_TRANSFORM_FEEDBACK_BUFFER_EXT 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_EXT 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT 0x8C85 +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT 0x8C8F +#define GL_INTERLEAVED_ATTRIBS_EXT 0x8C8C +#define GL_SEPARATE_ATTRIBS_EXT 0x8C8D +#define GL_PRIMITIVES_GENERATED_EXT 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT 0x8C88 +#define GL_RASTERIZER_DISCARD_EXT 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_EXT 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_EXT 0x8C7F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT 0x8C76 +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKEXTPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKEXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEEXTPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSEXTPROC) (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGEXTPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackEXT (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedbackEXT (void); +GLAPI void APIENTRY glBindBufferRangeEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferOffsetEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +GLAPI void APIENTRY glBindBufferBaseEXT (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryingsEXT (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVaryingEXT (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +#endif +#endif /* GL_EXT_transform_feedback */ + +#ifndef GL_EXT_vertex_array +#define GL_EXT_vertex_array 1 +#define GL_VERTEX_ARRAY_EXT 0x8074 +#define GL_NORMAL_ARRAY_EXT 0x8075 +#define GL_COLOR_ARRAY_EXT 0x8076 +#define GL_INDEX_ARRAY_EXT 0x8077 +#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078 +#define GL_EDGE_FLAG_ARRAY_EXT 0x8079 +#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A +#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B +#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C +#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D +#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E +#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F +#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080 +#define GL_COLOR_ARRAY_SIZE_EXT 0x8081 +#define GL_COLOR_ARRAY_TYPE_EXT 0x8082 +#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083 +#define GL_COLOR_ARRAY_COUNT_EXT 0x8084 +#define GL_INDEX_ARRAY_TYPE_EXT 0x8085 +#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086 +#define GL_INDEX_ARRAY_COUNT_EXT 0x8087 +#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A +#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B +#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C +#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D +#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E +#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F +#define GL_COLOR_ARRAY_POINTER_EXT 0x8090 +#define GL_INDEX_ARRAY_POINTER_EXT 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093 +typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); +typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer); +typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); +typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, void **params); +typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const void *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const void *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer); +typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glArrayElementEXT (GLint i); +GLAPI void APIENTRY glColorPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer); +GLAPI void APIENTRY glDrawArraysEXT (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei stride, GLsizei count, const GLboolean *pointer); +GLAPI void APIENTRY glGetPointervEXT (GLenum pname, void **params); +GLAPI void APIENTRY glIndexPointerEXT (GLenum type, GLsizei stride, GLsizei count, const void *pointer); +GLAPI void APIENTRY glNormalPointerEXT (GLenum type, GLsizei stride, GLsizei count, const void *pointer); +GLAPI void APIENTRY glTexCoordPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer); +GLAPI void APIENTRY glVertexPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer); +#endif +#endif /* GL_EXT_vertex_array */ + +#ifndef GL_EXT_vertex_array_bgra +#define GL_EXT_vertex_array_bgra 1 +#endif /* GL_EXT_vertex_array_bgra */ + +#ifndef GL_EXT_vertex_attrib_64bit +#define GL_EXT_vertex_attrib_64bit 1 +#define GL_DOUBLE_VEC2_EXT 0x8FFC +#define GL_DOUBLE_VEC3_EXT 0x8FFD +#define GL_DOUBLE_VEC4_EXT 0x8FFE +#define GL_DOUBLE_MAT2_EXT 0x8F46 +#define GL_DOUBLE_MAT3_EXT 0x8F47 +#define GL_DOUBLE_MAT4_EXT 0x8F48 +#define GL_DOUBLE_MAT2x3_EXT 0x8F49 +#define GL_DOUBLE_MAT2x4_EXT 0x8F4A +#define GL_DOUBLE_MAT3x2_EXT 0x8F4B +#define GL_DOUBLE_MAT3x4_EXT 0x8F4C +#define GL_DOUBLE_MAT4x2_EXT 0x8F4D +#define GL_DOUBLE_MAT4x3_EXT 0x8F4E +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DEXTPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DEXTPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVEXTPROC) (GLuint index, GLenum pname, GLdouble *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1dEXT (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2dEXT (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glGetVertexAttribLdvEXT (GLuint index, GLenum pname, GLdouble *params); +#endif +#endif /* GL_EXT_vertex_attrib_64bit */ + +#ifndef GL_EXT_vertex_shader +#define GL_EXT_vertex_shader 1 +#define GL_VERTEX_SHADER_EXT 0x8780 +#define GL_VERTEX_SHADER_BINDING_EXT 0x8781 +#define GL_OP_INDEX_EXT 0x8782 +#define GL_OP_NEGATE_EXT 0x8783 +#define GL_OP_DOT3_EXT 0x8784 +#define GL_OP_DOT4_EXT 0x8785 +#define GL_OP_MUL_EXT 0x8786 +#define GL_OP_ADD_EXT 0x8787 +#define GL_OP_MADD_EXT 0x8788 +#define GL_OP_FRAC_EXT 0x8789 +#define GL_OP_MAX_EXT 0x878A +#define GL_OP_MIN_EXT 0x878B +#define GL_OP_SET_GE_EXT 0x878C +#define GL_OP_SET_LT_EXT 0x878D +#define GL_OP_CLAMP_EXT 0x878E +#define GL_OP_FLOOR_EXT 0x878F +#define GL_OP_ROUND_EXT 0x8790 +#define GL_OP_EXP_BASE_2_EXT 0x8791 +#define GL_OP_LOG_BASE_2_EXT 0x8792 +#define GL_OP_POWER_EXT 0x8793 +#define GL_OP_RECIP_EXT 0x8794 +#define GL_OP_RECIP_SQRT_EXT 0x8795 +#define GL_OP_SUB_EXT 0x8796 +#define GL_OP_CROSS_PRODUCT_EXT 0x8797 +#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798 +#define GL_OP_MOV_EXT 0x8799 +#define GL_OUTPUT_VERTEX_EXT 0x879A +#define GL_OUTPUT_COLOR0_EXT 0x879B +#define GL_OUTPUT_COLOR1_EXT 0x879C +#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D +#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E +#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F +#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0 +#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1 +#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2 +#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3 +#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4 +#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5 +#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6 +#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7 +#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8 +#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9 +#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA +#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB +#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC +#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD +#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE +#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF +#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0 +#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1 +#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2 +#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3 +#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4 +#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5 +#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6 +#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7 +#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8 +#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9 +#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA +#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB +#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC +#define GL_OUTPUT_FOG_EXT 0x87BD +#define GL_SCALAR_EXT 0x87BE +#define GL_VECTOR_EXT 0x87BF +#define GL_MATRIX_EXT 0x87C0 +#define GL_VARIANT_EXT 0x87C1 +#define GL_INVARIANT_EXT 0x87C2 +#define GL_LOCAL_CONSTANT_EXT 0x87C3 +#define GL_LOCAL_EXT 0x87C4 +#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5 +#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6 +#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7 +#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8 +#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9 +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE +#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF +#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0 +#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1 +#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2 +#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3 +#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4 +#define GL_X_EXT 0x87D5 +#define GL_Y_EXT 0x87D6 +#define GL_Z_EXT 0x87D7 +#define GL_W_EXT 0x87D8 +#define GL_NEGATIVE_X_EXT 0x87D9 +#define GL_NEGATIVE_Y_EXT 0x87DA +#define GL_NEGATIVE_Z_EXT 0x87DB +#define GL_NEGATIVE_W_EXT 0x87DC +#define GL_ZERO_EXT 0x87DD +#define GL_ONE_EXT 0x87DE +#define GL_NEGATIVE_ONE_EXT 0x87DF +#define GL_NORMALIZED_RANGE_EXT 0x87E0 +#define GL_FULL_RANGE_EXT 0x87E1 +#define GL_CURRENT_VERTEX_EXT 0x87E2 +#define GL_MVP_MATRIX_EXT 0x87E3 +#define GL_VARIANT_VALUE_EXT 0x87E4 +#define GL_VARIANT_DATATYPE_EXT 0x87E5 +#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6 +#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7 +#define GL_VARIANT_ARRAY_EXT 0x87E8 +#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9 +#define GL_INVARIANT_VALUE_EXT 0x87EA +#define GL_INVARIANT_DATATYPE_EXT 0x87EB +#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC +#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED +typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); +typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); +typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const void *addr); +typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const void *addr); +typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); +typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); +typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); +typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); +typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); +typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); +typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); +typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); +typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const void *addr); +typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); +typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); +typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, void **data); +typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVertexShaderEXT (void); +GLAPI void APIENTRY glEndVertexShaderEXT (void); +GLAPI void APIENTRY glBindVertexShaderEXT (GLuint id); +GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint range); +GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint id); +GLAPI void APIENTRY glShaderOp1EXT (GLenum op, GLuint res, GLuint arg1); +GLAPI void APIENTRY glShaderOp2EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +GLAPI void APIENTRY glShaderOp3EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +GLAPI void APIENTRY glSwizzleEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +GLAPI void APIENTRY glWriteMaskEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +GLAPI void APIENTRY glInsertComponentEXT (GLuint res, GLuint src, GLuint num); +GLAPI void APIENTRY glExtractComponentEXT (GLuint res, GLuint src, GLuint num); +GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +GLAPI void APIENTRY glSetInvariantEXT (GLuint id, GLenum type, const void *addr); +GLAPI void APIENTRY glSetLocalConstantEXT (GLuint id, GLenum type, const void *addr); +GLAPI void APIENTRY glVariantbvEXT (GLuint id, const GLbyte *addr); +GLAPI void APIENTRY glVariantsvEXT (GLuint id, const GLshort *addr); +GLAPI void APIENTRY glVariantivEXT (GLuint id, const GLint *addr); +GLAPI void APIENTRY glVariantfvEXT (GLuint id, const GLfloat *addr); +GLAPI void APIENTRY glVariantdvEXT (GLuint id, const GLdouble *addr); +GLAPI void APIENTRY glVariantubvEXT (GLuint id, const GLubyte *addr); +GLAPI void APIENTRY glVariantusvEXT (GLuint id, const GLushort *addr); +GLAPI void APIENTRY glVariantuivEXT (GLuint id, const GLuint *addr); +GLAPI void APIENTRY glVariantPointerEXT (GLuint id, GLenum type, GLuint stride, const void *addr); +GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint id); +GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint id); +GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum light, GLenum value); +GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum face, GLenum value); +GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum unit, GLenum coord, GLenum value); +GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum unit, GLenum value); +GLAPI GLuint APIENTRY glBindParameterEXT (GLenum value); +GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint id, GLenum cap); +GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +GLAPI void APIENTRY glGetVariantPointervEXT (GLuint id, GLenum value, void **data); +GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +#endif +#endif /* GL_EXT_vertex_shader */ + +#ifndef GL_EXT_vertex_weighting +#define GL_EXT_vertex_weighting 1 +#define GL_MODELVIEW0_STACK_DEPTH_EXT 0x0BA3 +#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502 +#define GL_MODELVIEW0_MATRIX_EXT 0x0BA6 +#define GL_MODELVIEW1_MATRIX_EXT 0x8506 +#define GL_VERTEX_WEIGHTING_EXT 0x8509 +#define GL_MODELVIEW0_EXT 0x1700 +#define GL_MODELVIEW1_EXT 0x850A +#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B +#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C +#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D +#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E +#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F +#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510 +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexWeightfEXT (GLfloat weight); +GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *weight); +GLAPI void APIENTRY glVertexWeightPointerEXT (GLint size, GLenum type, GLsizei stride, const void *pointer); +#endif +#endif /* GL_EXT_vertex_weighting */ + +#ifndef GL_EXT_win32_keyed_mutex +#define GL_EXT_win32_keyed_mutex 1 +typedef GLboolean (APIENTRYP PFNGLACQUIREKEYEDMUTEXWIN32EXTPROC) (GLuint memory, GLuint64 key, GLuint timeout); +typedef GLboolean (APIENTRYP PFNGLRELEASEKEYEDMUTEXWIN32EXTPROC) (GLuint memory, GLuint64 key); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAcquireKeyedMutexWin32EXT (GLuint memory, GLuint64 key, GLuint timeout); +GLAPI GLboolean APIENTRY glReleaseKeyedMutexWin32EXT (GLuint memory, GLuint64 key); +#endif +#endif /* GL_EXT_win32_keyed_mutex */ + +#ifndef GL_EXT_window_rectangles +#define GL_EXT_window_rectangles 1 +#define GL_INCLUSIVE_EXT 0x8F10 +#define GL_EXCLUSIVE_EXT 0x8F11 +#define GL_WINDOW_RECTANGLE_EXT 0x8F12 +#define GL_WINDOW_RECTANGLE_MODE_EXT 0x8F13 +#define GL_MAX_WINDOW_RECTANGLES_EXT 0x8F14 +#define GL_NUM_WINDOW_RECTANGLES_EXT 0x8F15 +typedef void (APIENTRYP PFNGLWINDOWRECTANGLESEXTPROC) (GLenum mode, GLsizei count, const GLint *box); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowRectanglesEXT (GLenum mode, GLsizei count, const GLint *box); +#endif +#endif /* GL_EXT_window_rectangles */ + +#ifndef GL_EXT_x11_sync_object +#define GL_EXT_x11_sync_object 1 +#define GL_SYNC_X11_FENCE_EXT 0x90E1 +typedef GLsync (APIENTRYP PFNGLIMPORTSYNCEXTPROC) (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLsync APIENTRY glImportSyncEXT (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags); +#endif +#endif /* GL_EXT_x11_sync_object */ + +#ifndef GL_GREMEDY_frame_terminator +#define GL_GREMEDY_frame_terminator 1 +typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameTerminatorGREMEDY (void); +#endif +#endif /* GL_GREMEDY_frame_terminator */ + +#ifndef GL_GREMEDY_string_marker +#define GL_GREMEDY_string_marker 1 +typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const void *string); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei len, const void *string); +#endif +#endif /* GL_GREMEDY_string_marker */ + +#ifndef GL_HP_convolution_border_modes +#define GL_HP_convolution_border_modes 1 +#define GL_IGNORE_BORDER_HP 0x8150 +#define GL_CONSTANT_BORDER_HP 0x8151 +#define GL_REPLICATE_BORDER_HP 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154 +#endif /* GL_HP_convolution_border_modes */ + +#ifndef GL_HP_image_transform +#define GL_HP_image_transform 1 +#define GL_IMAGE_SCALE_X_HP 0x8155 +#define GL_IMAGE_SCALE_Y_HP 0x8156 +#define GL_IMAGE_TRANSLATE_X_HP 0x8157 +#define GL_IMAGE_TRANSLATE_Y_HP 0x8158 +#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159 +#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A +#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B +#define GL_IMAGE_MAG_FILTER_HP 0x815C +#define GL_IMAGE_MIN_FILTER_HP 0x815D +#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E +#define GL_CUBIC_HP 0x815F +#define GL_AVERAGE_HP 0x8160 +#define GL_IMAGE_TRANSFORM_2D_HP 0x8161 +#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162 +#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163 +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImageTransformParameteriHP (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glImageTransformParameterfHP (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glImageTransformParameterivHP (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum target, GLenum pname, GLfloat *params); +#endif +#endif /* GL_HP_image_transform */ + +#ifndef GL_HP_occlusion_test +#define GL_HP_occlusion_test 1 +#define GL_OCCLUSION_TEST_HP 0x8165 +#define GL_OCCLUSION_TEST_RESULT_HP 0x8166 +#endif /* GL_HP_occlusion_test */ + +#ifndef GL_HP_texture_lighting +#define GL_HP_texture_lighting 1 +#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167 +#define GL_TEXTURE_POST_SPECULAR_HP 0x8168 +#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169 +#endif /* GL_HP_texture_lighting */ + +#ifndef GL_IBM_cull_vertex +#define GL_IBM_cull_vertex 1 +#define GL_CULL_VERTEX_IBM 103050 +#endif /* GL_IBM_cull_vertex */ + +#ifndef GL_IBM_multimode_draw_arrays +#define GL_IBM_multimode_draw_arrays 1 +typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, GLint modestride); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, GLint modestride); +#endif +#endif /* GL_IBM_multimode_draw_arrays */ + +#ifndef GL_IBM_rasterpos_clip +#define GL_IBM_rasterpos_clip 1 +#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262 +#endif /* GL_IBM_rasterpos_clip */ + +#ifndef GL_IBM_static_data +#define GL_IBM_static_data 1 +#define GL_ALL_STATIC_DATA_IBM 103060 +#define GL_STATIC_VERTEX_ARRAY_IBM 103061 +typedef void (APIENTRYP PFNGLFLUSHSTATICDATAIBMPROC) (GLenum target); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushStaticDataIBM (GLenum target); +#endif +#endif /* GL_IBM_static_data */ + +#ifndef GL_IBM_texture_mirrored_repeat +#define GL_IBM_texture_mirrored_repeat 1 +#define GL_MIRRORED_REPEAT_IBM 0x8370 +#endif /* GL_IBM_texture_mirrored_repeat */ + +#ifndef GL_IBM_vertex_array_lists +#define GL_IBM_vertex_array_lists 1 +#define GL_VERTEX_ARRAY_LIST_IBM 103070 +#define GL_NORMAL_ARRAY_LIST_IBM 103071 +#define GL_COLOR_ARRAY_LIST_IBM 103072 +#define GL_INDEX_ARRAY_LIST_IBM 103073 +#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074 +#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075 +#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076 +#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077 +#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080 +#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081 +#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082 +#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083 +#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084 +#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085 +#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086 +#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087 +typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean **pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint stride, const GLboolean **pointer, GLint ptrstride); +GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride); +GLAPI void APIENTRY glIndexPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride); +GLAPI void APIENTRY glNormalPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride); +GLAPI void APIENTRY glTexCoordPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +GLAPI void APIENTRY glVertexPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride); +#endif +#endif /* GL_IBM_vertex_array_lists */ + +#ifndef GL_INGR_blend_func_separate +#define GL_INGR_blend_func_separate 1 +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif +#endif /* GL_INGR_blend_func_separate */ + +#ifndef GL_INGR_color_clamp +#define GL_INGR_color_clamp 1 +#define GL_RED_MIN_CLAMP_INGR 0x8560 +#define GL_GREEN_MIN_CLAMP_INGR 0x8561 +#define GL_BLUE_MIN_CLAMP_INGR 0x8562 +#define GL_ALPHA_MIN_CLAMP_INGR 0x8563 +#define GL_RED_MAX_CLAMP_INGR 0x8564 +#define GL_GREEN_MAX_CLAMP_INGR 0x8565 +#define GL_BLUE_MAX_CLAMP_INGR 0x8566 +#define GL_ALPHA_MAX_CLAMP_INGR 0x8567 +#endif /* GL_INGR_color_clamp */ + +#ifndef GL_INGR_interlace_read +#define GL_INGR_interlace_read 1 +#define GL_INTERLACE_READ_INGR 0x8568 +#endif /* GL_INGR_interlace_read */ + +#ifndef GL_INTEL_blackhole_render +#define GL_INTEL_blackhole_render 1 +#define GL_BLACKHOLE_RENDER_INTEL 0x83FC +#endif /* GL_INTEL_blackhole_render */ + +#ifndef GL_INTEL_conservative_rasterization +#define GL_INTEL_conservative_rasterization 1 +#define GL_CONSERVATIVE_RASTERIZATION_INTEL 0x83FE +#endif /* GL_INTEL_conservative_rasterization */ + +#ifndef GL_INTEL_fragment_shader_ordering +#define GL_INTEL_fragment_shader_ordering 1 +#endif /* GL_INTEL_fragment_shader_ordering */ + +#ifndef GL_INTEL_framebuffer_CMAA +#define GL_INTEL_framebuffer_CMAA 1 +typedef void (APIENTRYP PFNGLAPPLYFRAMEBUFFERATTACHMENTCMAAINTELPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glApplyFramebufferAttachmentCMAAINTEL (void); +#endif +#endif /* GL_INTEL_framebuffer_CMAA */ + +#ifndef GL_INTEL_map_texture +#define GL_INTEL_map_texture 1 +#define GL_TEXTURE_MEMORY_LAYOUT_INTEL 0x83FF +#define GL_LAYOUT_DEFAULT_INTEL 0 +#define GL_LAYOUT_LINEAR_INTEL 1 +#define GL_LAYOUT_LINEAR_CPU_CACHED_INTEL 2 +typedef void (APIENTRYP PFNGLSYNCTEXTUREINTELPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLUNMAPTEXTURE2DINTELPROC) (GLuint texture, GLint level); +typedef void *(APIENTRYP PFNGLMAPTEXTURE2DINTELPROC) (GLuint texture, GLint level, GLbitfield access, GLint *stride, GLenum *layout); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSyncTextureINTEL (GLuint texture); +GLAPI void APIENTRY glUnmapTexture2DINTEL (GLuint texture, GLint level); +GLAPI void *APIENTRY glMapTexture2DINTEL (GLuint texture, GLint level, GLbitfield access, GLint *stride, GLenum *layout); +#endif +#endif /* GL_INTEL_map_texture */ + +#ifndef GL_INTEL_parallel_arrays +#define GL_INTEL_parallel_arrays 1 +#define GL_PARALLEL_ARRAYS_INTEL 0x83F4 +#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5 +#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6 +#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7 +#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8 +typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const void **pointer); +typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexPointervINTEL (GLint size, GLenum type, const void **pointer); +GLAPI void APIENTRY glNormalPointervINTEL (GLenum type, const void **pointer); +GLAPI void APIENTRY glColorPointervINTEL (GLint size, GLenum type, const void **pointer); +GLAPI void APIENTRY glTexCoordPointervINTEL (GLint size, GLenum type, const void **pointer); +#endif +#endif /* GL_INTEL_parallel_arrays */ + +#ifndef GL_INTEL_performance_query +#define GL_INTEL_performance_query 1 +#define GL_PERFQUERY_SINGLE_CONTEXT_INTEL 0x00000000 +#define GL_PERFQUERY_GLOBAL_CONTEXT_INTEL 0x00000001 +#define GL_PERFQUERY_WAIT_INTEL 0x83FB +#define GL_PERFQUERY_FLUSH_INTEL 0x83FA +#define GL_PERFQUERY_DONOT_FLUSH_INTEL 0x83F9 +#define GL_PERFQUERY_COUNTER_EVENT_INTEL 0x94F0 +#define GL_PERFQUERY_COUNTER_DURATION_NORM_INTEL 0x94F1 +#define GL_PERFQUERY_COUNTER_DURATION_RAW_INTEL 0x94F2 +#define GL_PERFQUERY_COUNTER_THROUGHPUT_INTEL 0x94F3 +#define GL_PERFQUERY_COUNTER_RAW_INTEL 0x94F4 +#define GL_PERFQUERY_COUNTER_TIMESTAMP_INTEL 0x94F5 +#define GL_PERFQUERY_COUNTER_DATA_UINT32_INTEL 0x94F8 +#define GL_PERFQUERY_COUNTER_DATA_UINT64_INTEL 0x94F9 +#define GL_PERFQUERY_COUNTER_DATA_FLOAT_INTEL 0x94FA +#define GL_PERFQUERY_COUNTER_DATA_DOUBLE_INTEL 0x94FB +#define GL_PERFQUERY_COUNTER_DATA_BOOL32_INTEL 0x94FC +#define GL_PERFQUERY_QUERY_NAME_LENGTH_MAX_INTEL 0x94FD +#define GL_PERFQUERY_COUNTER_NAME_LENGTH_MAX_INTEL 0x94FE +#define GL_PERFQUERY_COUNTER_DESC_LENGTH_MAX_INTEL 0x94FF +#define GL_PERFQUERY_GPA_EXTENDED_COUNTERS_INTEL 0x9500 +typedef void (APIENTRYP PFNGLBEGINPERFQUERYINTELPROC) (GLuint queryHandle); +typedef void (APIENTRYP PFNGLCREATEPERFQUERYINTELPROC) (GLuint queryId, GLuint *queryHandle); +typedef void (APIENTRYP PFNGLDELETEPERFQUERYINTELPROC) (GLuint queryHandle); +typedef void (APIENTRYP PFNGLENDPERFQUERYINTELPROC) (GLuint queryHandle); +typedef void (APIENTRYP PFNGLGETFIRSTPERFQUERYIDINTELPROC) (GLuint *queryId); +typedef void (APIENTRYP PFNGLGETNEXTPERFQUERYIDINTELPROC) (GLuint queryId, GLuint *nextQueryId); +typedef void (APIENTRYP PFNGLGETPERFCOUNTERINFOINTELPROC) (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue); +typedef void (APIENTRYP PFNGLGETPERFQUERYDATAINTELPROC) (GLuint queryHandle, GLuint flags, GLsizei dataSize, void *data, GLuint *bytesWritten); +typedef void (APIENTRYP PFNGLGETPERFQUERYIDBYNAMEINTELPROC) (GLchar *queryName, GLuint *queryId); +typedef void (APIENTRYP PFNGLGETPERFQUERYINFOINTELPROC) (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginPerfQueryINTEL (GLuint queryHandle); +GLAPI void APIENTRY glCreatePerfQueryINTEL (GLuint queryId, GLuint *queryHandle); +GLAPI void APIENTRY glDeletePerfQueryINTEL (GLuint queryHandle); +GLAPI void APIENTRY glEndPerfQueryINTEL (GLuint queryHandle); +GLAPI void APIENTRY glGetFirstPerfQueryIdINTEL (GLuint *queryId); +GLAPI void APIENTRY glGetNextPerfQueryIdINTEL (GLuint queryId, GLuint *nextQueryId); +GLAPI void APIENTRY glGetPerfCounterInfoINTEL (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue); +GLAPI void APIENTRY glGetPerfQueryDataINTEL (GLuint queryHandle, GLuint flags, GLsizei dataSize, void *data, GLuint *bytesWritten); +GLAPI void APIENTRY glGetPerfQueryIdByNameINTEL (GLchar *queryName, GLuint *queryId); +GLAPI void APIENTRY glGetPerfQueryInfoINTEL (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask); +#endif +#endif /* GL_INTEL_performance_query */ + +#ifndef GL_MESAX_texture_stack +#define GL_MESAX_texture_stack 1 +#define GL_TEXTURE_1D_STACK_MESAX 0x8759 +#define GL_TEXTURE_2D_STACK_MESAX 0x875A +#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B +#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C +#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D +#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E +#endif /* GL_MESAX_texture_stack */ + +#ifndef GL_MESA_framebuffer_flip_x +#define GL_MESA_framebuffer_flip_x 1 +#define GL_FRAMEBUFFER_FLIP_X_MESA 0x8BBC +#endif /* GL_MESA_framebuffer_flip_x */ + +#ifndef GL_MESA_framebuffer_flip_y +#define GL_MESA_framebuffer_flip_y 1 +#define GL_FRAMEBUFFER_FLIP_Y_MESA 0x8BBB +typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIMESAPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVMESAPROC) (GLenum target, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferParameteriMESA (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glGetFramebufferParameterivMESA (GLenum target, GLenum pname, GLint *params); +#endif +#endif /* GL_MESA_framebuffer_flip_y */ + +#ifndef GL_MESA_framebuffer_swap_xy +#define GL_MESA_framebuffer_swap_xy 1 +#define GL_FRAMEBUFFER_SWAP_XY_MESA 0x8BBD +#endif /* GL_MESA_framebuffer_swap_xy */ + +#ifndef GL_MESA_pack_invert +#define GL_MESA_pack_invert 1 +#define GL_PACK_INVERT_MESA 0x8758 +#endif /* GL_MESA_pack_invert */ + +#ifndef GL_MESA_program_binary_formats +#define GL_MESA_program_binary_formats 1 +#define GL_PROGRAM_BINARY_FORMAT_MESA 0x875F +#endif /* GL_MESA_program_binary_formats */ + +#ifndef GL_MESA_resize_buffers +#define GL_MESA_resize_buffers 1 +typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glResizeBuffersMESA (void); +#endif +#endif /* GL_MESA_resize_buffers */ + +#ifndef GL_MESA_shader_integer_functions +#define GL_MESA_shader_integer_functions 1 +#endif /* GL_MESA_shader_integer_functions */ + +#ifndef GL_MESA_tile_raster_order +#define GL_MESA_tile_raster_order 1 +#define GL_TILE_RASTER_ORDER_FIXED_MESA 0x8BB8 +#define GL_TILE_RASTER_ORDER_INCREASING_X_MESA 0x8BB9 +#define GL_TILE_RASTER_ORDER_INCREASING_Y_MESA 0x8BBA +#endif /* GL_MESA_tile_raster_order */ + +#ifndef GL_MESA_window_pos +#define GL_MESA_window_pos 1 +typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dMESA (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2fMESA (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2iMESA (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos2sMESA (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *v); +GLAPI void APIENTRY glWindowPos3dMESA (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3iMESA (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos3sMESA (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *v); +GLAPI void APIENTRY glWindowPos4dMESA (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos4fMESA (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos4iMESA (GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos4sMESA (GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *v); +#endif +#endif /* GL_MESA_window_pos */ + +#ifndef GL_MESA_ycbcr_texture +#define GL_MESA_ycbcr_texture 1 +#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB +#define GL_YCBCR_MESA 0x8757 +#endif /* GL_MESA_ycbcr_texture */ + +#ifndef GL_NVX_blend_equation_advanced_multi_draw_buffers +#define GL_NVX_blend_equation_advanced_multi_draw_buffers 1 +#endif /* GL_NVX_blend_equation_advanced_multi_draw_buffers */ + +#ifndef GL_NVX_conditional_render +#define GL_NVX_conditional_render 1 +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVXPROC) (GLuint id); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVXPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginConditionalRenderNVX (GLuint id); +GLAPI void APIENTRY glEndConditionalRenderNVX (void); +#endif +#endif /* GL_NVX_conditional_render */ + +#ifndef GL_NVX_gpu_memory_info +#define GL_NVX_gpu_memory_info 1 +#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047 +#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048 +#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049 +#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A +#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B +#endif /* GL_NVX_gpu_memory_info */ + +#ifndef GL_NVX_gpu_multicast2 +#define GL_NVX_gpu_multicast2 1 +#define GL_UPLOAD_GPU_MASK_NVX 0x954A +typedef void (APIENTRYP PFNGLUPLOADGPUMASKNVXPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLMULTICASTVIEWPORTARRAYVNVXPROC) (GLuint gpu, GLuint first, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTICASTVIEWPORTPOSITIONWSCALENVXPROC) (GLuint gpu, GLuint index, GLfloat xcoeff, GLfloat ycoeff); +typedef void (APIENTRYP PFNGLMULTICASTSCISSORARRAYVNVXPROC) (GLuint gpu, GLuint first, GLsizei count, const GLint *v); +typedef GLuint (APIENTRYP PFNGLASYNCCOPYBUFFERSUBDATANVXPROC) (GLsizei waitSemaphoreCount, const GLuint *waitSemaphoreArray, const GLuint64 *fenceValueArray, GLuint readGpu, GLbitfield writeGpuMask, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size, GLsizei signalSemaphoreCount, const GLuint *signalSemaphoreArray, const GLuint64 *signalValueArray); +typedef GLuint (APIENTRYP PFNGLASYNCCOPYIMAGESUBDATANVXPROC) (GLsizei waitSemaphoreCount, const GLuint *waitSemaphoreArray, const GLuint64 *waitValueArray, GLuint srcGpu, GLbitfield dstGpuMask, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth, GLsizei signalSemaphoreCount, const GLuint *signalSemaphoreArray, const GLuint64 *signalValueArray); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUploadGpuMaskNVX (GLbitfield mask); +GLAPI void APIENTRY glMulticastViewportArrayvNVX (GLuint gpu, GLuint first, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glMulticastViewportPositionWScaleNVX (GLuint gpu, GLuint index, GLfloat xcoeff, GLfloat ycoeff); +GLAPI void APIENTRY glMulticastScissorArrayvNVX (GLuint gpu, GLuint first, GLsizei count, const GLint *v); +GLAPI GLuint APIENTRY glAsyncCopyBufferSubDataNVX (GLsizei waitSemaphoreCount, const GLuint *waitSemaphoreArray, const GLuint64 *fenceValueArray, GLuint readGpu, GLbitfield writeGpuMask, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size, GLsizei signalSemaphoreCount, const GLuint *signalSemaphoreArray, const GLuint64 *signalValueArray); +GLAPI GLuint APIENTRY glAsyncCopyImageSubDataNVX (GLsizei waitSemaphoreCount, const GLuint *waitSemaphoreArray, const GLuint64 *waitValueArray, GLuint srcGpu, GLbitfield dstGpuMask, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth, GLsizei signalSemaphoreCount, const GLuint *signalSemaphoreArray, const GLuint64 *signalValueArray); +#endif +#endif /* GL_NVX_gpu_multicast2 */ + +#ifndef GL_NVX_linked_gpu_multicast +#define GL_NVX_linked_gpu_multicast 1 +#define GL_LGPU_SEPARATE_STORAGE_BIT_NVX 0x0800 +#define GL_MAX_LGPU_GPUS_NVX 0x92BA +typedef void (APIENTRYP PFNGLLGPUNAMEDBUFFERSUBDATANVXPROC) (GLbitfield gpuMask, GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +typedef void (APIENTRYP PFNGLLGPUCOPYIMAGESUBDATANVXPROC) (GLuint sourceGpu, GLbitfield destinationGpuMask, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srxY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLLGPUINTERLOCKNVXPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLGPUNamedBufferSubDataNVX (GLbitfield gpuMask, GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +GLAPI void APIENTRY glLGPUCopyImageSubDataNVX (GLuint sourceGpu, GLbitfield destinationGpuMask, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srxY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glLGPUInterlockNVX (void); +#endif +#endif /* GL_NVX_linked_gpu_multicast */ + +#ifndef GL_NVX_progress_fence +#define GL_NVX_progress_fence 1 +typedef GLuint (APIENTRYP PFNGLCREATEPROGRESSFENCENVXPROC) (void); +typedef void (APIENTRYP PFNGLSIGNALSEMAPHOREUI64NVXPROC) (GLuint signalGpu, GLsizei fenceObjectCount, const GLuint *semaphoreArray, const GLuint64 *fenceValueArray); +typedef void (APIENTRYP PFNGLWAITSEMAPHOREUI64NVXPROC) (GLuint waitGpu, GLsizei fenceObjectCount, const GLuint *semaphoreArray, const GLuint64 *fenceValueArray); +typedef void (APIENTRYP PFNGLCLIENTWAITSEMAPHOREUI64NVXPROC) (GLsizei fenceObjectCount, const GLuint *semaphoreArray, const GLuint64 *fenceValueArray); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glCreateProgressFenceNVX (void); +GLAPI void APIENTRY glSignalSemaphoreui64NVX (GLuint signalGpu, GLsizei fenceObjectCount, const GLuint *semaphoreArray, const GLuint64 *fenceValueArray); +GLAPI void APIENTRY glWaitSemaphoreui64NVX (GLuint waitGpu, GLsizei fenceObjectCount, const GLuint *semaphoreArray, const GLuint64 *fenceValueArray); +GLAPI void APIENTRY glClientWaitSemaphoreui64NVX (GLsizei fenceObjectCount, const GLuint *semaphoreArray, const GLuint64 *fenceValueArray); +#endif +#endif /* GL_NVX_progress_fence */ + +#ifndef GL_NV_alpha_to_coverage_dither_control +#define GL_NV_alpha_to_coverage_dither_control 1 +#define GL_ALPHA_TO_COVERAGE_DITHER_DEFAULT_NV 0x934D +#define GL_ALPHA_TO_COVERAGE_DITHER_ENABLE_NV 0x934E +#define GL_ALPHA_TO_COVERAGE_DITHER_DISABLE_NV 0x934F +#define GL_ALPHA_TO_COVERAGE_DITHER_MODE_NV 0x92BF +typedef void (APIENTRYP PFNGLALPHATOCOVERAGEDITHERCONTROLNVPROC) (GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAlphaToCoverageDitherControlNV (GLenum mode); +#endif +#endif /* GL_NV_alpha_to_coverage_dither_control */ + +#ifndef GL_NV_bindless_multi_draw_indirect +#define GL_NV_bindless_multi_draw_indirect 1 +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTBINDLESSNVPROC) (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTBINDLESSNVPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirectBindlessNV (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount); +GLAPI void APIENTRY glMultiDrawElementsIndirectBindlessNV (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount); +#endif +#endif /* GL_NV_bindless_multi_draw_indirect */ + +#ifndef GL_NV_bindless_multi_draw_indirect_count +#define GL_NV_bindless_multi_draw_indirect_count 1 +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTBINDLESSCOUNTNVPROC) (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei maxDrawCount, GLsizei stride, GLint vertexBufferCount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTBINDLESSCOUNTNVPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei maxDrawCount, GLsizei stride, GLint vertexBufferCount); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirectBindlessCountNV (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei maxDrawCount, GLsizei stride, GLint vertexBufferCount); +GLAPI void APIENTRY glMultiDrawElementsIndirectBindlessCountNV (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei maxDrawCount, GLsizei stride, GLint vertexBufferCount); +#endif +#endif /* GL_NV_bindless_multi_draw_indirect_count */ + +#ifndef GL_NV_bindless_texture +#define GL_NV_bindless_texture 1 +typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLENVPROC) (GLuint texture); +typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLENVPROC) (GLuint texture, GLuint sampler); +typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle); +typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTNVPROC) (GLuint64 handle); +typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLENVPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); +typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle, GLenum access); +typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTNVPROC) (GLuint64 handle); +typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64NVPROC) (GLint location, GLuint64 value); +typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VNVPROC) (GLint location, GLsizei count, const GLuint64 *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64NVPROC) (GLuint program, GLint location, GLuint64 value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle); +typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint64 APIENTRY glGetTextureHandleNV (GLuint texture); +GLAPI GLuint64 APIENTRY glGetTextureSamplerHandleNV (GLuint texture, GLuint sampler); +GLAPI void APIENTRY glMakeTextureHandleResidentNV (GLuint64 handle); +GLAPI void APIENTRY glMakeTextureHandleNonResidentNV (GLuint64 handle); +GLAPI GLuint64 APIENTRY glGetImageHandleNV (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); +GLAPI void APIENTRY glMakeImageHandleResidentNV (GLuint64 handle, GLenum access); +GLAPI void APIENTRY glMakeImageHandleNonResidentNV (GLuint64 handle); +GLAPI void APIENTRY glUniformHandleui64NV (GLint location, GLuint64 value); +GLAPI void APIENTRY glUniformHandleui64vNV (GLint location, GLsizei count, const GLuint64 *value); +GLAPI void APIENTRY glProgramUniformHandleui64NV (GLuint program, GLint location, GLuint64 value); +GLAPI void APIENTRY glProgramUniformHandleui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64 *values); +GLAPI GLboolean APIENTRY glIsTextureHandleResidentNV (GLuint64 handle); +GLAPI GLboolean APIENTRY glIsImageHandleResidentNV (GLuint64 handle); +#endif +#endif /* GL_NV_bindless_texture */ + +#ifndef GL_NV_blend_equation_advanced +#define GL_NV_blend_equation_advanced 1 +#define GL_BLEND_OVERLAP_NV 0x9281 +#define GL_BLEND_PREMULTIPLIED_SRC_NV 0x9280 +#define GL_BLUE_NV 0x1905 +#define GL_COLORBURN_NV 0x929A +#define GL_COLORDODGE_NV 0x9299 +#define GL_CONJOINT_NV 0x9284 +#define GL_CONTRAST_NV 0x92A1 +#define GL_DARKEN_NV 0x9297 +#define GL_DIFFERENCE_NV 0x929E +#define GL_DISJOINT_NV 0x9283 +#define GL_DST_ATOP_NV 0x928F +#define GL_DST_IN_NV 0x928B +#define GL_DST_NV 0x9287 +#define GL_DST_OUT_NV 0x928D +#define GL_DST_OVER_NV 0x9289 +#define GL_EXCLUSION_NV 0x92A0 +#define GL_GREEN_NV 0x1904 +#define GL_HARDLIGHT_NV 0x929B +#define GL_HARDMIX_NV 0x92A9 +#define GL_HSL_COLOR_NV 0x92AF +#define GL_HSL_HUE_NV 0x92AD +#define GL_HSL_LUMINOSITY_NV 0x92B0 +#define GL_HSL_SATURATION_NV 0x92AE +#define GL_INVERT_OVG_NV 0x92B4 +#define GL_INVERT_RGB_NV 0x92A3 +#define GL_LIGHTEN_NV 0x9298 +#define GL_LINEARBURN_NV 0x92A5 +#define GL_LINEARDODGE_NV 0x92A4 +#define GL_LINEARLIGHT_NV 0x92A7 +#define GL_MINUS_CLAMPED_NV 0x92B3 +#define GL_MINUS_NV 0x929F +#define GL_MULTIPLY_NV 0x9294 +#define GL_OVERLAY_NV 0x9296 +#define GL_PINLIGHT_NV 0x92A8 +#define GL_PLUS_CLAMPED_ALPHA_NV 0x92B2 +#define GL_PLUS_CLAMPED_NV 0x92B1 +#define GL_PLUS_DARKER_NV 0x9292 +#define GL_PLUS_NV 0x9291 +#define GL_RED_NV 0x1903 +#define GL_SCREEN_NV 0x9295 +#define GL_SOFTLIGHT_NV 0x929C +#define GL_SRC_ATOP_NV 0x928E +#define GL_SRC_IN_NV 0x928A +#define GL_SRC_NV 0x9286 +#define GL_SRC_OUT_NV 0x928C +#define GL_SRC_OVER_NV 0x9288 +#define GL_UNCORRELATED_NV 0x9282 +#define GL_VIVIDLIGHT_NV 0x92A6 +#define GL_XOR_NV 0x1506 +typedef void (APIENTRYP PFNGLBLENDPARAMETERINVPROC) (GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLBLENDBARRIERNVPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendParameteriNV (GLenum pname, GLint value); +GLAPI void APIENTRY glBlendBarrierNV (void); +#endif +#endif /* GL_NV_blend_equation_advanced */ + +#ifndef GL_NV_blend_equation_advanced_coherent +#define GL_NV_blend_equation_advanced_coherent 1 +#define GL_BLEND_ADVANCED_COHERENT_NV 0x9285 +#endif /* GL_NV_blend_equation_advanced_coherent */ + +#ifndef GL_NV_blend_minmax_factor +#define GL_NV_blend_minmax_factor 1 +#endif /* GL_NV_blend_minmax_factor */ + +#ifndef GL_NV_blend_square +#define GL_NV_blend_square 1 +#endif /* GL_NV_blend_square */ + +#ifndef GL_NV_clip_space_w_scaling +#define GL_NV_clip_space_w_scaling 1 +#define GL_VIEWPORT_POSITION_W_SCALE_NV 0x937C +#define GL_VIEWPORT_POSITION_W_SCALE_X_COEFF_NV 0x937D +#define GL_VIEWPORT_POSITION_W_SCALE_Y_COEFF_NV 0x937E +typedef void (APIENTRYP PFNGLVIEWPORTPOSITIONWSCALENVPROC) (GLuint index, GLfloat xcoeff, GLfloat ycoeff); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glViewportPositionWScaleNV (GLuint index, GLfloat xcoeff, GLfloat ycoeff); +#endif +#endif /* GL_NV_clip_space_w_scaling */ + +#ifndef GL_NV_command_list +#define GL_NV_command_list 1 +#define GL_TERMINATE_SEQUENCE_COMMAND_NV 0x0000 +#define GL_NOP_COMMAND_NV 0x0001 +#define GL_DRAW_ELEMENTS_COMMAND_NV 0x0002 +#define GL_DRAW_ARRAYS_COMMAND_NV 0x0003 +#define GL_DRAW_ELEMENTS_STRIP_COMMAND_NV 0x0004 +#define GL_DRAW_ARRAYS_STRIP_COMMAND_NV 0x0005 +#define GL_DRAW_ELEMENTS_INSTANCED_COMMAND_NV 0x0006 +#define GL_DRAW_ARRAYS_INSTANCED_COMMAND_NV 0x0007 +#define GL_ELEMENT_ADDRESS_COMMAND_NV 0x0008 +#define GL_ATTRIBUTE_ADDRESS_COMMAND_NV 0x0009 +#define GL_UNIFORM_ADDRESS_COMMAND_NV 0x000A +#define GL_BLEND_COLOR_COMMAND_NV 0x000B +#define GL_STENCIL_REF_COMMAND_NV 0x000C +#define GL_LINE_WIDTH_COMMAND_NV 0x000D +#define GL_POLYGON_OFFSET_COMMAND_NV 0x000E +#define GL_ALPHA_REF_COMMAND_NV 0x000F +#define GL_VIEWPORT_COMMAND_NV 0x0010 +#define GL_SCISSOR_COMMAND_NV 0x0011 +#define GL_FRONT_FACE_COMMAND_NV 0x0012 +typedef void (APIENTRYP PFNGLCREATESTATESNVPROC) (GLsizei n, GLuint *states); +typedef void (APIENTRYP PFNGLDELETESTATESNVPROC) (GLsizei n, const GLuint *states); +typedef GLboolean (APIENTRYP PFNGLISSTATENVPROC) (GLuint state); +typedef void (APIENTRYP PFNGLSTATECAPTURENVPROC) (GLuint state, GLenum mode); +typedef GLuint (APIENTRYP PFNGLGETCOMMANDHEADERNVPROC) (GLenum tokenID, GLuint size); +typedef GLushort (APIENTRYP PFNGLGETSTAGEINDEXNVPROC) (GLenum shadertype); +typedef void (APIENTRYP PFNGLDRAWCOMMANDSNVPROC) (GLenum primitiveMode, GLuint buffer, const GLintptr *indirects, const GLsizei *sizes, GLuint count); +typedef void (APIENTRYP PFNGLDRAWCOMMANDSADDRESSNVPROC) (GLenum primitiveMode, const GLuint64 *indirects, const GLsizei *sizes, GLuint count); +typedef void (APIENTRYP PFNGLDRAWCOMMANDSSTATESNVPROC) (GLuint buffer, const GLintptr *indirects, const GLsizei *sizes, const GLuint *states, const GLuint *fbos, GLuint count); +typedef void (APIENTRYP PFNGLDRAWCOMMANDSSTATESADDRESSNVPROC) (const GLuint64 *indirects, const GLsizei *sizes, const GLuint *states, const GLuint *fbos, GLuint count); +typedef void (APIENTRYP PFNGLCREATECOMMANDLISTSNVPROC) (GLsizei n, GLuint *lists); +typedef void (APIENTRYP PFNGLDELETECOMMANDLISTSNVPROC) (GLsizei n, const GLuint *lists); +typedef GLboolean (APIENTRYP PFNGLISCOMMANDLISTNVPROC) (GLuint list); +typedef void (APIENTRYP PFNGLLISTDRAWCOMMANDSSTATESCLIENTNVPROC) (GLuint list, GLuint segment, const void **indirects, const GLsizei *sizes, const GLuint *states, const GLuint *fbos, GLuint count); +typedef void (APIENTRYP PFNGLCOMMANDLISTSEGMENTSNVPROC) (GLuint list, GLuint segments); +typedef void (APIENTRYP PFNGLCOMPILECOMMANDLISTNVPROC) (GLuint list); +typedef void (APIENTRYP PFNGLCALLCOMMANDLISTNVPROC) (GLuint list); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCreateStatesNV (GLsizei n, GLuint *states); +GLAPI void APIENTRY glDeleteStatesNV (GLsizei n, const GLuint *states); +GLAPI GLboolean APIENTRY glIsStateNV (GLuint state); +GLAPI void APIENTRY glStateCaptureNV (GLuint state, GLenum mode); +GLAPI GLuint APIENTRY glGetCommandHeaderNV (GLenum tokenID, GLuint size); +GLAPI GLushort APIENTRY glGetStageIndexNV (GLenum shadertype); +GLAPI void APIENTRY glDrawCommandsNV (GLenum primitiveMode, GLuint buffer, const GLintptr *indirects, const GLsizei *sizes, GLuint count); +GLAPI void APIENTRY glDrawCommandsAddressNV (GLenum primitiveMode, const GLuint64 *indirects, const GLsizei *sizes, GLuint count); +GLAPI void APIENTRY glDrawCommandsStatesNV (GLuint buffer, const GLintptr *indirects, const GLsizei *sizes, const GLuint *states, const GLuint *fbos, GLuint count); +GLAPI void APIENTRY glDrawCommandsStatesAddressNV (const GLuint64 *indirects, const GLsizei *sizes, const GLuint *states, const GLuint *fbos, GLuint count); +GLAPI void APIENTRY glCreateCommandListsNV (GLsizei n, GLuint *lists); +GLAPI void APIENTRY glDeleteCommandListsNV (GLsizei n, const GLuint *lists); +GLAPI GLboolean APIENTRY glIsCommandListNV (GLuint list); +GLAPI void APIENTRY glListDrawCommandsStatesClientNV (GLuint list, GLuint segment, const void **indirects, const GLsizei *sizes, const GLuint *states, const GLuint *fbos, GLuint count); +GLAPI void APIENTRY glCommandListSegmentsNV (GLuint list, GLuint segments); +GLAPI void APIENTRY glCompileCommandListNV (GLuint list); +GLAPI void APIENTRY glCallCommandListNV (GLuint list); +#endif +#endif /* GL_NV_command_list */ + +#ifndef GL_NV_compute_program5 +#define GL_NV_compute_program5 1 +#define GL_COMPUTE_PROGRAM_NV 0x90FB +#define GL_COMPUTE_PROGRAM_PARAMETER_BUFFER_NV 0x90FC +#endif /* GL_NV_compute_program5 */ + +#ifndef GL_NV_compute_shader_derivatives +#define GL_NV_compute_shader_derivatives 1 +#endif /* GL_NV_compute_shader_derivatives */ + +#ifndef GL_NV_conditional_render +#define GL_NV_conditional_render 1 +#define GL_QUERY_WAIT_NV 0x8E13 +#define GL_QUERY_NO_WAIT_NV 0x8E14 +#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16 +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginConditionalRenderNV (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRenderNV (void); +#endif +#endif /* GL_NV_conditional_render */ + +#ifndef GL_NV_conservative_raster +#define GL_NV_conservative_raster 1 +#define GL_CONSERVATIVE_RASTERIZATION_NV 0x9346 +#define GL_SUBPIXEL_PRECISION_BIAS_X_BITS_NV 0x9347 +#define GL_SUBPIXEL_PRECISION_BIAS_Y_BITS_NV 0x9348 +#define GL_MAX_SUBPIXEL_PRECISION_BIAS_BITS_NV 0x9349 +typedef void (APIENTRYP PFNGLSUBPIXELPRECISIONBIASNVPROC) (GLuint xbits, GLuint ybits); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSubpixelPrecisionBiasNV (GLuint xbits, GLuint ybits); +#endif +#endif /* GL_NV_conservative_raster */ + +#ifndef GL_NV_conservative_raster_dilate +#define GL_NV_conservative_raster_dilate 1 +#define GL_CONSERVATIVE_RASTER_DILATE_NV 0x9379 +#define GL_CONSERVATIVE_RASTER_DILATE_RANGE_NV 0x937A +#define GL_CONSERVATIVE_RASTER_DILATE_GRANULARITY_NV 0x937B +typedef void (APIENTRYP PFNGLCONSERVATIVERASTERPARAMETERFNVPROC) (GLenum pname, GLfloat value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConservativeRasterParameterfNV (GLenum pname, GLfloat value); +#endif +#endif /* GL_NV_conservative_raster_dilate */ + +#ifndef GL_NV_conservative_raster_pre_snap +#define GL_NV_conservative_raster_pre_snap 1 +#define GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_NV 0x9550 +#endif /* GL_NV_conservative_raster_pre_snap */ + +#ifndef GL_NV_conservative_raster_pre_snap_triangles +#define GL_NV_conservative_raster_pre_snap_triangles 1 +#define GL_CONSERVATIVE_RASTER_MODE_NV 0x954D +#define GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV 0x954E +#define GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV 0x954F +typedef void (APIENTRYP PFNGLCONSERVATIVERASTERPARAMETERINVPROC) (GLenum pname, GLint param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConservativeRasterParameteriNV (GLenum pname, GLint param); +#endif +#endif /* GL_NV_conservative_raster_pre_snap_triangles */ + +#ifndef GL_NV_conservative_raster_underestimation +#define GL_NV_conservative_raster_underestimation 1 +#endif /* GL_NV_conservative_raster_underestimation */ + +#ifndef GL_NV_copy_depth_to_color +#define GL_NV_copy_depth_to_color 1 +#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E +#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F +#endif /* GL_NV_copy_depth_to_color */ + +#ifndef GL_NV_copy_image +#define GL_NV_copy_image 1 +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATANVPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyImageSubDataNV (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif +#endif /* GL_NV_copy_image */ + +#ifndef GL_NV_deep_texture3D +#define GL_NV_deep_texture3D 1 +#define GL_MAX_DEEP_3D_TEXTURE_WIDTH_HEIGHT_NV 0x90D0 +#define GL_MAX_DEEP_3D_TEXTURE_DEPTH_NV 0x90D1 +#endif /* GL_NV_deep_texture3D */ + +#ifndef GL_NV_depth_buffer_float +#define GL_NV_depth_buffer_float 1 +#define GL_DEPTH_COMPONENT32F_NV 0x8DAB +#define GL_DEPTH32F_STENCIL8_NV 0x8DAC +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD +#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF +typedef void (APIENTRYP PFNGLDEPTHRANGEDNVPROC) (GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLCLEARDEPTHDNVPROC) (GLdouble depth); +typedef void (APIENTRYP PFNGLDEPTHBOUNDSDNVPROC) (GLdouble zmin, GLdouble zmax); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthRangedNV (GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glClearDepthdNV (GLdouble depth); +GLAPI void APIENTRY glDepthBoundsdNV (GLdouble zmin, GLdouble zmax); +#endif +#endif /* GL_NV_depth_buffer_float */ + +#ifndef GL_NV_depth_clamp +#define GL_NV_depth_clamp 1 +#define GL_DEPTH_CLAMP_NV 0x864F +#endif /* GL_NV_depth_clamp */ + +#ifndef GL_NV_draw_texture +#define GL_NV_draw_texture 1 +typedef void (APIENTRYP PFNGLDRAWTEXTURENVPROC) (GLuint texture, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawTextureNV (GLuint texture, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1); +#endif +#endif /* GL_NV_draw_texture */ + +#ifndef GL_NV_draw_vulkan_image +#define GL_NV_draw_vulkan_image 1 +typedef void (APIENTRY *GLVULKANPROCNV)(void); +typedef void (APIENTRYP PFNGLDRAWVKIMAGENVPROC) (GLuint64 vkImage, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1); +typedef GLVULKANPROCNV (APIENTRYP PFNGLGETVKPROCADDRNVPROC) (const GLchar *name); +typedef void (APIENTRYP PFNGLWAITVKSEMAPHORENVPROC) (GLuint64 vkSemaphore); +typedef void (APIENTRYP PFNGLSIGNALVKSEMAPHORENVPROC) (GLuint64 vkSemaphore); +typedef void (APIENTRYP PFNGLSIGNALVKFENCENVPROC) (GLuint64 vkFence); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawVkImageNV (GLuint64 vkImage, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1); +GLAPI GLVULKANPROCNV APIENTRY glGetVkProcAddrNV (const GLchar *name); +GLAPI void APIENTRY glWaitVkSemaphoreNV (GLuint64 vkSemaphore); +GLAPI void APIENTRY glSignalVkSemaphoreNV (GLuint64 vkSemaphore); +GLAPI void APIENTRY glSignalVkFenceNV (GLuint64 vkFence); +#endif +#endif /* GL_NV_draw_vulkan_image */ + +#ifndef GL_NV_evaluators +#define GL_NV_evaluators 1 +#define GL_EVAL_2D_NV 0x86C0 +#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1 +#define GL_MAP_TESSELLATION_NV 0x86C2 +#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3 +#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4 +#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5 +#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6 +#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7 +#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8 +#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9 +#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA +#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB +#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC +#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD +#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE +#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF +#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0 +#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1 +#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2 +#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3 +#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4 +#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5 +#define GL_MAX_MAP_TESSELLATION_NV 0x86D6 +#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7 +typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const void *points); +typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, void *points); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const void *points); +GLAPI void APIENTRY glMapParameterivNV (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMapParameterfvNV (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, void *points); +GLAPI void APIENTRY glGetMapParameterivNV (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMapParameterfvNV (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum target, GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glEvalMapsNV (GLenum target, GLenum mode); +#endif +#endif /* GL_NV_evaluators */ + +#ifndef GL_NV_explicit_multisample +#define GL_NV_explicit_multisample 1 +#define GL_SAMPLE_POSITION_NV 0x8E50 +#define GL_SAMPLE_MASK_NV 0x8E51 +#define GL_SAMPLE_MASK_VALUE_NV 0x8E52 +#define GL_TEXTURE_BINDING_RENDERBUFFER_NV 0x8E53 +#define GL_TEXTURE_RENDERBUFFER_DATA_STORE_BINDING_NV 0x8E54 +#define GL_TEXTURE_RENDERBUFFER_NV 0x8E55 +#define GL_SAMPLER_RENDERBUFFER_NV 0x8E56 +#define GL_INT_SAMPLER_RENDERBUFFER_NV 0x8E57 +#define GL_UNSIGNED_INT_SAMPLER_RENDERBUFFER_NV 0x8E58 +#define GL_MAX_SAMPLE_MASK_WORDS_NV 0x8E59 +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVNVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKINDEXEDNVPROC) (GLuint index, GLbitfield mask); +typedef void (APIENTRYP PFNGLTEXRENDERBUFFERNVPROC) (GLenum target, GLuint renderbuffer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetMultisamplefvNV (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaskIndexedNV (GLuint index, GLbitfield mask); +GLAPI void APIENTRY glTexRenderbufferNV (GLenum target, GLuint renderbuffer); +#endif +#endif /* GL_NV_explicit_multisample */ + +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences); +GLAPI void APIENTRY glGenFencesNV (GLsizei n, GLuint *fences); +GLAPI GLboolean APIENTRY glIsFenceNV (GLuint fence); +GLAPI GLboolean APIENTRY glTestFenceNV (GLuint fence); +GLAPI void APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params); +GLAPI void APIENTRY glFinishFenceNV (GLuint fence); +GLAPI void APIENTRY glSetFenceNV (GLuint fence, GLenum condition); +#endif +#endif /* GL_NV_fence */ + +#ifndef GL_NV_fill_rectangle +#define GL_NV_fill_rectangle 1 +#define GL_FILL_RECTANGLE_NV 0x933C +#endif /* GL_NV_fill_rectangle */ + +#ifndef GL_NV_float_buffer +#define GL_NV_float_buffer 1 +#define GL_FLOAT_R_NV 0x8880 +#define GL_FLOAT_RG_NV 0x8881 +#define GL_FLOAT_RGB_NV 0x8882 +#define GL_FLOAT_RGBA_NV 0x8883 +#define GL_FLOAT_R16_NV 0x8884 +#define GL_FLOAT_R32_NV 0x8885 +#define GL_FLOAT_RG16_NV 0x8886 +#define GL_FLOAT_RG32_NV 0x8887 +#define GL_FLOAT_RGB16_NV 0x8888 +#define GL_FLOAT_RGB32_NV 0x8889 +#define GL_FLOAT_RGBA16_NV 0x888A +#define GL_FLOAT_RGBA32_NV 0x888B +#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C +#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D +#define GL_FLOAT_RGBA_MODE_NV 0x888E +#endif /* GL_NV_float_buffer */ + +#ifndef GL_NV_fog_distance +#define GL_NV_fog_distance 1 +#define GL_FOG_DISTANCE_MODE_NV 0x855A +#define GL_EYE_RADIAL_NV 0x855B +#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C +#endif /* GL_NV_fog_distance */ + +#ifndef GL_NV_fragment_coverage_to_color +#define GL_NV_fragment_coverage_to_color 1 +#define GL_FRAGMENT_COVERAGE_TO_COLOR_NV 0x92DD +#define GL_FRAGMENT_COVERAGE_COLOR_NV 0x92DE +typedef void (APIENTRYP PFNGLFRAGMENTCOVERAGECOLORNVPROC) (GLuint color); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFragmentCoverageColorNV (GLuint color); +#endif +#endif /* GL_NV_fragment_coverage_to_color */ + +#ifndef GL_NV_fragment_program +#define GL_NV_fragment_program 1 +#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 +#define GL_FRAGMENT_PROGRAM_NV 0x8870 +#define GL_MAX_TEXTURE_COORDS_NV 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 +#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 +#define GL_PROGRAM_ERROR_STRING_NV 0x8874 +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif +#endif /* GL_NV_fragment_program */ + +#ifndef GL_NV_fragment_program2 +#define GL_NV_fragment_program2 1 +#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4 +#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5 +#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6 +#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7 +#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8 +#endif /* GL_NV_fragment_program2 */ + +#ifndef GL_NV_fragment_program4 +#define GL_NV_fragment_program4 1 +#endif /* GL_NV_fragment_program4 */ + +#ifndef GL_NV_fragment_program_option +#define GL_NV_fragment_program_option 1 +#endif /* GL_NV_fragment_program_option */ + +#ifndef GL_NV_fragment_shader_barycentric +#define GL_NV_fragment_shader_barycentric 1 +#endif /* GL_NV_fragment_shader_barycentric */ + +#ifndef GL_NV_fragment_shader_interlock +#define GL_NV_fragment_shader_interlock 1 +#endif /* GL_NV_fragment_shader_interlock */ + +#ifndef GL_NV_framebuffer_mixed_samples +#define GL_NV_framebuffer_mixed_samples 1 +#define GL_COVERAGE_MODULATION_TABLE_NV 0x9331 +#define GL_COLOR_SAMPLES_NV 0x8E20 +#define GL_DEPTH_SAMPLES_NV 0x932D +#define GL_STENCIL_SAMPLES_NV 0x932E +#define GL_MIXED_DEPTH_SAMPLES_SUPPORTED_NV 0x932F +#define GL_MIXED_STENCIL_SAMPLES_SUPPORTED_NV 0x9330 +#define GL_COVERAGE_MODULATION_NV 0x9332 +#define GL_COVERAGE_MODULATION_TABLE_SIZE_NV 0x9333 +typedef void (APIENTRYP PFNGLCOVERAGEMODULATIONTABLENVPROC) (GLsizei n, const GLfloat *v); +typedef void (APIENTRYP PFNGLGETCOVERAGEMODULATIONTABLENVPROC) (GLsizei bufSize, GLfloat *v); +typedef void (APIENTRYP PFNGLCOVERAGEMODULATIONNVPROC) (GLenum components); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCoverageModulationTableNV (GLsizei n, const GLfloat *v); +GLAPI void APIENTRY glGetCoverageModulationTableNV (GLsizei bufSize, GLfloat *v); +GLAPI void APIENTRY glCoverageModulationNV (GLenum components); +#endif +#endif /* GL_NV_framebuffer_mixed_samples */ + +#ifndef GL_NV_framebuffer_multisample_coverage +#define GL_NV_framebuffer_multisample_coverage 1 +#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB +#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10 +#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11 +#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12 +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +#endif +#endif /* GL_NV_framebuffer_multisample_coverage */ + +#ifndef GL_NV_geometry_program4 +#define GL_NV_geometry_program4 1 +#define GL_GEOMETRY_PROGRAM_NV 0x8C26 +#define GL_MAX_PROGRAM_OUTPUT_VERTICES_NV 0x8C27 +#define GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV 0x8C28 +typedef void (APIENTRYP PFNGLPROGRAMVERTEXLIMITNVPROC) (GLenum target, GLint limit); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramVertexLimitNV (GLenum target, GLint limit); +GLAPI void APIENTRY glFramebufferTextureEXT (GLenum target, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTextureFaceEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif +#endif /* GL_NV_geometry_program4 */ + +#ifndef GL_NV_geometry_shader4 +#define GL_NV_geometry_shader4 1 +#endif /* GL_NV_geometry_shader4 */ + +#ifndef GL_NV_geometry_shader_passthrough +#define GL_NV_geometry_shader_passthrough 1 +#endif /* GL_NV_geometry_shader_passthrough */ + +#ifndef GL_NV_gpu_multicast +#define GL_NV_gpu_multicast 1 +#define GL_PER_GPU_STORAGE_BIT_NV 0x0800 +#define GL_MULTICAST_GPUS_NV 0x92BA +#define GL_RENDER_GPU_MASK_NV 0x9558 +#define GL_PER_GPU_STORAGE_NV 0x9548 +#define GL_MULTICAST_PROGRAMMABLE_SAMPLE_LOCATION_NV 0x9549 +typedef void (APIENTRYP PFNGLRENDERGPUMASKNVPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLMULTICASTBUFFERSUBDATANVPROC) (GLbitfield gpuMask, GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +typedef void (APIENTRYP PFNGLMULTICASTCOPYBUFFERSUBDATANVPROC) (GLuint readGpu, GLbitfield writeGpuMask, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLMULTICASTCOPYIMAGESUBDATANVPROC) (GLuint srcGpu, GLbitfield dstGpuMask, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +typedef void (APIENTRYP PFNGLMULTICASTBLITFRAMEBUFFERNVPROC) (GLuint srcGpu, GLuint dstGpu, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLMULTICASTFRAMEBUFFERSAMPLELOCATIONSFVNVPROC) (GLuint gpu, GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTICASTBARRIERNVPROC) (void); +typedef void (APIENTRYP PFNGLMULTICASTWAITSYNCNVPROC) (GLuint signalGpu, GLbitfield waitGpuMask); +typedef void (APIENTRYP PFNGLMULTICASTGETQUERYOBJECTIVNVPROC) (GLuint gpu, GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLMULTICASTGETQUERYOBJECTUIVNVPROC) (GLuint gpu, GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLMULTICASTGETQUERYOBJECTI64VNVPROC) (GLuint gpu, GLuint id, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLMULTICASTGETQUERYOBJECTUI64VNVPROC) (GLuint gpu, GLuint id, GLenum pname, GLuint64 *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderGpuMaskNV (GLbitfield mask); +GLAPI void APIENTRY glMulticastBufferSubDataNV (GLbitfield gpuMask, GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); +GLAPI void APIENTRY glMulticastCopyBufferSubDataNV (GLuint readGpu, GLbitfield writeGpuMask, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GLAPI void APIENTRY glMulticastCopyImageSubDataNV (GLuint srcGpu, GLbitfield dstGpuMask, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +GLAPI void APIENTRY glMulticastBlitFramebufferNV (GLuint srcGpu, GLuint dstGpu, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI void APIENTRY glMulticastFramebufferSampleLocationsfvNV (GLuint gpu, GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glMulticastBarrierNV (void); +GLAPI void APIENTRY glMulticastWaitSyncNV (GLuint signalGpu, GLbitfield waitGpuMask); +GLAPI void APIENTRY glMulticastGetQueryObjectivNV (GLuint gpu, GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glMulticastGetQueryObjectuivNV (GLuint gpu, GLuint id, GLenum pname, GLuint *params); +GLAPI void APIENTRY glMulticastGetQueryObjecti64vNV (GLuint gpu, GLuint id, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glMulticastGetQueryObjectui64vNV (GLuint gpu, GLuint id, GLenum pname, GLuint64 *params); +#endif +#endif /* GL_NV_gpu_multicast */ + +#ifndef GL_NV_gpu_program4 +#define GL_NV_gpu_program4 1 +#define GL_MIN_PROGRAM_TEXEL_OFFSET_NV 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET_NV 0x8905 +#define GL_PROGRAM_ATTRIB_COMPONENTS_NV 0x8906 +#define GL_PROGRAM_RESULT_COMPONENTS_NV 0x8907 +#define GL_MAX_PROGRAM_ATTRIB_COMPONENTS_NV 0x8908 +#define GL_MAX_PROGRAM_RESULT_COMPONENTS_NV 0x8909 +#define GL_MAX_PROGRAM_GENERIC_ATTRIBS_NV 0x8DA5 +#define GL_MAX_PROGRAM_GENERIC_RESULTS_NV 0x8DA6 +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramLocalParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glProgramLocalParameterI4ivNV (GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glProgramLocalParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramLocalParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glProgramLocalParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glProgramLocalParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glProgramEnvParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glProgramEnvParameterI4ivNV (GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glProgramEnvParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramEnvParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glProgramEnvParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glProgramEnvParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetProgramLocalParameterIivNV (GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetProgramLocalParameterIuivNV (GLenum target, GLuint index, GLuint *params); +GLAPI void APIENTRY glGetProgramEnvParameterIivNV (GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetProgramEnvParameterIuivNV (GLenum target, GLuint index, GLuint *params); +#endif +#endif /* GL_NV_gpu_program4 */ + +#ifndef GL_NV_gpu_program5 +#define GL_NV_gpu_program5 1 +#define GL_MAX_GEOMETRY_PROGRAM_INVOCATIONS_NV 0x8E5A +#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5B +#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5C +#define GL_FRAGMENT_PROGRAM_INTERPOLATION_OFFSET_BITS_NV 0x8E5D +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5F +#define GL_MAX_PROGRAM_SUBROUTINE_PARAMETERS_NV 0x8F44 +#define GL_MAX_PROGRAM_SUBROUTINE_NUM_NV 0x8F45 +typedef void (APIENTRYP PFNGLPROGRAMSUBROUTINEPARAMETERSUIVNVPROC) (GLenum target, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSUBROUTINEPARAMETERUIVNVPROC) (GLenum target, GLuint index, GLuint *param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramSubroutineParametersuivNV (GLenum target, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetProgramSubroutineParameteruivNV (GLenum target, GLuint index, GLuint *param); +#endif +#endif /* GL_NV_gpu_program5 */ + +#ifndef GL_NV_gpu_program5_mem_extended +#define GL_NV_gpu_program5_mem_extended 1 +#endif /* GL_NV_gpu_program5_mem_extended */ + +#ifndef GL_NV_gpu_shader5 +#define GL_NV_gpu_shader5 1 +#endif /* GL_NV_gpu_shader5 */ + +#ifndef GL_NV_half_float +#define GL_NV_half_float 1 +typedef unsigned short GLhalfNV; +#define GL_HALF_FLOAT_NV 0x140B +typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); +typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); +typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertex2hNV (GLhalfNV x, GLhalfNV y); +GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertex3hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z); +GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertex4hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glNormal3hNV (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glColor4hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV s); +GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV s, GLhalfNV t); +GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r); +GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum target, GLhalfNV s); +GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum target, GLhalfNV s, GLhalfNV t); +GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib1hNV (GLuint index, GLhalfNV x); +GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib2hNV (GLuint index, GLhalfNV x, GLhalfNV y); +GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib3hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib4hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glFogCoordhNV (GLhalfNV fog); +GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *fog); +GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV weight); +GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *weight); +#endif +#endif /* GL_NV_half_float */ + +#ifndef GL_NV_internalformat_sample_query +#define GL_NV_internalformat_sample_query 1 +#define GL_MULTISAMPLES_NV 0x9371 +#define GL_SUPERSAMPLE_SCALE_X_NV 0x9372 +#define GL_SUPERSAMPLE_SCALE_Y_NV 0x9373 +#define GL_CONFORMANT_NV 0x9374 +typedef void (APIENTRYP PFNGLGETINTERNALFORMATSAMPLEIVNVPROC) (GLenum target, GLenum internalformat, GLsizei samples, GLenum pname, GLsizei count, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetInternalformatSampleivNV (GLenum target, GLenum internalformat, GLsizei samples, GLenum pname, GLsizei count, GLint *params); +#endif +#endif /* GL_NV_internalformat_sample_query */ + +#ifndef GL_NV_light_max_exponent +#define GL_NV_light_max_exponent 1 +#define GL_MAX_SHININESS_NV 0x8504 +#define GL_MAX_SPOT_EXPONENT_NV 0x8505 +#endif /* GL_NV_light_max_exponent */ + +#ifndef GL_NV_memory_attachment +#define GL_NV_memory_attachment 1 +#define GL_ATTACHED_MEMORY_OBJECT_NV 0x95A4 +#define GL_ATTACHED_MEMORY_OFFSET_NV 0x95A5 +#define GL_MEMORY_ATTACHABLE_ALIGNMENT_NV 0x95A6 +#define GL_MEMORY_ATTACHABLE_SIZE_NV 0x95A7 +#define GL_MEMORY_ATTACHABLE_NV 0x95A8 +#define GL_DETACHED_MEMORY_INCARNATION_NV 0x95A9 +#define GL_DETACHED_TEXTURES_NV 0x95AA +#define GL_DETACHED_BUFFERS_NV 0x95AB +#define GL_MAX_DETACHED_TEXTURES_NV 0x95AC +#define GL_MAX_DETACHED_BUFFERS_NV 0x95AD +typedef void (APIENTRYP PFNGLGETMEMORYOBJECTDETACHEDRESOURCESUIVNVPROC) (GLuint memory, GLenum pname, GLint first, GLsizei count, GLuint *params); +typedef void (APIENTRYP PFNGLRESETMEMORYOBJECTPARAMETERNVPROC) (GLuint memory, GLenum pname); +typedef void (APIENTRYP PFNGLTEXATTACHMEMORYNVPROC) (GLenum target, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLBUFFERATTACHMEMORYNVPROC) (GLenum target, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLTEXTUREATTACHMEMORYNVPROC) (GLuint texture, GLuint memory, GLuint64 offset); +typedef void (APIENTRYP PFNGLNAMEDBUFFERATTACHMEMORYNVPROC) (GLuint buffer, GLuint memory, GLuint64 offset); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetMemoryObjectDetachedResourcesuivNV (GLuint memory, GLenum pname, GLint first, GLsizei count, GLuint *params); +GLAPI void APIENTRY glResetMemoryObjectParameterNV (GLuint memory, GLenum pname); +GLAPI void APIENTRY glTexAttachMemoryNV (GLenum target, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glBufferAttachMemoryNV (GLenum target, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glTextureAttachMemoryNV (GLuint texture, GLuint memory, GLuint64 offset); +GLAPI void APIENTRY glNamedBufferAttachMemoryNV (GLuint buffer, GLuint memory, GLuint64 offset); +#endif +#endif /* GL_NV_memory_attachment */ + +#ifndef GL_NV_memory_object_sparse +#define GL_NV_memory_object_sparse 1 +typedef void (APIENTRYP PFNGLBUFFERPAGECOMMITMENTMEMNVPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLuint memory, GLuint64 memOffset, GLboolean commit); +typedef void (APIENTRYP PFNGLTEXPAGECOMMITMENTMEMNVPROC) (GLenum target, GLint layer, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset, GLboolean commit); +typedef void (APIENTRYP PFNGLNAMEDBUFFERPAGECOMMITMENTMEMNVPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLuint memory, GLuint64 memOffset, GLboolean commit); +typedef void (APIENTRYP PFNGLTEXTUREPAGECOMMITMENTMEMNVPROC) (GLuint texture, GLint layer, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset, GLboolean commit); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferPageCommitmentMemNV (GLenum target, GLintptr offset, GLsizeiptr size, GLuint memory, GLuint64 memOffset, GLboolean commit); +GLAPI void APIENTRY glTexPageCommitmentMemNV (GLenum target, GLint layer, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset, GLboolean commit); +GLAPI void APIENTRY glNamedBufferPageCommitmentMemNV (GLuint buffer, GLintptr offset, GLsizeiptr size, GLuint memory, GLuint64 memOffset, GLboolean commit); +GLAPI void APIENTRY glTexturePageCommitmentMemNV (GLuint texture, GLint layer, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset, GLboolean commit); +#endif +#endif /* GL_NV_memory_object_sparse */ + +#ifndef GL_NV_mesh_shader +#define GL_NV_mesh_shader 1 +#define GL_MESH_SHADER_NV 0x9559 +#define GL_TASK_SHADER_NV 0x955A +#define GL_MAX_MESH_UNIFORM_BLOCKS_NV 0x8E60 +#define GL_MAX_MESH_TEXTURE_IMAGE_UNITS_NV 0x8E61 +#define GL_MAX_MESH_IMAGE_UNIFORMS_NV 0x8E62 +#define GL_MAX_MESH_UNIFORM_COMPONENTS_NV 0x8E63 +#define GL_MAX_MESH_ATOMIC_COUNTER_BUFFERS_NV 0x8E64 +#define GL_MAX_MESH_ATOMIC_COUNTERS_NV 0x8E65 +#define GL_MAX_MESH_SHADER_STORAGE_BLOCKS_NV 0x8E66 +#define GL_MAX_COMBINED_MESH_UNIFORM_COMPONENTS_NV 0x8E67 +#define GL_MAX_TASK_UNIFORM_BLOCKS_NV 0x8E68 +#define GL_MAX_TASK_TEXTURE_IMAGE_UNITS_NV 0x8E69 +#define GL_MAX_TASK_IMAGE_UNIFORMS_NV 0x8E6A +#define GL_MAX_TASK_UNIFORM_COMPONENTS_NV 0x8E6B +#define GL_MAX_TASK_ATOMIC_COUNTER_BUFFERS_NV 0x8E6C +#define GL_MAX_TASK_ATOMIC_COUNTERS_NV 0x8E6D +#define GL_MAX_TASK_SHADER_STORAGE_BLOCKS_NV 0x8E6E +#define GL_MAX_COMBINED_TASK_UNIFORM_COMPONENTS_NV 0x8E6F +#define GL_MAX_MESH_WORK_GROUP_INVOCATIONS_NV 0x95A2 +#define GL_MAX_TASK_WORK_GROUP_INVOCATIONS_NV 0x95A3 +#define GL_MAX_MESH_TOTAL_MEMORY_SIZE_NV 0x9536 +#define GL_MAX_TASK_TOTAL_MEMORY_SIZE_NV 0x9537 +#define GL_MAX_MESH_OUTPUT_VERTICES_NV 0x9538 +#define GL_MAX_MESH_OUTPUT_PRIMITIVES_NV 0x9539 +#define GL_MAX_TASK_OUTPUT_COUNT_NV 0x953A +#define GL_MAX_DRAW_MESH_TASKS_COUNT_NV 0x953D +#define GL_MAX_MESH_VIEWS_NV 0x9557 +#define GL_MESH_OUTPUT_PER_VERTEX_GRANULARITY_NV 0x92DF +#define GL_MESH_OUTPUT_PER_PRIMITIVE_GRANULARITY_NV 0x9543 +#define GL_MAX_MESH_WORK_GROUP_SIZE_NV 0x953B +#define GL_MAX_TASK_WORK_GROUP_SIZE_NV 0x953C +#define GL_MESH_WORK_GROUP_SIZE_NV 0x953E +#define GL_TASK_WORK_GROUP_SIZE_NV 0x953F +#define GL_MESH_VERTICES_OUT_NV 0x9579 +#define GL_MESH_PRIMITIVES_OUT_NV 0x957A +#define GL_MESH_OUTPUT_TYPE_NV 0x957B +#define GL_UNIFORM_BLOCK_REFERENCED_BY_MESH_SHADER_NV 0x959C +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TASK_SHADER_NV 0x959D +#define GL_REFERENCED_BY_MESH_SHADER_NV 0x95A0 +#define GL_REFERENCED_BY_TASK_SHADER_NV 0x95A1 +#define GL_MESH_SHADER_BIT_NV 0x00000040 +#define GL_TASK_SHADER_BIT_NV 0x00000080 +#define GL_MESH_SUBROUTINE_NV 0x957C +#define GL_TASK_SUBROUTINE_NV 0x957D +#define GL_MESH_SUBROUTINE_UNIFORM_NV 0x957E +#define GL_TASK_SUBROUTINE_UNIFORM_NV 0x957F +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_MESH_SHADER_NV 0x959E +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TASK_SHADER_NV 0x959F +typedef void (APIENTRYP PFNGLDRAWMESHTASKSNVPROC) (GLuint first, GLuint count); +typedef void (APIENTRYP PFNGLDRAWMESHTASKSINDIRECTNVPROC) (GLintptr indirect); +typedef void (APIENTRYP PFNGLMULTIDRAWMESHTASKSINDIRECTNVPROC) (GLintptr indirect, GLsizei drawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWMESHTASKSINDIRECTCOUNTNVPROC) (GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawMeshTasksNV (GLuint first, GLuint count); +GLAPI void APIENTRY glDrawMeshTasksIndirectNV (GLintptr indirect); +GLAPI void APIENTRY glMultiDrawMeshTasksIndirectNV (GLintptr indirect, GLsizei drawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawMeshTasksIndirectCountNV (GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +#endif +#endif /* GL_NV_mesh_shader */ + +#ifndef GL_NV_multisample_coverage +#define GL_NV_multisample_coverage 1 +#endif /* GL_NV_multisample_coverage */ + +#ifndef GL_NV_multisample_filter_hint +#define GL_NV_multisample_filter_hint 1 +#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 +#endif /* GL_NV_multisample_filter_hint */ + +#ifndef GL_NV_occlusion_query +#define GL_NV_occlusion_query 1 +#define GL_PIXEL_COUNTER_BITS_NV 0x8864 +#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865 +#define GL_PIXEL_COUNT_NV 0x8866 +#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867 +typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint id); +GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint id); +GLAPI void APIENTRY glEndOcclusionQueryNV (void); +GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint id, GLenum pname, GLuint *params); +#endif +#endif /* GL_NV_occlusion_query */ + +#ifndef GL_NV_packed_depth_stencil +#define GL_NV_packed_depth_stencil 1 +#define GL_DEPTH_STENCIL_NV 0x84F9 +#define GL_UNSIGNED_INT_24_8_NV 0x84FA +#endif /* GL_NV_packed_depth_stencil */ + +#ifndef GL_NV_parameter_buffer_object +#define GL_NV_parameter_buffer_object 1 +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_BINDINGS_NV 0x8DA0 +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_SIZE_NV 0x8DA1 +#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8DA2 +#define GL_GEOMETRY_PROGRAM_PARAMETER_BUFFER_NV 0x8DA3 +#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8DA4 +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSFVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIIVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIUIVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLuint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramBufferParametersfvNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glProgramBufferParametersIivNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramBufferParametersIuivNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLuint *params); +#endif +#endif /* GL_NV_parameter_buffer_object */ + +#ifndef GL_NV_parameter_buffer_object2 +#define GL_NV_parameter_buffer_object2 1 +#endif /* GL_NV_parameter_buffer_object2 */ + +#ifndef GL_NV_path_rendering +#define GL_NV_path_rendering 1 +#define GL_PATH_FORMAT_SVG_NV 0x9070 +#define GL_PATH_FORMAT_PS_NV 0x9071 +#define GL_STANDARD_FONT_NAME_NV 0x9072 +#define GL_SYSTEM_FONT_NAME_NV 0x9073 +#define GL_FILE_NAME_NV 0x9074 +#define GL_PATH_STROKE_WIDTH_NV 0x9075 +#define GL_PATH_END_CAPS_NV 0x9076 +#define GL_PATH_INITIAL_END_CAP_NV 0x9077 +#define GL_PATH_TERMINAL_END_CAP_NV 0x9078 +#define GL_PATH_JOIN_STYLE_NV 0x9079 +#define GL_PATH_MITER_LIMIT_NV 0x907A +#define GL_PATH_DASH_CAPS_NV 0x907B +#define GL_PATH_INITIAL_DASH_CAP_NV 0x907C +#define GL_PATH_TERMINAL_DASH_CAP_NV 0x907D +#define GL_PATH_DASH_OFFSET_NV 0x907E +#define GL_PATH_CLIENT_LENGTH_NV 0x907F +#define GL_PATH_FILL_MODE_NV 0x9080 +#define GL_PATH_FILL_MASK_NV 0x9081 +#define GL_PATH_FILL_COVER_MODE_NV 0x9082 +#define GL_PATH_STROKE_COVER_MODE_NV 0x9083 +#define GL_PATH_STROKE_MASK_NV 0x9084 +#define GL_COUNT_UP_NV 0x9088 +#define GL_COUNT_DOWN_NV 0x9089 +#define GL_PATH_OBJECT_BOUNDING_BOX_NV 0x908A +#define GL_CONVEX_HULL_NV 0x908B +#define GL_BOUNDING_BOX_NV 0x908D +#define GL_TRANSLATE_X_NV 0x908E +#define GL_TRANSLATE_Y_NV 0x908F +#define GL_TRANSLATE_2D_NV 0x9090 +#define GL_TRANSLATE_3D_NV 0x9091 +#define GL_AFFINE_2D_NV 0x9092 +#define GL_AFFINE_3D_NV 0x9094 +#define GL_TRANSPOSE_AFFINE_2D_NV 0x9096 +#define GL_TRANSPOSE_AFFINE_3D_NV 0x9098 +#define GL_UTF8_NV 0x909A +#define GL_UTF16_NV 0x909B +#define GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV 0x909C +#define GL_PATH_COMMAND_COUNT_NV 0x909D +#define GL_PATH_COORD_COUNT_NV 0x909E +#define GL_PATH_DASH_ARRAY_COUNT_NV 0x909F +#define GL_PATH_COMPUTED_LENGTH_NV 0x90A0 +#define GL_PATH_FILL_BOUNDING_BOX_NV 0x90A1 +#define GL_PATH_STROKE_BOUNDING_BOX_NV 0x90A2 +#define GL_SQUARE_NV 0x90A3 +#define GL_ROUND_NV 0x90A4 +#define GL_TRIANGULAR_NV 0x90A5 +#define GL_BEVEL_NV 0x90A6 +#define GL_MITER_REVERT_NV 0x90A7 +#define GL_MITER_TRUNCATE_NV 0x90A8 +#define GL_SKIP_MISSING_GLYPH_NV 0x90A9 +#define GL_USE_MISSING_GLYPH_NV 0x90AA +#define GL_PATH_ERROR_POSITION_NV 0x90AB +#define GL_ACCUM_ADJACENT_PAIRS_NV 0x90AD +#define GL_ADJACENT_PAIRS_NV 0x90AE +#define GL_FIRST_TO_REST_NV 0x90AF +#define GL_PATH_GEN_MODE_NV 0x90B0 +#define GL_PATH_GEN_COEFF_NV 0x90B1 +#define GL_PATH_GEN_COMPONENTS_NV 0x90B3 +#define GL_PATH_STENCIL_FUNC_NV 0x90B7 +#define GL_PATH_STENCIL_REF_NV 0x90B8 +#define GL_PATH_STENCIL_VALUE_MASK_NV 0x90B9 +#define GL_PATH_STENCIL_DEPTH_OFFSET_FACTOR_NV 0x90BD +#define GL_PATH_STENCIL_DEPTH_OFFSET_UNITS_NV 0x90BE +#define GL_PATH_COVER_DEPTH_FUNC_NV 0x90BF +#define GL_PATH_DASH_OFFSET_RESET_NV 0x90B4 +#define GL_MOVE_TO_RESETS_NV 0x90B5 +#define GL_MOVE_TO_CONTINUES_NV 0x90B6 +#define GL_CLOSE_PATH_NV 0x00 +#define GL_MOVE_TO_NV 0x02 +#define GL_RELATIVE_MOVE_TO_NV 0x03 +#define GL_LINE_TO_NV 0x04 +#define GL_RELATIVE_LINE_TO_NV 0x05 +#define GL_HORIZONTAL_LINE_TO_NV 0x06 +#define GL_RELATIVE_HORIZONTAL_LINE_TO_NV 0x07 +#define GL_VERTICAL_LINE_TO_NV 0x08 +#define GL_RELATIVE_VERTICAL_LINE_TO_NV 0x09 +#define GL_QUADRATIC_CURVE_TO_NV 0x0A +#define GL_RELATIVE_QUADRATIC_CURVE_TO_NV 0x0B +#define GL_CUBIC_CURVE_TO_NV 0x0C +#define GL_RELATIVE_CUBIC_CURVE_TO_NV 0x0D +#define GL_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0E +#define GL_RELATIVE_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0F +#define GL_SMOOTH_CUBIC_CURVE_TO_NV 0x10 +#define GL_RELATIVE_SMOOTH_CUBIC_CURVE_TO_NV 0x11 +#define GL_SMALL_CCW_ARC_TO_NV 0x12 +#define GL_RELATIVE_SMALL_CCW_ARC_TO_NV 0x13 +#define GL_SMALL_CW_ARC_TO_NV 0x14 +#define GL_RELATIVE_SMALL_CW_ARC_TO_NV 0x15 +#define GL_LARGE_CCW_ARC_TO_NV 0x16 +#define GL_RELATIVE_LARGE_CCW_ARC_TO_NV 0x17 +#define GL_LARGE_CW_ARC_TO_NV 0x18 +#define GL_RELATIVE_LARGE_CW_ARC_TO_NV 0x19 +#define GL_RESTART_PATH_NV 0xF0 +#define GL_DUP_FIRST_CUBIC_CURVE_TO_NV 0xF2 +#define GL_DUP_LAST_CUBIC_CURVE_TO_NV 0xF4 +#define GL_RECT_NV 0xF6 +#define GL_CIRCULAR_CCW_ARC_TO_NV 0xF8 +#define GL_CIRCULAR_CW_ARC_TO_NV 0xFA +#define GL_CIRCULAR_TANGENT_ARC_TO_NV 0xFC +#define GL_ARC_TO_NV 0xFE +#define GL_RELATIVE_ARC_TO_NV 0xFF +#define GL_BOLD_BIT_NV 0x01 +#define GL_ITALIC_BIT_NV 0x02 +#define GL_GLYPH_WIDTH_BIT_NV 0x01 +#define GL_GLYPH_HEIGHT_BIT_NV 0x02 +#define GL_GLYPH_HORIZONTAL_BEARING_X_BIT_NV 0x04 +#define GL_GLYPH_HORIZONTAL_BEARING_Y_BIT_NV 0x08 +#define GL_GLYPH_HORIZONTAL_BEARING_ADVANCE_BIT_NV 0x10 +#define GL_GLYPH_VERTICAL_BEARING_X_BIT_NV 0x20 +#define GL_GLYPH_VERTICAL_BEARING_Y_BIT_NV 0x40 +#define GL_GLYPH_VERTICAL_BEARING_ADVANCE_BIT_NV 0x80 +#define GL_GLYPH_HAS_KERNING_BIT_NV 0x100 +#define GL_FONT_X_MIN_BOUNDS_BIT_NV 0x00010000 +#define GL_FONT_Y_MIN_BOUNDS_BIT_NV 0x00020000 +#define GL_FONT_X_MAX_BOUNDS_BIT_NV 0x00040000 +#define GL_FONT_Y_MAX_BOUNDS_BIT_NV 0x00080000 +#define GL_FONT_UNITS_PER_EM_BIT_NV 0x00100000 +#define GL_FONT_ASCENDER_BIT_NV 0x00200000 +#define GL_FONT_DESCENDER_BIT_NV 0x00400000 +#define GL_FONT_HEIGHT_BIT_NV 0x00800000 +#define GL_FONT_MAX_ADVANCE_WIDTH_BIT_NV 0x01000000 +#define GL_FONT_MAX_ADVANCE_HEIGHT_BIT_NV 0x02000000 +#define GL_FONT_UNDERLINE_POSITION_BIT_NV 0x04000000 +#define GL_FONT_UNDERLINE_THICKNESS_BIT_NV 0x08000000 +#define GL_FONT_HAS_KERNING_BIT_NV 0x10000000 +#define GL_ROUNDED_RECT_NV 0xE8 +#define GL_RELATIVE_ROUNDED_RECT_NV 0xE9 +#define GL_ROUNDED_RECT2_NV 0xEA +#define GL_RELATIVE_ROUNDED_RECT2_NV 0xEB +#define GL_ROUNDED_RECT4_NV 0xEC +#define GL_RELATIVE_ROUNDED_RECT4_NV 0xED +#define GL_ROUNDED_RECT8_NV 0xEE +#define GL_RELATIVE_ROUNDED_RECT8_NV 0xEF +#define GL_RELATIVE_RECT_NV 0xF7 +#define GL_FONT_GLYPHS_AVAILABLE_NV 0x9368 +#define GL_FONT_TARGET_UNAVAILABLE_NV 0x9369 +#define GL_FONT_UNAVAILABLE_NV 0x936A +#define GL_FONT_UNINTELLIGIBLE_NV 0x936B +#define GL_CONIC_CURVE_TO_NV 0x1A +#define GL_RELATIVE_CONIC_CURVE_TO_NV 0x1B +#define GL_FONT_NUM_GLYPH_INDICES_BIT_NV 0x20000000 +#define GL_STANDARD_FONT_FORMAT_NV 0x936C +#define GL_2_BYTES_NV 0x1407 +#define GL_3_BYTES_NV 0x1408 +#define GL_4_BYTES_NV 0x1409 +#define GL_EYE_LINEAR_NV 0x2400 +#define GL_OBJECT_LINEAR_NV 0x2401 +#define GL_CONSTANT_NV 0x8576 +#define GL_PATH_FOG_GEN_MODE_NV 0x90AC +#define GL_PRIMARY_COLOR_NV 0x852C +#define GL_SECONDARY_COLOR_NV 0x852D +#define GL_PATH_GEN_COLOR_FORMAT_NV 0x90B2 +#define GL_PATH_PROJECTION_NV 0x1701 +#define GL_PATH_MODELVIEW_NV 0x1700 +#define GL_PATH_MODELVIEW_STACK_DEPTH_NV 0x0BA3 +#define GL_PATH_MODELVIEW_MATRIX_NV 0x0BA6 +#define GL_PATH_MAX_MODELVIEW_STACK_DEPTH_NV 0x0D36 +#define GL_PATH_TRANSPOSE_MODELVIEW_MATRIX_NV 0x84E3 +#define GL_PATH_PROJECTION_STACK_DEPTH_NV 0x0BA4 +#define GL_PATH_PROJECTION_MATRIX_NV 0x0BA7 +#define GL_PATH_MAX_PROJECTION_STACK_DEPTH_NV 0x0D38 +#define GL_PATH_TRANSPOSE_PROJECTION_MATRIX_NV 0x84E4 +#define GL_FRAGMENT_INPUT_NV 0x936D +typedef GLuint (APIENTRYP PFNGLGENPATHSNVPROC) (GLsizei range); +typedef void (APIENTRYP PFNGLDELETEPATHSNVPROC) (GLuint path, GLsizei range); +typedef GLboolean (APIENTRYP PFNGLISPATHNVPROC) (GLuint path); +typedef void (APIENTRYP PFNGLPATHCOMMANDSNVPROC) (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords); +typedef void (APIENTRYP PFNGLPATHCOORDSNVPROC) (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords); +typedef void (APIENTRYP PFNGLPATHSUBCOMMANDSNVPROC) (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords); +typedef void (APIENTRYP PFNGLPATHSUBCOORDSNVPROC) (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords); +typedef void (APIENTRYP PFNGLPATHSTRINGNVPROC) (GLuint path, GLenum format, GLsizei length, const void *pathString); +typedef void (APIENTRYP PFNGLPATHGLYPHSNVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +typedef void (APIENTRYP PFNGLPATHGLYPHRANGENVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +typedef void (APIENTRYP PFNGLWEIGHTPATHSNVPROC) (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights); +typedef void (APIENTRYP PFNGLCOPYPATHNVPROC) (GLuint resultPath, GLuint srcPath); +typedef void (APIENTRYP PFNGLINTERPOLATEPATHSNVPROC) (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight); +typedef void (APIENTRYP PFNGLTRANSFORMPATHNVPROC) (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues); +typedef void (APIENTRYP PFNGLPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, const GLint *value); +typedef void (APIENTRYP PFNGLPATHPARAMETERINVPROC) (GLuint path, GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, const GLfloat *value); +typedef void (APIENTRYP PFNGLPATHPARAMETERFNVPROC) (GLuint path, GLenum pname, GLfloat value); +typedef void (APIENTRYP PFNGLPATHDASHARRAYNVPROC) (GLuint path, GLsizei dashCount, const GLfloat *dashArray); +typedef void (APIENTRYP PFNGLPATHSTENCILFUNCNVPROC) (GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLPATHSTENCILDEPTHOFFSETNVPROC) (GLfloat factor, GLfloat units); +typedef void (APIENTRYP PFNGLSTENCILFILLPATHNVPROC) (GLuint path, GLenum fillMode, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHNVPROC) (GLuint path, GLint reference, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues); +typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues); +typedef void (APIENTRYP PFNGLPATHCOVERDEPTHFUNCNVPROC) (GLenum func); +typedef void (APIENTRYP PFNGLCOVERFILLPATHNVPROC) (GLuint path, GLenum coverMode); +typedef void (APIENTRYP PFNGLCOVERSTROKEPATHNVPROC) (GLuint path, GLenum coverMode); +typedef void (APIENTRYP PFNGLCOVERFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +typedef void (APIENTRYP PFNGLCOVERSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +typedef void (APIENTRYP PFNGLGETPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, GLint *value); +typedef void (APIENTRYP PFNGLGETPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, GLfloat *value); +typedef void (APIENTRYP PFNGLGETPATHCOMMANDSNVPROC) (GLuint path, GLubyte *commands); +typedef void (APIENTRYP PFNGLGETPATHCOORDSNVPROC) (GLuint path, GLfloat *coords); +typedef void (APIENTRYP PFNGLGETPATHDASHARRAYNVPROC) (GLuint path, GLfloat *dashArray); +typedef void (APIENTRYP PFNGLGETPATHMETRICSNVPROC) (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics); +typedef void (APIENTRYP PFNGLGETPATHMETRICRANGENVPROC) (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics); +typedef void (APIENTRYP PFNGLGETPATHSPACINGNVPROC) (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing); +typedef GLboolean (APIENTRYP PFNGLISPOINTINFILLPATHNVPROC) (GLuint path, GLuint mask, GLfloat x, GLfloat y); +typedef GLboolean (APIENTRYP PFNGLISPOINTINSTROKEPATHNVPROC) (GLuint path, GLfloat x, GLfloat y); +typedef GLfloat (APIENTRYP PFNGLGETPATHLENGTHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments); +typedef GLboolean (APIENTRYP PFNGLPOINTALONGPATHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY); +typedef void (APIENTRYP PFNGLMATRIXLOAD3X2FNVPROC) (GLenum matrixMode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOAD3X3FNVPROC) (GLenum matrixMode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSE3X3FNVPROC) (GLenum matrixMode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULT3X2FNVPROC) (GLenum matrixMode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULT3X3FNVPROC) (GLenum matrixMode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSE3X3FNVPROC) (GLenum matrixMode, const GLfloat *m); +typedef void (APIENTRYP PFNGLSTENCILTHENCOVERFILLPATHNVPROC) (GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode); +typedef void (APIENTRYP PFNGLSTENCILTHENCOVERSTROKEPATHNVPROC) (GLuint path, GLint reference, GLuint mask, GLenum coverMode); +typedef void (APIENTRYP PFNGLSTENCILTHENCOVERFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +typedef void (APIENTRYP PFNGLSTENCILTHENCOVERSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +typedef GLenum (APIENTRYP PFNGLPATHGLYPHINDEXRANGENVPROC) (GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint pathParameterTemplate, GLfloat emScale, GLuint *baseAndCount); +typedef GLenum (APIENTRYP PFNGLPATHGLYPHINDEXARRAYNVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +typedef GLenum (APIENTRYP PFNGLPATHMEMORYGLYPHINDEXARRAYNVPROC) (GLuint firstPathName, GLenum fontTarget, GLsizeiptr fontSize, const void *fontData, GLsizei faceIndex, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +typedef void (APIENTRYP PFNGLPROGRAMPATHFRAGMENTINPUTGENNVPROC) (GLuint program, GLint location, GLenum genMode, GLint components, const GLfloat *coeffs); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEFVNVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei count, GLsizei *length, GLfloat *params); +typedef void (APIENTRYP PFNGLPATHCOLORGENNVPROC) (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs); +typedef void (APIENTRYP PFNGLPATHTEXGENNVPROC) (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs); +typedef void (APIENTRYP PFNGLPATHFOGGENNVPROC) (GLenum genMode); +typedef void (APIENTRYP PFNGLGETPATHCOLORGENIVNVPROC) (GLenum color, GLenum pname, GLint *value); +typedef void (APIENTRYP PFNGLGETPATHCOLORGENFVNVPROC) (GLenum color, GLenum pname, GLfloat *value); +typedef void (APIENTRYP PFNGLGETPATHTEXGENIVNVPROC) (GLenum texCoordSet, GLenum pname, GLint *value); +typedef void (APIENTRYP PFNGLGETPATHTEXGENFVNVPROC) (GLenum texCoordSet, GLenum pname, GLfloat *value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glGenPathsNV (GLsizei range); +GLAPI void APIENTRY glDeletePathsNV (GLuint path, GLsizei range); +GLAPI GLboolean APIENTRY glIsPathNV (GLuint path); +GLAPI void APIENTRY glPathCommandsNV (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords); +GLAPI void APIENTRY glPathCoordsNV (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords); +GLAPI void APIENTRY glPathSubCommandsNV (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords); +GLAPI void APIENTRY glPathSubCoordsNV (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords); +GLAPI void APIENTRY glPathStringNV (GLuint path, GLenum format, GLsizei length, const void *pathString); +GLAPI void APIENTRY glPathGlyphsNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +GLAPI void APIENTRY glPathGlyphRangeNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +GLAPI void APIENTRY glWeightPathsNV (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights); +GLAPI void APIENTRY glCopyPathNV (GLuint resultPath, GLuint srcPath); +GLAPI void APIENTRY glInterpolatePathsNV (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight); +GLAPI void APIENTRY glTransformPathNV (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues); +GLAPI void APIENTRY glPathParameterivNV (GLuint path, GLenum pname, const GLint *value); +GLAPI void APIENTRY glPathParameteriNV (GLuint path, GLenum pname, GLint value); +GLAPI void APIENTRY glPathParameterfvNV (GLuint path, GLenum pname, const GLfloat *value); +GLAPI void APIENTRY glPathParameterfNV (GLuint path, GLenum pname, GLfloat value); +GLAPI void APIENTRY glPathDashArrayNV (GLuint path, GLsizei dashCount, const GLfloat *dashArray); +GLAPI void APIENTRY glPathStencilFuncNV (GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glPathStencilDepthOffsetNV (GLfloat factor, GLfloat units); +GLAPI void APIENTRY glStencilFillPathNV (GLuint path, GLenum fillMode, GLuint mask); +GLAPI void APIENTRY glStencilStrokePathNV (GLuint path, GLint reference, GLuint mask); +GLAPI void APIENTRY glStencilFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues); +GLAPI void APIENTRY glStencilStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues); +GLAPI void APIENTRY glPathCoverDepthFuncNV (GLenum func); +GLAPI void APIENTRY glCoverFillPathNV (GLuint path, GLenum coverMode); +GLAPI void APIENTRY glCoverStrokePathNV (GLuint path, GLenum coverMode); +GLAPI void APIENTRY glCoverFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +GLAPI void APIENTRY glCoverStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +GLAPI void APIENTRY glGetPathParameterivNV (GLuint path, GLenum pname, GLint *value); +GLAPI void APIENTRY glGetPathParameterfvNV (GLuint path, GLenum pname, GLfloat *value); +GLAPI void APIENTRY glGetPathCommandsNV (GLuint path, GLubyte *commands); +GLAPI void APIENTRY glGetPathCoordsNV (GLuint path, GLfloat *coords); +GLAPI void APIENTRY glGetPathDashArrayNV (GLuint path, GLfloat *dashArray); +GLAPI void APIENTRY glGetPathMetricsNV (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics); +GLAPI void APIENTRY glGetPathMetricRangeNV (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics); +GLAPI void APIENTRY glGetPathSpacingNV (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing); +GLAPI GLboolean APIENTRY glIsPointInFillPathNV (GLuint path, GLuint mask, GLfloat x, GLfloat y); +GLAPI GLboolean APIENTRY glIsPointInStrokePathNV (GLuint path, GLfloat x, GLfloat y); +GLAPI GLfloat APIENTRY glGetPathLengthNV (GLuint path, GLsizei startSegment, GLsizei numSegments); +GLAPI GLboolean APIENTRY glPointAlongPathNV (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY); +GLAPI void APIENTRY glMatrixLoad3x2fNV (GLenum matrixMode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoad3x3fNV (GLenum matrixMode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoadTranspose3x3fNV (GLenum matrixMode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMult3x2fNV (GLenum matrixMode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMult3x3fNV (GLenum matrixMode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMultTranspose3x3fNV (GLenum matrixMode, const GLfloat *m); +GLAPI void APIENTRY glStencilThenCoverFillPathNV (GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode); +GLAPI void APIENTRY glStencilThenCoverStrokePathNV (GLuint path, GLint reference, GLuint mask, GLenum coverMode); +GLAPI void APIENTRY glStencilThenCoverFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +GLAPI void APIENTRY glStencilThenCoverStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); +GLAPI GLenum APIENTRY glPathGlyphIndexRangeNV (GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint pathParameterTemplate, GLfloat emScale, GLuint *baseAndCount); +GLAPI GLenum APIENTRY glPathGlyphIndexArrayNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +GLAPI GLenum APIENTRY glPathMemoryGlyphIndexArrayNV (GLuint firstPathName, GLenum fontTarget, GLsizeiptr fontSize, const void *fontData, GLsizei faceIndex, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale); +GLAPI void APIENTRY glProgramPathFragmentInputGenNV (GLuint program, GLint location, GLenum genMode, GLint components, const GLfloat *coeffs); +GLAPI void APIENTRY glGetProgramResourcefvNV (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei count, GLsizei *length, GLfloat *params); +GLAPI void APIENTRY glPathColorGenNV (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs); +GLAPI void APIENTRY glPathTexGenNV (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs); +GLAPI void APIENTRY glPathFogGenNV (GLenum genMode); +GLAPI void APIENTRY glGetPathColorGenivNV (GLenum color, GLenum pname, GLint *value); +GLAPI void APIENTRY glGetPathColorGenfvNV (GLenum color, GLenum pname, GLfloat *value); +GLAPI void APIENTRY glGetPathTexGenivNV (GLenum texCoordSet, GLenum pname, GLint *value); +GLAPI void APIENTRY glGetPathTexGenfvNV (GLenum texCoordSet, GLenum pname, GLfloat *value); +#endif +#endif /* GL_NV_path_rendering */ + +#ifndef GL_NV_path_rendering_shared_edge +#define GL_NV_path_rendering_shared_edge 1 +#define GL_SHARED_EDGE_NV 0xC0 +#endif /* GL_NV_path_rendering_shared_edge */ + +#ifndef GL_NV_pixel_data_range +#define GL_NV_pixel_data_range 1 +#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878 +#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879 +#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A +#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B +#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C +#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D +typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, const void *pointer); +typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, const void *pointer); +GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target); +#endif +#endif /* GL_NV_pixel_data_range */ + +#ifndef GL_NV_point_sprite +#define GL_NV_point_sprite 1 +#define GL_POINT_SPRITE_NV 0x8861 +#define GL_COORD_REPLACE_NV 0x8862 +#define GL_POINT_SPRITE_R_MODE_NV 0x8863 +typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameteriNV (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameterivNV (GLenum pname, const GLint *params); +#endif +#endif /* GL_NV_point_sprite */ + +#ifndef GL_NV_present_video +#define GL_NV_present_video 1 +#define GL_FRAME_NV 0x8E26 +#define GL_FIELDS_NV 0x8E27 +#define GL_CURRENT_TIME_NV 0x8E28 +#define GL_NUM_FILL_STREAMS_NV 0x8E29 +#define GL_PRESENT_TIME_NV 0x8E2A +#define GL_PRESENT_DURATION_NV 0x8E2B +typedef void (APIENTRYP PFNGLPRESENTFRAMEKEYEDNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); +typedef void (APIENTRYP PFNGLPRESENTFRAMEDUALFILLNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); +typedef void (APIENTRYP PFNGLGETVIDEOIVNVPROC) (GLuint video_slot, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOUIVNVPROC) (GLuint video_slot, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLGETVIDEOI64VNVPROC) (GLuint video_slot, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETVIDEOUI64VNVPROC) (GLuint video_slot, GLenum pname, GLuint64EXT *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPresentFrameKeyedNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); +GLAPI void APIENTRY glPresentFrameDualFillNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); +GLAPI void APIENTRY glGetVideoivNV (GLuint video_slot, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideouivNV (GLuint video_slot, GLenum pname, GLuint *params); +GLAPI void APIENTRY glGetVideoi64vNV (GLuint video_slot, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetVideoui64vNV (GLuint video_slot, GLenum pname, GLuint64EXT *params); +#endif +#endif /* GL_NV_present_video */ + +#ifndef GL_NV_primitive_restart +#define GL_NV_primitive_restart 1 +#define GL_PRIMITIVE_RESTART_NV 0x8558 +#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559 +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPrimitiveRestartNV (void); +GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint index); +#endif +#endif /* GL_NV_primitive_restart */ + +#ifndef GL_NV_primitive_shading_rate +#define GL_NV_primitive_shading_rate 1 +#define GL_SHADING_RATE_IMAGE_PER_PRIMITIVE_NV 0x95B1 +#define GL_SHADING_RATE_IMAGE_PALETTE_COUNT_NV 0x95B2 +#endif /* GL_NV_primitive_shading_rate */ + +#ifndef GL_NV_query_resource +#define GL_NV_query_resource 1 +#define GL_QUERY_RESOURCE_TYPE_VIDMEM_ALLOC_NV 0x9540 +#define GL_QUERY_RESOURCE_MEMTYPE_VIDMEM_NV 0x9542 +#define GL_QUERY_RESOURCE_SYS_RESERVED_NV 0x9544 +#define GL_QUERY_RESOURCE_TEXTURE_NV 0x9545 +#define GL_QUERY_RESOURCE_RENDERBUFFER_NV 0x9546 +#define GL_QUERY_RESOURCE_BUFFEROBJECT_NV 0x9547 +typedef GLint (APIENTRYP PFNGLQUERYRESOURCENVPROC) (GLenum queryType, GLint tagId, GLuint count, GLint *buffer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glQueryResourceNV (GLenum queryType, GLint tagId, GLuint count, GLint *buffer); +#endif +#endif /* GL_NV_query_resource */ + +#ifndef GL_NV_query_resource_tag +#define GL_NV_query_resource_tag 1 +typedef void (APIENTRYP PFNGLGENQUERYRESOURCETAGNVPROC) (GLsizei n, GLint *tagIds); +typedef void (APIENTRYP PFNGLDELETEQUERYRESOURCETAGNVPROC) (GLsizei n, const GLint *tagIds); +typedef void (APIENTRYP PFNGLQUERYRESOURCETAGNVPROC) (GLint tagId, const GLchar *tagString); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueryResourceTagNV (GLsizei n, GLint *tagIds); +GLAPI void APIENTRY glDeleteQueryResourceTagNV (GLsizei n, const GLint *tagIds); +GLAPI void APIENTRY glQueryResourceTagNV (GLint tagId, const GLchar *tagString); +#endif +#endif /* GL_NV_query_resource_tag */ + +#ifndef GL_NV_register_combiners +#define GL_NV_register_combiners 1 +#define GL_REGISTER_COMBINERS_NV 0x8522 +#define GL_VARIABLE_A_NV 0x8523 +#define GL_VARIABLE_B_NV 0x8524 +#define GL_VARIABLE_C_NV 0x8525 +#define GL_VARIABLE_D_NV 0x8526 +#define GL_VARIABLE_E_NV 0x8527 +#define GL_VARIABLE_F_NV 0x8528 +#define GL_VARIABLE_G_NV 0x8529 +#define GL_CONSTANT_COLOR0_NV 0x852A +#define GL_CONSTANT_COLOR1_NV 0x852B +#define GL_SPARE0_NV 0x852E +#define GL_SPARE1_NV 0x852F +#define GL_DISCARD_NV 0x8530 +#define GL_E_TIMES_F_NV 0x8531 +#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532 +#define GL_UNSIGNED_IDENTITY_NV 0x8536 +#define GL_UNSIGNED_INVERT_NV 0x8537 +#define GL_EXPAND_NORMAL_NV 0x8538 +#define GL_EXPAND_NEGATE_NV 0x8539 +#define GL_HALF_BIAS_NORMAL_NV 0x853A +#define GL_HALF_BIAS_NEGATE_NV 0x853B +#define GL_SIGNED_IDENTITY_NV 0x853C +#define GL_SIGNED_NEGATE_NV 0x853D +#define GL_SCALE_BY_TWO_NV 0x853E +#define GL_SCALE_BY_FOUR_NV 0x853F +#define GL_SCALE_BY_ONE_HALF_NV 0x8540 +#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541 +#define GL_COMBINER_INPUT_NV 0x8542 +#define GL_COMBINER_MAPPING_NV 0x8543 +#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544 +#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545 +#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546 +#define GL_COMBINER_MUX_SUM_NV 0x8547 +#define GL_COMBINER_SCALE_NV 0x8548 +#define GL_COMBINER_BIAS_NV 0x8549 +#define GL_COMBINER_AB_OUTPUT_NV 0x854A +#define GL_COMBINER_CD_OUTPUT_NV 0x854B +#define GL_COMBINER_SUM_OUTPUT_NV 0x854C +#define GL_MAX_GENERAL_COMBINERS_NV 0x854D +#define GL_NUM_GENERAL_COMBINERS_NV 0x854E +#define GL_COLOR_SUM_CLAMP_NV 0x854F +#define GL_COMBINER0_NV 0x8550 +#define GL_COMBINER1_NV 0x8551 +#define GL_COMBINER2_NV 0x8552 +#define GL_COMBINER3_NV 0x8553 +#define GL_COMBINER4_NV 0x8554 +#define GL_COMBINER5_NV 0x8555 +#define GL_COMBINER6_NV 0x8556 +#define GL_COMBINER7_NV 0x8557 +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerParameterfvNV (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glCombinerParameterfNV (GLenum pname, GLfloat param); +GLAPI void APIENTRY glCombinerParameterivNV (GLenum pname, const GLint *params); +GLAPI void APIENTRY glCombinerParameteriNV (GLenum pname, GLint param); +GLAPI void APIENTRY glCombinerInputNV (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +GLAPI void APIENTRY glCombinerOutputNV (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +GLAPI void APIENTRY glFinalCombinerInputNV (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum stage, GLenum portion, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum variable, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum variable, GLenum pname, GLint *params); +#endif +#endif /* GL_NV_register_combiners */ + +#ifndef GL_NV_register_combiners2 +#define GL_NV_register_combiners2 1 +#define GL_PER_STAGE_CONSTANTS_NV 0x8535 +typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum stage, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum stage, GLenum pname, GLfloat *params); +#endif +#endif /* GL_NV_register_combiners2 */ + +#ifndef GL_NV_representative_fragment_test +#define GL_NV_representative_fragment_test 1 +#define GL_REPRESENTATIVE_FRAGMENT_TEST_NV 0x937F +#endif /* GL_NV_representative_fragment_test */ + +#ifndef GL_NV_robustness_video_memory_purge +#define GL_NV_robustness_video_memory_purge 1 +#define GL_PURGED_CONTEXT_RESET_NV 0x92BB +#endif /* GL_NV_robustness_video_memory_purge */ + +#ifndef GL_NV_sample_locations +#define GL_NV_sample_locations 1 +#define GL_SAMPLE_LOCATION_SUBPIXEL_BITS_NV 0x933D +#define GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_NV 0x933E +#define GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_NV 0x933F +#define GL_PROGRAMMABLE_SAMPLE_LOCATION_TABLE_SIZE_NV 0x9340 +#define GL_SAMPLE_LOCATION_NV 0x8E50 +#define GL_PROGRAMMABLE_SAMPLE_LOCATION_NV 0x9341 +#define GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_NV 0x9342 +#define GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_NV 0x9343 +typedef void (APIENTRYP PFNGLFRAMEBUFFERSAMPLELOCATIONSFVNVPROC) (GLenum target, GLuint start, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERSAMPLELOCATIONSFVNVPROC) (GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLRESOLVEDEPTHVALUESNVPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferSampleLocationsfvNV (GLenum target, GLuint start, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glNamedFramebufferSampleLocationsfvNV (GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glResolveDepthValuesNV (void); +#endif +#endif /* GL_NV_sample_locations */ + +#ifndef GL_NV_sample_mask_override_coverage +#define GL_NV_sample_mask_override_coverage 1 +#endif /* GL_NV_sample_mask_override_coverage */ + +#ifndef GL_NV_scissor_exclusive +#define GL_NV_scissor_exclusive 1 +#define GL_SCISSOR_TEST_EXCLUSIVE_NV 0x9555 +#define GL_SCISSOR_BOX_EXCLUSIVE_NV 0x9556 +typedef void (APIENTRYP PFNGLSCISSOREXCLUSIVENVPROC) (GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLSCISSOREXCLUSIVEARRAYVNVPROC) (GLuint first, GLsizei count, const GLint *v); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glScissorExclusiveNV (GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glScissorExclusiveArrayvNV (GLuint first, GLsizei count, const GLint *v); +#endif +#endif /* GL_NV_scissor_exclusive */ + +#ifndef GL_NV_shader_atomic_counters +#define GL_NV_shader_atomic_counters 1 +#endif /* GL_NV_shader_atomic_counters */ + +#ifndef GL_NV_shader_atomic_float +#define GL_NV_shader_atomic_float 1 +#endif /* GL_NV_shader_atomic_float */ + +#ifndef GL_NV_shader_atomic_float64 +#define GL_NV_shader_atomic_float64 1 +#endif /* GL_NV_shader_atomic_float64 */ + +#ifndef GL_NV_shader_atomic_fp16_vector +#define GL_NV_shader_atomic_fp16_vector 1 +#endif /* GL_NV_shader_atomic_fp16_vector */ + +#ifndef GL_NV_shader_atomic_int64 +#define GL_NV_shader_atomic_int64 1 +#endif /* GL_NV_shader_atomic_int64 */ + +#ifndef GL_NV_shader_buffer_load +#define GL_NV_shader_buffer_load 1 +#define GL_BUFFER_GPU_ADDRESS_NV 0x8F1D +#define GL_GPU_ADDRESS_NV 0x8F34 +#define GL_MAX_SHADER_BUFFER_ADDRESS_NV 0x8F35 +typedef void (APIENTRYP PFNGLMAKEBUFFERRESIDENTNVPROC) (GLenum target, GLenum access); +typedef void (APIENTRYP PFNGLMAKEBUFFERNONRESIDENTNVPROC) (GLenum target); +typedef GLboolean (APIENTRYP PFNGLISBUFFERRESIDENTNVPROC) (GLenum target); +typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERRESIDENTNVPROC) (GLuint buffer, GLenum access); +typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERNONRESIDENTNVPROC) (GLuint buffer); +typedef GLboolean (APIENTRYP PFNGLISNAMEDBUFFERRESIDENTNVPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERUI64VNVPROC) (GLenum target, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERUI64VNVPROC) (GLuint buffer, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLGETINTEGERUI64VNVPROC) (GLenum value, GLuint64EXT *result); +typedef void (APIENTRYP PFNGLUNIFORMUI64NVPROC) (GLint location, GLuint64EXT value); +typedef void (APIENTRYP PFNGLUNIFORMUI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64NVPROC) (GLuint program, GLint location, GLuint64EXT value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMakeBufferResidentNV (GLenum target, GLenum access); +GLAPI void APIENTRY glMakeBufferNonResidentNV (GLenum target); +GLAPI GLboolean APIENTRY glIsBufferResidentNV (GLenum target); +GLAPI void APIENTRY glMakeNamedBufferResidentNV (GLuint buffer, GLenum access); +GLAPI void APIENTRY glMakeNamedBufferNonResidentNV (GLuint buffer); +GLAPI GLboolean APIENTRY glIsNamedBufferResidentNV (GLuint buffer); +GLAPI void APIENTRY glGetBufferParameterui64vNV (GLenum target, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glGetNamedBufferParameterui64vNV (GLuint buffer, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glGetIntegerui64vNV (GLenum value, GLuint64EXT *result); +GLAPI void APIENTRY glUniformui64NV (GLint location, GLuint64EXT value); +GLAPI void APIENTRY glUniformui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniformui64NV (GLuint program, GLint location, GLuint64EXT value); +GLAPI void APIENTRY glProgramUniformui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif +#endif /* GL_NV_shader_buffer_load */ + +#ifndef GL_NV_shader_buffer_store +#define GL_NV_shader_buffer_store 1 +#define GL_SHADER_GLOBAL_ACCESS_BARRIER_BIT_NV 0x00000010 +#endif /* GL_NV_shader_buffer_store */ + +#ifndef GL_NV_shader_storage_buffer_object +#define GL_NV_shader_storage_buffer_object 1 +#endif /* GL_NV_shader_storage_buffer_object */ + +#ifndef GL_NV_shader_subgroup_partitioned +#define GL_NV_shader_subgroup_partitioned 1 +#define GL_SUBGROUP_FEATURE_PARTITIONED_BIT_NV 0x00000100 +#endif /* GL_NV_shader_subgroup_partitioned */ + +#ifndef GL_NV_shader_texture_footprint +#define GL_NV_shader_texture_footprint 1 +#endif /* GL_NV_shader_texture_footprint */ + +#ifndef GL_NV_shader_thread_group +#define GL_NV_shader_thread_group 1 +#define GL_WARP_SIZE_NV 0x9339 +#define GL_WARPS_PER_SM_NV 0x933A +#define GL_SM_COUNT_NV 0x933B +#endif /* GL_NV_shader_thread_group */ + +#ifndef GL_NV_shader_thread_shuffle +#define GL_NV_shader_thread_shuffle 1 +#endif /* GL_NV_shader_thread_shuffle */ + +#ifndef GL_NV_shading_rate_image +#define GL_NV_shading_rate_image 1 +#define GL_SHADING_RATE_IMAGE_NV 0x9563 +#define GL_SHADING_RATE_NO_INVOCATIONS_NV 0x9564 +#define GL_SHADING_RATE_1_INVOCATION_PER_PIXEL_NV 0x9565 +#define GL_SHADING_RATE_1_INVOCATION_PER_1X2_PIXELS_NV 0x9566 +#define GL_SHADING_RATE_1_INVOCATION_PER_2X1_PIXELS_NV 0x9567 +#define GL_SHADING_RATE_1_INVOCATION_PER_2X2_PIXELS_NV 0x9568 +#define GL_SHADING_RATE_1_INVOCATION_PER_2X4_PIXELS_NV 0x9569 +#define GL_SHADING_RATE_1_INVOCATION_PER_4X2_PIXELS_NV 0x956A +#define GL_SHADING_RATE_1_INVOCATION_PER_4X4_PIXELS_NV 0x956B +#define GL_SHADING_RATE_2_INVOCATIONS_PER_PIXEL_NV 0x956C +#define GL_SHADING_RATE_4_INVOCATIONS_PER_PIXEL_NV 0x956D +#define GL_SHADING_RATE_8_INVOCATIONS_PER_PIXEL_NV 0x956E +#define GL_SHADING_RATE_16_INVOCATIONS_PER_PIXEL_NV 0x956F +#define GL_SHADING_RATE_IMAGE_BINDING_NV 0x955B +#define GL_SHADING_RATE_IMAGE_TEXEL_WIDTH_NV 0x955C +#define GL_SHADING_RATE_IMAGE_TEXEL_HEIGHT_NV 0x955D +#define GL_SHADING_RATE_IMAGE_PALETTE_SIZE_NV 0x955E +#define GL_MAX_COARSE_FRAGMENT_SAMPLES_NV 0x955F +#define GL_SHADING_RATE_SAMPLE_ORDER_DEFAULT_NV 0x95AE +#define GL_SHADING_RATE_SAMPLE_ORDER_PIXEL_MAJOR_NV 0x95AF +#define GL_SHADING_RATE_SAMPLE_ORDER_SAMPLE_MAJOR_NV 0x95B0 +typedef void (APIENTRYP PFNGLBINDSHADINGRATEIMAGENVPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLGETSHADINGRATEIMAGEPALETTENVPROC) (GLuint viewport, GLuint entry, GLenum *rate); +typedef void (APIENTRYP PFNGLGETSHADINGRATESAMPLELOCATIONIVNVPROC) (GLenum rate, GLuint samples, GLuint index, GLint *location); +typedef void (APIENTRYP PFNGLSHADINGRATEIMAGEBARRIERNVPROC) (GLboolean synchronize); +typedef void (APIENTRYP PFNGLSHADINGRATEIMAGEPALETTENVPROC) (GLuint viewport, GLuint first, GLsizei count, const GLenum *rates); +typedef void (APIENTRYP PFNGLSHADINGRATESAMPLEORDERNVPROC) (GLenum order); +typedef void (APIENTRYP PFNGLSHADINGRATESAMPLEORDERCUSTOMNVPROC) (GLenum rate, GLuint samples, const GLint *locations); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindShadingRateImageNV (GLuint texture); +GLAPI void APIENTRY glGetShadingRateImagePaletteNV (GLuint viewport, GLuint entry, GLenum *rate); +GLAPI void APIENTRY glGetShadingRateSampleLocationivNV (GLenum rate, GLuint samples, GLuint index, GLint *location); +GLAPI void APIENTRY glShadingRateImageBarrierNV (GLboolean synchronize); +GLAPI void APIENTRY glShadingRateImagePaletteNV (GLuint viewport, GLuint first, GLsizei count, const GLenum *rates); +GLAPI void APIENTRY glShadingRateSampleOrderNV (GLenum order); +GLAPI void APIENTRY glShadingRateSampleOrderCustomNV (GLenum rate, GLuint samples, const GLint *locations); +#endif +#endif /* GL_NV_shading_rate_image */ + +#ifndef GL_NV_stereo_view_rendering +#define GL_NV_stereo_view_rendering 1 +#endif /* GL_NV_stereo_view_rendering */ + +#ifndef GL_NV_tessellation_program5 +#define GL_NV_tessellation_program5 1 +#define GL_MAX_PROGRAM_PATCH_ATTRIBS_NV 0x86D8 +#define GL_TESS_CONTROL_PROGRAM_NV 0x891E +#define GL_TESS_EVALUATION_PROGRAM_NV 0x891F +#define GL_TESS_CONTROL_PROGRAM_PARAMETER_BUFFER_NV 0x8C74 +#define GL_TESS_EVALUATION_PROGRAM_PARAMETER_BUFFER_NV 0x8C75 +#endif /* GL_NV_tessellation_program5 */ + +#ifndef GL_NV_texgen_emboss +#define GL_NV_texgen_emboss 1 +#define GL_EMBOSS_LIGHT_NV 0x855D +#define GL_EMBOSS_CONSTANT_NV 0x855E +#define GL_EMBOSS_MAP_NV 0x855F +#endif /* GL_NV_texgen_emboss */ + +#ifndef GL_NV_texgen_reflection +#define GL_NV_texgen_reflection 1 +#define GL_NORMAL_MAP_NV 0x8511 +#define GL_REFLECTION_MAP_NV 0x8512 +#endif /* GL_NV_texgen_reflection */ + +#ifndef GL_NV_texture_barrier +#define GL_NV_texture_barrier 1 +typedef void (APIENTRYP PFNGLTEXTUREBARRIERNVPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureBarrierNV (void); +#endif +#endif /* GL_NV_texture_barrier */ + +#ifndef GL_NV_texture_compression_vtc +#define GL_NV_texture_compression_vtc 1 +#endif /* GL_NV_texture_compression_vtc */ + +#ifndef GL_NV_texture_env_combine4 +#define GL_NV_texture_env_combine4 1 +#define GL_COMBINE4_NV 0x8503 +#define GL_SOURCE3_RGB_NV 0x8583 +#define GL_SOURCE3_ALPHA_NV 0x858B +#define GL_OPERAND3_RGB_NV 0x8593 +#define GL_OPERAND3_ALPHA_NV 0x859B +#endif /* GL_NV_texture_env_combine4 */ + +#ifndef GL_NV_texture_expand_normal +#define GL_NV_texture_expand_normal 1 +#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F +#endif /* GL_NV_texture_expand_normal */ + +#ifndef GL_NV_texture_multisample +#define GL_NV_texture_multisample 1 +#define GL_TEXTURE_COVERAGE_SAMPLES_NV 0x9045 +#define GL_TEXTURE_COLOR_SAMPLES_NV 0x9046 +typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); +typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage2DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); +GLAPI void APIENTRY glTexImage3DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); +GLAPI void APIENTRY glTextureImage2DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); +GLAPI void APIENTRY glTextureImage3DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); +GLAPI void APIENTRY glTextureImage2DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); +GLAPI void APIENTRY glTextureImage3DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); +#endif +#endif /* GL_NV_texture_multisample */ + +#ifndef GL_NV_texture_rectangle +#define GL_NV_texture_rectangle 1 +#define GL_TEXTURE_RECTANGLE_NV 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 +#endif /* GL_NV_texture_rectangle */ + +#ifndef GL_NV_texture_rectangle_compressed +#define GL_NV_texture_rectangle_compressed 1 +#endif /* GL_NV_texture_rectangle_compressed */ + +#ifndef GL_NV_texture_shader +#define GL_NV_texture_shader 1 +#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C +#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D +#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E +#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9 +#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA +#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB +#define GL_DSDT_MAG_INTENSITY_NV 0x86DC +#define GL_SHADER_CONSISTENT_NV 0x86DD +#define GL_TEXTURE_SHADER_NV 0x86DE +#define GL_SHADER_OPERATION_NV 0x86DF +#define GL_CULL_MODES_NV 0x86E0 +#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1 +#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2 +#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3 +#define GL_OFFSET_TEXTURE_2D_MATRIX_NV 0x86E1 +#define GL_OFFSET_TEXTURE_2D_SCALE_NV 0x86E2 +#define GL_OFFSET_TEXTURE_2D_BIAS_NV 0x86E3 +#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4 +#define GL_CONST_EYE_NV 0x86E5 +#define GL_PASS_THROUGH_NV 0x86E6 +#define GL_CULL_FRAGMENT_NV 0x86E7 +#define GL_OFFSET_TEXTURE_2D_NV 0x86E8 +#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9 +#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA +#define GL_DOT_PRODUCT_NV 0x86EC +#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED +#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE +#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0 +#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1 +#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2 +#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3 +#define GL_HILO_NV 0x86F4 +#define GL_DSDT_NV 0x86F5 +#define GL_DSDT_MAG_NV 0x86F6 +#define GL_DSDT_MAG_VIB_NV 0x86F7 +#define GL_HILO16_NV 0x86F8 +#define GL_SIGNED_HILO_NV 0x86F9 +#define GL_SIGNED_HILO16_NV 0x86FA +#define GL_SIGNED_RGBA_NV 0x86FB +#define GL_SIGNED_RGBA8_NV 0x86FC +#define GL_SIGNED_RGB_NV 0x86FE +#define GL_SIGNED_RGB8_NV 0x86FF +#define GL_SIGNED_LUMINANCE_NV 0x8701 +#define GL_SIGNED_LUMINANCE8_NV 0x8702 +#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 +#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 +#define GL_SIGNED_ALPHA_NV 0x8705 +#define GL_SIGNED_ALPHA8_NV 0x8706 +#define GL_SIGNED_INTENSITY_NV 0x8707 +#define GL_SIGNED_INTENSITY8_NV 0x8708 +#define GL_DSDT8_NV 0x8709 +#define GL_DSDT8_MAG8_NV 0x870A +#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B +#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C +#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D +#define GL_HI_SCALE_NV 0x870E +#define GL_LO_SCALE_NV 0x870F +#define GL_DS_SCALE_NV 0x8710 +#define GL_DT_SCALE_NV 0x8711 +#define GL_MAGNITUDE_SCALE_NV 0x8712 +#define GL_VIBRANCE_SCALE_NV 0x8713 +#define GL_HI_BIAS_NV 0x8714 +#define GL_LO_BIAS_NV 0x8715 +#define GL_DS_BIAS_NV 0x8716 +#define GL_DT_BIAS_NV 0x8717 +#define GL_MAGNITUDE_BIAS_NV 0x8718 +#define GL_VIBRANCE_BIAS_NV 0x8719 +#define GL_TEXTURE_BORDER_VALUES_NV 0x871A +#define GL_TEXTURE_HI_SIZE_NV 0x871B +#define GL_TEXTURE_LO_SIZE_NV 0x871C +#define GL_TEXTURE_DS_SIZE_NV 0x871D +#define GL_TEXTURE_DT_SIZE_NV 0x871E +#define GL_TEXTURE_MAG_SIZE_NV 0x871F +#endif /* GL_NV_texture_shader */ + +#ifndef GL_NV_texture_shader2 +#define GL_NV_texture_shader2 1 +#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF +#endif /* GL_NV_texture_shader2 */ + +#ifndef GL_NV_texture_shader3 +#define GL_NV_texture_shader3 1 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853 +#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854 +#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857 +#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858 +#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859 +#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A +#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B +#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C +#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D +#define GL_HILO8_NV 0x885E +#define GL_SIGNED_HILO8_NV 0x885F +#define GL_FORCE_BLUE_TO_ONE_NV 0x8860 +#endif /* GL_NV_texture_shader3 */ + +#ifndef GL_NV_timeline_semaphore +#define GL_NV_timeline_semaphore 1 +#define GL_TIMELINE_SEMAPHORE_VALUE_NV 0x9595 +#define GL_SEMAPHORE_TYPE_NV 0x95B3 +#define GL_SEMAPHORE_TYPE_BINARY_NV 0x95B4 +#define GL_SEMAPHORE_TYPE_TIMELINE_NV 0x95B5 +#define GL_MAX_TIMELINE_SEMAPHORE_VALUE_DIFFERENCE_NV 0x95B6 +typedef void (APIENTRYP PFNGLCREATESEMAPHORESNVPROC) (GLsizei n, GLuint *semaphores); +typedef void (APIENTRYP PFNGLSEMAPHOREPARAMETERIVNVPROC) (GLuint semaphore, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETSEMAPHOREPARAMETERIVNVPROC) (GLuint semaphore, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCreateSemaphoresNV (GLsizei n, GLuint *semaphores); +GLAPI void APIENTRY glSemaphoreParameterivNV (GLuint semaphore, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetSemaphoreParameterivNV (GLuint semaphore, GLenum pname, GLint *params); +#endif +#endif /* GL_NV_timeline_semaphore */ + +#ifndef GL_NV_transform_feedback +#define GL_NV_transform_feedback 1 +#define GL_BACK_PRIMARY_COLOR_NV 0x8C77 +#define GL_BACK_SECONDARY_COLOR_NV 0x8C78 +#define GL_TEXTURE_COORD_NV 0x8C79 +#define GL_CLIP_DISTANCE_NV 0x8C7A +#define GL_VERTEX_ID_NV 0x8C7B +#define GL_PRIMITIVE_ID_NV 0x8C7C +#define GL_GENERIC_ATTRIB_NV 0x8C7D +#define GL_TRANSFORM_FEEDBACK_ATTRIBS_NV 0x8C7E +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_NV 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_NV 0x8C80 +#define GL_ACTIVE_VARYINGS_NV 0x8C81 +#define GL_ACTIVE_VARYING_MAX_LENGTH_NV 0x8C82 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_NV 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_NV 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_NV 0x8C85 +#define GL_TRANSFORM_FEEDBACK_RECORD_NV 0x8C86 +#define GL_PRIMITIVES_GENERATED_NV 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV 0x8C88 +#define GL_RASTERIZER_DISCARD_NV 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_NV 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_NV 0x8C8B +#define GL_INTERLEAVED_ATTRIBS_NV 0x8C8C +#define GL_SEPARATE_ATTRIBS_NV 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER_NV 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_NV 0x8C8F +#define GL_LAYER_NV 0x8DAA +#define GL_NEXT_BUFFER_NV -2 +#define GL_SKIP_COMPONENTS4_NV -3 +#define GL_SKIP_COMPONENTS3_NV -4 +#define GL_SKIP_COMPONENTS2_NV -5 +#define GL_SKIP_COMPONENTS1_NV -6 +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKNVPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC) (GLsizei count, const GLint *attribs, GLenum bufferMode); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGENVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETNVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASENVPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC) (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); +typedef void (APIENTRYP PFNGLACTIVEVARYINGNVPROC) (GLuint program, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETVARYINGLOCATIONNVPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEVARYINGNVPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) (GLuint program, GLuint index, GLint *location); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKSTREAMATTRIBSNVPROC) (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackNV (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedbackNV (void); +GLAPI void APIENTRY glTransformFeedbackAttribsNV (GLsizei count, const GLint *attribs, GLenum bufferMode); +GLAPI void APIENTRY glBindBufferRangeNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferOffsetNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +GLAPI void APIENTRY glBindBufferBaseNV (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryingsNV (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); +GLAPI void APIENTRY glActiveVaryingNV (GLuint program, const GLchar *name); +GLAPI GLint APIENTRY glGetVaryingLocationNV (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetActiveVaryingNV (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetTransformFeedbackVaryingNV (GLuint program, GLuint index, GLint *location); +GLAPI void APIENTRY glTransformFeedbackStreamAttribsNV (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); +#endif +#endif /* GL_NV_transform_feedback */ + +#ifndef GL_NV_transform_feedback2 +#define GL_NV_transform_feedback2 1 +#define GL_TRANSFORM_FEEDBACK_NV 0x8E22 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED_NV 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE_NV 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING_NV 0x8E25 +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSNVPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSNVPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKNVPROC) (GLenum mode, GLuint id); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedbackNV (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacksNV (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacksNV (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedbackNV (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedbackNV (void); +GLAPI void APIENTRY glResumeTransformFeedbackNV (void); +GLAPI void APIENTRY glDrawTransformFeedbackNV (GLenum mode, GLuint id); +#endif +#endif /* GL_NV_transform_feedback2 */ + +#ifndef GL_NV_uniform_buffer_std430_layout +#define GL_NV_uniform_buffer_std430_layout 1 +#endif /* GL_NV_uniform_buffer_std430_layout */ + +#ifndef GL_NV_uniform_buffer_unified_memory +#define GL_NV_uniform_buffer_unified_memory 1 +#define GL_UNIFORM_BUFFER_UNIFIED_NV 0x936E +#define GL_UNIFORM_BUFFER_ADDRESS_NV 0x936F +#define GL_UNIFORM_BUFFER_LENGTH_NV 0x9370 +#endif /* GL_NV_uniform_buffer_unified_memory */ + +#ifndef GL_NV_vdpau_interop +#define GL_NV_vdpau_interop 1 +typedef GLintptr GLvdpauSurfaceNV; +#define GL_SURFACE_STATE_NV 0x86EB +#define GL_SURFACE_REGISTERED_NV 0x86FD +#define GL_SURFACE_MAPPED_NV 0x8700 +#define GL_WRITE_DISCARD_NV 0x88BE +typedef void (APIENTRYP PFNGLVDPAUINITNVPROC) (const void *vdpDevice, const void *getProcAddress); +typedef void (APIENTRYP PFNGLVDPAUFININVPROC) (void); +typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTERVIDEOSURFACENVPROC) (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC) (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +typedef GLboolean (APIENTRYP PFNGLVDPAUISSURFACENVPROC) (GLvdpauSurfaceNV surface); +typedef void (APIENTRYP PFNGLVDPAUUNREGISTERSURFACENVPROC) (GLvdpauSurfaceNV surface); +typedef void (APIENTRYP PFNGLVDPAUGETSURFACEIVNVPROC) (GLvdpauSurfaceNV surface, GLenum pname, GLsizei count, GLsizei *length, GLint *values); +typedef void (APIENTRYP PFNGLVDPAUSURFACEACCESSNVPROC) (GLvdpauSurfaceNV surface, GLenum access); +typedef void (APIENTRYP PFNGLVDPAUMAPSURFACESNVPROC) (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); +typedef void (APIENTRYP PFNGLVDPAUUNMAPSURFACESNVPROC) (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVDPAUInitNV (const void *vdpDevice, const void *getProcAddress); +GLAPI void APIENTRY glVDPAUFiniNV (void); +GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterVideoSurfaceNV (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterOutputSurfaceNV (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +GLAPI GLboolean APIENTRY glVDPAUIsSurfaceNV (GLvdpauSurfaceNV surface); +GLAPI void APIENTRY glVDPAUUnregisterSurfaceNV (GLvdpauSurfaceNV surface); +GLAPI void APIENTRY glVDPAUGetSurfaceivNV (GLvdpauSurfaceNV surface, GLenum pname, GLsizei count, GLsizei *length, GLint *values); +GLAPI void APIENTRY glVDPAUSurfaceAccessNV (GLvdpauSurfaceNV surface, GLenum access); +GLAPI void APIENTRY glVDPAUMapSurfacesNV (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); +GLAPI void APIENTRY glVDPAUUnmapSurfacesNV (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); +#endif +#endif /* GL_NV_vdpau_interop */ + +#ifndef GL_NV_vdpau_interop2 +#define GL_NV_vdpau_interop2 1 +typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTERVIDEOSURFACEWITHPICTURESTRUCTURENVPROC) (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames, GLboolean isFrameStructure); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterVideoSurfaceWithPictureStructureNV (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames, GLboolean isFrameStructure); +#endif +#endif /* GL_NV_vdpau_interop2 */ + +#ifndef GL_NV_vertex_array_range +#define GL_NV_vertex_array_range 1 +#define GL_VERTEX_ARRAY_RANGE_NV 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E +#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F +#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520 +#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521 +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const void *pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); +GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei length, const void *pointer); +#endif +#endif /* GL_NV_vertex_array_range */ + +#ifndef GL_NV_vertex_array_range2 +#define GL_NV_vertex_array_range2 1 +#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533 +#endif /* GL_NV_vertex_array_range2 */ + +#ifndef GL_NV_vertex_attrib_integer_64bit +#define GL_NV_vertex_attrib_integer_64bit 1 +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64NVPROC) (GLuint index, GLint64EXT x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64NVPROC) (GLuint index, GLuint64EXT x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLI64VNVPROC) (GLuint index, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VNVPROC) (GLuint index, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1i64NV (GLuint index, GLint64EXT x); +GLAPI void APIENTRY glVertexAttribL2i64NV (GLuint index, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glVertexAttribL3i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glVertexAttribL4i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glVertexAttribL1i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL2i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL3i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL4i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL1ui64NV (GLuint index, GLuint64EXT x); +GLAPI void APIENTRY glVertexAttribL2ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glVertexAttribL3ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glVertexAttribL4ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glVertexAttribL1ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL2ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL3ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL4ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glGetVertexAttribLi64vNV (GLuint index, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetVertexAttribLui64vNV (GLuint index, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glVertexAttribLFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); +#endif +#endif /* GL_NV_vertex_attrib_integer_64bit */ + +#ifndef GL_NV_vertex_buffer_unified_memory +#define GL_NV_vertex_buffer_unified_memory 1 +#define GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV 0x8F1E +#define GL_ELEMENT_ARRAY_UNIFIED_NV 0x8F1F +#define GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV 0x8F20 +#define GL_VERTEX_ARRAY_ADDRESS_NV 0x8F21 +#define GL_NORMAL_ARRAY_ADDRESS_NV 0x8F22 +#define GL_COLOR_ARRAY_ADDRESS_NV 0x8F23 +#define GL_INDEX_ARRAY_ADDRESS_NV 0x8F24 +#define GL_TEXTURE_COORD_ARRAY_ADDRESS_NV 0x8F25 +#define GL_EDGE_FLAG_ARRAY_ADDRESS_NV 0x8F26 +#define GL_SECONDARY_COLOR_ARRAY_ADDRESS_NV 0x8F27 +#define GL_FOG_COORD_ARRAY_ADDRESS_NV 0x8F28 +#define GL_ELEMENT_ARRAY_ADDRESS_NV 0x8F29 +#define GL_VERTEX_ATTRIB_ARRAY_LENGTH_NV 0x8F2A +#define GL_VERTEX_ARRAY_LENGTH_NV 0x8F2B +#define GL_NORMAL_ARRAY_LENGTH_NV 0x8F2C +#define GL_COLOR_ARRAY_LENGTH_NV 0x8F2D +#define GL_INDEX_ARRAY_LENGTH_NV 0x8F2E +#define GL_TEXTURE_COORD_ARRAY_LENGTH_NV 0x8F2F +#define GL_EDGE_FLAG_ARRAY_LENGTH_NV 0x8F30 +#define GL_SECONDARY_COLOR_ARRAY_LENGTH_NV 0x8F31 +#define GL_FOG_COORD_ARRAY_LENGTH_NV 0x8F32 +#define GL_ELEMENT_ARRAY_LENGTH_NV 0x8F33 +#define GL_DRAW_INDIRECT_UNIFIED_NV 0x8F40 +#define GL_DRAW_INDIRECT_ADDRESS_NV 0x8F41 +#define GL_DRAW_INDIRECT_LENGTH_NV 0x8F42 +typedef void (APIENTRYP PFNGLBUFFERADDRESSRANGENVPROC) (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); +typedef void (APIENTRYP PFNGLVERTEXFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLNORMALFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLINDEXFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLTEXCOORDFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLEDGEFLAGFORMATNVPROC) (GLsizei stride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLFOGCOORDFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferAddressRangeNV (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); +GLAPI void APIENTRY glVertexFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glNormalFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glColorFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glIndexFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glTexCoordFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glEdgeFlagFormatNV (GLsizei stride); +GLAPI void APIENTRY glSecondaryColorFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glFogCoordFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormatNV (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); +GLAPI void APIENTRY glVertexAttribIFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glGetIntegerui64i_vNV (GLenum value, GLuint index, GLuint64EXT *result); +#endif +#endif /* GL_NV_vertex_buffer_unified_memory */ + +#ifndef GL_NV_vertex_program +#define GL_NV_vertex_program 1 +#define GL_VERTEX_PROGRAM_NV 0x8620 +#define GL_VERTEX_STATE_PROGRAM_NV 0x8621 +#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623 +#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624 +#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625 +#define GL_CURRENT_ATTRIB_NV 0x8626 +#define GL_PROGRAM_LENGTH_NV 0x8627 +#define GL_PROGRAM_STRING_NV 0x8628 +#define GL_MODELVIEW_PROJECTION_NV 0x8629 +#define GL_IDENTITY_NV 0x862A +#define GL_INVERSE_NV 0x862B +#define GL_TRANSPOSE_NV 0x862C +#define GL_INVERSE_TRANSPOSE_NV 0x862D +#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E +#define GL_MAX_TRACK_MATRICES_NV 0x862F +#define GL_MATRIX0_NV 0x8630 +#define GL_MATRIX1_NV 0x8631 +#define GL_MATRIX2_NV 0x8632 +#define GL_MATRIX3_NV 0x8633 +#define GL_MATRIX4_NV 0x8634 +#define GL_MATRIX5_NV 0x8635 +#define GL_MATRIX6_NV 0x8636 +#define GL_MATRIX7_NV 0x8637 +#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640 +#define GL_CURRENT_MATRIX_NV 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643 +#define GL_PROGRAM_PARAMETER_NV 0x8644 +#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645 +#define GL_PROGRAM_TARGET_NV 0x8646 +#define GL_PROGRAM_RESIDENT_NV 0x8647 +#define GL_TRACK_MATRIX_NV 0x8648 +#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649 +#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A +#define GL_PROGRAM_ERROR_POSITION_NV 0x864B +#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650 +#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651 +#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652 +#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653 +#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654 +#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655 +#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656 +#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657 +#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658 +#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659 +#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A +#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B +#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C +#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D +#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E +#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F +#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660 +#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661 +#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662 +#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663 +#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664 +#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665 +#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666 +#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667 +#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668 +#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669 +#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A +#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B +#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C +#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D +#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E +#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F +#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670 +#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671 +#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672 +#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673 +#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674 +#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675 +#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676 +#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677 +#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678 +#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679 +#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A +#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B +#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C +#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D +#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E +#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F +typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); +typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); +typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, void **pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const void *pointer); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei n, const GLuint *programs, GLboolean *residences); +GLAPI void APIENTRY glBindProgramNV (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteProgramsNV (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glExecuteProgramNV (GLenum target, GLuint id, const GLfloat *params); +GLAPI void APIENTRY glGenProgramsNV (GLsizei n, GLuint *programs); +GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum target, GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetProgramivNV (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramStringNV (GLuint id, GLenum pname, GLubyte *program); +GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum target, GLuint address, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribivNV (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint index, GLenum pname, void **pointer); +GLAPI GLboolean APIENTRY glIsProgramNV (GLuint id); +GLAPI void APIENTRY glLoadProgramNV (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +GLAPI void APIENTRY glProgramParameter4dNV (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramParameter4dvNV (GLenum target, GLuint index, const GLdouble *v); +GLAPI void APIENTRY glProgramParameter4fNV (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramParameter4fvNV (GLenum target, GLuint index, const GLfloat *v); +GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glTrackMatrixNV (GLenum target, GLuint address, GLenum matrix, GLenum transform); +GLAPI void APIENTRY glVertexAttribPointerNV (GLuint index, GLint fsize, GLenum type, GLsizei stride, const void *pointer); +GLAPI void APIENTRY glVertexAttrib1dNV (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1fNV (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1sNV (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2dNV (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2fNV (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2sNV (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3sNV (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4sNV (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs1svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs2svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs3svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs4svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint index, GLsizei count, const GLubyte *v); +#endif +#endif /* GL_NV_vertex_program */ + +#ifndef GL_NV_vertex_program1_1 +#define GL_NV_vertex_program1_1 1 +#endif /* GL_NV_vertex_program1_1 */ + +#ifndef GL_NV_vertex_program2 +#define GL_NV_vertex_program2 1 +#endif /* GL_NV_vertex_program2 */ + +#ifndef GL_NV_vertex_program2_option +#define GL_NV_vertex_program2_option 1 +#endif /* GL_NV_vertex_program2_option */ + +#ifndef GL_NV_vertex_program3 +#define GL_NV_vertex_program3 1 +#endif /* GL_NV_vertex_program3 */ + +#ifndef GL_NV_vertex_program4 +#define GL_NV_vertex_program4 1 +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_NV 0x88FD +#endif /* GL_NV_vertex_program4 */ + +#ifndef GL_NV_video_capture +#define GL_NV_video_capture 1 +#define GL_VIDEO_BUFFER_NV 0x9020 +#define GL_VIDEO_BUFFER_BINDING_NV 0x9021 +#define GL_FIELD_UPPER_NV 0x9022 +#define GL_FIELD_LOWER_NV 0x9023 +#define GL_NUM_VIDEO_CAPTURE_STREAMS_NV 0x9024 +#define GL_NEXT_VIDEO_CAPTURE_BUFFER_STATUS_NV 0x9025 +#define GL_VIDEO_CAPTURE_TO_422_SUPPORTED_NV 0x9026 +#define GL_LAST_VIDEO_CAPTURE_STATUS_NV 0x9027 +#define GL_VIDEO_BUFFER_PITCH_NV 0x9028 +#define GL_VIDEO_COLOR_CONVERSION_MATRIX_NV 0x9029 +#define GL_VIDEO_COLOR_CONVERSION_MAX_NV 0x902A +#define GL_VIDEO_COLOR_CONVERSION_MIN_NV 0x902B +#define GL_VIDEO_COLOR_CONVERSION_OFFSET_NV 0x902C +#define GL_VIDEO_BUFFER_INTERNAL_FORMAT_NV 0x902D +#define GL_PARTIAL_SUCCESS_NV 0x902E +#define GL_SUCCESS_NV 0x902F +#define GL_FAILURE_NV 0x9030 +#define GL_YCBYCR8_422_NV 0x9031 +#define GL_YCBAYCR8A_4224_NV 0x9032 +#define GL_Z6Y10Z6CB10Z6Y10Z6CR10_422_NV 0x9033 +#define GL_Z6Y10Z6CB10Z6A10Z6Y10Z6CR10Z6A10_4224_NV 0x9034 +#define GL_Z4Y12Z4CB12Z4Y12Z4CR12_422_NV 0x9035 +#define GL_Z4Y12Z4CB12Z4A12Z4Y12Z4CR12Z4A12_4224_NV 0x9036 +#define GL_Z4Y12Z4CB12Z4CR12_444_NV 0x9037 +#define GL_VIDEO_CAPTURE_FRAME_WIDTH_NV 0x9038 +#define GL_VIDEO_CAPTURE_FRAME_HEIGHT_NV 0x9039 +#define GL_VIDEO_CAPTURE_FIELD_UPPER_HEIGHT_NV 0x903A +#define GL_VIDEO_CAPTURE_FIELD_LOWER_HEIGHT_NV 0x903B +#define GL_VIDEO_CAPTURE_SURFACE_ORIGIN_NV 0x903C +typedef void (APIENTRYP PFNGLBEGINVIDEOCAPTURENVPROC) (GLuint video_capture_slot); +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMBUFFERNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMTEXTURENVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLENDVIDEOCAPTURENVPROC) (GLuint video_capture_slot); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTUREIVNVPROC) (GLuint video_capture_slot, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); +typedef GLenum (APIENTRYP PFNGLVIDEOCAPTURENVPROC) (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVideoCaptureNV (GLuint video_capture_slot); +GLAPI void APIENTRY glBindVideoCaptureStreamBufferNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); +GLAPI void APIENTRY glBindVideoCaptureStreamTextureNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); +GLAPI void APIENTRY glEndVideoCaptureNV (GLuint video_capture_slot); +GLAPI void APIENTRY glGetVideoCaptureivNV (GLuint video_capture_slot, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideoCaptureStreamivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideoCaptureStreamfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVideoCaptureStreamdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); +GLAPI GLenum APIENTRY glVideoCaptureNV (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); +GLAPI void APIENTRY glVideoCaptureStreamParameterivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); +GLAPI void APIENTRY glVideoCaptureStreamParameterfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glVideoCaptureStreamParameterdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); +#endif +#endif /* GL_NV_video_capture */ + +#ifndef GL_NV_viewport_array2 +#define GL_NV_viewport_array2 1 +#endif /* GL_NV_viewport_array2 */ + +#ifndef GL_NV_viewport_swizzle +#define GL_NV_viewport_swizzle 1 +#define GL_VIEWPORT_SWIZZLE_POSITIVE_X_NV 0x9350 +#define GL_VIEWPORT_SWIZZLE_NEGATIVE_X_NV 0x9351 +#define GL_VIEWPORT_SWIZZLE_POSITIVE_Y_NV 0x9352 +#define GL_VIEWPORT_SWIZZLE_NEGATIVE_Y_NV 0x9353 +#define GL_VIEWPORT_SWIZZLE_POSITIVE_Z_NV 0x9354 +#define GL_VIEWPORT_SWIZZLE_NEGATIVE_Z_NV 0x9355 +#define GL_VIEWPORT_SWIZZLE_POSITIVE_W_NV 0x9356 +#define GL_VIEWPORT_SWIZZLE_NEGATIVE_W_NV 0x9357 +#define GL_VIEWPORT_SWIZZLE_X_NV 0x9358 +#define GL_VIEWPORT_SWIZZLE_Y_NV 0x9359 +#define GL_VIEWPORT_SWIZZLE_Z_NV 0x935A +#define GL_VIEWPORT_SWIZZLE_W_NV 0x935B +typedef void (APIENTRYP PFNGLVIEWPORTSWIZZLENVPROC) (GLuint index, GLenum swizzlex, GLenum swizzley, GLenum swizzlez, GLenum swizzlew); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glViewportSwizzleNV (GLuint index, GLenum swizzlex, GLenum swizzley, GLenum swizzlez, GLenum swizzlew); +#endif +#endif /* GL_NV_viewport_swizzle */ + +#ifndef GL_OML_interlace +#define GL_OML_interlace 1 +#define GL_INTERLACE_OML 0x8980 +#define GL_INTERLACE_READ_OML 0x8981 +#endif /* GL_OML_interlace */ + +#ifndef GL_OML_resample +#define GL_OML_resample 1 +#define GL_PACK_RESAMPLE_OML 0x8984 +#define GL_UNPACK_RESAMPLE_OML 0x8985 +#define GL_RESAMPLE_REPLICATE_OML 0x8986 +#define GL_RESAMPLE_ZERO_FILL_OML 0x8987 +#define GL_RESAMPLE_AVERAGE_OML 0x8988 +#define GL_RESAMPLE_DECIMATE_OML 0x8989 +#endif /* GL_OML_resample */ + +#ifndef GL_OML_subsample +#define GL_OML_subsample 1 +#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982 +#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983 +#endif /* GL_OML_subsample */ + +#ifndef GL_OVR_multiview +#define GL_OVR_multiview 1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR 0x9630 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR 0x9632 +#define GL_MAX_VIEWS_OVR 0x9631 +#define GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR 0x9633 +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint baseViewIndex, GLsizei numViews); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferTextureMultiviewOVR (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint baseViewIndex, GLsizei numViews); +#endif +#endif /* GL_OVR_multiview */ + +#ifndef GL_OVR_multiview2 +#define GL_OVR_multiview2 1 +#endif /* GL_OVR_multiview2 */ + +#ifndef GL_PGI_misc_hints +#define GL_PGI_misc_hints 1 +#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8 +#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD +#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE +#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202 +#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203 +#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204 +#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C +#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D +#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E +#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F +#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210 +#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211 +#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216 +#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217 +#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218 +#define GL_FULL_STIPPLE_HINT_PGI 0x1A219 +#define GL_CLIP_NEAR_HINT_PGI 0x1A220 +#define GL_CLIP_FAR_HINT_PGI 0x1A221 +#define GL_WIDE_LINE_HINT_PGI 0x1A222 +#define GL_BACK_NORMALS_HINT_PGI 0x1A223 +typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glHintPGI (GLenum target, GLint mode); +#endif +#endif /* GL_PGI_misc_hints */ + +#ifndef GL_PGI_vertex_hints +#define GL_PGI_vertex_hints 1 +#define GL_VERTEX_DATA_HINT_PGI 0x1A22A +#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B +#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C +#define GL_MAX_VERTEX_HINT_PGI 0x1A22D +#define GL_COLOR3_BIT_PGI 0x00010000 +#define GL_COLOR4_BIT_PGI 0x00020000 +#define GL_EDGEFLAG_BIT_PGI 0x00040000 +#define GL_INDEX_BIT_PGI 0x00080000 +#define GL_MAT_AMBIENT_BIT_PGI 0x00100000 +#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000 +#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000 +#define GL_MAT_EMISSION_BIT_PGI 0x00800000 +#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000 +#define GL_MAT_SHININESS_BIT_PGI 0x02000000 +#define GL_MAT_SPECULAR_BIT_PGI 0x04000000 +#define GL_NORMAL_BIT_PGI 0x08000000 +#define GL_TEXCOORD1_BIT_PGI 0x10000000 +#define GL_TEXCOORD2_BIT_PGI 0x20000000 +#define GL_TEXCOORD3_BIT_PGI 0x40000000 +#define GL_TEXCOORD4_BIT_PGI 0x80000000 +#define GL_VERTEX23_BIT_PGI 0x00000004 +#define GL_VERTEX4_BIT_PGI 0x00000008 +#endif /* GL_PGI_vertex_hints */ + +#ifndef GL_REND_screen_coordinates +#define GL_REND_screen_coordinates 1 +#define GL_SCREEN_COORDINATES_REND 0x8490 +#define GL_INVERTED_SCREEN_W_REND 0x8491 +#endif /* GL_REND_screen_coordinates */ + +#ifndef GL_S3_s3tc +#define GL_S3_s3tc 1 +#define GL_RGB_S3TC 0x83A0 +#define GL_RGB4_S3TC 0x83A1 +#define GL_RGBA_S3TC 0x83A2 +#define GL_RGBA4_S3TC 0x83A3 +#define GL_RGBA_DXT5_S3TC 0x83A4 +#define GL_RGBA4_DXT5_S3TC 0x83A5 +#endif /* GL_S3_s3tc */ + +#ifndef GL_SGIS_detail_texture +#define GL_SGIS_detail_texture 1 +#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095 +#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096 +#define GL_LINEAR_DETAIL_SGIS 0x8097 +#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098 +#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099 +#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A +#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B +#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C +typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum target, GLfloat *points); +#endif +#endif /* GL_SGIS_detail_texture */ + +#ifndef GL_SGIS_fog_function +#define GL_SGIS_fog_function 1 +#define GL_FOG_FUNC_SGIS 0x812A +#define GL_FOG_FUNC_POINTS_SGIS 0x812B +#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C +typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogFuncSGIS (GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *points); +#endif +#endif /* GL_SGIS_fog_function */ + +#ifndef GL_SGIS_generate_mipmap +#define GL_SGIS_generate_mipmap 1 +#define GL_GENERATE_MIPMAP_SGIS 0x8191 +#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 +#endif /* GL_SGIS_generate_mipmap */ + +#ifndef GL_SGIS_multisample +#define GL_SGIS_multisample 1 +#define GL_MULTISAMPLE_SGIS 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F +#define GL_SAMPLE_MASK_SGIS 0x80A0 +#define GL_1PASS_SGIS 0x80A1 +#define GL_2PASS_0_SGIS 0x80A2 +#define GL_2PASS_1_SGIS 0x80A3 +#define GL_4PASS_0_SGIS 0x80A4 +#define GL_4PASS_1_SGIS 0x80A5 +#define GL_4PASS_2_SGIS 0x80A6 +#define GL_4PASS_3_SGIS 0x80A7 +#define GL_SAMPLE_BUFFERS_SGIS 0x80A8 +#define GL_SAMPLES_SGIS 0x80A9 +#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA +#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB +#define GL_SAMPLE_PATTERN_SGIS 0x80AC +typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskSGIS (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glSamplePatternSGIS (GLenum pattern); +#endif +#endif /* GL_SGIS_multisample */ + +#ifndef GL_SGIS_pixel_texture +#define GL_SGIS_pixel_texture 1 +#define GL_PIXEL_TEXTURE_SGIS 0x8353 +#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354 +#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355 +#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356 +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum pname, GLint param); +GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum pname, const GLint *params); +GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum pname, GLint *params); +GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum pname, GLfloat *params); +#endif +#endif /* GL_SGIS_pixel_texture */ + +#ifndef GL_SGIS_point_line_texgen +#define GL_SGIS_point_line_texgen 1 +#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0 +#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1 +#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2 +#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3 +#define GL_EYE_POINT_SGIS 0x81F4 +#define GL_OBJECT_POINT_SGIS 0x81F5 +#define GL_EYE_LINE_SGIS 0x81F6 +#define GL_OBJECT_LINE_SGIS 0x81F7 +#endif /* GL_SGIS_point_line_texgen */ + +#ifndef GL_SGIS_point_parameters +#define GL_SGIS_point_parameters 1 +#define GL_POINT_SIZE_MIN_SGIS 0x8126 +#define GL_POINT_SIZE_MAX_SGIS 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128 +#define GL_DISTANCE_ATTENUATION_SGIS 0x8129 +typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfSGIS (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvSGIS (GLenum pname, const GLfloat *params); +#endif +#endif /* GL_SGIS_point_parameters */ + +#ifndef GL_SGIS_sharpen_texture +#define GL_SGIS_sharpen_texture 1 +#define GL_LINEAR_SHARPEN_SGIS 0x80AD +#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE +#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF +#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0 +typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum target, GLfloat *points); +#endif +#endif /* GL_SGIS_sharpen_texture */ + +#ifndef GL_SGIS_texture4D +#define GL_SGIS_texture4D 1 +#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130 +#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131 +#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132 +#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133 +#define GL_TEXTURE_4D_SGIS 0x8134 +#define GL_PROXY_TEXTURE_4D_SGIS 0x8135 +#define GL_TEXTURE_4DSIZE_SGIS 0x8136 +#define GL_TEXTURE_WRAP_Q_SGIS 0x8137 +#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138 +#define GL_TEXTURE_4D_BINDING_SGIS 0x814F +typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const void *pixels); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage4DSGIS (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const void *pixels); +GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const void *pixels); +#endif +#endif /* GL_SGIS_texture4D */ + +#ifndef GL_SGIS_texture_border_clamp +#define GL_SGIS_texture_border_clamp 1 +#define GL_CLAMP_TO_BORDER_SGIS 0x812D +#endif /* GL_SGIS_texture_border_clamp */ + +#ifndef GL_SGIS_texture_color_mask +#define GL_SGIS_texture_color_mask 1 +#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF +typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif +#endif /* GL_SGIS_texture_color_mask */ + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_SGIS_texture_edge_clamp 1 +#define GL_CLAMP_TO_EDGE_SGIS 0x812F +#endif /* GL_SGIS_texture_edge_clamp */ + +#ifndef GL_SGIS_texture_filter4 +#define GL_SGIS_texture_filter4 1 +#define GL_FILTER4_SGIS 0x8146 +#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147 +typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); +typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum target, GLenum filter, GLfloat *weights); +GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif +#endif /* GL_SGIS_texture_filter4 */ + +#ifndef GL_SGIS_texture_lod +#define GL_SGIS_texture_lod 1 +#define GL_TEXTURE_MIN_LOD_SGIS 0x813A +#define GL_TEXTURE_MAX_LOD_SGIS 0x813B +#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C +#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D +#endif /* GL_SGIS_texture_lod */ + +#ifndef GL_SGIS_texture_select +#define GL_SGIS_texture_select 1 +#define GL_DUAL_ALPHA4_SGIS 0x8110 +#define GL_DUAL_ALPHA8_SGIS 0x8111 +#define GL_DUAL_ALPHA12_SGIS 0x8112 +#define GL_DUAL_ALPHA16_SGIS 0x8113 +#define GL_DUAL_LUMINANCE4_SGIS 0x8114 +#define GL_DUAL_LUMINANCE8_SGIS 0x8115 +#define GL_DUAL_LUMINANCE12_SGIS 0x8116 +#define GL_DUAL_LUMINANCE16_SGIS 0x8117 +#define GL_DUAL_INTENSITY4_SGIS 0x8118 +#define GL_DUAL_INTENSITY8_SGIS 0x8119 +#define GL_DUAL_INTENSITY12_SGIS 0x811A +#define GL_DUAL_INTENSITY16_SGIS 0x811B +#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C +#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D +#define GL_QUAD_ALPHA4_SGIS 0x811E +#define GL_QUAD_ALPHA8_SGIS 0x811F +#define GL_QUAD_LUMINANCE4_SGIS 0x8120 +#define GL_QUAD_LUMINANCE8_SGIS 0x8121 +#define GL_QUAD_INTENSITY4_SGIS 0x8122 +#define GL_QUAD_INTENSITY8_SGIS 0x8123 +#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124 +#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125 +#endif /* GL_SGIS_texture_select */ + +#ifndef GL_SGIX_async +#define GL_SGIX_async 1 +#define GL_ASYNC_MARKER_SGIX 0x8329 +typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); +typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); +typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); +typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); +typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); +typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint marker); +GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *markerp); +GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *markerp); +GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei range); +GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint marker, GLsizei range); +GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint marker); +#endif +#endif /* GL_SGIX_async */ + +#ifndef GL_SGIX_async_histogram +#define GL_SGIX_async_histogram 1 +#define GL_ASYNC_HISTOGRAM_SGIX 0x832C +#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D +#endif /* GL_SGIX_async_histogram */ + +#ifndef GL_SGIX_async_pixel +#define GL_SGIX_async_pixel 1 +#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C +#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D +#define GL_ASYNC_READ_PIXELS_SGIX 0x835E +#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F +#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360 +#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361 +#endif /* GL_SGIX_async_pixel */ + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_SGIX_blend_alpha_minmax 1 +#define GL_ALPHA_MIN_SGIX 0x8320 +#define GL_ALPHA_MAX_SGIX 0x8321 +#endif /* GL_SGIX_blend_alpha_minmax */ + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_SGIX_calligraphic_fragment 1 +#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183 +#endif /* GL_SGIX_calligraphic_fragment */ + +#ifndef GL_SGIX_clipmap +#define GL_SGIX_clipmap 1 +#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170 +#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171 +#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172 +#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173 +#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174 +#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175 +#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176 +#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177 +#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178 +#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D +#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E +#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F +#endif /* GL_SGIX_clipmap */ + +#ifndef GL_SGIX_convolution_accuracy +#define GL_SGIX_convolution_accuracy 1 +#define GL_CONVOLUTION_HINT_SGIX 0x8316 +#endif /* GL_SGIX_convolution_accuracy */ + +#ifndef GL_SGIX_depth_pass_instrument +#define GL_SGIX_depth_pass_instrument 1 +#endif /* GL_SGIX_depth_pass_instrument */ + +#ifndef GL_SGIX_depth_texture +#define GL_SGIX_depth_texture 1 +#define GL_DEPTH_COMPONENT16_SGIX 0x81A5 +#define GL_DEPTH_COMPONENT24_SGIX 0x81A6 +#define GL_DEPTH_COMPONENT32_SGIX 0x81A7 +#endif /* GL_SGIX_depth_texture */ + +#ifndef GL_SGIX_flush_raster +#define GL_SGIX_flush_raster 1 +typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushRasterSGIX (void); +#endif +#endif /* GL_SGIX_flush_raster */ + +#ifndef GL_SGIX_fog_offset +#define GL_SGIX_fog_offset 1 +#define GL_FOG_OFFSET_SGIX 0x8198 +#define GL_FOG_OFFSET_VALUE_SGIX 0x8199 +#endif /* GL_SGIX_fog_offset */ + +#ifndef GL_SGIX_fragment_lighting +#define GL_SGIX_fragment_lighting 1 +#define GL_FRAGMENT_LIGHTING_SGIX 0x8400 +#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401 +#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402 +#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403 +#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404 +#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405 +#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406 +#define GL_LIGHT_ENV_MODE_SGIX 0x8407 +#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408 +#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409 +#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A +#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B +#define GL_FRAGMENT_LIGHT0_SGIX 0x840C +#define GL_FRAGMENT_LIGHT1_SGIX 0x840D +#define GL_FRAGMENT_LIGHT2_SGIX 0x840E +#define GL_FRAGMENT_LIGHT3_SGIX 0x840F +#define GL_FRAGMENT_LIGHT4_SGIX 0x8410 +#define GL_FRAGMENT_LIGHT5_SGIX 0x8411 +#define GL_FRAGMENT_LIGHT6_SGIX 0x8412 +#define GL_FRAGMENT_LIGHT7_SGIX 0x8413 +typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum face, GLenum mode); +GLAPI void APIENTRY glFragmentLightfSGIX (GLenum light, GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum light, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentLightiSGIX (GLenum light, GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentLightivSGIX (GLenum light, GLenum pname, const GLint *params); +GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum pname, const GLint *params); +GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum face, GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum face, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum face, GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum face, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum light, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum light, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum face, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum face, GLenum pname, GLint *params); +GLAPI void APIENTRY glLightEnviSGIX (GLenum pname, GLint param); +#endif +#endif /* GL_SGIX_fragment_lighting */ + +#ifndef GL_SGIX_framezoom +#define GL_SGIX_framezoom 1 +#define GL_FRAMEZOOM_SGIX 0x818B +#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C +#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D +typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameZoomSGIX (GLint factor); +#endif +#endif /* GL_SGIX_framezoom */ + +#ifndef GL_SGIX_igloo_interface +#define GL_SGIX_igloo_interface 1 +typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const void *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum pname, const void *params); +#endif +#endif /* GL_SGIX_igloo_interface */ + +#ifndef GL_SGIX_instruments +#define GL_SGIX_instruments 1 +#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180 +#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181 +typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); +typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); +typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); +typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); +GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei size, GLint *buffer); +GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *marker_p); +GLAPI void APIENTRY glReadInstrumentsSGIX (GLint marker); +GLAPI void APIENTRY glStartInstrumentsSGIX (void); +GLAPI void APIENTRY glStopInstrumentsSGIX (GLint marker); +#endif +#endif /* GL_SGIX_instruments */ + +#ifndef GL_SGIX_interlace +#define GL_SGIX_interlace 1 +#define GL_INTERLACE_SGIX 0x8094 +#endif /* GL_SGIX_interlace */ + +#ifndef GL_SGIX_ir_instrument1 +#define GL_SGIX_ir_instrument1 1 +#define GL_IR_INSTRUMENT1_SGIX 0x817F +#endif /* GL_SGIX_ir_instrument1 */ + +#ifndef GL_SGIX_list_priority +#define GL_SGIX_list_priority 1 +#define GL_LIST_PRIORITY_SGIX 0x8182 +typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint list, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetListParameterivSGIX (GLuint list, GLenum pname, GLint *params); +GLAPI void APIENTRY glListParameterfSGIX (GLuint list, GLenum pname, GLfloat param); +GLAPI void APIENTRY glListParameterfvSGIX (GLuint list, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glListParameteriSGIX (GLuint list, GLenum pname, GLint param); +GLAPI void APIENTRY glListParameterivSGIX (GLuint list, GLenum pname, const GLint *params); +#endif +#endif /* GL_SGIX_list_priority */ + +#ifndef GL_SGIX_pixel_texture +#define GL_SGIX_pixel_texture 1 +#define GL_PIXEL_TEX_GEN_SGIX 0x8139 +#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B +typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenSGIX (GLenum mode); +#endif +#endif /* GL_SGIX_pixel_texture */ + +#ifndef GL_SGIX_pixel_tiles +#define GL_SGIX_pixel_tiles 1 +#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E +#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F +#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140 +#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141 +#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142 +#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143 +#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144 +#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145 +#endif /* GL_SGIX_pixel_tiles */ + +#ifndef GL_SGIX_polynomial_ffd +#define GL_SGIX_polynomial_ffd 1 +#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001 +#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002 +#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194 +#define GL_TEXTURE_DEFORMATION_SGIX 0x8195 +#define GL_DEFORMATIONS_MASK_SGIX 0x8196 +#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197 +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +GLAPI void APIENTRY glDeformSGIX (GLbitfield mask); +GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield mask); +#endif +#endif /* GL_SGIX_polynomial_ffd */ + +#ifndef GL_SGIX_reference_plane +#define GL_SGIX_reference_plane 1 +#define GL_REFERENCE_PLANE_SGIX 0x817D +#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E +typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *equation); +#endif +#endif /* GL_SGIX_reference_plane */ + +#ifndef GL_SGIX_resample +#define GL_SGIX_resample 1 +#define GL_PACK_RESAMPLE_SGIX 0x842E +#define GL_UNPACK_RESAMPLE_SGIX 0x842F +#define GL_RESAMPLE_REPLICATE_SGIX 0x8433 +#define GL_RESAMPLE_ZERO_FILL_SGIX 0x8434 +#define GL_RESAMPLE_DECIMATE_SGIX 0x8430 +#endif /* GL_SGIX_resample */ + +#ifndef GL_SGIX_scalebias_hint +#define GL_SGIX_scalebias_hint 1 +#define GL_SCALEBIAS_HINT_SGIX 0x8322 +#endif /* GL_SGIX_scalebias_hint */ + +#ifndef GL_SGIX_shadow +#define GL_SGIX_shadow 1 +#define GL_TEXTURE_COMPARE_SGIX 0x819A +#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B +#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C +#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D +#endif /* GL_SGIX_shadow */ + +#ifndef GL_SGIX_shadow_ambient +#define GL_SGIX_shadow_ambient 1 +#define GL_SHADOW_AMBIENT_SGIX 0x80BF +#endif /* GL_SGIX_shadow_ambient */ + +#ifndef GL_SGIX_sprite +#define GL_SGIX_sprite 1 +#define GL_SPRITE_SGIX 0x8148 +#define GL_SPRITE_MODE_SGIX 0x8149 +#define GL_SPRITE_AXIS_SGIX 0x814A +#define GL_SPRITE_TRANSLATION_SGIX 0x814B +#define GL_SPRITE_AXIAL_SGIX 0x814C +#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D +#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum pname, GLfloat param); +GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum pname, GLint param); +GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum pname, const GLint *params); +#endif +#endif /* GL_SGIX_sprite */ + +#ifndef GL_SGIX_subsample +#define GL_SGIX_subsample 1 +#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0 +#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1 +#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2 +#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3 +#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4 +#endif /* GL_SGIX_subsample */ + +#ifndef GL_SGIX_tag_sample_buffer +#define GL_SGIX_tag_sample_buffer 1 +typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTagSampleBufferSGIX (void); +#endif +#endif /* GL_SGIX_tag_sample_buffer */ + +#ifndef GL_SGIX_texture_add_env +#define GL_SGIX_texture_add_env 1 +#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE +#endif /* GL_SGIX_texture_add_env */ + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_SGIX_texture_coordinate_clamp 1 +#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369 +#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A +#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B +#endif /* GL_SGIX_texture_coordinate_clamp */ + +#ifndef GL_SGIX_texture_lod_bias +#define GL_SGIX_texture_lod_bias 1 +#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E +#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F +#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190 +#endif /* GL_SGIX_texture_lod_bias */ + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_SGIX_texture_multi_buffer 1 +#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E +#endif /* GL_SGIX_texture_multi_buffer */ + +#ifndef GL_SGIX_texture_scale_bias +#define GL_SGIX_texture_scale_bias 1 +#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179 +#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A +#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B +#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C +#endif /* GL_SGIX_texture_scale_bias */ + +#ifndef GL_SGIX_vertex_preclip +#define GL_SGIX_vertex_preclip 1 +#define GL_VERTEX_PRECLIP_SGIX 0x83EE +#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF +#endif /* GL_SGIX_vertex_preclip */ + +#ifndef GL_SGIX_ycrcb +#define GL_SGIX_ycrcb 1 +#define GL_YCRCB_422_SGIX 0x81BB +#define GL_YCRCB_444_SGIX 0x81BC +#endif /* GL_SGIX_ycrcb */ + +#ifndef GL_SGIX_ycrcb_subsample +#define GL_SGIX_ycrcb_subsample 1 +#endif /* GL_SGIX_ycrcb_subsample */ + +#ifndef GL_SGIX_ycrcba +#define GL_SGIX_ycrcba 1 +#define GL_YCRCB_SGIX 0x8318 +#define GL_YCRCBA_SGIX 0x8319 +#endif /* GL_SGIX_ycrcba */ + +#ifndef GL_SGI_color_matrix +#define GL_SGI_color_matrix 1 +#define GL_COLOR_MATRIX_SGI 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB +#endif /* GL_SGI_color_matrix */ + +#ifndef GL_SGI_color_table +#define GL_SGI_color_table 1 +#define GL_COLOR_TABLE_SGI 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2 +#define GL_PROXY_COLOR_TABLE_SGI 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5 +#define GL_COLOR_TABLE_SCALE_SGI 0x80D6 +#define GL_COLOR_TABLE_BIAS_SGI 0x80D7 +#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8 +#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF +typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, void *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableSGI (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table); +GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glColorTableParameterivSGI (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyColorTableSGI (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glGetColorTableSGI (GLenum target, GLenum format, GLenum type, void *table); +GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum target, GLenum pname, GLint *params); +#endif +#endif /* GL_SGI_color_table */ + +#ifndef GL_SGI_texture_color_table +#define GL_SGI_texture_color_table 1 +#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC +#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD +#endif /* GL_SGI_texture_color_table */ + +#ifndef GL_SUNX_constant_data +#define GL_SUNX_constant_data 1 +#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5 +#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6 +typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFinishTextureSUNX (void); +#endif +#endif /* GL_SUNX_constant_data */ + +#ifndef GL_SUN_convolution_border_modes +#define GL_SUN_convolution_border_modes 1 +#define GL_WRAP_BORDER_SUN 0x81D4 +#endif /* GL_SUN_convolution_border_modes */ + +#ifndef GL_SUN_global_alpha +#define GL_SUN_global_alpha 1 +#define GL_GLOBAL_ALPHA_SUN 0x81D9 +#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte factor); +GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort factor); +GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint factor); +GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat factor); +GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble factor); +GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte factor); +GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort factor); +GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint factor); +#endif +#endif /* GL_SUN_global_alpha */ + +#ifndef GL_SUN_mesh_array +#define GL_SUN_mesh_array 1 +#define GL_QUAD_MESH_SUN 0x8614 +#define GL_TRIANGLE_MESH_SUN 0x8615 +typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif +#endif /* GL_SUN_mesh_array */ + +#ifndef GL_SUN_slice_accum +#define GL_SUN_slice_accum 1 +#define GL_SLICE_ACCUM_SUN 0x85CC +#endif /* GL_SUN_slice_accum */ + +#ifndef GL_SUN_triangle_list +#define GL_SUN_triangle_list 1 +#define GL_RESTART_SUN 0x0001 +#define GL_REPLACE_MIDDLE_SUN 0x0002 +#define GL_REPLACE_OLDEST_SUN 0x0003 +#define GL_TRIANGLE_LIST_SUN 0x81D7 +#define GL_REPLACEMENT_CODE_SUN 0x81D8 +#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0 +#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1 +#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2 +#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3 +#define GL_R1UI_V3F_SUN 0x85C4 +#define GL_R1UI_C4UB_V3F_SUN 0x85C5 +#define GL_R1UI_C3F_V3F_SUN 0x85C6 +#define GL_R1UI_N3F_V3F_SUN 0x85C7 +#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8 +#define GL_R1UI_T2F_V3F_SUN 0x85C9 +#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA +#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const void **pointer); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint code); +GLAPI void APIENTRY glReplacementCodeusSUN (GLushort code); +GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte code); +GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *code); +GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *code); +GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *code); +GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum type, GLsizei stride, const void **pointer); +#endif +#endif /* GL_SUN_triangle_list */ + +#ifndef GL_SUN_vertex +#define GL_SUN_vertex 1 +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *rc, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *rc, const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif +#endif /* GL_SUN_vertex */ + +#ifndef GL_WIN_phong_shading +#define GL_WIN_phong_shading 1 +#define GL_PHONG_WIN 0x80EA +#define GL_PHONG_HINT_WIN 0x80EB +#endif /* GL_WIN_phong_shading */ + +#ifndef GL_WIN_specular_fog +#define GL_WIN_specular_fog 1 +#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC +#endif /* GL_WIN_specular_fog */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/irr/test/CMakeLists.txt b/irr/test/CMakeLists.txt new file mode 100644 index 000000000..6518f69c1 --- /dev/null +++ b/irr/test/CMakeLists.txt @@ -0,0 +1,32 @@ +link_libraries(IrrlichtMt::IrrlichtMt) +add_executable(image_loader_test image_loader_test.cpp) + +function(test_image_loader format expected input) + string(TOLOWER ${format} suffix) + add_test(NAME ImageLoader${format}-${input} COMMAND image_loader_test ${expected} data/sample_${input}.${suffix} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +endfunction() + +test_image_loader(BMP 16color-16bpp 4bpp_v3) +# test_image_loader(BMP 16color-16bpp 4bpp_v7) +# test_image_loader(BMP 16color-16bpp 4bpp_v3_rle) +# test_image_loader(BMP 16color-16bpp 4bpp_v7_rle) +test_image_loader(BMP 30color-16bpp 8bpp_v3) +# test_image_loader(BMP 30color-16bpp 8bpp_v7) +test_image_loader(BMP 30color-16bpp 8bpp_v3_rle) +# test_image_loader(BMP 30color-16bpp 8bpp_v7_rle) +# test_image_loader(BMP 30color-16bpp 16bpp_v3) +# test_image_loader(BMP 30color-16bpp 16bpp_v7) +test_image_loader(BMP 30color-24bpp 24bpp_v3) +test_image_loader(BMP 30color-24bpp 24bpp_v7) + +test_image_loader(PNG 30color-24bpp 8bpp) +test_image_loader(PNG 30color-24bpp 24bpp) + +test_image_loader(TGA 30color-32bpp 8bpp_up) +test_image_loader(TGA 30color-32bpp 8bpp_down) +# test_image_loader(TGA 30color-16bpp 8bpp_rle_up) +# test_image_loader(TGA 30color-16bpp 8bpp_rle_down) +test_image_loader(TGA 30color-24bpp 24bpp_up) +test_image_loader(TGA 30color-24bpp 24bpp_down) +test_image_loader(TGA 30color-24bpp 24bpp_rle_up) +test_image_loader(TGA 30color-24bpp 24bpp_rle_down) diff --git a/irr/test/data/sample_16bpp_v3.bmp b/irr/test/data/sample_16bpp_v3.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4b6fbcf501a0fb43d42dc6ab2d6a2b67acb8a0e0 GIT binary patch literal 654 zcmZ{iF=~ZC5QaCoKmq~VEz+b)nc~4)!OkL<5*B3Om6mqy%FHdEC$SVyky^+_HZ!|f zw28}1p&$Ru|F6~O&!dXZ2lqFw7p^C+2ldQdsW1Ni`kpGj;HIs%We={y2|bQD{zEDi>Xk$h2^`XdhGq;dDQ^AUlO+ocbJxVJk@Kh{C$n3hIGLY0B+)aZ z`HZZ$;64-{ZlVW`aHUyE6cg96-pI^8EV%V#TQ5}RLanVK@uGP{&z!hkFma`UN+~j> z3AK=Af4H7wK84Tu2nSWT3YT&Ocg|7VNRmoz7cxlfz-kIEIB@&0^^&(Zfac)XK~iLP zAHZ$>#LS4$95*9+NMvMkaGC4=IH(p(J7z8_My}*EI@S`sv?9vxe z@1!`+QmDlVBY*sN|1X!XKev#cPuY8^N2zOc;by*8^p)uvh}HEo|H>Su~65W6Eb0=6saHGH#U1IikPLQQc^g z0OOi1u{dysqmLf_)Q*kjtq!nSIB}2_g`HaTW77-M5mw91s2(v}?Hv8g)n^XNf%1$q vmlP9MNE)?hsorwe%8hGHR}|A^;(4!RAS`8Un{Os_%1S!P^^(r@-vjUq7yl1M literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_24bpp.png b/irr/test/data/sample_24bpp.png new file mode 100644 index 0000000000000000000000000000000000000000..d38f5989c712b9edb7992dd8f84b78a2a962420a GIT binary patch literal 580 zcmV-K0=xZ*P);t$FE~(5E9%T9 zp8{gF0Uiu{H{aNfAR>SFUL78mO;lMkQQvsH-FeCVxTmSEyRTzHK*v(Ob(Lkea*hmi z0`$Al$^G&u5W;YDgp3K(=|&42Nz~&0TDBnVI+ThvYPu+?b?)Xp<(b8o>G6Cc2ogYJ zRVw?b`0CKsTawjYyhU@HFtM`Mk;@klxX38fA>0D~!VjsR}z+dq~9&4Dz4H3rxW zb|(zO05Ya35W*tmT~QEN1L#DB+ZSuVki+=tAoQkfq#0&d>Ky?jSq7F?&q$A%Uph7W zWNfZ@B68@;+>XeYV`QZx?Pnb1DvAVlEdO0<@44BsR zWkW?>(aG1|z% S%MUvM0000sbf}{zguo6k3 zVrRNEqJelxcKpts*>N!%4$HFP+y8QAjhQm~%b01CF*CFFZ0l!A1smjT5ZYqX?mjS4 zdGK-&Js*xAYvY@v(e?4@r2ci<{5MyS>>YV>TqD`2HR42d*G*Mh=tA<-JpMazQADV?_l? z=RuzixvQRl_{8n-RuBOZC24t}VYL%*+%ize3Fy;lnQ@;&l?Rh$(kGM$t!yFua|KD4#O&kTcrqyTj>PDrGj)4gTfY@B*h^(Wx^r{$Oy$|6VNFJ zc~5x|NDN`+tcNU-CDD$Rh!D%bV+Qc z+VAgtyzcqW2d&3^>*la|b<{jAe4muQ&MKb*AkB&$a74N87i+d~4`cVQZLSCf;_q&X z&98(NI=^cS1HC`_+~X$&Q8^Z{P1)@nBCfqI$ap|@5|-;q5)m;zcqMr>LLsBMc<3rS zzEqaTy&$s%U@#lL%UUCflBDFV-#P|Tm^6w}r`1Nlg}h-Pba0X1@lsg+M)(|C|hdKg0Sn*(jpO&kr0H7;LsG& zP|=oKOH`nh-qZJZt|u{v%N?H2`905bu1dvK_cyK*YC?(5l;e8$G1&WjI|yD5+fRk| z%~9+6xOGzeIW2#m*S;?9nwhJ5(^LwT5mzb{dVQ5!R3>yf`~Iq_r~KnN0Py7O#;vAY zR~qhMUA*rc?U$6!`J+0$?jSD~(ow4xLfaG_S*ZPz;3LinK?5+71T;*C#G!&xol$hY zN;!%!UXZ3Vm+34FV7G^{+e0y=06oVL!T$Du zF07eEqzacAb;~q?IE52BRpgnlCjdJ)aAptPJRBMVM3D$FE6w?|=`InOu+j|J>6Ely$xfZ*^qv{R z$iFGOkTD?!=6oAT$GxdSWao}eVx?gRGb&%Tkne^p;pm8U%()4QatC3T_KO~Jm+=4N Z@BUjB=a-VpsfE7CeZUl+5g^f)R2}WEH#3qo!O2k6N z&U7}SfkaJqJa_Nx7?Z+qS++TQzWdE22&RJUHxo<;vw^L|GP{pSwflCEyc`anqT$Wa z;OcmAQvW`Uzs}m9=Xd?f&iHt6lm+~kwdK9{SF6&G=L9cLyuDkC)L!?z)Yk9uTGNyX zjV+fv$cuuc9kd;&fl2E@jqO21YQzP_kQO6g((JIQt+kvnH1e{ug-E3yq$LGG7+7>9 zym;sn(iu~bO<5C{Rs^N>LTSCiW+1L)f7?byUIa{8z_EG(l_f2M)ET3q;N_A7vooco z$up&4KxJ*CfRybdXC)>ig)o5RWHmidcLbrKUJptqnN+|^ES*%lP)I?f-q7f|_=|)Q zP&U=H=te;5^&lUI^_zOoNi$GdGED(PqeiXh_ad=lqd-CliInZq)dZ}yl;tAHXGs+m pHLzTy6m(BHm#p5u=Q8=1$^K+(E9<$9{AzxAX>M~NznGg3egMO@v-AJ} literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_24bpp_v3.bmp b/irr/test/data/sample_24bpp_v3.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4684f14669f8f4a1601a63dcb70a92ed998200fe GIT binary patch literal 954 zcmaizF-yZh7=|M{>)_(<;^gQLaQDY_3w7vXTy!uMq+SLWmm*TE7!bsz(7{Q>LB-8( zE~16Dn&y1Ie91MogK~F-!jtFy-iw=Ciwj=%x52r_US=<`=e!k8&)b>zyw!Ex*$*5x zh-K|Rr}h5FQTlc~eu>6+C&|rea@PDgkH0Uvqsxckb#Ho=*)k6MFD`8D;Pc(8`s+2t z&WU|+Z&BOZfm7S&BX(=rvO<%wRmbw6EU}Yr&T4XEJ67|TS#;{f2*@HfUf8tVV`|&z zgA)zgr)6K}>cH6vrx#sIZ&KrLMGf<>1e?us|^c@{Rq zVW$d*Rh-x?)Dv&y^AcOD=4^4-ls0?UbPlVycv}_JOe%qcn6&i6f+a9x>P73lFf4_a zS*fT{3me2zQN0g{8cGTejb4`f%+w1jQ)_IbC6>Y+%lpCI)MYkT7p#rknQW1-$(h=*(ilrFt0?^MWzGI`!Tti@bg?i1 literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_24bpp_v7.bmp b/irr/test/data/sample_24bpp_v7.bmp new file mode 100644 index 0000000000000000000000000000000000000000..1fa343188bc7deadf985d9ea5d274a1363e35c11 GIT binary patch literal 1038 zcma)*J4*vW6otn}t%Z%fy+0z2m5u)-*n}vgF&1j!Mv%B$*w_S-V8nnRHh~mYA{Huk z+S!N(5;fWJyK{FZYf@;qGfW=eoO93J}ygv!mXrjQ=$Mg=ahrDDRSvnI6hS(7=e;-Xv6 zBTc7bxZK1o`B1PJrcE8R&V^iTTGY>9?N8s<=g(PF QQ8KJF@ZZB4|8v3q0IVCfB>(^b literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_4bpp_v3.bmp b/irr/test/data/sample_4bpp_v3.bmp new file mode 100644 index 0000000000000000000000000000000000000000..0cc06f3161f8e3f81cd682e77503e8d1d8b594ed GIT binary patch literal 298 zcmZ?r)na4-gEAng0mQ;U%n!tj3@kvBfnf^}3v)xT0FVvB|9jdP{Ib5hL4Z_ zGYFcccg$LI?%lfw3=D$CW)+=Kw!HAS?>BFqiwgzX!EX#??^?4j4ycA-{@dLfxAw$^ zg4iEFU%Rn;bsQgv&3HMteCMhd1_cHN1wmo6^qI5HfXq~21hOk;tpc%~{>tvoj-1L0 zV*4}5N~e}KtU3c?D~L;Hm$qtw*$mv$rl}3H)&Rv_?sD%o4Qo(Z1!B7ZotIY8x#|D| F0|4G7a;N|R literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_8bpp.png b/irr/test/data/sample_8bpp.png new file mode 100644 index 0000000000000000000000000000000000000000..c81f816f4f031b4596304b336d80942b8d598b48 GIT binary patch literal 346 zcmV-g0j2(lP)++atplo7P@c)0aK|9UknLF9QaZMnUG3b{yq`d9m91+wK&Byvx&U4-laBY@Q zRWa7FSO+(^Q&Fv0Vn|l&kxCmaynv`FY;1yv7%?D- zjgZ1h#6rc+bT*h+fMqj*L$k=ZVtMES-5c{ zBI1M$1SA{5g)5OPG-RhcHxdO$9lKI9NG{yX$KjrHE)Wmk1!MpcVzd0Eo}1BgU-ZIk zx%^qrclE}!{<^Lg&-Hpo?|sm#hvm}k^-6iM_Vjz>>3FlRw|^aM^>?-(%g*I)_d)-> z+dsPRAL(zWy}J|r{j7KMr~Gl*`+KE7dKLx3(B;Cf)?^sf8|Y!`K@taUh5I!NZ5q|H z$SZ6M5*EAMcce4WWzsMphKa!E(y=0JK+^~B4IJo{?b$`nQcP?S2QuX7(5$H} zbC4hd7X=$yV;!5Ih)t1zNo1Ks56o${eb7$tx-r2qLv9q(YbJu^6{0oHzNg#>h->?%?$RROJQbYwYTBNZN z5pg98fsiI(kt&1~CfI3bBPzH_*10*mMNawfa(LczfCT_k&<2_mG)S;3%Xa0hef_-J zcx6`yc4x`1ZQD0L?RMWDF50ax)%xw#W_AAV{@2d^*Y_j4_v6#_)uw<&hJkVK^wrWOt1~_&-QK}-$HKrnoWXD6Jc$bO7 zS9!gW#+V3#++i+91|;B+fW{aSY(WQ&<2t}lfR9Q{OtFa_FmB+Mg~%~;RT}A7qQ~1E zlLRHDbCIg3F10sqWpq%wz_Kw5i8+(K6r{ZbeHnV%o3zD%+#yRNzb3x=h>6F>G|H%-s49P7G`?0(+}Yva>r}H literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_8bpp_up.tga b/irr/test/data/sample_8bpp_up.tga new file mode 100644 index 0000000000000000000000000000000000000000..a314e8689590abe043c1c5a60eb908aa77de8fe6 GIT binary patch literal 419 zcmYk(Jxjwt7zgmn`=yukl3bH(lB?f9zeRB!|fM`3oxD*kwVnGlW zp@Wl%gNmEoTttOdZF62y2mj-b-LhEb_hUWc%}NH+k6~JkdF*CipXMUR(|*(=?A2lot`VtS7s_xlcNjcm5K5g_yu3qUMc_p literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_8bpp_v3.bmp b/irr/test/data/sample_8bpp_v3.bmp new file mode 100644 index 0000000000000000000000000000000000000000..a890e64655127621d12b5418e1799341e990ad14 GIT binary patch literal 474 zcmYk2y)Oh&6vfYczwu^wzIOJRomq`WA^r%xKSn1MDjEtOiLeTdMg*}!A`y*5p%PIb zIy#LYvDlsGzFCEvoSVE~PTsxej!%r~C~Kek2q`A{Bn^x@FscE=V|@+LTS?ANla?SC zW>BooL(ZK*Zcafiw;&hqAzN+8gGtEs3lu9KcwH;-w9&)EW)D|eUC5nVoNafpyYqvh z{fxbnZ^-jc9A18*dns{r)4}Jp#PMAR?~esepF4PakuXh%dzGpmMz#82UY24C`u`xb zrs-rntE6E<#vo_R28cCzRuy3q)fCHf#j=d2LikA(*9UTD=g^x3dFly2j-!AzZ1U+% z%}gCGD%CiQB4WA$OV_l&(P0?X>kaZ*1~j!J@9$V^G;+9BmYO0-cpUg4v+Y5}GBOG? z=0Sz|b{U441uap`BW9={6*EB0VV>>VWoo#t5J=*{8DL)3uq+Bg%yo4dU0$Mp9{d7t CQCp}0 literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_8bpp_v3_rle.bmp b/irr/test/data/sample_8bpp_v3_rle.bmp new file mode 100644 index 0000000000000000000000000000000000000000..d460d0fd66c87c67af2e4d3f302a7a44b1bdec51 GIT binary patch literal 524 zcmXw$y-wUf6orqy{u!@-#`dgtc6Zh^X{dOJ^mzruE2N7^k%}}>Btb%CDbmm&1SlYo zkWiXP6saOa0Z}^WXi$R0CfW7mj=hX@Mw(A&=AL`!`HLkR_1dR>o+L<|WPy=@McSS% zG@7Hck$$sGdI!Dw8rAw+=#>-btyj?RN6>56(4#}>gO|{oUr~K{!2L#rn~zic*qY+o zrwR1VCC;`d*xmVu>hKnOCx4;8JmT~DA56|QjxNS{{H}3)HOB9s6;5x*_;sg&*m3+Y ziW8pYoo)}_kisOy4CD=T4HH)B_$pL!KP$+X4jJo<;DI0h*zg=2R-w$P+h%C>E+pYQ?*S4%#oGi<`-NDT7wqTj; zVUxWx7&LVQSM?oP6ro6Y#yqe0#1&nTjtJA3anCe6^D7rtVR%HmWh&Hl14R{x`z-Rf i*G$Ls6$DbE5UJm0QPOfTpr5#bFeY=>{xa(`Kc^Flsbf zlxG>x)E)Wsj`db6hihf2DUyW8fgdv4ZYs+tQJ66gs?4{`X2>jPi87DOP=8crfXrc@ g?b~J7a9tsg#DP;`Ud^y9YKF{pbt+xH#PoUa1n?(co&W#< literal 0 HcmV?d00001 diff --git a/irr/test/data/sample_8bpp_v7_rle.bmp b/irr/test/data/sample_8bpp_v7_rle.bmp new file mode 100644 index 0000000000000000000000000000000000000000..d197b09a615ea5b00dc78ab57a7f2dc44d43fed9 GIT binary patch literal 608 zcmb7?KTi}v7{;I7+ds4HpV{5Hz2RHbhLQppgPFF$x6@4Kc)c zMiLTZV?tqNj0F-p>1Yg)aKf?UJG%=#lX)jIzdSSV^S+sx$8$F7VOzjU+6f9yVS!Nq zPicAhsEG%3HUa3{S)XQRpFFQO_gLDrcQ^Fn3+TmF=vNDul$DI z7(st{2L1LMs`U%}eN*AjyBi#B-r)Pz1bXKezHCqMe&-t1=mfiaSI}QC@$ujvCI=dy zevWbZL*w(|80W_o_D{w*JEb~e$MM4`PI#7gd(-fSWGNwLAa9^+n6OI6SD}jgSwX^d z$e3r`3lJ|umB_5fyM_;qyyi-UeJOd7i{8|b)lWm%W$6%)Bo`u2*}!Y{c4;|%Ka_DI zvOFhlcj|Xs+p=0aS(f*DgI4c$U>WaWc1X7|9sXxV{q~p3&G+`$Ix5-f5x2Bo& GiT(q@QD6!H literal 0 HcmV?d00001 diff --git a/irr/test/image_loader_test.cpp b/irr/test/image_loader_test.cpp new file mode 100644 index 000000000..1dd4888f2 --- /dev/null +++ b/irr/test/image_loader_test.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include +#include + +using namespace irr; + +struct ImageDesc +{ + const char *name; + video::ECOLOR_FORMAT format; + std::vector data; +}; + +template +std::vector to_byte_array(std::initializer_list in_data) +{ + std::vector data; + data.resize(sizeof(T) * in_data.size()); + memcpy(data.data(), in_data.begin(), data.size()); + return data; +} + +static const ImageDesc test_images[] = { + {"16color-16bpp", video::ECF_A1R5G5B5, to_byte_array({ + 0xb6df, 0xb6df, 0xb6df, 0xb6df, 0xc23f, 0xc23f, 0xd61f, 0xd61f, 0xea3f, 0xea3f, 0xfe5e, 0xfe5e, 0xfe7c, 0xfe7a, 0xfe7a, 0xfe97, 0xfeb5, 0xfeb5, 0xff16, + 0xb6df, 0xb6df, 0xff3f, 0xff3f, 0xc23f, 0xf2df, 0xf2df, 0xf2df, 0xea3f, 0xda7f, 0xda7f, 0xfe5e, 0xfe7a, 0xc23f, 0xbe7f, 0xbe7f, 0xfeb5, 0xfeb5, 0xfb76, + 0xb6df, 0xff9e, 0xc23f, 0xc23f, 0xc23f, 0xf2df, 0xd61f, 0xf2df, 0xea3f, 0xda7f, 0xfe5e, 0xda7f, 0xfe7a, 0xc23f, 0xfe97, 0xfeb5, 0xfeb5, 0xff16, 0xfb76, + 0xb6df, 0xff9e, 0xbe7f, 0xc23f, 0xd61f, 0xfe7c, 0xd61f, 0xf2df, 0xfe5e, 0xf2df, 0xfe7c, 0xda7f, 0xfe7a, 0xda7f, 0xbe7f, 0xfeb5, 0xff16, 0xff16, 0xfb76, + 0xb6df, 0xff9e, 0xc23f, 0xc23f, 0xd61f, 0xff3f, 0xd61f, 0xf2df, 0xfe5e, 0xda7f, 0xfe7c, 0xda7f, 0xfe7a, 0xc23f, 0xfeb5, 0xfeb5, 0xff16, 0xff16, 0xfb76, + 0xb6df, 0xbe7f, 0xff9e, 0xff3f, 0xd61f, 0xff3f, 0xf2df, 0xf2df, 0xfe5e, 0xf2df, 0xda7f, 0xfe97, 0xfe97, 0xda7f, 0xc23f, 0xda7f, 0xfb76, 0xfb76, 0xfb76, + 0xbe7f, 0xc23f, 0xc23f, 0xd61f, 0xd61f, 0xea3f, 0xea3f, 0xfe5e, 0xfe5e, 0xfe7c, 0xfe7c, 0xfe7a, 0xfe97, 0xfeb5, 0xfeb5, 0xfeb5, 0xfb76, 0xfb76, 0xfb76, + 0xbe7f, 0xc23f, 0xd61f, 0xd61f, 0xd61f, 0xea3f, 0xea3f, 0xfe5e, 0xfe5e, 0xfe7c, 0xfe97, 0xfe97, 0xfe97, 0xfeb5, 0xff16, 0xff16, 0xfb76, 0xfb76, 0xfb76, + 0xc23f, 0xff9e, 0xc23f, 0xd61f, 0xff3f, 0xea3f, 0xfe5e, 0xff3f, 0xfe7c, 0xfe7c, 0xf2df, 0xfe97, 0xfeb5, 0xfeb5, 0xda7f, 0xff16, 0xc23f, 0xc23f, 0xbe7f, + 0xc23f, 0xff9e, 0xff9e, 0xd61f, 0xff9e, 0xea3f, 0xff3f, 0xfe5e, 0xff3f, 0xfe7a, 0xf2df, 0xf2df, 0xfeb5, 0xf2df, 0xda7f, 0xfb76, 0xc23f, 0xfb76, 0xfb76, + 0xc23f, 0xff9e, 0xd61f, 0xff9e, 0xff9e, 0xfe5e, 0xff3f, 0xff3f, 0xff3f, 0xfe7a, 0xff3f, 0xfeb5, 0xf2df, 0xff16, 0xda7f, 0xfb76, 0xda7f, 0xda7f, 0xfb76, + 0xc23f, 0xff9e, 0xea3f, 0xea3f, 0xff9e, 0xfe5e, 0xff9e, 0xfe7c, 0xff3f, 0xfe97, 0xf2df, 0xfeb5, 0xfeb5, 0xff16, 0xf2df, 0xfb76, 0xda7f, 0xfb76, 0xfb76, + 0xd61f, 0xff9e, 0xd61f, 0xea3f, 0xff9e, 0xfe5e, 0xff9e, 0xfe7c, 0xff3f, 0xfe97, 0xff3f, 0xfeb5, 0xff16, 0xfb76, 0xda7f, 0xfb76, 0xda7f, 0xda7f, 0xc23f, + 0xd61f, 0xd61f, 0xea3f, 0xea3f, 0xea3f, 0xfe5e, 0xfe7c, 0xfe7a, 0xfe7a, 0xfe97, 0xfeb5, 0xff16, 0xff16, 0xfb76, 0xfb76, 0xfb76, 0xfb76, 0xfb76, 0xfb76, + 0xd61f, 0xd61f, 0xea3f, 0xfe5e, 0xfe5e, 0xfe7c, 0xfe7a, 0xfe7a, 0xfe97, 0xfeb5, 0xfeb5, 0xff16, 0xff16, 0xfb76, 0xfb76, 0xfb76, 0xfb76, 0xfb76, 0xfb76, + })}, + + {"30color-16bpp", video::ECF_A1R5G5B5, to_byte_array({ + 0xbabf, 0xbabf, 0xbabf, 0xbabf, 0xbe3f, 0xbdff, 0xc9ff, 0xda1f, 0xee3f, 0xee3f, 0xfa5f, 0xfe5e, 0xfe7c, 0xfe7b, 0xfe79, 0xfe97, 0xfeb5, 0xfed5, 0xff16, + 0xbabf, 0xbabf, 0xff1f, 0xff1f, 0xbdff, 0xfaff, 0xf2df, 0xeabf, 0xee3f, 0xe27f, 0xda7f, 0xfe5e, 0xfe7b, 0xc25f, 0xbe7f, 0xbe7f, 0xfeb5, 0xfed5, 0xff56, + 0xbabf, 0xff7e, 0xbe7f, 0xc25f, 0xbdff, 0xfaff, 0xda1f, 0xf2df, 0xee3f, 0xda7f, 0xfe5e, 0xce5f, 0xfe79, 0xce5f, 0xfe97, 0xfeb5, 0xfed5, 0xff16, 0xff56, + 0xbabf, 0xff7e, 0xbe7f, 0xbdff, 0xc9ff, 0xfaff, 0xda1f, 0xf2df, 0xfa5f, 0xeabf, 0xfe5e, 0xda7f, 0xfe79, 0xce5f, 0xc25f, 0xfeb5, 0xff16, 0xff16, 0xff76, + 0xbabf, 0xff7e, 0xc25f, 0xbdff, 0xc9ff, 0xff1f, 0xda1f, 0xf2df, 0xfa5f, 0xeabf, 0xfe7c, 0xda7f, 0xfe79, 0xce5f, 0xfeb5, 0xfed5, 0xff16, 0xff56, 0xff97, + 0xbabf, 0xbe7f, 0xff7e, 0xff5e, 0xda1f, 0xff1f, 0xfaff, 0xfaff, 0xfa5f, 0xf2df, 0xeabf, 0xfe79, 0xfe97, 0xda7f, 0xce5f, 0xce5f, 0xff56, 0xff76, 0xff97, + 0xbe7f, 0xc25f, 0xbdff, 0xc9ff, 0xda1f, 0xda1f, 0xee3f, 0xfa5f, 0xfa5f, 0xfe7c, 0xfe7b, 0xfe79, 0xfe97, 0xfeb5, 0xfed5, 0xfed5, 0xff76, 0xff76, 0xff97, + 0xbe7f, 0xbe3f, 0xc9ff, 0xc9ff, 0xda1f, 0xee3f, 0xee3f, 0xfa5f, 0xfe5e, 0xfe7c, 0xfe79, 0xfe97, 0xfe97, 0xfeb5, 0xff16, 0xff16, 0xff76, 0xff97, 0xff97, + 0xbe3f, 0xffbe, 0xc9ff, 0xda1f, 0xff5e, 0xee3f, 0xfa5f, 0xff1f, 0xfe7c, 0xfe7b, 0xf2df, 0xfe97, 0xfeb5, 0xfeb5, 0xda7f, 0xff76, 0xce5f, 0xbe3f, 0xc25f, + 0xbe3f, 0xffbe, 0xffbe, 0xda1f, 0xff7e, 0xfa5f, 0xff5e, 0xfe5e, 0xff1f, 0xfe79, 0xf2df, 0xf2df, 0xfeb5, 0xeabf, 0xda7f, 0xff76, 0xce5f, 0xff97, 0xff97, + 0xbdff, 0xffbe, 0xda1f, 0xff7e, 0xff7e, 0xfa5f, 0xff5e, 0xff1f, 0xff1f, 0xfe79, 0xfaff, 0xfeb5, 0xf2df, 0xff16, 0xe27f, 0xff97, 0xda7f, 0xce5f, 0xff97, + 0xbdff, 0xffbe, 0xda1f, 0xee3f, 0xffbe, 0xfa5f, 0xff7e, 0xfe7b, 0xff1f, 0xfe97, 0xfaff, 0xfeb5, 0xfed5, 0xff56, 0xeabf, 0xff97, 0xda7f, 0xff97, 0xff97, + 0xc9ff, 0xffbe, 0xda1f, 0xee3f, 0xff7e, 0xfa5f, 0xff7e, 0xfe7c, 0xff5e, 0xfe97, 0xfaff, 0xfed5, 0xff16, 0xff56, 0xeabf, 0xff97, 0xda7f, 0xda7f, 0xce5f, + 0xda1f, 0xda1f, 0xee3f, 0xee3f, 0xfa5f, 0xfe5e, 0xfe7c, 0xfe79, 0xfe79, 0xfe97, 0xfeb5, 0xfed5, 0xff16, 0xff56, 0xff97, 0xff97, 0xff97, 0xff97, 0xff97, + 0xda1f, 0xda1f, 0xee3f, 0xfa5f, 0xfe5e, 0xfe7c, 0xfe7b, 0xfe79, 0xfe97, 0xfeb5, 0xfed5, 0xff16, 0xff56, 0xff97, 0xff97, 0xff97, 0xff97, 0xff97, 0xff97, + })}, + + {"30color-24bpp", video::ECF_R8G8B8, { + 0x71, 0xaf, 0xff, 0x71, 0xaf, 0xff, 0x71, 0xaf, 0xff, 0x71, 0xaf, 0xff, 0x7b, 0x8b, 0xff, 0x7a, 0x7f, 0xff, 0x90, 0x7f, 0xff, 0xb6, 0x85, 0xff, 0xd9, 0x8c, 0xff, 0xd9, 0x8c, 0xff, 0xf4, 0x92, 0xfe, 0xfe, 0x96, 0xf0, 0xfd, 0x99, 0xe3, 0xfd, 0x9b, 0xda, 0xfc, 0x9f, 0xca, 0xfc, 0xa4, 0xbc, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xf9, 0xc6, 0xb1, + 0x71, 0xaf, 0xff, 0x71, 0xaf, 0xff, 0xff, 0xc6, 0xfc, 0xff, 0xc6, 0xfc, 0x7a, 0x7f, 0xff, 0xf7, 0xbe, 0xff, 0xe4, 0xb2, 0xfe, 0xd4, 0xa9, 0xff, 0xd9, 0x8c, 0xff, 0xc3, 0x98, 0xff, 0xb2, 0x9a, 0xff, 0xfe, 0x96, 0xf0, 0xfd, 0x9b, 0xda, 0x86, 0x93, 0xfe, 0x78, 0x9b, 0xff, 0x78, 0x9b, 0xff, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xf8, 0xd2, 0xb3, + 0x71, 0xaf, 0xff, 0xfe, 0xdc, 0xf3, 0x78, 0x9b, 0xff, 0x86, 0x93, 0xfe, 0x7a, 0x7f, 0xff, 0xf7, 0xbe, 0xff, 0xb6, 0x85, 0xff, 0xe4, 0xb2, 0xfe, 0xd9, 0x8c, 0xff, 0xb2, 0x9a, 0xff, 0xfe, 0x96, 0xf0, 0x9a, 0x91, 0xff, 0xfc, 0x9f, 0xca, 0x9a, 0x91, 0xff, 0xfc, 0xa4, 0xbc, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xf9, 0xc6, 0xb1, 0xf8, 0xd2, 0xb3, + 0x71, 0xaf, 0xff, 0xfe, 0xdc, 0xf3, 0x78, 0x9b, 0xff, 0x7a, 0x7f, 0xff, 0x90, 0x7f, 0xff, 0xf7, 0xbe, 0xff, 0xb6, 0x85, 0xff, 0xe4, 0xb2, 0xfe, 0xf4, 0x92, 0xfe, 0xd4, 0xa9, 0xff, 0xfe, 0x96, 0xf0, 0xb2, 0x9a, 0xff, 0xfc, 0x9f, 0xca, 0x9a, 0x91, 0xff, 0x86, 0x93, 0xfe, 0xfb, 0xa9, 0xab, 0xf9, 0xc6, 0xb1, 0xf9, 0xc6, 0xb1, 0xf8, 0xd8, 0xb5, + 0x71, 0xaf, 0xff, 0xfe, 0xdc, 0xf3, 0x86, 0x93, 0xfe, 0x7a, 0x7f, 0xff, 0x90, 0x7f, 0xff, 0xff, 0xc6, 0xfc, 0xb6, 0x85, 0xff, 0xe4, 0xb2, 0xfe, 0xf4, 0x92, 0xfe, 0xd4, 0xa9, 0xff, 0xfd, 0x99, 0xe3, 0xb2, 0x9a, 0xff, 0xfc, 0x9f, 0xca, 0x9a, 0x91, 0xff, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xf9, 0xc6, 0xb1, 0xf8, 0xd2, 0xb3, 0xf8, 0xe4, 0xb9, + 0x71, 0xaf, 0xff, 0x78, 0x9b, 0xff, 0xfe, 0xdc, 0xf3, 0xff, 0xd0, 0xf7, 0xb6, 0x85, 0xff, 0xff, 0xc6, 0xfc, 0xf7, 0xbe, 0xff, 0xf7, 0xbe, 0xff, 0xf4, 0x92, 0xfe, 0xe4, 0xb2, 0xfe, 0xd4, 0xa9, 0xff, 0xfc, 0x9f, 0xca, 0xfc, 0xa4, 0xbc, 0xb2, 0x9a, 0xff, 0x9a, 0x91, 0xff, 0x9a, 0x91, 0xff, 0xf8, 0xd2, 0xb3, 0xf8, 0xd8, 0xb5, 0xf8, 0xe4, 0xb9, + 0x78, 0x9b, 0xff, 0x86, 0x93, 0xfe, 0x7a, 0x7f, 0xff, 0x90, 0x7f, 0xff, 0xb6, 0x85, 0xff, 0xb6, 0x85, 0xff, 0xd9, 0x8c, 0xff, 0xf4, 0x92, 0xfe, 0xf4, 0x92, 0xfe, 0xfd, 0x99, 0xe3, 0xfd, 0x9b, 0xda, 0xfc, 0x9f, 0xca, 0xfc, 0xa4, 0xbc, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xfa, 0xb6, 0xad, 0xf8, 0xd8, 0xb5, 0xf8, 0xd8, 0xb5, 0xf8, 0xe4, 0xb9, + 0x78, 0x9b, 0xff, 0x7b, 0x8b, 0xff, 0x90, 0x7f, 0xff, 0x90, 0x7f, 0xff, 0xb6, 0x85, 0xff, 0xd9, 0x8c, 0xff, 0xd9, 0x8c, 0xff, 0xf4, 0x92, 0xfe, 0xfe, 0x96, 0xf0, 0xfd, 0x99, 0xe3, 0xfc, 0x9f, 0xca, 0xfc, 0xa4, 0xbc, 0xfc, 0xa4, 0xbc, 0xfb, 0xa9, 0xab, 0xf9, 0xc6, 0xb1, 0xf9, 0xc6, 0xb1, 0xf8, 0xd8, 0xb5, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, + 0x7b, 0x8b, 0xff, 0xff, 0xeb, 0xf2, 0x90, 0x7f, 0xff, 0xb6, 0x85, 0xff, 0xff, 0xd0, 0xf7, 0xd9, 0x8c, 0xff, 0xf4, 0x92, 0xfe, 0xff, 0xc6, 0xfc, 0xfd, 0x99, 0xe3, 0xfd, 0x9b, 0xda, 0xe4, 0xb2, 0xfe, 0xfc, 0xa4, 0xbc, 0xfb, 0xa9, 0xab, 0xfb, 0xa9, 0xab, 0xb2, 0x9a, 0xff, 0xf8, 0xd8, 0xb5, 0x9a, 0x91, 0xff, 0x7b, 0x8b, 0xff, 0x86, 0x93, 0xfe, + 0x7b, 0x8b, 0xff, 0xff, 0xeb, 0xf2, 0xff, 0xeb, 0xf2, 0xb6, 0x85, 0xff, 0xfe, 0xdc, 0xf3, 0xf4, 0x92, 0xfe, 0xff, 0xd0, 0xf7, 0xfe, 0x96, 0xf0, 0xff, 0xc6, 0xfc, 0xfc, 0x9f, 0xca, 0xe4, 0xb2, 0xfe, 0xe4, 0xb2, 0xfe, 0xfb, 0xa9, 0xab, 0xd4, 0xa9, 0xff, 0xb2, 0x9a, 0xff, 0xf8, 0xd8, 0xb5, 0x9a, 0x91, 0xff, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, + 0x7a, 0x7f, 0xff, 0xff, 0xeb, 0xf2, 0xb6, 0x85, 0xff, 0xfe, 0xdc, 0xf3, 0xfe, 0xdc, 0xf3, 0xf4, 0x92, 0xfe, 0xff, 0xd0, 0xf7, 0xff, 0xc6, 0xfc, 0xff, 0xc6, 0xfc, 0xfc, 0x9f, 0xca, 0xf7, 0xbe, 0xff, 0xfb, 0xa9, 0xab, 0xe4, 0xb2, 0xfe, 0xf9, 0xc6, 0xb1, 0xc3, 0x98, 0xff, 0xf8, 0xe4, 0xb9, 0xb2, 0x9a, 0xff, 0x9a, 0x91, 0xff, 0xf8, 0xe4, 0xb9, + 0x7a, 0x7f, 0xff, 0xff, 0xeb, 0xf2, 0xb6, 0x85, 0xff, 0xd9, 0x8c, 0xff, 0xff, 0xeb, 0xf2, 0xf4, 0x92, 0xfe, 0xfe, 0xdc, 0xf3, 0xfd, 0x9b, 0xda, 0xff, 0xc6, 0xfc, 0xfc, 0xa4, 0xbc, 0xf7, 0xbe, 0xff, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xf8, 0xd2, 0xb3, 0xd4, 0xa9, 0xff, 0xf8, 0xe4, 0xb9, 0xb2, 0x9a, 0xff, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, + 0x90, 0x7f, 0xff, 0xff, 0xeb, 0xf2, 0xb6, 0x85, 0xff, 0xd9, 0x8c, 0xff, 0xfe, 0xdc, 0xf3, 0xf4, 0x92, 0xfe, 0xfe, 0xdc, 0xf3, 0xfd, 0x99, 0xe3, 0xff, 0xd0, 0xf7, 0xfc, 0xa4, 0xbc, 0xf7, 0xbe, 0xff, 0xfa, 0xb6, 0xad, 0xf9, 0xc6, 0xb1, 0xf8, 0xd2, 0xb3, 0xd4, 0xa9, 0xff, 0xf8, 0xe4, 0xb9, 0xb2, 0x9a, 0xff, 0xb2, 0x9a, 0xff, 0x9a, 0x91, 0xff, + 0xb6, 0x85, 0xff, 0xb6, 0x85, 0xff, 0xd9, 0x8c, 0xff, 0xd9, 0x8c, 0xff, 0xf4, 0x92, 0xfe, 0xfe, 0x96, 0xf0, 0xfd, 0x99, 0xe3, 0xfc, 0x9f, 0xca, 0xfc, 0x9f, 0xca, 0xfc, 0xa4, 0xbc, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xf9, 0xc6, 0xb1, 0xf8, 0xd2, 0xb3, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, + 0xb6, 0x85, 0xff, 0xb6, 0x85, 0xff, 0xd9, 0x8c, 0xff, 0xf4, 0x92, 0xfe, 0xfe, 0x96, 0xf0, 0xfd, 0x99, 0xe3, 0xfd, 0x9b, 0xda, 0xfc, 0x9f, 0xca, 0xfc, 0xa4, 0xbc, 0xfb, 0xa9, 0xab, 0xfa, 0xb6, 0xad, 0xf9, 0xc6, 0xb1, 0xf8, 0xd2, 0xb3, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, 0xf8, 0xe4, 0xb9, + }}, + + {"30color-32bpp", video::ECF_A8R8G8B8, to_byte_array({ + 0xff71afff, 0xff71afff, 0xff71afff, 0xff71afff, 0xff7b8bff, 0xff7a7fff, 0xff907fff, 0xffb685ff, 0xffd98cff, 0xffd98cff, 0xfff492fe, 0xfffe96f0, 0xfffd99e3, 0xfffd9bda, 0xfffc9fca, 0xfffca4bc, 0xfffba9ab, 0xfffab6ad, 0xfff9c6b1, + 0xff71afff, 0xff71afff, 0xffffc6fc, 0xffffc6fc, 0xff7a7fff, 0xfff7beff, 0xffe4b2fe, 0xffd4a9ff, 0xffd98cff, 0xffc398ff, 0xffb29aff, 0xfffe96f0, 0xfffd9bda, 0xff8693fe, 0xff789bff, 0xff789bff, 0xfffba9ab, 0xfffab6ad, 0xfff8d2b3, + 0xff71afff, 0xfffedcf3, 0xff789bff, 0xff8693fe, 0xff7a7fff, 0xfff7beff, 0xffb685ff, 0xffe4b2fe, 0xffd98cff, 0xffb29aff, 0xfffe96f0, 0xff9a91ff, 0xfffc9fca, 0xff9a91ff, 0xfffca4bc, 0xfffba9ab, 0xfffab6ad, 0xfff9c6b1, 0xfff8d2b3, + 0xff71afff, 0xfffedcf3, 0xff789bff, 0xff7a7fff, 0xff907fff, 0xfff7beff, 0xffb685ff, 0xffe4b2fe, 0xfff492fe, 0xffd4a9ff, 0xfffe96f0, 0xffb29aff, 0xfffc9fca, 0xff9a91ff, 0xff8693fe, 0xfffba9ab, 0xfff9c6b1, 0xfff9c6b1, 0xfff8d8b5, + 0xff71afff, 0xfffedcf3, 0xff8693fe, 0xff7a7fff, 0xff907fff, 0xffffc6fc, 0xffb685ff, 0xffe4b2fe, 0xfff492fe, 0xffd4a9ff, 0xfffd99e3, 0xffb29aff, 0xfffc9fca, 0xff9a91ff, 0xfffba9ab, 0xfffab6ad, 0xfff9c6b1, 0xfff8d2b3, 0xfff8e4b9, + 0xff71afff, 0xff789bff, 0xfffedcf3, 0xffffd0f7, 0xffb685ff, 0xffffc6fc, 0xfff7beff, 0xfff7beff, 0xfff492fe, 0xffe4b2fe, 0xffd4a9ff, 0xfffc9fca, 0xfffca4bc, 0xffb29aff, 0xff9a91ff, 0xff9a91ff, 0xfff8d2b3, 0xfff8d8b5, 0xfff8e4b9, + 0xff789bff, 0xff8693fe, 0xff7a7fff, 0xff907fff, 0xffb685ff, 0xffb685ff, 0xffd98cff, 0xfff492fe, 0xfff492fe, 0xfffd99e3, 0xfffd9bda, 0xfffc9fca, 0xfffca4bc, 0xfffba9ab, 0xfffab6ad, 0xfffab6ad, 0xfff8d8b5, 0xfff8d8b5, 0xfff8e4b9, + 0xff789bff, 0xff7b8bff, 0xff907fff, 0xff907fff, 0xffb685ff, 0xffd98cff, 0xffd98cff, 0xfff492fe, 0xfffe96f0, 0xfffd99e3, 0xfffc9fca, 0xfffca4bc, 0xfffca4bc, 0xfffba9ab, 0xfff9c6b1, 0xfff9c6b1, 0xfff8d8b5, 0xfff8e4b9, 0xfff8e4b9, + 0xff7b8bff, 0xffffebf2, 0xff907fff, 0xffb685ff, 0xffffd0f7, 0xffd98cff, 0xfff492fe, 0xffffc6fc, 0xfffd99e3, 0xfffd9bda, 0xffe4b2fe, 0xfffca4bc, 0xfffba9ab, 0xfffba9ab, 0xffb29aff, 0xfff8d8b5, 0xff9a91ff, 0xff7b8bff, 0xff8693fe, + 0xff7b8bff, 0xffffebf2, 0xffffebf2, 0xffb685ff, 0xfffedcf3, 0xfff492fe, 0xffffd0f7, 0xfffe96f0, 0xffffc6fc, 0xfffc9fca, 0xffe4b2fe, 0xffe4b2fe, 0xfffba9ab, 0xffd4a9ff, 0xffb29aff, 0xfff8d8b5, 0xff9a91ff, 0xfff8e4b9, 0xfff8e4b9, + 0xff7a7fff, 0xffffebf2, 0xffb685ff, 0xfffedcf3, 0xfffedcf3, 0xfff492fe, 0xffffd0f7, 0xffffc6fc, 0xffffc6fc, 0xfffc9fca, 0xfff7beff, 0xfffba9ab, 0xffe4b2fe, 0xfff9c6b1, 0xffc398ff, 0xfff8e4b9, 0xffb29aff, 0xff9a91ff, 0xfff8e4b9, + 0xff7a7fff, 0xffffebf2, 0xffb685ff, 0xffd98cff, 0xffffebf2, 0xfff492fe, 0xfffedcf3, 0xfffd9bda, 0xffffc6fc, 0xfffca4bc, 0xfff7beff, 0xfffba9ab, 0xfffab6ad, 0xfff8d2b3, 0xffd4a9ff, 0xfff8e4b9, 0xffb29aff, 0xfff8e4b9, 0xfff8e4b9, + 0xff907fff, 0xffffebf2, 0xffb685ff, 0xffd98cff, 0xfffedcf3, 0xfff492fe, 0xfffedcf3, 0xfffd99e3, 0xffffd0f7, 0xfffca4bc, 0xfff7beff, 0xfffab6ad, 0xfff9c6b1, 0xfff8d2b3, 0xffd4a9ff, 0xfff8e4b9, 0xffb29aff, 0xffb29aff, 0xff9a91ff, + 0xffb685ff, 0xffb685ff, 0xffd98cff, 0xffd98cff, 0xfff492fe, 0xfffe96f0, 0xfffd99e3, 0xfffc9fca, 0xfffc9fca, 0xfffca4bc, 0xfffba9ab, 0xfffab6ad, 0xfff9c6b1, 0xfff8d2b3, 0xfff8e4b9, 0xfff8e4b9, 0xfff8e4b9, 0xfff8e4b9, 0xfff8e4b9, + 0xffb685ff, 0xffb685ff, 0xffd98cff, 0xfff492fe, 0xfffe96f0, 0xfffd99e3, 0xfffd9bda, 0xfffc9fca, 0xfffca4bc, 0xfffba9ab, 0xfffab6ad, 0xfff9c6b1, 0xfff8d2b3, 0xfff8e4b9, 0xfff8e4b9, 0xfff8e4b9, 0xfff8e4b9, 0xfff8e4b9, 0xfff8e4b9, + })}, + +}; + +void printImageBytes(const video::IImage *img) +{ + const auto *data = (u8 *)img->getData(); + const auto w = img->getPitch(); + const auto h = img->getDimension().Height; + for (int y = 0; y < h; y++) { + for (int k = 0; k < w; k++) { + std::printf("0x%02x, ", *data++); + } + std::printf("\n"); + } +} + +int main(int argc, char *argv[]) +try { + if (argc != 3) + throw std::runtime_error("Invalid arguments. Expected sample ID and image file name"); + + const ImageDesc *sample = nullptr; + for (auto &&image : test_images) { + if (strcmp(argv[1], image.name) == 0) + sample = ℑ + } + if (!sample) + throw std::runtime_error("Sample not found"); + + SIrrlichtCreationParameters p; + p.DriverType = video::EDT_NULL; + p.WindowSize = core::dimension2du(640, 480); + p.LoggingLevel = ELL_DEBUG; + + auto *device = createDeviceEx(p); + if (!device) + throw std::runtime_error("Failed to create device"); + + auto *driver = device->getVideoDriver(); + + auto *img = driver->createImageFromFile(argv[2]); + if (!img) + throw std::runtime_error("Failed to load image"); + + if (img->getDimension() != core::dimension2du{19, 15}) + throw std::runtime_error("Wrong image dimensions"); + + if (img->getColorFormat() != sample->format) + throw std::runtime_error("Wrong image format"); + + if (img->getImageDataSizeInBytes() != sample->data.size()) + throw std::logic_error("Image data size not equal to sample size"); + + if (memcmp(img->getData(), sample->data.data(), sample->data.size()) != 0) { + printImageBytes(img); + throw std::runtime_error("Wrong image contents"); + } + + img->drop(); + device->drop(); + + return 0; +} catch (const std::exception &e) { + std::printf("Test failed: %s\n", e.what()); + return 1; +} From 9cee9bc279c53fff9c3b5d60b423afdeae7b9fb3 Mon Sep 17 00:00:00 2001 From: Desour Date: Thu, 21 Mar 2024 20:43:20 +0100 Subject: [PATCH 66/91] Build with the imported IrrlichtMt at irr Also remove the now useless options (like IRRLICHT_INCLUDE_DIR) and update download instructions, CI and similar. Co-authored-by: sfan5 --- .github/workflows/linux.yml | 2 - .github/workflows/macos.yml | 1 - .github/workflows/windows.yml | 7 --- .gitignore | 2 +- CMakeLists.txt | 60 ++----------------- Dockerfile | 6 +- android/app/build.gradle | 2 +- android/native/build.gradle | 2 +- cmake/Modules/MinetestAndroidLibs.cmake | 16 ++--- .../Modules/MinetestFindIrrlichtHeaders.cmake | 18 ------ doc/compiling/README.md | 2 - doc/compiling/linux.md | 40 +++---------- doc/compiling/macos.md | 6 -- doc/compiling/windows.md | 6 -- misc/irrlichtmt_tag.txt | 1 - src/CMakeLists.txt | 4 -- util/buildbot/buildwin32.sh | 6 +- util/buildbot/buildwin64.sh | 6 +- util/buildbot/common.sh | 12 +++- util/buildbot/sha256sums.txt | 8 ++- util/ci/common.sh | 10 +--- 21 files changed, 47 insertions(+), 170 deletions(-) delete mode 100644 cmake/Modules/MinetestFindIrrlichtHeaders.cmake delete mode 100644 misc/irrlichtmt_tag.txt diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 5ca19a747..e80e4df31 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -11,7 +11,6 @@ on: - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'util/ci/**' - - 'misc/irrlichtmt_tag.txt' - 'Dockerfile' - '.dockerignore' - '.github/workflows/linux.yml' @@ -24,7 +23,6 @@ on: - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'util/ci/**' - - 'misc/irrlichtmt_tag.txt' - 'Dockerfile' - '.dockerignore' - '.github/workflows/linux.yml' diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 56b3f9fdc..77df1e3ea 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -33,7 +33,6 @@ jobs: - name: Build run: | - git clone https://github.com/minetest/irrlicht lib/irrlichtmt --depth 1 -b $(cat misc/irrlichtmt_tag.txt) mkdir build cd build cmake .. \ diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index eb9a13fac..e2303ff24 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -11,7 +11,6 @@ on: - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'util/buildbot/**' - - 'misc/irrlichtmt_tag.txt' - 'misc/*.manifest' - '.github/workflows/windows.yml' pull_request: @@ -23,7 +22,6 @@ on: - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'util/buildbot/**' - - 'misc/irrlichtmt_tag.txt' - 'misc/*.manifest' - '.github/workflows/windows.yml' @@ -97,11 +95,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Checkout IrrlichtMt - run: | - $ref = @(Get-Content misc\irrlichtmt_tag.txt) - git clone https://github.com/minetest/irrlicht lib\irrlichtmt --depth 1 -b $ref[0] - - name: Restore from cache and run vcpkg uses: lukka/run-vcpkg@v7 with: diff --git a/.gitignore b/.gitignore index c9fc16611..37e27bfed 100644 --- a/.gitignore +++ b/.gitignore @@ -119,7 +119,7 @@ compile_commands.json *.sln .vs/ -# Optional user provided library folder +# Old irrlichtmt. Still ignored to make bisecting easier. lib/irrlichtmt # Generated mod storage database diff --git a/CMakeLists.txt b/CMakeLists.txt index e6586425e..3e867d3b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,27 +91,12 @@ if(ANDROID) endif() -set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.") -if(ANDROID) - # currently manually provided -elseif(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "") - find_package(IrrlichtMt QUIET - PATHS "${IRRLICHTMT_BUILD_DIR}" - NO_DEFAULT_PATH - ) - - if(NOT TARGET IrrlichtMt::IrrlichtMt) - # find_package() searches certain subdirectories. ${PATH}/cmake is not - # the only one, but it is the one where IrrlichtMt is supposed to export - # IrrlichtMtConfig.cmake - message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.") - endif() -elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt") - message(STATUS "Using user-provided IrrlichtMt at subdirectory 'lib/irrlichtmt'") +if(TRUE) + message(STATUS "Using imported IrrlichtMt at subdirectory 'irr'") if(BUILD_CLIENT) # tell IrrlichtMt to create a static library set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared library" FORCE) - add_subdirectory(lib/irrlichtmt EXCLUDE_FROM_ALL) + add_subdirectory(irr EXCLUDE_FROM_ALL) unset(BUILD_SHARED_LIBS CACHE) if(NOT TARGET IrrlichtMt) @@ -120,44 +105,7 @@ elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt") else() add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED) set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt/include") - endif() -else() - find_package(IrrlichtMt QUIET) - if(NOT TARGET IrrlichtMt::IrrlichtMt) - string(CONCAT explanation_msg - "You must install IrrlichMt as described in docs/compiling/\n") - if(BUILD_CLIENT) - message(FATAL_ERROR "IrrlichtMt is required to build the client, but it was not found.\n${explanation_msg}") - endif() - - include(MinetestFindIrrlichtHeaders) - if(NOT IRRLICHT_INCLUDE_DIR) - message(FATAL_ERROR "IrrlichtMt headers are required to build the server, but none found.\n${explanation_msg}") - endif() - message(STATUS "Found IrrlichtMt headers: ${IRRLICHT_INCLUDE_DIR}") - add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED) - # Note that we can't use target_include_directories() since that doesn't work for IMPORTED targets before CMake 3.11 - set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${IRRLICHT_INCLUDE_DIR}") - endif() -endif() - -if(ANDROID) - # skipped for now -elseif(BUILD_CLIENT AND TARGET IrrlichtMt::IrrlichtMt) - # retrieve version somehow - if(NOT IrrlichtMt_VERSION) - get_target_property(IrrlichtMt_VERSION IrrlichtMt VERSION) - endif() - message(STATUS "Found IrrlichtMt ${IrrlichtMt_VERSION}") - - set(TARGET_VER_S 1.9.0mt15) - string(REPLACE "mt" "." TARGET_VER ${TARGET_VER_S}) - if(IrrlichtMt_VERSION VERSION_LESS ${TARGET_VER}) - message(FATAL_ERROR "At least IrrlichtMt ${TARGET_VER_S} is required to build") - elseif(NOT DEVELOPMENT_BUILD AND IrrlichtMt_VERSION VERSION_GREATER ${TARGET_VER}) - message(FATAL_ERROR "IrrlichtMt ${TARGET_VER_S} is required to build") + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/irr/include") endif() endif() diff --git a/Dockerfile b/Dockerfile index 95476663f..701c0492a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ ARG DOCKER_IMAGE=alpine:3.19 FROM $DOCKER_IMAGE AS dev -ENV IRRLICHT_VERSION master ENV SPATIALINDEX_VERSION master ENV LUAJIT_VERSION v2.1 @@ -30,9 +29,7 @@ RUN git clone --recursive https://github.com/jupp0r/prometheus-cpp && \ git clone --recursive https://luajit.org/git/luajit.git -b ${LUAJIT_VERSION} && \ cd luajit && \ make amalg && make install && \ - cd /usr/src/ && \ - git clone --depth=1 https://github.com/minetest/irrlicht -b ${IRRLICHT_VERSION} && \ - cp -r irrlicht/include /usr/include/irrlichtmt + cd /usr/src/ FROM dev as builder @@ -48,6 +45,7 @@ COPY lib /usr/src/minetest/lib COPY misc /usr/src/minetest/misc COPY po /usr/src/minetest/po COPY src /usr/src/minetest/src +COPY irr /usr/src/minetest/irr COPY textures /usr/src/minetest/textures WORKDIR /usr/src/minetest diff --git a/android/app/build.gradle b/android/app/build.gradle index c7471d2c7..30ee19c95 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -75,7 +75,7 @@ task prepareAssets() { from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders" } copy { - from "../native/deps/armeabi-v7a/Irrlicht/Shaders" into "${assetsFolder}/client/shaders/Irrlicht" + from "${projRoot}/irr/media/Shaders" into "${assetsFolder}/client/shaders/Irrlicht" } copy { from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts" diff --git a/android/native/build.gradle b/android/native/build.gradle index e78ddfc49..925ab8912 100644 --- a/android/native/build.gradle +++ b/android/native/build.gradle @@ -52,7 +52,7 @@ if (new File(depsDir, 'armeabi-v7a').exists()) { task downloadDeps(type: Download) { def depsZip = new File(buildDir, 'deps.zip') - src 'https://github.com/minetest/minetest_android_deps/releases/download/latest/deps.zip' + src 'https://github.com/minetest/minetest_android_deps/releases/download/latest/deps-lite.zip' dest depsZip overwrite false diff --git a/cmake/Modules/MinetestAndroidLibs.cmake b/cmake/Modules/MinetestAndroidLibs.cmake index a133976cb..02383903f 100644 --- a/cmake/Modules/MinetestAndroidLibs.cmake +++ b/cmake/Modules/MinetestAndroidLibs.cmake @@ -1,31 +1,27 @@ set(DEPS "${CMAKE_SOURCE_DIR}/android/native/deps/${ANDROID_ABI}") -add_library(IrrlichtMt::IrrlichtMt STATIC IMPORTED) -set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${DEPS}/Irrlicht/include) -set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES - IMPORTED_LOCATION ${DEPS}/Irrlicht/libIrrlichtMt.a) -set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES - INTERFACE_LINK_LIBRARIES "EGL;GLESv1_CM;GLESv2;${DEPS}/Irrlicht/libpng.a;${DEPS}/Irrlicht/libjpeg.a") - set(CURL_INCLUDE_DIR ${DEPS}/Curl/include) set(CURL_LIBRARY ${DEPS}/Curl/libcurl.a;${DEPS}/Curl/libmbedcrypto.a;${DEPS}/Curl/libmbedtls.a;${DEPS}/Curl/libmbedx509.a) -set(FREETYPE_INCLUDE_DIR_ft2build ${DEPS}/Freetype/include/freetype2) set(FREETYPE_INCLUDE_DIR_freetype2 ${FREETYPE_INCLUDE_DIR_ft2build}/freetype) +set(FREETYPE_INCLUDE_DIR_ft2build ${DEPS}/Freetype/include/freetype2) set(FREETYPE_LIBRARY ${DEPS}/Freetype/libfreetype.a) set(GETTEXT_INCLUDE_DIR ${DEPS}/Gettext/include;${DEPS}/Iconv/include) set(GETTEXT_LIBRARY ${DEPS}/Gettext/libintl.a) set(ICONV_LIBRARY ${DEPS}/Iconv/libiconv.a;${DEPS}/Iconv/libcharset.a) +set(JPEG_INCLUDE_DIR ${DEPS}/JPEG/include) +set(JPEG_LIBRARY ${DEPS}/JPEG/libjpeg.a) set(LUA_INCLUDE_DIR ${DEPS}/LuaJIT/include) set(LUA_LIBRARY ${DEPS}/LuaJIT/libluajit.a) set(OGG_INCLUDE_DIR ${DEPS}/Vorbis/include) set(OGG_LIBRARY ${DEPS}/Vorbis/libogg.a) set(OPENAL_INCLUDE_DIR ${DEPS}/OpenAL-Soft/include) set(OPENAL_LIBRARY ${DEPS}/OpenAL-Soft/libopenal.a;OpenSLES) +set(PNG_LIBRARY ${DEPS}/PNG/libpng.a) +set(PNG_PNG_INCLUDE_DIR ${DEPS}/PNG/include) set(SQLITE3_INCLUDE_DIR ${DEPS}/SQLite/include) set(SQLITE3_LIBRARY ${DEPS}/SQLite/libsqlite3.a) set(VORBIS_INCLUDE_DIR ${DEPS}/Vorbis/include) -set(VORBISFILE_LIBRARY ${DEPS}/Vorbis/libvorbisfile.a) set(VORBIS_LIBRARY ${DEPS}/Vorbis/libvorbis.a) +set(VORBISFILE_LIBRARY ${DEPS}/Vorbis/libvorbisfile.a) set(ZSTD_INCLUDE_DIR ${DEPS}/Zstd/include) set(ZSTD_LIBRARY ${DEPS}/Zstd/libzstd.a) diff --git a/cmake/Modules/MinetestFindIrrlichtHeaders.cmake b/cmake/Modules/MinetestFindIrrlichtHeaders.cmake deleted file mode 100644 index e434b582f..000000000 --- a/cmake/Modules/MinetestFindIrrlichtHeaders.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# Locate IrrlichtMt headers on system. - -find_path(IRRLICHT_INCLUDE_DIR NAMES irrlicht.h - DOC "Path to the directory with IrrlichtMt includes" - PATHS - /usr/local/include/irrlichtmt - /usr/include/irrlichtmt - /system/develop/headers/irrlichtmt #Haiku - PATH_SUFFIXES "include/irrlichtmt" -) - -# Handholding for users -if(IRRLICHT_INCLUDE_DIR AND (NOT IS_DIRECTORY "${IRRLICHT_INCLUDE_DIR}" OR - NOT EXISTS "${IRRLICHT_INCLUDE_DIR}/irrlicht.h")) - message(WARNING "IRRLICHT_INCLUDE_DIR was set to ${IRRLICHT_INCLUDE_DIR} " - "but irrlicht.h does not exist inside. The path will not be used.") - unset(IRRLICHT_INCLUDE_DIR CACHE) -endif() diff --git a/doc/compiling/README.md b/doc/compiling/README.md index 4ecaa88bb..ba40a07e2 100644 --- a/doc/compiling/README.md +++ b/doc/compiling/README.md @@ -55,8 +55,6 @@ Library specific options: GETTEXT_LIBRARY - Optional/platform-dependent with gettext; path to libintl.so/libintl.dll.a GETTEXT_MSGFMT - Only when building with gettext; path to msgfmt/msgfmt.exe ICONV_LIBRARY - Optional/platform-dependent; path to libiconv.so/libiconv.dylib - IRRLICHT_DLL - Only on Windows; path to IrrlichtMt.dll - IRRLICHT_INCLUDE_DIR - Directory that contains IrrCompileConfig.h (usable for server build only) LEVELDB_INCLUDE_DIR - Only when building with LevelDB; directory that contains db.h LEVELDB_LIBRARY - Only when building with LevelDB; path to libleveldb.a/libleveldb.so/libleveldb.dll.a LEVELDB_DLL - Only when building with LevelDB on Windows; path to libleveldb.dll diff --git a/doc/compiling/linux.md b/doc/compiling/linux.md index ffe38d339..c0a6d5dbe 100644 --- a/doc/compiling/linux.md +++ b/doc/compiling/linux.md @@ -6,10 +6,9 @@ | ---------- | ------- | ---------- | | GCC | 7.5+ | or Clang 7.0.1+ | | CMake | 3.5+ | | -| IrrlichtMt | - | Custom version of Irrlicht, see https://github.com/minetest/irrlicht | -| libjpeg | - | (via IrrlichtMt) | -| libpng | - | (via IrrlichtMt) | -| SDL | 2.x | (via IrrlichtMt) | +| libjpeg | - | | +| libpng | - | | +| SDL | 2.x | | | Freetype | 2.0+ | | | SQLite3 | 3+ | | | Zlib | - | | @@ -22,27 +21,27 @@ For Debian/Ubuntu users: - sudo apt install g++ make libc6-dev cmake libpng-dev libjpeg-dev libxi-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev libzstd-dev libluajit-5.1-dev gettext libsdl2-dev + sudo apt install g++ make libc6-dev cmake libpng-dev libjpeg-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev libzstd-dev libluajit-5.1-dev gettext libsdl2-dev For Fedora users: - sudo dnf install make automake gcc gcc-c++ kernel-devel cmake libcurl-devel openal-soft-devel libpng-devel libjpeg-devel libvorbis-devel libXi-devel libogg-devel freetype-devel mesa-libGL-devel zlib-devel jsoncpp-devel gmp-devel sqlite-devel luajit-devel leveldb-devel ncurses-devel spatialindex-devel libzstd-devel gettext SDL2-devel + sudo dnf install make automake gcc gcc-c++ kernel-devel cmake libcurl-devel openal-soft-devel libpng-devel libjpeg-devel libvorbis-devel libogg-devel freetype-devel mesa-libGL-devel zlib-devel jsoncpp-devel gmp-devel sqlite-devel luajit-devel leveldb-devel ncurses-devel spatialindex-devel libzstd-devel gettext SDL2-devel For openSUSE users: - sudo zypper install gcc cmake libjpeg8-devel libpng16-devel openal-soft-devel libcurl-devel sqlite3-devel luajit-devel libzstd-devel Mesa-libGL-devel libXi-devel libvorbis-devel freetype2-devel SDL2-devel + sudo zypper install gcc cmake libjpeg8-devel libpng16-devel openal-soft-devel libcurl-devel sqlite3-devel luajit-devel libzstd-devel Mesa-libGL-devel libvorbis-devel freetype2-devel SDL2-devel For Arch users: - sudo pacman -S --needed base-devel libcurl-gnutls cmake libxi libpng sqlite libogg libvorbis openal freetype2 jsoncpp gmp luajit leveldb ncurses zstd gettext sdl2 + sudo pacman -S --needed base-devel libcurl-gnutls cmake libpng sqlite libogg libvorbis openal freetype2 jsoncpp gmp luajit leveldb ncurses zstd gettext sdl2 For Alpine users: - sudo apk add build-base cmake libpng-dev jpeg-dev libxi-dev mesa-dev sqlite-dev libogg-dev libvorbis-dev openal-soft-dev curl-dev freetype-dev zlib-dev gmp-dev jsoncpp-dev luajit-dev zstd-dev gettext sdl2-dev + sudo apk add build-base cmake libpng-dev jpeg-dev mesa-dev sqlite-dev libogg-dev libvorbis-dev openal-soft-dev curl-dev freetype-dev zlib-dev gmp-dev jsoncpp-dev luajit-dev zstd-dev gettext sdl2-dev For Void users: - sudo xbps-install cmake libpng-devel jpeg-devel libXi-devel mesa sqlite-devel libogg-devel libvorbis-devel libopenal-devel libcurl-devel freetype-devel zlib-devel gmp-devel jsoncpp-devel LuaJIT-devel libzstd-devel gettext SDL2-devel + sudo xbps-install cmake libpng-devel jpeg-devel mesa sqlite-devel libogg-devel libvorbis-devel libopenal-devel libcurl-devel freetype-devel zlib-devel gmp-devel jsoncpp-devel LuaJIT-devel libzstd-devel gettext SDL2-devel ## Download @@ -73,24 +72,12 @@ Download source (this is the URL to the latest of source repository, which might git clone --depth 1 https://github.com/minetest/minetest.git cd minetest -Download IrrlichtMt to `lib/irrlichtmt`, it will be used to satisfy the IrrlichtMt dependency that way: - - git clone --depth 1 --branch "$(cat misc/irrlichtmt_tag.txt)" https://github.com/minetest/irrlicht.git lib/irrlichtmt - Download source, without using Git: wget https://github.com/minetest/minetest/archive/master.tar.gz tar xf master.tar.gz cd minetest-master -Download IrrlichtMt, without using Git: - - cd lib/ - wget https://github.com/minetest/irrlicht/archive/master.tar.gz - tar xf master.tar.gz - mv irrlicht-master irrlichtmt - cd .. - ## Build Build a version that runs directly from the source directory: @@ -109,12 +96,3 @@ Run it: - You can disable the client build by specifying `-DBUILD_CLIENT=FALSE`. - You can select between Release and Debug build by `-DCMAKE_BUILD_TYPE=`. - Debug build is slower, but gives much more useful output in a debugger. -- If you build a bare server you don't need to compile IrrlichtMt, just the headers suffice. - - In that case use `-DIRRLICHT_INCLUDE_DIR=/some/where/irrlichtmt/include`. - -- Minetest will use the IrrlichtMt package that is found first, given by the following order: - 1. Specified `IRRLICHTMT_BUILD_DIR` CMake variable - 2. `${PROJECT_SOURCE_DIR}/lib/irrlichtmt` (if existent) - 3. Installation of IrrlichtMt in the system-specific library paths - 4. For server builds with disabled `BUILD_CLIENT` variable, the headers from `IRRLICHT_INCLUDE_DIR` will be used. - - NOTE: Changing the IrrlichtMt build directory (includes system installs) requires regenerating the CMake cache (`rm CMakeCache.txt`) diff --git a/doc/compiling/macos.md b/doc/compiling/macos.md index bea40f6ef..6b9b4b6b8 100644 --- a/doc/compiling/macos.md +++ b/doc/compiling/macos.md @@ -20,12 +20,6 @@ git clone --depth 1 https://github.com/minetest/minetest.git cd minetest ``` -Download Minetest's fork of Irrlicht: - -```bash -git clone --depth 1 --branch "$(cat misc/irrlichtmt_tag.txt)" https://github.com/minetest/irrlicht.git lib/irrlichtmt -``` - ## Build ```bash diff --git a/doc/compiling/windows.md b/doc/compiling/windows.md index b42bf8206..c63a7b319 100644 --- a/doc/compiling/windows.md +++ b/doc/compiling/windows.md @@ -17,12 +17,6 @@ After you successfully built vcpkg you can easily install the required libraries vcpkg install zlib zstd curl[winssl] openal-soft libvorbis libogg libjpeg-turbo sqlite3 freetype luajit gmp jsoncpp gettext sdl2 --triplet x64-windows ``` -- **Don't forget about IrrlichtMt.** The easiest way is to clone it to `lib/irrlichtmt`: - -```bat -for /F %i in (misc\irrlichtmt_tag.txt) do git clone --depth 1 --branch %i https://github.com/minetest/irrlicht.git lib\irrlichtmt -``` - - `curl` is optional, but required to read the serverlist, `curl[winssl]` is required to use the content store. - `openal-soft`, `libvorbis` and `libogg` are optional, but required to use sound. - `luajit` is optional, it replaces the integrated Lua interpreter with a faster just-in-time interpreter. diff --git a/misc/irrlichtmt_tag.txt b/misc/irrlichtmt_tag.txt deleted file mode 100644 index 98b3fdbf1..000000000 --- a/misc/irrlichtmt_tag.txt +++ /dev/null @@ -1 +0,0 @@ -1.9.0mt15 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 00f6b724e..bf849493a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -883,10 +883,6 @@ if(WIN32) install(FILES ${GETTEXT_DLL} DESTINATION ${BINDIR}) endif() endif() - - if(BUILD_CLIENT AND IRRLICHT_DLL) - install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR}) - endif() endif() if(BUILD_CLIENT AND NOT ANDROID) diff --git a/util/buildbot/buildwin32.sh b/util/buildbot/buildwin32.sh index 3504505e5..34767f707 100755 --- a/util/buildbot/buildwin32.sh +++ b/util/buildbot/buildwin32.sh @@ -25,13 +25,10 @@ echo "Using $toolchain_file" find_runtime_dlls ${compiler%-*} # Get stuff -irrlicht_version=$(cat $topdir/../../misc/irrlichtmt_tag.txt) - mkdir -p $libdir cd $libdir libhost="http://minetest.kitsunemimi.pw" -download "https://github.com/minetest/irrlicht/releases/download/$irrlicht_version/win32-llvm.zip" irrlicht-$irrlicht_version-win32.zip download "$libhost/llvm/zlib-$zlib_version-win32.zip" download "$libhost/llvm/zstd-$zstd_version-win32.zip" download "$libhost/llvm/libogg-$ogg_version-win32.zip" @@ -43,6 +40,9 @@ download "$libhost/llvm/sqlite3-$sqlite3_version-win32.zip" download "$libhost/llvm/luajit-$luajit_version-win32.zip" download "$libhost/llvm/libleveldb-$leveldb_version-win32.zip" download "$libhost/llvm/openal-soft-$openal_version-win32.zip" +download "$libhost/llvm/libjpeg-$libjpeg_version-win32.zip" +download "$libhost/llvm/libpng-$libpng_version-win32.zip" +download "$libhost/llvm/sdl2-$sdl2_version-win32.zip" # Set source dir, downloading Minetest as needed get_sources diff --git a/util/buildbot/buildwin64.sh b/util/buildbot/buildwin64.sh index 774a1dfb8..c63a18901 100755 --- a/util/buildbot/buildwin64.sh +++ b/util/buildbot/buildwin64.sh @@ -25,13 +25,10 @@ echo "Using $toolchain_file" find_runtime_dlls ${compiler%-*} # Get stuff -irrlicht_version=$(cat $topdir/../../misc/irrlichtmt_tag.txt) - mkdir -p $libdir cd $libdir libhost="http://minetest.kitsunemimi.pw" -download "https://github.com/minetest/irrlicht/releases/download/$irrlicht_version/win64-llvm.zip" irrlicht-$irrlicht_version-win64.zip download "$libhost/llvm/zlib-$zlib_version-win64.zip" download "$libhost/llvm/zstd-$zstd_version-win64.zip" download "$libhost/llvm/libogg-$ogg_version-win64.zip" @@ -43,6 +40,9 @@ download "$libhost/llvm/sqlite3-$sqlite3_version-win64.zip" download "$libhost/llvm/luajit-$luajit_version-win64.zip" download "$libhost/llvm/libleveldb-$leveldb_version-win64.zip" download "$libhost/llvm/openal-soft-$openal_version-win64.zip" +download "$libhost/llvm/libjpeg-$libjpeg_version-win64.zip" +download "$libhost/llvm/libpng-$libpng_version-win64.zip" +download "$libhost/llvm/sdl2-$sdl2_version-win64.zip" # Set source dir, downloading Minetest as needed get_sources diff --git a/util/buildbot/common.sh b/util/buildbot/common.sh index 5db13820e..1ef96d7b2 100644 --- a/util/buildbot/common.sh +++ b/util/buildbot/common.sh @@ -13,6 +13,9 @@ luajit_version=20240125 leveldb_version=1.23 zlib_version=1.3.1 zstd_version=1.5.5 +libjpeg_version=3.0.1 +libpng_version=1.6.40 +sdl2_version=2.28.5 download () { local url=$1 @@ -77,8 +80,13 @@ _dlls () { add_cmake_libs () { cmake_args+=( - -DCMAKE_PREFIX_PATH=$libdir/irrlicht - -DIRRLICHT_DLL="$(_dlls $libdir/irrlicht/lib/*)" + -DPNG_LIBRARY=$libdir/libpng/lib/libpng.dll.a + -DPNG_PNG_INCLUDE_DIR=$libdir/libpng/include + + -DJPEG_LIBRARY=$libdir/libjpeg/lib/libjpeg.dll.a + -DJPEG_INCLUDE_DIR=$libdir/libjpeg/include + + -DCMAKE_PREFIX_PATH=$libdir/sdl2/lib/cmake -DZLIB_INCLUDE_DIR=$libdir/zlib/include -DZLIB_LIBRARY=$libdir/zlib/lib/libz.dll.a diff --git a/util/buildbot/sha256sums.txt b/util/buildbot/sha256sums.txt index 42fddbcb8..fce73a0a9 100644 --- a/util/buildbot/sha256sums.txt +++ b/util/buildbot/sha256sums.txt @@ -4,12 +4,14 @@ aa86abc3eb054d74d5fe15996f281cf84230a61b4ab7b3a702ab7dbb71e1203f curl-8.5.0-win acf901e93aedbcfa92eb3aab1def252676af845b1747ca5c3e7c5866576168cc freetype-2.13.2-win64.zip 41b10766de2773f0f0851fde16b363024685e0397f4bb2e5cd2a7be196960a01 gettext-0.20.2-win32.zip 1ceed167ff16fea944f76ab6ea2969160c71a67419259b17c9c523e7a01eb883 gettext-0.20.2-win64.zip -14bb60cbf9dd93e906d9c9117a99d19a500cda6bcfd6fc125e04f3c75778acc2 irrlicht-1.9.0mt15-win32.zip -31edd6a0af033b9ab455c5e019748cfa7e0cf167c9cbc5957227e72e971c2565 irrlicht-1.9.0mt15-win64.zip +53dfd31285f470fcf0dca88217c5cf9c557729af6d103afae5936e72ddc38d3c libjpeg-3.0.1-win32.zip +3d44e0740914e6878300e30653aad39e974821b5d7f6c2567e246b4eb04a5324 libjpeg-3.0.1-win64.zip f54e9a577e2db47ed28f4a01e74181d2c607627c551d30f48263e01b59e84f67 libleveldb-1.23-win32.zip 2f039848a4e6c05a2347fe5a7fa63c430dd08d1bc88235645a863c859e14f5f8 libleveldb-1.23-win64.zip 0df94afb8efa361cceb132ecf9491720afbc45ba844a7b1c94607295829b53ca libogg-1.3.5-win32.zip 5c4acb4c99429a04b5e69650719b2eb17616bf52837d2372a0f859952eebce48 libogg-1.3.5-win64.zip +6baf4e819bfb3573760524b5dc9a04b5e479090d6d2046b86cf39a3107c0071f libpng-1.6.40-win32.zip +c02e029f01fce44baea7f4aecfd2564bd8a03507c0c6af8b03339ae0452c8b7d libpng-1.6.40-win64.zip 456ece10a2be4247b27fbe88f88ddd54aae604736a6b76ba9a922b602fe40f40 libvorbis-1.3.7-win32.zip 57f4db02da00556895bb63fafa6e46b5f7dac87c25fde27af4315f56a1aa7a86 libvorbis-1.3.7-win64.zip 0f21ff3be90311092fe32e0e30878ef3ae9d9437b8d9ac25ef279e0d84e9bb8e llvm-mingw-20231128-ucrt-ubuntu-20.04-x86_64.tar.xz @@ -17,6 +19,8 @@ da6ad10632cf172992158e9ea0977a87914b5d5de93a972c3430b6a412237556 luajit-2024012 2b1dabe83d478b398cf9226d96de7fa62c973365c4aea70d27ba5782fb49d2d0 luajit-20240125-win64.zip e2443451fe5c2066eb564c64b8a1762738a88b7fd749c8b5907fed45c785497b openal-soft-1.23.1-win32.zip cb041445a118469caefbad2647470cb8571c8337bce2adc07634011ab5625417 openal-soft-1.23.1-win64.zip +f9f890af960e92fd3f532f2e9ac00681c33bc67a722e000dfdaeb41b0064f1a0 sdl2-2.28.5-win32.zip +8dde2c6963544b7d8a2e87c128ebbdf51ad0e70c7e2df986ff4e963ce9996d9b sdl2-2.28.5-win64.zip 326701086a0ed66e09a9f3ec4d971654c13b6bd79cfdd079c947ecdcd6409525 sqlite3-3.44.2-win32.zip b2d474e3625f8f426b6cc5c0ecac831a1de46f7d1027bf4a9f6267b0b0411d42 sqlite3-3.44.2-win64.zip 8af10515d57dbfee5d2106cd66cafa2adeb4270d4c6047ccbf7e8b5d2d50681c zlib-1.3.1-win32.zip diff --git a/util/ci/common.sh b/util/ci/common.sh index 257899880..ac80029f0 100644 --- a/util/ci/common.sh +++ b/util/ci/common.sh @@ -4,19 +4,11 @@ install_linux_deps() { local pkgs=( cmake gettext postgresql - libpng-dev libjpeg-dev libxi-dev libgl1-mesa-dev + libpng-dev libjpeg-dev libgl1-mesa-dev libsdl2-dev libsqlite3-dev libhiredis-dev libogg-dev libgmp-dev libvorbis-dev libopenal-dev libpq-dev libleveldb-dev libcurl4-openssl-dev libzstd-dev ) - if [[ "$1" == "--no-irr" ]]; then - shift - else - local ver=$(cat misc/irrlichtmt_tag.txt) - wget "https://github.com/minetest/irrlicht/releases/download/$ver/ubuntu-focal.tar.gz" - sudo tar -xaf ubuntu-focal.tar.gz -C /usr/local - fi - sudo apt-get update sudo apt-get install -y --no-install-recommends "${pkgs[@]}" "$@" From 6a7a613741fe32fa14897a4f780d7382105a103c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 21 Mar 2024 23:54:28 +0100 Subject: [PATCH 67/91] Update the CI run with multiplayer tests --- .github/workflows/android.yml | 2 ++ .github/workflows/cpp_lint.yml | 2 ++ .github/workflows/linux.yml | 2 ++ .github/workflows/lua.yml | 12 ++++++------ .github/workflows/macos.yml | 2 ++ .github/workflows/windows.yml | 2 ++ 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index ffcae5cf5..c59dd6732 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -8,6 +8,8 @@ on: - 'lib/**.cpp' - 'src/**.[ch]' - 'src/**.cpp' + - 'irr/**.[ch]' + - 'irr/**.cpp' - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'android/**' diff --git a/.github/workflows/cpp_lint.yml b/.github/workflows/cpp_lint.yml index 51c6c8273..79b8ffc4e 100644 --- a/.github/workflows/cpp_lint.yml +++ b/.github/workflows/cpp_lint.yml @@ -8,6 +8,8 @@ on: - 'lib/**.cpp' - 'src/**.[ch]' - 'src/**.cpp' + - 'irr/**.[ch]' + - 'irr/**.cpp' - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'util/ci/**' diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index e80e4df31..eb2b032da 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -8,6 +8,8 @@ on: - 'lib/**.cpp' - 'src/**.[ch]' - 'src/**.cpp' + - 'irr/**.[ch]' + - 'irr/**.cpp' - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'util/ci/**' diff --git a/.github/workflows/lua.yml b/.github/workflows/lua.yml index ff556908f..6f803d133 100644 --- a/.github/workflows/lua.yml +++ b/.github/workflows/lua.yml @@ -14,24 +14,24 @@ on: - '.github/workflows/**.yml' jobs: - # Note that the integration tests are also run build.yml, but only when C++ code is changed. + # Note that the integration tests are also run in build.yml, but only when C++ code is changed. integration_tests: name: "Compile and run multiplayer tests" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - name: Install deps run: | source ./util/ci/common.sh - install_linux_deps clang-10 gdb libluajit-5.1-dev + install_linux_deps clang gdb libluajit-5.1-dev - name: Build run: | ./util/ci/build.sh env: - CC: clang-10 - CXX: clang++-10 - CMAKE_FLAGS: "-DENABLE_GETTEXT=0 -DBUILD_SERVER=0" + CC: clang + CXX: clang++ + CMAKE_FLAGS: "-DENABLE_GETTEXT=0 -DBUILD_SERVER=0 -DBUILD_UNITTESTS=0" - name: Integration test + devtest run: | diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 77df1e3ea..24c2b9f51 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -8,6 +8,8 @@ on: - 'lib/**.cpp' - 'src/**.[ch]' - 'src/**.cpp' + - 'irr/**.[ch]' + - 'irr/**.cpp' - '**/CMakeLists.txt' - 'cmake/Modules/**' - '.github/workflows/macos.yml' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e2303ff24..061bd704b 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -8,6 +8,8 @@ on: - 'lib/**.cpp' - 'src/**.[ch]' - 'src/**.cpp' + - 'irr/**.[ch]' + - 'irr/**.cpp' - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'util/buildbot/**' From b487341c32be3ebd8ba0cc875b1374c0904c32ea Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 27 Mar 2024 18:32:05 +0000 Subject: [PATCH 68/91] Deprecate writing to mod directories (#14486) --- src/script/cpp_api/s_security.cpp | 65 +++++++++++++++++++++++-------- src/script/cpp_api/s_security.h | 6 +-- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index cadeafdd1..7c8ba8931 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -505,6 +505,28 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path, const char } +bool checkModNameWhitelisted(const std::string &mod_name, const std::string &setting) +{ + assert(str_starts_with(setting, "secure.")); + + if (mod_name.empty()) + return false; + + std::string value = g_settings->get(setting); + value.erase(std::remove(value.begin(), value.end(), ' '), value.end()); + auto mod_list = str_split(value, ','); + + return CONTAINS(mod_list, mod_name); +} + + +bool ScriptApiSecurity::checkWhitelisted(lua_State *L, const std::string &setting) +{ + std::string mod_name = ScriptApiBase::getCurrentModName(L); + return checkModNameWhitelisted(mod_name, setting); +} + + bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, bool write_required, bool *write_allowed) { @@ -555,7 +577,6 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, return false; // Get mod name - // FIXME: insecure = problem here? std::string mod_name = ScriptApiBase::getCurrentModNameInsecure(L); if (!mod_name.empty()) { // Builtin can access anything @@ -571,7 +592,32 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, if (mod) { str = fs::AbsolutePath(mod->path); if (!str.empty() && fs::PathStartsWith(abs_path, str)) { - if (write_allowed) *write_allowed = true; + // `mod_name` cannot be trusted here, so we catch the scenarios where this becomes a problem: + bool is_trusted = checkModNameWhitelisted(mod_name, "secure.trusted_mods") || + checkModNameWhitelisted(mod_name, "secure.http_mods"); + std::string filename = lowercase(fs::GetFilenameFromPath(abs_path.c_str())); + // By writing to any of these a malicious mod could turn itself into + // an existing trusted mod by renaming or becoming a modpack. + bool is_dangerous_file = filename == "mod.conf" || + filename == "modpack.conf" || + filename == "modpack.txt"; + if (write_required) { + if (is_trusted) { + throw LuaError( + "Unable to write to a trusted or http mod's directory. " + "For data storage consider minetest.get_mod_data_path() or minetest.get_worldpath() instead."); + } else if (is_dangerous_file) { + throw LuaError( + "Unable to write to special file for security reasons"); + } else { + const char *message = + "Writing to mod directories is deprecated, as any changes " + "will be overwritten when updating content. " + "For data storage consider minetest.get_mod_data_path() or minetest.get_worldpath() instead."; + log_deprecated(L, message, 1); + } + } + if (write_allowed) *write_allowed = !is_trusted && !is_dangerous_file; return true; } } @@ -630,21 +676,6 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, return false; } -bool ScriptApiSecurity::checkWhitelisted(lua_State *L, const std::string &setting) -{ - assert(str_starts_with(setting, "secure.")); - - std::string mod_name = ScriptApiBase::getCurrentModName(L); - if (mod_name.empty()) - return false; - - std::string value = g_settings->get(setting); - value.erase(std::remove(value.begin(), value.end(), ' '), value.end()); - auto mod_list = str_split(value, ','); - - return CONTAINS(mod_list, mod_name); -} - int ScriptApiSecurity::sl_g_dofile(lua_State *L) { diff --git a/src/script/cpp_api/s_security.h b/src/script/cpp_api/s_security.h index 880ce1638..ee93e1f99 100644 --- a/src/script/cpp_api/s_security.h +++ b/src/script/cpp_api/s_security.h @@ -49,12 +49,12 @@ public: static bool safeLoadString(lua_State *L, const std::string &code, const char *chunk_name); // Loads a file as Lua code safely (doesn't allow bytecode). static bool safeLoadFile(lua_State *L, const char *path, const char *display_name = NULL); - // Checks if mods are allowed to read (and optionally write) to the path - static bool checkPath(lua_State *L, const char *path, bool write_required, - bool *write_allowed=NULL); // Check if mod is whitelisted in the given setting // This additionally checks that the mod's main file scope is executing. static bool checkWhitelisted(lua_State *L, const std::string &setting); + // Checks if mods are allowed to read (and optionally write) to the path + static bool checkPath(lua_State *L, const char *path, bool write_required, + bool *write_allowed=NULL); private: int getThread(lua_State *L); From d53ef90a733a22facbd513e464afb518478c0579 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 27 Mar 2024 12:00:39 +0100 Subject: [PATCH 69/91] Remove Irrlicht versioning --- irr/include/IrrCompileConfig.h | 13 ------- irr/include/IrrlichtDevice.h | 6 ---- irr/include/SIrrCreationParameters.h | 38 --------------------- irr/src/CIrrDeviceStub.cpp | 30 ---------------- irr/src/CIrrDeviceStub.h | 6 ---- irr/src/CMakeLists.txt | 17 ++------- src/client/clientlauncher.cpp | 4 --- src/client/game.cpp | 4 --- src/client/shader.cpp | 4 --- src/client/shadows/dynamicshadowsrender.cpp | 5 --- src/main.cpp | 3 -- src/script/lua_api/l_mainmenu.cpp | 5 --- 12 files changed, 2 insertions(+), 133 deletions(-) diff --git a/irr/include/IrrCompileConfig.h b/irr/include/IrrCompileConfig.h index 3e248cbc0..42fc7fc2d 100644 --- a/irr/include/IrrCompileConfig.h +++ b/irr/include/IrrCompileConfig.h @@ -4,19 +4,6 @@ #pragma once -//! Identifies the IrrlichtMt fork customized for the Minetest engine -#define IRRLICHT_VERSION_MT_REVISION 15 -#define IRRLICHT_VERSION_MT "mt15" - -//! Irrlicht SDK Version -#define IRRLICHT_VERSION_MAJOR 1 -#define IRRLICHT_VERSION_MINOR 9 -#define IRRLICHT_VERSION_REVISION 0 -// This flag will be defined only in SVN, the official release code will have -// it undefined -#define IRRLICHT_VERSION_SVN alpha -#define IRRLICHT_SDK_VERSION "1.9.0" IRRLICHT_VERSION_MT - #ifdef _WIN32 #define IRRCALLCONV __stdcall #else diff --git a/irr/include/IrrlichtDevice.h b/irr/include/IrrlichtDevice.h index 8f4105a4f..f0ec9f005 100644 --- a/irr/include/IrrlichtDevice.h +++ b/irr/include/IrrlichtDevice.h @@ -194,12 +194,6 @@ public: /** IrrlichtDevice::run() will always return false after closeDevice() was called. */ virtual void closeDevice() = 0; - //! Get the version of the engine. - /** The returned string - will look like this: "1.2.3" or this: "1.2". - \return String which contains the version. */ - virtual const c8 *getVersion() const = 0; - //! Sets a new user event receiver which will receive events from the engine. /** Return true in IEventReceiver::OnEvent to prevent the event from continuing along the chain of event receivers. The path that an event takes through the system depends diff --git a/irr/include/SIrrCreationParameters.h b/irr/include/SIrrCreationParameters.h index 26e46e324..0cd1a9218 100644 --- a/irr/include/SIrrCreationParameters.h +++ b/irr/include/SIrrCreationParameters.h @@ -10,7 +10,6 @@ #include "ILogger.h" #include "position2d.h" #include "path.h" -#include "IrrCompileConfig.h" // for IRRLICHT_SDK_VERSION namespace irr { @@ -44,7 +43,6 @@ struct SIrrlichtCreationParameters #else LoggingLevel(ELL_INFORMATION), #endif - SDK_version_do_not_use(IRRLICHT_SDK_VERSION), PrivateData(0), #ifdef IRR_MOBILE_PATHS OGLES2ShaderPath("media/Shaders/") @@ -54,37 +52,6 @@ struct SIrrlichtCreationParameters { } - SIrrlichtCreationParameters(const SIrrlichtCreationParameters &other) : - SDK_version_do_not_use(IRRLICHT_SDK_VERSION) - { - *this = other; - } - - SIrrlichtCreationParameters &operator=(const SIrrlichtCreationParameters &other) - { - DeviceType = other.DeviceType; - DriverType = other.DriverType; - WindowSize = other.WindowSize; - WindowPosition = other.WindowPosition; - Bits = other.Bits; - ZBufferBits = other.ZBufferBits; - Fullscreen = other.Fullscreen; - WindowMaximized = other.WindowMaximized; - WindowResizable = other.WindowResizable; - Stencilbuffer = other.Stencilbuffer; - Vsync = other.Vsync; - AntiAlias = other.AntiAlias; - WithAlphaChannel = other.WithAlphaChannel; - Doublebuffer = other.Doublebuffer; - Stereobuffer = other.Stereobuffer; - EventReceiver = other.EventReceiver; - WindowId = other.WindowId; - LoggingLevel = other.LoggingLevel; - PrivateData = other.PrivateData; - OGLES2ShaderPath = other.OGLES2ShaderPath; - return *this; - } - //! Type of the device. /** This setting decides the windowing system used by the device, most device types are native to a specific operating system and so may not be available. @@ -247,11 +214,6 @@ struct SIrrlichtCreationParameters */ ELOG_LEVEL LoggingLevel; - //! Don't use or change this parameter. - /** Always set it to IRRLICHT_SDK_VERSION, which is done by default. - This is needed for sdk version checks. */ - const c8 *const SDK_version_do_not_use; - //! Define some private data storage. /** Used when platform devices need access to OS specific data structures etc. This is only used for Android at the moment in order to access the native diff --git a/irr/src/CIrrDeviceStub.cpp b/irr/src/CIrrDeviceStub.cpp index 2292db191..1ff120d10 100644 --- a/irr/src/CIrrDeviceStub.cpp +++ b/irr/src/CIrrDeviceStub.cpp @@ -38,12 +38,6 @@ CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters ¶ms) : os::Printer::Logger = Logger; FileSystem = io::createFileSystem(); - - core::stringc s = "Irrlicht Engine version "; - s.append(getVersion()); - os::Printer::log(s.c_str(), ELL_INFORMATION); - - checkVersion(params.SDK_version_do_not_use); } CIrrDeviceStub::~CIrrDeviceStub() @@ -129,12 +123,6 @@ bool CIrrDeviceStub::setWindowIcon(const video::IImage *img) return false; } -//! Returns the version of the engine. -const char *CIrrDeviceStub::getVersion() const -{ - return IRRLICHT_SDK_VERSION; -} - //! \return Returns a pointer to the mouse cursor control interface. gui::ICursorControl *CIrrDeviceStub::getCursorControl() { @@ -147,24 +135,6 @@ video::IContextManager *CIrrDeviceStub::getContextManager() return ContextManager; } -//! checks version of sdk and prints warning if there might be a problem -bool CIrrDeviceStub::checkVersion(const char *version) -{ - if (strcmp(getVersion(), version)) { - core::stringc w; - w = "Warning: The library version of the Irrlicht Engine ("; - w += getVersion(); - w += ") does not match the version the application was compiled with ("; - w += version; - w += "). This may cause problems."; - os::Printer::log(w.c_str(), ELL_WARNING); - - return false; - } - - return true; -} - //! Compares to the last call of this function to return double and triple clicks. u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent) { diff --git a/irr/src/CIrrDeviceStub.h b/irr/src/CIrrDeviceStub.h index 163e44f39..9a1966f01 100644 --- a/irr/src/CIrrDeviceStub.h +++ b/irr/src/CIrrDeviceStub.h @@ -70,9 +70,6 @@ public: //! Sets the window icon. bool setWindowIcon(const video::IImage *img) override; - //! Returns the version of the engine. - const char *getVersion() const override; - //! send the event to the right receiver bool postEventFromUser(const SEvent &event) override; @@ -159,9 +156,6 @@ public: protected: void createGUIAndScene(); - //! checks version of SDK and prints warning if there might be a problem - bool checkVersion(const char *version); - //! Compares to the last call of this function to return double and triple clicks. /** Needed for win32 device event handling \return Returns only 1,2 or 3. A 4th click will start with 1 again. diff --git a/irr/src/CMakeLists.txt b/irr/src/CMakeLists.txt index 46eaf9cca..23944105f 100644 --- a/irr/src/CMakeLists.txt +++ b/irr/src/CMakeLists.txt @@ -56,20 +56,6 @@ elseif(MSVC) add_compile_options(/D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) endif() -# Sanity-check version - -include(CheckCXXSourceCompiles) -set(CMAKE_REQUIRED_INCLUDES ${PROJECT_SOURCE_DIR}/include) -unset(REVISION_SANITY_CHECK CACHE) -check_cxx_source_compiles("#include \n\ -#if IRRLICHT_VERSION_MT_REVISION != ${IRRLICHTMT_REVISION}\n\ -#error\n\ -#endif\n\ -int main() {}" REVISION_SANITY_CHECK) -if(NOT REVISION_SANITY_CHECK) - message(FATAL_ERROR "IrrlichtMt revision number mismatches between CMake and headers.") -endif() - # Platform-independent configuration (hard-coded currently) add_definitions( -DIRR_ENABLE_BUILTIN_FONT @@ -246,11 +232,12 @@ endif() # Required libs +include(CheckCXXSourceCompiles) + find_package(ZLIB REQUIRED) find_package(JPEG REQUIRED) find_package(PNG REQUIRED) - if(ENABLE_GLES1) # only tested on Android, probably works on Linux (is this needed anywhere else?) find_library(OPENGLES_LIBRARY NAMES GLESv1_CM REQUIRED) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 93ed392b9..56beba927 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -164,11 +164,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) while (m_rendering_engine->run() && !*kill && !g_gamecallback->shutdown_requested) { // Set the window caption -#if IRRLICHT_VERSION_MT_REVISION >= 15 auto driver_name = m_rendering_engine->getVideoDriver()->getName(); -#else - auto driver_name = wide_to_utf8(m_rendering_engine->getVideoDriver()->getName()); -#endif std::string caption = std::string(PROJECT_NAME_C) + " " + g_version_hash + " [" + gettext("Main Menu") + "]" + diff --git a/src/client/game.cpp b/src/client/game.cpp index 84b2815c8..849e7702a 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1478,11 +1478,7 @@ bool Game::createClient(const GameStartData &start_data) /* Set window caption */ -#if IRRLICHT_VERSION_MT_REVISION >= 15 auto driver_name = driver->getName(); -#else - auto driver_name = wide_to_utf8(driver->getName()); -#endif std::string str = std::string(PROJECT_NAME_C) + " " + g_version_hash + " ["; str += simple_singleplayer_mode ? gettext("Singleplayer") diff --git a/src/client/shader.cpp b/src/client/shader.cpp index c6de1ee35..4f84ecbe7 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -368,7 +368,6 @@ ShaderSource::~ShaderSource() { MutexAutoLock lock(m_shaderinfo_cache_mutex); -#if IRRLICHT_VERSION_MT_REVISION >= 15 // Delete materials video::IGPUProgrammingServices *gpu = RenderingEngine::get_video_driver()-> getGPUProgrammingServices(); @@ -377,7 +376,6 @@ ShaderSource::~ShaderSource() gpu->deleteShaderMaterial(i.material); } m_shaderinfo_cache.clear(); -#endif } u32 ShaderSource::getShader(const std::string &name, @@ -501,7 +499,6 @@ void ShaderSource::rebuildShaders() { MutexAutoLock lock(m_shaderinfo_cache_mutex); -#if IRRLICHT_VERSION_MT_REVISION >= 15 // Delete materials video::IGPUProgrammingServices *gpu = RenderingEngine::get_video_driver()-> getGPUProgrammingServices(); @@ -511,7 +508,6 @@ void ShaderSource::rebuildShaders() i.material = video::EMT_SOLID; // invalidate } } -#endif // Recreate shaders for (ShaderInfo &i : m_shaderinfo_cache) { diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp index ca61d8467..08cdca0ad 100644 --- a/src/client/shadows/dynamicshadowsrender.cpp +++ b/src/client/shadows/dynamicshadowsrender.cpp @@ -192,12 +192,7 @@ void ShadowRenderer::addNodeToShadowList( { m_shadow_node_array.emplace_back(node, shadowMode); // node should never be ClientMap -#if IRRLICHT_VERSION_MT_REVISION >= 15 assert(!node->getName().has_value() || *node->getName() != "ClientMap"); -#else - // TODO: Remove this as soon as we require 1.9.0mt15 - assert(strcmp(node->getName(), "ClientMap") != 0); -#endif node->forEachMaterial([this] (auto &mat) { mat.setTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal); }); diff --git a/src/main.cpp b/src/main.cpp index 763a8ae37..d693a6b5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -425,9 +425,6 @@ static void print_version(std::ostream &os) { os << PROJECT_NAME_C " " << g_version_hash << " (" << porting::getPlatformName() << ")" << std::endl; -#ifndef SERVER - os << "Using Irrlicht " IRRLICHT_SDK_VERSION << std::endl; -#endif #if USE_LUAJIT os << "Using " << LUAJIT_VERSION << std::endl; #else diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 44b4b57e7..c98f974d2 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -996,12 +996,7 @@ int ModApiMainMenu::l_get_active_driver(lua_State *L) int ModApiMainMenu::l_get_active_renderer(lua_State *L) { -#if IRRLICHT_VERSION_MT_REVISION >= 15 lua_pushstring(L, RenderingEngine::get_video_driver()->getName()); -#else - auto tmp = wide_to_utf8(RenderingEngine::get_video_driver()->getName()); - lua_pushstring(L, tmp.c_str()); -#endif return 1; } From 08284e420d85476494977abb7e09b8db50f7b29b Mon Sep 17 00:00:00 2001 From: src-tinkerer <149616646+src-tinkerer@users.noreply.github.com> Date: Wed, 27 Mar 2024 21:46:41 +0000 Subject: [PATCH 70/91] Disable default password check in single player (#14493) --- src/network/serverpackethandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 6d93265eb..2c6f024ee 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -261,7 +261,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt) } } else { std::string default_password = g_settings->get("default_password"); - if (default_password.length() == 0) { + if (isSingleplayer() || default_password.length() == 0) { auth_mechs |= AUTH_MECHANISM_FIRST_SRP; } else { // Take care of default passwords. From d307d01b18b84a117ecd2c427cec85595cf72ea3 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 24 Mar 2024 10:33:41 +0100 Subject: [PATCH 71/91] Fix tests that rely on UTF-8 literals and the lowercase function --- src/filesys.cpp | 4 ++-- src/unittest/test_settings.cpp | 6 +++--- src/unittest/test_utilities.cpp | 27 ++++++++++++++++----------- src/util/string.h | 23 +++++++++++++++++++---- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/filesys.cpp b/src/filesys.cpp index 88d617801..9f493d7cf 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -701,8 +701,8 @@ bool PathStartsWith(const std::string &path, const std::string &prefix) char pathchar = path[pathpos+len]; char prefixchar = prefix[prefixpos+len]; if(FILESYS_CASE_INSENSITIVE){ - pathchar = tolower(pathchar); - prefixchar = tolower(prefixchar); + pathchar = my_tolower(pathchar); + prefixchar = my_tolower(prefixchar); } if(pathchar != prefixchar) return false; diff --git a/src/unittest/test_settings.cpp b/src/unittest/test_settings.cpp index 6f382fabc..f5145ee16 100644 --- a/src/unittest/test_settings.cpp +++ b/src/unittest/test_settings.cpp @@ -51,7 +51,7 @@ void TestSettings::runTests(IGameDef *gamedef) //////////////////////////////////////////////////////////////////////////////// const char *TestSettings::config_text_before = - "leet = 1337\n" + u8"leet = 1337\n" "leetleet = 13371337\n" "leetleet_neg = -13371337\n" "floaty_thing = 1.1\n" @@ -77,7 +77,7 @@ const char *TestSettings::config_text_before = "[dummy_eof_end_tag]\n"; const std::string TestSettings::config_text_after = - "leet = 1337\n" + u8"leet = 1337\n" "leetleet = 13371337\n" "leetleet_neg = -13371337\n" "floaty_thing = 1.1\n" @@ -154,7 +154,7 @@ void TestSettings::testAllSettings() // Not sure if 1.1 is an exact value as a float, but doesn't matter UASSERT(fabs(s.getFloat("floaty_thing") - 1.1) < 0.001); - UASSERT(s.get("stringy_thing") == "asd /( ¤%&(/\" BLÖÄRP"); + UASSERT(s.get("stringy_thing") == u8"asd /( ¤%&(/\" BLÖÄRP"); UASSERT(fabs(s.getV3F("coord").X - 1.0) < 0.001); UASSERT(fabs(s.getV3F("coord").Y - 2.0) < 0.001); UASSERT(fabs(s.getV3F("coord").Z - 4.5) < 0.001); diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp index 752950abe..5c653a529 100644 --- a/src/unittest/test_utilities.cpp +++ b/src/unittest/test_utilities.cpp @@ -183,9 +183,11 @@ void TestUtilities::testWrapDegrees_0_360_v3f() void TestUtilities::testLowercase() { - UASSERT(lowercase("Foo bAR") == "foo bar"); - UASSERT(lowercase("eeeeeeaaaaaaaaaaaààààà") == "eeeeeeaaaaaaaaaaaààààà"); - UASSERT(lowercase("MINETEST-powa") == "minetest-powa"); + UASSERTEQ(auto, lowercase("Foo bAR"), "foo bar"); + UASSERTEQ(auto, lowercase(u8"eeeeeeaaaaaaaaaaaààààà"), u8"eeeeeeaaaaaaaaaaaààààà"); + // intentionally won't handle Unicode, regardless of locale + UASSERTEQ(auto, lowercase(u8"ÜÜ"), u8"ÜÜ"); + UASSERTEQ(auto, lowercase("MINETEST-powa"), "minetest-powa"); } @@ -309,18 +311,21 @@ void TestUtilities::testAsciiPrintableHelper() void TestUtilities::testUTF8() { - UASSERT(utf8_to_wide("¤") == L"¤"); + UASSERT(utf8_to_wide(u8"¤") == L"¤"); - UASSERT(wide_to_utf8(L"¤") == "¤"); + UASSERTEQ(std::string, wide_to_utf8(L"¤"), u8"¤"); UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide("")), ""); UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide("the shovel dug a crumbly node!")), "the shovel dug a crumbly node!"); - UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide("-ä-")), - "-ä-"); - UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide("-\xF0\xA0\x80\x8B-")), - "-\xF0\xA0\x80\x8B-"); - + UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide(u8"-ä-")), + u8"-ä-"); + UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide(u8"-\U0002000b-")), + u8"-\U0002000b-"); + if constexpr (sizeof(wchar_t) == 4) { + const auto *literal = U"-\U0002000b-"; + UASSERT(utf8_to_wide(u8"-\U0002000b-") == reinterpret_cast(literal)); + } } void TestUtilities::testRemoveEscapes() @@ -643,7 +648,7 @@ void TestUtilities::testSanitizeDirName() UASSERTEQ(auto, sanitizeDirName(" a ", "~"), "_a_"); UASSERTEQ(auto, sanitizeDirName("COM1", "~"), "~COM1"); UASSERTEQ(auto, sanitizeDirName("COM1", ":"), "_COM1"); - UASSERTEQ(auto, sanitizeDirName("cOm\u00B2", "~"), "~cOm\u00B2"); + UASSERTEQ(auto, sanitizeDirName(u8"cOm\u00B2", "~"), u8"~cOm\u00B2"); UASSERTEQ(auto, sanitizeDirName("cOnIn$", "~"), "~cOnIn$"); UASSERTEQ(auto, sanitizeDirName(" cOnIn$ ", "~"), "_cOnIn$_"); } diff --git a/src/util/string.h b/src/util/string.h index 0c81a15cb..bddbc62ce 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -101,6 +101,21 @@ bool parseColorString(const std::string &value, video::SColor &color, bool quiet unsigned char default_alpha = 0xff); std::string encodeHexColorString(video::SColor color); +/** + * Converts a letter to lowercase, with safe handling of the char type and non-ASCII. + * @param c input letter + * @returns same letter but lowercase +*/ +inline char my_tolower(char c) +{ + // By design this function cannot handle any Unicode (codepoints don't fit into char), + // but make sure to pass it through unchanged. + // tolower() can mangle it if the POSIX locale is not UTF-8. + if (static_cast(c) > 0x7f) + return c; + // toupper(3): "If the argument c is of type char, it must be cast to unsigned char" + return tolower(static_cast(c)); +} /** * Returns a copy of \p str with spaces inserted at the right hand side to ensure @@ -173,7 +188,7 @@ inline bool str_equal(std::basic_string_view s1, return false; for (size_t i = 0; i < s1.size(); ++i) - if(tolower(s1[i]) != tolower(s2[i])) + if (my_tolower(s1[i]) != my_tolower(s2[i])) return false; return true; @@ -212,7 +227,7 @@ inline bool str_starts_with(std::basic_string_view str, return str.compare(0, prefix.size(), prefix) == 0; for (size_t i = 0; i < prefix.size(); ++i) - if (tolower(str[i]) != tolower(prefix[i])) + if (my_tolower(str[i]) != my_tolower(prefix[i])) return false; return true; } @@ -253,7 +268,7 @@ inline bool str_ends_with(std::basic_string_view str, return str.compare(start, suffix.size(), suffix) == 0; for (size_t i = 0; i < suffix.size(); ++i) - if (tolower(str[start + i]) != tolower(suffix[i])) + if (my_tolower(str[start + i]) != my_tolower(suffix[i])) return false; return true; } @@ -305,7 +320,7 @@ inline std::string lowercase(std::string_view str) std::string s2; s2.resize(str.size()); for (size_t i = 0; i < str.size(); i++) - s2[i] = tolower(str[i]); + s2[i] = my_tolower(str[i]); return s2; } From bb6782ca58a8a23709cfe0b0e9083ef8f50377b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Sat, 30 Mar 2024 11:05:58 +0100 Subject: [PATCH 72/91] Add repeat_dig_time setting (#14295) --- builtin/settingtypes.txt | 6 +++++- src/client/game.cpp | 22 +++++++++++++++------- src/defaultsettings.cpp | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 57420ec15..517a83012 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -114,7 +114,11 @@ always_fly_fast (Always fly fast) bool true # the place button. # # Requires: keyboard_mouse -repeat_place_time (Place repetition interval) float 0.25 0.16 2 +repeat_place_time (Place repetition interval) float 0.25 0.15 2.0 + +# The minimum time in seconds it takes between digging nodes when holding +# the dig button. +repeat_dig_time (Dig repetition interval) float 0.15 0.15 2.0 # Automatically jump up single-node obstacles. autojump (Automatic jumping) bool false diff --git a/src/client/game.cpp b/src/client/game.cpp index 849e7702a..67529681b 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -939,6 +939,7 @@ private: f32 m_cache_mouse_sensitivity; f32 m_cache_joystick_frustum_sensitivity; f32 m_repeat_place_time; + f32 m_repeat_dig_time; f32 m_cache_cam_smoothing; bool m_invert_mouse; @@ -985,6 +986,8 @@ Game::Game() : &settingChangedCallback, this); g_settings->registerChangedCallback("repeat_place_time", &settingChangedCallback, this); + g_settings->registerChangedCallback("repeat_dig_time", + &settingChangedCallback, this); g_settings->registerChangedCallback("noclip", &settingChangedCallback, this); g_settings->registerChangedCallback("free_move", @@ -1051,6 +1054,8 @@ Game::~Game() &settingChangedCallback, this); g_settings->deregisterChangedCallback("repeat_place_time", &settingChangedCallback, this); + g_settings->deregisterChangedCallback("repeat_dig_time", + &settingChangedCallback, this); g_settings->deregisterChangedCallback("noclip", &settingChangedCallback, this); g_settings->deregisterChangedCallback("free_move", @@ -3912,12 +3917,14 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, runData.nodig_delay_timer = runData.dig_time_complete / (float)crack_animation_length; - // We don't want a corresponding delay to very time consuming nodes - // and nodes without digging time (e.g. torches) get a fixed delay. - if (runData.nodig_delay_timer > 0.3) - runData.nodig_delay_timer = 0.3; - else if (runData.dig_instantly) - runData.nodig_delay_timer = 0.15; + // Don't add a corresponding delay to very time consuming nodes. + runData.nodig_delay_timer = std::min(runData.nodig_delay_timer, 0.3f); + + // Ensure that the delay between breaking nodes + // (dig_time_complete + nodig_delay_timer) is at least the + // value of the repeat_dig_time setting. + runData.nodig_delay_timer = std::max(runData.nodig_delay_timer, + m_repeat_dig_time - runData.dig_time_complete); if (client->modsLoaded() && client->getScript()->on_dignode(nodepos, n)) { @@ -4315,7 +4322,8 @@ void Game::readSettings() m_cache_enable_fog = g_settings->getBool("enable_fog"); m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity", 0.001f, 10.0f); m_cache_joystick_frustum_sensitivity = std::max(g_settings->getFloat("joystick_frustum_sensitivity"), 0.001f); - m_repeat_place_time = g_settings->getFloat("repeat_place_time", 0.16f, 2.0); + m_repeat_place_time = g_settings->getFloat("repeat_place_time", 0.15f, 2.0f); + m_repeat_dig_time = g_settings->getFloat("repeat_dig_time", 0.15f, 2.0f); m_cache_enable_noclip = g_settings->getBool("noclip"); m_cache_enable_free_move = g_settings->getBool("free_move"); diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index d4942a4f5..e018e591b 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -301,6 +301,7 @@ void set_default_settings() settings->setDefault("invert_hotbar_mouse_wheel", "false"); settings->setDefault("mouse_sensitivity", "0.2"); settings->setDefault("repeat_place_time", "0.25"); + settings->setDefault("repeat_dig_time", "0.15"); settings->setDefault("safe_dig_and_place", "false"); settings->setDefault("random_input", "false"); settings->setDefault("aux1_descends", "false"); From 6c6e48f00607233ae6cb3cf37fa4544d727aacf2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 30 Mar 2024 11:06:28 +0100 Subject: [PATCH 73/91] Move values the mainmenu caches to dedicated files (#14433) --- builtin/mainmenu/common.lua | 35 ++++++++-- builtin/mainmenu/content/update_detector.lua | 21 ++++-- builtin/mainmenu/dlg_reinstall_mtg.lua | 23 ++++-- builtin/mainmenu/dlg_version_info.lua | 23 +++--- builtin/mainmenu/init.lua | 2 - builtin/mainmenu/misc.lua | 6 -- builtin/mainmenu/serverlistmgr.lua | 70 +++++++++++-------- builtin/mainmenu/tests/serverlistmgr_spec.lua | 3 +- builtin/settingtypes.txt | 15 +--- doc/menu_lua_api.md | 4 -- src/defaultsettings.cpp | 5 +- src/gui/guiEngine.cpp | 2 + src/script/lua_api/l_mainmenu.cpp | 40 ----------- src/script/lua_api/l_mainmenu.h | 4 -- src/script/scripting_mainmenu.cpp | 18 +++-- src/script/scripting_mainmenu.h | 3 + 16 files changed, 142 insertions(+), 132 deletions(-) delete mode 100644 builtin/mainmenu/misc.lua diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 471360581..16c5c9d95 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -18,6 +18,26 @@ -- Global menu data menudata = {} +-- located in user cache path, for remembering this like e.g. last update check +cache_settings = Settings(core.get_cache_path() .. DIR_DELIM .. "common.conf") + +--- Checks if the given key contains a timestamp less than a certain age. +--- Pair this with a call to `cache_settings:set(key, tostring(os.time()))` +--- after successfully refreshing the cache. +--- @param key Name of entry in cache_settings +--- @param max_age Age to check against, in seconds +--- @return true if the max age is not reached +function check_cache_age(key, max_age) + local time_now = os.time() + local time_checked = tonumber(cache_settings:get(key)) or 0 + return time_now - time_checked < max_age +end + +function core.on_before_close() + -- called before the menu is closed, either exit or to join a game + cache_settings:write() +end + -- Local cached values local min_supp_proto, max_supp_proto @@ -27,6 +47,16 @@ function common_update_cached_supp_proto() end common_update_cached_supp_proto() +-- Other global functions + +function core.sound_stop(handle, ...) + return handle:stop(...) +end + +function os.tmpname() + error('do not use') -- instead: core.get_temp_path() +end + -- Menu helper functions local function render_client_count(n) @@ -140,11 +170,6 @@ function render_serverlist_row(spec) return table.concat(details, ",") end ---------------------------------------------------------------------------------- -os.tmpname = function() - error('do not use') -- instead use core.get_temp_path() -end --------------------------------------------------------------------------------- function menu_render_worldlist() local retval = {} diff --git a/builtin/mainmenu/content/update_detector.lua b/builtin/mainmenu/content/update_detector.lua index 558a0fabb..f70220224 100644 --- a/builtin/mainmenu/content/update_detector.lua +++ b/builtin/mainmenu/content/update_detector.lua @@ -26,13 +26,23 @@ if not core.get_http_api then end +assert(core.create_dir(core.get_cache_path() .. DIR_DELIM .. "cdb")) +local cache_file_path = core.get_cache_path() .. DIR_DELIM .. "cdb" .. DIR_DELIM .. "updates.json" local has_fetched = false local latest_releases do - local tmp = core.get_once("cdb_latest_releases") - if tmp then - latest_releases = core.deserialize(tmp, true) - has_fetched = latest_releases ~= nil + if check_cache_age("cdb_updates_last_checked", 3 * 3600) then + local f = io.open(cache_file_path, "r") + local data = "" + if f then + data = f:read("*a") + f:close() + end + data = data ~= "" and core.parse_json(data) or nil + if type(data) == "table" then + latest_releases = data + has_fetched = true + end end end @@ -97,7 +107,8 @@ local function fetch() return end latest_releases = lowercase_keys(releases) - core.set_once("cdb_latest_releases", core.serialize(latest_releases)) + core.safe_file_write(cache_file_path, core.write_json(latest_releases)) + cache_settings:set("cdb_updates_last_checked", tostring(os.time())) if update_detector.get_count() > 0 then local maintab = ui.find_by_name("maintab") diff --git a/builtin/mainmenu/dlg_reinstall_mtg.lua b/builtin/mainmenu/dlg_reinstall_mtg.lua index 77652e968..c86c75d2b 100644 --- a/builtin/mainmenu/dlg_reinstall_mtg.lua +++ b/builtin/mainmenu/dlg_reinstall_mtg.lua @@ -15,15 +15,30 @@ --with this program; if not, write to the Free Software Foundation, Inc., --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +---- IMPORTANT ---- +-- This whole file can be removed after a while. +-- It was only directly useful for upgrades from 5.7.0 to 5.8.0, but +-- maybe some odd fellow directly upgrades from 5.6.1 to 5.9.0 in the future... +-- see in case it's not obvious +---- ---- + +local SETTING_NAME = "no_mtg_notification" + function check_reinstall_mtg() - if core.settings:get_bool("no_mtg_notification") then + -- used to be in minetest.conf + if core.settings:get_bool(SETTING_NAME) then + cache_settings:set_bool(SETTING_NAME, true) + core.settings:remove(SETTING_NAME) + end + + if cache_settings:get_bool(SETTING_NAME) then return end local games = core.get_games() for _, game in ipairs(games) do if game.id == "minetest" then - core.settings:set_bool("no_mtg_notification", true) + cache_settings:set_bool(SETTING_NAME, true) return end end @@ -37,7 +52,7 @@ function check_reinstall_mtg() end end if not mtg_world_found then - core.settings:set_bool("no_mtg_notification", true) + cache_settings:set_bool(SETTING_NAME, true) return end @@ -87,7 +102,7 @@ local function buttonhandler(this, fields) end if fields.dismiss then - core.settings:set_bool("no_mtg_notification", true) + cache_settings:set_bool("no_mtg_notification", true) this:delete() return true end diff --git a/builtin/mainmenu/dlg_version_info.lua b/builtin/mainmenu/dlg_version_info.lua index 98085ee4a..483cd30bd 100644 --- a/builtin/mainmenu/dlg_version_info.lua +++ b/builtin/mainmenu/dlg_version_info.lua @@ -51,12 +51,13 @@ end local function version_info_buttonhandler(this, fields) if fields.version_check_remind then -- Erase last known, user will be reminded again at next check - core.settings:set("update_last_known", "") + cache_settings:set("update_last_known", "") this:delete() return true end if fields.version_check_never then - core.settings:set("update_last_checked", "disabled") + -- clear checked URL + core.settings:set("update_information_url", "") this:delete() return true end @@ -116,7 +117,7 @@ local function on_version_info_received(json) return end - local known_update = tonumber(core.settings:get("update_last_known")) or 0 + local known_update = tonumber(cache_settings:get("update_last_known")) or 0 -- Format: MMNNPPP (Major, Minor, Patch) local new_number = type(json.latest) == "table" and json.latest.version_code @@ -135,7 +136,7 @@ local function on_version_info_received(json) return end - core.settings:set("update_last_known", tostring(new_number)) + cache_settings:set("update_last_known", tostring(new_number)) -- Show version info dialog (once) maintab:hide() @@ -149,20 +150,20 @@ end function check_new_version() local url = core.settings:get("update_information_url") - if core.settings:get("update_last_checked") == "disabled" or - url == "" then + if url == "" then -- Never show any updates return end - local time_now = os.time() - local time_checked = tonumber(core.settings:get("update_last_checked")) or 0 - if time_now - time_checked < 2 * 24 * 3600 then - -- Check interval of 2 entire days + -- every 2 days + if check_cache_age("update_last_checked", 2 * 24 * 3600) then return end + cache_settings:set("update_last_checked", tostring(os.time())) - core.settings:set("update_last_checked", tostring(time_now)) + -- Clean old leftovers (this can be removed after 5.9.0 or so) + core.settings:remove("update_last_checked") + core.settings:remove("update_last_known") core.handle_async(function(params) local http = core.get_http_api() diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 388ab458d..41885e298 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -28,8 +28,6 @@ local basepath = core.get_builtin_path() defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" .. DIR_DELIM .. "pack" .. DIR_DELIM -dofile(menupath .. DIR_DELIM .. "misc.lua") - dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua") dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua") dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua") diff --git a/builtin/mainmenu/misc.lua b/builtin/mainmenu/misc.lua deleted file mode 100644 index 0677e96a3..000000000 --- a/builtin/mainmenu/misc.lua +++ /dev/null @@ -1,6 +0,0 @@ - --- old non-method sound function - -function core.sound_stop(handle, ...) - return handle:stop(...) -end diff --git a/builtin/mainmenu/serverlistmgr.lua b/builtin/mainmenu/serverlistmgr.lua index ab686ded0..997768c15 100644 --- a/builtin/mainmenu/serverlistmgr.lua +++ b/builtin/mainmenu/serverlistmgr.lua @@ -17,7 +17,7 @@ serverlistmgr = { -- continent code we detected for ourselves - my_continent = core.get_once("continent"), + my_continent = nil, -- list of locally favorites servers favorites = nil, @@ -26,6 +26,15 @@ serverlistmgr = { servers = nil, } +do + if check_cache_age("geoip_last_checked", 3600) then + local tmp = cache_settings:get("geoip") or "" + if tmp:match("^[A-Z][A-Z]$") then + serverlistmgr.my_continent = tmp + end + end +end + -------------------------------------------------------------------------------- -- Efficient data structure for normalizing arbitrary scores attached to objects -- e.g. {{"a", 3.14}, {"b", 3.14}, {"c", 20}, {"d", 0}} @@ -112,6 +121,22 @@ local public_downloading = false local geoip_downloading = false -------------------------------------------------------------------------------- +local function fetch_geoip() + local http = core.get_http_api() + local url = core.settings:get("serverlist_url") .. "/geoip" + + local response = http.fetch_sync({ url = url }) + if not response.succeeded then + return + end + + local retval = core.parse_json(response.data) + if type(retval) ~= "table" then + return + end + return type(retval.continent) == "string" and retval.continent +end + function serverlistmgr.sync() if not serverlistmgr.servers then serverlistmgr.servers = {{ @@ -129,37 +154,23 @@ function serverlistmgr.sync() return end - -- only fetched once per MT instance if not serverlistmgr.my_continent and not geoip_downloading then geoip_downloading = true - core.handle_async( - function(param) - local http = core.get_http_api() - local url = core.settings:get("serverlist_url") .. "/geoip" - - local response = http.fetch_sync({ url = url }) - if not response.succeeded then - return - end - - local retval = core.parse_json(response.data) - return retval and type(retval.continent) == "string" and retval.continent - end, - nil, - function(result) - geoip_downloading = false - if not result then - return - end - serverlistmgr.my_continent = result - core.set_once("continent", result) - -- reorder list if we already have it - if serverlistmgr.servers then - serverlistmgr.servers = order_server_list(serverlistmgr.servers) - core.event_handler("Refresh") - end + core.handle_async(fetch_geoip, nil, function(result) + geoip_downloading = false + if not result then + return end - ) + serverlistmgr.my_continent = result + cache_settings:set("geoip", result) + cache_settings:set("geoip_last_checked", tostring(os.time())) + + -- re-sort list if applicable + if serverlistmgr.servers then + serverlistmgr.servers = order_server_list(serverlistmgr.servers) + core.event_handler("Refresh") + end + end) end if public_downloading then @@ -167,6 +178,7 @@ function serverlistmgr.sync() end public_downloading = true + -- note: this isn't cached because it's way too dynamic core.handle_async( function(param) local http = core.get_http_api() diff --git a/builtin/mainmenu/tests/serverlistmgr_spec.lua b/builtin/mainmenu/tests/serverlistmgr_spec.lua index 25e208d10..21ce8a226 100644 --- a/builtin/mainmenu/tests/serverlistmgr_spec.lua +++ b/builtin/mainmenu/tests/serverlistmgr_spec.lua @@ -1,5 +1,6 @@ -_G.core = {get_once = function(_) end} +_G.core = {} _G.unpack = table.unpack +_G.check_cache_age = function() return false end _G.serverlistmgr = {} dofile("builtin/common/vector.lua") diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 517a83012..b039780bc 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -776,6 +776,7 @@ serverlist_url (Serverlist URL) string servers.minetest.net enable_split_login_register (Enable split login/register) bool true # URL to JSON file which provides information about the newest Minetest release +# If this is empty the engine will never check for updates. update_information_url (Update information URL) string https://www.minetest.net/release_info.json [*Server] @@ -2291,20 +2292,6 @@ show_advanced (Show advanced settings) bool false # Changing this setting requires a restart. enable_sound (Sound) bool true -# Unix timestamp (integer) of when the client last checked for an update -# Set this value to "disabled" to never check for updates. -update_last_checked (Last update check) string - -# Version number which was last seen during an update check. -# -# Representation: MMMIIIPPP, where M=Major, I=Minor, P=Patch -# Ex: 5.5.0 is 005005000 -update_last_known (Last known version update) int 0 - -# If this is set to true, the user will never (again) be shown the -# "reinstall Minetest Game" notification. -no_mtg_notification (Don't show "reinstall Minetest Game" notification) bool false - # Key for moving the player forward. keymap_forward (Forward key) key KEY_KEY_W diff --git a/doc/menu_lua_api.md b/doc/menu_lua_api.md index 3e8bb3583..979ef868f 100644 --- a/doc/menu_lua_api.md +++ b/doc/menu_lua_api.md @@ -55,10 +55,6 @@ Functions * Android only. Shares file using the share popup * `core.get_version()` (possible in async calls) * returns current core version -* `core.set_once(key, value)`: - * save a string value that persists even if menu is closed -* `core.get_once(key)`: - * get a string value saved by above function, or `nil` diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index e018e591b..bb50a00aa 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -356,11 +356,10 @@ void set_default_settings() settings->setDefault("contentdb_flag_blacklist", "nonfree, desktop_default"); #endif - settings->setDefault("update_information_url", "https://www.minetest.net/release_info.json"); #if ENABLE_UPDATE_CHECKER - settings->setDefault("update_last_checked", ""); + settings->setDefault("update_information_url", "https://www.minetest.net/release_info.json"); #else - settings->setDefault("update_last_checked", "disabled"); + settings->setDefault("update_information_url", ""); #endif // Server diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index ea74f6afa..4d35f38ab 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -369,6 +369,8 @@ void GUIEngine::run() #endif } + m_script->beforeClose(); + RenderingEngine::autosaveScreensizeAndCo(initial_screen_size, initial_window_maximized); } diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index c98f974d2..fdb9e3740 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -1080,44 +1080,6 @@ int ModApiMainMenu::l_do_async_callback(lua_State *L) return 1; } -/******************************************************************************/ -// this is intentionally a global and not part of MainMenuScripting or such -namespace { - std::unordered_map once_values; - std::mutex once_mutex; -} - -int ModApiMainMenu::l_set_once(lua_State *L) -{ - std::string key = readParam(L, 1); - if (lua_isnil(L, 2)) - return 0; - std::string value = readParam(L, 2); - - { - MutexAutoLock lock(once_mutex); - once_values[key] = value; - } - - return 0; -} - -int ModApiMainMenu::l_get_once(lua_State *L) -{ - std::string key = readParam(L, 1); - - { - MutexAutoLock lock(once_mutex); - auto it = once_values.find(key); - if (it == once_values.end()) - lua_pushnil(L); - else - lua_pushstring(L, it->second.c_str()); - } - - return 1; -} - /******************************************************************************/ void ModApiMainMenu::Initialize(lua_State *L, int top) { @@ -1170,8 +1132,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(open_dir); API_FCT(share_file); API_FCT(do_async_callback); - API_FCT(set_once); - API_FCT(get_once); } /******************************************************************************/ diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index 780e3b5b8..5535d2170 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -166,10 +166,6 @@ private: static int l_share_file(lua_State *L); - static int l_set_once(lua_State *L); - - static int l_get_once(lua_State *L); - // async static int l_do_async_callback(lua_State *L); diff --git a/src/script/scripting_mainmenu.cpp b/src/script/scripting_mainmenu.cpp index d88082b7d..e5cb81cab 100644 --- a/src/script/scripting_mainmenu.cpp +++ b/src/script/scripting_mainmenu.cpp @@ -58,7 +58,6 @@ MainMenuScripting::MainMenuScripting(GUIEngine* guiengine): infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl; } -/******************************************************************************/ void MainMenuScripting::initializeModApi(lua_State *L, int top) { registerLuaClasses(L, top); @@ -79,20 +78,31 @@ void MainMenuScripting::initializeModApi(lua_State *L, int top) asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS); } -/******************************************************************************/ void MainMenuScripting::registerLuaClasses(lua_State *L, int top) { LuaSettings::Register(L); MainMenuSoundHandle::Register(L); } -/******************************************************************************/ +void MainMenuScripting::beforeClose() +{ + SCRIPTAPI_PRECHECKHEADER + + int error_handler = PUSH_ERROR_HANDLER(L); + + lua_getglobal(L, "core"); + lua_getfield(L, -1, "on_before_close"); + + PCALL_RES(lua_pcall(L, 0, 0, error_handler)); + + lua_pop(L, 2); // Pop core, error handler +} + void MainMenuScripting::step() { asyncEngine.step(getStack()); } -/******************************************************************************/ u32 MainMenuScripting::queueAsync(std::string &&serialized_func, std::string &&serialized_param) { diff --git a/src/script/scripting_mainmenu.h b/src/script/scripting_mainmenu.h index 3c329654a..d2e5716e2 100644 --- a/src/script/scripting_mainmenu.h +++ b/src/script/scripting_mainmenu.h @@ -37,6 +37,9 @@ public: // Global step handler to pass back async events void step(); + // Calls core.on_before_close() + void beforeClose(); + // Pass async events from engine to async threads u32 queueAsync(std::string &&serialized_func, std::string &&serialized_param); From 6ac053bbaadc30f1313bbbf1db25667e273d4ce8 Mon Sep 17 00:00:00 2001 From: cx384 Date: Sun, 17 Mar 2024 14:09:25 +0100 Subject: [PATCH 74/91] Extract image generation/cache from texturesource.cpp --- src/client/CMakeLists.txt | 1 + src/client/imagesource.cpp | 1975 ++++++++++++++++++++++++++++++++++ src/client/imagesource.h | 84 ++ src/client/texturesource.cpp | 1961 +-------------------------------- 4 files changed, 2069 insertions(+), 1952 deletions(-) create mode 100644 src/client/imagesource.cpp create mode 100644 src/client/imagesource.h diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index f2aa511b7..d451d0911 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -69,6 +69,7 @@ set(client_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/texturepaths.cpp ${CMAKE_CURRENT_SOURCE_DIR}/texturesource.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/imagesource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wieldmesh.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadows.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadowsrender.cpp diff --git a/src/client/imagesource.cpp b/src/client/imagesource.cpp new file mode 100644 index 000000000..92da3ee27 --- /dev/null +++ b/src/client/imagesource.cpp @@ -0,0 +1,1975 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "imagesource.h" + +#include +#include "settings.h" +#include "mesh.h" +#include "util/strfnd.h" +#include "renderingengine.h" +#include "util/base64.h" +#include "irrlicht_changes/printing.h" +#include "imagefilters.h" +#include "texturepaths.h" +#include "util/numeric.h" + + +//////////////////////////////// +// SourceImageCache Functions // +//////////////////////////////// + +SourceImageCache::~SourceImageCache() { + for (auto &m_image : m_images) { + m_image.second->drop(); + } + m_images.clear(); +} + +void SourceImageCache::insert(const std::string &name, video::IImage *img, bool prefer_local) +{ + assert(img); // Pre-condition + // Remove old image + std::map::iterator n; + n = m_images.find(name); + if (n != m_images.end()){ + if (n->second) + n->second->drop(); + } + + video::IImage* toadd = img; + bool need_to_grab = true; + + // Try to use local texture instead if asked to + if (prefer_local) { + bool is_base_pack; + std::string path = getTexturePath(name, &is_base_pack); + // Ignore base pack + if (!path.empty() && !is_base_pack) { + video::IImage *img2 = RenderingEngine::get_video_driver()-> + createImageFromFile(path.c_str()); + if (img2){ + toadd = img2; + need_to_grab = false; + } + } + } + + if (need_to_grab) + toadd->grab(); + m_images[name] = toadd; +} +video::IImage* SourceImageCache::get(const std::string &name) +{ + std::map::iterator n; + n = m_images.find(name); + if (n != m_images.end()) + return n->second; + return NULL; +} + +// Primarily fetches from cache, secondarily tries to read from filesystem +video::IImage* SourceImageCache::getOrLoad(const std::string &name) +{ + std::map::iterator n; + n = m_images.find(name); + if (n != m_images.end()){ + n->second->grab(); // Grab for caller + return n->second; + } + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + std::string path = getTexturePath(name); + if (path.empty()) { + infostream<<"SourceImageCache::getOrLoad(): No path found for \"" + <createImageFromFile(path.c_str()); + + if (img){ + m_images[name] = img; + img->grab(); // Grab for caller + } + return img; +} + + +//////////////////////////// +// Image Helper Functions // +//////////////////////////// + + +/** Draw an image on top of another one with gamma-incorrect alpha compositing + * + * This exists because IImage::copyToWithAlpha() doesn't seem to always work. + * + * \tparam overlay If enabled, only modify pixels in dst which are fully opaque. + * Defaults to false. + * \param src Top image. This image must have the ECF_A8R8G8B8 color format. + * \param dst Bottom image. + * The top image is drawn onto this base image in-place. + * \param dst_pos An offset vector to move src before drawing it onto dst + * \param size Size limit of the copied area +*/ +template +static void blit_with_alpha(video::IImage *src, video::IImage *dst, + v2s32 dst_pos, v2u32 size); + +// Apply a color to an image. Uses an int (0-255) to calculate the ratio. +// If the ratio is 255 or -1 and keep_alpha is true, then it multiples the +// color alpha with the destination alpha. +// Otherwise, any pixels that are not fully transparent get the color alpha. +static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color, int ratio, bool keep_alpha); + +// paint a texture using the given color +static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color); + +// Perform a Screen blend with the given color. The opposite effect of a +// Multiply blend. +static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color); + +// Adjust the hue, saturation, and lightness of destination. Like +// "Hue-Saturation" in GIMP. +// If colorize is true then the image will be converted to a grayscale +// image as though seen through a colored glass, like "Colorize" in GIMP. +static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 hue, s32 saturation, s32 lightness, bool colorize); + +// Apply an overlay blend to an images. +// Overlay blend combines Multiply and Screen blend modes.The parts of the top +// layer where the base layer is light become lighter, the parts where the base +// layer is dark become darker.Areas where the base layer are mid grey are +// unaffected.An overlay with the same picture looks like an S - curve. +static void apply_overlay(video::IImage *overlay, video::IImage *dst, + v2s32 overlay_pos, v2s32 dst_pos, v2u32 size, bool hardlight); + +// Adjust the brightness and contrast of the base image. Conceptually like +// "Brightness-Contrast" in GIMP but allowing brightness to be wound all the +// way up to white or down to black. +static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 brightness, s32 contrast); + +// Apply a mask to an image +static void apply_mask(video::IImage *mask, video::IImage *dst, + v2s32 mask_pos, v2s32 dst_pos, v2u32 size); + +// Draw or overlay a crack +static void draw_crack(video::IImage *crack, video::IImage *dst, + bool use_overlay, s32 frame_count, s32 progression, + video::IVideoDriver *driver, u8 tiles = 1); + +// Brighten image +void brighten(video::IImage *image); +// Parse a transform name +u32 parseImageTransform(std::string_view s); +// Apply transform to image dimension +core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim); +// Apply transform to image data +void imageTransform(u32 transform, video::IImage *src, video::IImage *dst); + +inline static void applyShadeFactor(video::SColor &color, u32 factor) +{ + u32 f = core::clamp(factor, 0, 256); + color.setRed(color.getRed() * f / 256); + color.setGreen(color.getGreen() * f / 256); + color.setBlue(color.getBlue() * f / 256); +} + +static video::IImage *createInventoryCubeImage( + video::IImage *top, video::IImage *left, video::IImage *right) +{ + core::dimension2du size_top = top->getDimension(); + core::dimension2du size_left = left->getDimension(); + core::dimension2du size_right = right->getDimension(); + + u32 size = npot2(std::max({ + size_top.Width, size_top.Height, + size_left.Width, size_left.Height, + size_right.Width, size_right.Height, + })); + + // It must be divisible by 4, to let everything work correctly. + // But it is a power of 2, so being at least 4 is the same. + // And the resulting texture should't be too large as well. + size = core::clamp(size, 4, 64); + + // With such parameters, the cube fits exactly, touching each image line + // from `0` to `cube_size - 1`. (Note that division is exact here). + u32 cube_size = 9 * size; + u32 offset = size / 2; + + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + + auto lock_image = [size, driver] (video::IImage *&image) -> const u32 * { + image->grab(); + core::dimension2du dim = image->getDimension(); + video::ECOLOR_FORMAT format = image->getColorFormat(); + if (dim.Width != size || dim.Height != size || format != video::ECF_A8R8G8B8) { + video::IImage *scaled = driver->createImage(video::ECF_A8R8G8B8, {size, size}); + image->copyToScaling(scaled); + image->drop(); + image = scaled; + } + sanity_check(image->getPitch() == 4 * size); + return reinterpret_cast(image->getData()); + }; + auto free_image = [] (video::IImage *image) -> void { + image->drop(); + }; + + video::IImage *result = driver->createImage(video::ECF_A8R8G8B8, {cube_size, cube_size}); + sanity_check(result->getPitch() == 4 * cube_size); + result->fill(video::SColor(0x00000000u)); + u32 *target = reinterpret_cast(result->getData()); + + // Draws single cube face + // `shade_factor` is face brightness, in range [0.0, 1.0] + // (xu, xv, x1; yu, yv, y1) form coordinate transformation matrix + // `offsets` list pixels to be drawn for single source pixel + auto draw_image = [=] (video::IImage *image, float shade_factor, + s16 xu, s16 xv, s16 x1, + s16 yu, s16 yv, s16 y1, + std::initializer_list offsets) -> void { + u32 brightness = core::clamp(256 * shade_factor, 0, 256); + const u32 *source = lock_image(image); + for (u16 v = 0; v < size; v++) { + for (u16 u = 0; u < size; u++) { + video::SColor pixel(*source); + applyShadeFactor(pixel, brightness); + s16 x = xu * u + xv * v + x1; + s16 y = yu * u + yv * v + y1; + for (const auto &off : offsets) + target[(y + off.Y) * cube_size + (x + off.X) + offset] = pixel.color; + source++; + } + } + free_image(image); + }; + + draw_image(top, 1.000000f, + 4, -4, 4 * (size - 1), + 2, 2, 0, + { + {2, 0}, {3, 0}, {4, 0}, {5, 0}, + {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, + {2, 2}, {3, 2}, {4, 2}, {5, 2}, + }); + + draw_image(left, 0.836660f, + 4, 0, 0, + 2, 5, 2 * size, + { + {0, 0}, {1, 0}, + {0, 1}, {1, 1}, {2, 1}, {3, 1}, + {0, 2}, {1, 2}, {2, 2}, {3, 2}, + {0, 3}, {1, 3}, {2, 3}, {3, 3}, + {0, 4}, {1, 4}, {2, 4}, {3, 4}, + {2, 5}, {3, 5}, + }); + + draw_image(right, 0.670820f, + 4, 0, 4 * size, + -2, 5, 4 * size - 2, + { + {2, 0}, {3, 0}, + {0, 1}, {1, 1}, {2, 1}, {3, 1}, + {0, 2}, {1, 2}, {2, 2}, {3, 2}, + {0, 3}, {1, 3}, {2, 3}, {3, 3}, + {0, 4}, {1, 4}, {2, 4}, {3, 4}, + {0, 5}, {1, 5}, + }); + + return result; +} + +static std::string unescape_string(const std::string &str, const char esc = '\\') +{ + std::string out; + size_t pos = 0, cpos; + out.reserve(str.size()); + while (1) { + cpos = str.find_first_of(esc, pos); + if (cpos == std::string::npos) { + out += str.substr(pos); + break; + } + out += str.substr(pos, cpos - pos) + str[cpos + 1]; + pos = cpos + 2; + } + return out; +} + +/* + Replaces the smaller of the two images with one upscaled to match the + dimensions of the other. + Ensure no other references to these images are being held, as one may + get dropped and switched with a new image. +*/ +void upscaleImagesToMatchLargest(video::IImage *& img1, + video::IImage *& img2) +{ + core::dimension2d dim1 = img1->getDimension(); + core::dimension2d dim2 = img2->getDimension(); + + if (dim1 == dim2) { + // image dimensions match, no scaling required + + } + else if (dim1.Width * dim1.Height < dim2.Width * dim2.Height) { + // Upscale img1 + video::IImage *scaled_image = RenderingEngine::get_video_driver()-> + createImage(video::ECF_A8R8G8B8, dim2); + img1->copyToScaling(scaled_image); + img1->drop(); + img1 = scaled_image; + + } else { + // Upscale img2 + video::IImage *scaled_image = RenderingEngine::get_video_driver()-> + createImage(video::ECF_A8R8G8B8, dim1); + img2->copyToScaling(scaled_image); + img2->drop(); + img2 = scaled_image; + } +} + +void blitBaseImage(video::IImage* &src, video::IImage* &dst) +{ + //infostream<<"Blitting "< dim_dst = dst->getDimension(); + // Position to copy the blitted to in the base image + core::position2d pos_to(0,0); + + blit_with_alpha(src, dst, pos_to, dim_dst); +} + + +namespace { + +/** Calculate the color of a single pixel drawn on top of another pixel without + * gamma correction + * + * The color mixing is a little more complicated than just + * video::SColor::getInterpolated because getInterpolated does not handle alpha + * correctly. + * For example, a pixel with alpha=64 drawn atop a pixel with alpha=128 should + * yield a pixel with alpha=160, while getInterpolated would yield alpha=96. + * + * \tparam overlay If enabled, only modify dst_col if it is fully opaque + * \param src_col Color of the top pixel + * \param dst_col Color of the bottom pixel. This color is modified in-place to + * store the result. +*/ +template +void blit_pixel(video::SColor src_col, video::SColor &dst_col) +{ + u8 dst_a = (u8)dst_col.getAlpha(); + if constexpr (overlay) { + if (dst_a != 255) + // The bottom pixel has transparency -> do nothing + return; + } + u8 src_a = (u8)src_col.getAlpha(); + if (src_a == 0) { + // A fully transparent pixel is on top -> do nothing + return; + } + if (src_a == 255 || dst_a == 0) { + // The top pixel is fully opaque or the bottom pixel is + // fully transparent -> replace the color + dst_col = src_col; + return; + } + struct Color { u8 r, g, b; }; + Color src{(u8)src_col.getRed(), (u8)src_col.getGreen(), + (u8)src_col.getBlue()}; + Color dst{(u8)dst_col.getRed(), (u8)dst_col.getGreen(), + (u8)dst_col.getBlue()}; + if (dst_a == 255) { + // A semi-transparent pixel is on top and an opaque one in + // the bottom -> lerp r, g, and b + dst.r = (dst.r * (255 - src_a) + src.r * src_a) / 255; + dst.g = (dst.g * (255 - src_a) + src.g * src_a) / 255; + dst.b = (dst.b * (255 - src_a) + src.b * src_a) / 255; + dst_col.set(255, dst.r, dst.g, dst.b); + return; + } + // A semi-transparent pixel is on top of a + // semi-transparent pixel -> general alpha compositing + u16 a_new_255 = src_a * 255 + (255 - src_a) * dst_a; + dst.r = (dst.r * (255 - src_a) * dst_a + src.r * src_a * 255) / a_new_255; + dst.g = (dst.g * (255 - src_a) * dst_a + src.g * src_a * 255) / a_new_255; + dst.b = (dst.b * (255 - src_a) * dst_a + src.b * src_a * 255) / a_new_255; + dst_a = (a_new_255 + 127) / 255; + dst_col.set(dst_a, dst.r, dst.g, dst.b); +} + +} // namespace +template +void blit_with_alpha(video::IImage *src, video::IImage *dst, v2s32 dst_pos, + v2u32 size) +{ + if (dst->getColorFormat() != video::ECF_A8R8G8B8) + throw BaseException("blit_with_alpha() supports only ECF_A8R8G8B8 " + "destination images."); + + core::dimension2d src_dim = src->getDimension(); + core::dimension2d dst_dim = dst->getDimension(); + bool drop_src = false; + if (src->getColorFormat() != video::ECF_A8R8G8B8) { + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::IImage *src_converted = driver->createImage(video::ECF_A8R8G8B8, + src_dim); + if (!src_converted) + throw BaseException("blit_with_alpha() failed to convert the " + "source image to ECF_A8R8G8B8."); + src->copyTo(src_converted); + src = src_converted; + drop_src = true; + } + video::SColor *pixels_src = + reinterpret_cast(src->getData()); + video::SColor *pixels_dst = + reinterpret_cast(dst->getData()); + // Limit y and x to the overlapping ranges + // s.t. the positions are all in bounds after offsetting. + u32 x_start = (u32)std::max(0, -dst_pos.X); + u32 y_start = (u32)std::max(0, -dst_pos.Y); + u32 x_end = (u32)std::min({size.X, src_dim.Width, + dst_dim.Width - (s64)dst_pos.X}); + u32 y_end = (u32)std::min({size.Y, src_dim.Height, + dst_dim.Height - (s64)dst_pos.Y}); + for (u32 y0 = y_start; y0 < y_end; ++y0) { + size_t i_src = y0 * src_dim.Width + x_start; + size_t i_dst = (dst_pos.Y + y0) * dst_dim.Width + dst_pos.X + x_start; + for (u32 x0 = x_start; x0 < x_end; ++x0) { + blit_pixel(pixels_src[i_src++], pixels_dst[i_dst++]); + } + } + if (drop_src) + src->drop(); +} + +/* + Apply color to destination, using a weighted interpolation blend +*/ +static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color, int ratio, bool keep_alpha) +{ + u32 alpha = color.getAlpha(); + video::SColor dst_c; + if ((ratio == -1 && alpha == 255) || ratio == 255) { // full replacement of color + if (keep_alpha) { // replace the color with alpha = dest alpha * color alpha + dst_c = color; + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + u32 dst_alpha = dst->getPixel(x, y).getAlpha(); + if (dst_alpha > 0) { + dst_c.setAlpha(dst_alpha * alpha / 255); + dst->setPixel(x, y, dst_c); + } + } + } else { // replace the color including the alpha + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) + if (dst->getPixel(x, y).getAlpha() > 0) + dst->setPixel(x, y, color); + } + } else { // interpolate between the color and destination + float interp = (ratio == -1 ? color.getAlpha() / 255.0f : ratio / 255.0f); + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + if (dst_c.getAlpha() > 0) { + dst_c = color.getInterpolated(dst_c, interp); + dst->setPixel(x, y, dst_c); + } + } + } +} + +/* + Apply color to destination, using a Multiply blend mode +*/ +static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color) +{ + video::SColor dst_c; + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + dst_c.set( + dst_c.getAlpha(), + (dst_c.getRed() * color.getRed()) / 255, + (dst_c.getGreen() * color.getGreen()) / 255, + (dst_c.getBlue() * color.getBlue()) / 255 + ); + dst->setPixel(x, y, dst_c); + } +} + +/* + Apply color to destination, using a Screen blend mode +*/ +static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, + const video::SColor color) +{ + video::SColor dst_c; + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + dst_c.set( + dst_c.getAlpha(), + 255 - ((255 - dst_c.getRed()) * (255 - color.getRed())) / 255, + 255 - ((255 - dst_c.getGreen()) * (255 - color.getGreen())) / 255, + 255 - ((255 - dst_c.getBlue()) * (255 - color.getBlue())) / 255 + ); + dst->setPixel(x, y, dst_c); + } +} + +/* + Adjust the hue, saturation, and lightness of destination. Like + "Hue-Saturation" in GIMP, but with 0 as the mid-point. + Hue should be from -180 to +180, or from 0 to 360. + Saturation and Lightness are percentages. + Lightness is from -100 to +100. + Saturation goes down to -100 (fully desaturated) but can go above 100, + allowing for even muted colors to become saturated. + + If colorize is true then saturation is from 0 to 100, and destination will + be converted to a grayscale image as seen through a colored glass, like + "Colorize" in GIMP. +*/ +static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 hue, s32 saturation, s32 lightness, bool colorize) +{ + video::SColorf colorf; + video::SColorHSL hsl; + f32 norm_s = core::clamp(saturation, -100, 1000) / 100.0f; + f32 norm_l = core::clamp(lightness, -100, 100) / 100.0f; + + if (colorize) { + hsl.Saturation = core::clamp((f32)saturation, 0.0f, 100.0f); + } + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + + if (colorize) { + f32 lum = dst->getPixel(x, y).getLuminance() / 255.0f; + + if (norm_l < 0) { + lum *= norm_l + 1.0f; + } else { + lum = lum * (1.0f - norm_l) + norm_l; + } + hsl.Hue = 0; + hsl.Luminance = lum * 100; + + } else { + // convert the RGB to HSL + colorf = video::SColorf(dst->getPixel(x, y)); + hsl.fromRGB(colorf); + + if (norm_l < 0) { + hsl.Luminance *= norm_l + 1.0f; + } else{ + hsl.Luminance = hsl.Luminance + norm_l * (100.0f - hsl.Luminance); + } + + // Adjusting saturation in the same manner as lightness resulted in + // muted colors being affected too much and bright colors not + // affected enough, so I'm borrowing a leaf out of gimp's book and + // using a different scaling approach for saturation. + // https://github.com/GNOME/gimp/blob/6cc1e035f1822bf5198e7e99a53f7fa6e281396a/app/operations/gimpoperationhuesaturation.c#L139-L145= + // This difference is why values over 100% are not necessary for + // lightness but are very useful with saturation. An alternative UI + // approach would be to have an upper saturation limit of 100, but + // multiply positive values by ~3 to make it a more useful positive + // range scale. + hsl.Saturation *= norm_s + 1.0f; + hsl.Saturation = core::clamp(hsl.Saturation, 0.0f, 100.0f); + } + + // Apply the specified HSL adjustments + hsl.Hue = fmod(hsl.Hue + hue, 360); + if (hsl.Hue < 0) + hsl.Hue += 360; + + // Convert back to RGB + hsl.toRGB(colorf); + dst->setPixel(x, y, colorf.toSColor()); + } +} + + +/* + Apply an Overlay blend to destination + If hardlight is true then swap the dst & blend images (a hardlight blend) +*/ +static void apply_overlay(video::IImage *blend, video::IImage *dst, + v2s32 blend_pos, v2s32 dst_pos, v2u32 size, bool hardlight) +{ + video::IImage *blend_layer = hardlight ? dst : blend; + video::IImage *base_layer = hardlight ? blend : dst; + v2s32 blend_layer_pos = hardlight ? dst_pos : blend_pos; + v2s32 base_layer_pos = hardlight ? blend_pos : dst_pos; + + for (u32 y = 0; y < size.Y; y++) + for (u32 x = 0; x < size.X; x++) { + s32 base_x = x + base_layer_pos.X; + s32 base_y = y + base_layer_pos.Y; + + video::SColor blend_c = + blend_layer->getPixel(x + blend_layer_pos.X, y + blend_layer_pos.Y); + video::SColor base_c = base_layer->getPixel(base_x, base_y); + double blend_r = blend_c.getRed() / 255.0; + double blend_g = blend_c.getGreen() / 255.0; + double blend_b = blend_c.getBlue() / 255.0; + double base_r = base_c.getRed() / 255.0; + double base_g = base_c.getGreen() / 255.0; + double base_b = base_c.getBlue() / 255.0; + + base_c.set( + base_c.getAlpha(), + // Do a Multiply blend if less that 0.5, otherwise do a Screen blend + (u32)((base_r < 0.5 ? 2 * base_r * blend_r : 1 - 2 * (1 - base_r) * (1 - blend_r)) * 255), + (u32)((base_g < 0.5 ? 2 * base_g * blend_g : 1 - 2 * (1 - base_g) * (1 - blend_g)) * 255), + (u32)((base_b < 0.5 ? 2 * base_b * blend_b : 1 - 2 * (1 - base_b) * (1 - blend_b)) * 255) + ); + dst->setPixel(base_x, base_y, base_c); + } +} + +/* + Adjust the brightness and contrast of the base image. + + Conceptually like GIMP's "Brightness-Contrast" feature but allows brightness to be + wound all the way up to white or down to black. +*/ +static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, + s32 brightness, s32 contrast) +{ + video::SColor dst_c; + // Only allow normalized contrast to get as high as 127/128 to avoid infinite slope. + // (we could technically allow -128/128 here as that would just result in 0 slope) + double norm_c = core::clamp(contrast, -127, 127) / 128.0; + double norm_b = core::clamp(brightness, -127, 127) / 127.0; + + // Scale brightness so its range is -127.5 to 127.5, otherwise brightness + // adjustments will outputs values from 0.5 to 254.5 instead of 0 to 255. + double scaled_b = brightness * 127.5 / 127; + + // Calculate a contrast slope such that that no colors will get clamped due + // to the brightness setting. + // This allows the texture modifier to used as a brightness modifier without + // the user having to calculate a contrast to avoid clipping at that brightness. + double slope = 1 - fabs(norm_b); + + // Apply the user's contrast adjustment to the calculated slope, such that + // -127 will make it near-vertical and +127 will make it horizontal + double angle = atan(slope); + angle += norm_c <= 0 + ? norm_c * angle // allow contrast slope to be lowered to 0 + : norm_c * (M_PI_2 - angle); // allow contrast slope to be raised almost vert. + slope = tan(angle); + + double c = slope <= 1 + ? -slope * 127.5 + 127.5 + scaled_b // shift up/down when slope is horiz. + : -slope * (127.5 - scaled_b) + 127.5; // shift left/right when slope is vert. + + // add 0.5 to c so that when the final result is cast to int, it is effectively + // rounded rather than trunc'd. + c += 0.5; + + for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) + for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { + dst_c = dst->getPixel(x, y); + + dst_c.set( + dst_c.getAlpha(), + core::clamp((int)(slope * dst_c.getRed() + c), 0, 255), + core::clamp((int)(slope * dst_c.getGreen() + c), 0, 255), + core::clamp((int)(slope * dst_c.getBlue() + c), 0, 255) + ); + dst->setPixel(x, y, dst_c); + } +} + +/* + Apply mask to destination +*/ +static void apply_mask(video::IImage *mask, video::IImage *dst, + v2s32 mask_pos, v2s32 dst_pos, v2u32 size) +{ + for (u32 y0 = 0; y0 < size.Y; y0++) { + for (u32 x0 = 0; x0 < size.X; x0++) { + s32 mask_x = x0 + mask_pos.X; + s32 mask_y = y0 + mask_pos.Y; + s32 dst_x = x0 + dst_pos.X; + s32 dst_y = y0 + dst_pos.Y; + video::SColor mask_c = mask->getPixel(mask_x, mask_y); + video::SColor dst_c = dst->getPixel(dst_x, dst_y); + dst_c.color &= mask_c.color; + dst->setPixel(dst_x, dst_y, dst_c); + } + } +} + +video::IImage *create_crack_image(video::IImage *crack, s32 frame_index, + core::dimension2d size, u8 tiles, video::IVideoDriver *driver) +{ + core::dimension2d strip_size = crack->getDimension(); + + if (tiles == 0 || strip_size.getArea() == 0) + return nullptr; + + core::dimension2d frame_size(strip_size.Width, strip_size.Width); + core::dimension2d tile_size(size / tiles); + s32 frame_count = strip_size.Height / strip_size.Width; + if (frame_index >= frame_count) + frame_index = frame_count - 1; + core::rect frame(v2s32(0, frame_index * frame_size.Height), frame_size); + video::IImage *result = nullptr; + + // extract crack frame + video::IImage *crack_tile = driver->createImage(video::ECF_A8R8G8B8, tile_size); + if (!crack_tile) + return nullptr; + if (tile_size == frame_size) { + crack->copyTo(crack_tile, v2s32(0, 0), frame); + } else { + video::IImage *crack_frame = driver->createImage(video::ECF_A8R8G8B8, frame_size); + if (!crack_frame) + goto exit__has_tile; + crack->copyTo(crack_frame, v2s32(0, 0), frame); + crack_frame->copyToScaling(crack_tile); + crack_frame->drop(); + } + if (tiles == 1) + return crack_tile; + + // tile it + result = driver->createImage(video::ECF_A8R8G8B8, size); + if (!result) + goto exit__has_tile; + result->fill({}); + for (u8 i = 0; i < tiles; i++) + for (u8 j = 0; j < tiles; j++) + crack_tile->copyTo(result, v2s32(i * tile_size.Width, j * tile_size.Height)); + +exit__has_tile: + crack_tile->drop(); + return result; +} + +static void draw_crack(video::IImage *crack, video::IImage *dst, + bool use_overlay, s32 frame_count, s32 progression, + video::IVideoDriver *driver, u8 tiles) +{ + // Dimension of destination image + core::dimension2d dim_dst = dst->getDimension(); + // Limit frame_count + if (frame_count > (s32) dim_dst.Height) + frame_count = dim_dst.Height; + if (frame_count < 1) + frame_count = 1; + // Dimension of the scaled crack stage, + // which is the same as the dimension of a single destination frame + core::dimension2d frame_size( + dim_dst.Width, + dim_dst.Height / frame_count + ); + video::IImage *crack_scaled = create_crack_image(crack, progression, + frame_size, tiles, driver); + if (!crack_scaled) + return; + + auto blit = use_overlay ? blit_with_alpha : blit_with_alpha; + for (s32 i = 0; i < frame_count; ++i) { + v2s32 dst_pos(0, frame_size.Height * i); + blit(crack_scaled, dst, dst_pos, frame_size); + } + + crack_scaled->drop(); +} + +void brighten(video::IImage *image) +{ + if (image == NULL) + return; + + core::dimension2d dim = image->getDimension(); + + for (u32 y=0; ygetPixel(x,y); + c.setRed(0.5 * 255 + 0.5 * (float)c.getRed()); + c.setGreen(0.5 * 255 + 0.5 * (float)c.getGreen()); + c.setBlue(0.5 * 255 + 0.5 * (float)c.getBlue()); + image->setPixel(x,y,c); + } +} + +u32 parseImageTransform(std::string_view s) +{ + int total_transform = 0; + + std::string transform_names[8]; + transform_names[0] = "i"; + transform_names[1] = "r90"; + transform_names[2] = "r180"; + transform_names[3] = "r270"; + transform_names[4] = "fx"; + transform_names[6] = "fy"; + + std::size_t pos = 0; + while(pos < s.size()) + { + int transform = -1; + for (int i = 0; i <= 7; ++i) + { + const std::string &name_i = transform_names[i]; + + if (s[pos] == ('0' + i)) + { + transform = i; + pos++; + break; + } + + if (!(name_i.empty()) && lowercase(s.substr(pos, name_i.size())) == name_i) { + transform = i; + pos += name_i.size(); + break; + } + } + if (transform < 0) + break; + + // Multiply total_transform and transform in the group D4 + int new_total = 0; + if (transform < 4) + new_total = (transform + total_transform) % 4; + else + new_total = (transform - total_transform + 8) % 4; + if ((transform >= 4) ^ (total_transform >= 4)) + new_total += 4; + + total_transform = new_total; + } + return total_transform; +} + +core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim) +{ + if (transform % 2 == 0) + return dim; + + return core::dimension2d(dim.Height, dim.Width); +} + +void imageTransform(u32 transform, video::IImage *src, video::IImage *dst) +{ + if (src == NULL || dst == NULL) + return; + + core::dimension2d dstdim = dst->getDimension(); + + // Pre-conditions + assert(dstdim == imageTransformDimension(transform, src->getDimension())); + assert(transform <= 7); + + /* + Compute the transformation from source coordinates (sx,sy) + to destination coordinates (dx,dy). + */ + int sxn = 0; + int syn = 2; + if (transform == 0) // identity + sxn = 0, syn = 2; // sx = dx, sy = dy + else if (transform == 1) // rotate by 90 degrees ccw + sxn = 3, syn = 0; // sx = (H-1) - dy, sy = dx + else if (transform == 2) // rotate by 180 degrees + sxn = 1, syn = 3; // sx = (W-1) - dx, sy = (H-1) - dy + else if (transform == 3) // rotate by 270 degrees ccw + sxn = 2, syn = 1; // sx = dy, sy = (W-1) - dx + else if (transform == 4) // flip x + sxn = 1, syn = 2; // sx = (W-1) - dx, sy = dy + else if (transform == 5) // flip x then rotate by 90 degrees ccw + sxn = 2, syn = 0; // sx = dy, sy = dx + else if (transform == 6) // flip y + sxn = 0, syn = 3; // sx = dx, sy = (H-1) - dy + else if (transform == 7) // flip y then rotate by 90 degrees ccw + sxn = 3, syn = 1; // sx = (H-1) - dy, sy = (W-1) - dx + + for (u32 dy=0; dygetPixel(sx,sy); + dst->setPixel(dx,dy,c); + } +} + +namespace { + // For more colorspace transformations, see for example + // https://github.com/tobspr/GLSL-Color-Spaces/blob/master/ColorSpaces.inc.glsl + + inline float linear_to_srgb_component(float v) + { + if (v > 0.0031308f) + return 1.055f * powf(v, 1.0f / 2.4f) - 0.055f; + return 12.92f * v; + } + inline float srgb_to_linear_component(float v) + { + if (v > 0.04045f) + return powf((v + 0.055f) / 1.055f, 2.4f); + return v / 12.92f; + } + + v3f srgb_to_linear(const video::SColor col_srgb) + { + v3f col(col_srgb.getRed(), col_srgb.getGreen(), col_srgb.getBlue()); + col /= 255.0f; + col.X = srgb_to_linear_component(col.X); + col.Y = srgb_to_linear_component(col.Y); + col.Z = srgb_to_linear_component(col.Z); + return col; + } + + video::SColor linear_to_srgb(const v3f col_linear) + { + v3f col; + col.X = linear_to_srgb_component(col_linear.X); + col.Y = linear_to_srgb_component(col_linear.Y); + col.Z = linear_to_srgb_component(col_linear.Z); + col *= 255.0f; + col.X = core::clamp(col.X, 0.0f, 255.0f); + col.Y = core::clamp(col.Y, 0.0f, 255.0f); + col.Z = core::clamp(col.Z, 0.0f, 255.0f); + return video::SColor(0xff, myround(col.X), myround(col.Y), + myround(col.Z)); + } +} + + +/////////////////////////// +// ImageSource Functions // +/////////////////////////// + +#define CHECK_BASEIMG() \ + do { \ + if (!baseimg) { \ + errorstream << "generateImagePart(): baseimg == NULL" \ + << " for part_of_name=\"" << part_of_name \ + << "\", cancelling." << std::endl; \ + return false; \ + } \ + } while(0) + +#define COMPLAIN_INVALID(description) \ + do { \ + errorstream << "generateImagePart(): invalid " << (description) \ + << " for part_of_name=\"" << part_of_name \ + << "\", cancelling." << std::endl; \ + return false; \ + } while(0) + +#define CHECK_DIM(w, h) \ + do { \ + if ((w) <= 0 || (h) <= 0 || (w) >= 0xffff || (h) >= 0xffff) { \ + COMPLAIN_INVALID("width or height"); \ + } \ + } while(0) + +bool ImageSource::generateImagePart(std::string_view part_of_name, + video::IImage *& baseimg, std::set &source_image_names) +{ + const char escape = '\\'; // same as in generateImage() + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + sanity_check(driver); + + if (baseimg && (baseimg->getDimension().Width == 0 || + baseimg->getDimension().Height == 0)) { + errorstream << "generateImagePart(): baseimg is zero-sized?!" + << std::endl; + baseimg->drop(); + baseimg = nullptr; + } + + // Stuff starting with [ are special commands + if (part_of_name.empty() || part_of_name[0] != '[') { + std::string part_s(part_of_name); + source_image_names.insert(part_s); + video::IImage *image = m_sourcecache.getOrLoad(part_s); + if (!image) { + // Do not create the dummy texture + if (part_of_name.empty()) + return true; + + // Do not create normalmap dummies + if (str_ends_with(part_of_name, "_normal.png")) { + warningstream << "generateImagePart(): Could not load normal map \"" + << part_of_name << "\"" << std::endl; + return true; + } + + errorstream << "generateImagePart(): Could not load image \"" + << part_of_name << "\" while building texture; " + "Creating a dummy image" << std::endl; + + core::dimension2d dim(1,1); + image = driver->createImage(video::ECF_A8R8G8B8, dim); + sanity_check(image != NULL); + image->setPixel(0,0, video::SColor(255,myrand()%256, + myrand()%256,myrand()%256)); + } + + // If base image is NULL, load as base. + if (baseimg == NULL) + { + /* + Copy it this way to get an alpha channel. + Otherwise images with alpha cannot be blitted on + images that don't have alpha in the original file. + */ + core::dimension2d dim = image->getDimension(); + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + image->copyTo(baseimg); + } + // Else blit on base. + else + { + blitBaseImage(image, baseimg); + } + + image->drop(); + } + else + { + // A special texture modification + + /* + [crack:N:P + [cracko:N:P + Adds a cracking texture + N = animation frame count, P = crack progression + */ + if (str_starts_with(part_of_name, "[crack")) + { + CHECK_BASEIMG(); + + // Crack image number and overlay option + // Format: crack[o][:]:: + bool use_overlay = (part_of_name[6] == 'o'); + Strfnd sf(part_of_name); + sf.next(":"); + s32 frame_count = stoi(sf.next(":")); + s32 progression = stoi(sf.next(":")); + s32 tiles = 1; + // Check whether there is the argument, that is, + // whether there are 3 arguments. If so, shift values + // as the first and not the last argument is optional. + auto s = sf.next(":"); + if (!s.empty()) { + tiles = frame_count; + frame_count = progression; + progression = stoi(s); + } + + if (progression >= 0) { + /* + Load crack image. + + It is an image with a number of cracking stages + horizontally tiled. + */ + video::IImage *img_crack = m_sourcecache.getOrLoad( + "crack_anylength.png"); + + if (img_crack) { + draw_crack(img_crack, baseimg, + use_overlay, frame_count, + progression, driver, tiles); + img_crack->drop(); + } + } + } + /* + [combine:WxH:X,Y=filename:X,Y=filename2 + Creates a bigger texture from any amount of smaller ones + */ + else if (str_starts_with(part_of_name, "[combine")) + { + Strfnd sf(part_of_name); + sf.next(":"); + u32 w0 = stoi(sf.next("x")); + u32 h0 = stoi(sf.next(":")); + if (!baseimg) { + CHECK_DIM(w0, h0); + baseimg = driver->createImage(video::ECF_A8R8G8B8, {w0, h0}); + baseimg->fill(video::SColor(0,0,0,0)); + } + + while (!sf.at_end()) { + v2s32 pos_base; + pos_base.X = stoi(sf.next(",")); + pos_base.Y = stoi(sf.next("=")); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + auto basedim = baseimg->getDimension(); + if (pos_base.X > (s32)basedim.Width || pos_base.Y > (s32)basedim.Height) { + warningstream << "generateImagePart(): Skipping \"" + << filename << "\" as it's out-of-bounds " << pos_base + << " for [combine" << std::endl; + continue; + } + infostream << "Adding \"" << filename<< "\" to combined " + << pos_base << std::endl; + + video::IImage *img = generateImage(filename, source_image_names); + if (!img) { + errorstream << "generateImagePart(): Failed to load image \"" + << filename << "\" for [combine" << std::endl; + continue; + } + const auto dim = img->getDimension(); + if (pos_base.X + dim.Width <= 0 || pos_base.Y + dim.Height <= 0) { + warningstream << "generateImagePart(): Skipping \"" + << filename << "\" as it's out-of-bounds " << pos_base + << " for [combine" << std::endl; + img->drop(); + continue; + } + + blit_with_alpha(img, baseimg, pos_base, dim); + img->drop(); + } + } + /* + [fill:WxH:color + [fill:WxH:X,Y:color + Creates a texture of the given size and color, optionally with an , + position. An alpha value may be specified in the `Colorstring`. + */ + else if (str_starts_with(part_of_name, "[fill")) + { + u32 x = 0; + u32 y = 0; + + Strfnd sf(part_of_name); + sf.next(":"); + u32 width = stoi(sf.next("x")); + u32 height = stoi(sf.next(":")); + std::string color_or_x = sf.next(","); + + video::SColor color; + if (!parseColorString(color_or_x, color, true)) { + x = stoi(color_or_x); + y = stoi(sf.next(":")); + std::string color_str = sf.next(":"); + + if (!parseColorString(color_str, color, false)) + return false; + } + core::dimension2d dim(width, height); + + CHECK_DIM(dim.Width, dim.Height); + if (baseimg) { + auto basedim = baseimg->getDimension(); + if (x >= basedim.Width || y >= basedim.Height) + COMPLAIN_INVALID("X or Y offset"); + } + + video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim); + img->fill(color); + + if (baseimg == nullptr) { + baseimg = img; + } else { + blit_with_alpha(img, baseimg, v2s32(x, y), dim); + img->drop(); + } + } + /* + [brighten + */ + else if (str_starts_with(part_of_name, "[brighten")) + { + CHECK_BASEIMG(); + + brighten(baseimg); + } + /* + [noalpha + Make image completely opaque. + Used for the leaves texture when in old leaves mode, so + that the transparent parts don't look completely black + when simple alpha channel is used for rendering. + */ + else if (str_starts_with(part_of_name, "[noalpha")) + { + CHECK_BASEIMG(); + core::dimension2d dim = baseimg->getDimension(); + + // Set alpha to full + for (u32 y=0; ygetPixel(x,y); + c.setAlpha(255); + baseimg->setPixel(x,y,c); + } + } + /* + [makealpha:R,G,B + Convert one color to transparent. + */ + else if (str_starts_with(part_of_name, "[makealpha:")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name.substr(11)); + u32 r1 = stoi(sf.next(",")); + u32 g1 = stoi(sf.next(",")); + u32 b1 = stoi(sf.next("")); + + core::dimension2d dim = baseimg->getDimension(); + + for (u32 y=0; ygetPixel(x,y); + u32 r = c.getRed(); + u32 g = c.getGreen(); + u32 b = c.getBlue(); + if (!(r == r1 && g == g1 && b == b1)) + continue; + c.setAlpha(0); + baseimg->setPixel(x,y,c); + } + } + /* + [transformN + Rotates and/or flips the image. + + N can be a number (between 0 and 7) or a transform name. + Rotations are counter-clockwise. + 0 I identity + 1 R90 rotate by 90 degrees + 2 R180 rotate by 180 degrees + 3 R270 rotate by 270 degrees + 4 FX flip X + 5 FXR90 flip X then rotate by 90 degrees + 6 FY flip Y + 7 FYR90 flip Y then rotate by 90 degrees + + Note: Transform names can be concatenated to produce + their product (applies the first then the second). + The resulting transform will be equivalent to one of the + eight existing ones, though (see: dihedral group). + */ + else if (str_starts_with(part_of_name, "[transform")) + { + CHECK_BASEIMG(); + + u32 transform = parseImageTransform(part_of_name.substr(10)); + core::dimension2d dim = imageTransformDimension( + transform, baseimg->getDimension()); + video::IImage *image = driver->createImage( + baseimg->getColorFormat(), dim); + sanity_check(image != NULL); + imageTransform(transform, baseimg, image); + baseimg->drop(); + baseimg = image; + } + /* + [inventorycube{topimage{leftimage{rightimage + In every subimage, replace ^ with &. + Create an "inventory cube". + NOTE: This should be used only on its own. + Example (a grass block (not actually used in game): + "[inventorycube{grass.png{mud.png&grass_side.png{mud.png&grass_side.png" + */ + else if (str_starts_with(part_of_name, "[inventorycube")) + { + if (baseimg) { + errorstream<<"generateImagePart(): baseimg != NULL " + <<"for part_of_name=\""<drop(); + img_left->drop(); + img_right->drop(); + + return true; + } + /* + [lowpart:percent:filename + Adds the lower part of a texture + */ + else if (str_starts_with(part_of_name, "[lowpart:")) + { + Strfnd sf(part_of_name); + sf.next(":"); + u32 percent = stoi(sf.next(":"), 0, 100); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + video::IImage *img = generateImage(filename, source_image_names); + if (img) { + core::dimension2d dim = img->getDimension(); + if (!baseimg) + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + + core::position2d pos_base(0, 0); + core::position2d clippos(0, 0); + clippos.Y = dim.Height * (100-percent) / 100; + core::dimension2d clipdim = dim; + clipdim.Height = clipdim.Height * percent / 100 + 1; + core::rect cliprect(clippos, clipdim); + img->copyToWithAlpha(baseimg, pos_base, + core::rect(v2s32(0,0), dim), + video::SColor(255,255,255,255), + &cliprect); + img->drop(); + } + } + /* + [verticalframe:N:I + Crops a frame of a vertical animation. + N = frame count, I = frame index + */ + else if (str_starts_with(part_of_name, "[verticalframe:")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + u32 frame_count = stoi(sf.next(":")); + u32 frame_index = stoi(sf.next(":")); + + if (frame_count == 0){ + errorstream << "generateImagePart(): invalid frame_count " + << "for part_of_name=\"" << part_of_name + << "\", using frame_count = 1 instead." << std::endl; + frame_count = 1; + } + if (frame_index >= frame_count) + frame_index = frame_count - 1; + + v2u32 frame_size = baseimg->getDimension(); + frame_size.Y /= frame_count; + + video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, + frame_size); + + // Fill target image with transparency + img->fill(video::SColor(0,0,0,0)); + + core::dimension2d dim = frame_size; + core::position2d pos_dst(0, 0); + core::position2d pos_src(0, frame_index * frame_size.Y); + baseimg->copyToWithAlpha(img, pos_dst, + core::rect(pos_src, dim), + video::SColor(255,255,255,255), + NULL); + // Replace baseimg + baseimg->drop(); + baseimg = img; + } + /* + [mask:filename + Applies a mask to an image + */ + else if (str_starts_with(part_of_name, "[mask:")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + video::IImage *img = generateImage(filename, source_image_names); + if (img) { + apply_mask(img, baseimg, v2s32(0, 0), v2s32(0, 0), + img->getDimension()); + img->drop(); + } else { + errorstream << "generateImagePart(): Failed to load image \"" + << filename << "\" for [mask" << std::endl; + } + } + /* + [multiply:color + or + [screen:color + Multiply and Screen blend modes are basic blend modes for darkening and lightening + images, respectively. + A Multiply blend multiplies a given color to every pixel of an image. + A Screen blend has the opposite effect to a Multiply blend. + color = color as ColorString + */ + else if (str_starts_with(part_of_name, "[multiply:") || + str_starts_with(part_of_name, "[screen:")) { + Strfnd sf(part_of_name); + sf.next(":"); + std::string color_str = sf.next(":"); + + CHECK_BASEIMG(); + + video::SColor color; + + if (!parseColorString(color_str, color, false)) + return false; + if (str_starts_with(part_of_name, "[multiply:")) { + apply_multiplication(baseimg, v2u32(0, 0), + baseimg->getDimension(), color); + } else { + apply_screen(baseimg, v2u32(0, 0), baseimg->getDimension(), color); + } + } + /* + [colorize:color:ratio + Overlays image with given color + color = color as ColorString + ratio = optional string "alpha", or a weighting between 0 and 255 + */ + else if (str_starts_with(part_of_name, "[colorize:")) + { + Strfnd sf(part_of_name); + sf.next(":"); + std::string color_str = sf.next(":"); + std::string ratio_str = sf.next(":"); + + CHECK_BASEIMG(); + + video::SColor color; + int ratio = -1; + bool keep_alpha = false; + + if (!parseColorString(color_str, color, false)) + return false; + + if (is_number(ratio_str)) + ratio = mystoi(ratio_str, 0, 255); + else if (ratio_str == "alpha") + keep_alpha = true; + + apply_colorize(baseimg, v2u32(0, 0), baseimg->getDimension(), color, ratio, keep_alpha); + } + /* + [applyfiltersformesh + Internal modifier + */ + else if (str_starts_with(part_of_name, "[applyfiltersformesh")) + { + /* IMPORTANT: When changing this, getTextureForMesh() needs to be + * updated too. */ + + CHECK_BASEIMG(); + + // Apply the "clean transparent" filter, if needed + if (m_setting_mipmap || m_setting_bilinear_filter || + m_setting_trilinear_filter || m_setting_anisotropic_filter) + imageCleanTransparent(baseimg, 127); + + /* Upscale textures to user's requested minimum size. This is a trick to make + * filters look as good on low-res textures as on high-res ones, by making + * low-res textures BECOME high-res ones. This is helpful for worlds that + * mix high- and low-res textures, or for mods with least-common-denominator + * textures that don't have the resources to offer high-res alternatives. + */ + const bool filter = m_setting_trilinear_filter || m_setting_bilinear_filter; + const s32 scaleto = filter ? g_settings->getU16("texture_min_size") : 1; + if (scaleto > 1) { + const core::dimension2d dim = baseimg->getDimension(); + + /* Calculate scaling needed to make the shortest texture dimension + * equal to the target minimum. If e.g. this is a vertical frames + * animation, the short dimension will be the real size. + */ + u32 xscale = scaleto / dim.Width; + u32 yscale = scaleto / dim.Height; + const s32 scale = std::max(xscale, yscale); + + // Never downscale; only scale up by 2x or more. + if (scale > 1) { + u32 w = scale * dim.Width; + u32 h = scale * dim.Height; + const core::dimension2d newdim(w, h); + video::IImage *newimg = driver->createImage( + baseimg->getColorFormat(), newdim); + baseimg->copyToScaling(newimg); + baseimg->drop(); + baseimg = newimg; + } + } + } + /* + [resize:WxH + Resizes the base image to the given dimensions + */ + else if (str_starts_with(part_of_name, "[resize")) + { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + u32 width = stoi(sf.next("x")); + u32 height = stoi(sf.next("")); + CHECK_DIM(width, height); + + video::IImage *image = driver-> + createImage(video::ECF_A8R8G8B8, {width, height}); + baseimg->copyToScaling(image); + baseimg->drop(); + baseimg = image; + } + /* + [opacity:R + Makes the base image transparent according to the given ratio. + R must be between 0 and 255. + 0 means totally transparent. + 255 means totally opaque. + */ + else if (str_starts_with(part_of_name, "[opacity:")) { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + + u32 ratio = mystoi(sf.next(""), 0, 255); + + core::dimension2d dim = baseimg->getDimension(); + + for (u32 y = 0; y < dim.Height; y++) + for (u32 x = 0; x < dim.Width; x++) + { + video::SColor c = baseimg->getPixel(x, y); + c.setAlpha(floor((c.getAlpha() * ratio) / 255 + 0.5)); + baseimg->setPixel(x, y, c); + } + } + /* + [invert:mode + Inverts the given channels of the base image. + Mode may contain the characters "r", "g", "b", "a". + Only the channels that are mentioned in the mode string + will be inverted. + */ + else if (str_starts_with(part_of_name, "[invert:")) { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + + std::string mode = sf.next(""); + u32 mask = 0; + if (mode.find('a') != std::string::npos) + mask |= 0xff000000UL; + if (mode.find('r') != std::string::npos) + mask |= 0x00ff0000UL; + if (mode.find('g') != std::string::npos) + mask |= 0x0000ff00UL; + if (mode.find('b') != std::string::npos) + mask |= 0x000000ffUL; + + core::dimension2d dim = baseimg->getDimension(); + + for (u32 y = 0; y < dim.Height; y++) + for (u32 x = 0; x < dim.Width; x++) + { + video::SColor c = baseimg->getPixel(x, y); + c.color ^= mask; + baseimg->setPixel(x, y, c); + } + } + /* + [sheet:WxH:X,Y + Retrieves a tile at position X,Y (in tiles) + from the base image it assumes to be a + tilesheet with dimensions W,H (in tiles). + */ + else if (str_starts_with(part_of_name, "[sheet:")) { + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + u32 w0 = stoi(sf.next("x")); + u32 h0 = stoi(sf.next(":")); + u32 x0 = stoi(sf.next(",")); + u32 y0 = stoi(sf.next(":")); + + CHECK_DIM(w0, h0); + if (x0 >= w0 || y0 >= h0) + COMPLAIN_INVALID("tile position (X,Y)"); + + core::dimension2d img_dim = baseimg->getDimension(); + core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); + if (tile_dim.Width == 0) + tile_dim.Width = 1; + if (tile_dim.Height == 0) + tile_dim.Height = 1; + + video::IImage *img = driver->createImage( + video::ECF_A8R8G8B8, tile_dim); + img->fill(video::SColor(0,0,0,0)); + + v2u32 vdim(tile_dim); + core::rect rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); + baseimg->copyToWithAlpha(img, v2s32(0), rect, + video::SColor(255,255,255,255), NULL); + + // Replace baseimg + baseimg->drop(); + baseimg = img; + } + /* + [png:base64 + Decodes a PNG image in base64 form. + Use minetest.encode_png and minetest.encode_base64 + to produce a valid string. + */ + else if (str_starts_with(part_of_name, "[png:")) { + std::string png; + { + auto blob = part_of_name.substr(5); + if (!base64_is_valid(blob)) { + errorstream << "generateImagePart(): " + << "malformed base64 in [png" << std::endl; + return false; + } + png = base64_decode(blob); + } + + auto *device = RenderingEngine::get_raw_device(); + auto *fs = device->getFileSystem(); + auto *vd = device->getVideoDriver(); + auto *memfile = fs->createMemoryReadFile(png.data(), png.size(), "__temp_png"); + video::IImage* pngimg = vd->createImageFromFile(memfile); + memfile->drop(); + + if (!pngimg) { + errorstream << "generateImagePart(): Invalid PNG data" << std::endl; + return false; + } + + if (baseimg) { + blitBaseImage(pngimg, baseimg); + } else { + core::dimension2d dim = pngimg->getDimension(); + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + pngimg->copyTo(baseimg); + } + pngimg->drop(); + } + /* + [hsl:hue:saturation:lightness + or + [colorizehsl:hue:saturation:lightness + + Adjust the hue, saturation, and lightness of the base image. Like + "Hue-Saturation" in GIMP, but with 0 as the mid-point. + Hue should be from -180 to +180, though 0 to 360 is also supported. + Saturation and lightness are optional, with lightness from -100 to + +100, and sauration from -100 to +100-or-higher. + + If colorize is true then saturation is from 0 to 100, and the image + will be converted to a grayscale image as though seen through a + colored glass, like "Colorize" in GIMP. + */ + else if (str_starts_with(part_of_name, "[hsl:") || + str_starts_with(part_of_name, "[colorizehsl:")) { + + CHECK_BASEIMG(); + + bool colorize = str_starts_with(part_of_name, "[colorizehsl:"); + + // saturation range is 0 to 100 when colorize is true + s32 defaultSaturation = colorize ? 50 : 0; + + Strfnd sf(part_of_name); + sf.next(":"); + s32 hue = mystoi(sf.next(":"), -180, 360); + s32 saturation = sf.at_end() ? defaultSaturation : mystoi(sf.next(":"), -100, 1000); + s32 lightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -100, 100); + + + apply_hue_saturation(baseimg, v2u32(0, 0), baseimg->getDimension(), + hue, saturation, lightness, colorize); + } + /* + [overlay:filename + or + [hardlight:filename + + "A.png^[hardlight:B.png" is the same as "B.png^[overlay:A.Png" + + Applies an Overlay or Hard Light blend between two images, like the + layer modes of the same names in GIMP. + Overlay combines Multiply and Screen blend modes. The parts of the + top layer where the base layer is light become lighter, the parts + where the base layer is dark become darker. Areas where the base + layer are mid grey are unaffected. An overlay with the same picture + looks like an S-curve. + + Swapping the top layer and base layer is a Hard Light blend + */ + else if (str_starts_with(part_of_name, "[overlay:") || + str_starts_with(part_of_name, "[hardlight:")) { + + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + std::string filename = unescape_string(sf.next_esc(":", escape), escape); + + video::IImage *img = generateImage(filename, source_image_names); + if (img) { + upscaleImagesToMatchLargest(baseimg, img); + + bool hardlight = str_starts_with(part_of_name, "[hardlight:"); + apply_overlay(img, baseimg, v2s32(0, 0), v2s32(0, 0), + img->getDimension(), hardlight); + img->drop(); + } else { + errorstream << "generateImage(): Failed to load image \"" + << filename << "\" for [overlay or [hardlight" << std::endl; + } + } + /* + [contrast:C:B + + Adjust the brightness and contrast of the base image. Conceptually + like GIMP's "Brightness-Contrast" feature but allows brightness to + be wound all the way up to white or down to black. + C and B are both values from -127 to +127. + B is optional. + */ + else if (str_starts_with(part_of_name, "[contrast:")) { + + CHECK_BASEIMG(); + + Strfnd sf(part_of_name); + sf.next(":"); + s32 contrast = mystoi(sf.next(":"), -127, 127); + s32 brightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -127, 127); + + apply_brightness_contrast(baseimg, v2u32(0, 0), + baseimg->getDimension(), brightness, contrast); + } + else + { + errorstream << "generateImagePart(): Invalid " + " modification: \"" << part_of_name << "\"" << std::endl; + } + } + + return true; +} + +#undef CHECK_BASEIMG + +#undef COMPLAIN_INVALID + +#undef CHECK_DIM + + +video::IImage* ImageSource::generateImage(std::string_view name, + std::set &source_image_names) +{ + // Get the base image + + const char separator = '^'; + const char escape = '\\'; + const char paren_open = '('; + const char paren_close = ')'; + + // Find last separator in the name + s32 last_separator_pos = -1; + u8 paren_bal = 0; + for (s32 i = name.size() - 1; i >= 0; i--) { + if (i > 0 && name[i-1] == escape) + continue; + switch (name[i]) { + case separator: + if (paren_bal == 0) { + last_separator_pos = i; + i = -1; // break out of loop + } + break; + case paren_open: + if (paren_bal == 0) { + errorstream << "generateImage(): unbalanced parentheses" + << "(extranous '(') while generating texture \"" + << name << "\"" << std::endl; + return NULL; + } + paren_bal--; + break; + case paren_close: + paren_bal++; + break; + default: + break; + } + } + if (paren_bal > 0) { + errorstream << "generateImage(): unbalanced parentheses" + << "(missing matching '(') while generating texture \"" + << name << "\"" << std::endl; + return NULL; + } + + + video::IImage *baseimg = NULL; + + /* + If separator was found, make the base image + using a recursive call. + */ + if (last_separator_pos != -1) { + baseimg = generateImage(name.substr(0, last_separator_pos), source_image_names); + } + + /* + Parse out the last part of the name of the image and act + according to it + */ + + auto last_part_of_name = name.substr(last_separator_pos + 1); + + /* + If this name is enclosed in parentheses, generate it + and blit it onto the base image + */ + if (last_part_of_name.empty()) { + // keep baseimg == nullptr + } else if (last_part_of_name[0] == paren_open + && last_part_of_name.back() == paren_close) { + auto name2 = last_part_of_name.substr(1, + last_part_of_name.size() - 2); + video::IImage *tmp = generateImage(name2, source_image_names); + if (!tmp) { + errorstream << "generateImage(): " + "Failed to generate \"" << name2 << "\"" + << std::endl; + return NULL; + } + + if (baseimg) { + core::dimension2d dim = tmp->getDimension(); + blit_with_alpha(tmp, baseimg, v2s32(0, 0), dim); + tmp->drop(); + } else { + baseimg = tmp; + } + } else if (!generateImagePart(last_part_of_name, baseimg, source_image_names)) { + // Generate image according to part of name + errorstream << "generateImage(): " + "Failed to generate \"" << last_part_of_name << "\"" + << std::endl; + } + + // If no resulting image, print a warning + if (baseimg == NULL) { + errorstream << "generateImage(): baseimg is NULL (attempted to" + " create texture \"" << name << "\")" << std::endl; + } else if (baseimg->getDimension().Width == 0 || + baseimg->getDimension().Height == 0) { + errorstream << "generateImage(): zero-sized image was created?! " + "(attempted to create texture \"" << name << "\")" << std::endl; + baseimg->drop(); + baseimg = nullptr; + } + + return baseimg; +} + +video::SColor ImageSource::getImageAverageColor(const video::IImage &image) +{ + video::SColor c(0, 0, 0, 0); + u32 total = 0; + v3f col_acc(0, 0, 0); + core::dimension2d dim = image.getDimension(); + u16 step = 1; + if (dim.Width > 16) + step = dim.Width / 16; + for (u16 x = 0; x < dim.Width; x += step) { + for (u16 y = 0; y < dim.Width; y += step) { + c = image.getPixel(x,y); + if (c.getAlpha() > 0) { + total++; + col_acc += srgb_to_linear(c); + } + } + } + if (total > 0) { + col_acc /= total; + c = linear_to_srgb(col_acc); + } + c.setAlpha(255); + return c; +} + +void ImageSource::insertImage(const std::string &name, video::IImage *img, bool prefer_local) { + m_sourcecache.insert(name, img, prefer_local); +} diff --git a/src/client/imagesource.h b/src/client/imagesource.h new file mode 100644 index 000000000..15c982f8a --- /dev/null +++ b/src/client/imagesource.h @@ -0,0 +1,84 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include +#include +#include "settings.h" + +// This file is only for internal generation/modification of images. +// Use texturesource.h instead to handle textures. + +// A cache used for storing source images. +class SourceImageCache { +public: + ~SourceImageCache(); + + void insert(const std::string &name, video::IImage *img, bool prefer_local); + + video::IImage* get(const std::string &name); + + // Primarily fetches from cache, secondarily tries to read from filesystem + video::IImage *getOrLoad(const std::string &name); +private: + std::map m_images; +}; + +/* + * Generates and caches images. + * The image name defines the image by filename and texture modifiers. +*/ +struct ImageSource { + /*! Generates an image from a full string like + * "stone.png^mineral_coal.png^[crack:1:0". + * The returned Image should be dropped. + * source_image_names is important to determine when to flush the image from a cache (dynamic media) + */ + video::IImage* generateImage(std::string_view name, std::set &source_image_names); + + // To add self made images. + void insertImage(const std::string &name, video::IImage *img, bool prefer_local); + + // TODO should probably be moved elsewhere + static video::SColor getImageAverageColor(const video::IImage &image); + + ImageSource() : + m_setting_mipmap{g_settings->getBool("mip_map")}, + m_setting_trilinear_filter{g_settings->getBool("trilinear_filter")}, + m_setting_bilinear_filter{g_settings->getBool("bilinear_filter")}, + m_setting_anisotropic_filter{g_settings->getBool("anisotropic_filter")} + {}; + +private: + + // Generate image based on a string like "stone.png" or "[crack:1:0". + // if baseimg is NULL, it is created. Otherwise stuff is made on it. + // source_image_names is important to determine when to flush the image from a cache (dynamic media) + bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg, std::set &source_image_names); + + // Cached settings needed for making textures from meshes + bool m_setting_mipmap; + bool m_setting_trilinear_filter; + bool m_setting_bilinear_filter; + bool m_setting_anisotropic_filter; + + // Cache of source images + SourceImageCache m_sourcecache; +}; diff --git a/src/client/texturesource.cpp b/src/client/texturesource.cpp index e23b88dbe..7e56a57cd 100644 --- a/src/client/texturesource.cpp +++ b/src/client/texturesource.cpp @@ -20,17 +20,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "texturesource.h" #include -#include #include "util/thread.h" -#include "settings.h" -#include "util/strfnd.h" #include "imagefilters.h" #include "guiscalingfilter.h" #include "renderingengine.h" -#include "util/base64.h" -#include "irrlicht_changes/printing.h" -#include "util/numeric.h" #include "texturepaths.h" +#include "imagesource.h" /* Stores internal information about a texture. @@ -63,90 +58,6 @@ struct TextureInfo } }; -/* - SourceImageCache: A cache used for storing source images. -*/ - -class SourceImageCache -{ -public: - ~SourceImageCache() { - for (auto &m_image : m_images) { - m_image.second->drop(); - } - m_images.clear(); - } - void insert(const std::string &name, video::IImage *img, bool prefer_local) - { - assert(img); // Pre-condition - // Remove old image - std::map::iterator n; - n = m_images.find(name); - if (n != m_images.end()){ - if (n->second) - n->second->drop(); - } - - video::IImage* toadd = img; - bool need_to_grab = true; - - // Try to use local texture instead if asked to - if (prefer_local) { - bool is_base_pack; - std::string path = getTexturePath(name, &is_base_pack); - // Ignore base pack - if (!path.empty() && !is_base_pack) { - video::IImage *img2 = RenderingEngine::get_video_driver()-> - createImageFromFile(path.c_str()); - if (img2){ - toadd = img2; - need_to_grab = false; - } - } - } - - if (need_to_grab) - toadd->grab(); - m_images[name] = toadd; - } - video::IImage* get(const std::string &name) - { - std::map::iterator n; - n = m_images.find(name); - if (n != m_images.end()) - return n->second; - return NULL; - } - // Primarily fetches from cache, secondarily tries to read from filesystem - video::IImage *getOrLoad(const std::string &name) - { - std::map::iterator n; - n = m_images.find(name); - if (n != m_images.end()){ - n->second->grab(); // Grab for caller - return n->second; - } - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - std::string path = getTexturePath(name); - if (path.empty()) { - infostream<<"SourceImageCache::getOrLoad(): No path found for \"" - <createImageFromFile(path.c_str()); - - if (img){ - m_images[name] = img; - img->grab(); // Grab for caller - } - return img; - } -private: - std::map m_images; -}; - /* TextureSource */ @@ -256,9 +167,9 @@ private: // The id of the thread that is allowed to use irrlicht directly std::thread::id m_main_thread; - // Cache of source images + // Generates and caches source images // This should be only accessed from the main thread - SourceImageCache m_sourcecache; + ImageSource m_imagesource; // Rebuild images and textures from the current set of source images // Shall be called from the main thread. @@ -268,19 +179,6 @@ private: // Generate a texture u32 generateTexture(const std::string &name); - // Generate image based on a string like "stone.png" or "[crack:1:0". - // if baseimg is NULL, it is created. Otherwise stuff is made on it. - // source_image_names is important to determine when to flush the image from a cache (dynamic media) - bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg, std::set &source_image_names); - - /*! Generates an image from a full string like - * "stone.png^mineral_coal.png^[crack:1:0". - * Shall be called from the main thread. - * The returned Image should be dropped. - * source_image_names is important to determine when to flush the image from a cache (dynamic media) - */ - video::IImage* generateImage(std::string_view name, std::set &source_image_names); - // Thread-safe cache of what source images are known (true = known) MutexedMap m_source_image_existence; @@ -404,78 +302,6 @@ u32 TextureSource::getTextureId(const std::string &name) return 0; } - -/** Draw an image on top of another one with gamma-incorrect alpha compositing - * - * This exists because IImage::copyToWithAlpha() doesn't seem to always work. - * - * \tparam overlay If enabled, only modify pixels in dst which are fully opaque. - * Defaults to false. - * \param src Top image. This image must have the ECF_A8R8G8B8 color format. - * \param dst Bottom image. - * The top image is drawn onto this base image in-place. - * \param dst_pos An offset vector to move src before drawing it onto dst - * \param size Size limit of the copied area -*/ -template -static void blit_with_alpha(video::IImage *src, video::IImage *dst, - v2s32 dst_pos, v2u32 size); - -// Apply a color to an image. Uses an int (0-255) to calculate the ratio. -// If the ratio is 255 or -1 and keep_alpha is true, then it multiples the -// color alpha with the destination alpha. -// Otherwise, any pixels that are not fully transparent get the color alpha. -static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color, int ratio, bool keep_alpha); - -// paint a texture using the given color -static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color); - -// Perform a Screen blend with the given color. The opposite effect of a -// Multiply blend. -static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color); - -// Adjust the hue, saturation, and lightness of destination. Like -// "Hue-Saturation" in GIMP. -// If colorize is true then the image will be converted to a grayscale -// image as though seen through a colored glass, like "Colorize" in GIMP. -static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 hue, s32 saturation, s32 lightness, bool colorize); - -// Apply an overlay blend to an images. -// Overlay blend combines Multiply and Screen blend modes.The parts of the top -// layer where the base layer is light become lighter, the parts where the base -// layer is dark become darker.Areas where the base layer are mid grey are -// unaffected.An overlay with the same picture looks like an S - curve. -static void apply_overlay(video::IImage *overlay, video::IImage *dst, - v2s32 overlay_pos, v2s32 dst_pos, v2u32 size, bool hardlight); - -// Adjust the brightness and contrast of the base image. Conceptually like -// "Brightness-Contrast" in GIMP but allowing brightness to be wound all the -// way up to white or down to black. -static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 brightness, s32 contrast); - -// Apply a mask to an image -static void apply_mask(video::IImage *mask, video::IImage *dst, - v2s32 mask_pos, v2s32 dst_pos, v2u32 size); - -// Draw or overlay a crack -static void draw_crack(video::IImage *crack, video::IImage *dst, - bool use_overlay, s32 frame_count, s32 progression, - video::IVideoDriver *driver, u8 tiles = 1); - -// Brighten image -void brighten(video::IImage *image); -// Parse a transform name -u32 parseImageTransform(std::string_view s); -// Apply transform to image dimension -core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim); -// Apply transform to image data -void imageTransform(u32 transform, video::IImage *src, video::IImage *dst); - /* This method generates all the textures */ @@ -512,7 +338,7 @@ u32 TextureSource::generateTexture(const std::string &name) // passed into texture info for dynamic media tracking std::set source_image_names; - video::IImage *img = generateImage(name, source_image_names); + video::IImage *img = m_imagesource.generateImage(name, source_image_names); video::ITexture *tex = NULL; @@ -595,7 +421,7 @@ Palette* TextureSource::getPalette(const std::string &name) if (it == m_palettes.end()) { // Create palette std::set source_image_names; // unused, sadly. - video::IImage *img = generateImage(name, source_image_names); + video::IImage *img = m_imagesource.generateImage(name, source_image_names); if (!img) { warningstream << "TextureSource::getPalette(): palette \"" << name << "\" could not be loaded." << std::endl; @@ -658,7 +484,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im { sanity_check(std::this_thread::get_id() == m_main_thread); - m_sourcecache.insert(name, img, true); + m_imagesource.insertImage(name, img, true); m_source_image_existence.set(name, true); // now we need to check for any textures that need updating @@ -707,7 +533,7 @@ void TextureSource::rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti) // replaces the previous sourceImages // shouldn't really need to be done, but can't hurt std::set source_image_names; - video::IImage *img = generateImage(ti.name, source_image_names); + video::IImage *img = m_imagesource.generateImage(ti.name, source_image_names); img = Align2Npot2(img, driver); // Create texture from resulting image video::ITexture *t = NULL; @@ -725,1715 +551,6 @@ void TextureSource::rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti) m_texture_trash.push_back(t_old); } -inline static void applyShadeFactor(video::SColor &color, u32 factor) -{ - u32 f = core::clamp(factor, 0, 256); - color.setRed(color.getRed() * f / 256); - color.setGreen(color.getGreen() * f / 256); - color.setBlue(color.getBlue() * f / 256); -} - -static video::IImage *createInventoryCubeImage( - video::IImage *top, video::IImage *left, video::IImage *right) -{ - core::dimension2du size_top = top->getDimension(); - core::dimension2du size_left = left->getDimension(); - core::dimension2du size_right = right->getDimension(); - - u32 size = npot2(std::max({ - size_top.Width, size_top.Height, - size_left.Width, size_left.Height, - size_right.Width, size_right.Height, - })); - - // It must be divisible by 4, to let everything work correctly. - // But it is a power of 2, so being at least 4 is the same. - // And the resulting texture should't be too large as well. - size = core::clamp(size, 4, 64); - - // With such parameters, the cube fits exactly, touching each image line - // from `0` to `cube_size - 1`. (Note that division is exact here). - u32 cube_size = 9 * size; - u32 offset = size / 2; - - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - - auto lock_image = [size, driver] (video::IImage *&image) -> const u32 * { - image->grab(); - core::dimension2du dim = image->getDimension(); - video::ECOLOR_FORMAT format = image->getColorFormat(); - if (dim.Width != size || dim.Height != size || format != video::ECF_A8R8G8B8) { - video::IImage *scaled = driver->createImage(video::ECF_A8R8G8B8, {size, size}); - image->copyToScaling(scaled); - image->drop(); - image = scaled; - } - sanity_check(image->getPitch() == 4 * size); - return reinterpret_cast(image->getData()); - }; - auto free_image = [] (video::IImage *image) -> void { - image->drop(); - }; - - video::IImage *result = driver->createImage(video::ECF_A8R8G8B8, {cube_size, cube_size}); - sanity_check(result->getPitch() == 4 * cube_size); - result->fill(video::SColor(0x00000000u)); - u32 *target = reinterpret_cast(result->getData()); - - // Draws single cube face - // `shade_factor` is face brightness, in range [0.0, 1.0] - // (xu, xv, x1; yu, yv, y1) form coordinate transformation matrix - // `offsets` list pixels to be drawn for single source pixel - auto draw_image = [=] (video::IImage *image, float shade_factor, - s16 xu, s16 xv, s16 x1, - s16 yu, s16 yv, s16 y1, - std::initializer_list offsets) -> void { - u32 brightness = core::clamp(256 * shade_factor, 0, 256); - const u32 *source = lock_image(image); - for (u16 v = 0; v < size; v++) { - for (u16 u = 0; u < size; u++) { - video::SColor pixel(*source); - applyShadeFactor(pixel, brightness); - s16 x = xu * u + xv * v + x1; - s16 y = yu * u + yv * v + y1; - for (const auto &off : offsets) - target[(y + off.Y) * cube_size + (x + off.X) + offset] = pixel.color; - source++; - } - } - free_image(image); - }; - - draw_image(top, 1.000000f, - 4, -4, 4 * (size - 1), - 2, 2, 0, - { - {2, 0}, {3, 0}, {4, 0}, {5, 0}, - {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, - {2, 2}, {3, 2}, {4, 2}, {5, 2}, - }); - - draw_image(left, 0.836660f, - 4, 0, 0, - 2, 5, 2 * size, - { - {0, 0}, {1, 0}, - {0, 1}, {1, 1}, {2, 1}, {3, 1}, - {0, 2}, {1, 2}, {2, 2}, {3, 2}, - {0, 3}, {1, 3}, {2, 3}, {3, 3}, - {0, 4}, {1, 4}, {2, 4}, {3, 4}, - {2, 5}, {3, 5}, - }); - - draw_image(right, 0.670820f, - 4, 0, 4 * size, - -2, 5, 4 * size - 2, - { - {2, 0}, {3, 0}, - {0, 1}, {1, 1}, {2, 1}, {3, 1}, - {0, 2}, {1, 2}, {2, 2}, {3, 2}, - {0, 3}, {1, 3}, {2, 3}, {3, 3}, - {0, 4}, {1, 4}, {2, 4}, {3, 4}, - {0, 5}, {1, 5}, - }); - - return result; -} - -video::IImage* TextureSource::generateImage(std::string_view name, - std::set &source_image_names) -{ - // Get the base image - - const char separator = '^'; - const char escape = '\\'; - const char paren_open = '('; - const char paren_close = ')'; - - // Find last separator in the name - s32 last_separator_pos = -1; - u8 paren_bal = 0; - for (s32 i = name.size() - 1; i >= 0; i--) { - if (i > 0 && name[i-1] == escape) - continue; - switch (name[i]) { - case separator: - if (paren_bal == 0) { - last_separator_pos = i; - i = -1; // break out of loop - } - break; - case paren_open: - if (paren_bal == 0) { - errorstream << "generateImage(): unbalanced parentheses" - << "(extranous '(') while generating texture \"" - << name << "\"" << std::endl; - return NULL; - } - paren_bal--; - break; - case paren_close: - paren_bal++; - break; - default: - break; - } - } - if (paren_bal > 0) { - errorstream << "generateImage(): unbalanced parentheses" - << "(missing matching '(') while generating texture \"" - << name << "\"" << std::endl; - return NULL; - } - - - video::IImage *baseimg = NULL; - - /* - If separator was found, make the base image - using a recursive call. - */ - if (last_separator_pos != -1) { - baseimg = generateImage(name.substr(0, last_separator_pos), source_image_names); - } - - /* - Parse out the last part of the name of the image and act - according to it - */ - - auto last_part_of_name = name.substr(last_separator_pos + 1); - - /* - If this name is enclosed in parentheses, generate it - and blit it onto the base image - */ - if (last_part_of_name.empty()) { - // keep baseimg == nullptr - } else if (last_part_of_name[0] == paren_open - && last_part_of_name.back() == paren_close) { - auto name2 = last_part_of_name.substr(1, - last_part_of_name.size() - 2); - video::IImage *tmp = generateImage(name2, source_image_names); - if (!tmp) { - errorstream << "generateImage(): " - "Failed to generate \"" << name2 << "\"" - << std::endl; - return NULL; - } - - if (baseimg) { - core::dimension2d dim = tmp->getDimension(); - blit_with_alpha(tmp, baseimg, v2s32(0, 0), dim); - tmp->drop(); - } else { - baseimg = tmp; - } - } else if (!generateImagePart(last_part_of_name, baseimg, source_image_names)) { - // Generate image according to part of name - errorstream << "generateImage(): " - "Failed to generate \"" << last_part_of_name << "\"" - << std::endl; - } - - // If no resulting image, print a warning - if (baseimg == NULL) { - errorstream << "generateImage(): baseimg is NULL (attempted to" - " create texture \"" << name << "\")" << std::endl; - } else if (baseimg->getDimension().Width == 0 || - baseimg->getDimension().Height == 0) { - errorstream << "generateImage(): zero-sized image was created?! " - "(attempted to create texture \"" << name << "\")" << std::endl; - baseimg->drop(); - baseimg = nullptr; - } - - return baseimg; -} - -static std::string unescape_string(const std::string &str, const char esc = '\\') -{ - std::string out; - size_t pos = 0, cpos; - out.reserve(str.size()); - while (1) { - cpos = str.find_first_of(esc, pos); - if (cpos == std::string::npos) { - out += str.substr(pos); - break; - } - out += str.substr(pos, cpos - pos) + str[cpos + 1]; - pos = cpos + 2; - } - return out; -} - -/* - Replaces the smaller of the two images with one upscaled to match the - dimensions of the other. - Ensure no other references to these images are being held, as one may - get dropped and switched with a new image. -*/ -void upscaleImagesToMatchLargest(video::IImage *& img1, - video::IImage *& img2) -{ - core::dimension2d dim1 = img1->getDimension(); - core::dimension2d dim2 = img2->getDimension(); - - if (dim1 == dim2) { - // image dimensions match, no scaling required - - } - else if (dim1.Width * dim1.Height < dim2.Width * dim2.Height) { - // Upscale img1 - video::IImage *scaled_image = RenderingEngine::get_video_driver()-> - createImage(video::ECF_A8R8G8B8, dim2); - img1->copyToScaling(scaled_image); - img1->drop(); - img1 = scaled_image; - - } else { - // Upscale img2 - video::IImage *scaled_image = RenderingEngine::get_video_driver()-> - createImage(video::ECF_A8R8G8B8, dim1); - img2->copyToScaling(scaled_image); - img2->drop(); - img2 = scaled_image; - } -} - -void blitBaseImage(video::IImage* &src, video::IImage* &dst) -{ - //infostream<<"Blitting "< dim_dst = dst->getDimension(); - // Position to copy the blitted to in the base image - core::position2d pos_to(0,0); - - blit_with_alpha(src, dst, pos_to, dim_dst); -} - -#define CHECK_BASEIMG() \ - do { \ - if (!baseimg) { \ - errorstream << "generateImagePart(): baseimg == NULL" \ - << " for part_of_name=\"" << part_of_name \ - << "\", cancelling." << std::endl; \ - return false; \ - } \ - } while(0) - -#define COMPLAIN_INVALID(description) \ - do { \ - errorstream << "generateImagePart(): invalid " << (description) \ - << " for part_of_name=\"" << part_of_name \ - << "\", cancelling." << std::endl; \ - return false; \ - } while(0) - -#define CHECK_DIM(w, h) \ - do { \ - if ((w) <= 0 || (h) <= 0 || (w) >= 0xffff || (h) >= 0xffff) { \ - COMPLAIN_INVALID("width or height"); \ - } \ - } while(0) - -bool TextureSource::generateImagePart(std::string_view part_of_name, - video::IImage *& baseimg, std::set &source_image_names) -{ - const char escape = '\\'; // same as in generateImage() - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - sanity_check(driver); - - if (baseimg && (baseimg->getDimension().Width == 0 || - baseimg->getDimension().Height == 0)) { - errorstream << "generateImagePart(): baseimg is zero-sized?!" - << std::endl; - baseimg->drop(); - baseimg = nullptr; - } - - // Stuff starting with [ are special commands - if (part_of_name.empty() || part_of_name[0] != '[') { - std::string part_s(part_of_name); - source_image_names.insert(part_s); - video::IImage *image = m_sourcecache.getOrLoad(part_s); - if (!image) { - // Do not create the dummy texture - if (part_of_name.empty()) - return true; - - // Do not create normalmap dummies - if (str_ends_with(part_of_name, "_normal.png")) { - warningstream << "generateImagePart(): Could not load normal map \"" - << part_of_name << "\"" << std::endl; - return true; - } - - errorstream << "generateImagePart(): Could not load image \"" - << part_of_name << "\" while building texture; " - "Creating a dummy image" << std::endl; - - core::dimension2d dim(1,1); - image = driver->createImage(video::ECF_A8R8G8B8, dim); - sanity_check(image != NULL); - image->setPixel(0,0, video::SColor(255,myrand()%256, - myrand()%256,myrand()%256)); - } - - // If base image is NULL, load as base. - if (baseimg == NULL) - { - /* - Copy it this way to get an alpha channel. - Otherwise images with alpha cannot be blitted on - images that don't have alpha in the original file. - */ - core::dimension2d dim = image->getDimension(); - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - image->copyTo(baseimg); - } - // Else blit on base. - else - { - blitBaseImage(image, baseimg); - } - - image->drop(); - } - else - { - // A special texture modification - - /* - [crack:N:P - [cracko:N:P - Adds a cracking texture - N = animation frame count, P = crack progression - */ - if (str_starts_with(part_of_name, "[crack")) - { - CHECK_BASEIMG(); - - // Crack image number and overlay option - // Format: crack[o][:]:: - bool use_overlay = (part_of_name[6] == 'o'); - Strfnd sf(part_of_name); - sf.next(":"); - s32 frame_count = stoi(sf.next(":")); - s32 progression = stoi(sf.next(":")); - s32 tiles = 1; - // Check whether there is the argument, that is, - // whether there are 3 arguments. If so, shift values - // as the first and not the last argument is optional. - auto s = sf.next(":"); - if (!s.empty()) { - tiles = frame_count; - frame_count = progression; - progression = stoi(s); - } - - if (progression >= 0) { - /* - Load crack image. - - It is an image with a number of cracking stages - horizontally tiled. - */ - video::IImage *img_crack = m_sourcecache.getOrLoad( - "crack_anylength.png"); - - if (img_crack) { - draw_crack(img_crack, baseimg, - use_overlay, frame_count, - progression, driver, tiles); - img_crack->drop(); - } - } - } - /* - [combine:WxH:X,Y=filename:X,Y=filename2 - Creates a bigger texture from any amount of smaller ones - */ - else if (str_starts_with(part_of_name, "[combine")) - { - Strfnd sf(part_of_name); - sf.next(":"); - u32 w0 = stoi(sf.next("x")); - u32 h0 = stoi(sf.next(":")); - if (!baseimg) { - CHECK_DIM(w0, h0); - baseimg = driver->createImage(video::ECF_A8R8G8B8, {w0, h0}); - baseimg->fill(video::SColor(0,0,0,0)); - } - - while (!sf.at_end()) { - v2s32 pos_base; - pos_base.X = stoi(sf.next(",")); - pos_base.Y = stoi(sf.next("=")); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - auto basedim = baseimg->getDimension(); - if (pos_base.X > (s32)basedim.Width || pos_base.Y > (s32)basedim.Height) { - warningstream << "generateImagePart(): Skipping \"" - << filename << "\" as it's out-of-bounds " << pos_base - << " for [combine" << std::endl; - continue; - } - infostream << "Adding \"" << filename<< "\" to combined " - << pos_base << std::endl; - - video::IImage *img = generateImage(filename, source_image_names); - if (!img) { - errorstream << "generateImagePart(): Failed to load image \"" - << filename << "\" for [combine" << std::endl; - continue; - } - const auto dim = img->getDimension(); - if (pos_base.X + dim.Width <= 0 || pos_base.Y + dim.Height <= 0) { - warningstream << "generateImagePart(): Skipping \"" - << filename << "\" as it's out-of-bounds " << pos_base - << " for [combine" << std::endl; - img->drop(); - continue; - } - - blit_with_alpha(img, baseimg, pos_base, dim); - img->drop(); - } - } - /* - [fill:WxH:color - [fill:WxH:X,Y:color - Creates a texture of the given size and color, optionally with an , - position. An alpha value may be specified in the `Colorstring`. - */ - else if (str_starts_with(part_of_name, "[fill")) - { - u32 x = 0; - u32 y = 0; - - Strfnd sf(part_of_name); - sf.next(":"); - u32 width = stoi(sf.next("x")); - u32 height = stoi(sf.next(":")); - std::string color_or_x = sf.next(","); - - video::SColor color; - if (!parseColorString(color_or_x, color, true)) { - x = stoi(color_or_x); - y = stoi(sf.next(":")); - std::string color_str = sf.next(":"); - - if (!parseColorString(color_str, color, false)) - return false; - } - core::dimension2d dim(width, height); - - CHECK_DIM(dim.Width, dim.Height); - if (baseimg) { - auto basedim = baseimg->getDimension(); - if (x >= basedim.Width || y >= basedim.Height) - COMPLAIN_INVALID("X or Y offset"); - } - - video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim); - img->fill(color); - - if (baseimg == nullptr) { - baseimg = img; - } else { - blit_with_alpha(img, baseimg, v2s32(x, y), dim); - img->drop(); - } - } - /* - [brighten - */ - else if (str_starts_with(part_of_name, "[brighten")) - { - CHECK_BASEIMG(); - - brighten(baseimg); - } - /* - [noalpha - Make image completely opaque. - Used for the leaves texture when in old leaves mode, so - that the transparent parts don't look completely black - when simple alpha channel is used for rendering. - */ - else if (str_starts_with(part_of_name, "[noalpha")) - { - CHECK_BASEIMG(); - core::dimension2d dim = baseimg->getDimension(); - - // Set alpha to full - for (u32 y=0; ygetPixel(x,y); - c.setAlpha(255); - baseimg->setPixel(x,y,c); - } - } - /* - [makealpha:R,G,B - Convert one color to transparent. - */ - else if (str_starts_with(part_of_name, "[makealpha:")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name.substr(11)); - u32 r1 = stoi(sf.next(",")); - u32 g1 = stoi(sf.next(",")); - u32 b1 = stoi(sf.next("")); - - core::dimension2d dim = baseimg->getDimension(); - - for (u32 y=0; ygetPixel(x,y); - u32 r = c.getRed(); - u32 g = c.getGreen(); - u32 b = c.getBlue(); - if (!(r == r1 && g == g1 && b == b1)) - continue; - c.setAlpha(0); - baseimg->setPixel(x,y,c); - } - } - /* - [transformN - Rotates and/or flips the image. - - N can be a number (between 0 and 7) or a transform name. - Rotations are counter-clockwise. - 0 I identity - 1 R90 rotate by 90 degrees - 2 R180 rotate by 180 degrees - 3 R270 rotate by 270 degrees - 4 FX flip X - 5 FXR90 flip X then rotate by 90 degrees - 6 FY flip Y - 7 FYR90 flip Y then rotate by 90 degrees - - Note: Transform names can be concatenated to produce - their product (applies the first then the second). - The resulting transform will be equivalent to one of the - eight existing ones, though (see: dihedral group). - */ - else if (str_starts_with(part_of_name, "[transform")) - { - CHECK_BASEIMG(); - - u32 transform = parseImageTransform(part_of_name.substr(10)); - core::dimension2d dim = imageTransformDimension( - transform, baseimg->getDimension()); - video::IImage *image = driver->createImage( - baseimg->getColorFormat(), dim); - sanity_check(image != NULL); - imageTransform(transform, baseimg, image); - baseimg->drop(); - baseimg = image; - } - /* - [inventorycube{topimage{leftimage{rightimage - In every subimage, replace ^ with &. - Create an "inventory cube". - NOTE: This should be used only on its own. - Example (a grass block (not actually used in game): - "[inventorycube{grass.png{mud.png&grass_side.png{mud.png&grass_side.png" - */ - else if (str_starts_with(part_of_name, "[inventorycube")) - { - if (baseimg) { - errorstream<<"generateImagePart(): baseimg != NULL " - <<"for part_of_name=\""<drop(); - img_left->drop(); - img_right->drop(); - - return true; - } - /* - [lowpart:percent:filename - Adds the lower part of a texture - */ - else if (str_starts_with(part_of_name, "[lowpart:")) - { - Strfnd sf(part_of_name); - sf.next(":"); - u32 percent = stoi(sf.next(":"), 0, 100); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - video::IImage *img = generateImage(filename, source_image_names); - if (img) { - core::dimension2d dim = img->getDimension(); - if (!baseimg) - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - - core::position2d pos_base(0, 0); - core::position2d clippos(0, 0); - clippos.Y = dim.Height * (100-percent) / 100; - core::dimension2d clipdim = dim; - clipdim.Height = clipdim.Height * percent / 100 + 1; - core::rect cliprect(clippos, clipdim); - img->copyToWithAlpha(baseimg, pos_base, - core::rect(v2s32(0,0), dim), - video::SColor(255,255,255,255), - &cliprect); - img->drop(); - } - } - /* - [verticalframe:N:I - Crops a frame of a vertical animation. - N = frame count, I = frame index - */ - else if (str_starts_with(part_of_name, "[verticalframe:")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - u32 frame_count = stoi(sf.next(":")); - u32 frame_index = stoi(sf.next(":")); - - if (frame_count == 0){ - errorstream << "generateImagePart(): invalid frame_count " - << "for part_of_name=\"" << part_of_name - << "\", using frame_count = 1 instead." << std::endl; - frame_count = 1; - } - if (frame_index >= frame_count) - frame_index = frame_count - 1; - - v2u32 frame_size = baseimg->getDimension(); - frame_size.Y /= frame_count; - - video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, - frame_size); - - // Fill target image with transparency - img->fill(video::SColor(0,0,0,0)); - - core::dimension2d dim = frame_size; - core::position2d pos_dst(0, 0); - core::position2d pos_src(0, frame_index * frame_size.Y); - baseimg->copyToWithAlpha(img, pos_dst, - core::rect(pos_src, dim), - video::SColor(255,255,255,255), - NULL); - // Replace baseimg - baseimg->drop(); - baseimg = img; - } - /* - [mask:filename - Applies a mask to an image - */ - else if (str_starts_with(part_of_name, "[mask:")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - video::IImage *img = generateImage(filename, source_image_names); - if (img) { - apply_mask(img, baseimg, v2s32(0, 0), v2s32(0, 0), - img->getDimension()); - img->drop(); - } else { - errorstream << "generateImagePart(): Failed to load image \"" - << filename << "\" for [mask" << std::endl; - } - } - /* - [multiply:color - or - [screen:color - Multiply and Screen blend modes are basic blend modes for darkening and lightening - images, respectively. - A Multiply blend multiplies a given color to every pixel of an image. - A Screen blend has the opposite effect to a Multiply blend. - color = color as ColorString - */ - else if (str_starts_with(part_of_name, "[multiply:") || - str_starts_with(part_of_name, "[screen:")) { - Strfnd sf(part_of_name); - sf.next(":"); - std::string color_str = sf.next(":"); - - CHECK_BASEIMG(); - - video::SColor color; - - if (!parseColorString(color_str, color, false)) - return false; - if (str_starts_with(part_of_name, "[multiply:")) { - apply_multiplication(baseimg, v2u32(0, 0), - baseimg->getDimension(), color); - } else { - apply_screen(baseimg, v2u32(0, 0), baseimg->getDimension(), color); - } - } - /* - [colorize:color:ratio - Overlays image with given color - color = color as ColorString - ratio = optional string "alpha", or a weighting between 0 and 255 - */ - else if (str_starts_with(part_of_name, "[colorize:")) - { - Strfnd sf(part_of_name); - sf.next(":"); - std::string color_str = sf.next(":"); - std::string ratio_str = sf.next(":"); - - CHECK_BASEIMG(); - - video::SColor color; - int ratio = -1; - bool keep_alpha = false; - - if (!parseColorString(color_str, color, false)) - return false; - - if (is_number(ratio_str)) - ratio = mystoi(ratio_str, 0, 255); - else if (ratio_str == "alpha") - keep_alpha = true; - - apply_colorize(baseimg, v2u32(0, 0), baseimg->getDimension(), color, ratio, keep_alpha); - } - /* - [applyfiltersformesh - Internal modifier - */ - else if (str_starts_with(part_of_name, "[applyfiltersformesh")) - { - /* IMPORTANT: When changing this, getTextureForMesh() needs to be - * updated too. */ - - CHECK_BASEIMG(); - - // Apply the "clean transparent" filter, if needed - if (m_setting_mipmap || m_setting_bilinear_filter || - m_setting_trilinear_filter || m_setting_anisotropic_filter) - imageCleanTransparent(baseimg, 127); - - /* Upscale textures to user's requested minimum size. This is a trick to make - * filters look as good on low-res textures as on high-res ones, by making - * low-res textures BECOME high-res ones. This is helpful for worlds that - * mix high- and low-res textures, or for mods with least-common-denominator - * textures that don't have the resources to offer high-res alternatives. - */ - const bool filter = m_setting_trilinear_filter || m_setting_bilinear_filter; - const s32 scaleto = filter ? g_settings->getU16("texture_min_size") : 1; - if (scaleto > 1) { - const core::dimension2d dim = baseimg->getDimension(); - - /* Calculate scaling needed to make the shortest texture dimension - * equal to the target minimum. If e.g. this is a vertical frames - * animation, the short dimension will be the real size. - */ - u32 xscale = scaleto / dim.Width; - u32 yscale = scaleto / dim.Height; - const s32 scale = std::max(xscale, yscale); - - // Never downscale; only scale up by 2x or more. - if (scale > 1) { - u32 w = scale * dim.Width; - u32 h = scale * dim.Height; - const core::dimension2d newdim(w, h); - video::IImage *newimg = driver->createImage( - baseimg->getColorFormat(), newdim); - baseimg->copyToScaling(newimg); - baseimg->drop(); - baseimg = newimg; - } - } - } - /* - [resize:WxH - Resizes the base image to the given dimensions - */ - else if (str_starts_with(part_of_name, "[resize")) - { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - u32 width = stoi(sf.next("x")); - u32 height = stoi(sf.next("")); - CHECK_DIM(width, height); - - video::IImage *image = driver-> - createImage(video::ECF_A8R8G8B8, {width, height}); - baseimg->copyToScaling(image); - baseimg->drop(); - baseimg = image; - } - /* - [opacity:R - Makes the base image transparent according to the given ratio. - R must be between 0 and 255. - 0 means totally transparent. - 255 means totally opaque. - */ - else if (str_starts_with(part_of_name, "[opacity:")) { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - - u32 ratio = mystoi(sf.next(""), 0, 255); - - core::dimension2d dim = baseimg->getDimension(); - - for (u32 y = 0; y < dim.Height; y++) - for (u32 x = 0; x < dim.Width; x++) - { - video::SColor c = baseimg->getPixel(x, y); - c.setAlpha(floor((c.getAlpha() * ratio) / 255 + 0.5)); - baseimg->setPixel(x, y, c); - } - } - /* - [invert:mode - Inverts the given channels of the base image. - Mode may contain the characters "r", "g", "b", "a". - Only the channels that are mentioned in the mode string - will be inverted. - */ - else if (str_starts_with(part_of_name, "[invert:")) { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - - std::string mode = sf.next(""); - u32 mask = 0; - if (mode.find('a') != std::string::npos) - mask |= 0xff000000UL; - if (mode.find('r') != std::string::npos) - mask |= 0x00ff0000UL; - if (mode.find('g') != std::string::npos) - mask |= 0x0000ff00UL; - if (mode.find('b') != std::string::npos) - mask |= 0x000000ffUL; - - core::dimension2d dim = baseimg->getDimension(); - - for (u32 y = 0; y < dim.Height; y++) - for (u32 x = 0; x < dim.Width; x++) - { - video::SColor c = baseimg->getPixel(x, y); - c.color ^= mask; - baseimg->setPixel(x, y, c); - } - } - /* - [sheet:WxH:X,Y - Retrieves a tile at position X,Y (in tiles) - from the base image it assumes to be a - tilesheet with dimensions W,H (in tiles). - */ - else if (str_starts_with(part_of_name, "[sheet:")) { - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - u32 w0 = stoi(sf.next("x")); - u32 h0 = stoi(sf.next(":")); - u32 x0 = stoi(sf.next(",")); - u32 y0 = stoi(sf.next(":")); - - CHECK_DIM(w0, h0); - if (x0 >= w0 || y0 >= h0) - COMPLAIN_INVALID("tile position (X,Y)"); - - core::dimension2d img_dim = baseimg->getDimension(); - core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); - if (tile_dim.Width == 0) - tile_dim.Width = 1; - if (tile_dim.Height == 0) - tile_dim.Height = 1; - - video::IImage *img = driver->createImage( - video::ECF_A8R8G8B8, tile_dim); - img->fill(video::SColor(0,0,0,0)); - - v2u32 vdim(tile_dim); - core::rect rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); - baseimg->copyToWithAlpha(img, v2s32(0), rect, - video::SColor(255,255,255,255), NULL); - - // Replace baseimg - baseimg->drop(); - baseimg = img; - } - /* - [png:base64 - Decodes a PNG image in base64 form. - Use minetest.encode_png and minetest.encode_base64 - to produce a valid string. - */ - else if (str_starts_with(part_of_name, "[png:")) { - std::string png; - { - auto blob = part_of_name.substr(5); - if (!base64_is_valid(blob)) { - errorstream << "generateImagePart(): " - << "malformed base64 in [png" << std::endl; - return false; - } - png = base64_decode(blob); - } - - auto *device = RenderingEngine::get_raw_device(); - auto *fs = device->getFileSystem(); - auto *vd = device->getVideoDriver(); - auto *memfile = fs->createMemoryReadFile(png.data(), png.size(), "__temp_png"); - video::IImage* pngimg = vd->createImageFromFile(memfile); - memfile->drop(); - - if (!pngimg) { - errorstream << "generateImagePart(): Invalid PNG data" << std::endl; - return false; - } - - if (baseimg) { - blitBaseImage(pngimg, baseimg); - } else { - core::dimension2d dim = pngimg->getDimension(); - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - pngimg->copyTo(baseimg); - } - pngimg->drop(); - } - /* - [hsl:hue:saturation:lightness - or - [colorizehsl:hue:saturation:lightness - - Adjust the hue, saturation, and lightness of the base image. Like - "Hue-Saturation" in GIMP, but with 0 as the mid-point. - Hue should be from -180 to +180, though 0 to 360 is also supported. - Saturation and lightness are optional, with lightness from -100 to - +100, and sauration from -100 to +100-or-higher. - - If colorize is true then saturation is from 0 to 100, and the image - will be converted to a grayscale image as though seen through a - colored glass, like "Colorize" in GIMP. - */ - else if (str_starts_with(part_of_name, "[hsl:") || - str_starts_with(part_of_name, "[colorizehsl:")) { - - CHECK_BASEIMG(); - - bool colorize = str_starts_with(part_of_name, "[colorizehsl:"); - - // saturation range is 0 to 100 when colorize is true - s32 defaultSaturation = colorize ? 50 : 0; - - Strfnd sf(part_of_name); - sf.next(":"); - s32 hue = mystoi(sf.next(":"), -180, 360); - s32 saturation = sf.at_end() ? defaultSaturation : mystoi(sf.next(":"), -100, 1000); - s32 lightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -100, 100); - - - apply_hue_saturation(baseimg, v2u32(0, 0), baseimg->getDimension(), - hue, saturation, lightness, colorize); - } - /* - [overlay:filename - or - [hardlight:filename - - "A.png^[hardlight:B.png" is the same as "B.png^[overlay:A.Png" - - Applies an Overlay or Hard Light blend between two images, like the - layer modes of the same names in GIMP. - Overlay combines Multiply and Screen blend modes. The parts of the - top layer where the base layer is light become lighter, the parts - where the base layer is dark become darker. Areas where the base - layer are mid grey are unaffected. An overlay with the same picture - looks like an S-curve. - - Swapping the top layer and base layer is a Hard Light blend - */ - else if (str_starts_with(part_of_name, "[overlay:") || - str_starts_with(part_of_name, "[hardlight:")) { - - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - std::string filename = unescape_string(sf.next_esc(":", escape), escape); - - video::IImage *img = generateImage(filename, source_image_names); - if (img) { - upscaleImagesToMatchLargest(baseimg, img); - - bool hardlight = str_starts_with(part_of_name, "[hardlight:"); - apply_overlay(img, baseimg, v2s32(0, 0), v2s32(0, 0), - img->getDimension(), hardlight); - img->drop(); - } else { - errorstream << "generateImage(): Failed to load image \"" - << filename << "\" for [overlay or [hardlight" << std::endl; - } - } - /* - [contrast:C:B - - Adjust the brightness and contrast of the base image. Conceptually - like GIMP's "Brightness-Contrast" feature but allows brightness to - be wound all the way up to white or down to black. - C and B are both values from -127 to +127. - B is optional. - */ - else if (str_starts_with(part_of_name, "[contrast:")) { - - CHECK_BASEIMG(); - - Strfnd sf(part_of_name); - sf.next(":"); - s32 contrast = mystoi(sf.next(":"), -127, 127); - s32 brightness = sf.at_end() ? 0 : mystoi(sf.next(":"), -127, 127); - - apply_brightness_contrast(baseimg, v2u32(0, 0), - baseimg->getDimension(), brightness, contrast); - } - else - { - errorstream << "generateImagePart(): Invalid " - " modification: \"" << part_of_name << "\"" << std::endl; - } - } - - return true; -} - -#undef CHECK_BASEIMG - -#undef COMPLAIN_INVALID - -#undef CHECK_DIM - - -namespace { - -/** Calculate the color of a single pixel drawn on top of another pixel without - * gamma correction - * - * The color mixing is a little more complicated than just - * video::SColor::getInterpolated because getInterpolated does not handle alpha - * correctly. - * For example, a pixel with alpha=64 drawn atop a pixel with alpha=128 should - * yield a pixel with alpha=160, while getInterpolated would yield alpha=96. - * - * \tparam overlay If enabled, only modify dst_col if it is fully opaque - * \param src_col Color of the top pixel - * \param dst_col Color of the bottom pixel. This color is modified in-place to - * store the result. -*/ -template -void blit_pixel(video::SColor src_col, video::SColor &dst_col) -{ - u8 dst_a = (u8)dst_col.getAlpha(); - if constexpr (overlay) { - if (dst_a != 255) - // The bottom pixel has transparency -> do nothing - return; - } - u8 src_a = (u8)src_col.getAlpha(); - if (src_a == 0) { - // A fully transparent pixel is on top -> do nothing - return; - } - if (src_a == 255 || dst_a == 0) { - // The top pixel is fully opaque or the bottom pixel is - // fully transparent -> replace the color - dst_col = src_col; - return; - } - struct Color { u8 r, g, b; }; - Color src{(u8)src_col.getRed(), (u8)src_col.getGreen(), - (u8)src_col.getBlue()}; - Color dst{(u8)dst_col.getRed(), (u8)dst_col.getGreen(), - (u8)dst_col.getBlue()}; - if (dst_a == 255) { - // A semi-transparent pixel is on top and an opaque one in - // the bottom -> lerp r, g, and b - dst.r = (dst.r * (255 - src_a) + src.r * src_a) / 255; - dst.g = (dst.g * (255 - src_a) + src.g * src_a) / 255; - dst.b = (dst.b * (255 - src_a) + src.b * src_a) / 255; - dst_col.set(255, dst.r, dst.g, dst.b); - return; - } - // A semi-transparent pixel is on top of a - // semi-transparent pixel -> general alpha compositing - u16 a_new_255 = src_a * 255 + (255 - src_a) * dst_a; - dst.r = (dst.r * (255 - src_a) * dst_a + src.r * src_a * 255) / a_new_255; - dst.g = (dst.g * (255 - src_a) * dst_a + src.g * src_a * 255) / a_new_255; - dst.b = (dst.b * (255 - src_a) * dst_a + src.b * src_a * 255) / a_new_255; - dst_a = (a_new_255 + 127) / 255; - dst_col.set(dst_a, dst.r, dst.g, dst.b); -} - -} // namespace - -template -void blit_with_alpha(video::IImage *src, video::IImage *dst, v2s32 dst_pos, - v2u32 size) -{ - if (dst->getColorFormat() != video::ECF_A8R8G8B8) - throw BaseException("blit_with_alpha() supports only ECF_A8R8G8B8 " - "destination images."); - - core::dimension2d src_dim = src->getDimension(); - core::dimension2d dst_dim = dst->getDimension(); - bool drop_src = false; - if (src->getColorFormat() != video::ECF_A8R8G8B8) { - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - video::IImage *src_converted = driver->createImage(video::ECF_A8R8G8B8, - src_dim); - if (!src_converted) - throw BaseException("blit_with_alpha() failed to convert the " - "source image to ECF_A8R8G8B8."); - src->copyTo(src_converted); - src = src_converted; - drop_src = true; - } - video::SColor *pixels_src = - reinterpret_cast(src->getData()); - video::SColor *pixels_dst = - reinterpret_cast(dst->getData()); - // Limit y and x to the overlapping ranges - // s.t. the positions are all in bounds after offsetting. - u32 x_start = (u32)std::max(0, -dst_pos.X); - u32 y_start = (u32)std::max(0, -dst_pos.Y); - u32 x_end = (u32)std::min({size.X, src_dim.Width, - dst_dim.Width - (s64)dst_pos.X}); - u32 y_end = (u32)std::min({size.Y, src_dim.Height, - dst_dim.Height - (s64)dst_pos.Y}); - for (u32 y0 = y_start; y0 < y_end; ++y0) { - size_t i_src = y0 * src_dim.Width + x_start; - size_t i_dst = (dst_pos.Y + y0) * dst_dim.Width + dst_pos.X + x_start; - for (u32 x0 = x_start; x0 < x_end; ++x0) { - blit_pixel(pixels_src[i_src++], pixels_dst[i_dst++]); - } - } - if (drop_src) - src->drop(); -} - -/* - Apply color to destination, using a weighted interpolation blend -*/ -static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color, int ratio, bool keep_alpha) -{ - u32 alpha = color.getAlpha(); - video::SColor dst_c; - if ((ratio == -1 && alpha == 255) || ratio == 255) { // full replacement of color - if (keep_alpha) { // replace the color with alpha = dest alpha * color alpha - dst_c = color; - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - u32 dst_alpha = dst->getPixel(x, y).getAlpha(); - if (dst_alpha > 0) { - dst_c.setAlpha(dst_alpha * alpha / 255); - dst->setPixel(x, y, dst_c); - } - } - } else { // replace the color including the alpha - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) - if (dst->getPixel(x, y).getAlpha() > 0) - dst->setPixel(x, y, color); - } - } else { // interpolate between the color and destination - float interp = (ratio == -1 ? color.getAlpha() / 255.0f : ratio / 255.0f); - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - if (dst_c.getAlpha() > 0) { - dst_c = color.getInterpolated(dst_c, interp); - dst->setPixel(x, y, dst_c); - } - } - } -} - -/* - Apply color to destination, using a Multiply blend mode -*/ -static void apply_multiplication(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color) -{ - video::SColor dst_c; - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - dst_c.set( - dst_c.getAlpha(), - (dst_c.getRed() * color.getRed()) / 255, - (dst_c.getGreen() * color.getGreen()) / 255, - (dst_c.getBlue() * color.getBlue()) / 255 - ); - dst->setPixel(x, y, dst_c); - } -} - -/* - Apply color to destination, using a Screen blend mode -*/ -static void apply_screen(video::IImage *dst, v2u32 dst_pos, v2u32 size, - const video::SColor color) -{ - video::SColor dst_c; - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - dst_c.set( - dst_c.getAlpha(), - 255 - ((255 - dst_c.getRed()) * (255 - color.getRed())) / 255, - 255 - ((255 - dst_c.getGreen()) * (255 - color.getGreen())) / 255, - 255 - ((255 - dst_c.getBlue()) * (255 - color.getBlue())) / 255 - ); - dst->setPixel(x, y, dst_c); - } -} - -/* - Adjust the hue, saturation, and lightness of destination. Like - "Hue-Saturation" in GIMP, but with 0 as the mid-point. - Hue should be from -180 to +180, or from 0 to 360. - Saturation and Lightness are percentages. - Lightness is from -100 to +100. - Saturation goes down to -100 (fully desaturated) but can go above 100, - allowing for even muted colors to become saturated. - - If colorize is true then saturation is from 0 to 100, and destination will - be converted to a grayscale image as seen through a colored glass, like - "Colorize" in GIMP. -*/ -static void apply_hue_saturation(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 hue, s32 saturation, s32 lightness, bool colorize) -{ - video::SColorf colorf; - video::SColorHSL hsl; - f32 norm_s = core::clamp(saturation, -100, 1000) / 100.0f; - f32 norm_l = core::clamp(lightness, -100, 100) / 100.0f; - - if (colorize) { - hsl.Saturation = core::clamp((f32)saturation, 0.0f, 100.0f); - } - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - - if (colorize) { - f32 lum = dst->getPixel(x, y).getLuminance() / 255.0f; - - if (norm_l < 0) { - lum *= norm_l + 1.0f; - } else { - lum = lum * (1.0f - norm_l) + norm_l; - } - hsl.Hue = 0; - hsl.Luminance = lum * 100; - - } else { - // convert the RGB to HSL - colorf = video::SColorf(dst->getPixel(x, y)); - hsl.fromRGB(colorf); - - if (norm_l < 0) { - hsl.Luminance *= norm_l + 1.0f; - } else{ - hsl.Luminance = hsl.Luminance + norm_l * (100.0f - hsl.Luminance); - } - - // Adjusting saturation in the same manner as lightness resulted in - // muted colors being affected too much and bright colors not - // affected enough, so I'm borrowing a leaf out of gimp's book and - // using a different scaling approach for saturation. - // https://github.com/GNOME/gimp/blob/6cc1e035f1822bf5198e7e99a53f7fa6e281396a/app/operations/gimpoperationhuesaturation.c#L139-L145= - // This difference is why values over 100% are not necessary for - // lightness but are very useful with saturation. An alternative UI - // approach would be to have an upper saturation limit of 100, but - // multiply positive values by ~3 to make it a more useful positive - // range scale. - hsl.Saturation *= norm_s + 1.0f; - hsl.Saturation = core::clamp(hsl.Saturation, 0.0f, 100.0f); - } - - // Apply the specified HSL adjustments - hsl.Hue = fmod(hsl.Hue + hue, 360); - if (hsl.Hue < 0) - hsl.Hue += 360; - - // Convert back to RGB - hsl.toRGB(colorf); - dst->setPixel(x, y, colorf.toSColor()); - } -} - - -/* - Apply an Overlay blend to destination - If hardlight is true then swap the dst & blend images (a hardlight blend) -*/ -static void apply_overlay(video::IImage *blend, video::IImage *dst, - v2s32 blend_pos, v2s32 dst_pos, v2u32 size, bool hardlight) -{ - video::IImage *blend_layer = hardlight ? dst : blend; - video::IImage *base_layer = hardlight ? blend : dst; - v2s32 blend_layer_pos = hardlight ? dst_pos : blend_pos; - v2s32 base_layer_pos = hardlight ? blend_pos : dst_pos; - - for (u32 y = 0; y < size.Y; y++) - for (u32 x = 0; x < size.X; x++) { - s32 base_x = x + base_layer_pos.X; - s32 base_y = y + base_layer_pos.Y; - - video::SColor blend_c = - blend_layer->getPixel(x + blend_layer_pos.X, y + blend_layer_pos.Y); - video::SColor base_c = base_layer->getPixel(base_x, base_y); - double blend_r = blend_c.getRed() / 255.0; - double blend_g = blend_c.getGreen() / 255.0; - double blend_b = blend_c.getBlue() / 255.0; - double base_r = base_c.getRed() / 255.0; - double base_g = base_c.getGreen() / 255.0; - double base_b = base_c.getBlue() / 255.0; - - base_c.set( - base_c.getAlpha(), - // Do a Multiply blend if less that 0.5, otherwise do a Screen blend - (u32)((base_r < 0.5 ? 2 * base_r * blend_r : 1 - 2 * (1 - base_r) * (1 - blend_r)) * 255), - (u32)((base_g < 0.5 ? 2 * base_g * blend_g : 1 - 2 * (1 - base_g) * (1 - blend_g)) * 255), - (u32)((base_b < 0.5 ? 2 * base_b * blend_b : 1 - 2 * (1 - base_b) * (1 - blend_b)) * 255) - ); - dst->setPixel(base_x, base_y, base_c); - } -} - -/* - Adjust the brightness and contrast of the base image. - - Conceptually like GIMP's "Brightness-Contrast" feature but allows brightness to be - wound all the way up to white or down to black. -*/ -static void apply_brightness_contrast(video::IImage *dst, v2u32 dst_pos, v2u32 size, - s32 brightness, s32 contrast) -{ - video::SColor dst_c; - // Only allow normalized contrast to get as high as 127/128 to avoid infinite slope. - // (we could technically allow -128/128 here as that would just result in 0 slope) - double norm_c = core::clamp(contrast, -127, 127) / 128.0; - double norm_b = core::clamp(brightness, -127, 127) / 127.0; - - // Scale brightness so its range is -127.5 to 127.5, otherwise brightness - // adjustments will outputs values from 0.5 to 254.5 instead of 0 to 255. - double scaled_b = brightness * 127.5 / 127; - - // Calculate a contrast slope such that that no colors will get clamped due - // to the brightness setting. - // This allows the texture modifier to used as a brightness modifier without - // the user having to calculate a contrast to avoid clipping at that brightness. - double slope = 1 - fabs(norm_b); - - // Apply the user's contrast adjustment to the calculated slope, such that - // -127 will make it near-vertical and +127 will make it horizontal - double angle = atan(slope); - angle += norm_c <= 0 - ? norm_c * angle // allow contrast slope to be lowered to 0 - : norm_c * (M_PI_2 - angle); // allow contrast slope to be raised almost vert. - slope = tan(angle); - - double c = slope <= 1 - ? -slope * 127.5 + 127.5 + scaled_b // shift up/down when slope is horiz. - : -slope * (127.5 - scaled_b) + 127.5; // shift left/right when slope is vert. - - // add 0.5 to c so that when the final result is cast to int, it is effectively - // rounded rather than trunc'd. - c += 0.5; - - for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++) - for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) { - dst_c = dst->getPixel(x, y); - - dst_c.set( - dst_c.getAlpha(), - core::clamp((int)(slope * dst_c.getRed() + c), 0, 255), - core::clamp((int)(slope * dst_c.getGreen() + c), 0, 255), - core::clamp((int)(slope * dst_c.getBlue() + c), 0, 255) - ); - dst->setPixel(x, y, dst_c); - } -} - -/* - Apply mask to destination -*/ -static void apply_mask(video::IImage *mask, video::IImage *dst, - v2s32 mask_pos, v2s32 dst_pos, v2u32 size) -{ - for (u32 y0 = 0; y0 < size.Y; y0++) { - for (u32 x0 = 0; x0 < size.X; x0++) { - s32 mask_x = x0 + mask_pos.X; - s32 mask_y = y0 + mask_pos.Y; - s32 dst_x = x0 + dst_pos.X; - s32 dst_y = y0 + dst_pos.Y; - video::SColor mask_c = mask->getPixel(mask_x, mask_y); - video::SColor dst_c = dst->getPixel(dst_x, dst_y); - dst_c.color &= mask_c.color; - dst->setPixel(dst_x, dst_y, dst_c); - } - } -} - -video::IImage *create_crack_image(video::IImage *crack, s32 frame_index, - core::dimension2d size, u8 tiles, video::IVideoDriver *driver) -{ - core::dimension2d strip_size = crack->getDimension(); - - if (tiles == 0 || strip_size.getArea() == 0) - return nullptr; - - core::dimension2d frame_size(strip_size.Width, strip_size.Width); - core::dimension2d tile_size(size / tiles); - s32 frame_count = strip_size.Height / strip_size.Width; - if (frame_index >= frame_count) - frame_index = frame_count - 1; - core::rect frame(v2s32(0, frame_index * frame_size.Height), frame_size); - video::IImage *result = nullptr; - - // extract crack frame - video::IImage *crack_tile = driver->createImage(video::ECF_A8R8G8B8, tile_size); - if (!crack_tile) - return nullptr; - if (tile_size == frame_size) { - crack->copyTo(crack_tile, v2s32(0, 0), frame); - } else { - video::IImage *crack_frame = driver->createImage(video::ECF_A8R8G8B8, frame_size); - if (!crack_frame) - goto exit__has_tile; - crack->copyTo(crack_frame, v2s32(0, 0), frame); - crack_frame->copyToScaling(crack_tile); - crack_frame->drop(); - } - if (tiles == 1) - return crack_tile; - - // tile it - result = driver->createImage(video::ECF_A8R8G8B8, size); - if (!result) - goto exit__has_tile; - result->fill({}); - for (u8 i = 0; i < tiles; i++) - for (u8 j = 0; j < tiles; j++) - crack_tile->copyTo(result, v2s32(i * tile_size.Width, j * tile_size.Height)); - -exit__has_tile: - crack_tile->drop(); - return result; -} - -static void draw_crack(video::IImage *crack, video::IImage *dst, - bool use_overlay, s32 frame_count, s32 progression, - video::IVideoDriver *driver, u8 tiles) -{ - // Dimension of destination image - core::dimension2d dim_dst = dst->getDimension(); - // Limit frame_count - if (frame_count > (s32) dim_dst.Height) - frame_count = dim_dst.Height; - if (frame_count < 1) - frame_count = 1; - // Dimension of the scaled crack stage, - // which is the same as the dimension of a single destination frame - core::dimension2d frame_size( - dim_dst.Width, - dim_dst.Height / frame_count - ); - video::IImage *crack_scaled = create_crack_image(crack, progression, - frame_size, tiles, driver); - if (!crack_scaled) - return; - - auto blit = use_overlay ? blit_with_alpha : blit_with_alpha; - for (s32 i = 0; i < frame_count; ++i) { - v2s32 dst_pos(0, frame_size.Height * i); - blit(crack_scaled, dst, dst_pos, frame_size); - } - - crack_scaled->drop(); -} - -void brighten(video::IImage *image) -{ - if (image == NULL) - return; - - core::dimension2d dim = image->getDimension(); - - for (u32 y=0; ygetPixel(x,y); - c.setRed(0.5 * 255 + 0.5 * (float)c.getRed()); - c.setGreen(0.5 * 255 + 0.5 * (float)c.getGreen()); - c.setBlue(0.5 * 255 + 0.5 * (float)c.getBlue()); - image->setPixel(x,y,c); - } -} - -u32 parseImageTransform(std::string_view s) -{ - int total_transform = 0; - - std::string transform_names[8]; - transform_names[0] = "i"; - transform_names[1] = "r90"; - transform_names[2] = "r180"; - transform_names[3] = "r270"; - transform_names[4] = "fx"; - transform_names[6] = "fy"; - - std::size_t pos = 0; - while(pos < s.size()) - { - int transform = -1; - for (int i = 0; i <= 7; ++i) - { - const std::string &name_i = transform_names[i]; - - if (s[pos] == ('0' + i)) - { - transform = i; - pos++; - break; - } - - if (!(name_i.empty()) && lowercase(s.substr(pos, name_i.size())) == name_i) { - transform = i; - pos += name_i.size(); - break; - } - } - if (transform < 0) - break; - - // Multiply total_transform and transform in the group D4 - int new_total = 0; - if (transform < 4) - new_total = (transform + total_transform) % 4; - else - new_total = (transform - total_transform + 8) % 4; - if ((transform >= 4) ^ (total_transform >= 4)) - new_total += 4; - - total_transform = new_total; - } - return total_transform; -} - -core::dimension2d imageTransformDimension(u32 transform, core::dimension2d dim) -{ - if (transform % 2 == 0) - return dim; - - return core::dimension2d(dim.Height, dim.Width); -} - -void imageTransform(u32 transform, video::IImage *src, video::IImage *dst) -{ - if (src == NULL || dst == NULL) - return; - - core::dimension2d dstdim = dst->getDimension(); - - // Pre-conditions - assert(dstdim == imageTransformDimension(transform, src->getDimension())); - assert(transform <= 7); - - /* - Compute the transformation from source coordinates (sx,sy) - to destination coordinates (dx,dy). - */ - int sxn = 0; - int syn = 2; - if (transform == 0) // identity - sxn = 0, syn = 2; // sx = dx, sy = dy - else if (transform == 1) // rotate by 90 degrees ccw - sxn = 3, syn = 0; // sx = (H-1) - dy, sy = dx - else if (transform == 2) // rotate by 180 degrees - sxn = 1, syn = 3; // sx = (W-1) - dx, sy = (H-1) - dy - else if (transform == 3) // rotate by 270 degrees ccw - sxn = 2, syn = 1; // sx = dy, sy = (W-1) - dx - else if (transform == 4) // flip x - sxn = 1, syn = 2; // sx = (W-1) - dx, sy = dy - else if (transform == 5) // flip x then rotate by 90 degrees ccw - sxn = 2, syn = 0; // sx = dy, sy = dx - else if (transform == 6) // flip y - sxn = 0, syn = 3; // sx = dx, sy = (H-1) - dy - else if (transform == 7) // flip y then rotate by 90 degrees ccw - sxn = 3, syn = 1; // sx = (H-1) - dy, sy = (W-1) - dx - - for (u32 dy=0; dygetPixel(sx,sy); - dst->setPixel(dx,dy,c); - } -} - video::ITexture* TextureSource::getNormalTexture(const std::string &name) { if (isKnownSourceImage("override_normal.png")) @@ -2455,48 +572,6 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name) return NULL; } -namespace { - // For more colorspace transformations, see for example - // https://github.com/tobspr/GLSL-Color-Spaces/blob/master/ColorSpaces.inc.glsl - - inline float linear_to_srgb_component(float v) - { - if (v > 0.0031308f) - return 1.055f * powf(v, 1.0f / 2.4f) - 0.055f; - return 12.92f * v; - } - inline float srgb_to_linear_component(float v) - { - if (v > 0.04045f) - return powf((v + 0.055f) / 1.055f, 2.4f); - return v / 12.92f; - } - - v3f srgb_to_linear(const video::SColor col_srgb) - { - v3f col(col_srgb.getRed(), col_srgb.getGreen(), col_srgb.getBlue()); - col /= 255.0f; - col.X = srgb_to_linear_component(col.X); - col.Y = srgb_to_linear_component(col.Y); - col.Z = srgb_to_linear_component(col.Z); - return col; - } - - video::SColor linear_to_srgb(const v3f col_linear) - { - v3f col; - col.X = linear_to_srgb_component(col_linear.X); - col.Y = linear_to_srgb_component(col_linear.Y); - col.Z = linear_to_srgb_component(col_linear.Z); - col *= 255.0f; - col.X = core::clamp(col.X, 0.0f, 255.0f); - col.Y = core::clamp(col.Y, 0.0f, 255.0f); - col.Z = core::clamp(col.Z, 0.0f, 255.0f); - return video::SColor(0xff, myround(col.X), myround(col.Y), - myround(col.Z)); - } -} - video::SColor TextureSource::getTextureAverageColor(const std::string &name) { video::IVideoDriver *driver = RenderingEngine::get_video_driver(); @@ -2510,27 +585,9 @@ video::SColor TextureSource::getTextureAverageColor(const std::string &name) if (!image) return c; - u32 total = 0; - v3f col_acc(0, 0, 0); - core::dimension2d dim = image->getDimension(); - u16 step = 1; - if (dim.Width > 16) - step = dim.Width / 16; - for (u16 x = 0; x < dim.Width; x += step) { - for (u16 y = 0; y < dim.Width; y += step) { - c = image->getPixel(x,y); - if (c.getAlpha() > 0) { - total++; - col_acc += srgb_to_linear(c); - } - } - } + c = ImageSource::getImageAverageColor(*image); image->drop(); - if (total > 0) { - col_acc /= total; - c = linear_to_srgb(col_acc); - } - c.setAlpha(255); + return c; } From 673d2499e8643474576ae7937bebd6391d0ac63a Mon Sep 17 00:00:00 2001 From: cx384 Date: Sun, 17 Mar 2024 15:04:40 +0100 Subject: [PATCH 75/91] Refactor texturepaths.cpp and SourceImageCache --- src/client/imagesource.cpp | 15 ++-- src/client/imagesource.h | 24 ++--- src/client/texturesource.cpp | 169 +++++++++++++---------------------- 3 files changed, 80 insertions(+), 128 deletions(-) diff --git a/src/client/imagesource.cpp b/src/client/imagesource.cpp index 92da3ee27..d401e98ed 100644 --- a/src/client/imagesource.cpp +++ b/src/client/imagesource.cpp @@ -75,13 +75,14 @@ void SourceImageCache::insert(const std::string &name, video::IImage *img, bool toadd->grab(); m_images[name] = toadd; } + video::IImage* SourceImageCache::get(const std::string &name) { std::map::iterator n; n = m_images.find(name); if (n != m_images.end()) return n->second; - return NULL; + return nullptr; } // Primarily fetches from cache, secondarily tries to read from filesystem @@ -96,12 +97,12 @@ video::IImage* SourceImageCache::getOrLoad(const std::string &name) video::IVideoDriver *driver = RenderingEngine::get_video_driver(); std::string path = getTexturePath(name); if (path.empty()) { - infostream<<"SourceImageCache::getOrLoad(): No path found for \"" - <createImageFromFile(path.c_str()); if (img){ @@ -1970,6 +1971,6 @@ video::SColor ImageSource::getImageAverageColor(const video::IImage &image) return c; } -void ImageSource::insertImage(const std::string &name, video::IImage *img, bool prefer_local) { +void ImageSource::insertSourceImage(const std::string &name, video::IImage *img, bool prefer_local) { m_sourcecache.insert(name, img, prefer_local); } diff --git a/src/client/imagesource.h b/src/client/imagesource.h index 15c982f8a..f3a30617a 100644 --- a/src/client/imagesource.h +++ b/src/client/imagesource.h @@ -23,10 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "settings.h" -// This file is only for internal generation/modification of images. -// Use texturesource.h instead to handle textures. +// This file is only used for internal generation of images. +// Use texturesource.h to handle textures. // A cache used for storing source images. +// (A "source image" is an unmodified image directly taken from the filesystem.) +// Does not contain modified images. class SourceImageCache { public: ~SourceImageCache(); @@ -35,16 +37,13 @@ public: video::IImage* get(const std::string &name); - // Primarily fetches from cache, secondarily tries to read from filesystem + // Primarily fetches from cache, secondarily tries to read from filesystem. video::IImage *getOrLoad(const std::string &name); private: std::map m_images; }; -/* - * Generates and caches images. - * The image name defines the image by filename and texture modifiers. -*/ +// Generates images using texture modifiers, and caches source images. struct ImageSource { /*! Generates an image from a full string like * "stone.png^mineral_coal.png^[crack:1:0". @@ -53,8 +52,8 @@ struct ImageSource { */ video::IImage* generateImage(std::string_view name, std::set &source_image_names); - // To add self made images. - void insertImage(const std::string &name, video::IImage *img, bool prefer_local); + // Insert a source image into the cache without touching the filesystem. + void insertSourceImage(const std::string &name, video::IImage *img, bool prefer_local); // TODO should probably be moved elsewhere static video::SColor getImageAverageColor(const video::IImage &image); @@ -69,9 +68,10 @@ struct ImageSource { private: // Generate image based on a string like "stone.png" or "[crack:1:0". - // if baseimg is NULL, it is created. Otherwise stuff is made on it. - // source_image_names is important to determine when to flush the image from a cache (dynamic media) - bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg, std::set &source_image_names); + // If baseimg is NULL, it is created. Otherwise stuff is made on it. + // source_image_names is important to determine when to flush the image from a cache (dynamic media). + bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg, + std::set &source_image_names); // Cached settings needed for making textures from meshes bool m_setting_mipmap; diff --git a/src/client/texturesource.cpp b/src/client/texturesource.cpp index 7e56a57cd..12a21771a 100644 --- a/src/client/texturesource.cpp +++ b/src/client/texturesource.cpp @@ -27,41 +27,18 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "texturepaths.h" #include "imagesource.h" -/* - Stores internal information about a texture. -*/ +// Stores internal information about a texture. struct TextureInfo { std::string name; - video::ITexture *texture; - std::set sourceImages; + video::ITexture *texture = nullptr; - TextureInfo( - const std::string &name_, - video::ITexture *texture_=NULL - ): - name(name_), - texture(texture_) - { - } - - TextureInfo( - const std::string &name_, - video::ITexture *texture_, - std::set &&sourceImages_ - ): - name(name_), - texture(texture_), - sourceImages(std::move(sourceImages_)) - { - } + // Stores source image names which ImageSource::generateImage used. + std::set sourceImages{}; }; -/* - TextureSource -*/ - +// TextureSource class TextureSource : public IWritableTextureSource { public: @@ -150,7 +127,7 @@ public: // Shall be called from the main thread. void processQueue(); - // Insert an image into the cache without touching the filesystem. + // Insert a source image into the cache without touching the filesystem. // Shall be called from the main thread. void insertSourceImage(const std::string &name, video::IImage *img); @@ -200,11 +177,8 @@ private: // Maps image file names to loaded palettes. std::unordered_map m_palettes; - // Cached settings needed for making textures from meshes - bool m_setting_mipmap; - bool m_setting_trilinear_filter; - bool m_setting_bilinear_filter; - bool m_setting_anisotropic_filter; + // Cached from settings for making textures from meshes + bool mesh_filter_needed; }; IWritableTextureSource *createTextureSource() @@ -217,16 +191,17 @@ TextureSource::TextureSource() m_main_thread = std::this_thread::get_id(); // Add a NULL TextureInfo as the first index, named "" - m_textureinfo_cache.emplace_back(""); + m_textureinfo_cache.emplace_back(TextureInfo{""}); m_name_to_id[""] = 0; // Cache some settings // Note: Since this is only done once, the game must be restarted - // for these settings to take effect - m_setting_mipmap = g_settings->getBool("mip_map"); - m_setting_trilinear_filter = g_settings->getBool("trilinear_filter"); - m_setting_bilinear_filter = g_settings->getBool("bilinear_filter"); - m_setting_anisotropic_filter = g_settings->getBool("anisotropic_filter"); + // for these settings to take effect. + mesh_filter_needed = + g_settings->getBool("mip_map") || + g_settings->getBool("trilinear_filter") || + g_settings->getBool("bilinear_filter") || + g_settings->getBool("anisotropic_filter"); } TextureSource::~TextureSource() @@ -236,45 +211,37 @@ TextureSource::~TextureSource() unsigned int textures_before = driver->getTextureCount(); for (const auto &iter : m_textureinfo_cache) { - //cleanup texture + // cleanup texture if (iter.texture) driver->removeTexture(iter.texture); } m_textureinfo_cache.clear(); for (auto t : m_texture_trash) { - //cleanup trashed texture + // cleanup trashed texture driver->removeTexture(t); } - infostream << "~TextureSource() before cleanup: "<< textures_before + infostream << "~TextureSource() before cleanup: " << textures_before << " after: " << driver->getTextureCount() << std::endl; } u32 TextureSource::getTextureId(const std::string &name) { - { - /* - See if texture already exists - */ + { // See if texture already exists MutexAutoLock lock(m_textureinfo_cache_mutex); - std::map::iterator n; - n = m_name_to_id.find(name); + auto n = m_name_to_id.find(name); if (n != m_name_to_id.end()) - { return n->second; - } } - /* - Get texture - */ + // Get texture if (std::this_thread::get_id() == m_main_thread) { return generateTexture(name); } - infostream<<"getTextureId(): Queued: name=\""< result_queue; @@ -302,34 +269,26 @@ u32 TextureSource::getTextureId(const std::string &name) return 0; } -/* - This method generates all the textures -*/ +// This method generates all the textures u32 TextureSource::generateTexture(const std::string &name) { // Empty name means texture 0 if (name.empty()) { - infostream<<"generateTexture(): name is empty"<second; - } } - /* - Calling only allowed from main thread - */ + // Calling only allowed from main thread if (std::this_thread::get_id() != m_main_thread) { - errorstream<<"TextureSource::generateTexture() " - "called not from main thread"< source_image_names; video::IImage *img = m_imagesource.generateImage(name, source_image_names); - video::ITexture *tex = NULL; + video::ITexture *tex = nullptr; - if (img != NULL) { + if (img) { img = Align2Npot2(img, driver); // Create texture from resulting image tex = driver->addTexture(name.c_str(), img); @@ -350,14 +309,12 @@ u32 TextureSource::generateTexture(const std::string &name) img->drop(); } - /* - Add texture to caches (add NULL textures too) - */ + // Add texture to caches (add NULL textures too) MutexAutoLock lock(m_textureinfo_cache_mutex); u32 id = m_textureinfo_cache.size(); - TextureInfo ti(name, tex, std::move(source_image_names)); + TextureInfo ti{name, tex, std::move(source_image_names)}; m_textureinfo_cache.emplace_back(std::move(ti)); m_name_to_id[name] = id; @@ -368,11 +325,10 @@ std::string TextureSource::getTextureName(u32 id) { MutexAutoLock lock(m_textureinfo_cache_mutex); - if (id >= m_textureinfo_cache.size()) - { - errorstream<<"TextureSource::getTextureName(): id="<= m_textureinfo_cache.size()=" - <= m_textureinfo_cache.size()) { + errorstream << "TextureSource::getTextureName(): id=" << id + << " >= m_textureinfo_cache.size()=" << m_textureinfo_cache.size() + << std::endl; return ""; } @@ -384,7 +340,7 @@ video::ITexture* TextureSource::getTexture(u32 id) MutexAutoLock lock(m_textureinfo_cache_mutex); if (id >= m_textureinfo_cache.size()) - return NULL; + return nullptr; return m_textureinfo_cache[id].texture; } @@ -392,19 +348,16 @@ video::ITexture* TextureSource::getTexture(u32 id) video::ITexture* TextureSource::getTexture(const std::string &name, u32 *id) { u32 actual_id = getTextureId(name); - if (id){ + if (id) *id = actual_id; - } + return getTexture(actual_id); } video::ITexture* TextureSource::getTextureForMesh(const std::string &name, u32 *id) { // Avoid duplicating texture if it won't actually change - const bool filter_needed = - m_setting_mipmap || m_setting_trilinear_filter || - m_setting_bilinear_filter || m_setting_anisotropic_filter; - if (filter_needed && !name.empty()) + if (mesh_filter_needed && !name.empty()) return getTexture(name + "^[applyfiltersformesh", id); return getTexture(name, id); } @@ -415,7 +368,7 @@ Palette* TextureSource::getPalette(const std::string &name) sanity_check(std::this_thread::get_id() == m_main_thread); if (name.empty()) - return NULL; + return nullptr; auto it = m_palettes.find(name); if (it == m_palettes.end()) { @@ -425,7 +378,7 @@ Palette* TextureSource::getPalette(const std::string &name) if (!img) { warningstream << "TextureSource::getPalette(): palette \"" << name << "\" could not be loaded." << std::endl; - return NULL; + return nullptr; } Palette new_palette; u32 w = img->getDimension().Width; @@ -433,7 +386,7 @@ Palette* TextureSource::getPalette(const std::string &name) // Real area of the image u32 area = h * w; if (area == 0) - return NULL; + return nullptr; if (area > 256) { warningstream << "TextureSource::getPalette(): the specified" << " palette image \"" << name << "\" is larger than 256" @@ -462,17 +415,14 @@ Palette* TextureSource::getPalette(const std::string &name) } if (it != m_palettes.end()) return &((*it).second); - return NULL; + return nullptr; } void TextureSource::processQueue() { - /* - Fetch textures - */ + // Fetch textures // NOTE: process outstanding requests from all mesh generation threads - while (!m_get_texture_queue.empty()) - { + while (!m_get_texture_queue.empty()) { GetRequest request = m_get_texture_queue.pop(); @@ -484,7 +434,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im { sanity_check(std::this_thread::get_id() == m_main_thread); - m_imagesource.insertImage(name, img, true); + m_imagesource.insertSourceImage(name, img, true); m_source_image_existence.set(name, true); // now we need to check for any textures that need updating @@ -505,7 +455,8 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im } } if (affected > 0) - verbosestream << "TextureSource: inserting \"" << name << "\" caused rebuild of " << affected << " textures." << std::endl; + verbosestream << "TextureSource: inserting \"" << name << "\" caused rebuild of " + << affected << " textures." << std::endl; } void TextureSource::rebuildImagesAndTextures() @@ -516,7 +467,7 @@ void TextureSource::rebuildImagesAndTextures() sanity_check(driver); infostream << "TextureSource: recreating " << m_textureinfo_cache.size() - << " textures" << std::endl; + << " textures" << std::endl; // Recreate textures for (TextureInfo &ti : m_textureinfo_cache) { @@ -529,14 +480,15 @@ void TextureSource::rebuildImagesAndTextures() void TextureSource::rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti) { assert(!ti.name.empty()); + sanity_check(std::this_thread::get_id() == m_main_thread); - // replaces the previous sourceImages - // shouldn't really need to be done, but can't hurt + // Replaces the previous sourceImages. + // Shouldn't really need to be done, but can't hurt. std::set source_image_names; video::IImage *img = m_imagesource.generateImage(ti.name, source_image_names); img = Align2Npot2(img, driver); // Create texture from resulting image - video::ITexture *t = NULL; + video::ITexture *t = nullptr; if (img) { t = driver->addTexture(ti.name.c_str(), img); guiScalingCache(io::path(ti.name.c_str()), driver, img); @@ -569,23 +521,22 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name) } return getTexture(fname_base); } - return NULL; + return nullptr; } video::SColor TextureSource::getTextureAverageColor(const std::string &name) { video::IVideoDriver *driver = RenderingEngine::get_video_driver(); - video::SColor c(0, 0, 0, 0); video::ITexture *texture = getTexture(name); if (!texture) - return c; + return {0, 0, 0, 0}; video::IImage *image = driver->createImage(texture, core::position2d(0, 0), texture->getOriginalSize()); if (!image) - return c; + return {0, 0, 0, 0}; - c = ImageSource::getImageAverageColor(*image); + video::SColor c = ImageSource::getImageAverageColor(*image); image->drop(); return c; @@ -604,7 +555,7 @@ video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present) video::IVideoDriver *driver = RenderingEngine::get_video_driver(); video::IImage *flags_image = driver->createImage( video::ECF_A8R8G8B8, core::dimension2d(1, 1)); - sanity_check(flags_image != NULL); + sanity_check(flags_image); video::SColor c(255, normalmap_present ? 255 : 0, 0, 0); flags_image->setPixel(0, 0, c); insertSourceImage(tname, flags_image); From d1a1aed23ec28f1f3ac28c49cdbd833440d099ab Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 16 Mar 2024 15:07:18 +0100 Subject: [PATCH 76/91] Reduce unnecessary include in serialize.h --- src/content_nodemeta.cpp | 1 + src/nodemetadata.cpp | 1 + src/object_properties.cpp | 1 + src/script/common/c_converter.cpp | 1 + src/serialization.cpp | 2 +- src/util/serialize.h | 2 +- 6 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 39743c11f..f3ffc4bef 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodetimer.h" #include "inventory.h" #include "log.h" +#include "debug.h" #include "serialization.h" #include "util/serialize.h" #include "util/string.h" diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index 43770fee1..a11503ebe 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventory.h" #include "irrlicht_changes/printing.h" #include "log.h" +#include "debug.h" #include "util/serialize.h" #include "constants.h" // MAP_BLOCKSIZE #include diff --git a/src/object_properties.cpp b/src/object_properties.cpp index df3d245f9..5fb6a7d41 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlicht_changes/printing.h" #include "irrlichttypes_bloated.h" #include "exceptions.h" +#include "log.h" #include "util/serialize.h" #include diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index a7b18365a..446f88f3d 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -25,6 +25,7 @@ extern "C" { #include "util/numeric.h" #include "util/serialize.h" #include "util/string.h" +#include "log.h" #include "common/c_converter.h" #include "common/c_internal.h" #include "constants.h" diff --git a/src/serialization.cpp b/src/serialization.cpp index 689e4d986..4134126ca 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "serialization.h" - +#include "log.h" #include "util/serialize.h" #include diff --git a/src/util/serialize.h b/src/util/serialize.h index 00250ece5..d7526a765 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_bloated.h" #include "exceptions.h" // for SerializationError -#include "debug.h" // for assert #include "ieee_float.h" #include "config.h" @@ -39,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #endif #include // for memcpy +#include #include #include #include From 008d6be9005cf05a575a588503ea791d02c31c8e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 16 Mar 2024 15:10:11 +0100 Subject: [PATCH 77/91] Rework iconv encoding detection WCHAR_T doesn't seem as portable as we thought, so it's just easier to detect the right encoding using macros at this point. --- src/util/serialize.h | 37 ++++++++++++++++++++++++------------- src/util/string.cpp | 30 +++++++++++------------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/util/serialize.h b/src/util/serialize.h index d7526a765..5065de61d 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -24,25 +24,36 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "ieee_float.h" #include "config.h" -#if HAVE_ENDIAN_H - #ifdef _WIN32 - #define __BYTE_ORDER 0 - #define __LITTLE_ENDIAN 0 - #define __BIG_ENDIAN 1 - #elif defined(__MACH__) && defined(__APPLE__) - #include - #elif defined(__FreeBSD__) || defined(__DragonFly__) - #include - #else - #include - #endif -#endif #include // for memcpy #include #include #include #include +/* make sure BYTE_ORDER macros are available */ +#ifdef _WIN32 + #define BYTE_ORDER 1234 +#elif defined(__MACH__) && defined(__APPLE__) + #include +#elif defined(__FreeBSD__) || defined(__DragonFly__) + #include +#elif HAVE_ENDIAN_H + #include +#else + #error "Can't detect endian (missing header)" +#endif +#ifndef LITTLE_ENDIAN + #define LITTLE_ENDIAN 1234 +#endif +#ifndef BIG_ENDIAN + #define BIG_ENDIAN 4321 +#endif +#if !defined(BYTE_ORDER) && defined(_BYTE_ORDER) + #define BYTE_ORDER _BYTE_ORDER +#elif !defined(BYTE_ORDER) && defined(__BYTE_ORDER) + #define BYTE_ORDER __BYTE_ORDER +#endif + #define FIXEDPOINT_FACTOR 1000.0f // 0x7FFFFFFF / 1000.0f is not serializable. diff --git a/src/util/string.cpp b/src/util/string.cpp index 6c2ae7ca7..eb65373a4 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "string.h" -#include "pointer.h" +#include "serialize.h" // BYTE_ORDER #include "numeric.h" #include "log.h" @@ -67,20 +67,16 @@ static bool convert(const char *to, const char *from, char *outbuf, return true; } -#ifdef __ANDROID__ -// On Android iconv disagrees how big a wchar_t is for whatever reason -const char *DEFAULT_ENCODING = "UTF-32LE"; -#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) - // NetBSD does not allow "WCHAR_T" as a charset input to iconv. - #include - #if BYTE_ORDER == BIG_ENDIAN - const char *DEFAULT_ENCODING = "UTF-32BE"; - #else - const char *DEFAULT_ENCODING = "UTF-32LE"; - #endif -#else -const char *DEFAULT_ENCODING = "WCHAR_T"; -#endif +// select right encoding for wchar_t size +constexpr auto DEFAULT_ENCODING = ([] () -> const char* { + constexpr auto sz = sizeof(wchar_t); + static_assert(sz == 2 || sz == 4, "Unexpected wide char size"); + if constexpr (sz == 2) { + return (BYTE_ORDER == BIG_ENDIAN) ? "UTF-16BE" : "UTF-16LE"; + } else { + return (BYTE_ORDER == BIG_ENDIAN) ? "UTF-32BE" : "UTF-32LE"; + } +})(); std::wstring utf8_to_wide(std::string_view input) { @@ -93,10 +89,6 @@ std::wstring utf8_to_wide(std::string_view input) std::wstring out; out.resize(outbuf_size / sizeof(wchar_t)); -#if defined(__ANDROID__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) - static_assert(sizeof(wchar_t) == 4, "Unexpected wide char size"); -#endif - char *outbuf = reinterpret_cast(&out[0]); if (!convert(DEFAULT_ENCODING, "UTF-8", outbuf, &outbuf_size, inbuf, inbuf_size)) { infostream << "Couldn't convert UTF-8 string 0x" << hex_encode(input) From 5df60d85f71215b091430a32c7834dd9c90bf79a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 24 Mar 2024 19:53:54 +0100 Subject: [PATCH 78/91] Cache iconv context per-thread --- src/unittest/test_utilities.cpp | 7 +++++ src/util/string.cpp | 49 ++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp index 5c653a529..16032d130 100644 --- a/src/unittest/test_utilities.cpp +++ b/src/unittest/test_utilities.cpp @@ -318,6 +318,7 @@ void TestUtilities::testUTF8() UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide("")), ""); UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide("the shovel dug a crumbly node!")), "the shovel dug a crumbly node!"); + UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide(u8"-ä-")), u8"-ä-"); UASSERTEQ(std::string, wide_to_utf8(utf8_to_wide(u8"-\U0002000b-")), @@ -326,6 +327,12 @@ void TestUtilities::testUTF8() const auto *literal = U"-\U0002000b-"; UASSERT(utf8_to_wide(u8"-\U0002000b-") == reinterpret_cast(literal)); } + + // try to check that the conversion function does not accidentally keep + // its internal state across invocations. + // \xC4\x81 is UTF-8 for \u0101 + utf8_to_wide("\xC4"); + UASSERT(utf8_to_wide("\x81") != L"\u0101"); } void TestUtilities::testRemoveEscapes() diff --git a/src/util/string.cpp b/src/util/string.cpp index eb65373a4..0c896e6ec 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -41,28 +41,49 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef _WIN32 -static bool convert(const char *to, const char *from, char *outbuf, - size_t *outbuf_size, char *inbuf, size_t inbuf_size) +namespace { + class IconvSmartPointer { + iconv_t m_cd; + static const iconv_t null_value; + public: + IconvSmartPointer() : m_cd(null_value) {} + ~IconvSmartPointer() { reset(); } + + DISABLE_CLASS_COPY(IconvSmartPointer) + ALLOW_CLASS_MOVE(IconvSmartPointer) + + iconv_t get() const { return m_cd; } + operator bool() const { return m_cd != null_value; } + void reset(iconv_t cd = null_value) { + if (m_cd != null_value) + iconv_close(m_cd); + m_cd = cd; + } + }; + + // note that this can't be constexpr if iconv_t is a pointer + const iconv_t IconvSmartPointer::null_value = (iconv_t) -1; +} + +static bool convert(iconv_t cd, char *outbuf, size_t *outbuf_size, + char *inbuf, size_t inbuf_size) { - iconv_t cd = iconv_open(to, from); + // reset conversion state + iconv(cd, nullptr, nullptr, nullptr, nullptr); char *inbuf_ptr = inbuf; char *outbuf_ptr = outbuf; - size_t *inbuf_left_ptr = &inbuf_size; - const size_t old_outbuf_size = *outbuf_size; size_t old_size = inbuf_size; while (inbuf_size > 0) { - iconv(cd, &inbuf_ptr, inbuf_left_ptr, &outbuf_ptr, outbuf_size); + iconv(cd, &inbuf_ptr, &inbuf_size, &outbuf_ptr, outbuf_size); if (inbuf_size == old_size) { - iconv_close(cd); return false; } old_size = inbuf_size; } - iconv_close(cd); *outbuf_size = old_outbuf_size - *outbuf_size; return true; } @@ -80,6 +101,10 @@ constexpr auto DEFAULT_ENCODING = ([] () -> const char* { std::wstring utf8_to_wide(std::string_view input) { + thread_local IconvSmartPointer cd; + if (!cd) + cd.reset(iconv_open(DEFAULT_ENCODING, "UTF-8")); + const size_t inbuf_size = input.length(); // maximum possible size, every character is sizeof(wchar_t) bytes size_t outbuf_size = input.length() * sizeof(wchar_t); @@ -90,7 +115,7 @@ std::wstring utf8_to_wide(std::string_view input) out.resize(outbuf_size / sizeof(wchar_t)); char *outbuf = reinterpret_cast(&out[0]); - if (!convert(DEFAULT_ENCODING, "UTF-8", outbuf, &outbuf_size, inbuf, inbuf_size)) { + if (!convert(cd.get(), outbuf, &outbuf_size, inbuf, inbuf_size)) { infostream << "Couldn't convert UTF-8 string 0x" << hex_encode(input) << " into wstring" << std::endl; delete[] inbuf; @@ -104,6 +129,10 @@ std::wstring utf8_to_wide(std::string_view input) std::string wide_to_utf8(std::wstring_view input) { + thread_local IconvSmartPointer cd; + if (!cd) + cd.reset(iconv_open("UTF-8", DEFAULT_ENCODING)); + const size_t inbuf_size = input.length() * sizeof(wchar_t); // maximum possible size: utf-8 encodes codepoints using 1 up to 4 bytes size_t outbuf_size = input.length() * 4; @@ -113,7 +142,7 @@ std::string wide_to_utf8(std::wstring_view input) std::string out; out.resize(outbuf_size); - if (!convert("UTF-8", DEFAULT_ENCODING, &out[0], &outbuf_size, inbuf, inbuf_size)) { + if (!convert(cd.get(), &out[0], &outbuf_size, inbuf, inbuf_size)) { infostream << "Couldn't convert wstring 0x" << hex_encode(inbuf, inbuf_size) << " into UTF-8 string" << std::endl; delete[] inbuf; From 97066bf79524cc0ecf61f45023dc2b32acaecad9 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 23 Mar 2024 17:16:21 +0100 Subject: [PATCH 79/91] Sanity-check reliable packet size at earlier point --- src/network/connection.cpp | 39 ++++++++++++++++++------------- src/network/connectionthreads.cpp | 2 +- src/network/connectionthreads.h | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/network/connection.cpp b/src/network/connection.cpp index d16d59f59..84a6c53c5 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -103,12 +103,10 @@ void makeSplitPacket(const SharedBuffer &data, u32 chunksize_max, u16 seqnum std::list> *chunks) { // Chunk packets, containing the TYPE_SPLIT header - u32 chunk_header_size = 7; - u32 maximum_data_size = chunksize_max - chunk_header_size; - u32 start = 0; - u32 end = 0; - u32 chunk_num = 0; - u16 chunk_count = 0; + const u32 chunk_header_size = 7; + const u32 maximum_data_size = chunksize_max - chunk_header_size; + u32 start = 0, end = 0; + u16 chunk_num = 0; do { end = start + maximum_data_size - 1; if (end > data.getSize() - 1) @@ -126,16 +124,16 @@ void makeSplitPacket(const SharedBuffer &data, u32 chunksize_max, u16 seqnum memcpy(&chunk[chunk_header_size], &data[start], payload_size); chunks->push_back(chunk); - chunk_count++; start = end + 1; + sanity_check(chunk_num < 0xFFFF); // overflow chunk_num++; } while (end != data.getSize() - 1); - for (SharedBuffer &chunk : *chunks) { + for (auto &chunk : *chunks) { // Write chunk_count - writeU16(&(chunk[3]), chunk_count); + writeU16(&chunk[3], chunk_num); } } @@ -1061,22 +1059,22 @@ bool UDPPeer::processReliableSendCommand( const auto &c = *c_ptr; Channel &chan = channels[c.channelnum]; - u32 chunksize_max = max_packet_size + const u32 chunksize_max = max_packet_size - BASE_HEADER_SIZE - RELIABLE_HEADER_SIZE; - sanity_check(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); - std::list> originals; - u16 split_sequence_number = chan.readNextSplitSeqNum(); if (c.raw) { originals.emplace_back(c.data); } else { - makeAutoSplitPacket(c.data, chunksize_max,split_sequence_number, &originals); - chan.setNextSplitSeqNum(split_sequence_number); + u16 split_seqnum = chan.readNextSplitSeqNum(); + makeAutoSplitPacket(c.data, chunksize_max, split_seqnum, &originals); + chan.setNextSplitSeqNum(split_seqnum); } + sanity_check(originals.size() < MAX_RELIABLE_WINDOW_SIZE); + bool have_sequence_number = false; bool have_initial_sequence_number = false; std::queue toadd; @@ -1271,7 +1269,7 @@ Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout, m_udpSocket(ipv6), m_protocol_id(protocol_id), m_sendThread(new ConnectionSendThread(max_packet_size, timeout)), - m_receiveThread(new ConnectionReceiveThread(max_packet_size)), + m_receiveThread(new ConnectionReceiveThread()), m_bc_peerhandler(peerhandler) { @@ -1505,6 +1503,15 @@ void Connection::Send(session_t peer_id, u8 channelnum, { assert(channelnum < CHANNEL_COUNT); // Pre-condition + // approximate check similar to UDPPeer::processReliableSendCommand() + // to get nicer errors / backtraces if this happens. + if (reliable && pkt->getSize() > MAX_RELIABLE_WINDOW_SIZE*512) { + std::ostringstream oss; + oss << "Packet too big for window, peer_id=" << peer_id + << " command=" << pkt->getCommand() << " size=" << pkt->getSize(); + FATAL_ERROR(oss.str().c_str()); + } + putCommand(ConnectionCommand::send(peer_id, channelnum, pkt, reliable)); } diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index 3d217ec6c..d5c9a39ed 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -796,7 +796,7 @@ void ConnectionSendThread::sendAsPacket(session_t peer_id, u8 channelnum, m_outgoing_queue.push(packet); } -ConnectionReceiveThread::ConnectionReceiveThread(unsigned int max_packet_size) : +ConnectionReceiveThread::ConnectionReceiveThread() : Thread("ConnectionReceive") { } diff --git a/src/network/connectionthreads.h b/src/network/connectionthreads.h index ce96e4342..fff71f657 100644 --- a/src/network/connectionthreads.h +++ b/src/network/connectionthreads.h @@ -113,7 +113,7 @@ private: class ConnectionReceiveThread : public Thread { public: - ConnectionReceiveThread(unsigned int max_packet_size); + ConnectionReceiveThread(); void *run(); From 6e3246c5fd7aa78dc697f7a588e6a01b5f00db7c Mon Sep 17 00:00:00 2001 From: grorp Date: Sat, 30 Mar 2024 11:07:36 +0100 Subject: [PATCH 80/91] Limit crosshair scaling to integer multiples to avoid distortion (#14501) --- src/client/hud.cpp | 31 ++++++++++++++++++++++--------- src/client/hud.h | 1 + 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/client/hud.cpp b/src/client/hud.cpp index e1641366e..5a6f5d5c2 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -44,6 +44,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #define OBJECT_CROSSHAIR_LINE_SIZE 8 #define CROSSHAIR_LINE_SIZE 10 +static void setting_changed_callback(const std::string &name, void *data) +{ + static_cast(data)->readScalingSetting(); +} + Hud::Hud(Client *client, LocalPlayer *player, Inventory *inventory) { @@ -52,12 +57,8 @@ Hud::Hud(Client *client, LocalPlayer *player, this->player = player; this->inventory = inventory; - m_hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f); - m_scale_factor = m_hud_scaling * RenderingEngine::getDisplayDensity(); - m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE * - RenderingEngine::getDisplayDensity() + 0.5f); - m_hotbar_imagesize *= m_hud_scaling; - m_padding = m_hotbar_imagesize / 12; + readScalingSetting(); + g_settings->registerChangedCallback("hud_scaling", setting_changed_callback, this); for (auto &hbar_color : hbar_colors) hbar_color = video::SColor(255, 255, 255, 255); @@ -138,8 +139,20 @@ Hud::Hud(Client *client, LocalPlayer *player, m_rotation_mesh_buffer.setHardwareMappingHint(scene::EHM_STATIC); } +void Hud::readScalingSetting() +{ + m_hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f); + m_scale_factor = m_hud_scaling * RenderingEngine::getDisplayDensity(); + m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE * + RenderingEngine::getDisplayDensity() + 0.5f); + m_hotbar_imagesize *= m_hud_scaling; + m_padding = m_hotbar_imagesize / 12; +} + Hud::~Hud() { + g_settings->deregisterChangedCallback("hud_scaling", setting_changed_callback, this); + if (m_selection_mesh) m_selection_mesh->drop(); } @@ -786,9 +799,9 @@ void Hud::drawCrosshair() { auto draw_image_crosshair = [this] (video::ITexture *tex) { core::dimension2di orig_size(tex->getOriginalSize()); - core::dimension2di scaled_size( - core::round32(orig_size.Width * m_scale_factor), - core::round32(orig_size.Height * m_scale_factor)); + // Integer scaling to avoid artifacts, floor instead of round since too + // small looks better than too large in this case. + core::dimension2di scaled_size = orig_size * std::floor(m_scale_factor); core::rect src_rect(orig_size); core::position2d pos(m_displaycenter.X - scaled_size.Width / 2, diff --git a/src/client/hud.h b/src/client/hud.h index 303feb783..746a1b33e 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -57,6 +57,7 @@ public: Hud(Client *client, LocalPlayer *player, Inventory *inventory); + void readScalingSetting(); ~Hud(); enum BlockBoundsMode toggleBlockBounds(); From e8a8525bcdae6b2109b9e4158f928a7c6f9c1404 Mon Sep 17 00:00:00 2001 From: Muhammad Rifqi Priyo Susanto Date: Sat, 30 Mar 2024 17:08:18 +0700 Subject: [PATCH 81/91] Fix path splitting in translation updater script --- util/mod_translation_updater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/mod_translation_updater.py b/util/mod_translation_updater.py index c941331a8..8c468c8d2 100755 --- a/util/mod_translation_updater.py +++ b/util/mod_translation_updater.py @@ -425,7 +425,7 @@ def generate_template(folder, mod_name): sources = sorted(list(sources), key=str.lower) newSources = [] for i in sources: - i = "/".join(os.path.split(i)).lstrip("/") + i = i.replace("\\", "/") newSources.append(f"{symbol_source_prefix} {i} {symbol_source_suffix}") dOut[d] = newSources From 517f1602aa77c93af5b06f6cd1f2c20075f9547b Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Sun, 24 Mar 2024 22:35:55 +0100 Subject: [PATCH 82/91] Re-add "long tap to punch" as a client-side setting --- builtin/settingtypes.txt | 13 +++++++++++++ doc/lua_api.md | 9 +++++---- src/client/game.cpp | 6 ++++-- src/defaultsettings.cpp | 1 + src/gui/touchscreengui.cpp | 4 ++-- src/itemdef.cpp | 31 ++++++++++++++++++++++--------- src/itemdef.h | 8 ++++++-- src/script/common/c_types.cpp | 1 + 8 files changed, 54 insertions(+), 19 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index b039780bc..b9c0cda80 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -185,6 +185,19 @@ fixed_virtual_joystick (Fixed virtual joystick) bool false # Requires: touchscreen_gui virtual_joystick_triggers_aux1 (Virtual joystick triggers Aux1 button) bool false +# The gesture for for punching players/entities. +# This can be overridden by games and mods. +# +# * short_tap +# Easy to use and well-known from other games that shall not be named. +# +# * long_tap +# Known from the classic Minetest mobile controls. +# Combat is more or less impossible. +# +# Requires: touchscreen_gui +touch_punch_gesture (Punch gesture) enum short_tap short_tap,long_tap + [Graphics and Audio] diff --git a/doc/lua_api.md b/doc/lua_api.md index 8a1df92ef..30b7e46bc 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9098,15 +9098,16 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and touch_interaction = { -- Only affects touchscreen clients. -- Defines the meaning of short and long taps with the item in hand. - -- The fields in this table have two valid values: + -- The fields in this table can be set to the following values: + -- * "user" (meaning depends on client-side settings) -- * "long_dig_short_place" (long tap = dig, short tap = place) -- * "short_dig_long_place" (short tap = dig, long tap = place) -- The field to be used is selected according to the current -- `pointed_thing`. - pointed_nothing = "long_dig_short_place", - pointed_node = "long_dig_short_place", - pointed_object = "short_dig_long_place", + pointed_nothing = "user", + pointed_node = "user", + pointed_object = "user", }, sound = { diff --git a/src/client/game.cpp b/src/client/game.cpp index 67529681b..3c3feaa72 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3280,8 +3280,10 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud) if (pointed != runData.pointed_old) infostream << "Pointing at " << pointed.dump() << std::endl; - if (g_touchscreengui) - g_touchscreengui->applyContextControls(selected_def.touch_interaction.getMode(pointed)); + if (g_touchscreengui) { + auto mode = selected_def.touch_interaction.getMode(pointed.type); + g_touchscreengui->applyContextControls(mode); + } // Note that updating the selection mesh every frame is not particularly efficient, // but the halo rendering code is already inefficient so there's no point in optimizing it here diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index bb50a00aa..11b42c779 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -490,6 +490,7 @@ void set_default_settings() settings->setDefault("touch_use_crosshair", "false"); settings->setDefault("fixed_virtual_joystick", "false"); settings->setDefault("virtual_joystick_triggers_aux1", "false"); + settings->setDefault("touch_punch_gesture", "short_tap"); #ifdef ENABLE_TOUCH settings->setDefault("clickable_chat_weblinks", "false"); #else diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 07fe90585..2d41d4fde 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -1105,11 +1105,11 @@ void TouchScreenGUI::applyContextControls(const TouchInteractionMode &mode) // Since the pointed thing has already been determined when this function // is called, we cannot use this function to update the shootline. + sanity_check(mode != TouchInteractionMode_USER); + u64 now = porting::getTimeMs(); bool target_dig_pressed = false; bool target_place_pressed = false; - u64 now = porting::getTimeMs(); - // If the meanings of short and long taps have been swapped, abort any ongoing // short taps because they would do something else than the player expected. // Long taps don't need this, they're adjusted to the swapped meanings instead. diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 5031487ea..ad2ed4847 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -40,24 +40,37 @@ with this program; if not, write to the Free Software Foundation, Inc., TouchInteraction::TouchInteraction() { - pointed_nothing = LONG_DIG_SHORT_PLACE; - pointed_node = LONG_DIG_SHORT_PLACE; - // Map punching to single tap by default. - pointed_object = SHORT_DIG_LONG_PLACE; + pointed_nothing = TouchInteractionMode_USER; + pointed_node = TouchInteractionMode_USER; + pointed_object = TouchInteractionMode_USER; } -TouchInteractionMode TouchInteraction::getMode(const PointedThing &pointed) const +TouchInteractionMode TouchInteraction::getMode(PointedThingType pointed_type) const { - switch (pointed.type) { + TouchInteractionMode result; + switch (pointed_type) { case POINTEDTHING_NOTHING: - return pointed_nothing; + result = pointed_nothing; + break; case POINTEDTHING_NODE: - return pointed_node; + result = pointed_node; + break; case POINTEDTHING_OBJECT: - return pointed_object; + result = pointed_object; + break; default: FATAL_ERROR("Invalid PointedThingType given to TouchInteraction::getMode"); } + + if (result == TouchInteractionMode_USER) { + if (pointed_type == POINTEDTHING_OBJECT) + result = g_settings->get("touch_punch_gesture") == "long_tap" ? + LONG_DIG_SHORT_PLACE : SHORT_DIG_LONG_PLACE; + else + result = LONG_DIG_SHORT_PLACE; + } + + return result; } void TouchInteraction::serialize(std::ostream &os) const diff --git a/src/itemdef.h b/src/itemdef.h index 884d31501..782dad816 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -30,10 +30,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "texture_override.h" // TextureOverride #include "tool.h" #include "util/pointabilities.h" +#include "util/pointedthing.h" + class IGameDef; class Client; struct ToolCapabilities; -struct PointedThing; #ifndef SERVER #include "client/texturesource.h" struct ItemMesh; @@ -57,6 +58,7 @@ enum TouchInteractionMode : u8 { LONG_DIG_SHORT_PLACE, SHORT_DIG_LONG_PLACE, + TouchInteractionMode_USER, // Meaning depends on client-side settings TouchInteractionMode_END, // Dummy for validity check }; @@ -67,7 +69,9 @@ struct TouchInteraction TouchInteractionMode pointed_object; TouchInteraction(); - TouchInteractionMode getMode(const PointedThing &pointed) const; + // Returns the right mode for the pointed thing and resolves any occurrence + // of TouchInteractionMode_USER into an actual mode. + TouchInteractionMode getMode(PointedThingType pointed_type) const; void serialize(std::ostream &os) const; void deSerialize(std::istream &is); }; diff --git a/src/script/common/c_types.cpp b/src/script/common/c_types.cpp index 7338834f7..be6ef65ae 100644 --- a/src/script/common/c_types.cpp +++ b/src/script/common/c_types.cpp @@ -37,5 +37,6 @@ struct EnumString es_TouchInteractionMode[] = { {LONG_DIG_SHORT_PLACE, "long_dig_short_place"}, {SHORT_DIG_LONG_PLACE, "short_dig_long_place"}, + {TouchInteractionMode_USER, "user"}, {0, NULL}, }; From 8935f2af3ca8b6720e98ecbe25b52c4a56db9bc4 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Sun, 24 Mar 2024 21:55:39 +0100 Subject: [PATCH 83/91] Make long tap delay customizable and change default to 400ms --- builtin/settingtypes.txt | 15 ++++++++++----- src/defaultsettings.cpp | 3 ++- src/gui/touchscreengui.cpp | 3 ++- src/gui/touchscreengui.h | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index b9c0cda80..8ffb1c3c1 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -157,16 +157,21 @@ invert_hotbar_mouse_wheel (Hotbar: Invert mouse wheel direction) bool false # Requires: !android enable_touch (Enable touchscreen) bool true -# The length in pixels it takes for touchscreen interaction to start. -# -# Requires: touchscreen_gui -touchscreen_threshold (Touchscreen threshold) int 20 0 100 - # Touchscreen sensitivity multiplier. # # Requires: touchscreen_gui touchscreen_sensitivity (Touchscreen sensitivity) float 0.2 0.001 10.0 +# The length in pixels after which a touch interaction is considered movement. +# +# Requires: touchscreen_gui +touchscreen_threshold (Movement threshold) int 20 0 100 + +# The delay in milliseconds after which a touch interaction is considered a long tap. +# +# Requires: touchscreen_gui +touch_long_tap_delay (Threshold for long taps) int 400 100 1000 + # Use crosshair to select object instead of whole screen. # If enabled, a crosshair will be shown and will be used for selecting object. # diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 11b42c779..0907c4c6d 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -485,8 +485,9 @@ void set_default_settings() settings->setDefault("keymap_sneak", "KEY_SHIFT"); #endif - settings->setDefault("touchscreen_threshold", "20"); settings->setDefault("touchscreen_sensitivity", "0.2"); + settings->setDefault("touchscreen_threshold", "20"); + settings->setDefault("touch_long_tap_delay", "400"); settings->setDefault("touch_use_crosshair", "false"); settings->setDefault("fixed_virtual_joystick", "false"); settings->setDefault("virtual_joystick_triggers_aux1", "false"); diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 2d41d4fde..007420b08 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -414,6 +414,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver) } m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold"); + m_long_tap_delay = g_settings->getU16("touch_long_tap_delay"); m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick"); m_joystick_triggers_aux1 = g_settings->getBool("virtual_joystick_triggers_aux1"); m_screensize = m_device->getVideoDriver()->getScreenSize(); @@ -999,7 +1000,7 @@ void TouchScreenGUI::step(float dtime) if (m_has_move_id && !m_move_has_really_moved && m_tap_state == TapState::None) { u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs()); - if (delta > MIN_DIG_TIME_MS) { + if (delta > m_long_tap_delay) { m_tap_state = TapState::LongTap; } } diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 1e9aa128d..2ee881b93 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -79,7 +79,6 @@ typedef enum AHBB_Dir_Right_Left } autohide_button_bar_dir; -#define MIN_DIG_TIME_MS 500 #define BUTTON_REPEAT_DELAY 0.2f #define SETTINGS_BAR_Y_OFFSET 5 #define RARE_CONTROLS_BAR_Y_OFFSET 5 @@ -225,6 +224,7 @@ private: v2u32 m_screensize; s32 button_size; double m_touchscreen_threshold; + u16 m_long_tap_delay; bool m_visible; // is the whole touch screen gui visible std::unordered_map> m_hotbar_rects; From e79587c934d2a0497ed8a4300a6e58e1d35e70d7 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Sun, 4 Feb 2024 19:13:29 +0100 Subject: [PATCH 84/91] Add shorthand form for touch_interaction --- doc/lua_api.md | 26 +++++++++++++------------- src/script/common/c_content.cpp | 15 +++++++++++---- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 30b7e46bc..329f17b01 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9095,20 +9095,20 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and -- Otherwise should be name of node which the client immediately places -- upon digging. Server will always update with actual result shortly. - touch_interaction = { - -- Only affects touchscreen clients. - -- Defines the meaning of short and long taps with the item in hand. - -- The fields in this table can be set to the following values: - -- * "user" (meaning depends on client-side settings) - -- * "long_dig_short_place" (long tap = dig, short tap = place) - -- * "short_dig_long_place" (short tap = dig, long tap = place) - -- The field to be used is selected according to the current - -- `pointed_thing`. - - pointed_nothing = "user", - pointed_node = "user", - pointed_object = "user", + touch_interaction = OR { + pointed_nothing = , + pointed_node = , + pointed_object = , }, + -- Only affects touchscreen clients. + -- Defines the meaning of short and long taps with the item in hand. + -- If specified as a table, the field to be used is selected according to + -- the current `pointed_thing`. + -- There are three possible TouchInteractionMode values: + -- * "user" (meaning depends on client-side settings) + -- * "long_dig_short_place" (long tap = dig, short tap = place) + -- * "short_dig_long_place" (short tap = dig, long tap = place) + -- The default value is "user". sound = { -- Definition of item sounds to be played at various events. diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 02f69b3e1..de4f2fe02 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -156,17 +156,24 @@ void read_item_definition(lua_State* L, int index, getboolfield(L, index, "wallmounted_rotate_vertical", def.wallmounted_rotate_vertical); + TouchInteraction &inter = def.touch_interaction; lua_getfield(L, index, "touch_interaction"); - if (!lua_isnil(L, -1)) { - luaL_checktype(L, -1, LUA_TTABLE); - - TouchInteraction &inter = def.touch_interaction; + if (lua_istable(L, -1)) { inter.pointed_nothing = (TouchInteractionMode)getenumfield(L, -1, "pointed_nothing", es_TouchInteractionMode, inter.pointed_nothing); inter.pointed_node = (TouchInteractionMode)getenumfield(L, -1, "pointed_node", es_TouchInteractionMode, inter.pointed_node); inter.pointed_object = (TouchInteractionMode)getenumfield(L, -1, "pointed_object", es_TouchInteractionMode, inter.pointed_object); + } else if (lua_isstring(L, -1)) { + int value; + if (string_to_enum(es_TouchInteractionMode, value, lua_tostring(L, -1))) { + inter.pointed_nothing = (TouchInteractionMode)value; + inter.pointed_node = (TouchInteractionMode)value; + inter.pointed_object = (TouchInteractionMode)value; + } + } else if (!lua_isnil(L, -1)) { + throw LuaError("invalid type for 'touch_interaction'"); } lua_pop(L, 1); } From 3a35db6e67f542e923e624c32e9d07c1bdbe919a Mon Sep 17 00:00:00 2001 From: cx384 Date: Fri, 22 Mar 2024 00:46:19 +0100 Subject: [PATCH 85/91] Turn dos files into unix files --- misc/winresource.rc | 132 +-- src/gui/guiButton.cpp | 1538 +++++++++++++++--------------- src/gui/guiButton.h | 560 +++++------ src/gui/guiSkin.cpp | 2074 ++++++++++++++++++++--------------------- src/gui/guiSkin.h | 720 +++++++------- 5 files changed, 2512 insertions(+), 2512 deletions(-) diff --git a/misc/winresource.rc b/misc/winresource.rc index ffb493873..d5a71797a 100644 --- a/misc/winresource.rc +++ b/misc/winresource.rc @@ -1,66 +1,66 @@ -#include -#include -#include -#include - -#ifndef USE_CMAKE_CONFIG_H -#define USE_CMAKE_CONFIG_H -#endif -#include "config.h" -#undef USE_CMAKE_CONFIG_H - -#if RUN_IN_PLACE - #define BUILDMODE "RUN_IN_PLACE=1" -#else - #define BUILDMODE "RUN_IN_PLACE=0" -#endif - -#ifdef __MINGW32__ -CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "minetest.exe.manifest" -#endif - -LANGUAGE 0, SUBLANG_NEUTRAL -130 ICON "minetest-icon.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -1 VERSIONINFO - FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0 - PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0 - FILEFLAGSMASK 0x3fL -#ifndef NDEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS VOS_NT_WINDOWS32 - FILETYPE VFT_APP - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Comments", "" - VALUE "CompanyName", PROJECT_NAME_C " community" - VALUE "FileDescription", PROJECT_NAME_C " engine" - VALUE "FileVersion", VERSION_STRING - VALUE "InternalName", PROJECT_NAME - VALUE "LegalCopyright", "(c) 2011-2015 celeron55" - VALUE "LegalTrademarks", """Minetest"" is the property of the Minetest community, don't use it without permission!" - VALUE "OriginalFilename", "minetest.exe" - VALUE "PrivateBuild", VERSION_EXTRA - VALUE "ProductName", PROJECT_NAME_C - VALUE "ProductVersion", PRODUCT_VERSION_STRING - VALUE "SpecialBuild", BUILDMODE - END -END -BLOCK "VarFileInfo" -BEGIN - VALUE "Translation", 0x409, 1200 -END -END - +#include +#include +#include +#include + +#ifndef USE_CMAKE_CONFIG_H +#define USE_CMAKE_CONFIG_H +#endif +#include "config.h" +#undef USE_CMAKE_CONFIG_H + +#if RUN_IN_PLACE + #define BUILDMODE "RUN_IN_PLACE=1" +#else + #define BUILDMODE "RUN_IN_PLACE=0" +#endif + +#ifdef __MINGW32__ +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "minetest.exe.manifest" +#endif + +LANGUAGE 0, SUBLANG_NEUTRAL +130 ICON "minetest-icon.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +1 VERSIONINFO + FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0 + PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0 + FILEFLAGSMASK 0x3fL +#ifndef NDEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS_NT_WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "" + VALUE "CompanyName", PROJECT_NAME_C " community" + VALUE "FileDescription", PROJECT_NAME_C " engine" + VALUE "FileVersion", VERSION_STRING + VALUE "InternalName", PROJECT_NAME + VALUE "LegalCopyright", "(c) 2011-2015 celeron55" + VALUE "LegalTrademarks", """Minetest"" is the property of the Minetest community, don't use it without permission!" + VALUE "OriginalFilename", "minetest.exe" + VALUE "PrivateBuild", VERSION_EXTRA + VALUE "ProductName", PROJECT_NAME_C + VALUE "ProductVersion", PRODUCT_VERSION_STRING + VALUE "SpecialBuild", BUILDMODE + END +END +BLOCK "VarFileInfo" +BEGIN + VALUE "Translation", 0x409, 1200 +END +END + diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index 30a9b45cc..4e47e7425 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -1,769 +1,769 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "guiButton.h" - - -#include "client/guiscalingfilter.h" -#include "IGUISkin.h" -#include "IGUIEnvironment.h" -#include "IVideoDriver.h" -#include "IGUIFont.h" -#include "irrlicht_changes/static_text.h" -#include "porting.h" -#include "StyleSpec.h" -#include "util/numeric.h" - -using namespace irr; -using namespace gui; - -// Multiply with a color to get the default corresponding hovered color -#define COLOR_HOVERED_MOD 1.25f - -// Multiply with a color to get the default corresponding pressed color -#define COLOR_PRESSED_MOD 0.85f - -//! constructor -GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent, - s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, - bool noclip) : - IGUIButton(environment, parent, id, rectangle), - TSrc(tsrc) -{ - setNotClipped(noclip); - - // This element can be tabbed. - setTabStop(true); - setTabOrder(-1); - - // PATCH - for (size_t i = 0; i < 4; i++) { - Colors[i] = Environment->getSkin()->getColor((EGUI_DEFAULT_COLOR)i); - } - StaticText = gui::StaticText::add(Environment, Text.c_str(), core::rect(0,0,rectangle.getWidth(),rectangle.getHeight()), false, false, this, id); - StaticText->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); - // END PATCH -} - -//! destructor -GUIButton::~GUIButton() -{ - if (OverrideFont) - OverrideFont->drop(); - - if (SpriteBank) - SpriteBank->drop(); -} - - -//! Sets if the images should be scaled to fit the button -void GUIButton::setScaleImage(bool scaleImage) -{ - ScaleImage = scaleImage; -} - - -//! Returns whether the button scale the used images -bool GUIButton::isScalingImage() const -{ - return ScaleImage; -} - - -//! Sets if the button should use the skin to draw its border -void GUIButton::setDrawBorder(bool border) -{ - DrawBorder = border; -} - - -void GUIButton::setSpriteBank(IGUISpriteBank* sprites) -{ - if (sprites) - sprites->grab(); - - if (SpriteBank) - SpriteBank->drop(); - - SpriteBank = sprites; -} - -void GUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop, bool scale) -{ - ButtonSprites[(u32)state].Index = index; - ButtonSprites[(u32)state].Color = color; - ButtonSprites[(u32)state].Loop = loop; - ButtonSprites[(u32)state].Scale = scale; -} - -//! Get the sprite-index for the given state or -1 when no sprite is set -s32 GUIButton::getSpriteIndex(EGUI_BUTTON_STATE state) const -{ - return ButtonSprites[(u32)state].Index; -} - -//! Get the sprite color for the given state. Color is only used when a sprite is set. -video::SColor GUIButton::getSpriteColor(EGUI_BUTTON_STATE state) const -{ - return ButtonSprites[(u32)state].Color; -} - -//! Returns if the sprite in the given state does loop -bool GUIButton::getSpriteLoop(EGUI_BUTTON_STATE state) const -{ - return ButtonSprites[(u32)state].Loop; -} - -//! Returns if the sprite in the given state is scaled -bool GUIButton::getSpriteScale(EGUI_BUTTON_STATE state) const -{ - return ButtonSprites[(u32)state].Scale; -} - -//! called if an event happened. -bool GUIButton::OnEvent(const SEvent& event) -{ - if (!isEnabled()) - return IGUIElement::OnEvent(event); - - switch(event.EventType) - { - case EET_KEY_INPUT_EVENT: - if (event.KeyInput.PressedDown && - (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) - { - if (!IsPushButton) - setPressed(true); - else - setPressed(!Pressed); - - return true; - } - if (Pressed && !IsPushButton && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE) - { - setPressed(false); - return true; - } - else - if (!event.KeyInput.PressedDown && Pressed && - (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) - { - - if (!IsPushButton) - setPressed(false); - - if (Parent) - { - ClickShiftState = event.KeyInput.Shift; - ClickControlState = event.KeyInput.Control; - - SEvent newEvent; - newEvent.EventType = EET_GUI_EVENT; - newEvent.GUIEvent.Caller = this; - newEvent.GUIEvent.Element = 0; - newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED; - Parent->OnEvent(newEvent); - } - return true; - } - break; - case EET_GUI_EVENT: - if (event.GUIEvent.Caller == this) - { - if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) - { - if (!IsPushButton) - setPressed(false); - FocusTime = (u32)porting::getTimeMs(); - } - else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) - { - FocusTime = (u32)porting::getTimeMs(); - } - else if (event.GUIEvent.EventType == EGET_ELEMENT_HOVERED || event.GUIEvent.EventType == EGET_ELEMENT_LEFT) - { - HoverTime = (u32)porting::getTimeMs(); - } - } - break; - case EET_MOUSE_INPUT_EVENT: - if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) - { - // Sometimes formspec elements can receive mouse events when the - // mouse is outside of the formspec. Thus, we test the position here. - if ( !IsPushButton && AbsoluteClippingRect.isPointInside( - core::position2d(event.MouseInput.X, event.MouseInput.Y ))) { - Environment->setFocus(this); - setPressed(true); - } - - return true; - } - else - if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) - { - bool wasPressed = Pressed; - - if ( !AbsoluteClippingRect.isPointInside( core::position2d(event.MouseInput.X, event.MouseInput.Y ) ) ) - { - if (!IsPushButton) - setPressed(false); - return true; - } - - if (!IsPushButton) - setPressed(false); - else - { - setPressed(!Pressed); - } - - if ((!IsPushButton && wasPressed && Parent) || - (IsPushButton && wasPressed != Pressed)) - { - ClickShiftState = event.MouseInput.Shift; - ClickControlState = event.MouseInput.Control; - - SEvent newEvent; - newEvent.EventType = EET_GUI_EVENT; - newEvent.GUIEvent.Caller = this; - newEvent.GUIEvent.Element = 0; - newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED; - Parent->OnEvent(newEvent); - } - - return true; - } - break; - default: - break; - } - - return Parent ? Parent->OnEvent(event) : false; -} - - -//! draws the element and its children -void GUIButton::draw() -{ - if (!IsVisible) - return; - - // PATCH - // Track hovered state, if it has changed then we need to update the style. - bool hovered = isHovered(); - bool focused = isFocused(); - if (hovered != WasHovered || focused != WasFocused) { - WasHovered = hovered; - WasFocused = focused; - setFromState(); - } - - GUISkin* skin = dynamic_cast(Environment->getSkin()); - video::IVideoDriver* driver = Environment->getVideoDriver(); - // END PATCH - - if (DrawBorder) - { - if (!Pressed) - { - // PATCH - skin->drawColored3DButtonPaneStandard(this, AbsoluteRect, - &AbsoluteClippingRect, Colors); - // END PATCH - } - else - { - // PATCH - skin->drawColored3DButtonPanePressed(this, AbsoluteRect, - &AbsoluteClippingRect, Colors); - // END PATCH - } - } - - const core::position2di buttonCenter(AbsoluteRect.getCenter()); - // PATCH - // The image changes based on the state, so we use the default every time. - EGUI_BUTTON_IMAGE_STATE imageState = EGBIS_IMAGE_UP; - // END PATCH - if ( ButtonImages[(u32)imageState].Texture ) - { - core::position2d pos(buttonCenter); - core::rect sourceRect(ButtonImages[(u32)imageState].SourceRect); - if ( sourceRect.getWidth() == 0 && sourceRect.getHeight() == 0 ) - sourceRect = core::rect(core::position2di(0,0), ButtonImages[(u32)imageState].Texture->getOriginalSize()); - - pos.X -= sourceRect.getWidth() / 2; - pos.Y -= sourceRect.getHeight() / 2; - - if ( Pressed ) - { - // Create a pressed-down effect by moving the image when it looks identical to the unpressed state image - EGUI_BUTTON_IMAGE_STATE unpressedState = getImageState(false); - if ( unpressedState == imageState || ButtonImages[(u32)imageState] == ButtonImages[(u32)unpressedState] ) - { - pos.X += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X); - pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y); - } - } - - // PATCH - video::ITexture* texture = ButtonImages[(u32)imageState].Texture; - video::SColor image_colors[] = { BgColor, BgColor, BgColor, BgColor }; - if (BgMiddle.getArea() == 0) { - driver->draw2DImage(texture, - ScaleImage? AbsoluteRect : core::rect(pos, sourceRect.getSize()), - sourceRect, &AbsoluteClippingRect, - image_colors, UseAlphaChannel); - } else { - draw2DImage9Slice(driver, texture, - ScaleImage ? AbsoluteRect : core::rect(pos, sourceRect.getSize()), - sourceRect, BgMiddle, &AbsoluteClippingRect, image_colors); - } - // END PATCH - } - - if (SpriteBank) - { - if (isEnabled()) - { - core::position2di pos(buttonCenter); - // pressed / unpressed animation - EGUI_BUTTON_STATE state = Pressed ? EGBS_BUTTON_DOWN : EGBS_BUTTON_UP; - drawSprite(state, ClickTime, pos); - - // focused / unfocused animation - state = Environment->hasFocus(this) ? EGBS_BUTTON_FOCUSED : EGBS_BUTTON_NOT_FOCUSED; - drawSprite(state, FocusTime, pos); - - // mouse over / off animation - state = isHovered() ? EGBS_BUTTON_MOUSE_OVER : EGBS_BUTTON_MOUSE_OFF; - drawSprite(state, HoverTime, pos); - } - else - { - // draw disabled -// drawSprite(EGBS_BUTTON_DISABLED, 0, pos); - } - } - - IGUIElement::draw(); -} - -void GUIButton::drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center) -{ - u32 stateIdx = (u32)state; - - if (ButtonSprites[stateIdx].Index != -1) - { - if ( ButtonSprites[stateIdx].Scale ) - { - const video::SColor colors[] = {ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color}; - SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, AbsoluteRect.UpperLeftCorner, - &AbsoluteClippingRect, colors[0], // FIXME: remove [0] - porting::getTimeMs()-startTime, ButtonSprites[stateIdx].Loop); - } - else - { - SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, center, - &AbsoluteClippingRect, ButtonSprites[stateIdx].Color, startTime, porting::getTimeMs(), - ButtonSprites[stateIdx].Loop, true); - } - } -} - -EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed) const -{ - // PATCH - return getImageState(pressed, ButtonImages); - // END PATCH -} - -EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed, const ButtonImage* images) const -{ - // figure state we should have - EGUI_BUTTON_IMAGE_STATE state = EGBIS_IMAGE_DISABLED; - bool focused = isFocused(); - bool mouseOver = isHovered(); - if (isEnabled()) - { - if ( pressed ) - { - if ( focused && mouseOver ) - state = EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER; - else if ( focused ) - state = EGBIS_IMAGE_DOWN_FOCUSED; - else if ( mouseOver ) - state = EGBIS_IMAGE_DOWN_MOUSEOVER; - else - state = EGBIS_IMAGE_DOWN; - } - else // !pressed - { - if ( focused && mouseOver ) - state = EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER; - else if ( focused ) - state = EGBIS_IMAGE_UP_FOCUSED; - else if ( mouseOver ) - state = EGBIS_IMAGE_UP_MOUSEOVER; - else - state = EGBIS_IMAGE_UP; - } - } - - // find a compatible state that has images - while ( state != EGBIS_IMAGE_UP && !images[(u32)state].Texture ) - { - // PATCH - switch ( state ) - { - case EGBIS_IMAGE_UP_FOCUSED: - state = EGBIS_IMAGE_UP; - break; - case EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER: - state = EGBIS_IMAGE_UP_FOCUSED; - break; - case EGBIS_IMAGE_DOWN_MOUSEOVER: - state = EGBIS_IMAGE_DOWN; - break; - case EGBIS_IMAGE_DOWN_FOCUSED: - state = EGBIS_IMAGE_DOWN; - break; - case EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER: - state = EGBIS_IMAGE_DOWN_FOCUSED; - break; - case EGBIS_IMAGE_DISABLED: - if ( pressed ) - state = EGBIS_IMAGE_DOWN; - else - state = EGBIS_IMAGE_UP; - break; - default: - state = EGBIS_IMAGE_UP; - } - // END PATCH - } - - return state; -} - -//! sets another skin independent font. if this is set to zero, the button uses the font of the skin. -void GUIButton::setOverrideFont(IGUIFont* font) -{ - if (OverrideFont == font) - return; - - if (OverrideFont) - OverrideFont->drop(); - - OverrideFont = font; - - if (OverrideFont) - OverrideFont->grab(); - - StaticText->setOverrideFont(font); -} - -//! Gets the override font (if any) -IGUIFont * GUIButton::getOverrideFont() const -{ - return OverrideFont; -} - -//! Get the font which is used right now for drawing -IGUIFont* GUIButton::getActiveFont() const -{ - if ( OverrideFont ) - return OverrideFont; - IGUISkin* skin = Environment->getSkin(); - if (skin) - return skin->getFont(EGDF_BUTTON); - return 0; -} - -//! Sets another color for the text. -void GUIButton::setOverrideColor(video::SColor color) -{ - OverrideColor = color; - OverrideColorEnabled = true; - - StaticText->setOverrideColor(color); -} - -video::SColor GUIButton::getOverrideColor() const -{ - return OverrideColor; -} - -video::SColor GUIButton::getActiveColor() const -{ - return video::SColor(0,0,0,0); // unused? -} - -void GUIButton::enableOverrideColor(bool enable) -{ - OverrideColorEnabled = enable; -} - -bool GUIButton::isOverrideColorEnabled() const -{ - return OverrideColorEnabled; -} - -void GUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image, const core::rect& sourceRect) -{ - if ( state >= EGBIS_COUNT ) - return; - - if ( image ) - image->grab(); - - u32 stateIdx = (u32)state; - if ( ButtonImages[stateIdx].Texture ) - ButtonImages[stateIdx].Texture->drop(); - - ButtonImages[stateIdx].Texture = image; - ButtonImages[stateIdx].SourceRect = sourceRect; -} - -// PATCH -void GUIButton::setImage(video::ITexture* image) -{ - setImage(gui::EGBIS_IMAGE_UP, image); -} - -void GUIButton::setImage(video::ITexture* image, const core::rect& pos) -{ - setImage(gui::EGBIS_IMAGE_UP, image, pos); -} - -void GUIButton::setPressedImage(video::ITexture* image) -{ - setImage(gui::EGBIS_IMAGE_DOWN, image); -} - -void GUIButton::setPressedImage(video::ITexture* image, const core::rect& pos) -{ - setImage(gui::EGBIS_IMAGE_DOWN, image, pos); -} - -//! Sets the text displayed by the button -void GUIButton::setText(const wchar_t* text) -{ - StaticText->setText(text); - - IGUIButton::setText(text); -} -// END PATCH - -//! Sets if the button should behave like a push button. Which means it -//! can be in two states: Normal or Pressed. With a click on the button, -//! the user can change the state of the button. -void GUIButton::setIsPushButton(bool isPushButton) -{ - IsPushButton = isPushButton; -} - - -//! Returns if the button is currently pressed -bool GUIButton::isPressed() const -{ - return Pressed; -} - -// PATCH -//! Returns if this element (or one of its direct children) is hovered -bool GUIButton::isHovered() const -{ - IGUIElement *hovered = Environment->getHovered(); - return hovered == this || (hovered != nullptr && hovered->getParent() == this); -} - -//! Returns if this element (or one of its direct children) is focused -bool GUIButton::isFocused() const -{ - return Environment->hasFocus((IGUIElement*)this, true); -} -// END PATCH - -//! Sets the pressed state of the button if this is a pushbutton -void GUIButton::setPressed(bool pressed) -{ - if (Pressed != pressed) - { - ClickTime = porting::getTimeMs(); - Pressed = pressed; - setFromState(); - } -} - - -//! Returns whether the button is a push button -bool GUIButton::isPushButton() const -{ - return IsPushButton; -} - - -//! Sets if the alpha channel should be used for drawing images on the button (default is false) -void GUIButton::setUseAlphaChannel(bool useAlphaChannel) -{ - UseAlphaChannel = useAlphaChannel; -} - - -//! Returns if the alpha channel should be used for drawing images on the button -bool GUIButton::isAlphaChannelUsed() const -{ - return UseAlphaChannel; -} - - -bool GUIButton::isDrawingBorder() const -{ - return DrawBorder; -} - - -// PATCH -GUIButton* GUIButton::addButton(IGUIEnvironment *environment, - const core::rect& rectangle, ISimpleTextureSource *tsrc, - IGUIElement* parent, s32 id, const wchar_t* text, - const wchar_t *tooltiptext) -{ - GUIButton* button = new GUIButton(environment, parent ? parent : environment->getRootGUIElement(), id, rectangle, tsrc); - if (text) - button->setText(text); - - if ( tooltiptext ) - button->setToolTipText ( tooltiptext ); - - button->drop(); - return button; -} - -void GUIButton::setColor(video::SColor color) -{ - BgColor = color; - - float d = 0.65f; - for (size_t i = 0; i < 4; i++) { - video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); - Colors[i] = base.getInterpolated(color, d); - } -} - -//! Set element properties from a StyleSpec corresponding to the button state -void GUIButton::setFromState() -{ - StyleSpec::State state = StyleSpec::STATE_DEFAULT; - - if (isPressed()) - state = static_cast(state | StyleSpec::STATE_PRESSED); - - if (isHovered()) - state = static_cast(state | StyleSpec::STATE_HOVERED); - - if (isFocused()) - state = static_cast(state | StyleSpec::STATE_FOCUSED); - - setFromStyle(StyleSpec::getStyleFromStatePropagation(Styles, state)); -} - -//! Set element properties from a StyleSpec -void GUIButton::setFromStyle(const StyleSpec& style) -{ - bool hovered = (style.getState() & StyleSpec::STATE_HOVERED) != 0; - bool pressed = (style.getState() & StyleSpec::STATE_PRESSED) != 0; - - if (style.isNotDefault(StyleSpec::BGCOLOR)) { - setColor(style.getColor(StyleSpec::BGCOLOR)); - - // If we have a propagated hover/press color, we need to automatically - // lighten/darken it - if (!Styles[style.getState()].isNotDefault(StyleSpec::BGCOLOR)) { - if (pressed) { - BgColor = multiplyColorValue(BgColor, COLOR_PRESSED_MOD); - - for (size_t i = 0; i < 4; i++) - Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD); - } else if (hovered) { - BgColor = multiplyColorValue(BgColor, COLOR_HOVERED_MOD); - - for (size_t i = 0; i < 4; i++) - Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD); - } - } - - } else { - BgColor = video::SColor(255, 255, 255, 255); - for (size_t i = 0; i < 4; i++) { - video::SColor base = - Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); - if (pressed) { - Colors[i] = multiplyColorValue(base, COLOR_PRESSED_MOD); - } else if (hovered) { - Colors[i] = multiplyColorValue(base, COLOR_HOVERED_MOD); - } else { - Colors[i] = base; - } - } - } - - if (style.isNotDefault(StyleSpec::TEXTCOLOR)) { - setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR)); - } else { - setOverrideColor(video::SColor(255,255,255,255)); - OverrideColorEnabled = false; - } - setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); - setDrawBorder(style.getBool(StyleSpec::BORDER, true)); - setUseAlphaChannel(style.getBool(StyleSpec::ALPHA, true)); - setOverrideFont(style.getFont()); - - if (style.isNotDefault(StyleSpec::BGIMG)) { - video::ITexture *texture = style.getTexture(StyleSpec::BGIMG, - getTextureSource()); - setImage(guiScalingImageButton( - Environment->getVideoDriver(), texture, - AbsoluteRect.getWidth(), AbsoluteRect.getHeight())); - setScaleImage(true); - } else { - setImage(nullptr); - } - - BgMiddle = style.getRect(StyleSpec::BGIMG_MIDDLE, BgMiddle); - - // Child padding and offset - Padding = style.getRect(StyleSpec::PADDING, core::rect()); - Padding = core::rect( - Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner, - Padding.LowerRightCorner + BgMiddle.LowerRightCorner); - - GUISkin* skin = dynamic_cast(Environment->getSkin()); - core::vector2d defaultPressOffset( - skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X), - skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y)); - ContentOffset = style.getVector2i(StyleSpec::CONTENT_OFFSET, isPressed() - ? defaultPressOffset - : core::vector2d(0)); - - core::rect childBounds( - Padding.UpperLeftCorner.X + ContentOffset.X, - Padding.UpperLeftCorner.Y + ContentOffset.Y, - AbsoluteRect.getWidth() + Padding.LowerRightCorner.X + ContentOffset.X, - AbsoluteRect.getHeight() + Padding.LowerRightCorner.Y + ContentOffset.Y); - - for (IGUIElement *child : getChildren()) { - child->setRelativePosition(childBounds); - } -} - -//! Set the styles used for each state -void GUIButton::setStyles(const std::array& styles) -{ - Styles = styles; - setFromState(); -} -// END PATCH +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "guiButton.h" + + +#include "client/guiscalingfilter.h" +#include "IGUISkin.h" +#include "IGUIEnvironment.h" +#include "IVideoDriver.h" +#include "IGUIFont.h" +#include "irrlicht_changes/static_text.h" +#include "porting.h" +#include "StyleSpec.h" +#include "util/numeric.h" + +using namespace irr; +using namespace gui; + +// Multiply with a color to get the default corresponding hovered color +#define COLOR_HOVERED_MOD 1.25f + +// Multiply with a color to get the default corresponding pressed color +#define COLOR_PRESSED_MOD 0.85f + +//! constructor +GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent, + s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, + bool noclip) : + IGUIButton(environment, parent, id, rectangle), + TSrc(tsrc) +{ + setNotClipped(noclip); + + // This element can be tabbed. + setTabStop(true); + setTabOrder(-1); + + // PATCH + for (size_t i = 0; i < 4; i++) { + Colors[i] = Environment->getSkin()->getColor((EGUI_DEFAULT_COLOR)i); + } + StaticText = gui::StaticText::add(Environment, Text.c_str(), core::rect(0,0,rectangle.getWidth(),rectangle.getHeight()), false, false, this, id); + StaticText->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); + // END PATCH +} + +//! destructor +GUIButton::~GUIButton() +{ + if (OverrideFont) + OverrideFont->drop(); + + if (SpriteBank) + SpriteBank->drop(); +} + + +//! Sets if the images should be scaled to fit the button +void GUIButton::setScaleImage(bool scaleImage) +{ + ScaleImage = scaleImage; +} + + +//! Returns whether the button scale the used images +bool GUIButton::isScalingImage() const +{ + return ScaleImage; +} + + +//! Sets if the button should use the skin to draw its border +void GUIButton::setDrawBorder(bool border) +{ + DrawBorder = border; +} + + +void GUIButton::setSpriteBank(IGUISpriteBank* sprites) +{ + if (sprites) + sprites->grab(); + + if (SpriteBank) + SpriteBank->drop(); + + SpriteBank = sprites; +} + +void GUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop, bool scale) +{ + ButtonSprites[(u32)state].Index = index; + ButtonSprites[(u32)state].Color = color; + ButtonSprites[(u32)state].Loop = loop; + ButtonSprites[(u32)state].Scale = scale; +} + +//! Get the sprite-index for the given state or -1 when no sprite is set +s32 GUIButton::getSpriteIndex(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Index; +} + +//! Get the sprite color for the given state. Color is only used when a sprite is set. +video::SColor GUIButton::getSpriteColor(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Color; +} + +//! Returns if the sprite in the given state does loop +bool GUIButton::getSpriteLoop(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Loop; +} + +//! Returns if the sprite in the given state is scaled +bool GUIButton::getSpriteScale(EGUI_BUTTON_STATE state) const +{ + return ButtonSprites[(u32)state].Scale; +} + +//! called if an event happened. +bool GUIButton::OnEvent(const SEvent& event) +{ + if (!isEnabled()) + return IGUIElement::OnEvent(event); + + switch(event.EventType) + { + case EET_KEY_INPUT_EVENT: + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) + { + if (!IsPushButton) + setPressed(true); + else + setPressed(!Pressed); + + return true; + } + if (Pressed && !IsPushButton && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE) + { + setPressed(false); + return true; + } + else + if (!event.KeyInput.PressedDown && Pressed && + (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)) + { + + if (!IsPushButton) + setPressed(false); + + if (Parent) + { + ClickShiftState = event.KeyInput.Shift; + ClickControlState = event.KeyInput.Control; + + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED; + Parent->OnEvent(newEvent); + } + return true; + } + break; + case EET_GUI_EVENT: + if (event.GUIEvent.Caller == this) + { + if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) + { + if (!IsPushButton) + setPressed(false); + FocusTime = (u32)porting::getTimeMs(); + } + else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) + { + FocusTime = (u32)porting::getTimeMs(); + } + else if (event.GUIEvent.EventType == EGET_ELEMENT_HOVERED || event.GUIEvent.EventType == EGET_ELEMENT_LEFT) + { + HoverTime = (u32)porting::getTimeMs(); + } + } + break; + case EET_MOUSE_INPUT_EVENT: + if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) + { + // Sometimes formspec elements can receive mouse events when the + // mouse is outside of the formspec. Thus, we test the position here. + if ( !IsPushButton && AbsoluteClippingRect.isPointInside( + core::position2d(event.MouseInput.X, event.MouseInput.Y ))) { + Environment->setFocus(this); + setPressed(true); + } + + return true; + } + else + if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) + { + bool wasPressed = Pressed; + + if ( !AbsoluteClippingRect.isPointInside( core::position2d(event.MouseInput.X, event.MouseInput.Y ) ) ) + { + if (!IsPushButton) + setPressed(false); + return true; + } + + if (!IsPushButton) + setPressed(false); + else + { + setPressed(!Pressed); + } + + if ((!IsPushButton && wasPressed && Parent) || + (IsPushButton && wasPressed != Pressed)) + { + ClickShiftState = event.MouseInput.Shift; + ClickControlState = event.MouseInput.Control; + + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED; + Parent->OnEvent(newEvent); + } + + return true; + } + break; + default: + break; + } + + return Parent ? Parent->OnEvent(event) : false; +} + + +//! draws the element and its children +void GUIButton::draw() +{ + if (!IsVisible) + return; + + // PATCH + // Track hovered state, if it has changed then we need to update the style. + bool hovered = isHovered(); + bool focused = isFocused(); + if (hovered != WasHovered || focused != WasFocused) { + WasHovered = hovered; + WasFocused = focused; + setFromState(); + } + + GUISkin* skin = dynamic_cast(Environment->getSkin()); + video::IVideoDriver* driver = Environment->getVideoDriver(); + // END PATCH + + if (DrawBorder) + { + if (!Pressed) + { + // PATCH + skin->drawColored3DButtonPaneStandard(this, AbsoluteRect, + &AbsoluteClippingRect, Colors); + // END PATCH + } + else + { + // PATCH + skin->drawColored3DButtonPanePressed(this, AbsoluteRect, + &AbsoluteClippingRect, Colors); + // END PATCH + } + } + + const core::position2di buttonCenter(AbsoluteRect.getCenter()); + // PATCH + // The image changes based on the state, so we use the default every time. + EGUI_BUTTON_IMAGE_STATE imageState = EGBIS_IMAGE_UP; + // END PATCH + if ( ButtonImages[(u32)imageState].Texture ) + { + core::position2d pos(buttonCenter); + core::rect sourceRect(ButtonImages[(u32)imageState].SourceRect); + if ( sourceRect.getWidth() == 0 && sourceRect.getHeight() == 0 ) + sourceRect = core::rect(core::position2di(0,0), ButtonImages[(u32)imageState].Texture->getOriginalSize()); + + pos.X -= sourceRect.getWidth() / 2; + pos.Y -= sourceRect.getHeight() / 2; + + if ( Pressed ) + { + // Create a pressed-down effect by moving the image when it looks identical to the unpressed state image + EGUI_BUTTON_IMAGE_STATE unpressedState = getImageState(false); + if ( unpressedState == imageState || ButtonImages[(u32)imageState] == ButtonImages[(u32)unpressedState] ) + { + pos.X += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X); + pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y); + } + } + + // PATCH + video::ITexture* texture = ButtonImages[(u32)imageState].Texture; + video::SColor image_colors[] = { BgColor, BgColor, BgColor, BgColor }; + if (BgMiddle.getArea() == 0) { + driver->draw2DImage(texture, + ScaleImage? AbsoluteRect : core::rect(pos, sourceRect.getSize()), + sourceRect, &AbsoluteClippingRect, + image_colors, UseAlphaChannel); + } else { + draw2DImage9Slice(driver, texture, + ScaleImage ? AbsoluteRect : core::rect(pos, sourceRect.getSize()), + sourceRect, BgMiddle, &AbsoluteClippingRect, image_colors); + } + // END PATCH + } + + if (SpriteBank) + { + if (isEnabled()) + { + core::position2di pos(buttonCenter); + // pressed / unpressed animation + EGUI_BUTTON_STATE state = Pressed ? EGBS_BUTTON_DOWN : EGBS_BUTTON_UP; + drawSprite(state, ClickTime, pos); + + // focused / unfocused animation + state = Environment->hasFocus(this) ? EGBS_BUTTON_FOCUSED : EGBS_BUTTON_NOT_FOCUSED; + drawSprite(state, FocusTime, pos); + + // mouse over / off animation + state = isHovered() ? EGBS_BUTTON_MOUSE_OVER : EGBS_BUTTON_MOUSE_OFF; + drawSprite(state, HoverTime, pos); + } + else + { + // draw disabled +// drawSprite(EGBS_BUTTON_DISABLED, 0, pos); + } + } + + IGUIElement::draw(); +} + +void GUIButton::drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center) +{ + u32 stateIdx = (u32)state; + + if (ButtonSprites[stateIdx].Index != -1) + { + if ( ButtonSprites[stateIdx].Scale ) + { + const video::SColor colors[] = {ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color}; + SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, AbsoluteRect.UpperLeftCorner, + &AbsoluteClippingRect, colors[0], // FIXME: remove [0] + porting::getTimeMs()-startTime, ButtonSprites[stateIdx].Loop); + } + else + { + SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, center, + &AbsoluteClippingRect, ButtonSprites[stateIdx].Color, startTime, porting::getTimeMs(), + ButtonSprites[stateIdx].Loop, true); + } + } +} + +EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed) const +{ + // PATCH + return getImageState(pressed, ButtonImages); + // END PATCH +} + +EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed, const ButtonImage* images) const +{ + // figure state we should have + EGUI_BUTTON_IMAGE_STATE state = EGBIS_IMAGE_DISABLED; + bool focused = isFocused(); + bool mouseOver = isHovered(); + if (isEnabled()) + { + if ( pressed ) + { + if ( focused && mouseOver ) + state = EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER; + else if ( focused ) + state = EGBIS_IMAGE_DOWN_FOCUSED; + else if ( mouseOver ) + state = EGBIS_IMAGE_DOWN_MOUSEOVER; + else + state = EGBIS_IMAGE_DOWN; + } + else // !pressed + { + if ( focused && mouseOver ) + state = EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER; + else if ( focused ) + state = EGBIS_IMAGE_UP_FOCUSED; + else if ( mouseOver ) + state = EGBIS_IMAGE_UP_MOUSEOVER; + else + state = EGBIS_IMAGE_UP; + } + } + + // find a compatible state that has images + while ( state != EGBIS_IMAGE_UP && !images[(u32)state].Texture ) + { + // PATCH + switch ( state ) + { + case EGBIS_IMAGE_UP_FOCUSED: + state = EGBIS_IMAGE_UP; + break; + case EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER: + state = EGBIS_IMAGE_UP_FOCUSED; + break; + case EGBIS_IMAGE_DOWN_MOUSEOVER: + state = EGBIS_IMAGE_DOWN; + break; + case EGBIS_IMAGE_DOWN_FOCUSED: + state = EGBIS_IMAGE_DOWN; + break; + case EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER: + state = EGBIS_IMAGE_DOWN_FOCUSED; + break; + case EGBIS_IMAGE_DISABLED: + if ( pressed ) + state = EGBIS_IMAGE_DOWN; + else + state = EGBIS_IMAGE_UP; + break; + default: + state = EGBIS_IMAGE_UP; + } + // END PATCH + } + + return state; +} + +//! sets another skin independent font. if this is set to zero, the button uses the font of the skin. +void GUIButton::setOverrideFont(IGUIFont* font) +{ + if (OverrideFont == font) + return; + + if (OverrideFont) + OverrideFont->drop(); + + OverrideFont = font; + + if (OverrideFont) + OverrideFont->grab(); + + StaticText->setOverrideFont(font); +} + +//! Gets the override font (if any) +IGUIFont * GUIButton::getOverrideFont() const +{ + return OverrideFont; +} + +//! Get the font which is used right now for drawing +IGUIFont* GUIButton::getActiveFont() const +{ + if ( OverrideFont ) + return OverrideFont; + IGUISkin* skin = Environment->getSkin(); + if (skin) + return skin->getFont(EGDF_BUTTON); + return 0; +} + +//! Sets another color for the text. +void GUIButton::setOverrideColor(video::SColor color) +{ + OverrideColor = color; + OverrideColorEnabled = true; + + StaticText->setOverrideColor(color); +} + +video::SColor GUIButton::getOverrideColor() const +{ + return OverrideColor; +} + +video::SColor GUIButton::getActiveColor() const +{ + return video::SColor(0,0,0,0); // unused? +} + +void GUIButton::enableOverrideColor(bool enable) +{ + OverrideColorEnabled = enable; +} + +bool GUIButton::isOverrideColorEnabled() const +{ + return OverrideColorEnabled; +} + +void GUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image, const core::rect& sourceRect) +{ + if ( state >= EGBIS_COUNT ) + return; + + if ( image ) + image->grab(); + + u32 stateIdx = (u32)state; + if ( ButtonImages[stateIdx].Texture ) + ButtonImages[stateIdx].Texture->drop(); + + ButtonImages[stateIdx].Texture = image; + ButtonImages[stateIdx].SourceRect = sourceRect; +} + +// PATCH +void GUIButton::setImage(video::ITexture* image) +{ + setImage(gui::EGBIS_IMAGE_UP, image); +} + +void GUIButton::setImage(video::ITexture* image, const core::rect& pos) +{ + setImage(gui::EGBIS_IMAGE_UP, image, pos); +} + +void GUIButton::setPressedImage(video::ITexture* image) +{ + setImage(gui::EGBIS_IMAGE_DOWN, image); +} + +void GUIButton::setPressedImage(video::ITexture* image, const core::rect& pos) +{ + setImage(gui::EGBIS_IMAGE_DOWN, image, pos); +} + +//! Sets the text displayed by the button +void GUIButton::setText(const wchar_t* text) +{ + StaticText->setText(text); + + IGUIButton::setText(text); +} +// END PATCH + +//! Sets if the button should behave like a push button. Which means it +//! can be in two states: Normal or Pressed. With a click on the button, +//! the user can change the state of the button. +void GUIButton::setIsPushButton(bool isPushButton) +{ + IsPushButton = isPushButton; +} + + +//! Returns if the button is currently pressed +bool GUIButton::isPressed() const +{ + return Pressed; +} + +// PATCH +//! Returns if this element (or one of its direct children) is hovered +bool GUIButton::isHovered() const +{ + IGUIElement *hovered = Environment->getHovered(); + return hovered == this || (hovered != nullptr && hovered->getParent() == this); +} + +//! Returns if this element (or one of its direct children) is focused +bool GUIButton::isFocused() const +{ + return Environment->hasFocus((IGUIElement*)this, true); +} +// END PATCH + +//! Sets the pressed state of the button if this is a pushbutton +void GUIButton::setPressed(bool pressed) +{ + if (Pressed != pressed) + { + ClickTime = porting::getTimeMs(); + Pressed = pressed; + setFromState(); + } +} + + +//! Returns whether the button is a push button +bool GUIButton::isPushButton() const +{ + return IsPushButton; +} + + +//! Sets if the alpha channel should be used for drawing images on the button (default is false) +void GUIButton::setUseAlphaChannel(bool useAlphaChannel) +{ + UseAlphaChannel = useAlphaChannel; +} + + +//! Returns if the alpha channel should be used for drawing images on the button +bool GUIButton::isAlphaChannelUsed() const +{ + return UseAlphaChannel; +} + + +bool GUIButton::isDrawingBorder() const +{ + return DrawBorder; +} + + +// PATCH +GUIButton* GUIButton::addButton(IGUIEnvironment *environment, + const core::rect& rectangle, ISimpleTextureSource *tsrc, + IGUIElement* parent, s32 id, const wchar_t* text, + const wchar_t *tooltiptext) +{ + GUIButton* button = new GUIButton(environment, parent ? parent : environment->getRootGUIElement(), id, rectangle, tsrc); + if (text) + button->setText(text); + + if ( tooltiptext ) + button->setToolTipText ( tooltiptext ); + + button->drop(); + return button; +} + +void GUIButton::setColor(video::SColor color) +{ + BgColor = color; + + float d = 0.65f; + for (size_t i = 0; i < 4; i++) { + video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); + Colors[i] = base.getInterpolated(color, d); + } +} + +//! Set element properties from a StyleSpec corresponding to the button state +void GUIButton::setFromState() +{ + StyleSpec::State state = StyleSpec::STATE_DEFAULT; + + if (isPressed()) + state = static_cast(state | StyleSpec::STATE_PRESSED); + + if (isHovered()) + state = static_cast(state | StyleSpec::STATE_HOVERED); + + if (isFocused()) + state = static_cast(state | StyleSpec::STATE_FOCUSED); + + setFromStyle(StyleSpec::getStyleFromStatePropagation(Styles, state)); +} + +//! Set element properties from a StyleSpec +void GUIButton::setFromStyle(const StyleSpec& style) +{ + bool hovered = (style.getState() & StyleSpec::STATE_HOVERED) != 0; + bool pressed = (style.getState() & StyleSpec::STATE_PRESSED) != 0; + + if (style.isNotDefault(StyleSpec::BGCOLOR)) { + setColor(style.getColor(StyleSpec::BGCOLOR)); + + // If we have a propagated hover/press color, we need to automatically + // lighten/darken it + if (!Styles[style.getState()].isNotDefault(StyleSpec::BGCOLOR)) { + if (pressed) { + BgColor = multiplyColorValue(BgColor, COLOR_PRESSED_MOD); + + for (size_t i = 0; i < 4; i++) + Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD); + } else if (hovered) { + BgColor = multiplyColorValue(BgColor, COLOR_HOVERED_MOD); + + for (size_t i = 0; i < 4; i++) + Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD); + } + } + + } else { + BgColor = video::SColor(255, 255, 255, 255); + for (size_t i = 0; i < 4; i++) { + video::SColor base = + Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); + if (pressed) { + Colors[i] = multiplyColorValue(base, COLOR_PRESSED_MOD); + } else if (hovered) { + Colors[i] = multiplyColorValue(base, COLOR_HOVERED_MOD); + } else { + Colors[i] = base; + } + } + } + + if (style.isNotDefault(StyleSpec::TEXTCOLOR)) { + setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR)); + } else { + setOverrideColor(video::SColor(255,255,255,255)); + OverrideColorEnabled = false; + } + setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); + setDrawBorder(style.getBool(StyleSpec::BORDER, true)); + setUseAlphaChannel(style.getBool(StyleSpec::ALPHA, true)); + setOverrideFont(style.getFont()); + + if (style.isNotDefault(StyleSpec::BGIMG)) { + video::ITexture *texture = style.getTexture(StyleSpec::BGIMG, + getTextureSource()); + setImage(guiScalingImageButton( + Environment->getVideoDriver(), texture, + AbsoluteRect.getWidth(), AbsoluteRect.getHeight())); + setScaleImage(true); + } else { + setImage(nullptr); + } + + BgMiddle = style.getRect(StyleSpec::BGIMG_MIDDLE, BgMiddle); + + // Child padding and offset + Padding = style.getRect(StyleSpec::PADDING, core::rect()); + Padding = core::rect( + Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner, + Padding.LowerRightCorner + BgMiddle.LowerRightCorner); + + GUISkin* skin = dynamic_cast(Environment->getSkin()); + core::vector2d defaultPressOffset( + skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X), + skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y)); + ContentOffset = style.getVector2i(StyleSpec::CONTENT_OFFSET, isPressed() + ? defaultPressOffset + : core::vector2d(0)); + + core::rect childBounds( + Padding.UpperLeftCorner.X + ContentOffset.X, + Padding.UpperLeftCorner.Y + ContentOffset.Y, + AbsoluteRect.getWidth() + Padding.LowerRightCorner.X + ContentOffset.X, + AbsoluteRect.getHeight() + Padding.LowerRightCorner.Y + ContentOffset.Y); + + for (IGUIElement *child : getChildren()) { + child->setRelativePosition(childBounds); + } +} + +//! Set the styles used for each state +void GUIButton::setStyles(const std::array& styles) +{ + Styles = styles; + setFromState(); +} +// END PATCH diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h index b0fc4b647..c96f1ca4e 100644 --- a/src/gui/guiButton.h +++ b/src/gui/guiButton.h @@ -1,280 +1,280 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#pragma once - -#include -#include "irrlicht_changes/static_text.h" -#include "IGUIButton.h" -#include "IGUISpriteBank.h" -#include "ITexture.h" -#include "SColor.h" -#include "guiSkin.h" -#include "StyleSpec.h" - -using namespace irr; - -class ISimpleTextureSource; - -class GUIButton : public gui::IGUIButton -{ -public: - - //! constructor - GUIButton(gui::IGUIEnvironment* environment, gui::IGUIElement* parent, - s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, - bool noclip=false); - - //! destructor - virtual ~GUIButton(); - - //! called if an event happened. - virtual bool OnEvent(const SEvent& event) override; - - //! draws the element and its children - virtual void draw() override; - - //! sets another skin independent font. if this is set to zero, the button uses the font of the skin. - virtual void setOverrideFont(gui::IGUIFont* font=0) override; - - //! Gets the override font (if any) - virtual gui::IGUIFont* getOverrideFont() const override; - - //! Get the font which is used right now for drawing - virtual gui::IGUIFont* getActiveFont() const override; - - //! Sets another color for the button text. - virtual void setOverrideColor(video::SColor color) override; - - //! Gets the override color - virtual video::SColor getOverrideColor() const override; - - //! Gets the currently used text color - virtual video::SColor getActiveColor() const override; - - //! Sets if the button text should use the override color or the color in the gui skin. - virtual void enableOverrideColor(bool enable) override; - - //! Checks if an override color is enabled - virtual bool isOverrideColorEnabled(void) const override; - - // PATCH - //! Sets an image which should be displayed on the button when it is in the given state. - virtual void setImage(gui::EGUI_BUTTON_IMAGE_STATE state, - video::ITexture* image=nullptr, - const core::rect& sourceRect=core::rect(0,0,0,0)) override; - - //! Sets an image which should be displayed on the button when it is in normal state. - virtual void setImage(video::ITexture* image=nullptr) override; - - //! Sets an image which should be displayed on the button when it is in normal state. - virtual void setImage(video::ITexture* image, const core::rect& pos) override; - - //! Sets an image which should be displayed on the button when it is in pressed state. - virtual void setPressedImage(video::ITexture* image=nullptr) override; - - //! Sets an image which should be displayed on the button when it is in pressed state. - virtual void setPressedImage(video::ITexture* image, const core::rect& pos) override; - - //! Sets the text displayed by the button - virtual void setText(const wchar_t* text) override; - // END PATCH - - //! Sets the sprite bank used by the button - virtual void setSpriteBank(gui::IGUISpriteBank* bank=0) override; - - //! Sets the animated sprite for a specific button state - /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite - \param state: State of the button to set the sprite for - \param index: The sprite number from the current sprite bank - \param color: The color of the sprite - */ - virtual void setSprite(gui::EGUI_BUTTON_STATE state, s32 index, - video::SColor color=video::SColor(255,255,255,255), - bool loop=false, bool scale=false) override; - - //! Get the sprite-index for the given state or -1 when no sprite is set - virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const override; - - //! Get the sprite color for the given state. Color is only used when a sprite is set. - virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const override; - - //! Returns if the sprite in the given state does loop - virtual bool getSpriteLoop(gui::EGUI_BUTTON_STATE state) const override; - - //! Returns if the sprite in the given state is scaled - virtual bool getSpriteScale(gui::EGUI_BUTTON_STATE state) const override; - - //! Sets if the button should behave like a push button. Which means it - //! can be in two states: Normal or Pressed. With a click on the button, - //! the user can change the state of the button. - virtual void setIsPushButton(bool isPushButton=true) override; - - //! Checks whether the button is a push button - virtual bool isPushButton() const override; - - //! Sets the pressed state of the button if this is a pushbutton - virtual void setPressed(bool pressed=true) override; - - //! Returns if the button is currently pressed - virtual bool isPressed() const override; - - // PATCH - //! Returns if this element (or one of its direct children) is hovered - bool isHovered() const; - - //! Returns if this element (or one of its direct children) is focused - bool isFocused() const; - // END PATCH - - //! Sets if the button should use the skin to draw its border - virtual void setDrawBorder(bool border=true) override; - - //! Checks if the button face and border are being drawn - virtual bool isDrawingBorder() const override; - - //! Sets if the alpha channel should be used for drawing images on the button (default is false) - virtual void setUseAlphaChannel(bool useAlphaChannel=true) override; - - //! Checks if the alpha channel should be used for drawing images on the button - virtual bool isAlphaChannelUsed() const override; - - //! Sets if the button should scale the button images to fit - virtual void setScaleImage(bool scaleImage=true) override; - - //! Checks whether the button scales the used images - virtual bool isScalingImage() const override; - - //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event - virtual bool getClickShiftState() const override - { - return ClickShiftState; - } - - //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event - virtual bool getClickControlState() const override - { - return ClickControlState; - } - - void setColor(video::SColor color); - // PATCH - //! Set element properties from a StyleSpec corresponding to the button state - void setFromState(); - - //! Set element properties from a StyleSpec - virtual void setFromStyle(const StyleSpec& style); - - //! Set the styles used for each state - void setStyles(const std::array& styles); - // END PATCH - - - //! Do not drop returned handle - static GUIButton* addButton(gui::IGUIEnvironment *environment, - const core::rect& rectangle, ISimpleTextureSource *tsrc, - IGUIElement* parent, s32 id, const wchar_t* text, - const wchar_t *tooltiptext=L""); - -protected: - void drawSprite(gui::EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center); - gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const; - - ISimpleTextureSource *getTextureSource() { return TSrc; } - - struct ButtonImage - { - ButtonImage() = default; - - ButtonImage(const ButtonImage& other) - { - *this = other; - } - - ~ButtonImage() - { - if ( Texture ) - Texture->drop(); - } - - ButtonImage& operator=(const ButtonImage& other) - { - if ( this == &other ) - return *this; - - if (other.Texture) - other.Texture->grab(); - if ( Texture ) - Texture->drop(); - Texture = other.Texture; - SourceRect = other.SourceRect; - return *this; - } - - bool operator==(const ButtonImage& other) const - { - return Texture == other.Texture && SourceRect == other.SourceRect; - } - - - video::ITexture* Texture = nullptr; - core::rect SourceRect = core::rect(0,0,0,0); - }; - - gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed, const ButtonImage* images) const; - -private: - - struct ButtonSprite - { - bool operator==(const ButtonSprite &other) const - { - return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale; - } - - s32 Index = -1; - video::SColor Color; - bool Loop = false; - bool Scale = false; - }; - - ButtonSprite ButtonSprites[gui::EGBS_COUNT]; - gui::IGUISpriteBank* SpriteBank = nullptr; - - ButtonImage ButtonImages[gui::EGBIS_COUNT]; - - std::array Styles; - - gui::IGUIFont* OverrideFont = nullptr; - - bool OverrideColorEnabled = false; - video::SColor OverrideColor = video::SColor(101,255,255,255); - - u32 ClickTime = 0; - u32 HoverTime = 0; - u32 FocusTime = 0; - - bool ClickShiftState = false; - bool ClickControlState = false; - - bool IsPushButton = false; - bool Pressed = false; - bool UseAlphaChannel = false; - bool DrawBorder = true; - bool ScaleImage = false; - - video::SColor Colors[4]; - // PATCH - bool WasHovered = false; - bool WasFocused = false; - ISimpleTextureSource *TSrc; - - gui::IGUIStaticText *StaticText; - - core::rect BgMiddle; - core::rect Padding; - core::vector2d ContentOffset; - video::SColor BgColor = video::SColor(0xFF,0xFF,0xFF,0xFF); - // END PATCH -}; +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include +#include "irrlicht_changes/static_text.h" +#include "IGUIButton.h" +#include "IGUISpriteBank.h" +#include "ITexture.h" +#include "SColor.h" +#include "guiSkin.h" +#include "StyleSpec.h" + +using namespace irr; + +class ISimpleTextureSource; + +class GUIButton : public gui::IGUIButton +{ +public: + + //! constructor + GUIButton(gui::IGUIEnvironment* environment, gui::IGUIElement* parent, + s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, + bool noclip=false); + + //! destructor + virtual ~GUIButton(); + + //! called if an event happened. + virtual bool OnEvent(const SEvent& event) override; + + //! draws the element and its children + virtual void draw() override; + + //! sets another skin independent font. if this is set to zero, the button uses the font of the skin. + virtual void setOverrideFont(gui::IGUIFont* font=0) override; + + //! Gets the override font (if any) + virtual gui::IGUIFont* getOverrideFont() const override; + + //! Get the font which is used right now for drawing + virtual gui::IGUIFont* getActiveFont() const override; + + //! Sets another color for the button text. + virtual void setOverrideColor(video::SColor color) override; + + //! Gets the override color + virtual video::SColor getOverrideColor() const override; + + //! Gets the currently used text color + virtual video::SColor getActiveColor() const override; + + //! Sets if the button text should use the override color or the color in the gui skin. + virtual void enableOverrideColor(bool enable) override; + + //! Checks if an override color is enabled + virtual bool isOverrideColorEnabled(void) const override; + + // PATCH + //! Sets an image which should be displayed on the button when it is in the given state. + virtual void setImage(gui::EGUI_BUTTON_IMAGE_STATE state, + video::ITexture* image=nullptr, + const core::rect& sourceRect=core::rect(0,0,0,0)) override; + + //! Sets an image which should be displayed on the button when it is in normal state. + virtual void setImage(video::ITexture* image=nullptr) override; + + //! Sets an image which should be displayed on the button when it is in normal state. + virtual void setImage(video::ITexture* image, const core::rect& pos) override; + + //! Sets an image which should be displayed on the button when it is in pressed state. + virtual void setPressedImage(video::ITexture* image=nullptr) override; + + //! Sets an image which should be displayed on the button when it is in pressed state. + virtual void setPressedImage(video::ITexture* image, const core::rect& pos) override; + + //! Sets the text displayed by the button + virtual void setText(const wchar_t* text) override; + // END PATCH + + //! Sets the sprite bank used by the button + virtual void setSpriteBank(gui::IGUISpriteBank* bank=0) override; + + //! Sets the animated sprite for a specific button state + /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite + \param state: State of the button to set the sprite for + \param index: The sprite number from the current sprite bank + \param color: The color of the sprite + */ + virtual void setSprite(gui::EGUI_BUTTON_STATE state, s32 index, + video::SColor color=video::SColor(255,255,255,255), + bool loop=false, bool scale=false) override; + + //! Get the sprite-index for the given state or -1 when no sprite is set + virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const override; + + //! Get the sprite color for the given state. Color is only used when a sprite is set. + virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const override; + + //! Returns if the sprite in the given state does loop + virtual bool getSpriteLoop(gui::EGUI_BUTTON_STATE state) const override; + + //! Returns if the sprite in the given state is scaled + virtual bool getSpriteScale(gui::EGUI_BUTTON_STATE state) const override; + + //! Sets if the button should behave like a push button. Which means it + //! can be in two states: Normal or Pressed. With a click on the button, + //! the user can change the state of the button. + virtual void setIsPushButton(bool isPushButton=true) override; + + //! Checks whether the button is a push button + virtual bool isPushButton() const override; + + //! Sets the pressed state of the button if this is a pushbutton + virtual void setPressed(bool pressed=true) override; + + //! Returns if the button is currently pressed + virtual bool isPressed() const override; + + // PATCH + //! Returns if this element (or one of its direct children) is hovered + bool isHovered() const; + + //! Returns if this element (or one of its direct children) is focused + bool isFocused() const; + // END PATCH + + //! Sets if the button should use the skin to draw its border + virtual void setDrawBorder(bool border=true) override; + + //! Checks if the button face and border are being drawn + virtual bool isDrawingBorder() const override; + + //! Sets if the alpha channel should be used for drawing images on the button (default is false) + virtual void setUseAlphaChannel(bool useAlphaChannel=true) override; + + //! Checks if the alpha channel should be used for drawing images on the button + virtual bool isAlphaChannelUsed() const override; + + //! Sets if the button should scale the button images to fit + virtual void setScaleImage(bool scaleImage=true) override; + + //! Checks whether the button scales the used images + virtual bool isScalingImage() const override; + + //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event + virtual bool getClickShiftState() const override + { + return ClickShiftState; + } + + //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event + virtual bool getClickControlState() const override + { + return ClickControlState; + } + + void setColor(video::SColor color); + // PATCH + //! Set element properties from a StyleSpec corresponding to the button state + void setFromState(); + + //! Set element properties from a StyleSpec + virtual void setFromStyle(const StyleSpec& style); + + //! Set the styles used for each state + void setStyles(const std::array& styles); + // END PATCH + + + //! Do not drop returned handle + static GUIButton* addButton(gui::IGUIEnvironment *environment, + const core::rect& rectangle, ISimpleTextureSource *tsrc, + IGUIElement* parent, s32 id, const wchar_t* text, + const wchar_t *tooltiptext=L""); + +protected: + void drawSprite(gui::EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center); + gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const; + + ISimpleTextureSource *getTextureSource() { return TSrc; } + + struct ButtonImage + { + ButtonImage() = default; + + ButtonImage(const ButtonImage& other) + { + *this = other; + } + + ~ButtonImage() + { + if ( Texture ) + Texture->drop(); + } + + ButtonImage& operator=(const ButtonImage& other) + { + if ( this == &other ) + return *this; + + if (other.Texture) + other.Texture->grab(); + if ( Texture ) + Texture->drop(); + Texture = other.Texture; + SourceRect = other.SourceRect; + return *this; + } + + bool operator==(const ButtonImage& other) const + { + return Texture == other.Texture && SourceRect == other.SourceRect; + } + + + video::ITexture* Texture = nullptr; + core::rect SourceRect = core::rect(0,0,0,0); + }; + + gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed, const ButtonImage* images) const; + +private: + + struct ButtonSprite + { + bool operator==(const ButtonSprite &other) const + { + return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale; + } + + s32 Index = -1; + video::SColor Color; + bool Loop = false; + bool Scale = false; + }; + + ButtonSprite ButtonSprites[gui::EGBS_COUNT]; + gui::IGUISpriteBank* SpriteBank = nullptr; + + ButtonImage ButtonImages[gui::EGBIS_COUNT]; + + std::array Styles; + + gui::IGUIFont* OverrideFont = nullptr; + + bool OverrideColorEnabled = false; + video::SColor OverrideColor = video::SColor(101,255,255,255); + + u32 ClickTime = 0; + u32 HoverTime = 0; + u32 FocusTime = 0; + + bool ClickShiftState = false; + bool ClickControlState = false; + + bool IsPushButton = false; + bool Pressed = false; + bool UseAlphaChannel = false; + bool DrawBorder = true; + bool ScaleImage = false; + + video::SColor Colors[4]; + // PATCH + bool WasHovered = false; + bool WasFocused = false; + ISimpleTextureSource *TSrc; + + gui::IGUIStaticText *StaticText; + + core::rect BgMiddle; + core::rect Padding; + core::vector2d ContentOffset; + video::SColor BgColor = video::SColor(0xFF,0xFF,0xFF,0xFF); + // END PATCH +}; diff --git a/src/gui/guiSkin.cpp b/src/gui/guiSkin.cpp index 5462a2fec..0ecc80f02 100644 --- a/src/gui/guiSkin.cpp +++ b/src/gui/guiSkin.cpp @@ -1,1037 +1,1037 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// Copyright (C) 2019 Irrlick -// -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "guiSkin.h" - -#include "IGUIFont.h" -#include "IGUISpriteBank.h" -#include "IGUIElement.h" -#include "IVideoDriver.h" -#include "IAttributes.h" - -namespace irr -{ -namespace gui -{ - -GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) -: SpriteBank(0), Driver(driver), Type(type) -{ - #ifdef _DEBUG - setDebugName("GUISkin"); - #endif - - if ((Type == EGST_WINDOWS_CLASSIC) || (Type == EGST_WINDOWS_METALLIC)) - { - Colors[EGDC_3D_DARK_SHADOW] = video::SColor(101,50,50,50); - Colors[EGDC_3D_SHADOW] = video::SColor(101,130,130,130); - Colors[EGDC_3D_FACE] = video::SColor(220,100,100,100); - Colors[EGDC_3D_HIGH_LIGHT] = video::SColor(101,255,255,255); - Colors[EGDC_3D_LIGHT] = video::SColor(101,210,210,210); - Colors[EGDC_ACTIVE_BORDER] = video::SColor(101,16,14,115); - Colors[EGDC_ACTIVE_CAPTION] = video::SColor(255,255,255,255); - Colors[EGDC_APP_WORKSPACE] = video::SColor(101,100,100,100); - Colors[EGDC_BUTTON_TEXT] = video::SColor(240,10,10,10); - Colors[EGDC_GRAY_TEXT] = video::SColor(240,130,130,130); - Colors[EGDC_HIGH_LIGHT] = video::SColor(101,8,36,107); - Colors[EGDC_HIGH_LIGHT_TEXT] = video::SColor(240,255,255,255); - Colors[EGDC_INACTIVE_BORDER] = video::SColor(101,165,165,165); - Colors[EGDC_INACTIVE_CAPTION] = video::SColor(255,30,30,30); - Colors[EGDC_TOOLTIP] = video::SColor(200,0,0,0); - Colors[EGDC_TOOLTIP_BACKGROUND] = video::SColor(200,255,255,225); - Colors[EGDC_SCROLLBAR] = video::SColor(101,230,230,230); - Colors[EGDC_WINDOW] = video::SColor(101,255,255,255); - Colors[EGDC_WINDOW_SYMBOL] = video::SColor(200,10,10,10); - Colors[EGDC_ICON] = video::SColor(200,255,255,255); - Colors[EGDC_ICON_HIGH_LIGHT] = video::SColor(200,8,36,107); - Colors[EGDC_GRAY_WINDOW_SYMBOL] = video::SColor(240,100,100,100); - Colors[EGDC_EDITABLE] = video::SColor(255,255,255,255); - Colors[EGDC_GRAY_EDITABLE] = video::SColor(255,120,120,120); - Colors[EGDC_FOCUSED_EDITABLE] = video::SColor(255,240,240,255); - - - Sizes[EGDS_SCROLLBAR_SIZE] = 14; - Sizes[EGDS_MENU_HEIGHT] = 30; - Sizes[EGDS_WINDOW_BUTTON_WIDTH] = 15; - Sizes[EGDS_CHECK_BOX_WIDTH] = 18; - Sizes[EGDS_MESSAGE_BOX_WIDTH] = 500; - Sizes[EGDS_MESSAGE_BOX_HEIGHT] = 200; - Sizes[EGDS_BUTTON_WIDTH] = 80; - Sizes[EGDS_BUTTON_HEIGHT] = 30; - - Sizes[EGDS_TEXT_DISTANCE_X] = 2; - Sizes[EGDS_TEXT_DISTANCE_Y] = 0; - - Sizes[EGDS_TITLEBARTEXT_DISTANCE_X] = 2; - Sizes[EGDS_TITLEBARTEXT_DISTANCE_Y] = 0; - } - else - { - //0x80a6a8af - Colors[EGDC_3D_DARK_SHADOW] = 0x60767982; - //Colors[EGDC_3D_FACE] = 0xc0c9ccd4; // tab background - Colors[EGDC_3D_FACE] = 0xc0cbd2d9; // tab background - Colors[EGDC_3D_SHADOW] = 0x50e4e8f1; // tab background, and left-top highlight - Colors[EGDC_3D_HIGH_LIGHT] = 0x40c7ccdc; - Colors[EGDC_3D_LIGHT] = 0x802e313a; - Colors[EGDC_ACTIVE_BORDER] = 0x80404040; // window title - Colors[EGDC_ACTIVE_CAPTION] = 0xffd0d0d0; - Colors[EGDC_APP_WORKSPACE] = 0xc0646464; // unused - Colors[EGDC_BUTTON_TEXT] = 0xd0161616; - Colors[EGDC_GRAY_TEXT] = 0x3c141414; - Colors[EGDC_HIGH_LIGHT] = 0x6c606060; - Colors[EGDC_HIGH_LIGHT_TEXT] = 0xd0e0e0e0; - Colors[EGDC_INACTIVE_BORDER] = 0xf0a5a5a5; - Colors[EGDC_INACTIVE_CAPTION] = 0xffd2d2d2; - Colors[EGDC_TOOLTIP] = 0xf00f2033; - Colors[EGDC_TOOLTIP_BACKGROUND] = 0xc0cbd2d9; - Colors[EGDC_SCROLLBAR] = 0xf0e0e0e0; - Colors[EGDC_WINDOW] = 0xf0f0f0f0; - Colors[EGDC_WINDOW_SYMBOL] = 0xd0161616; - Colors[EGDC_ICON] = 0xd0161616; - Colors[EGDC_ICON_HIGH_LIGHT] = 0xd0606060; - Colors[EGDC_GRAY_WINDOW_SYMBOL] = 0x3c101010; - Colors[EGDC_EDITABLE] = 0xf0ffffff; - Colors[EGDC_GRAY_EDITABLE] = 0xf0cccccc; - Colors[EGDC_FOCUSED_EDITABLE] = 0xf0fffff0; - - Sizes[EGDS_SCROLLBAR_SIZE] = 14; - Sizes[EGDS_MENU_HEIGHT] = 48; - Sizes[EGDS_WINDOW_BUTTON_WIDTH] = 15; - Sizes[EGDS_CHECK_BOX_WIDTH] = 18; - Sizes[EGDS_MESSAGE_BOX_WIDTH] = 500; - Sizes[EGDS_MESSAGE_BOX_HEIGHT] = 200; - Sizes[EGDS_BUTTON_WIDTH] = 80; - Sizes[EGDS_BUTTON_HEIGHT] = 30; - - Sizes[EGDS_TEXT_DISTANCE_X] = 3; - Sizes[EGDS_TEXT_DISTANCE_Y] = 2; - - Sizes[EGDS_TITLEBARTEXT_DISTANCE_X] = 3; - Sizes[EGDS_TITLEBARTEXT_DISTANCE_Y] = 2; - } - - Sizes[EGDS_MESSAGE_BOX_GAP_SPACE] = 15; - Sizes[EGDS_MESSAGE_BOX_MIN_TEXT_WIDTH] = 0; - Sizes[EGDS_MESSAGE_BOX_MAX_TEXT_WIDTH] = 500; - Sizes[EGDS_MESSAGE_BOX_MIN_TEXT_HEIGHT] = 0; - Sizes[EGDS_MESSAGE_BOX_MAX_TEXT_HEIGHT] = 99999; - - Sizes[EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X] = 1; - Sizes[EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y] = 1; - Sizes[EGDS_BUTTON_PRESSED_TEXT_OFFSET_X] = 0; - Sizes[EGDS_BUTTON_PRESSED_TEXT_OFFSET_Y] = 2; - - Texts[EGDT_MSG_BOX_OK] = L"OK"; - Texts[EGDT_MSG_BOX_CANCEL] = L"Cancel"; - Texts[EGDT_MSG_BOX_YES] = L"Yes"; - Texts[EGDT_MSG_BOX_NO] = L"No"; - Texts[EGDT_WINDOW_CLOSE] = L"Close"; - Texts[EGDT_WINDOW_RESTORE] = L"Restore"; - Texts[EGDT_WINDOW_MINIMIZE] = L"Minimize"; - Texts[EGDT_WINDOW_MAXIMIZE] = L"Maximize"; - - Icons[EGDI_WINDOW_MAXIMIZE] = 225; - Icons[EGDI_WINDOW_RESTORE] = 226; - Icons[EGDI_WINDOW_CLOSE] = 227; - Icons[EGDI_WINDOW_MINIMIZE] = 228; - Icons[EGDI_CURSOR_UP] = 229; - Icons[EGDI_CURSOR_DOWN] = 230; - Icons[EGDI_CURSOR_LEFT] = 231; - Icons[EGDI_CURSOR_RIGHT] = 232; - Icons[EGDI_MENU_MORE] = 232; - Icons[EGDI_CHECK_BOX_CHECKED] = 233; - Icons[EGDI_DROP_DOWN] = 234; - Icons[EGDI_SMALL_CURSOR_UP] = 235; - Icons[EGDI_SMALL_CURSOR_DOWN] = 236; - Icons[EGDI_RADIO_BUTTON_CHECKED] = 237; - Icons[EGDI_MORE_LEFT] = 238; - Icons[EGDI_MORE_RIGHT] = 239; - Icons[EGDI_MORE_UP] = 240; - Icons[EGDI_MORE_DOWN] = 241; - Icons[EGDI_WINDOW_RESIZE] = 242; - Icons[EGDI_EXPAND] = 243; - Icons[EGDI_COLLAPSE] = 244; - - Icons[EGDI_FILE] = 245; - Icons[EGDI_DIRECTORY] = 246; - - for (u32 i=0; idrop(); - } - - if (SpriteBank) - SpriteBank->drop(); -} - - -//! returns default color -video::SColor GUISkin::getColor(EGUI_DEFAULT_COLOR color) const -{ - if ((u32)color < EGDC_COUNT) - return Colors[color]; - else - return video::SColor(); -} - - -//! sets a default color -void GUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor) -{ - if ((u32)which < EGDC_COUNT) - Colors[which] = newColor; -} - - -//! returns size for the given size type -s32 GUISkin::getSize(EGUI_DEFAULT_SIZE size) const -{ - if ((u32)size < EGDS_COUNT) - return Sizes[size]; - else - return 0; -} - - -//! sets a default size -void GUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size) -{ - if ((u32)which < EGDS_COUNT) - Sizes[which] = size; -} - - -//! returns the default font -IGUIFont* GUISkin::getFont(EGUI_DEFAULT_FONT which) const -{ - if (((u32)which < EGDF_COUNT) && Fonts[which]) - return Fonts[which]; - else - return Fonts[EGDF_DEFAULT]; -} - - -//! sets a default font -void GUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which) -{ - if ((u32)which >= EGDF_COUNT) - return; - - if (font) - { - font->grab(); - if (Fonts[which]) - Fonts[which]->drop(); - - Fonts[which] = font; - } -} - - -//! gets the sprite bank stored -IGUISpriteBank* GUISkin::getSpriteBank() const -{ - return SpriteBank; -} - - -//! set a new sprite bank or remove one by passing 0 -void GUISkin::setSpriteBank(IGUISpriteBank* bank) -{ - if (bank) - bank->grab(); - - if (SpriteBank) - SpriteBank->drop(); - - SpriteBank = bank; -} - - -//! Returns a default icon -u32 GUISkin::getIcon(EGUI_DEFAULT_ICON icon) const -{ - if ((u32)icon < EGDI_COUNT) - return Icons[icon]; - else - return 0; -} - - -//! Sets a default icon -void GUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index) -{ - if ((u32)icon < EGDI_COUNT) - Icons[icon] = index; -} - - -//! Returns a default text. For example for Message box button captions: -//! "OK", "Cancel", "Yes", "No" and so on. -const wchar_t* GUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const -{ - if ((u32)text < EGDT_COUNT) - return Texts[text].c_str(); - else - return Texts[0].c_str(); -} - - -//! Sets a default text. For example for Message box button captions: -//! "OK", "Cancel", "Yes", "No" and so on. -void GUISkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText) -{ - if ((u32)which < EGDT_COUNT) - Texts[which] = newText; -} - - -//! draws a standard 3d button pane -/** Used for drawing for example buttons in normal state. -It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and -EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. -\param rect: Defining area where to draw. -\param clip: Clip area. -\param element: Pointer to the element which wishes to draw this. This parameter -is usually not used by ISkin, but can be used for example by more complex -implementations to find out how to draw the part exactly. */ -// PATCH -void GUISkin::drawColored3DButtonPaneStandard(IGUIElement* element, - const core::rect& r, - const core::rect* clip, - const video::SColor* colors) -{ - if (!Driver) - return; - - if (!colors) - colors = Colors; - - core::rect rect = r; - - if ( Type == EGST_BURNING_SKIN ) - { - rect.UpperLeftCorner.X -= 1; - rect.UpperLeftCorner.Y -= 1; - rect.LowerRightCorner.X += 1; - rect.LowerRightCorner.Y += 1; - draw3DSunkenPane(element, - colors[ EGDC_WINDOW ].getInterpolated( 0xFFFFFFFF, 0.9f ) - ,false, true, rect, clip); - return; - } - - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - - rect.LowerRightCorner.X -= 1; - rect.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); - - rect.UpperLeftCorner.X += 1; - rect.UpperLeftCorner.Y += 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); - - rect.LowerRightCorner.X -= 1; - rect.LowerRightCorner.Y -= 1; - - if (!UseGradient) - { - Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); - } - else - { - const video::SColor c1 = colors[EGDC_3D_FACE]; - const video::SColor c2 = c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f); - Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); - } -} -// END PATCH - - -//! draws a pressed 3d button pane -/** Used for drawing for example buttons in pressed state. -It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and -EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. -\param rect: Defining area where to draw. -\param clip: Clip area. -\param element: Pointer to the element which wishes to draw this. This parameter -is usually not used by ISkin, but can be used for example by more complex -implementations to find out how to draw the part exactly. */ -// PATCH -void GUISkin::drawColored3DButtonPanePressed(IGUIElement* element, - const core::rect& r, - const core::rect* clip, - const video::SColor* colors) -{ - if (!Driver) - return; - - if (!colors) - colors = Colors; - - core::rect rect = r; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); - - rect.LowerRightCorner.X -= 1; - rect.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - - rect.UpperLeftCorner.X += 1; - rect.UpperLeftCorner.Y += 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); - - rect.UpperLeftCorner.X += 1; - rect.UpperLeftCorner.Y += 1; - - if (!UseGradient) - { - Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); - } - else - { - const video::SColor c1 = colors[EGDC_3D_FACE]; - const video::SColor c2 = c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f); - Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); - } -} -// END PATCH - - -//! draws a sunken 3d pane -/** Used for drawing the background of edit, combo or check boxes. -\param element: Pointer to the element which wishes to draw this. This parameter -is usually not used by ISkin, but can be used for example by more complex -implementations to find out how to draw the part exactly. -\param bgcolor: Background color. -\param flat: Specifies if the sunken pane should be flat or displayed as sunken -deep into the ground. -\param rect: Defining area where to draw. -\param clip: Clip area. */ -// PATCH -void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolor, - bool flat, bool fillBackGround, - const core::rect& r, - const core::rect* clip, - const video::SColor* colors) -{ - if (!Driver) - return; - - if (!colors) - colors = Colors; - - core::rect rect = r; - - if (fillBackGround) - Driver->draw2DRectangle(bgcolor, rect, clip); - - if (flat) - { - // draw flat sunken pane - - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top - - ++rect.UpperLeftCorner.Y; - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left - - rect = r; - ++rect.UpperLeftCorner.Y; - rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right - - rect = r; - ++rect.UpperLeftCorner.X; - rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; - --rect.LowerRightCorner.X; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom - } - else - { - // draw deep sunken pane - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top - ++rect.UpperLeftCorner.X; - ++rect.UpperLeftCorner.Y; - --rect.LowerRightCorner.X; - ++rect.LowerRightCorner.Y; - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - - rect.UpperLeftCorner.X = r.UpperLeftCorner.X; - rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y+1; - rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left - ++rect.UpperLeftCorner.X; - ++rect.UpperLeftCorner.Y; - ++rect.LowerRightCorner.X; - --rect.LowerRightCorner.Y; - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - - rect = r; - rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; - ++rect.UpperLeftCorner.Y; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right - --rect.UpperLeftCorner.X; - ++rect.UpperLeftCorner.Y; - --rect.LowerRightCorner.X; - --rect.LowerRightCorner.Y; - Driver->draw2DRectangle(colors[EGDC_3D_LIGHT], rect, clip); - - rect = r; - ++rect.UpperLeftCorner.X; - rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; - --rect.LowerRightCorner.X; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom - ++rect.UpperLeftCorner.X; - --rect.UpperLeftCorner.Y; - --rect.LowerRightCorner.X; - --rect.LowerRightCorner.Y; - Driver->draw2DRectangle(colors[EGDC_3D_LIGHT], rect, clip); - } -} -// END PATCH - -//! draws a window background -// return where to draw title bar text. -// PATCH -core::rect GUISkin::drawColored3DWindowBackground(IGUIElement* element, - bool drawTitleBar, video::SColor titleBarColor, - const core::rect& r, - const core::rect* clip, - core::rect* checkClientArea, - const video::SColor* colors) -{ - if (!Driver) - { - if ( checkClientArea ) - { - *checkClientArea = r; - } - return r; - } - - if (!colors) - colors = Colors; - - core::rect rect = r; - - // top border - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; - if ( !checkClientArea ) - { - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); - } - - // left border - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; - if ( !checkClientArea ) - { - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); - } - - // right border dark outer line - rect.UpperLeftCorner.X = r.LowerRightCorner.X - 1; - rect.LowerRightCorner.X = r.LowerRightCorner.X; - rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y; - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - if ( !checkClientArea ) - { - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - } - - // right border bright innner line - rect.UpperLeftCorner.X -= 1; - rect.LowerRightCorner.X -= 1; - rect.UpperLeftCorner.Y += 1; - rect.LowerRightCorner.Y -= 1; - if ( !checkClientArea ) - { - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); - } - - // bottom border dark outer line - rect.UpperLeftCorner.X = r.UpperLeftCorner.X; - rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - rect.LowerRightCorner.X = r.LowerRightCorner.X; - if ( !checkClientArea ) - { - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - } - - // bottom border bright inner line - rect.UpperLeftCorner.X += 1; - rect.LowerRightCorner.X -= 1; - rect.UpperLeftCorner.Y -= 1; - rect.LowerRightCorner.Y -= 1; - if ( !checkClientArea ) - { - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); - } - - // client area for background - rect = r; - rect.UpperLeftCorner.X +=1; - rect.UpperLeftCorner.Y +=1; - rect.LowerRightCorner.X -= 2; - rect.LowerRightCorner.Y -= 2; - if (checkClientArea) - { - *checkClientArea = rect; - } - - if ( !checkClientArea ) - { - if (!UseGradient) - { - Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); - } - else if ( Type == EGST_BURNING_SKIN ) - { - const video::SColor c1 = colors[EGDC_WINDOW].getInterpolated ( 0xFFFFFFFF, 0.9f ); - const video::SColor c2 = colors[EGDC_WINDOW].getInterpolated ( 0xFFFFFFFF, 0.8f ); - - Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); - } - else - { - const video::SColor c2 = colors[EGDC_3D_SHADOW]; - const video::SColor c1 = colors[EGDC_3D_FACE]; - Driver->draw2DRectangle(rect, c1, c1, c1, c2, clip); - } - } - - // title bar - rect = r; - rect.UpperLeftCorner.X += 2; - rect.UpperLeftCorner.Y += 2; - rect.LowerRightCorner.X -= 2; - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + getSize(EGDS_WINDOW_BUTTON_WIDTH) + 2; - - if (drawTitleBar ) - { - if (checkClientArea) - { - (*checkClientArea).UpperLeftCorner.Y = rect.LowerRightCorner.Y; - } - else - { - // draw title bar - //if (!UseGradient) - // Driver->draw2DRectangle(titleBarColor, rect, clip); - //else - if ( Type == EGST_BURNING_SKIN ) - { - const video::SColor c = titleBarColor.getInterpolated( video::SColor(titleBarColor.getAlpha(),255,255,255), 0.8f); - Driver->draw2DRectangle(rect, titleBarColor, titleBarColor, c, c, clip); - } - else - { - const video::SColor c = titleBarColor.getInterpolated(video::SColor(titleBarColor.getAlpha(),0,0,0), 0.2f); - Driver->draw2DRectangle(rect, titleBarColor, c, titleBarColor, c, clip); - } - } - } - - return rect; -} -// END PATCH - - -//! draws a standard 3d menu pane -/** Used for drawing for menus and context menus. -It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and -EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. -\param element: Pointer to the element which wishes to draw this. This parameter -is usually not used by ISkin, but can be used for example by more complex -implementations to find out how to draw the part exactly. -\param rect: Defining area where to draw. -\param clip: Clip area. */ -// PATCH -void GUISkin::drawColored3DMenuPane(IGUIElement* element, - const core::rect& r, const core::rect* clip, - const video::SColor* colors) -{ - if (!Driver) - return; - - if (!colors) - colors = Colors; - - core::rect rect = r; - - if ( Type == EGST_BURNING_SKIN ) - { - rect.UpperLeftCorner.Y -= 3; - draw3DButtonPaneStandard(element, rect, clip); - return; - } - - // in this skin, this is exactly what non pressed buttons look like, - // so we could simply call - // draw3DButtonPaneStandard(element, rect, clip); - // here. - // but if the skin is transparent, this doesn't look that nice. So - // We draw it a little bit better, with some more draw2DRectangle calls, - // but there aren't that much menus visible anyway. - - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); - - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); - - rect.UpperLeftCorner.X = r.LowerRightCorner.X - 1; - rect.LowerRightCorner.X = r.LowerRightCorner.X; - rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y; - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - - rect.UpperLeftCorner.X -= 1; - rect.LowerRightCorner.X -= 1; - rect.UpperLeftCorner.Y += 1; - rect.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); - - rect.UpperLeftCorner.X = r.UpperLeftCorner.X; - rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - rect.LowerRightCorner.X = r.LowerRightCorner.X; - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); - - rect.UpperLeftCorner.X += 1; - rect.LowerRightCorner.X -= 1; - rect.UpperLeftCorner.Y -= 1; - rect.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); - - rect = r; - rect.UpperLeftCorner.X +=1; - rect.UpperLeftCorner.Y +=1; - rect.LowerRightCorner.X -= 2; - rect.LowerRightCorner.Y -= 2; - - if (!UseGradient) - Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); - else - { - const video::SColor c1 = colors[EGDC_3D_FACE]; - const video::SColor c2 = colors[EGDC_3D_SHADOW]; - Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); - } -} -// END PATCH - - -//! draws a standard 3d tool bar -/** Used for drawing for toolbars and menus. -\param element: Pointer to the element which wishes to draw this. This parameter -is usually not used by ISkin, but can be used for example by more complex -implementations to find out how to draw the part exactly. -\param rect: Defining area where to draw. -\param clip: Clip area. */ -// PATCH -void GUISkin::drawColored3DToolBar(IGUIElement* element, - const core::rect& r, - const core::rect* clip, - const video::SColor* colors) -{ - if (!Driver) - return; - - if (!colors) - colors = Colors; - - core::rect rect = r; - - rect.UpperLeftCorner.X = r.UpperLeftCorner.X; - rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; - rect.LowerRightCorner.Y = r.LowerRightCorner.Y; - rect.LowerRightCorner.X = r.LowerRightCorner.X; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); - - rect = r; - rect.LowerRightCorner.Y -= 1; - - if (!UseGradient) - { - Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); - } - else - if ( Type == EGST_BURNING_SKIN ) - { - const video::SColor c1 = 0xF0000000 | colors[EGDC_3D_FACE].color; - const video::SColor c2 = 0xF0000000 | colors[EGDC_3D_SHADOW].color; - - rect.LowerRightCorner.Y += 1; - Driver->draw2DRectangle(rect, c1, c2, c1, c2, clip); - } - else - { - const video::SColor c1 = colors[EGDC_3D_FACE]; - const video::SColor c2 = colors[EGDC_3D_SHADOW]; - Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); - } -} -// END PATCH - -//! draws a tab button -/** Used for drawing for tab buttons on top of tabs. -\param element: Pointer to the element which wishes to draw this. This parameter -is usually not used by ISkin, but can be used for example by more complex -implementations to find out how to draw the part exactly. -\param active: Specifies if the tab is currently active. -\param rect: Defining area where to draw. -\param clip: Clip area. */ -// PATCH -void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, - const core::rect& frameRect, const core::rect* clip, EGUI_ALIGNMENT alignment, - const video::SColor* colors) -{ - if (!Driver) - return; - - if (!colors) - colors = Colors; - - core::rect tr = frameRect; - - if ( alignment == EGUIA_UPPERLEFT ) - { - tr.LowerRightCorner.X -= 2; - tr.LowerRightCorner.Y = tr.UpperLeftCorner.Y + 1; - tr.UpperLeftCorner.X += 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); - - // draw left highlight - tr = frameRect; - tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; - tr.UpperLeftCorner.Y += 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); - - // draw grey background - tr = frameRect; - tr.UpperLeftCorner.X += 1; - tr.UpperLeftCorner.Y += 1; - tr.LowerRightCorner.X -= 2; - Driver->draw2DRectangle(colors[EGDC_3D_FACE], tr, clip); - - // draw right middle gray shadow - tr.LowerRightCorner.X += 1; - tr.UpperLeftCorner.X = tr.LowerRightCorner.X - 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); - - tr.LowerRightCorner.X += 1; - tr.UpperLeftCorner.X += 1; - tr.UpperLeftCorner.Y += 1; - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], tr, clip); - } - else - { - tr.LowerRightCorner.X -= 2; - tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1; - tr.UpperLeftCorner.X += 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); - - // draw left highlight - tr = frameRect; - tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; - tr.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); - - // draw grey background - tr = frameRect; - tr.UpperLeftCorner.X += 1; - tr.UpperLeftCorner.Y -= 1; - tr.LowerRightCorner.X -= 2; - tr.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_FACE], tr, clip); - - // draw right middle gray shadow - tr.LowerRightCorner.X += 1; - tr.UpperLeftCorner.X = tr.LowerRightCorner.X - 1; - //tr.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); - - tr.LowerRightCorner.X += 1; - tr.UpperLeftCorner.X += 1; - tr.LowerRightCorner.Y -= 1; - Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], tr, clip); - } -} -// END PATCH - - -//! draws a tab control body -/** \param element: Pointer to the element which wishes to draw this. This parameter -is usually not used by ISkin, but can be used for example by more complex -implementations to find out how to draw the part exactly. -\param border: Specifies if the border should be drawn. -\param background: Specifies if the background should be drawn. -\param rect: Defining area where to draw. -\param clip: Clip area. */ -// PATCH -void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool background, - const core::rect& rect, const core::rect* clip, s32 tabHeight, EGUI_ALIGNMENT alignment, - const video::SColor* colors) -{ - if (!Driver) - return; - - if (!colors) - colors = Colors; - - core::rect tr = rect; - - if ( tabHeight == -1 ) - tabHeight = getSize(gui::EGDS_BUTTON_HEIGHT); - - // draw border. - if (border) - { - if ( alignment == EGUIA_UPPERLEFT ) - { - // draw left hightlight - tr.UpperLeftCorner.Y += tabHeight + 2; - tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); - - // draw right shadow - tr.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; - tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); - - // draw lower shadow - tr = rect; - tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); - } - else - { - // draw left hightlight - tr.LowerRightCorner.Y -= tabHeight + 2; - tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); - - // draw right shadow - tr.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; - tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; - Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); - - // draw lower shadow - tr = rect; - tr.LowerRightCorner.Y = tr.UpperLeftCorner.Y + 1; - Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); - } - } - - if (background) - { - if ( alignment == EGUIA_UPPERLEFT ) - { - tr = rect; - tr.UpperLeftCorner.Y += tabHeight + 2; - tr.LowerRightCorner.X -= 1; - tr.UpperLeftCorner.X += 1; - tr.LowerRightCorner.Y -= 1; - } - else - { - tr = rect; - tr.UpperLeftCorner.X += 1; - tr.UpperLeftCorner.Y -= 1; - tr.LowerRightCorner.X -= 1; - tr.LowerRightCorner.Y -= tabHeight + 2; - //tr.UpperLeftCorner.X += 1; - } - - if (!UseGradient) - Driver->draw2DRectangle(colors[EGDC_3D_FACE], tr, clip); - else - { - video::SColor c1 = colors[EGDC_3D_FACE]; - video::SColor c2 = colors[EGDC_3D_SHADOW]; - Driver->draw2DRectangle(tr, c1, c1, c2, c2, clip); - } - } -} -// END PATCH - - -//! draws an icon, usually from the skin's sprite bank -/** \param parent: Pointer to the element which wishes to draw this icon. -This parameter is usually not used by IGUISkin, but can be used for example -by more complex implementations to find out how to draw the part exactly. -\param icon: Specifies the icon to be drawn. -\param position: The position to draw the icon -\param starttime: The time at the start of the animation -\param currenttime: The present time, used to calculate the frame number -\param loop: Whether the animation should loop or not -\param clip: Clip area. */ -// PATCH -void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, - const core::position2di position, - u32 starttime, u32 currenttime, - bool loop, const core::rect* clip, - const video::SColor* colors) -{ - if (!SpriteBank) - return; - - if (!colors) - colors = Colors; - - bool gray = element && !element->isEnabled(); - SpriteBank->draw2DSprite(Icons[icon], position, clip, - colors[gray? EGDC_GRAY_WINDOW_SYMBOL : EGDC_WINDOW_SYMBOL], starttime, currenttime, loop, true); -} -// END PATCH - - -EGUI_SKIN_TYPE GUISkin::getType() const -{ - return Type; -} - - -//! draws a 2d rectangle. -void GUISkin::draw2DRectangle(IGUIElement* element, - const video::SColor &color, const core::rect& pos, - const core::rect* clip) -{ - Driver->draw2DRectangle(color, pos, clip); -} - - -//! gets the colors -// PATCH -void GUISkin::getColors(video::SColor* colors) -{ - u32 i; - for (i=0; idrop(); + } + + if (SpriteBank) + SpriteBank->drop(); +} + + +//! returns default color +video::SColor GUISkin::getColor(EGUI_DEFAULT_COLOR color) const +{ + if ((u32)color < EGDC_COUNT) + return Colors[color]; + else + return video::SColor(); +} + + +//! sets a default color +void GUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor) +{ + if ((u32)which < EGDC_COUNT) + Colors[which] = newColor; +} + + +//! returns size for the given size type +s32 GUISkin::getSize(EGUI_DEFAULT_SIZE size) const +{ + if ((u32)size < EGDS_COUNT) + return Sizes[size]; + else + return 0; +} + + +//! sets a default size +void GUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size) +{ + if ((u32)which < EGDS_COUNT) + Sizes[which] = size; +} + + +//! returns the default font +IGUIFont* GUISkin::getFont(EGUI_DEFAULT_FONT which) const +{ + if (((u32)which < EGDF_COUNT) && Fonts[which]) + return Fonts[which]; + else + return Fonts[EGDF_DEFAULT]; +} + + +//! sets a default font +void GUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which) +{ + if ((u32)which >= EGDF_COUNT) + return; + + if (font) + { + font->grab(); + if (Fonts[which]) + Fonts[which]->drop(); + + Fonts[which] = font; + } +} + + +//! gets the sprite bank stored +IGUISpriteBank* GUISkin::getSpriteBank() const +{ + return SpriteBank; +} + + +//! set a new sprite bank or remove one by passing 0 +void GUISkin::setSpriteBank(IGUISpriteBank* bank) +{ + if (bank) + bank->grab(); + + if (SpriteBank) + SpriteBank->drop(); + + SpriteBank = bank; +} + + +//! Returns a default icon +u32 GUISkin::getIcon(EGUI_DEFAULT_ICON icon) const +{ + if ((u32)icon < EGDI_COUNT) + return Icons[icon]; + else + return 0; +} + + +//! Sets a default icon +void GUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index) +{ + if ((u32)icon < EGDI_COUNT) + Icons[icon] = index; +} + + +//! Returns a default text. For example for Message box button captions: +//! "OK", "Cancel", "Yes", "No" and so on. +const wchar_t* GUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const +{ + if ((u32)text < EGDT_COUNT) + return Texts[text].c_str(); + else + return Texts[0].c_str(); +} + + +//! Sets a default text. For example for Message box button captions: +//! "OK", "Cancel", "Yes", "No" and so on. +void GUISkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText) +{ + if ((u32)which < EGDT_COUNT) + Texts[which] = newText; +} + + +//! draws a standard 3d button pane +/** Used for drawing for example buttons in normal state. +It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and +EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. +\param rect: Defining area where to draw. +\param clip: Clip area. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. */ +// PATCH +void GUISkin::drawColored3DButtonPaneStandard(IGUIElement* element, + const core::rect& r, + const core::rect* clip, + const video::SColor* colors) +{ + if (!Driver) + return; + + if (!colors) + colors = Colors; + + core::rect rect = r; + + if ( Type == EGST_BURNING_SKIN ) + { + rect.UpperLeftCorner.X -= 1; + rect.UpperLeftCorner.Y -= 1; + rect.LowerRightCorner.X += 1; + rect.LowerRightCorner.Y += 1; + draw3DSunkenPane(element, + colors[ EGDC_WINDOW ].getInterpolated( 0xFFFFFFFF, 0.9f ) + ,false, true, rect, clip); + return; + } + + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + + rect.LowerRightCorner.X -= 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); + + rect.LowerRightCorner.X -= 1; + rect.LowerRightCorner.Y -= 1; + + if (!UseGradient) + { + Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); + } + else + { + const video::SColor c1 = colors[EGDC_3D_FACE]; + const video::SColor c2 = c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f); + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} +// END PATCH + + +//! draws a pressed 3d button pane +/** Used for drawing for example buttons in pressed state. +It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and +EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. +\param rect: Defining area where to draw. +\param clip: Clip area. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. */ +// PATCH +void GUISkin::drawColored3DButtonPanePressed(IGUIElement* element, + const core::rect& r, + const core::rect* clip, + const video::SColor* colors) +{ + if (!Driver) + return; + + if (!colors) + colors = Colors; + + core::rect rect = r; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); + + rect.LowerRightCorner.X -= 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.UpperLeftCorner.Y += 1; + + if (!UseGradient) + { + Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); + } + else + { + const video::SColor c1 = colors[EGDC_3D_FACE]; + const video::SColor c2 = c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f); + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} +// END PATCH + + +//! draws a sunken 3d pane +/** Used for drawing the background of edit, combo or check boxes. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param bgcolor: Background color. +\param flat: Specifies if the sunken pane should be flat or displayed as sunken +deep into the ground. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +// PATCH +void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolor, + bool flat, bool fillBackGround, + const core::rect& r, + const core::rect* clip, + const video::SColor* colors) +{ + if (!Driver) + return; + + if (!colors) + colors = Colors; + + core::rect rect = r; + + if (fillBackGround) + Driver->draw2DRectangle(bgcolor, rect, clip); + + if (flat) + { + // draw flat sunken pane + + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top + + ++rect.UpperLeftCorner.Y; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left + + rect = r; + ++rect.UpperLeftCorner.Y; + rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right + + rect = r; + ++rect.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + --rect.LowerRightCorner.X; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom + } + else + { + // draw deep sunken pane + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top + ++rect.UpperLeftCorner.X; + ++rect.UpperLeftCorner.Y; + --rect.LowerRightCorner.X; + ++rect.LowerRightCorner.Y; + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y+1; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left + ++rect.UpperLeftCorner.X; + ++rect.UpperLeftCorner.Y; + ++rect.LowerRightCorner.X; + --rect.LowerRightCorner.Y; + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + + rect = r; + rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + ++rect.UpperLeftCorner.Y; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right + --rect.UpperLeftCorner.X; + ++rect.UpperLeftCorner.Y; + --rect.LowerRightCorner.X; + --rect.LowerRightCorner.Y; + Driver->draw2DRectangle(colors[EGDC_3D_LIGHT], rect, clip); + + rect = r; + ++rect.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + --rect.LowerRightCorner.X; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom + ++rect.UpperLeftCorner.X; + --rect.UpperLeftCorner.Y; + --rect.LowerRightCorner.X; + --rect.LowerRightCorner.Y; + Driver->draw2DRectangle(colors[EGDC_3D_LIGHT], rect, clip); + } +} +// END PATCH + +//! draws a window background +// return where to draw title bar text. +// PATCH +core::rect GUISkin::drawColored3DWindowBackground(IGUIElement* element, + bool drawTitleBar, video::SColor titleBarColor, + const core::rect& r, + const core::rect* clip, + core::rect* checkClientArea, + const video::SColor* colors) +{ + if (!Driver) + { + if ( checkClientArea ) + { + *checkClientArea = r; + } + return r; + } + + if (!colors) + colors = Colors; + + core::rect rect = r; + + // top border + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + if ( !checkClientArea ) + { + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); + } + + // left border + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + if ( !checkClientArea ) + { + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); + } + + // right border dark outer line + rect.UpperLeftCorner.X = r.LowerRightCorner.X - 1; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + if ( !checkClientArea ) + { + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + } + + // right border bright innner line + rect.UpperLeftCorner.X -= 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y += 1; + rect.LowerRightCorner.Y -= 1; + if ( !checkClientArea ) + { + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); + } + + // bottom border dark outer line + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + if ( !checkClientArea ) + { + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + } + + // bottom border bright inner line + rect.UpperLeftCorner.X += 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y -= 1; + rect.LowerRightCorner.Y -= 1; + if ( !checkClientArea ) + { + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); + } + + // client area for background + rect = r; + rect.UpperLeftCorner.X +=1; + rect.UpperLeftCorner.Y +=1; + rect.LowerRightCorner.X -= 2; + rect.LowerRightCorner.Y -= 2; + if (checkClientArea) + { + *checkClientArea = rect; + } + + if ( !checkClientArea ) + { + if (!UseGradient) + { + Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); + } + else if ( Type == EGST_BURNING_SKIN ) + { + const video::SColor c1 = colors[EGDC_WINDOW].getInterpolated ( 0xFFFFFFFF, 0.9f ); + const video::SColor c2 = colors[EGDC_WINDOW].getInterpolated ( 0xFFFFFFFF, 0.8f ); + + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } + else + { + const video::SColor c2 = colors[EGDC_3D_SHADOW]; + const video::SColor c1 = colors[EGDC_3D_FACE]; + Driver->draw2DRectangle(rect, c1, c1, c1, c2, clip); + } + } + + // title bar + rect = r; + rect.UpperLeftCorner.X += 2; + rect.UpperLeftCorner.Y += 2; + rect.LowerRightCorner.X -= 2; + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + getSize(EGDS_WINDOW_BUTTON_WIDTH) + 2; + + if (drawTitleBar ) + { + if (checkClientArea) + { + (*checkClientArea).UpperLeftCorner.Y = rect.LowerRightCorner.Y; + } + else + { + // draw title bar + //if (!UseGradient) + // Driver->draw2DRectangle(titleBarColor, rect, clip); + //else + if ( Type == EGST_BURNING_SKIN ) + { + const video::SColor c = titleBarColor.getInterpolated( video::SColor(titleBarColor.getAlpha(),255,255,255), 0.8f); + Driver->draw2DRectangle(rect, titleBarColor, titleBarColor, c, c, clip); + } + else + { + const video::SColor c = titleBarColor.getInterpolated(video::SColor(titleBarColor.getAlpha(),0,0,0), 0.2f); + Driver->draw2DRectangle(rect, titleBarColor, c, titleBarColor, c, clip); + } + } + } + + return rect; +} +// END PATCH + + +//! draws a standard 3d menu pane +/** Used for drawing for menus and context menus. +It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and +EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +// PATCH +void GUISkin::drawColored3DMenuPane(IGUIElement* element, + const core::rect& r, const core::rect* clip, + const video::SColor* colors) +{ + if (!Driver) + return; + + if (!colors) + colors = Colors; + + core::rect rect = r; + + if ( Type == EGST_BURNING_SKIN ) + { + rect.UpperLeftCorner.Y -= 3; + draw3DButtonPaneStandard(element, rect, clip); + return; + } + + // in this skin, this is exactly what non pressed buttons look like, + // so we could simply call + // draw3DButtonPaneStandard(element, rect, clip); + // here. + // but if the skin is transparent, this doesn't look that nice. So + // We draw it a little bit better, with some more draw2DRectangle calls, + // but there aren't that much menus visible anyway. + + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); + + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); + + rect.UpperLeftCorner.X = r.LowerRightCorner.X - 1; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + + rect.UpperLeftCorner.X -= 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y += 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); + + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip); + + rect.UpperLeftCorner.X += 1; + rect.LowerRightCorner.X -= 1; + rect.UpperLeftCorner.Y -= 1; + rect.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); + + rect = r; + rect.UpperLeftCorner.X +=1; + rect.UpperLeftCorner.Y +=1; + rect.LowerRightCorner.X -= 2; + rect.LowerRightCorner.Y -= 2; + + if (!UseGradient) + Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); + else + { + const video::SColor c1 = colors[EGDC_3D_FACE]; + const video::SColor c2 = colors[EGDC_3D_SHADOW]; + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} +// END PATCH + + +//! draws a standard 3d tool bar +/** Used for drawing for toolbars and menus. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +// PATCH +void GUISkin::drawColored3DToolBar(IGUIElement* element, + const core::rect& r, + const core::rect* clip, + const video::SColor* colors) +{ + if (!Driver) + return; + + if (!colors) + colors = Colors; + + core::rect rect = r; + + rect.UpperLeftCorner.X = r.UpperLeftCorner.X; + rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1; + rect.LowerRightCorner.Y = r.LowerRightCorner.Y; + rect.LowerRightCorner.X = r.LowerRightCorner.X; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); + + rect = r; + rect.LowerRightCorner.Y -= 1; + + if (!UseGradient) + { + Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip); + } + else + if ( Type == EGST_BURNING_SKIN ) + { + const video::SColor c1 = 0xF0000000 | colors[EGDC_3D_FACE].color; + const video::SColor c2 = 0xF0000000 | colors[EGDC_3D_SHADOW].color; + + rect.LowerRightCorner.Y += 1; + Driver->draw2DRectangle(rect, c1, c2, c1, c2, clip); + } + else + { + const video::SColor c1 = colors[EGDC_3D_FACE]; + const video::SColor c2 = colors[EGDC_3D_SHADOW]; + Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip); + } +} +// END PATCH + +//! draws a tab button +/** Used for drawing for tab buttons on top of tabs. +\param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param active: Specifies if the tab is currently active. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +// PATCH +void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, + const core::rect& frameRect, const core::rect* clip, EGUI_ALIGNMENT alignment, + const video::SColor* colors) +{ + if (!Driver) + return; + + if (!colors) + colors = Colors; + + core::rect tr = frameRect; + + if ( alignment == EGUIA_UPPERLEFT ) + { + tr.LowerRightCorner.X -= 2; + tr.LowerRightCorner.Y = tr.UpperLeftCorner.Y + 1; + tr.UpperLeftCorner.X += 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); + + // draw left highlight + tr = frameRect; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + tr.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); + + // draw grey background + tr = frameRect; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y += 1; + tr.LowerRightCorner.X -= 2; + Driver->draw2DRectangle(colors[EGDC_3D_FACE], tr, clip); + + // draw right middle gray shadow + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X = tr.LowerRightCorner.X - 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); + + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y += 1; + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], tr, clip); + } + else + { + tr.LowerRightCorner.X -= 2; + tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1; + tr.UpperLeftCorner.X += 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); + + // draw left highlight + tr = frameRect; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); + + // draw grey background + tr = frameRect; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y -= 1; + tr.LowerRightCorner.X -= 2; + tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_FACE], tr, clip); + + // draw right middle gray shadow + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X = tr.LowerRightCorner.X - 1; + //tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); + + tr.LowerRightCorner.X += 1; + tr.UpperLeftCorner.X += 1; + tr.LowerRightCorner.Y -= 1; + Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], tr, clip); + } +} +// END PATCH + + +//! draws a tab control body +/** \param element: Pointer to the element which wishes to draw this. This parameter +is usually not used by ISkin, but can be used for example by more complex +implementations to find out how to draw the part exactly. +\param border: Specifies if the border should be drawn. +\param background: Specifies if the background should be drawn. +\param rect: Defining area where to draw. +\param clip: Clip area. */ +// PATCH +void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool background, + const core::rect& rect, const core::rect* clip, s32 tabHeight, EGUI_ALIGNMENT alignment, + const video::SColor* colors) +{ + if (!Driver) + return; + + if (!colors) + colors = Colors; + + core::rect tr = rect; + + if ( tabHeight == -1 ) + tabHeight = getSize(gui::EGDS_BUTTON_HEIGHT); + + // draw border. + if (border) + { + if ( alignment == EGUIA_UPPERLEFT ) + { + // draw left hightlight + tr.UpperLeftCorner.Y += tabHeight + 2; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); + + // draw right shadow + tr.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); + + // draw lower shadow + tr = rect; + tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); + } + else + { + // draw left hightlight + tr.LowerRightCorner.Y -= tabHeight + 2; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); + + // draw right shadow + tr.UpperLeftCorner.X = rect.LowerRightCorner.X - 1; + tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1; + Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip); + + // draw lower shadow + tr = rect; + tr.LowerRightCorner.Y = tr.UpperLeftCorner.Y + 1; + Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], tr, clip); + } + } + + if (background) + { + if ( alignment == EGUIA_UPPERLEFT ) + { + tr = rect; + tr.UpperLeftCorner.Y += tabHeight + 2; + tr.LowerRightCorner.X -= 1; + tr.UpperLeftCorner.X += 1; + tr.LowerRightCorner.Y -= 1; + } + else + { + tr = rect; + tr.UpperLeftCorner.X += 1; + tr.UpperLeftCorner.Y -= 1; + tr.LowerRightCorner.X -= 1; + tr.LowerRightCorner.Y -= tabHeight + 2; + //tr.UpperLeftCorner.X += 1; + } + + if (!UseGradient) + Driver->draw2DRectangle(colors[EGDC_3D_FACE], tr, clip); + else + { + video::SColor c1 = colors[EGDC_3D_FACE]; + video::SColor c2 = colors[EGDC_3D_SHADOW]; + Driver->draw2DRectangle(tr, c1, c1, c2, c2, clip); + } + } +} +// END PATCH + + +//! draws an icon, usually from the skin's sprite bank +/** \param parent: Pointer to the element which wishes to draw this icon. +This parameter is usually not used by IGUISkin, but can be used for example +by more complex implementations to find out how to draw the part exactly. +\param icon: Specifies the icon to be drawn. +\param position: The position to draw the icon +\param starttime: The time at the start of the animation +\param currenttime: The present time, used to calculate the frame number +\param loop: Whether the animation should loop or not +\param clip: Clip area. */ +// PATCH +void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, + const core::position2di position, + u32 starttime, u32 currenttime, + bool loop, const core::rect* clip, + const video::SColor* colors) +{ + if (!SpriteBank) + return; + + if (!colors) + colors = Colors; + + bool gray = element && !element->isEnabled(); + SpriteBank->draw2DSprite(Icons[icon], position, clip, + colors[gray? EGDC_GRAY_WINDOW_SYMBOL : EGDC_WINDOW_SYMBOL], starttime, currenttime, loop, true); +} +// END PATCH + + +EGUI_SKIN_TYPE GUISkin::getType() const +{ + return Type; +} + + +//! draws a 2d rectangle. +void GUISkin::draw2DRectangle(IGUIElement* element, + const video::SColor &color, const core::rect& pos, + const core::rect* clip) +{ + Driver->draw2DRectangle(color, pos, clip); +} + + +//! gets the colors +// PATCH +void GUISkin::getColors(video::SColor* colors) +{ + u32 i; + for (i=0; i -#include "ITexture.h" - -namespace irr -{ -namespace video -{ - class IVideoDriver; -} -namespace gui -{ - class GUISkin : public IGUISkin - { - public: - - GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver); - - //! destructor - virtual ~GUISkin(); - - //! returns default color - virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const; - - //! sets a default color - virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor); - - //! returns size for the given size type - virtual s32 getSize(EGUI_DEFAULT_SIZE size) const; - - //! sets a default size - virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size); - - //! returns the default font - virtual IGUIFont* getFont(EGUI_DEFAULT_FONT which=EGDF_DEFAULT) const; - - //! sets a default font - virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT); - - //! sets the sprite bank used for drawing icons - virtual void setSpriteBank(IGUISpriteBank* bank); - - //! gets the sprite bank used for drawing icons - virtual IGUISpriteBank* getSpriteBank() const; - - //! Returns a default icon - /** Returns the sprite index within the sprite bank */ - virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const; - - //! Sets a default icon - /** Sets the sprite index used for drawing icons like arrows, - close buttons and ticks in checkboxes - \param icon: Enum specifying which icon to change - \param index: The sprite index used to draw this icon */ - virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index); - - //! Returns a default text. - /** For example for Message box button captions: - "OK", "Cancel", "Yes", "No" and so on. */ - virtual const wchar_t* getDefaultText(EGUI_DEFAULT_TEXT text) const; - - //! Sets a default text. - /** For example for Message box button captions: - "OK", "Cancel", "Yes", "No" and so on. */ - virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText); - - //! draws a standard 3d button pane - /** Used for drawing for example buttons in normal state. - It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and - EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. - \param rect: Defining area where to draw. - \param clip: Clip area. - \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. */ - virtual void draw3DButtonPaneStandard(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0) - { - drawColored3DButtonPaneStandard(element, rect,clip); - } - - virtual void drawColored3DButtonPaneStandard(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0, - const video::SColor* colors=0); - - //! draws a pressed 3d button pane - /** Used for drawing for example buttons in pressed state. - It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and - EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. - \param rect: Defining area where to draw. - \param clip: Clip area. - \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. */ - virtual void draw3DButtonPanePressed(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0) - { - drawColored3DButtonPanePressed(element, rect, clip); - } - - virtual void drawColored3DButtonPanePressed(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0, - const video::SColor* colors=0); - - //! draws a sunken 3d pane - /** Used for drawing the background of edit, combo or check boxes. - \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. - \param bgcolor: Background color. - \param flat: Specifies if the sunken pane should be flat or displayed as sunken - deep into the ground. - \param rect: Defining area where to draw. - \param clip: Clip area. */ - virtual void draw3DSunkenPane(IGUIElement* element, - video::SColor bgcolor, bool flat, - bool fillBackGround, - const core::rect& rect, - const core::rect* clip=0) - { - drawColored3DSunkenPane(element, bgcolor, flat, fillBackGround, rect, clip); - } - - virtual void drawColored3DSunkenPane(IGUIElement* element, - video::SColor bgcolor, bool flat, - bool fillBackGround, - const core::rect& rect, - const core::rect* clip=0, - const video::SColor* colors=0); - - //! draws a window background - /** Used for drawing the background of dialogs and windows. - \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. - \param titleBarColor: Title color. - \param drawTitleBar: True to enable title drawing. - \param rect: Defining area where to draw. - \param clip: Clip area. - \param checkClientArea: When set to non-null the function will not draw anything, - but will instead return the clientArea which can be used for drawing by the calling window. - That is the area without borders and without titlebar. - \return Returns rect where it would be good to draw title bar text. This will - work even when checkClientArea is set to a non-null value.*/ - virtual core::rect draw3DWindowBackground(IGUIElement* element, - bool drawTitleBar, video::SColor titleBarColor, - const core::rect& rect, - const core::rect* clip, - core::rect* checkClientArea) - { - return drawColored3DWindowBackground(element, drawTitleBar, titleBarColor, - rect, clip, checkClientArea); - } - - virtual core::rect drawColored3DWindowBackground(IGUIElement* element, - bool drawTitleBar, video::SColor titleBarColor, - const core::rect& rect, - const core::rect* clip, - core::rect* checkClientArea, - const video::SColor* colors=0); - - //! draws a standard 3d menu pane - /** Used for drawing for menus and context menus. - It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and - EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. - \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. - \param rect: Defining area where to draw. - \param clip: Clip area. */ - virtual void draw3DMenuPane(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0) - { - drawColored3DMenuPane(element, rect, clip); - } - - virtual void drawColored3DMenuPane(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0, - const video::SColor* colors=0); - - //! draws a standard 3d tool bar - /** Used for drawing for toolbars and menus. - \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. - \param rect: Defining area where to draw. - \param clip: Clip area. */ - virtual void draw3DToolBar(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0) - { - drawColored3DToolBar(element, rect, clip); - } - - virtual void drawColored3DToolBar(IGUIElement* element, - const core::rect& rect, - const core::rect* clip=0, - const video::SColor* colors=0); - - //! draws a tab button - /** Used for drawing for tab buttons on top of tabs. - \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. - \param active: Specifies if the tab is currently active. - \param rect: Defining area where to draw. - \param clip: Clip area. */ - virtual void draw3DTabButton(IGUIElement* element, bool active, - const core::rect& rect, const core::rect* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT) - { - drawColored3DTabButton(element, active, rect, clip, alignment); - } - - virtual void drawColored3DTabButton(IGUIElement* element, bool active, - const core::rect& rect, const core::rect* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT, - const video::SColor* colors=0); - - //! draws a tab control body - /** \param element: Pointer to the element which wishes to draw this. This parameter - is usually not used by ISkin, but can be used for example by more complex - implementations to find out how to draw the part exactly. - \param border: Specifies if the border should be drawn. - \param background: Specifies if the background should be drawn. - \param rect: Defining area where to draw. - \param clip: Clip area. */ - virtual void draw3DTabBody(IGUIElement* element, bool border, bool background, - const core::rect& rect, const core::rect* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT) - { - drawColored3DTabBody(element, border, background, rect, clip, tabHeight, alignment); - } - - virtual void drawColored3DTabBody(IGUIElement* element, bool border, bool background, - const core::rect& rect, const core::rect* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT, - const video::SColor* colors=0); - - //! draws an icon, usually from the skin's sprite bank - /** \param element: Pointer to the element which wishes to draw this icon. - This parameter is usually not used by IGUISkin, but can be used for example - by more complex implementations to find out how to draw the part exactly. - \param icon: Specifies the icon to be drawn. - \param position: The position to draw the icon - \param starttime: The time at the start of the animation - \param currenttime: The present time, used to calculate the frame number - \param loop: Whether the animation should loop or not - \param clip: Clip area. */ - virtual void drawIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, - const core::position2di position, - u32 starttime=0, u32 currenttime=0, - bool loop=false, const core::rect* clip=0) - { - drawColoredIcon(element, icon, position, starttime, currenttime, loop, clip); - } - - virtual void drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, - const core::position2di position, - u32 starttime=0, u32 currenttime=0, - bool loop=false, const core::rect* clip=0, - const video::SColor* colors=0); - - //! draws a 2d rectangle. - /** \param element: Pointer to the element which wishes to draw this icon. - This parameter is usually not used by IGUISkin, but can be used for example - by more complex implementations to find out how to draw the part exactly. - \param color: Color of the rectangle to draw. The alpha component specifies how - transparent the rectangle will be. - \param pos: Position of the rectangle. - \param clip: Pointer to rectangle against which the rectangle will be clipped. - If the pointer is null, no clipping will be performed. */ - virtual void draw2DRectangle(IGUIElement* element, const video::SColor &color, - const core::rect& pos, const core::rect* clip = 0); - - - //! get the type of this skin - virtual EGUI_SKIN_TYPE getType() const; - - //! gets the colors - virtual void getColors(video::SColor* colors); // ::PATCH: - - private: - - video::SColor Colors[EGDC_COUNT]; - s32 Sizes[EGDS_COUNT]; - u32 Icons[EGDI_COUNT]; - IGUIFont* Fonts[EGDF_COUNT]; - IGUISpriteBank* SpriteBank; - core::stringw Texts[EGDT_COUNT]; - video::IVideoDriver* Driver; - bool UseGradient; - - EGUI_SKIN_TYPE Type; - }; - - #define set3DSkinColors(skin, button_color) \ - { \ - skin->setColor(EGDC_3D_FACE, button_color); \ - skin->setColor(EGDC_3D_DARK_SHADOW, button_color, 0.25f); \ - skin->setColor(EGDC_3D_SHADOW, button_color, 0.5f); \ - skin->setColor(EGDC_3D_LIGHT, button_color); \ - skin->setColor(EGDC_3D_HIGH_LIGHT, button_color, 1.5f); \ - } - - #define getElementSkinColor(color) \ - { \ - if (!Colors) \ - { \ - IGUISkin* skin = Environment->getSkin(); \ - if (skin) \ - return skin->getColor(color); \ - } \ - return Colors[color]; \ - } - - #define setElementSkinColor(which, newColor, shading) \ - { \ - if (!Colors) \ - { \ - Colors = new video::SColor[EGDC_COUNT]; \ - GUISkin* skin = (GUISkin *)Environment->getSkin(); \ - if (skin) \ - skin->getColors(Colors); \ - } \ - Colors[which] = newColor; \ - setShading(Colors[which],shading); \ - } -} // end namespace gui -//! Sets the shading -inline void setShading(video::SColor &color,f32 s) // :PATCH: -{ - if (s < 1.0f) - { - color.setRed(color.getRed() * s); - color.setGreen(color.getGreen() * s); - color.setBlue(color.getBlue() * s); - } - else if (s > 1.0f) - { - s -= 1.0f; - - color.setRed(color.getRed() + (255 - color.getRed()) * s); - color.setGreen(color.getGreen() + (255 - color.getGreen()) * s); - color.setBlue(color.getBlue() + (255 - color.getBlue()) * s); - } -} -} // end namespace irr - -#endif +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#ifndef __GUI_SKIN_H_INCLUDED__ +#define __GUI_SKIN_H_INCLUDED__ + +#include "IGUISkin.h" +#include "irrString.h" +#include +#include "ITexture.h" + +namespace irr +{ +namespace video +{ + class IVideoDriver; +} +namespace gui +{ + class GUISkin : public IGUISkin + { + public: + + GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver); + + //! destructor + virtual ~GUISkin(); + + //! returns default color + virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const; + + //! sets a default color + virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor); + + //! returns size for the given size type + virtual s32 getSize(EGUI_DEFAULT_SIZE size) const; + + //! sets a default size + virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size); + + //! returns the default font + virtual IGUIFont* getFont(EGUI_DEFAULT_FONT which=EGDF_DEFAULT) const; + + //! sets a default font + virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT); + + //! sets the sprite bank used for drawing icons + virtual void setSpriteBank(IGUISpriteBank* bank); + + //! gets the sprite bank used for drawing icons + virtual IGUISpriteBank* getSpriteBank() const; + + //! Returns a default icon + /** Returns the sprite index within the sprite bank */ + virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const; + + //! Sets a default icon + /** Sets the sprite index used for drawing icons like arrows, + close buttons and ticks in checkboxes + \param icon: Enum specifying which icon to change + \param index: The sprite index used to draw this icon */ + virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index); + + //! Returns a default text. + /** For example for Message box button captions: + "OK", "Cancel", "Yes", "No" and so on. */ + virtual const wchar_t* getDefaultText(EGUI_DEFAULT_TEXT text) const; + + //! Sets a default text. + /** For example for Message box button captions: + "OK", "Cancel", "Yes", "No" and so on. */ + virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText); + + //! draws a standard 3d button pane + /** Used for drawing for example buttons in normal state. + It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and + EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. + \param rect: Defining area where to draw. + \param clip: Clip area. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. */ + virtual void draw3DButtonPaneStandard(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0) + { + drawColored3DButtonPaneStandard(element, rect,clip); + } + + virtual void drawColored3DButtonPaneStandard(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0, + const video::SColor* colors=0); + + //! draws a pressed 3d button pane + /** Used for drawing for example buttons in pressed state. + It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and + EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. + \param rect: Defining area where to draw. + \param clip: Clip area. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. */ + virtual void draw3DButtonPanePressed(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0) + { + drawColored3DButtonPanePressed(element, rect, clip); + } + + virtual void drawColored3DButtonPanePressed(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0, + const video::SColor* colors=0); + + //! draws a sunken 3d pane + /** Used for drawing the background of edit, combo or check boxes. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param bgcolor: Background color. + \param flat: Specifies if the sunken pane should be flat or displayed as sunken + deep into the ground. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DSunkenPane(IGUIElement* element, + video::SColor bgcolor, bool flat, + bool fillBackGround, + const core::rect& rect, + const core::rect* clip=0) + { + drawColored3DSunkenPane(element, bgcolor, flat, fillBackGround, rect, clip); + } + + virtual void drawColored3DSunkenPane(IGUIElement* element, + video::SColor bgcolor, bool flat, + bool fillBackGround, + const core::rect& rect, + const core::rect* clip=0, + const video::SColor* colors=0); + + //! draws a window background + /** Used for drawing the background of dialogs and windows. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param titleBarColor: Title color. + \param drawTitleBar: True to enable title drawing. + \param rect: Defining area where to draw. + \param clip: Clip area. + \param checkClientArea: When set to non-null the function will not draw anything, + but will instead return the clientArea which can be used for drawing by the calling window. + That is the area without borders and without titlebar. + \return Returns rect where it would be good to draw title bar text. This will + work even when checkClientArea is set to a non-null value.*/ + virtual core::rect draw3DWindowBackground(IGUIElement* element, + bool drawTitleBar, video::SColor titleBarColor, + const core::rect& rect, + const core::rect* clip, + core::rect* checkClientArea) + { + return drawColored3DWindowBackground(element, drawTitleBar, titleBarColor, + rect, clip, checkClientArea); + } + + virtual core::rect drawColored3DWindowBackground(IGUIElement* element, + bool drawTitleBar, video::SColor titleBarColor, + const core::rect& rect, + const core::rect* clip, + core::rect* checkClientArea, + const video::SColor* colors=0); + + //! draws a standard 3d menu pane + /** Used for drawing for menus and context menus. + It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and + EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DMenuPane(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0) + { + drawColored3DMenuPane(element, rect, clip); + } + + virtual void drawColored3DMenuPane(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0, + const video::SColor* colors=0); + + //! draws a standard 3d tool bar + /** Used for drawing for toolbars and menus. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DToolBar(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0) + { + drawColored3DToolBar(element, rect, clip); + } + + virtual void drawColored3DToolBar(IGUIElement* element, + const core::rect& rect, + const core::rect* clip=0, + const video::SColor* colors=0); + + //! draws a tab button + /** Used for drawing for tab buttons on top of tabs. + \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param active: Specifies if the tab is currently active. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DTabButton(IGUIElement* element, bool active, + const core::rect& rect, const core::rect* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT) + { + drawColored3DTabButton(element, active, rect, clip, alignment); + } + + virtual void drawColored3DTabButton(IGUIElement* element, bool active, + const core::rect& rect, const core::rect* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT, + const video::SColor* colors=0); + + //! draws a tab control body + /** \param element: Pointer to the element which wishes to draw this. This parameter + is usually not used by ISkin, but can be used for example by more complex + implementations to find out how to draw the part exactly. + \param border: Specifies if the border should be drawn. + \param background: Specifies if the background should be drawn. + \param rect: Defining area where to draw. + \param clip: Clip area. */ + virtual void draw3DTabBody(IGUIElement* element, bool border, bool background, + const core::rect& rect, const core::rect* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT) + { + drawColored3DTabBody(element, border, background, rect, clip, tabHeight, alignment); + } + + virtual void drawColored3DTabBody(IGUIElement* element, bool border, bool background, + const core::rect& rect, const core::rect* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT, + const video::SColor* colors=0); + + //! draws an icon, usually from the skin's sprite bank + /** \param element: Pointer to the element which wishes to draw this icon. + This parameter is usually not used by IGUISkin, but can be used for example + by more complex implementations to find out how to draw the part exactly. + \param icon: Specifies the icon to be drawn. + \param position: The position to draw the icon + \param starttime: The time at the start of the animation + \param currenttime: The present time, used to calculate the frame number + \param loop: Whether the animation should loop or not + \param clip: Clip area. */ + virtual void drawIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, + const core::position2di position, + u32 starttime=0, u32 currenttime=0, + bool loop=false, const core::rect* clip=0) + { + drawColoredIcon(element, icon, position, starttime, currenttime, loop, clip); + } + + virtual void drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, + const core::position2di position, + u32 starttime=0, u32 currenttime=0, + bool loop=false, const core::rect* clip=0, + const video::SColor* colors=0); + + //! draws a 2d rectangle. + /** \param element: Pointer to the element which wishes to draw this icon. + This parameter is usually not used by IGUISkin, but can be used for example + by more complex implementations to find out how to draw the part exactly. + \param color: Color of the rectangle to draw. The alpha component specifies how + transparent the rectangle will be. + \param pos: Position of the rectangle. + \param clip: Pointer to rectangle against which the rectangle will be clipped. + If the pointer is null, no clipping will be performed. */ + virtual void draw2DRectangle(IGUIElement* element, const video::SColor &color, + const core::rect& pos, const core::rect* clip = 0); + + + //! get the type of this skin + virtual EGUI_SKIN_TYPE getType() const; + + //! gets the colors + virtual void getColors(video::SColor* colors); // ::PATCH: + + private: + + video::SColor Colors[EGDC_COUNT]; + s32 Sizes[EGDS_COUNT]; + u32 Icons[EGDI_COUNT]; + IGUIFont* Fonts[EGDF_COUNT]; + IGUISpriteBank* SpriteBank; + core::stringw Texts[EGDT_COUNT]; + video::IVideoDriver* Driver; + bool UseGradient; + + EGUI_SKIN_TYPE Type; + }; + + #define set3DSkinColors(skin, button_color) \ + { \ + skin->setColor(EGDC_3D_FACE, button_color); \ + skin->setColor(EGDC_3D_DARK_SHADOW, button_color, 0.25f); \ + skin->setColor(EGDC_3D_SHADOW, button_color, 0.5f); \ + skin->setColor(EGDC_3D_LIGHT, button_color); \ + skin->setColor(EGDC_3D_HIGH_LIGHT, button_color, 1.5f); \ + } + + #define getElementSkinColor(color) \ + { \ + if (!Colors) \ + { \ + IGUISkin* skin = Environment->getSkin(); \ + if (skin) \ + return skin->getColor(color); \ + } \ + return Colors[color]; \ + } + + #define setElementSkinColor(which, newColor, shading) \ + { \ + if (!Colors) \ + { \ + Colors = new video::SColor[EGDC_COUNT]; \ + GUISkin* skin = (GUISkin *)Environment->getSkin(); \ + if (skin) \ + skin->getColors(Colors); \ + } \ + Colors[which] = newColor; \ + setShading(Colors[which],shading); \ + } +} // end namespace gui +//! Sets the shading +inline void setShading(video::SColor &color,f32 s) // :PATCH: +{ + if (s < 1.0f) + { + color.setRed(color.getRed() * s); + color.setGreen(color.getGreen() * s); + color.setBlue(color.getBlue() * s); + } + else if (s > 1.0f) + { + s -= 1.0f; + + color.setRed(color.getRed() + (255 - color.getRed()) * s); + color.setGreen(color.getGreen() + (255 - color.getGreen()) * s); + color.setBlue(color.getBlue() + (255 - color.getBlue()) * s); + } +} +} // end namespace irr + +#endif From d4b10db998ebeb689b3d27368e30952a42169d03 Mon Sep 17 00:00:00 2001 From: cx384 Date: Sat, 23 Mar 2024 17:56:54 +0100 Subject: [PATCH 86/91] Add LF config to .gitattributes --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitattributes b/.gitattributes index 2e62a4e59..06b76c6c8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ +# Forces all files which git considers text files to use LF line endings +* text=auto eol=lf + *.cpp diff=cpp *.h diff=cpp From eb8785a20990a7b35e82fcfcbe4d3c046fabe8c5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 2 Apr 2024 21:25:32 +0200 Subject: [PATCH 87/91] Fix segfault if SDL GL context fails --- irr/src/CIrrDeviceSDL.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index 17dc033d4..2609058a6 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -321,19 +321,21 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters ¶m) : //! destructor CIrrDeviceSDL::~CIrrDeviceSDL() { - if (--SDLDeviceInstances == 0) { #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) - const u32 numJoysticks = Joysticks.size(); - for (u32 i = 0; i < numJoysticks; ++i) - SDL_JoystickClose(Joysticks[i]); + const u32 numJoysticks = Joysticks.size(); + for (u32 i = 0; i < numJoysticks; ++i) + SDL_JoystickClose(Joysticks[i]); #endif - if (Window) { - SDL_GL_MakeCurrent(Window, NULL); - SDL_GL_DeleteContext(Context); - SDL_DestroyWindow(Window); - } - SDL_Quit(); + if (Window && Context) { + SDL_GL_MakeCurrent(Window, NULL); + SDL_GL_DeleteContext(Context); + } + if (Window) { + SDL_DestroyWindow(Window); + } + if (--SDLDeviceInstances == 0) { + SDL_Quit(); os::Printer::log("Quit SDL", ELL_INFORMATION); } } From 57a737c417aef1c3ca038384af750050713fd8d4 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 2 Apr 2024 21:25:46 +0200 Subject: [PATCH 88/91] Improve logging of driver probing --- src/client/renderingengine.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index debfe8e21..51f5e1e92 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -164,13 +164,19 @@ static std::optional chooseVideoDriver() return std::nullopt; } +static inline auto getVideoDriverName(video::E_DRIVER_TYPE driver) +{ + return RenderingEngine::getVideoDriverInfo(driver).friendly_name; +} + static irr::IrrlichtDevice *createDevice(SIrrlichtCreationParameters params, std::optional requested_driver) { if (requested_driver) { params.DriverType = *requested_driver; + verbosestream << "Trying video driver " << getVideoDriverName(params.DriverType) << std::endl; if (auto *device = createDeviceEx(params)) return device; - errorstream << "Failed to initialize the " << RenderingEngine::getVideoDriverInfo(*requested_driver).friendly_name << " video driver" << std::endl; + errorstream << "Failed to initialize the " << getVideoDriverName(params.DriverType) << " video driver" << std::endl; } sanity_check(requested_driver != video::EDT_NULL); @@ -179,6 +185,7 @@ static irr::IrrlichtDevice *createDevice(SIrrlichtCreationParameters params, std if (fallback_driver == video::EDT_NULL || fallback_driver == requested_driver) continue; params.DriverType = fallback_driver; + verbosestream << "Trying video driver " << getVideoDriverName(params.DriverType) << std::endl; if (auto *device = createDeviceEx(params)) return device; } @@ -232,7 +239,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) m_device = createDevice(params, driverType); driver = m_device->getVideoDriver(); - infostream << "Using the " << RenderingEngine::getVideoDriverInfo(driver->getDriverType()).friendly_name << " video driver" << std::endl; + verbosestream << "Using the " << getVideoDriverName(driver->getDriverType()) << " video driver" << std::endl; // This changes the minimum allowed number of vertices in a VBO. Default is 500. driver->setMinHardwareBufferVertexCount(4); From ff88ed7c7516c6a0174344a3c1a522bfe7cca7a5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 2 Apr 2024 21:26:55 +0200 Subject: [PATCH 89/91] Add symlink for Irrlicht shaders --- client/shaders/Irrlicht | 1 + 1 file changed, 1 insertion(+) create mode 120000 client/shaders/Irrlicht diff --git a/client/shaders/Irrlicht b/client/shaders/Irrlicht new file mode 120000 index 000000000..9349d3073 --- /dev/null +++ b/client/shaders/Irrlicht @@ -0,0 +1 @@ +../../irr/media/Shaders \ No newline at end of file From f8bff346f41005098f54b0ba4835a72ebb84f536 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 3 Apr 2024 13:56:49 +0200 Subject: [PATCH 90/91] Batched rendering of particles (#14489) Co-authored-by: x2048 Co-authored-by: Desour --- src/client/particles.cpp | 461 +++++++++++++++++++++++++-------------- src/client/particles.h | 145 +++++++----- src/tileanimation.h | 2 +- 3 files changed, 395 insertions(+), 213 deletions(-) diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 14384f3b8..638505846 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "particles.h" #include +#include #include "client.h" #include "collision.h" #include "client/content_cao.h" @@ -26,21 +27,27 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/renderingengine.h" #include "util/numeric.h" #include "light.h" +#include "localplayer.h" #include "environment.h" #include "clientmap.h" #include "mapnode.h" #include "nodedef.h" #include "client.h" #include "settings.h" +#include "profiler.h" + +ClientParticleTexture::ClientParticleTexture(const ServerParticleTexture& p, ITextureSource *tsrc) +{ + tex = p; + // note: getTextureForMesh not needed here because we don't use texture filtering + ref = tsrc->getTexture(p.string); +} /* Particle */ Particle::Particle( - IGameDef *gamedef, - LocalPlayer *player, - ClientEnvironment *env, const ParticleParameters &p, const ClientParticleTexRef &texture, v2f texpos, @@ -49,14 +56,10 @@ Particle::Particle( ParticleSpawner *parent, std::unique_ptr owned_texture ) : - scene::ISceneNode(((Client *)gamedef)->getSceneManager()->getRootSceneNode(), - ((Client *)gamedef)->getSceneManager()), - m_expiration(p.expirationtime), - m_env(env), - m_gamedef(gamedef), - m_collisionbox(aabb3f(v3f(-p.size / 2.0f), v3f(p.size / 2.0f))), + m_base_color(color), + m_texture(texture), m_texpos(texpos), m_texsize(texsize), @@ -64,102 +67,30 @@ Particle::Particle( m_velocity(p.vel), m_acceleration(p.acc), m_p(p), - m_player(player), - - m_base_color(color), - m_color(color), m_parent(parent), m_owned_texture(std::move(owned_texture)) { - // Set material - { - // translate blend modes to GL blend functions - video::E_BLEND_FACTOR bfsrc, bfdst; - video::E_BLEND_OPERATION blendop; - const auto blendmode = texture.tex != nullptr - ? texture.tex->blendmode - : ParticleParamTypes::BlendMode::alpha; +} - switch (blendmode) { - case ParticleParamTypes::BlendMode::add: - bfsrc = video::EBF_SRC_ALPHA; - bfdst = video::EBF_DST_ALPHA; - blendop = video::EBO_ADD; - break; +Particle::~Particle() +{ + if (m_buffer) + m_buffer->release(m_index); +} - case ParticleParamTypes::BlendMode::sub: - bfsrc = video::EBF_SRC_ALPHA; - bfdst = video::EBF_DST_ALPHA; - blendop = video::EBO_REVSUBTRACT; - break; - - case ParticleParamTypes::BlendMode::screen: - bfsrc = video::EBF_ONE; - bfdst = video::EBF_ONE_MINUS_SRC_COLOR; - blendop = video::EBO_ADD; - break; - - default: // includes ParticleParamTypes::BlendMode::alpha - bfsrc = video::EBF_SRC_ALPHA; - bfdst = video::EBF_ONE_MINUS_SRC_ALPHA; - blendop = video::EBO_ADD; - break; - } - - // Texture - m_material.Lighting = false; - m_material.BackfaceCulling = false; - m_material.FogEnable = true; - m_material.forEachTexture([] (auto &tex) { - tex.MinFilter = video::ETMINF_NEAREST_MIPMAP_NEAREST; - tex.MagFilter = video::ETMAGF_NEAREST; - }); - - // correctly render layered transparent particles -- see #10398 - m_material.ZWriteEnable = video::EZW_AUTO; - - // enable alpha blending and set blend mode - m_material.MaterialType = video::EMT_ONETEXTURE_BLEND; - m_material.MaterialTypeParam = video::pack_textureBlendFunc( - bfsrc, bfdst, - video::EMFN_MODULATE_1X, - video::EAS_TEXTURE | video::EAS_VERTEX_COLOR); - m_material.BlendOperation = blendop; - m_material.setTexture(0, m_texture.ref); +bool Particle::attachToBuffer(ParticleBuffer *buffer) +{ + auto index_opt = buffer->allocate(); + if (index_opt.has_value()) { + m_index = index_opt.value(); + m_buffer = buffer; + return true; } - - // Irrlicht stuff - this->setAutomaticCulling(scene::EAC_OFF); - - // Init lighting - updateLight(); - - // Init model - updateVertices(); + return false; } -void Particle::OnRegisterSceneNode() -{ - if (IsVisible) - SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT_EFFECT); - - ISceneNode::OnRegisterSceneNode(); -} - -void Particle::render() -{ - video::IVideoDriver *driver = SceneManager->getVideoDriver(); - driver->setMaterial(m_material); - driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); - - u16 indices[] = {0,1,2, 2,3,0}; - driver->drawVertexPrimitiveList(m_vertices, 4, - indices, 2, video::EVT_STANDARD, - scene::EPT_TRIANGLES, video::EIT_16BIT); -} - -void Particle::step(float dtime) +void Particle::step(float dtime, ClientEnvironment *env) { m_time += dtime; @@ -169,10 +100,10 @@ void Particle::step(float dtime) m_velocity = av*vecSign(m_velocity) + v3f(m_p.jitter.pickWithin())*dtime; if (m_p.collisiondetection) { - aabb3f box = m_collisionbox; + aabb3f box(v3f(-m_p.size / 2.0f), v3f(m_p.size / 2.0f)); v3f p_pos = m_pos * BS; v3f p_velocity = m_velocity * BS; - collisionMoveResult r = collisionMoveSimple(m_env, m_gamedef, BS * 0.5f, + collisionMoveResult r = collisionMoveSimple(env, env->getGameDef(), BS * 0.5f, box, 0.0f, dtime, &p_pos, &p_velocity, m_acceleration * BS, nullptr, m_p.object_collision); @@ -215,7 +146,7 @@ void Particle::step(float dtime) m_animation_time += dtime; int frame_length_i = 0; m_p.animation.determineParams( - m_material.getTexture(0)->getSize(), + m_texture.ref->getSize(), NULL, &frame_length_i, NULL); float frame_length = frame_length_i / 1000.0; while (m_animation_time > frame_length) { @@ -225,23 +156,19 @@ void Particle::step(float dtime) } // animate particle alpha in accordance with settings + float alpha = 1.f; if (m_texture.tex != nullptr) - m_alpha = m_texture.tex -> alpha.blend(m_time / (m_expiration+0.1f)); - else - m_alpha = 1.f; + alpha = m_texture.tex -> alpha.blend(m_time / (m_expiration+0.1f)); // Update lighting - updateLight(); + auto col = updateLight(env); + col.setAlpha(255 * alpha); // Update model - updateVertices(); - - // Update position -- see #10398 - v3s16 camera_offset = m_env->getCameraOffset(); - setPosition(m_pos*BS - intToFloat(camera_offset, BS)); + updateVertices(env, col); } -void Particle::updateLight() +video::SColor Particle::updateLight(ClientEnvironment *env) { u8 light = 0; bool pos_ok; @@ -251,32 +178,37 @@ void Particle::updateLight() floor(m_pos.Y+0.5), floor(m_pos.Z+0.5) ); - MapNode n = m_env->getClientMap().getNode(p, &pos_ok); + MapNode n = env->getClientMap().getNode(p, &pos_ok); if (pos_ok) - light = n.getLightBlend(m_env->getDayNightRatio(), - m_gamedef->ndef()->getLightingFlags(n)); + light = n.getLightBlend(env->getDayNightRatio(), + env->getGameDef()->ndef()->getLightingFlags(n)); else - light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0); + light = blend_light(env->getDayNightRatio(), LIGHT_SUN, 0); u8 m_light = decode_light(light + m_p.glow); - m_color.set(m_alpha*255, + return video::SColor(255, m_light * m_base_color.getRed() / 255, m_light * m_base_color.getGreen() / 255, m_light * m_base_color.getBlue() / 255); } -void Particle::updateVertices() +void Particle::updateVertices(ClientEnvironment *env, video::SColor color) { f32 tx0, tx1, ty0, ty1; v2f scale; + if (!m_buffer) + return; + + video::S3DVertex *vertices = m_buffer->getVertices(m_index); + if (m_texture.tex != nullptr) scale = m_texture.tex -> scale.blend(m_time / (m_expiration+0.1)); else scale = v2f(1.f, 1.f); if (m_p.animation.type != TAT_NONE) { - const v2u32 texsize = m_material.getTexture(0)->getSize(); + const v2u32 texsize = m_texture.ref->getSize(); v2f texcoord, framesize_f; v2u32 framesize; texcoord = m_p.animation.getTextureCoords(texsize, m_animation_frame); @@ -297,31 +229,30 @@ void Particle::updateVertices() auto half = m_p.size * .5f, hx = half * scale.X, hy = half * scale.Y; - m_vertices[0] = video::S3DVertex(-hx, -hy, - 0, 0, 0, 0, m_color, tx0, ty1); - m_vertices[1] = video::S3DVertex(hx, -hy, - 0, 0, 0, 0, m_color, tx1, ty1); - m_vertices[2] = video::S3DVertex(hx, hy, - 0, 0, 0, 0, m_color, tx1, ty0); - m_vertices[3] = video::S3DVertex(-hx, hy, - 0, 0, 0, 0, m_color, tx0, ty0); + vertices[0] = video::S3DVertex(-hx, -hy, + 0, 0, 0, 0, color, tx0, ty1); + vertices[1] = video::S3DVertex(hx, -hy, + 0, 0, 0, 0, color, tx1, ty1); + vertices[2] = video::S3DVertex(hx, hy, + 0, 0, 0, 0, color, tx1, ty0); + vertices[3] = video::S3DVertex(-hx, hy, + 0, 0, 0, 0, color, tx0, ty0); + // Update position -- see #10398 + auto *player = env->getLocalPlayer(); + v3s16 camera_offset = env->getCameraOffset(); - // see #10398 - // v3s16 camera_offset = m_env->getCameraOffset(); - // particle position is now handled by step() - m_box.reset(v3f()); - - for (video::S3DVertex &vertex : m_vertices) { + for (u16 i = 0; i < 4; i++) { + video::S3DVertex &vertex = vertices[i]; if (m_p.vertical) { - v3f ppos = m_player->getPosition()/BS; + v3f ppos = player->getPosition() / BS; vertex.Pos.rotateXZBy(std::atan2(ppos.Z - m_pos.Z, ppos.X - m_pos.X) / core::DEGTORAD + 90); } else { - vertex.Pos.rotateYZBy(m_player->getPitch()); - vertex.Pos.rotateXZBy(m_player->getYaw()); + vertex.Pos.rotateYZBy(player->getPitch()); + vertex.Pos.rotateXZBy(player->getYaw()); } - m_box.addInternalPoint(vertex.Pos); + vertex.Pos += m_pos * BS - intToFloat(camera_offset, BS); } } @@ -330,7 +261,6 @@ void Particle::updateVertices() */ ParticleSpawner::ParticleSpawner( - IGameDef *gamedef, LocalPlayer *player, const ParticleSpawnerParameters ¶ms, u16 attached_id, @@ -340,7 +270,6 @@ ParticleSpawner::ParticleSpawner( m_active(0), m_particlemanager(p_manager), m_time(0.0f), - m_gamedef(gamedef), m_player(player), p(params), m_texpool(std::move(texpool)), @@ -565,9 +494,6 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, ++m_active; m_particlemanager->addParticle(std::make_unique( - m_gamedef, - m_player, - env, pp, texture, texpos, @@ -624,6 +550,109 @@ void ParticleSpawner::step(float dtime, ClientEnvironment *env) } } +/* + ParticleBuffer +*/ + +ParticleBuffer::ParticleBuffer(ClientEnvironment *env, const video::SMaterial &material) + : scene::ISceneNode( + env->getGameDef()->getSceneManager()->getRootSceneNode(), + env->getGameDef()->getSceneManager()), + m_mesh_buffer(make_irr()) +{ + m_mesh_buffer->getMaterial() = material; +} + +static constexpr u16 quad_indices[] = { 0, 1, 2, 2, 3, 0 }; + +std::optional ParticleBuffer::allocate() +{ + u16 index; + + m_usage_timer = 0; + + if (!m_free_list.empty()) { + index = m_free_list.back(); + m_free_list.pop_back(); + auto *vertices = static_cast(m_mesh_buffer->getVertices()); + u16 *indices = m_mesh_buffer->getIndices(); + // reset vertices, because it is only written in Particle::step() + for (u16 i = 0; i < 4; i++) + vertices[4 * index + i] = video::S3DVertex(); + for (u16 i = 0; i < 6; i++) + indices[6 * index + i] = 4 * index + quad_indices[i]; + return index; + } + + if (m_count >= MAX_PARTICLES_PER_BUFFER) + return std::nullopt; + + // append new vertices + // note: Our buffer never gets smaller, but ParticleManager will delete + // us after a while. + std::array vertices {}; + m_mesh_buffer->append(&vertices.front(), 4, quad_indices, 6); + index = m_count++; + return index; +} + +void ParticleBuffer::release(u16 index) +{ + assert(index < m_count); + u16 *indices = m_mesh_buffer->getIndices(); + for (u16 i = 0; i < 6; i++) + indices[6 * index + i] = 0; + m_free_list.push_back(index); +} + +video::S3DVertex *ParticleBuffer::getVertices(u16 index) +{ + if (index >= m_count) + return nullptr; + m_bounding_box_dirty = true; + return &(static_cast(m_mesh_buffer->getVertices())[4 * index]); +} + +void ParticleBuffer::OnRegisterSceneNode() +{ + if (IsVisible) + SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT_EFFECT); + scene::ISceneNode::OnRegisterSceneNode(); +} + +const core::aabbox3df &ParticleBuffer::getBoundingBox() const +{ + if (!m_bounding_box_dirty) + return m_mesh_buffer->BoundingBox; + + core::aabbox3df box; + for (u16 i = 0; i < m_count; i++) { + // check if this index is used + static_assert(quad_indices[1] != 0); + if (m_mesh_buffer->getIndices()[6 * i + 1] == 0) + continue; + + for (u16 j = 0; j < 4; j++) + box.addInternalPoint(m_mesh_buffer->getPosition(i * 4 + j)); + } + + m_mesh_buffer->BoundingBox = box; + m_bounding_box_dirty = false; + return m_mesh_buffer->BoundingBox; +} + +void ParticleBuffer::render() +{ + video::IVideoDriver *driver = SceneManager->getVideoDriver(); + + if (isEmpty()) + return; + + driver->setTransform(video::ETS_WORLD, core::matrix4()); + driver->setMaterial(m_mesh_buffer->getMaterial()); + driver->drawMeshBuffer(m_mesh_buffer.get()); +} + /* ParticleManager */ @@ -639,8 +668,9 @@ ParticleManager::~ParticleManager() void ParticleManager::step(float dtime) { - stepParticles (dtime); - stepSpawners (dtime); + stepParticles(dtime); + stepSpawners(dtime); + stepBuffers(dtime); } void ParticleManager::stepSpawners(float dtime) @@ -684,35 +714,59 @@ void ParticleManager::stepParticles(float dtime) assert(parent->hasActive()); parent->decrActive(); } - // remove scene node - p.remove(); // delete m_particles[i] = std::move(m_particles.back()); m_particles.pop_back(); } else { - p.step(dtime); + p.step(dtime, m_env); ++i; } } } +void ParticleManager::stepBuffers(float dtime) +{ + constexpr float INTERVAL = 0.5f; + if (!m_buffer_gc.step(dtime, INTERVAL)) + return; + + MutexAutoLock lock(m_particle_list_lock); + + // remove buffers that have been unused for 5 seconds + size_t alloc = 0; + for (size_t i = 0; i < m_particle_buffers.size(); ) { + auto &buf = m_particle_buffers[i]; + buf->m_usage_timer += INTERVAL; + if (buf->isEmpty() && buf->m_usage_timer > 5.0f) { + // delete and swap with last + buf->remove(); + buf = std::move(m_particle_buffers.back()); + m_particle_buffers.pop_back(); + } else { + i++; + alloc += buf->m_count; + } + } + + g_profiler->avg("ParticleManager: particle buffer count [#]", m_particle_buffers.size()); + if (!m_particle_buffers.empty()) + g_profiler->avg("ParticleManager: buffer allocated size [#]", alloc); +} + void ParticleManager::clearAll() { MutexAutoLock lock(m_spawner_list_lock); MutexAutoLock lock2(m_particle_list_lock); - // clear particle spawners m_particle_spawners.clear(); m_dying_particle_spawners.clear(); - // clear particles - for (std::unique_ptr &p : m_particles) { - // remove scene node - p->remove(); - // delete - p.reset(); - } m_particles.clear(); + + // have to remove from scene first because it keeps a reference + for (auto &it : m_particle_buffers) + it->remove(); + m_particle_buffers.clear(); } void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, @@ -744,7 +798,6 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, addParticleSpawner(event->add_particlespawner.id, std::make_unique( - client, player, p, event->add_particlespawner.attached_id, @@ -785,7 +838,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, p.size = oldsize; if (texture.ref) { - addParticle(std::make_unique(client, player, m_env, + addParticle(std::make_unique( p, texture, texpos, texsize, color, nullptr, std::move(texstore))); } @@ -885,9 +938,6 @@ void ParticleManager::addNodeParticle(IGameDef *gamedef, ); addParticle(std::make_unique( - gamedef, - player, - m_env, p, ClientParticleTexRef(ref), texpos, @@ -902,13 +952,104 @@ void ParticleManager::reserveParticleSpace(size_t max_estimate) m_particles.reserve(m_particles.size() + max_estimate); } -void ParticleManager::addParticle(std::unique_ptr toadd) +video::SMaterial ParticleManager::getMaterialForParticle(const ClientParticleTexRef &texture) +{ + // translate blend modes to GL blend functions + video::E_BLEND_FACTOR bfsrc, bfdst; + video::E_BLEND_OPERATION blendop; + const auto blendmode = texture.tex ? texture.tex->blendmode : + ParticleParamTypes::BlendMode::alpha; + + switch (blendmode) { + case ParticleParamTypes::BlendMode::add: + bfsrc = video::EBF_SRC_ALPHA; + bfdst = video::EBF_DST_ALPHA; + blendop = video::EBO_ADD; + break; + + case ParticleParamTypes::BlendMode::sub: + bfsrc = video::EBF_SRC_ALPHA; + bfdst = video::EBF_DST_ALPHA; + blendop = video::EBO_REVSUBTRACT; + break; + + case ParticleParamTypes::BlendMode::screen: + bfsrc = video::EBF_ONE; + bfdst = video::EBF_ONE_MINUS_SRC_COLOR; + blendop = video::EBO_ADD; + break; + + default: // includes ParticleParamTypes::BlendMode::alpha + bfsrc = video::EBF_SRC_ALPHA; + bfdst = video::EBF_ONE_MINUS_SRC_ALPHA; + blendop = video::EBO_ADD; + break; + } + + video::SMaterial material; + + // Texture + material.Lighting = false; + material.BackfaceCulling = false; + material.FogEnable = true; + material.forEachTexture([] (auto &tex) { + tex.MinFilter = video::ETMINF_NEAREST_MIPMAP_NEAREST; + tex.MagFilter = video::ETMAGF_NEAREST; + }); + + // We don't have working transparency sorting. Disable Z-Write for + // correct results for clipped-alpha at least. + material.ZWriteEnable = video::EZW_OFF; + + // enable alpha blending and set blend mode + material.MaterialType = video::EMT_ONETEXTURE_BLEND; + material.MaterialTypeParam = video::pack_textureBlendFunc( + bfsrc, bfdst, + video::EMFN_MODULATE_1X, + video::EAS_TEXTURE | video::EAS_VERTEX_COLOR); + material.BlendOperation = blendop; + assert(texture.ref); + material.setTexture(0, texture.ref); + + return material; +} + +bool ParticleManager::addParticle(std::unique_ptr toadd) { MutexAutoLock lock(m_particle_list_lock); - m_particles.push_back(std::move(toadd)); -} + auto material = getMaterialForParticle(toadd->getTextureRef()); + ParticleBuffer *found = nullptr; + // simple shortcut when multiple particles of the same type get added + if (!m_particles.empty()) { + auto &last = m_particles.back(); + if (last->getBuffer() && last->getBuffer()->getMaterial(0) == material) + found = last->getBuffer(); + } + // search fitting buffer + if (!found) { + for (auto &buffer : m_particle_buffers) { + if (buffer->getMaterial(0) == material) { + found = buffer.get(); + break; + } + } + } + // or create a new one + if (!found) { + auto tmp = make_irr(m_env, material); + found = tmp.get(); + m_particle_buffers.push_back(std::move(tmp)); + } + + if (!toadd->attachToBuffer(found)) { + infostream << "ParticleManager: buffer full, dropping particle" << std::endl; + return false; + } + m_particles.push_back(std::move(toadd)); + return true; +} void ParticleManager::addParticleSpawner(u64 id, std::unique_ptr toadd) { diff --git a/src/client/particles.h b/src/client/particles.h index 2c8ceafa4..92ea8fb67 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -19,9 +19,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -#include +#include +#include #include "irrlichttypes_extrabloated.h" -#include "localplayer.h" +#include "irr_ptr.h" #include "../particles.h" struct ClientEvent; @@ -29,6 +30,10 @@ class ParticleManager; class ClientEnvironment; struct MapNode; struct ContentFeatures; +class LocalPlayer; +class ITextureSource; +class IGameDef; +class Client; struct ClientParticleTexture { @@ -38,9 +43,7 @@ struct ClientParticleTexture video::ITexture *ref = nullptr; ClientParticleTexture() = default; - ClientParticleTexture(const ServerParticleTexture& p, ITextureSource *t): - tex(p), - ref(t->getTextureForMesh(p.string)) {}; + ClientParticleTexture(const ServerParticleTexture& p, ITextureSource *tsrc); }; struct ClientParticleTexRef @@ -61,14 +64,12 @@ struct ClientParticleTexRef }; class ParticleSpawner; +class ParticleBuffer; -class Particle : public scene::ISceneNode +class Particle { public: Particle( - IGameDef *gamedef, - LocalPlayer *player, - ClientEnvironment *env, const ParticleParameters &p, const ClientParticleTexRef &texture, v2f texpos, @@ -78,61 +79,46 @@ public: std::unique_ptr owned_texture = nullptr ); - virtual const aabb3f &getBoundingBox() const - { - return m_box; - } + ~Particle(); - virtual u32 getMaterialCount() const - { - return 1; - } + DISABLE_CLASS_COPY(Particle) - virtual video::SMaterial& getMaterial(u32 i) - { - return m_material; - } + void step(float dtime, ClientEnvironment *env); - virtual void OnRegisterSceneNode(); - virtual void render(); - - void step(float dtime); - - bool isExpired () + bool isExpired () const { return m_expiration < m_time; } - ParticleSpawner *getParent() { return m_parent; } + ParticleSpawner *getParent() const { return m_parent; } + + const ClientParticleTexRef &getTextureRef() const { return m_texture; } + + ParticleBuffer *getBuffer() const { return m_buffer; } + bool attachToBuffer(ParticleBuffer *buffer); private: - void updateLight(); - void updateVertices(); - void setVertexAlpha(float a); + video::SColor updateLight(ClientEnvironment *env); + void updateVertices(ClientEnvironment *env, video::SColor color); + + ParticleBuffer *m_buffer = nullptr; + u16 m_index; // index in m_buffer - video::S3DVertex m_vertices[4]; float m_time = 0.0f; float m_expiration; - ClientEnvironment *m_env; - IGameDef *m_gamedef; - aabb3f m_box; - aabb3f m_collisionbox; + // Color without lighting + video::SColor m_base_color; + ClientParticleTexRef m_texture; - video::SMaterial m_material; v2f m_texpos; v2f m_texsize; v3f m_pos; v3f m_velocity; v3f m_acceleration; - const ParticleParameters m_p; - LocalPlayer *m_player; - //! Color without lighting - video::SColor m_base_color; - //! Final rendered color - video::SColor m_color; + const ParticleParameters m_p; + float m_animation_time = 0.0f; int m_animation_frame = 0; - float m_alpha = 0.0f; ParticleSpawner *m_parent = nullptr; // Used if not spawned from a particlespawner @@ -142,8 +128,7 @@ private: class ParticleSpawner { public: - ParticleSpawner(IGameDef *gamedef, - LocalPlayer *player, + ParticleSpawner(LocalPlayer *player, const ParticleSpawnerParameters ¶ms, u16 attached_id, std::vector &&texpool, @@ -164,7 +149,6 @@ private: size_t m_active; ParticleManager *m_particlemanager; float m_time; - IGameDef *m_gamedef; LocalPlayer *m_player; ParticleSpawnerParameters p; std::vector m_texpool; @@ -172,12 +156,61 @@ private: u16 m_attached_id; }; +class ParticleBuffer : public scene::ISceneNode +{ + friend class ParticleManager; +public: + ParticleBuffer(ClientEnvironment *env, const video::SMaterial &material); + + // for pointer stability + DISABLE_CLASS_COPY(ParticleBuffer) + + /// Reserves one more slot for a particle (4 vertices, 6 indices) + /// @return particle index within buffer + std::optional allocate(); + /// Frees the particle at `index` + void release(u16 index); + + /// @return video::S3DVertex[4] + video::S3DVertex *getVertices(u16 index); + + inline bool isEmpty() const { + return m_free_list.size() == m_count; + } + + virtual video::SMaterial &getMaterial(u32 num) override { + return m_mesh_buffer->getMaterial(); + } + virtual u32 getMaterialCount() const override { + return 1; + } + + virtual const core::aabbox3df &getBoundingBox() const override; + + virtual void render() override; + + virtual void OnRegisterSceneNode() override; + + // we have 16-bit indices + static constexpr u16 MAX_PARTICLES_PER_BUFFER = 16000; + +private: + irr_ptr m_mesh_buffer; + // unused (e.g. expired) particle indices for re-use + std::vector m_free_list; + // for automatic deletion when unused for a while. is reset on allocate(). + float m_usage_timer = 0; + // total count of contained particles + u16 m_count = 0; + mutable bool m_bounding_box_dirty = true; +}; + /** * Class doing particle as well as their spawners handling */ class ParticleManager { -friend class ParticleSpawner; + friend class ParticleSpawner; public: ParticleManager(ClientEnvironment* env); DISABLE_CLASS_COPY(ParticleManager) @@ -213,7 +246,9 @@ protected: ParticleParameters &p, video::ITexture **texture, v2f &texpos, v2f &texsize, video::SColor *color, u8 tilenum = 0); - void addParticle(std::unique_ptr toadd); + static video::SMaterial getMaterialForParticle(const ClientParticleTexRef &texture); + + bool addParticle(std::unique_ptr toadd); private: void addParticleSpawner(u64 id, std::unique_ptr toadd); @@ -221,17 +256,23 @@ private: void stepParticles(float dtime); void stepSpawners(float dtime); + void stepBuffers(float dtime); void clearAll(); std::vector> m_particles; std::unordered_map> m_particle_spawners; std::vector> m_dying_particle_spawners; - // Start the particle spawner ids generated from here after u32_max. lower values are - // for server sent spawners. - u64 m_next_particle_spawner_id = U32_MAX + 1; + std::vector> m_particle_buffers; + + // Start the particle spawner ids generated from here after u32_max. + // lower values are for server sent spawners. + u64 m_next_particle_spawner_id = static_cast(U32_MAX) + 1; ClientEnvironment *m_env; + + IntervalLimiter m_buffer_gc; + std::mutex m_particle_list_lock; std::mutex m_spawner_list_lock; }; diff --git a/src/tileanimation.h b/src/tileanimation.h index e7cf1a088..db258e240 100644 --- a/src/tileanimation.h +++ b/src/tileanimation.h @@ -31,7 +31,7 @@ enum TileAnimationType : u8 struct TileAnimationParams { - enum TileAnimationType type; + enum TileAnimationType type = TileAnimationType::TAT_NONE; union { // struct { From 0ea1ec31fc19ea5026db9b068bb3a606a8505d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:24:15 +0200 Subject: [PATCH 91/91] Misc. doc things (#14509) * Improve `[sheet` docs * Clarify that `self` is a luaentity in `self.name` * Clarify `textures = {itemname}` deprecation * Document global callback table names --- doc/lua_api.md | 53 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 329f17b01..cca231c73 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -659,8 +659,9 @@ The mask is applied using binary AND. #### `[sheet:x:,` -Retrieves a tile at position x,y from the base image -which it assumes to be a tilesheet with dimensions w,h. +Retrieves a tile at position x, y (in tiles, 0-indexed) +from the base image, which it assumes to be a tilesheet +with dimensions w, h (in tiles). #### `[colorize::` @@ -7313,8 +7314,41 @@ Global tables All callbacks registered with [Global callback registration functions] are added to corresponding `minetest.registered_*` tables. +For historical reasons, the use of an -s suffix in these names is inconsistent. - +* `minetest.registered_on_chat_messages` +* `minetest.registered_on_chatcommands` +* `minetest.registered_globalsteps` +* `minetest.registered_on_punchnodes` +* `minetest.registered_on_placenodes` +* `minetest.registered_on_dignodes` +* `minetest.registered_on_generateds` +* `minetest.registered_on_newplayers` +* `minetest.registered_on_dieplayers` +* `minetest.registered_on_respawnplayers` +* `minetest.registered_on_prejoinplayers` +* `minetest.registered_on_joinplayers` +* `minetest.registered_on_leaveplayers` +* `minetest.registered_on_player_receive_fields` +* `minetest.registered_on_cheats` +* `minetest.registered_on_crafts` +* `minetest.registered_craft_predicts` +* `minetest.registered_on_item_eats` +* `minetest.registered_on_item_pickups` +* `minetest.registered_on_punchplayers` +* `minetest.registered_on_authplayers` +* `minetest.registered_on_player_inventory_actions` +* `minetest.registered_allow_player_inventory_actions` +* `minetest.registered_on_rightclickplayers` +* `minetest.registered_on_mods_loaded` +* `minetest.registered_on_shutdown` +* `minetest.registered_on_protection_violation` +* `minetest.registered_on_priv_grant` +* `minetest.registered_on_priv_revoke` +* `minetest.registered_can_bypass_userlimit` +* `minetest.registered_on_modchannel_message` +* `minetest.registered_on_liquid_transformed` +* `minetest.registered_on_mapblocks_changed` Class reference =============== @@ -7944,8 +7978,12 @@ child will follow movement and rotation of that bone. * Fourth column: subject looking to the right * Fifth column: subject viewed from above * Sixth column: subject viewed from below -* `get_entity_name()` (**Deprecated**: Will be removed in a future version, use the field `self.name` instead) -* `get_luaentity()`: returns the object's associated luaentity table +* `get_luaentity()`: + * Returns the object's associated luaentity table, if there is one + * Otherwise returns `nil` (e.g. for players) +* `get_entity_name()`: + * **Deprecated**: Will be removed in a future version, + use `:get_luaentity().name` instead. #### Player only (no-op for other objects) @@ -8664,7 +8702,8 @@ Player properties need to be saved manually. -- "mesh" uses the defined mesh model. -- "wielditem" is used for dropped items. -- (see builtin/game/item_entity.lua). - -- For this use 'wield_item = itemname' (Deprecated: 'textures = {itemname}'). + -- For this use 'wield_item = itemname'. + -- Setting 'textures = {itemname}' has the same effect, but is deprecated. -- If the item has a 'wield_image' the object will be an extrusion of -- that, otherwise: -- If 'itemname' is a cubic node or nodebox the object will appear @@ -8691,8 +8730,8 @@ Player properties need to be saved manually. -- "cube" uses 6 textures just like a node, but all 6 must be defined. -- "sprite" uses 1 texture. -- "upright_sprite" uses 2 textures: {front, back}. - -- "wielditem" expects 'textures = {itemname}' (see 'visual' above). -- "mesh" requires one texture for each mesh buffer/material (in order) + -- Deprecated usage of "wielditem" expects 'textures = {itemname}' (see 'visual' above). colors = {}, -- Number of required colors depends on visual