Merge 9eb8909618 into b43a5b345b
This commit is contained in:
commit
7207f4fd32
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
set(CC_EXTERNAL_LIBS)
|
||||||
|
set(CC_EXTERNAL_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/sources)
|
||||||
|
set(CC_EXTERNAL_PRIVATE_INCLUDES)
|
||||||
|
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/cmake/CocosExternalConfig.cmake)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/sources/CMakeLists.txt)
|
||||||
|
|
||||||
|
|
||||||
|
if(WINDOWS)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/win32/CMakeLists.txt)
|
||||||
|
elseif(ANDROID)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/android/CMakeLists.txt)
|
||||||
|
elseif(APPLE)
|
||||||
|
if(MACOSX)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/mac/CMakeLists.txt)
|
||||||
|
elseif(IOS)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/ios/CMakeLists.txt)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
@ -1,132 +0,0 @@
|
||||||
LOCAL_PATH := $(call my-dir)
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_zlib_static
|
|
||||||
LOCAL_MODULE_FILENAME := zlib
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libz.a
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_freetype2_static
|
|
||||||
LOCAL_MODULE_FILENAME := freetype2
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfreetype.a
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include/freetype
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_jpeg_static
|
|
||||||
LOCAL_MODULE_FILENAME := jpeg
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libjpeg.a
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_png_static
|
|
||||||
LOCAL_MODULE_FILENAME := png
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libpng.a
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_chipmunk_static
|
|
||||||
LOCAL_MODULE_FILENAME := chipmunk
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libchipmunk.a
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_tiff_static
|
|
||||||
LOCAL_MODULE_FILENAME := tiff
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libtiff.a
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_webp_static
|
|
||||||
LOCAL_MODULE_FILENAME := webp
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libwebp.a
|
|
||||||
|
|
||||||
LOCAL_WHOLE_STATIC_LIBRARIES := cpufeatures
|
|
||||||
|
|
||||||
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
|
|
||||||
LOCAL_CFLAGS := -DHAVE_NEON=1
|
|
||||||
endif
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_crypto_static
|
|
||||||
LOCAL_MODULE_FILENAME := crypto
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libcrypto.a
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_MODULE := cocos_ssl_static
|
|
||||||
LOCAL_MODULE_FILENAME := ssl
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libssl.a
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := websockets_static
|
|
||||||
LOCAL_MODULE_FILENAME := libwebsockets_static
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libwebsockets.a
|
|
||||||
|
|
||||||
LOCAL_CPPFLAGS := -D__STDC_LIMIT_MACROS=1
|
|
||||||
LOCAL_EXPORT_CPPFLAGS := -D__STDC_LIMIT_MACROS=1
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := cocos_mozglue_static
|
|
||||||
LOCAL_MODULE_FILENAME := mozglue
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libmozglue.a
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := spidermonkey_static
|
|
||||||
LOCAL_MODULE_FILENAME := js_static
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libjs_static.a
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include/spidermonkey
|
|
||||||
|
|
||||||
LOCAL_CPPFLAGS := -D__STDC_LIMIT_MACROS=1 -Wno-invalid-offsetof
|
|
||||||
LOCAL_EXPORT_CPPFLAGS := -D__STDC_LIMIT_MACROS=1 -Wno-invalid-offsetof
|
|
||||||
LOCAL_STATIC_LIBRARIES += cocos_mozglue_static
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
#======================================
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := PluginProtocolStatic
|
|
||||||
LOCAL_MODULE_FILENAME := libPluginProtocolStatic
|
|
||||||
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libPluginProtocolStatic.a
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include/anysdk
|
|
||||||
LOCAL_EXPORT_LDLIBS += -llog
|
|
||||||
LOCAL_EXPORT_LDLIBS += -lz
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
#======================================
|
|
||||||
#$(call import-module,android/cpufeatures)
|
|
||||||
|
|
@ -0,0 +1,143 @@
|
||||||
|
|
||||||
|
add_library(crypto STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(crypto PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libcrypto.a
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(freetype STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(freetype PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libfreetype.a
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(jpeg STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(jpeg PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libjpeg.a
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(png STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(png PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libpng.a
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(ssl STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(ssl PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libssl.a
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(uv STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(uv PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libuv.a
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${platform_spec_path}/include/uv
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(webp STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(webp PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libwebp.a
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(websockets STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(websockets PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libwebsockets.a
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(z STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(z PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/libz.a
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${platform_spec_path}/include/zlib
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(android_platform STATIC
|
||||||
|
${CMAKE_ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c
|
||||||
|
${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
|
||||||
|
)
|
||||||
|
target_include_directories(android_platform PUBLIC
|
||||||
|
${CMAKE_ANDROID_NDK}/sources/android/cpufeatures
|
||||||
|
${CMAKE_ANDROID_NDK}/sources/android/native_app_glue
|
||||||
|
)
|
||||||
|
|
||||||
|
## Settings from ${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/Android.mk
|
||||||
|
# set_property(TARGET android_platform APPEND_STRING PROPERTY LINK_FLAGS "-u ANativeActivity_onCreate")
|
||||||
|
# target_link_libraries(android_platform PUBLIC
|
||||||
|
# android log dl
|
||||||
|
# )
|
||||||
|
|
||||||
|
set(se_libs_name)
|
||||||
|
|
||||||
|
if(USE_SE_V8)
|
||||||
|
|
||||||
|
add_library(v8_monolith STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(v8_monolith PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/v8/libv8_monolith.a
|
||||||
|
)
|
||||||
|
|
||||||
|
if(ANDROID_ABI STREQUAL "arm64-v8a" OR ANDROID_ABI STREQUAL "x86_64")
|
||||||
|
set_property(TARGET v8_monolith
|
||||||
|
APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS V8_COMPRESS_POINTERS
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(v8_inspector STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(v8_inspector PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/v8/libinspector.a
|
||||||
|
)
|
||||||
|
|
||||||
|
set(se_libs_name v8_monolith v8_inspector)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(USE_SOCKET)
|
||||||
|
list(APPEND CC_EXTERNAL_LIBS
|
||||||
|
websockets
|
||||||
|
ssl
|
||||||
|
crypto
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(USE_SE_V8 AND USE_V8_DEBUGGER)
|
||||||
|
list(APPEND CC_EXTERNAL_LIBS
|
||||||
|
v8_inspector
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(glslang STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(glslang PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/glslang/libglslang.a
|
||||||
|
)
|
||||||
|
add_library(OGLCompiler STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(OGLCompiler PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/glslang/libOGLCompiler.a
|
||||||
|
)
|
||||||
|
add_library(OSDependent STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(OSDependent PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/glslang/libOSDependent.a
|
||||||
|
)
|
||||||
|
add_library(SPIRV STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(SPIRV PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/glslang/libSPIRV.a
|
||||||
|
)
|
||||||
|
add_library(glslang-default-resource-limits STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(glslang-default-resource-limits PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${platform_spec_path}/glslang/libglslang-default-resource-limits.a
|
||||||
|
)
|
||||||
|
set(glslang_libs_name glslang OGLCompiler OSDependent SPIRV glslang-default-resource-limits)
|
||||||
|
|
||||||
|
|
||||||
|
list(APPEND CC_EXTERNAL_LIBS
|
||||||
|
freetype
|
||||||
|
jpeg
|
||||||
|
png
|
||||||
|
uv
|
||||||
|
webp
|
||||||
|
${se_libs_name}
|
||||||
|
z
|
||||||
|
android_platform
|
||||||
|
${glslang_libs_name}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
list(APPEND CC_EXTERNAL_INCLUDES
|
||||||
|
${platform_spec_path}/include
|
||||||
|
${platform_spec_path}/include/v8
|
||||||
|
${platform_spec_path}/include/uv
|
||||||
|
${platform_spec_path}/include/glslang
|
||||||
|
${CMAKE_ANDROID_NDK}/sources/android/native_app_glue
|
||||||
|
)
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,57 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 Google, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#ifndef _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||||
|
#define _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../glslang/Include/ResourceLimits.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
// These are the default resources for TBuiltInResources, used for both
|
||||||
|
// - parsing this string for the case where the user didn't supply one,
|
||||||
|
// - dumping out a template for user construction of a config file.
|
||||||
|
extern const TBuiltInResource DefaultTBuiltInResource;
|
||||||
|
|
||||||
|
// Returns the DefaultTBuiltInResource as a human-readable string.
|
||||||
|
std::string GetDefaultTBuiltInResourceString();
|
||||||
|
|
||||||
|
// Decodes the resource limits from |config| to |resources|.
|
||||||
|
void DecodeResourceLimits(TBuiltInResource* resources, char* config);
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
BSD 2-Clause License
|
||||||
|
|
||||||
|
Copyright (c) 2020, Travis Fort
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||||
|
#define _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||||
|
|
||||||
|
#include "../glslang/Include/glslang_c_interface.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// These are the default resources for TBuiltInResources, used for both
|
||||||
|
// - parsing this string for the case where the user didn't supply one,
|
||||||
|
// - dumping out a template for user construction of a config file.
|
||||||
|
const glslang_resource_t* glslang_default_resource(void);
|
||||||
|
|
||||||
|
// Returns the DefaultTBuiltInResource as a human-readable string.
|
||||||
|
// NOTE: User is responsible for freeing this string.
|
||||||
|
const char* glslang_default_resource_string();
|
||||||
|
|
||||||
|
// Decodes the resource limits from |config| to |resources|.
|
||||||
|
void glslang_decode_resource_limits(glslang_resource_t* resources, char* config);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||||
|
|
@ -1,245 +0,0 @@
|
||||||
/** @file AgentManager.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __CCX_AGENTMANAGER_H__
|
|
||||||
#define __CCX_AGENTMANAGER_H__
|
|
||||||
|
|
||||||
#include "PluginManager.h"
|
|
||||||
#include "ProtocolIAP.h"
|
|
||||||
#include "ProtocolAnalytics.h"
|
|
||||||
#include "ProtocolShare.h"
|
|
||||||
#include "ProtocolAds.h"
|
|
||||||
#include "ProtocolSocial.h"
|
|
||||||
#include "ProtocolUser.h"
|
|
||||||
#include "ProtocolPush.h"
|
|
||||||
#include "ProtocolCrash.h"
|
|
||||||
#include "ProtocolREC.h"
|
|
||||||
#include "ProtocolCustom.h"
|
|
||||||
#include "ProtocolAdTracking.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/** @brief Plugin_type enum, with inline docs */
|
|
||||||
typedef enum {
|
|
||||||
kPluginAds = 16,/**< enum value is the type of Ads. */
|
|
||||||
kPluginAnalytics = 1,/**< enum value is the type of Analytics. */
|
|
||||||
kPluginIAP = 8,/**< enum value is the type of IAP. */
|
|
||||||
kPluginShare = 2,/**< enum value is the type of Share. */
|
|
||||||
kPluginUser = 32,/**< enum value is the type of User. */
|
|
||||||
kPluginSocial = 4,/**< enum value is the type of Social. */
|
|
||||||
kPluginPush = 64,/**< enum value is the type of Push. */
|
|
||||||
kPluginCrash = 128,/**< enum value is the type of Crash. */
|
|
||||||
kPluginCustom = 256,/**< enum value is the type of Custom. */
|
|
||||||
kPluginREC = 512,/**< enum value is the type of REC. */
|
|
||||||
kPluginAdTracking = 1024,/**< enum value is the type of AdTracking. */
|
|
||||||
}Plugin_type;
|
|
||||||
/**
|
|
||||||
* @class AgentManager
|
|
||||||
*/
|
|
||||||
class AgentManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~AgentManager();
|
|
||||||
/**
|
|
||||||
@brief Get singleton of AgentManager
|
|
||||||
*/
|
|
||||||
|
|
||||||
static AgentManager* getInstance();
|
|
||||||
/**
|
|
||||||
@brief Destory the instance of AgentManager
|
|
||||||
*/
|
|
||||||
static void end();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@breif the init of AgentManager
|
|
||||||
@param the appKey of anysdk
|
|
||||||
@param the appSecret of anysdk
|
|
||||||
@param the privateKey of anysdk
|
|
||||||
@param the url of oauthLoginServer
|
|
||||||
@warning Must invoke this interface before loadAllPlugins
|
|
||||||
*/
|
|
||||||
void init(std::string appKey,std::string appSecret,std::string privateKey,std::string oauthLoginServer);
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief load the plugins
|
|
||||||
*/
|
|
||||||
CC_DEPRECATED_ATTRIBUTE void loadALLPlugin();
|
|
||||||
/**
|
|
||||||
@brief unload the plugins
|
|
||||||
*/
|
|
||||||
CC_DEPRECATED_ATTRIBUTE void unloadALLPlugin();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief load the plugins
|
|
||||||
*/
|
|
||||||
void loadAllPlugins();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief unload the plugins
|
|
||||||
*/
|
|
||||||
void unloadAllPlugins();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get Analytics plugin
|
|
||||||
@return if Analytics plugin exist ,return value is Analytics plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolAnalytics* getAnalyticsPlugin(){return _pAnalytics;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get User plugin
|
|
||||||
@return if User plugin exist ,return value is User plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolUser* getUserPlugin(){return _pUser;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get IAP plugin
|
|
||||||
@return if IAP plugin exist ,return value is IAP plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
std::map<std::string , ProtocolIAP*>* getIAPPlugin(){return &_pluginsIAPMap;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get Share plugin
|
|
||||||
@return if Share plugin exist ,return value is Share plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolShare* getSharePlugin(){return _pShare;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get Social plugin
|
|
||||||
@return if Social plugin exist ,return value is Social plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolSocial* getSocialPlugin(){return _pSocial;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get Ads plugin
|
|
||||||
@return if Ads plugin exist ,return value is Ads plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolAds* getAdsPlugin(){return _pAds;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get Push plugin
|
|
||||||
@return if Push plugin exist ,return value is Push plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolPush* getPushPlugin(){return _pPush;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get Crash plugin
|
|
||||||
@return if Crash plugin exist ,return value is Crash plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolCrash* getCrashPlugin(){return _pCrash;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get Custom plugin
|
|
||||||
@return if Crash plugin exist ,return value is Custom plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolCustom* getCustomPlugin(){return _pCustom;};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get REC plugin
|
|
||||||
@return if REC plugin exist ,return value is REC plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolREC* getRECPlugin(){return _pREC;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get AdTracking plugin
|
|
||||||
@return if AdTracking plugin exist ,return value is AdTracking plugin.
|
|
||||||
else return value is null pointer.
|
|
||||||
*/
|
|
||||||
ProtocolAdTracking* getAdTrackingPlugin(){return _pAdTracking;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get channel ID
|
|
||||||
@return return value is channel ID.
|
|
||||||
*/
|
|
||||||
std::string getChannelId();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get custom param
|
|
||||||
@return return value is custom param for channel.
|
|
||||||
*/
|
|
||||||
std::string getCustomParam();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get framework version
|
|
||||||
@return return value is the version of AnySDKFramework.
|
|
||||||
*/
|
|
||||||
std::string getFrameworkVersion();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@Title: setIsAnaylticsEnabled
|
|
||||||
@Description: choose to open or close
|
|
||||||
@param @param enabled true or false
|
|
||||||
@return void
|
|
||||||
*/
|
|
||||||
void setIsAnaylticsEnabled(bool value){bIsAnaylticsEnabled = value;};
|
|
||||||
/**
|
|
||||||
@Title: isAnaylticsEnabled
|
|
||||||
@Description: the status of Anayltics
|
|
||||||
@param @return true or false
|
|
||||||
@return boolean
|
|
||||||
*/
|
|
||||||
bool isAnaylticsEnabled(){return bIsAnaylticsEnabled;};
|
|
||||||
|
|
||||||
|
|
||||||
void loadPlugin(const char* nodeName,int type);
|
|
||||||
protected:
|
|
||||||
void setDebugMode(bool flag);
|
|
||||||
std::string getSupportPlugin();
|
|
||||||
void release();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
AgentManager(void);
|
|
||||||
|
|
||||||
// Analytics plugin
|
|
||||||
ProtocolAnalytics* _pAnalytics;
|
|
||||||
|
|
||||||
// user plugin
|
|
||||||
ProtocolUser* _pUser;
|
|
||||||
|
|
||||||
// IAP plugins
|
|
||||||
// ProtocolIAP* _pIAP;
|
|
||||||
std::map<std::string , ProtocolIAP*> _pluginsIAPMap;
|
|
||||||
|
|
||||||
// Share plugin
|
|
||||||
ProtocolShare* _pShare;
|
|
||||||
|
|
||||||
// Social plugin
|
|
||||||
ProtocolSocial* _pSocial;
|
|
||||||
|
|
||||||
// Ads plugin
|
|
||||||
ProtocolAds* _pAds;
|
|
||||||
|
|
||||||
// Push plugin
|
|
||||||
ProtocolPush* _pPush;
|
|
||||||
|
|
||||||
// Crash plugin
|
|
||||||
ProtocolCrash* _pCrash;
|
|
||||||
|
|
||||||
// Custom plugin
|
|
||||||
ProtocolCustom* _pCustom;
|
|
||||||
|
|
||||||
// REC plugin
|
|
||||||
ProtocolREC* _pREC;
|
|
||||||
|
|
||||||
// AdTracking plugin
|
|
||||||
ProtocolAdTracking* _pAdTracking;
|
|
||||||
|
|
||||||
bool bIsAnaylticsEnabled;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} //namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_AGENTMANAGER_H__ */
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/** @file JSBRelation.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_JSBRELATION_H__
|
|
||||||
#define __CCX_JSBRELATION_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @class JSBRelation
|
|
||||||
*/
|
|
||||||
class JSBRelation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static string getMethodsOfPlugin(PluginProtocol* plugin);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
}} //namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_JSBRELATION_H__ */
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/** @file PluginFactory.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PLUGIN_FACTORY_H__
|
|
||||||
#define __CCX_PLUGIN_FACTORY_H__
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
class PluginProtocol;
|
|
||||||
class PluginManager;
|
|
||||||
/**
|
|
||||||
* @class PluginFactory
|
|
||||||
*/
|
|
||||||
class PluginFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~PluginFactory();
|
|
||||||
/**
|
|
||||||
@brief Get singleton of PluginFactory
|
|
||||||
*/
|
|
||||||
static PluginFactory* getInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Destory the instance of PluginFactory
|
|
||||||
*/
|
|
||||||
static void purgeFactory();
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class PluginManager;
|
|
||||||
PluginFactory(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief create the plugin by name and type
|
|
||||||
@param the name of plugin
|
|
||||||
@param the type of plugin
|
|
||||||
*/
|
|
||||||
PluginProtocol* createPlugin(const char* name, int pluginType);
|
|
||||||
};
|
|
||||||
|
|
||||||
}} //namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PLUGIN_FACTORY_H__ */
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#ifndef __PLUGIN_JAVA_DATA_H__
|
|
||||||
#define __PLUGIN_JAVA_DATA_H__
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <jni.h>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
typedef struct _PluginJavaData_
|
|
||||||
{
|
|
||||||
jobject jobj;
|
|
||||||
std::string jclassName;
|
|
||||||
} PluginJavaData;
|
|
||||||
|
|
||||||
}} //namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif // __PLUGIN_JAVA_DATA_H__
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
#ifndef __PLUGIN_JNI_HELPER_H__
|
|
||||||
#define __PLUGIN_JNI_HELPER_H__
|
|
||||||
|
|
||||||
#include <jni.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk {namespace framework{
|
|
||||||
|
|
||||||
typedef struct PluginJniMethodInfo_
|
|
||||||
{
|
|
||||||
JNIEnv * env;
|
|
||||||
jclass classID;
|
|
||||||
jmethodID methodID;
|
|
||||||
} PluginJniMethodInfo;
|
|
||||||
|
|
||||||
class PluginJniHelper
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static JavaVM* getJavaVM();
|
|
||||||
static void setJavaVM(JavaVM *javaVM);
|
|
||||||
static JNIEnv* getEnv();
|
|
||||||
|
|
||||||
static bool getStaticMethodInfo(PluginJniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode);
|
|
||||||
static bool getMethodInfo(PluginJniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode);
|
|
||||||
static std::string jstring2string(jstring jstr);
|
|
||||||
static jstring newStringUTF(JNIEnv* env, const std::string& utf8Str);
|
|
||||||
|
|
||||||
static bool setClassLoaderFrom(jobject nativeActivityInstance);
|
|
||||||
|
|
||||||
static jmethodID loadclassMethod_methodID;
|
|
||||||
static jobject classloader;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static JavaVM *_psJavaVM;
|
|
||||||
static bool getMethodInfo_DefaultClassLoader(PluginJniMethodInfo &methodinfo,
|
|
||||||
const char *className,
|
|
||||||
const char *methodName,
|
|
||||||
const char *paramCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif // __PLUGIN_JNI_HELPER_H__
|
|
||||||
|
|
@ -1,156 +0,0 @@
|
||||||
#ifndef __PLUGIN_JNI_MACROS_H__
|
|
||||||
#define __PLUGIN_JNI_MACROS_H__
|
|
||||||
|
|
||||||
#define return_if_fails(cond) if (!(cond)) return;
|
|
||||||
#define return_val_if_fails(cond, ret) if(!(cond)) return (ret);
|
|
||||||
|
|
||||||
#define CALL_BASERET_JAVA_FUNC_WITH_PARAM(retType, paramCode, param, retCode, defaultRet) \
|
|
||||||
retType ret = defaultRet; \
|
|
||||||
return_val_if_fails(funcName != NULL && strlen(funcName) > 0, ret); \
|
|
||||||
return_val_if_fails(paramCode != NULL && strlen(paramCode) > 0, ret); \
|
|
||||||
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz); \
|
|
||||||
return_val_if_fails(pData != NULL, ret); \
|
|
||||||
\
|
|
||||||
PluginJniMethodInfo t; \
|
|
||||||
if (PluginJniHelper::getMethodInfo(t \
|
|
||||||
, pData->jclassName.c_str() \
|
|
||||||
, funcName \
|
|
||||||
, paramCode)) \
|
|
||||||
{ \
|
|
||||||
ret = t.env->Call##retCode##Method(pData->jobj, t.methodID, param); \
|
|
||||||
t.env->DeleteLocalRef(t.classID); \
|
|
||||||
} \
|
|
||||||
return ret; \
|
|
||||||
|
|
||||||
|
|
||||||
#define CALL_BASERET_JAVA_FUNC(retType, paramCode, retCode, defaultRet) \
|
|
||||||
retType ret = defaultRet; \
|
|
||||||
return_val_if_fails(funcName != NULL && strlen(funcName) > 0, ret); \
|
|
||||||
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz); \
|
|
||||||
return_val_if_fails(pData != NULL, ret); \
|
|
||||||
\
|
|
||||||
PluginJniMethodInfo t; \
|
|
||||||
if (PluginJniHelper::getMethodInfo(t \
|
|
||||||
, pData->jclassName.c_str() \
|
|
||||||
, funcName \
|
|
||||||
, paramCode)) \
|
|
||||||
{ \
|
|
||||||
ret = t.env->Call##retCode##Method(pData->jobj, t.methodID); \
|
|
||||||
t.env->DeleteLocalRef(t.classID); \
|
|
||||||
} \
|
|
||||||
return ret; \
|
|
||||||
|
|
||||||
|
|
||||||
#define CALL_JAVA_FUNC_WITH_VALIST(retCode) \
|
|
||||||
std::vector<PluginParam*> allParams; \
|
|
||||||
if (NULL != param) \
|
|
||||||
{ \
|
|
||||||
allParams.push_back(param); \
|
|
||||||
\
|
|
||||||
va_list argp; \
|
|
||||||
PluginParam* pArg = NULL; \
|
|
||||||
va_start( argp, param ); \
|
|
||||||
while (1) \
|
|
||||||
{ \
|
|
||||||
pArg = va_arg(argp, PluginParam*); \
|
|
||||||
if (pArg == NULL) \
|
|
||||||
break; \
|
|
||||||
\
|
|
||||||
allParams.push_back(pArg); \
|
|
||||||
} \
|
|
||||||
va_end(argp); \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
return call##retCode##FuncWithParam(funcName, allParams); \
|
|
||||||
|
|
||||||
|
|
||||||
#define CALL_JAVA_FUNC(retType, retCode, defaultRet, jRetCode) \
|
|
||||||
retType ret = defaultRet; \
|
|
||||||
PluginJavaData* pData = PluginUtils::getPluginJavaData(this); \
|
|
||||||
if (NULL == pData) { \
|
|
||||||
PluginUtils::outputLog(ANDROID_LOG_ERROR, "PluginProtocol", "Can't find java data for plugin : %s", this->getPluginName()); \
|
|
||||||
return ret; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
std::string paramCode; \
|
|
||||||
int nParamNum = params.size(); \
|
|
||||||
if (0 == nParamNum) \
|
|
||||||
{ \
|
|
||||||
paramCode = "()"; \
|
|
||||||
paramCode.append(jRetCode); \
|
|
||||||
ret = PluginUtils::callJava##retCode##FuncWithName(this, funcName); \
|
|
||||||
} else \
|
|
||||||
{ \
|
|
||||||
PluginParam* pRetParam = NULL; \
|
|
||||||
bool needDel = false; \
|
|
||||||
if (nParamNum == 1) { \
|
|
||||||
pRetParam = params[0]; \
|
|
||||||
} else { \
|
|
||||||
std::map<std::string, PluginParam*> allParams; \
|
|
||||||
for (int i = 0; i < nParamNum; i++) \
|
|
||||||
{ \
|
|
||||||
PluginParam* pArg = params[i]; \
|
|
||||||
if (pArg == NULL) \
|
|
||||||
{ \
|
|
||||||
break; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
char strKey[8] = { 0 }; \
|
|
||||||
sprintf(strKey, "Param%d", i + 1); \
|
|
||||||
allParams[strKey] = pArg; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
pRetParam = new PluginParam(allParams); \
|
|
||||||
needDel = true; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
switch(pRetParam->getCurrentType()) \
|
|
||||||
{ \
|
|
||||||
case PluginParam::kParamTypeInt: \
|
|
||||||
paramCode = "(I)"; \
|
|
||||||
paramCode.append(jRetCode); \
|
|
||||||
ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), pRetParam->getIntValue()); \
|
|
||||||
break; \
|
|
||||||
case PluginParam::kParamTypeFloat: \
|
|
||||||
paramCode = "(F)"; \
|
|
||||||
paramCode.append(jRetCode); \
|
|
||||||
ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), pRetParam->getFloatValue()); \
|
|
||||||
break; \
|
|
||||||
case PluginParam::kParamTypeBool: \
|
|
||||||
paramCode = "(Z)"; \
|
|
||||||
paramCode.append(jRetCode); \
|
|
||||||
ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), pRetParam->getBoolValue()); \
|
|
||||||
break; \
|
|
||||||
case PluginParam::kParamTypeString: \
|
|
||||||
{ \
|
|
||||||
jstring jstr = PluginJniHelper::newStringUTF(PluginUtils::getEnv(), pRetParam->getStringValue()); \
|
|
||||||
paramCode = "(Ljava/lang/String;)"; \
|
|
||||||
paramCode.append(jRetCode); \
|
|
||||||
ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), jstr); \
|
|
||||||
PluginUtils::getEnv()->DeleteLocalRef(jstr); \
|
|
||||||
} \
|
|
||||||
break; \
|
|
||||||
case PluginParam::kParamTypeStringMap: \
|
|
||||||
case PluginParam::kParamTypeMap: \
|
|
||||||
{ \
|
|
||||||
jobject jMap = PluginUtils::getJObjFromParam(pRetParam); \
|
|
||||||
paramCode = "(Lorg/json/JSONObject;)"; \
|
|
||||||
paramCode.append(jRetCode); \
|
|
||||||
ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), jMap); \
|
|
||||||
PluginUtils::getEnv()->DeleteLocalRef(jMap); \
|
|
||||||
} \
|
|
||||||
break; \
|
|
||||||
default: \
|
|
||||||
break; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
if (needDel && pRetParam != NULL) \
|
|
||||||
{ \
|
|
||||||
delete pRetParam; \
|
|
||||||
pRetParam = NULL; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
return ret; \
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __PLUGIN_JNI_MACROS_H__
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/** @file PluginFactory.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PLUGINMANAGER_H__
|
|
||||||
#define __CCX_PLUGINMANAGER_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include "PluginFactory.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @class PluginManager
|
|
||||||
*/
|
|
||||||
class PluginManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~PluginManager();
|
|
||||||
/**
|
|
||||||
@brief Get singleton of PluginManager
|
|
||||||
*/
|
|
||||||
static PluginManager* getInstance();
|
|
||||||
/**
|
|
||||||
@brief Destory the instance of PluginManager
|
|
||||||
*/
|
|
||||||
static void end();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief load the plugin by name and type
|
|
||||||
@param the name of plugin
|
|
||||||
@param the type of plugin
|
|
||||||
*/
|
|
||||||
PluginProtocol* loadPlugin(const char* name, int pluginType);
|
|
||||||
/**
|
|
||||||
@brief unload the plugin by name and type
|
|
||||||
@param the name of plugin
|
|
||||||
@param the type of plugin
|
|
||||||
*/
|
|
||||||
void unloadPlugin(const char* name, int pluginType = 0);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
PluginManager(void);
|
|
||||||
std::map<std::string, PluginProtocol*> _pluginsMap;
|
|
||||||
// bool _isDebug;
|
|
||||||
};
|
|
||||||
|
|
||||||
}} //namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PLUGINMANAGER_H__ */
|
|
||||||
|
|
@ -1,126 +0,0 @@
|
||||||
/** @file PluginParam.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PLUGIN_PARAM_H__
|
|
||||||
#define __CCX_PLUGIN_PARAM_H__
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
/// \typedef std::map<std::string, std::string> StringMap
|
|
||||||
/// typedef YString.
|
|
||||||
typedef std::map<std::string, std::string> StringMap;
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
class PluginProtocol;
|
|
||||||
/**
|
|
||||||
* @class PluginParam
|
|
||||||
*/
|
|
||||||
class PluginParam
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
@brief the default constructor of PluginParam
|
|
||||||
*/
|
|
||||||
PluginParam();
|
|
||||||
|
|
||||||
virtual ~PluginParam();
|
|
||||||
/**
|
|
||||||
@brief the constructor of PluginParam
|
|
||||||
@param the value is Integer
|
|
||||||
*/
|
|
||||||
PluginParam(int nValue);
|
|
||||||
/**
|
|
||||||
@brief the constructor of PluginParam
|
|
||||||
@param the value is float
|
|
||||||
*/
|
|
||||||
PluginParam(float fValue);
|
|
||||||
/**
|
|
||||||
@brief the constructor of PluginParam
|
|
||||||
@param the value is boolean
|
|
||||||
*/
|
|
||||||
PluginParam(bool bValue);
|
|
||||||
/**
|
|
||||||
@brief the default constructor of PluginParam
|
|
||||||
@param the value is char
|
|
||||||
*/
|
|
||||||
PluginParam(const char* strValue);
|
|
||||||
/**
|
|
||||||
@brief the default constructor of PluginParam
|
|
||||||
@param the value is StringMap
|
|
||||||
*/
|
|
||||||
PluginParam(StringMap strMapValue);
|
|
||||||
|
|
||||||
typedef enum{
|
|
||||||
kParamTypeNull = 0,
|
|
||||||
kParamTypeInt,
|
|
||||||
kParamTypeFloat,
|
|
||||||
kParamTypeBool,
|
|
||||||
kParamTypeString,
|
|
||||||
kParamTypeStringMap,
|
|
||||||
kParamTypeMap,
|
|
||||||
} ParamType;
|
|
||||||
/**
|
|
||||||
@brief get the ParamType of value
|
|
||||||
*/
|
|
||||||
inline ParamType getCurrentType() {
|
|
||||||
return _type;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
@brief get the int value
|
|
||||||
*/
|
|
||||||
inline int getIntValue() {
|
|
||||||
return _intValue;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
@brief get the float value
|
|
||||||
*/
|
|
||||||
inline float getFloatValue() {
|
|
||||||
return _floatValue;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
@brief get the boolean value
|
|
||||||
*/
|
|
||||||
inline bool getBoolValue() {
|
|
||||||
return _boolValue;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
@brief get the char value
|
|
||||||
*/
|
|
||||||
inline const char* getStringValue() {
|
|
||||||
return _strValue.c_str();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
@brief get the map of value
|
|
||||||
*/
|
|
||||||
inline std::map<std::string, PluginParam*> getMapValue() {
|
|
||||||
return _mapValue;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
@brief get the StringMap value
|
|
||||||
*/
|
|
||||||
inline StringMap getStrMapValue() {
|
|
||||||
return _strMapValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class PluginProtocol;
|
|
||||||
/**
|
|
||||||
@brief the constructor of PluginParam
|
|
||||||
@param the map of value
|
|
||||||
*/
|
|
||||||
PluginParam(std::map<std::string, PluginParam*> mapValue);
|
|
||||||
|
|
||||||
private:
|
|
||||||
ParamType _type;
|
|
||||||
|
|
||||||
int _intValue;
|
|
||||||
float _floatValue;
|
|
||||||
bool _boolValue;
|
|
||||||
std::string _strValue;
|
|
||||||
std::map<std::string, PluginParam*> _mapValue;
|
|
||||||
StringMap _strMapValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
}} //namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PLUGIN_PARAM_H__ */
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
/** @file PluginProtocol.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_IPLUGIN_H__
|
|
||||||
#define __CCX_IPLUGIN_H__
|
|
||||||
|
|
||||||
#include "PluginParam.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
||||||
#define CC_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
|
|
||||||
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
||||||
#define CC_DEPRECATED_ATTRIBUTE __declspec(deprecated)
|
|
||||||
#else
|
|
||||||
#define CC_DEPRECATED_ATTRIBUTE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @class PluginProtocol
|
|
||||||
* @brief The super class for all plugins.
|
|
||||||
*/
|
|
||||||
class PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~PluginProtocol() {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief set plugin name
|
|
||||||
*@param the name of plugin
|
|
||||||
*/
|
|
||||||
virtual void setPluginName(const char* name) = 0 ;
|
|
||||||
/**
|
|
||||||
*@brief get plugin name
|
|
||||||
*@return the name of plugin
|
|
||||||
*/
|
|
||||||
virtual const char* getPluginName() = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief get the version of plugin
|
|
||||||
*@return the version of plugin
|
|
||||||
*/
|
|
||||||
virtual std::string getPluginVersion();
|
|
||||||
/**
|
|
||||||
*@brief get the version of sdk
|
|
||||||
*@return the version of sdk
|
|
||||||
*/
|
|
||||||
virtual std::string getSDKVersion();
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief switch debug plug-in on/off
|
|
||||||
*@param the value of on/off
|
|
||||||
*/
|
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void setDebugMode(bool bDebug);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param PluginParam* param
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void callFuncWithParam(const char* funcName, PluginParam* param, ...);
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param std::vector<PluginParam*> params
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void callFuncWithParam(const char* funcName, std::vector<PluginParam*> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param PluginParam* param
|
|
||||||
*@return string
|
|
||||||
*/
|
|
||||||
virtual std::string callStringFuncWithParam(const char* funcName, PluginParam* param, ...);
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param std::vector<PluginParam*> params
|
|
||||||
*@return string
|
|
||||||
*/
|
|
||||||
virtual std::string callStringFuncWithParam(const char* funcName, std::vector<PluginParam*> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param PluginParam* param
|
|
||||||
*@return int
|
|
||||||
*/
|
|
||||||
virtual int callIntFuncWithParam(const char* funcName, PluginParam* param, ...);
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param std::vector<PluginParam*> params
|
|
||||||
*@return int
|
|
||||||
*/
|
|
||||||
virtual int callIntFuncWithParam(const char* funcName, std::vector<PluginParam*> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param PluginParam* param
|
|
||||||
*@return bool
|
|
||||||
*/
|
|
||||||
virtual bool callBoolFuncWithParam(const char* funcName, PluginParam* param, ...);
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param std::vector<PluginParam*> params
|
|
||||||
*@return bool
|
|
||||||
*/
|
|
||||||
virtual bool callBoolFuncWithParam(const char* funcName, std::vector<PluginParam*> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param PluginParam* param
|
|
||||||
*@return float
|
|
||||||
*/
|
|
||||||
virtual float callFloatFuncWithParam(const char* funcName, PluginParam* param, ...);
|
|
||||||
/**
|
|
||||||
*@brief methods for reflections
|
|
||||||
*@param function name
|
|
||||||
*@param std::vector<PluginParam*> params
|
|
||||||
*@return float
|
|
||||||
*/
|
|
||||||
virtual float callFloatFuncWithParam(const char* funcName, std::vector<PluginParam*> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Check function the plugin support or not
|
|
||||||
@param the name of plugin
|
|
||||||
@return if the function support ,return true
|
|
||||||
else retur false
|
|
||||||
*/
|
|
||||||
virtual bool isFunctionSupported(std::string functionName);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} //namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_IPLUGIN_H__ */
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
#ifndef __PLUGIN_UTILS_H__
|
|
||||||
#define __PLUGIN_UTILS_H__
|
|
||||||
|
|
||||||
#include "PluginJniHelper.h"
|
|
||||||
#include "PluginJavaData.h"
|
|
||||||
#include <map>
|
|
||||||
#include <list>
|
|
||||||
#include "PluginParam.h"
|
|
||||||
#include "PluginJniMacros.h"
|
|
||||||
#include <android/log.h>
|
|
||||||
//#include <android_native_app_glue.h>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
class PluginProtocol;
|
|
||||||
class PluginUtils
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
//cjh static void initPluginWrapper(android_app* app);
|
|
||||||
static jobject createJavaMapObject(std::map<std::string, std::string>* paramMap);
|
|
||||||
static jobject createJavaListObject(std::list<std::string>* paramList);
|
|
||||||
static void initJavaPlugin(PluginProtocol* pPlugin, jobject jObj, const char* className, int type);
|
|
||||||
static JNIEnv* getEnv();
|
|
||||||
|
|
||||||
static PluginJavaData* getPluginJavaData(PluginProtocol* pKeyObj);
|
|
||||||
static void setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pData, int type);
|
|
||||||
static void erasePluginJavaData(PluginProtocol* pKeyObj,int type);
|
|
||||||
static void erasePluginJavaData(std::string key);
|
|
||||||
|
|
||||||
static PluginProtocol* getPluginPtr(std::string className);
|
|
||||||
|
|
||||||
static jobject getJObjFromParam(PluginParam* param);
|
|
||||||
|
|
||||||
// methods have no return value
|
|
||||||
template <typename T>
|
|
||||||
static void callJavaFunctionWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param)
|
|
||||||
{
|
|
||||||
return_if_fails(funcName != NULL && strlen(funcName) > 0);
|
|
||||||
return_if_fails(paramCode != NULL && strlen(paramCode) > 0);
|
|
||||||
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz);
|
|
||||||
return_if_fails(pData != NULL);
|
|
||||||
|
|
||||||
PluginJniMethodInfo t;
|
|
||||||
if (PluginJniHelper::getMethodInfo(t
|
|
||||||
, pData->jclassName.c_str()
|
|
||||||
, funcName
|
|
||||||
, paramCode))
|
|
||||||
{
|
|
||||||
t.env->CallVoidMethod(pData->jobj, t.methodID, param);
|
|
||||||
t.env->DeleteLocalRef(t.classID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static void callJavaFunctionWithName(PluginProtocol* thiz, const char* funcName)
|
|
||||||
{
|
|
||||||
return_if_fails(funcName != NULL && strlen(funcName) > 0);
|
|
||||||
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz);
|
|
||||||
return_if_fails(pData != NULL);
|
|
||||||
|
|
||||||
PluginJniMethodInfo t;
|
|
||||||
if (PluginJniHelper::getMethodInfo(t
|
|
||||||
, pData->jclassName.c_str()
|
|
||||||
, funcName
|
|
||||||
, "()V"))
|
|
||||||
{
|
|
||||||
t.env->CallVoidMethod(pData->jobj, t.methodID);
|
|
||||||
t.env->DeleteLocalRef(t.classID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// methods return value is string
|
|
||||||
template <typename T>
|
|
||||||
static std::string callJavaStringFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param)
|
|
||||||
{
|
|
||||||
std::string ret = "";
|
|
||||||
return_val_if_fails(funcName != NULL && strlen(funcName) > 0, ret);
|
|
||||||
return_val_if_fails(paramCode != NULL && strlen(paramCode) > 0, ret);
|
|
||||||
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz);
|
|
||||||
return_val_if_fails(pData != NULL, ret);
|
|
||||||
|
|
||||||
PluginJniMethodInfo t;
|
|
||||||
if (PluginJniHelper::getMethodInfo(t
|
|
||||||
, pData->jclassName.c_str()
|
|
||||||
, funcName
|
|
||||||
, paramCode))
|
|
||||||
{
|
|
||||||
jstring strRet = (jstring)t.env->CallObjectMethod(pData->jobj, t.methodID, param);
|
|
||||||
ret = PluginJniHelper::jstring2string(strRet);
|
|
||||||
t.env->DeleteLocalRef(t.classID);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
static std::string callJavaStringFuncWithName(PluginProtocol* thiz, const char* funcName)
|
|
||||||
{
|
|
||||||
std::string ret = "";
|
|
||||||
return_val_if_fails(funcName != NULL && strlen(funcName) > 0, ret);
|
|
||||||
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz);
|
|
||||||
return_val_if_fails(pData != NULL, ret);
|
|
||||||
|
|
||||||
PluginJniMethodInfo t;
|
|
||||||
if (PluginJniHelper::getMethodInfo(t
|
|
||||||
, pData->jclassName.c_str()
|
|
||||||
, funcName
|
|
||||||
, "()Ljava/lang/String;"))
|
|
||||||
{
|
|
||||||
jstring strRet = (jstring) t.env->CallObjectMethod(pData->jobj, t.methodID);
|
|
||||||
ret = PluginJniHelper::jstring2string(strRet);
|
|
||||||
t.env->DeleteLocalRef(t.classID);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// methods return value is int
|
|
||||||
template <typename T>
|
|
||||||
static int callJavaIntFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param)
|
|
||||||
{
|
|
||||||
CALL_BASERET_JAVA_FUNC_WITH_PARAM(int, paramCode, param, Int, 0)
|
|
||||||
}
|
|
||||||
static int callJavaIntFuncWithName(PluginProtocol* thiz, const char* funcName)
|
|
||||||
{
|
|
||||||
CALL_BASERET_JAVA_FUNC(int, "()I", Int, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// methods return value is float
|
|
||||||
template <typename T>
|
|
||||||
static float callJavaFloatFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param)
|
|
||||||
{
|
|
||||||
CALL_BASERET_JAVA_FUNC_WITH_PARAM(float, paramCode, param, Float, 0.0f)
|
|
||||||
}
|
|
||||||
static float callJavaFloatFuncWithName(PluginProtocol* thiz, const char* funcName)
|
|
||||||
{
|
|
||||||
CALL_BASERET_JAVA_FUNC(float, "()F", Float, 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// methods return value is bool
|
|
||||||
template <typename T>
|
|
||||||
static bool callJavaBoolFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param)
|
|
||||||
{
|
|
||||||
CALL_BASERET_JAVA_FUNC_WITH_PARAM(bool, paramCode, param, Boolean, false)
|
|
||||||
}
|
|
||||||
static bool callJavaBoolFuncWithName(PluginProtocol* thiz, const char* funcName)
|
|
||||||
{
|
|
||||||
CALL_BASERET_JAVA_FUNC(bool, "()Z", Boolean, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
static void callJavaFunctionWithName_string_map(PluginProtocol* thiz, const char* funcName, const char* keyParam, std::map<std::string, std::string>* paramMap);
|
|
||||||
|
|
||||||
static void outputLog(int type, const char* logTag, const char* pFormat, ...);
|
|
||||||
static void output(int type, const char* logTag, const char* contents);
|
|
||||||
|
|
||||||
static void resetLogLevel();
|
|
||||||
private:
|
|
||||||
static std::string _logLevel;
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif //__PLUGIN_UTILS_H__
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
/** @file ProtocolAdTracking.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_ADTRACKING_H__
|
|
||||||
#define __CCX_PROTOCOL_ADTRACKING_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/**
|
|
||||||
*@class ProtocolAdTracking
|
|
||||||
*@brief the interface of AdTracking
|
|
||||||
*/
|
|
||||||
class ProtocolAdTracking : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @Title: onRegister
|
|
||||||
* @Description: Call this method if you want to track register events as happening during a section.
|
|
||||||
* @param userId user identifier
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
virtual void onRegister(const char* userId) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @Title: onLogin
|
|
||||||
* @Description:Call this method if you want to track login events as happening during a section.
|
|
||||||
* @param userInfo The details of this parameters are already covered by document.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
virtual void onLogin(std::map<std::string, std::string> userInfo) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @Title: onPay
|
|
||||||
* @Description: Call this method if you want to track pay events as happening during a section.
|
|
||||||
* @param productInfo The details of this parameters are already covered by document.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
virtual void onPay(std::map<std::string, std::string> productInfo) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @Title: trackEvent
|
|
||||||
* @Description: Call this method if you want to track custom events with parameters as happening during a section.
|
|
||||||
* @param eventId The custom event name.
|
|
||||||
* @param paramMap The details of this parameters are already covered by document.
|
|
||||||
*/
|
|
||||||
virtual void trackEvent(const char* eventId, std::map<std::string, std::string>* paramMap = NULL) = 0;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* ----- #ifndef __CCX_PROTOCOL_ADTRACKING_H__ ----- */
|
|
||||||
|
|
@ -1,133 +0,0 @@
|
||||||
/** @file ProtocolAds.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_ADS_H__
|
|
||||||
#define __CCX_PROTOCOL_ADS_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/// \typedef std::map<std::string, std::string> TAdsDeveloperInfo
|
|
||||||
/// typedef TAdsDeveloperInfo.
|
|
||||||
typedef std::map<std::string, std::string> TAdsDeveloperInfo;
|
|
||||||
/// \typedef std::map<std::string, std::string> TAdsInfo
|
|
||||||
/// typedef TAdsInfo.
|
|
||||||
typedef std::map<std::string, std::string> TAdsInfo;
|
|
||||||
/** @brief AdsResultCode enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kAdsReceived = 0, /**< enum the callback: the ad is received is at center. */
|
|
||||||
|
|
||||||
kAdsShown, /**< enum the callback: the advertisement dismissed. */
|
|
||||||
kAdsDismissed, /**< enum the callback: the advertisement dismissed. */
|
|
||||||
|
|
||||||
kPointsSpendSucceed, /**< enum the callback: the points spend succeed. */
|
|
||||||
kPointsSpendFailed, /**< enum the callback: the points spend failed. */
|
|
||||||
|
|
||||||
kNetworkError, /**< enum the callback of Network error at center. */
|
|
||||||
kUnknownError, /**< enum the callback of Unknown error. */
|
|
||||||
kOfferWallOnPointsChanged, /**< enum the callback of Changing the point of offerwall. */
|
|
||||||
kRewardedVideoWithReward,/**< enum the callback of receiving the reward of rewardedvideo. */
|
|
||||||
kInAppPurchaseFinished,/**< enum the callback of finishing IAP ad. */
|
|
||||||
kAdsClicked,/**< enum the callback of the advertisement clicked. */
|
|
||||||
kAdsExtension = 40000 /**< enum value is extension code . */
|
|
||||||
} AdsResultCode;
|
|
||||||
/** @brief AdsPos enum, with inline docs */
|
|
||||||
typedef enum {
|
|
||||||
kPosCenter = 0,/**< enum the toolbar is at center. */
|
|
||||||
kPosTop,/**< enum the toolbar is at top. */
|
|
||||||
kPosTopLeft,/**< enum the toolbar is at topleft. */
|
|
||||||
kPosTopRight,/**< enum the toolbar is at topright. */
|
|
||||||
kPosBottom,/**< enum the toolbar is at bottom. */
|
|
||||||
kPosBottomLeft,/**< enum the toolbar is at bottomleft. */
|
|
||||||
kPosBottomRight,/**< enum the toolbar is at bottomright. */
|
|
||||||
} AdsPos;
|
|
||||||
/** @brief AdsType enum, with inline docs */
|
|
||||||
typedef enum {
|
|
||||||
AD_TYPE_BANNER = 0,/**< enum value is banner ads . */
|
|
||||||
AD_TYPE_FULLSCREEN,/**< enum value is fullscreen ads . */
|
|
||||||
AD_TYPE_MOREAPP,/**< enum value is moreapp ads . */
|
|
||||||
AD_TYPE_OFFERWALL,/**< enum value is offerwall ads . */
|
|
||||||
AD_TYPE_REWARDEDVIDEO,/**< enum value is rewarded video ads . */
|
|
||||||
AD_TYPE_NATIVEEXPRESS,/**< enum value is Native express ads . */
|
|
||||||
AD_TYPE_NATIVEADVANCED,/**< enum value is Native advanced ads . */
|
|
||||||
} AdsType;
|
|
||||||
|
|
||||||
class ProtocolAds;
|
|
||||||
class AdsListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief The advertisement request result
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*/
|
|
||||||
virtual void onAdsResult(AdsResultCode code, const char* msg) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ProtocolAds : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief show adview
|
|
||||||
@param the type of ads
|
|
||||||
@param the idx of ads
|
|
||||||
*/
|
|
||||||
virtual void showAds(AdsType adsType, int idx = 1) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Hide the adview
|
|
||||||
@param the type of ads
|
|
||||||
@param the idx of ads
|
|
||||||
*/
|
|
||||||
virtual void hideAds(AdsType adsType, int idx = 1) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief preload the adview
|
|
||||||
@param the type of ads
|
|
||||||
@param the idx of ads
|
|
||||||
*/
|
|
||||||
virtual void preloadAds(AdsType adsType, int idx = 1)= 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief Query the points of player
|
|
||||||
*@return the point
|
|
||||||
*/
|
|
||||||
virtual float queryPoints() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief Spend the points.
|
|
||||||
Use this method to notify server spend points.
|
|
||||||
*@param points Need spend number of points
|
|
||||||
*/
|
|
||||||
virtual void spendPoints(int points) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief set the Ads listener
|
|
||||||
@param pListener The callback object for Ads result
|
|
||||||
*/
|
|
||||||
virtual void setAdsListener(AdsListener* listener) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief get pListener The callback object for Ads result
|
|
||||||
@return the listener
|
|
||||||
*/
|
|
||||||
virtual AdsListener* getAdsListener() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Is it supportive of this type of ads
|
|
||||||
@param the type of ads
|
|
||||||
@return if it is supportive ,return true
|
|
||||||
else retur false
|
|
||||||
*/
|
|
||||||
virtual bool isAdTypeSupported(AdsType adType) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PROTOCOL_ADS_H__ */
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
/** @file ProtocolAnalytics.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_ANALYTICS_H__
|
|
||||||
#define __CCX_PROTOCOL_ANALYTICS_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/// \typedef std::map<std::string, std::string> LogEventParamPair
|
|
||||||
/// typedef LogEventParamPair.
|
|
||||||
typedef std::pair< std::string, std::string > LogEventParamPair;
|
|
||||||
/// \typedef std::map<std::string, std::string> LogEventParamMap
|
|
||||||
/// typedef LogEventParamMap.
|
|
||||||
typedef std::map< std::string, std::string > LogEventParamMap;
|
|
||||||
typedef enum {
|
|
||||||
ANONYMOUS,/**< enum value is anonymous typek. */
|
|
||||||
REGISTED,/**< enum value is registed type. */
|
|
||||||
SINA_WEIBO,/**< enum value is sineweibo type. */
|
|
||||||
TENCENT_WEIBO,/**< enum value is tecentweibo type */
|
|
||||||
QQ,/**< enum value is qq type */
|
|
||||||
ND91,/**< enum value is nd91 type. */
|
|
||||||
} AccountType;
|
|
||||||
typedef enum {
|
|
||||||
LOGIN,/**< enum value is the login operate. */
|
|
||||||
LOGOUT,/**< enum value is the logout operate. */
|
|
||||||
REGISTER,/**< enum value is the register operate. */
|
|
||||||
} AccountOperate;
|
|
||||||
typedef enum {
|
|
||||||
MALE,/**< enum value is male. */
|
|
||||||
FEMALE,/**< enum value is female. */
|
|
||||||
UNKNOWN,/**< enum value is unknow. */
|
|
||||||
|
|
||||||
} AccountGender;
|
|
||||||
typedef enum {
|
|
||||||
GUIDE_LINE,/**< enum value is the guideline type.. */
|
|
||||||
MAIN_LINE,/**< enum value is the mainline type.. */
|
|
||||||
BRANCH_LINE,/**<enum value is the branchline type.. */
|
|
||||||
DAILY,/**< enum value is the daily type.. */
|
|
||||||
ACTIVITY,/**< enum value is the activity type. */
|
|
||||||
OTHER,/**< enum value is other type. */
|
|
||||||
} TaskType;
|
|
||||||
/**
|
|
||||||
*@class ProtocolAnalytics
|
|
||||||
*@brief the interface of Analytics
|
|
||||||
*/
|
|
||||||
class ProtocolAnalytics : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Start a new session.
|
|
||||||
*/
|
|
||||||
virtual void startSession() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Stop a session.
|
|
||||||
@warning This interface only worked on android
|
|
||||||
*/
|
|
||||||
virtual void stopSession() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Set the timeout for expiring a session.
|
|
||||||
@param millis In milliseconds as the unit of time.
|
|
||||||
@note It must be invoked before calling startSession.
|
|
||||||
*/
|
|
||||||
virtual void setSessionContinueMillis(long millis) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief log an error
|
|
||||||
@param errorId The identity of error
|
|
||||||
@param message Extern message for the error
|
|
||||||
*/
|
|
||||||
virtual void logError(const char* errorId, const char* message) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief log an event.
|
|
||||||
@param eventId The identity of event
|
|
||||||
@param paramMap Extern parameters of the event, use NULL if not needed.
|
|
||||||
*/
|
|
||||||
virtual void logEvent(const char* eventId, LogEventParamMap* paramMap = NULL) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Track an event begin.
|
|
||||||
@param eventId The identity of event
|
|
||||||
*/
|
|
||||||
virtual void logTimedEventBegin(const char* eventId) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Track an event end.
|
|
||||||
@param eventId The identity of event
|
|
||||||
*/
|
|
||||||
virtual void logTimedEventEnd(const char* eventId) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Whether to catch uncaught exceptions to server.
|
|
||||||
@warning This interface only worked on android.
|
|
||||||
*/
|
|
||||||
virtual void setCaptureUncaughtException(bool enabled) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __CCX_PROTOCOL_ANALYTICS_H__ */
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
/** @file ProtocolCrash.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_CRASH_H__
|
|
||||||
#define __CCX_PROTOCOL_CRASH_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
class ProtocolCrash : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* set user identifier
|
|
||||||
*
|
|
||||||
* @param userInfo
|
|
||||||
*/
|
|
||||||
virtual void setUserIdentifier(const char* identifier) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The uploader captured in exception information
|
|
||||||
*
|
|
||||||
* @param message Set the custom information
|
|
||||||
* @param exception The exception
|
|
||||||
*/
|
|
||||||
virtual void reportException(const char* message, const char* exception) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* customize logging
|
|
||||||
*
|
|
||||||
* @param string Custom log
|
|
||||||
*/
|
|
||||||
virtual void leaveBreadcrumb(const char* breadcrumb) = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PROTOCOL_CRASH_H__ */
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/** @file ProtocolCustom.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_CUSTOM_H__
|
|
||||||
#define __CCX_PROTOCOL_CUSTOM_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kCustomExtension = 80000 /**< enum value is extension code . */
|
|
||||||
} CustomResultCode;
|
|
||||||
/**
|
|
||||||
*@class CustomResultListener
|
|
||||||
*@brief the interface of share callback
|
|
||||||
*/
|
|
||||||
class CustomResultListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief the interface of share callback
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*/
|
|
||||||
virtual void onCustomResult(CustomResultCode ret, const char* msg) = 0;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*@class ProtocolCustom
|
|
||||||
*@brief the interface of custom
|
|
||||||
*/
|
|
||||||
class ProtocolCustom : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
@breif set the result listener
|
|
||||||
@param pListener The callback object for custom result
|
|
||||||
@wraning Must invoke this interface before custom
|
|
||||||
*/
|
|
||||||
virtual void setResultListener(CustomResultListener* pListener) = 0;
|
|
||||||
|
|
||||||
virtual CustomResultListener* getCustomListener() = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* ----- #ifndef __CCX_PROTOCOL_Custom_H__ ----- */
|
|
||||||
|
|
@ -1,119 +0,0 @@
|
||||||
/** @file ProtocolIAP.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_IAP_H__
|
|
||||||
#define __CCX_PROTOCOL_IAP_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/// \typedef std::map<std::string, std::string> TIAPDeveloperInfo
|
|
||||||
/// typedef TIAPDeveloperInfo.
|
|
||||||
typedef std::map<std::string, std::string> TIAPDeveloperInfo;
|
|
||||||
/// \typedef std::map<std::string, std::string> TProductInfo
|
|
||||||
/// typedef TProductInfo.
|
|
||||||
typedef std::map<std::string, std::string> TProductInfo;
|
|
||||||
/// typedef TProductsInfo.
|
|
||||||
typedef std::map<std::string, TProductInfo> AllProductsInfo;
|
|
||||||
/** @brief PayResultCode enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kPaySuccess = 0,/**< enum value is callback of succeeding in paying . */
|
|
||||||
kPayFail,/**< enum value is callback of failing to pay . */
|
|
||||||
kPayCancel,/**< enum value is callback of canceling to pay . */
|
|
||||||
kPayNetworkError,/**< enum value is callback of network error . */
|
|
||||||
kPayProductionInforIncomplete,/**< enum value is callback of incompleting info . */
|
|
||||||
kPayInitSuccess,/**< enum value is callback of succeeding in initing sdk . */
|
|
||||||
kPayInitFail,/**< enum value is callback of failing to init sdk . */
|
|
||||||
kPayNowPaying,/**< enum value is callback of paying now . */
|
|
||||||
kPayRechargeSuccess,/**< enum value is callback of succeeding in recharging. */
|
|
||||||
kPayExtension = 30000 /**< enum value is extension code . */
|
|
||||||
} PayResultCode;
|
|
||||||
/** @brief RequestResultCode enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kRequestSuccess = 31000,/**< enum value is callback of succeeding in paying . */
|
|
||||||
kRequestFail/**< enum value is callback of failing to pay . */
|
|
||||||
} RequestResultCode;
|
|
||||||
/**
|
|
||||||
*@class PayResultListener
|
|
||||||
*@brief the interface of pay callback
|
|
||||||
*/
|
|
||||||
class PayResultListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief the interface of pay callback
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*@param the info of pay
|
|
||||||
*/
|
|
||||||
virtual void onPayResult(PayResultCode ret, const char* msg, TProductInfo info) = 0;
|
|
||||||
/**
|
|
||||||
*@brief the interface of request callback
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*@param the info of request product
|
|
||||||
*/
|
|
||||||
virtual void onRequestResult(RequestResultCode ret, const char* msg, AllProductsInfo info) {}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*@class ProtocolIAP
|
|
||||||
*@brief the interface of pay
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ProtocolIAP : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief pay for product
|
|
||||||
@param info The info of product, must contains key:
|
|
||||||
productName The name of product
|
|
||||||
productPrice The price of product(must can be parse to float)
|
|
||||||
productDesc The description of product
|
|
||||||
@warning For different plugin, the parameter should have other keys to pay.
|
|
||||||
Look at the manual of plugins.
|
|
||||||
*/
|
|
||||||
virtual void payForProduct(TProductInfo info) = 0;
|
|
||||||
/**
|
|
||||||
@brief get order id
|
|
||||||
@return the order id
|
|
||||||
*/
|
|
||||||
virtual std::string getOrderId() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@breif set the result listener
|
|
||||||
@param pListener The callback object for pay result
|
|
||||||
@wraning Must invoke this interface before payForProduct.
|
|
||||||
*/
|
|
||||||
virtual void setResultListener(PayResultListener* pListener) = 0;
|
|
||||||
|
|
||||||
virtual PayResultListener* getPayListener() = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief get plugin id
|
|
||||||
@return the plugin id
|
|
||||||
*/
|
|
||||||
virtual std::string getPluginId() = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief change the state of paying
|
|
||||||
@param the state
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void resetPayState()
|
|
||||||
{
|
|
||||||
_paying = false;
|
|
||||||
}
|
|
||||||
static bool _paying;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PROTOCOL_IAP_H__ */
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
/** @file PluginFactory.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_PUSH_H__
|
|
||||||
#define __CCX_PROTOCOL_PUSH_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <list>
|
|
||||||
#include <string>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/** @brief Plugin_type enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kPushReceiveMessage = 0,/**value is callback of Receiving Message . */
|
|
||||||
kPushExtensionCode = 60000 /**< enum value is extension code . */
|
|
||||||
|
|
||||||
|
|
||||||
} PushActionResultCode;
|
|
||||||
class ProtocolPush;
|
|
||||||
/**
|
|
||||||
*@class PushActionListener
|
|
||||||
*@brief the interface of Push callback
|
|
||||||
*/
|
|
||||||
class PushActionListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief the interface of Push callback
|
|
||||||
*@param the adatper of plugin
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*/
|
|
||||||
virtual void onActionResult(ProtocolPush* pPlugin, PushActionResultCode code, const char* msg) = 0;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* @class ProtocolPush
|
|
||||||
*/
|
|
||||||
class ProtocolPush : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief start/register Push services
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void startPush() = 0 ;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief close Push services
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void closePush() = 0 ;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief set alias
|
|
||||||
*@param tags
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void setAlias(string alias) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief del alias
|
|
||||||
*@param tags
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void delAlias(string alias) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief set tag
|
|
||||||
*@param tags
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void setTags(list<string> tags) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief delete tag
|
|
||||||
*@param tags
|
|
||||||
*@return void
|
|
||||||
*/
|
|
||||||
virtual void delTags(list<string> tags) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief set the result listener
|
|
||||||
@param pListener The callback object for push result
|
|
||||||
*/
|
|
||||||
virtual void setActionListener(PushActionListener* listener) = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief get pListener The callback object for Push result
|
|
||||||
@return the listener
|
|
||||||
*/
|
|
||||||
virtual PushActionListener* getActionListener() = 0 ;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PROTOCOL_PUSH_H__ */
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
/** @file ProtocolREC.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_REC_H__
|
|
||||||
#define __CCX_PROTOCOL_REC_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
typedef std::map<std::string, std::string> TVideoInfo;
|
|
||||||
|
|
||||||
/** @brief RECResultCode enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kRECInitSuccess = 0,/**< enum value is callback of succeeding in initing sdk . */
|
|
||||||
kRECInitFail,/**< enum value is callback of failing to init sdk. */
|
|
||||||
kRECStartRecording,/**< enum value is callback of starting to record. */
|
|
||||||
kRECStopRecording,/**< enum value is callback of stoping to record. */
|
|
||||||
kRECPauseRecording,/**< enum value is callback of pausing to record. */
|
|
||||||
kRECResumeRecording,/**< enum value is callback of resuming to record. */
|
|
||||||
kRECEnterSDKPage,/**< enum value is callback of entering SDK`s page. */
|
|
||||||
kRECQuitSDKPage,/**< enum value is callback of quiting SDK`s page. */
|
|
||||||
kRECShareSuccess,/**< enum value is callback of succeeding in sharing. */
|
|
||||||
kRECShareFail,/**< enum value is callback of failing to share. */
|
|
||||||
kRECExtension = 90000 /**< enum value is extension code . */
|
|
||||||
} RECResultCode;
|
|
||||||
/**
|
|
||||||
*@class RECResultListener
|
|
||||||
*@brief the interface of REC callback
|
|
||||||
*/
|
|
||||||
class RECResultListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief the interface of REC callback
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*/
|
|
||||||
virtual void onRECResult(RECResultCode ret, const char* msg) = 0;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*@class ProtocolREC
|
|
||||||
*@brief the interface of REC
|
|
||||||
*/
|
|
||||||
class ProtocolREC : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: Start to record video
|
|
||||||
*/
|
|
||||||
virtual void startRecording() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: Stop to record video
|
|
||||||
*/
|
|
||||||
virtual void stopRecording() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: share video
|
|
||||||
* @Param info The info of share
|
|
||||||
*/
|
|
||||||
virtual void share(TVideoInfo info) = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
@breif set the result listener
|
|
||||||
@param pListener The callback object for REC result
|
|
||||||
@wraning Must invoke this interface before REC
|
|
||||||
*/
|
|
||||||
virtual void setResultListener(RECResultListener* pListener) = 0;
|
|
||||||
|
|
||||||
virtual RECResultListener* getRECListener() = 0;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* ----- #ifndef __CCX_PROTOCOL_SHARE_H__ ----- */
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
/** @file ProtocolShare.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_SHARE_H__
|
|
||||||
#define __CCX_PROTOCOL_SHARE_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/// \typedef std::map<std::string, std::string> TShareDeveloperInfo
|
|
||||||
/// typedef TShareDeveloperInfo.
|
|
||||||
typedef std::map<std::string, std::string> TShareDeveloperInfo;
|
|
||||||
/// \typedef std::map<std::string, std::string> TShareInfo
|
|
||||||
/// typedef TShareInfo.
|
|
||||||
typedef std::map<std::string, std::string> TShareInfo;
|
|
||||||
/** @brief ShareResultCode enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kShareSuccess = 0,/**< enum value is callback of failing to sharing . */
|
|
||||||
kShareFail,/**< enum value is callback of failing to share . */
|
|
||||||
kShareCancel,/**< enum value is callback of canceling to share . */
|
|
||||||
kShareNetworkError,/**< enum value is callback of network error . */
|
|
||||||
kShareExtension = 10000 /**< enum value is extension code . */
|
|
||||||
} ShareResultCode;
|
|
||||||
/**
|
|
||||||
*@class ShareResultListener
|
|
||||||
*@brief the interface of share callback
|
|
||||||
*/
|
|
||||||
class ShareResultListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief the interface of share callback
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*/
|
|
||||||
virtual void onShareResult(ShareResultCode ret, const char* msg) = 0;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*@class ProtocolShare
|
|
||||||
*@brief the interface of share
|
|
||||||
*/
|
|
||||||
class ProtocolShare : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief share information
|
|
||||||
@param info The info of share, contains key:
|
|
||||||
SharedText The text need to share
|
|
||||||
SharedImagePath The full path of image file need to share (optinal)
|
|
||||||
@warning For different plugin, the parameter should have other keys to share.
|
|
||||||
Look at the manual of plugins. */
|
|
||||||
virtual void share(TShareInfo info) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@breif set the result listener
|
|
||||||
@param pListener The callback object for share result
|
|
||||||
@wraning Must invoke this interface before share
|
|
||||||
*/
|
|
||||||
virtual void setResultListener(ShareResultListener* pListener) = 0;
|
|
||||||
|
|
||||||
virtual ShareResultListener* getShareListener() = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* ----- #ifndef __CCX_PROTOCOL_SHARE_H__ ----- */
|
|
||||||
|
|
@ -1,105 +0,0 @@
|
||||||
/** @file ProtocolSocial.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_SOCIAL_H__
|
|
||||||
#define __CCX_PROTOCOL_SOCIAL_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/// \typedef std::map<std::string, std::string> TSocialDeveloperInfo
|
|
||||||
/// typedef TSocialDeveloperInfo.
|
|
||||||
typedef std::map<std::string, std::string> TSocialDeveloperInfo;
|
|
||||||
/// \typedef std::map<std::string, std::string> TAchievementInfo
|
|
||||||
/// typedef TAchievementInfo.
|
|
||||||
typedef std::map<std::string, std::string> TAchievementInfo;
|
|
||||||
/** @brief SocialRetCode enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
// code for leaderboard feature
|
|
||||||
kScoreSubmitSucceed =1,/**< enum value is callback of succeeding in submiting. */
|
|
||||||
kScoreSubmitfail,/**< enum value is callback of failing to submit . */
|
|
||||||
|
|
||||||
// code for achievement feature
|
|
||||||
kAchUnlockSucceed,/**< enum value is callback of succeeding in unlocking. */
|
|
||||||
kAchUnlockFail,/**< enum value is callback of failing to unlock. */
|
|
||||||
|
|
||||||
kSocialSignInSucceed,/**< enum value is callback of succeeding to login. */
|
|
||||||
kSocialSignInFail,/**< enum value is callback of failing to login. */
|
|
||||||
|
|
||||||
kSocialSignOutSucceed,/**< enum value is callback of succeeding to login. */
|
|
||||||
kSocialSignOutFail,/**< enum value is callback of failing to login. */
|
|
||||||
kSocialGetGameFriends,/**< enum value is callback of getGameFriends. */
|
|
||||||
kSocialExtensionCode = 20000 /**< enum value is extension code . */
|
|
||||||
|
|
||||||
} SocialRetCode;
|
|
||||||
/**
|
|
||||||
*@class SocialListener
|
|
||||||
*@brief the interface of social callback
|
|
||||||
*/
|
|
||||||
class SocialListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief the interface of social callback
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*/
|
|
||||||
virtual void onSocialResult(SocialRetCode code, const char* msg) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@class ProtocolSocial
|
|
||||||
*@brief the interface of social
|
|
||||||
*/
|
|
||||||
class ProtocolSocial : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief user signIn
|
|
||||||
*/
|
|
||||||
virtual void signIn() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief user signOut
|
|
||||||
*/
|
|
||||||
virtual void signOut() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief submit the score
|
|
||||||
@param leaderboardID
|
|
||||||
@param the score
|
|
||||||
*/
|
|
||||||
virtual void submitScore(const char* leadboardID, long score) = 0;
|
|
||||||
/**
|
|
||||||
@brief show the id of Leaderboard page
|
|
||||||
@param leaderboardID
|
|
||||||
*/
|
|
||||||
virtual void showLeaderboard(const char* leaderboardID) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief methods of achievement feature
|
|
||||||
@param the info of achievement
|
|
||||||
*/
|
|
||||||
virtual void unlockAchievement(TAchievementInfo achInfo) = 0;
|
|
||||||
/**
|
|
||||||
@brief show the page of achievements
|
|
||||||
*/
|
|
||||||
virtual void showAchievements() = 0;
|
|
||||||
/**
|
|
||||||
@brief set pListener The callback object for social result
|
|
||||||
@param the listener
|
|
||||||
*/
|
|
||||||
virtual void setListener(SocialListener* listener) = 0;
|
|
||||||
/**
|
|
||||||
@brief get pListener The callback object for social result
|
|
||||||
@return the listener
|
|
||||||
*/
|
|
||||||
virtual SocialListener* getListener() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* ----- #ifndef __CCX_PROTOCOL_SOCIAL_H__ ----- */
|
|
||||||
|
|
@ -1,135 +0,0 @@
|
||||||
/** @file ProtocolUser.h
|
|
||||||
*/
|
|
||||||
#ifndef __CCX_PROTOCOL_USER_H__
|
|
||||||
#define __CCX_PROTOCOL_USER_H__
|
|
||||||
|
|
||||||
#include "PluginProtocol.h"
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
/// \typedef std::map<std::string, std::string> TUserDeveloperInfo
|
|
||||||
/// typedef TUserDeveloperInfo.
|
|
||||||
typedef std::map<std::string, std::string> TUserDeveloperInfo;
|
|
||||||
/** @brief Plugin_type enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kInitSuccess = 0,/**< enum value is callback of succeeding in initing sdk. */
|
|
||||||
kInitFail,/**< enum value is callback of failing to init sdk. */
|
|
||||||
kLoginSuccess,/**< enum value is callback of succeeding in login.*/
|
|
||||||
kLoginNetworkError,/**< enum value is callback of network error*/
|
|
||||||
kLoginNoNeed,/**< enum value is callback of no need login.*/
|
|
||||||
kLoginFail,/**< enum value is callback of failing to login. */
|
|
||||||
kLoginCancel,/**< enum value is callback of canceling to login. */
|
|
||||||
kLogoutSuccess,/**< enum value is callback of succeeding in logout. */
|
|
||||||
kLogoutFail,/**< enum value is callback of failing to logout. */
|
|
||||||
kPlatformEnter,/**< enum value is callback after enter platform. */
|
|
||||||
kPlatformBack,/**< enum value is callback after exit antiAddiction. */
|
|
||||||
kPausePage,/**< enum value is callback after exit pause page. */
|
|
||||||
kExitPage,/**< enum value is callback after exit exit page. */
|
|
||||||
kAntiAddictionQuery,/**< enum value is callback after querying antiAddiction. */
|
|
||||||
kRealNameRegister,/**< enum value is callback after registering realname. */
|
|
||||||
kAccountSwitchSuccess,/**< enum value is callback of succeeding in switching account. */
|
|
||||||
kAccountSwitchFail,/**< enum value is callback of failing to switch account. */
|
|
||||||
kOpenShop,/**< enum value is callback of open the shop. */
|
|
||||||
kAccountSwitchCancel,/**< enum value is callback of canceling to switch account. */
|
|
||||||
kGameExitPage,/**< enum value is callback of no channel exit page. */
|
|
||||||
kUserExtension = 50000 /**< enum value is extension code . */
|
|
||||||
|
|
||||||
|
|
||||||
} UserActionResultCode;
|
|
||||||
/** @brief ToolBarPlace enum, with inline docs */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
kToolBarTopLeft = 1,/**< enum the toolbar is at topleft. */
|
|
||||||
kToolBarTopRight,/**< enum the toolbar is at topright. */
|
|
||||||
kToolBarMidLeft,/**< enum the toolbar is at midleft. */
|
|
||||||
kToolBarMidRight,/**< enum the toolbar is at midright. */
|
|
||||||
kToolBarBottomLeft,/**< enum the toolbar is at bottomleft. */
|
|
||||||
kToolBarBottomRight,/**< enum the toolbar is at bottomright. */
|
|
||||||
} ToolBarPlace;
|
|
||||||
|
|
||||||
class ProtocolUser;
|
|
||||||
/**
|
|
||||||
*@class UserActionListener
|
|
||||||
*@brief the interface of user callback
|
|
||||||
*/
|
|
||||||
class UserActionListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*@brief the interface of user callback
|
|
||||||
*@param the adatper of plugin
|
|
||||||
*@param the id of callback
|
|
||||||
*@param the information of callback
|
|
||||||
*/
|
|
||||||
virtual void onActionResult(ProtocolUser* pPlugin, UserActionResultCode code, const char* msg) = 0;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* @class ProtocolUser
|
|
||||||
*/
|
|
||||||
class ProtocolUser : public PluginProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief User login
|
|
||||||
*/
|
|
||||||
virtual void login() = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief User login
|
|
||||||
if the process of logining need to know the param of server_id ,
|
|
||||||
you can use the function
|
|
||||||
and if you must change oauthloginserver, you can add the param of oauthLoginServer
|
|
||||||
@param server_id
|
|
||||||
@param oauthLoginServer
|
|
||||||
*/
|
|
||||||
|
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void login(std::string server_id, std::string oauthLoginServer = "") = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief User login
|
|
||||||
if the process of logining need to know the parameters ,
|
|
||||||
you can use the function
|
|
||||||
@param the parameters
|
|
||||||
*/
|
|
||||||
virtual void login(std::map<std::string, std::string> info) = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Check whether the user logined or not
|
|
||||||
@return If user logined, return value is true;
|
|
||||||
else return value is false.
|
|
||||||
*/
|
|
||||||
virtual bool isLogined() = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get USER ID
|
|
||||||
@return If user logined, return value is userID;
|
|
||||||
else return value is empty string.
|
|
||||||
*/
|
|
||||||
virtual std::string getUserID() = 0 ;
|
|
||||||
/**
|
|
||||||
@brief set the result listener
|
|
||||||
@param pListener The callback object for user result
|
|
||||||
*/
|
|
||||||
virtual void setActionListener(UserActionListener* listener) = 0 ;
|
|
||||||
/**
|
|
||||||
@brief get pListener The callback object for user result
|
|
||||||
@return the listener
|
|
||||||
*/
|
|
||||||
virtual UserActionListener* getActionListener() = 0 ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief get plugin id
|
|
||||||
@return the plugin id
|
|
||||||
*/
|
|
||||||
virtual std::string getPluginId() = 0 ;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif /* __CCX_PROTOCOL_USER_H__ */
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
#ifndef __STATISTICS_H__
|
|
||||||
#define __STATISTICS_H__
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
class Statistics
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void initInfo();
|
|
||||||
static void createPlugin(std::string pluginName, int pluginType);
|
|
||||||
static void callFunction(std::string pluginName, std::string functionName);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace anysdk { namespace framework {
|
|
||||||
|
|
||||||
#endif //__STATISTICS_H__
|
|
||||||
|
|
@ -1,241 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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 CHIPMUNK_H
|
|
||||||
#define CHIPMUNK_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
// For alloca().
|
|
||||||
#include <malloc.h>
|
|
||||||
#define CP_EXPORT __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#include <alloca.h>
|
|
||||||
#define CP_EXPORT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NUKE
|
|
||||||
#ifndef CP_ALLOW_PRIVATE_ACCESS
|
|
||||||
#define CP_ALLOW_PRIVATE_ACCESS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CP_ALLOW_PRIVATE_ACCESS == 1
|
|
||||||
#define CP_PRIVATE(__symbol__) __symbol__
|
|
||||||
#else
|
|
||||||
#define CP_PRIVATE(__symbol__) __symbol__##_private
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CP_EXPORT void cpMessage(const char *condition, const char *file, int line, int isError, int isHardError, const char *message, ...);
|
|
||||||
#ifdef NDEBUG
|
|
||||||
#define cpAssertWarn(__condition__, ...)
|
|
||||||
#define cpAssertSoft(__condition__, ...)
|
|
||||||
#else
|
|
||||||
#define cpAssertSoft(__condition__, ...) if(!(__condition__)){cpMessage(#__condition__, __FILE__, __LINE__, 1, 0, __VA_ARGS__); abort();}
|
|
||||||
#define cpAssertWarn(__condition__, ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 0, 0, __VA_ARGS__)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Hard assertions are used in situations where the program definitely will crash anyway, and the reason is inexpensive to detect.
|
|
||||||
#define cpAssertHard(__condition__, ...) if(!(__condition__)){cpMessage(#__condition__, __FILE__, __LINE__, 1, 1, __VA_ARGS__); abort();}
|
|
||||||
|
|
||||||
#include "chipmunk_types.h"
|
|
||||||
|
|
||||||
/// @defgroup misc Misc
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Allocated size for various Chipmunk buffers
|
|
||||||
#ifndef CP_BUFFER_BYTES
|
|
||||||
#define CP_BUFFER_BYTES (32*1024)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef cpcalloc
|
|
||||||
/// Chipmunk calloc() alias.
|
|
||||||
#define cpcalloc calloc
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef cprealloc
|
|
||||||
/// Chipmunk realloc() alias.
|
|
||||||
#define cprealloc realloc
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef cpfree
|
|
||||||
/// Chipmunk free() alias.
|
|
||||||
#define cpfree free
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct cpArray cpArray;
|
|
||||||
typedef struct cpHashSet cpHashSet;
|
|
||||||
|
|
||||||
typedef struct cpBody cpBody;
|
|
||||||
|
|
||||||
typedef struct cpShape cpShape;
|
|
||||||
typedef struct cpCircleShape cpCircleShape;
|
|
||||||
typedef struct cpSegmentShape cpSegmentShape;
|
|
||||||
typedef struct cpPolyShape cpPolyShape;
|
|
||||||
|
|
||||||
typedef struct cpConstraint cpConstraint;
|
|
||||||
typedef struct cpPinJoint cpPinJoint;
|
|
||||||
typedef struct cpSlideJoint cpSlideJoint;
|
|
||||||
typedef struct cpPivotJoint cpPivotJoint;
|
|
||||||
typedef struct cpGrooveJoint cpGrooveJoint;
|
|
||||||
typedef struct cpDampedSpring cpDampedSpring;
|
|
||||||
typedef struct cpDampedRotarySpring cpDampedRotarySpring;
|
|
||||||
typedef struct cpRotaryLimitJoint cpRotaryLimitJoint;
|
|
||||||
typedef struct cpRatchetJoint cpRatchetJoint;
|
|
||||||
typedef struct cpGearJoint cpGearJoint;
|
|
||||||
typedef struct cpSimpleMotorJoint cpSimpleMotorJoint;
|
|
||||||
|
|
||||||
typedef struct cpCollisionHandler cpCollisionHandler;
|
|
||||||
typedef struct cpContactPointSet cpContactPointSet;
|
|
||||||
typedef struct cpArbiter cpArbiter;
|
|
||||||
|
|
||||||
typedef struct cpSpace cpSpace;
|
|
||||||
|
|
||||||
#include "cpVect.h"
|
|
||||||
#include "cpBB.h"
|
|
||||||
#include "cpTransform.h"
|
|
||||||
#include "cpSpatialIndex.h"
|
|
||||||
|
|
||||||
#include "cpArbiter.h"
|
|
||||||
|
|
||||||
#include "cpBody.h"
|
|
||||||
#include "cpShape.h"
|
|
||||||
#include "cpPolyShape.h"
|
|
||||||
|
|
||||||
#include "cpConstraint.h"
|
|
||||||
|
|
||||||
#include "cpSpace.h"
|
|
||||||
#include "cpHastySpace.h"
|
|
||||||
|
|
||||||
// Chipmunk 7.0.1
|
|
||||||
#define CP_VERSION_MAJOR 7
|
|
||||||
#define CP_VERSION_MINOR 0
|
|
||||||
#define CP_VERSION_RELEASE 1
|
|
||||||
|
|
||||||
/// Version string.
|
|
||||||
CP_EXPORT extern const char *cpVersionString;
|
|
||||||
|
|
||||||
/// Calculate the moment of inertia for a circle.
|
|
||||||
/// @c r1 and @c r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
|
|
||||||
CP_EXPORT cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset);
|
|
||||||
|
|
||||||
/// Calculate area of a hollow circle.
|
|
||||||
/// @c r1 and @c r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
|
|
||||||
CP_EXPORT cpFloat cpAreaForCircle(cpFloat r1, cpFloat r2);
|
|
||||||
|
|
||||||
/// Calculate the moment of inertia for a line segment.
|
|
||||||
/// Beveling radius is not supported.
|
|
||||||
CP_EXPORT cpFloat cpMomentForSegment(cpFloat m, cpVect a, cpVect b, cpFloat radius);
|
|
||||||
|
|
||||||
/// Calculate the area of a fattened (capsule shaped) line segment.
|
|
||||||
CP_EXPORT cpFloat cpAreaForSegment(cpVect a, cpVect b, cpFloat radius);
|
|
||||||
|
|
||||||
/// Calculate the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid. The offset is added to each vertex.
|
|
||||||
CP_EXPORT cpFloat cpMomentForPoly(cpFloat m, int count, const cpVect *verts, cpVect offset, cpFloat radius);
|
|
||||||
|
|
||||||
/// Calculate the signed area of a polygon. A Clockwise winding gives positive area.
|
|
||||||
/// This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.
|
|
||||||
CP_EXPORT cpFloat cpAreaForPoly(const int count, const cpVect *verts, cpFloat radius);
|
|
||||||
|
|
||||||
/// Calculate the natural centroid of a polygon.
|
|
||||||
CP_EXPORT cpVect cpCentroidForPoly(const int count, const cpVect *verts);
|
|
||||||
|
|
||||||
/// Calculate the moment of inertia for a solid box.
|
|
||||||
CP_EXPORT cpFloat cpMomentForBox(cpFloat m, cpFloat width, cpFloat height);
|
|
||||||
|
|
||||||
/// Calculate the moment of inertia for a solid box.
|
|
||||||
CP_EXPORT cpFloat cpMomentForBox2(cpFloat m, cpBB box);
|
|
||||||
|
|
||||||
/// Calculate the convex hull of a given set of points. Returns the count of points in the hull.
|
|
||||||
/// @c result must be a pointer to a @c cpVect array with at least @c count elements. If @c verts == @c result, then @c verts will be reduced inplace.
|
|
||||||
/// @c first is an optional pointer to an integer to store where the first vertex in the hull came from (i.e. verts[first] == result[0])
|
|
||||||
/// @c tol is the allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull.
|
|
||||||
CP_EXPORT int cpConvexHull(int count, const cpVect *verts, cpVect *result, int *first, cpFloat tol);
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include "malloc.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Convenience macro to work with cpConvexHull.
|
|
||||||
/// @c count and @c verts is the input array passed to cpConvexHull().
|
|
||||||
/// @c count_var and @c verts_var are the names of the variables the macro creates to store the result.
|
|
||||||
/// The output vertex array is allocated on the stack using alloca() so it will be freed automatically, but cannot be returned from the current scope.
|
|
||||||
#define CP_CONVEX_HULL(__count__, __verts__, __count_var__, __verts_var__) \
|
|
||||||
cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \
|
|
||||||
int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \
|
|
||||||
|
|
||||||
/// Returns the closest point on the line segment ab, to the point p.
|
|
||||||
static inline cpVect
|
|
||||||
cpClosetPointOnSegment(const cpVect p, const cpVect a, const cpVect b)
|
|
||||||
{
|
|
||||||
cpVect delta = cpvsub(a, b);
|
|
||||||
cpFloat t = cpfclamp01(cpvdot(delta, cpvsub(p, b))/cpvlengthsq(delta));
|
|
||||||
return cpvadd(b, cpvmult(delta, t));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__has_extension)
|
|
||||||
#if __has_extension(blocks)
|
|
||||||
// Define alternate block based alternatives for a few of the callback heavy functions.
|
|
||||||
// Collision handlers are post-step callbacks are not included to avoid memory management issues.
|
|
||||||
// If you want to use blocks for those and are aware of how to correctly manage the memory, the implementation is trivial.
|
|
||||||
|
|
||||||
void cpSpaceEachBody_b(cpSpace *space, void (^block)(cpBody *body));
|
|
||||||
void cpSpaceEachShape_b(cpSpace *space, void (^block)(cpShape *shape));
|
|
||||||
void cpSpaceEachConstraint_b(cpSpace *space, void (^block)(cpConstraint *constraint));
|
|
||||||
|
|
||||||
void cpBodyEachShape_b(cpBody *body, void (^block)(cpShape *shape));
|
|
||||||
void cpBodyEachConstraint_b(cpBody *body, void (^block)(cpConstraint *constraint));
|
|
||||||
void cpBodyEachArbiter_b(cpBody *body, void (^block)(cpArbiter *arbiter));
|
|
||||||
|
|
||||||
typedef void (^cpSpacePointQueryBlock)(cpShape *shape, cpVect point, cpFloat distance, cpVect gradient);
|
|
||||||
void cpSpacePointQuery_b(cpSpace *space, cpVect point, cpFloat maxDistance, cpShapeFilter filter, cpSpacePointQueryBlock block);
|
|
||||||
|
|
||||||
typedef void (^cpSpaceSegmentQueryBlock)(cpShape *shape, cpVect point, cpVect normal, cpFloat alpha);
|
|
||||||
void cpSpaceSegmentQuery_b(cpSpace *space, cpVect start, cpVect end, cpFloat radius, cpShapeFilter filter, cpSpaceSegmentQueryBlock block);
|
|
||||||
|
|
||||||
typedef void (^cpSpaceBBQueryBlock)(cpShape *shape);
|
|
||||||
void cpSpaceBBQuery_b(cpSpace *space, cpBB bb, cpShapeFilter filter, cpSpaceBBQueryBlock block);
|
|
||||||
|
|
||||||
typedef void (^cpSpaceShapeQueryBlock)(cpShape *shape, cpContactPointSet *points);
|
|
||||||
cpBool cpSpaceShapeQuery_b(cpSpace *space, cpShape *shape, cpSpaceShapeQueryBlock block);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
//@}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpVect operator *(const cpVect v, const cpFloat s){return cpvmult(v, s);}
|
|
||||||
static inline cpVect operator +(const cpVect v1, const cpVect v2){return cpvadd(v1, v2);}
|
|
||||||
static inline cpVect operator -(const cpVect v1, const cpVect v2){return cpvsub(v1, v2);}
|
|
||||||
static inline cpBool operator ==(const cpVect v1, const cpVect v2){return cpveql(v1, v2);}
|
|
||||||
static inline cpVect operator -(const cpVect v){return cpvneg(v);}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef CHIPMUNK_FFI
|
|
||||||
|
|
||||||
// Create non static inlined copies of Chipmunk functions, useful for working with dynamic FFIs
|
|
||||||
// This file should only be included in chipmunk.c
|
|
||||||
|
|
||||||
// TODO: get rid of the reliance on static inlines.
|
|
||||||
// They make a mess for FFIs.
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#if _MSC_VER >= 1600
|
|
||||||
#define MAKE_REF(name) CP_EXPORT decltype(name) *_##name = name
|
|
||||||
#else
|
|
||||||
#define MAKE_REF(name)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define MAKE_REF(name) __typeof__(name) *_##name = name
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MAKE_REF(cpv); // makes a variable named _cpv that contains the function pointer for cpv()
|
|
||||||
MAKE_REF(cpveql);
|
|
||||||
MAKE_REF(cpvadd);
|
|
||||||
MAKE_REF(cpvneg);
|
|
||||||
MAKE_REF(cpvsub);
|
|
||||||
MAKE_REF(cpvmult);
|
|
||||||
MAKE_REF(cpvdot);
|
|
||||||
MAKE_REF(cpvcross);
|
|
||||||
MAKE_REF(cpvperp);
|
|
||||||
MAKE_REF(cpvrperp);
|
|
||||||
MAKE_REF(cpvproject);
|
|
||||||
MAKE_REF(cpvforangle);
|
|
||||||
MAKE_REF(cpvtoangle);
|
|
||||||
MAKE_REF(cpvrotate);
|
|
||||||
MAKE_REF(cpvunrotate);
|
|
||||||
MAKE_REF(cpvlengthsq);
|
|
||||||
MAKE_REF(cpvlength);
|
|
||||||
MAKE_REF(cpvlerp);
|
|
||||||
MAKE_REF(cpvnormalize);
|
|
||||||
MAKE_REF(cpvclamp);
|
|
||||||
MAKE_REF(cpvlerpconst);
|
|
||||||
MAKE_REF(cpvdist);
|
|
||||||
MAKE_REF(cpvdistsq);
|
|
||||||
MAKE_REF(cpvnear);
|
|
||||||
|
|
||||||
MAKE_REF(cpfmax);
|
|
||||||
MAKE_REF(cpfmin);
|
|
||||||
MAKE_REF(cpfabs);
|
|
||||||
MAKE_REF(cpfclamp);
|
|
||||||
MAKE_REF(cpflerp);
|
|
||||||
MAKE_REF(cpflerpconst);
|
|
||||||
|
|
||||||
MAKE_REF(cpBBNew);
|
|
||||||
MAKE_REF(cpBBNewForExtents);
|
|
||||||
MAKE_REF(cpBBNewForCircle);
|
|
||||||
MAKE_REF(cpBBIntersects);
|
|
||||||
MAKE_REF(cpBBContainsBB);
|
|
||||||
MAKE_REF(cpBBContainsVect);
|
|
||||||
MAKE_REF(cpBBMerge);
|
|
||||||
MAKE_REF(cpBBExpand);
|
|
||||||
MAKE_REF(cpBBCenter);
|
|
||||||
MAKE_REF(cpBBArea);
|
|
||||||
MAKE_REF(cpBBMergedArea);
|
|
||||||
MAKE_REF(cpBBSegmentQuery);
|
|
||||||
MAKE_REF(cpBBIntersectsSegment);
|
|
||||||
MAKE_REF(cpBBClampVect);
|
|
||||||
|
|
||||||
MAKE_REF(cpSpatialIndexDestroy);
|
|
||||||
MAKE_REF(cpSpatialIndexCount);
|
|
||||||
MAKE_REF(cpSpatialIndexEach);
|
|
||||||
MAKE_REF(cpSpatialIndexContains);
|
|
||||||
MAKE_REF(cpSpatialIndexInsert);
|
|
||||||
MAKE_REF(cpSpatialIndexRemove);
|
|
||||||
MAKE_REF(cpSpatialIndexReindex);
|
|
||||||
MAKE_REF(cpSpatialIndexReindexObject);
|
|
||||||
MAKE_REF(cpSpatialIndexSegmentQuery);
|
|
||||||
MAKE_REF(cpSpatialIndexQuery);
|
|
||||||
MAKE_REF(cpSpatialIndexReindexQuery);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,766 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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 CHIPMUNK_PRIVATE_H
|
|
||||||
#define CHIPMUNK_PRIVATE_H
|
|
||||||
#ifdef CHIPMUNK_H
|
|
||||||
#error Cannot include chipmunk_private.h after chipmunk.h.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CP_ALLOW_PRIVATE_ACCESS 1
|
|
||||||
#include "chipmunk/chipmunk.h"
|
|
||||||
|
|
||||||
#define CP_HASH_COEF (3344921057ul)
|
|
||||||
#define CP_HASH_PAIR(A, B) ((cpHashValue)(A)*CP_HASH_COEF ^ (cpHashValue)(B)*CP_HASH_COEF)
|
|
||||||
|
|
||||||
// TODO: Eww. Magic numbers.
|
|
||||||
#define MAGIC_EPSILON 1e-5
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: cpArray
|
|
||||||
|
|
||||||
struct cpArray {
|
|
||||||
int num, max;
|
|
||||||
void **arr;
|
|
||||||
};
|
|
||||||
|
|
||||||
cpArray *cpArrayNew(int size);
|
|
||||||
|
|
||||||
void cpArrayFree(cpArray *arr);
|
|
||||||
|
|
||||||
void cpArrayPush(cpArray *arr, void *object);
|
|
||||||
void *cpArrayPop(cpArray *arr);
|
|
||||||
void cpArrayDeleteObj(cpArray *arr, void *obj);
|
|
||||||
cpBool cpArrayContains(cpArray *arr, void *ptr);
|
|
||||||
|
|
||||||
void cpArrayFreeEach(cpArray *arr, void (freeFunc)(void*));
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: cpHashSet
|
|
||||||
|
|
||||||
typedef cpBool (*cpHashSetEqlFunc)(void *ptr, void *elt);
|
|
||||||
typedef void *(*cpHashSetTransFunc)(void *ptr, void *data);
|
|
||||||
|
|
||||||
cpHashSet *cpHashSetNew(int size, cpHashSetEqlFunc eqlFunc);
|
|
||||||
void cpHashSetSetDefaultValue(cpHashSet *set, void *default_value);
|
|
||||||
|
|
||||||
void cpHashSetFree(cpHashSet *set);
|
|
||||||
|
|
||||||
int cpHashSetCount(cpHashSet *set);
|
|
||||||
void *cpHashSetInsert(cpHashSet *set, cpHashValue hash, void *ptr, cpHashSetTransFunc trans, void *data);
|
|
||||||
void *cpHashSetRemove(cpHashSet *set, cpHashValue hash, void *ptr);
|
|
||||||
void *cpHashSetFind(cpHashSet *set, cpHashValue hash, void *ptr);
|
|
||||||
|
|
||||||
typedef void (*cpHashSetIteratorFunc)(void *elt, void *data);
|
|
||||||
void cpHashSetEach(cpHashSet *set, cpHashSetIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
typedef cpBool (*cpHashSetFilterFunc)(void *elt, void *data);
|
|
||||||
void cpHashSetFilter(cpHashSet *set, cpHashSetFilterFunc func, void *data);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Bodies
|
|
||||||
|
|
||||||
struct cpBody {
|
|
||||||
// Integration functions
|
|
||||||
cpBodyVelocityFunc velocity_func;
|
|
||||||
cpBodyPositionFunc position_func;
|
|
||||||
|
|
||||||
// mass and it's inverse
|
|
||||||
cpFloat m;
|
|
||||||
cpFloat m_inv;
|
|
||||||
|
|
||||||
// moment of inertia and it's inverse
|
|
||||||
cpFloat i;
|
|
||||||
cpFloat i_inv;
|
|
||||||
|
|
||||||
// center of gravity
|
|
||||||
cpVect cog;
|
|
||||||
|
|
||||||
// position, velocity, force
|
|
||||||
cpVect p;
|
|
||||||
cpVect v;
|
|
||||||
cpVect f;
|
|
||||||
|
|
||||||
// Angle, angular velocity, torque (radians)
|
|
||||||
cpFloat a;
|
|
||||||
cpFloat w;
|
|
||||||
cpFloat t;
|
|
||||||
|
|
||||||
cpTransform transform;
|
|
||||||
|
|
||||||
cpDataPointer userData;
|
|
||||||
|
|
||||||
// "pseudo-velocities" used for eliminating overlap.
|
|
||||||
// Erin Catto has some papers that talk about what these are.
|
|
||||||
cpVect v_bias;
|
|
||||||
cpFloat w_bias;
|
|
||||||
|
|
||||||
cpSpace *space;
|
|
||||||
|
|
||||||
cpShape *shapeList;
|
|
||||||
cpArbiter *arbiterList;
|
|
||||||
cpConstraint *constraintList;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
cpBody *root;
|
|
||||||
cpBody *next;
|
|
||||||
cpFloat idleTime;
|
|
||||||
} sleeping;
|
|
||||||
};
|
|
||||||
|
|
||||||
void cpBodyAddShape(cpBody *body, cpShape *shape);
|
|
||||||
void cpBodyRemoveShape(cpBody *body, cpShape *shape);
|
|
||||||
|
|
||||||
//void cpBodyAccumulateMassForShape(cpBody *body, cpShape *shape);
|
|
||||||
void cpBodyAccumulateMassFromShapes(cpBody *body);
|
|
||||||
|
|
||||||
void cpBodyRemoveConstraint(cpBody *body, cpConstraint *constraint);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Spatial Index Functions
|
|
||||||
|
|
||||||
cpSpatialIndex *cpSpatialIndexInit(cpSpatialIndex *index, cpSpatialIndexClass *klass, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Arbiters
|
|
||||||
|
|
||||||
enum cpArbiterState {
|
|
||||||
// Arbiter is active and its the first collision.
|
|
||||||
CP_ARBITER_STATE_FIRST_COLLISION,
|
|
||||||
// Arbiter is active and its not the first collision.
|
|
||||||
CP_ARBITER_STATE_NORMAL,
|
|
||||||
// Collision has been explicitly ignored.
|
|
||||||
// Either by returning false from a begin collision handler or calling cpArbiterIgnore().
|
|
||||||
CP_ARBITER_STATE_IGNORE,
|
|
||||||
// Collison is no longer active. A space will cache an arbiter for up to cpSpace.collisionPersistence more steps.
|
|
||||||
CP_ARBITER_STATE_CACHED,
|
|
||||||
// Collison arbiter is invalid because one of the shapes was removed.
|
|
||||||
CP_ARBITER_STATE_INVALIDATED,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpArbiterThread {
|
|
||||||
struct cpArbiter *next, *prev;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpContact {
|
|
||||||
cpVect r1, r2;
|
|
||||||
|
|
||||||
cpFloat nMass, tMass;
|
|
||||||
cpFloat bounce; // TODO: look for an alternate bounce solution.
|
|
||||||
|
|
||||||
cpFloat jnAcc, jtAcc, jBias;
|
|
||||||
cpFloat bias;
|
|
||||||
|
|
||||||
cpHashValue hash;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpCollisionInfo {
|
|
||||||
const cpShape *a, *b;
|
|
||||||
cpCollisionID id;
|
|
||||||
|
|
||||||
cpVect n;
|
|
||||||
|
|
||||||
int count;
|
|
||||||
// TODO Should this be a unique struct type?
|
|
||||||
struct cpContact *arr;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpArbiter {
|
|
||||||
cpFloat e;
|
|
||||||
cpFloat u;
|
|
||||||
cpVect surface_vr;
|
|
||||||
|
|
||||||
cpDataPointer data;
|
|
||||||
|
|
||||||
const cpShape *a, *b;
|
|
||||||
cpBody *body_a, *body_b;
|
|
||||||
struct cpArbiterThread thread_a, thread_b;
|
|
||||||
|
|
||||||
int count;
|
|
||||||
struct cpContact *contacts;
|
|
||||||
cpVect n;
|
|
||||||
|
|
||||||
// Regular, wildcard A and wildcard B collision handlers.
|
|
||||||
cpCollisionHandler *handler, *handlerA, *handlerB;
|
|
||||||
cpBool swapped;
|
|
||||||
|
|
||||||
cpTimestamp stamp;
|
|
||||||
enum cpArbiterState state;
|
|
||||||
};
|
|
||||||
|
|
||||||
cpArbiter* cpArbiterInit(cpArbiter *arb, cpShape *a, cpShape *b);
|
|
||||||
|
|
||||||
static inline struct cpArbiterThread *
|
|
||||||
cpArbiterThreadForBody(cpArbiter *arb, cpBody *body)
|
|
||||||
{
|
|
||||||
return (arb->body_a == body ? &arb->thread_a : &arb->thread_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cpArbiterUnthread(cpArbiter *arb);
|
|
||||||
|
|
||||||
void cpArbiterUpdate(cpArbiter *arb, struct cpCollisionInfo *info, cpSpace *space);
|
|
||||||
void cpArbiterPreStep(cpArbiter *arb, cpFloat dt, cpFloat bias, cpFloat slop);
|
|
||||||
void cpArbiterApplyCachedImpulse(cpArbiter *arb, cpFloat dt_coef);
|
|
||||||
void cpArbiterApplyImpulse(cpArbiter *arb);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Shapes/Collisions
|
|
||||||
|
|
||||||
struct cpShapeMassInfo {
|
|
||||||
cpFloat m;
|
|
||||||
cpFloat i;
|
|
||||||
cpVect cog;
|
|
||||||
cpFloat area;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum cpShapeType{
|
|
||||||
CP_CIRCLE_SHAPE,
|
|
||||||
CP_SEGMENT_SHAPE,
|
|
||||||
CP_POLY_SHAPE,
|
|
||||||
CP_NUM_SHAPES
|
|
||||||
} cpShapeType;
|
|
||||||
|
|
||||||
typedef cpBB (*cpShapeCacheDataImpl)(cpShape *shape, cpTransform transform);
|
|
||||||
typedef void (*cpShapeDestroyImpl)(cpShape *shape);
|
|
||||||
typedef void (*cpShapePointQueryImpl)(const cpShape *shape, cpVect p, cpPointQueryInfo *info);
|
|
||||||
typedef void (*cpShapeSegmentQueryImpl)(const cpShape *shape, cpVect a, cpVect b, cpFloat radius, cpSegmentQueryInfo *info);
|
|
||||||
|
|
||||||
typedef struct cpShapeClass cpShapeClass;
|
|
||||||
|
|
||||||
struct cpShapeClass {
|
|
||||||
cpShapeType type;
|
|
||||||
|
|
||||||
cpShapeCacheDataImpl cacheData;
|
|
||||||
cpShapeDestroyImpl destroy;
|
|
||||||
cpShapePointQueryImpl pointQuery;
|
|
||||||
cpShapeSegmentQueryImpl segmentQuery;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpShape {
|
|
||||||
const cpShapeClass *klass;
|
|
||||||
|
|
||||||
cpSpace *space;
|
|
||||||
cpBody *body;
|
|
||||||
struct cpShapeMassInfo massInfo;
|
|
||||||
cpBB bb;
|
|
||||||
|
|
||||||
cpBool sensor;
|
|
||||||
|
|
||||||
cpFloat e;
|
|
||||||
cpFloat u;
|
|
||||||
cpVect surfaceV;
|
|
||||||
|
|
||||||
cpDataPointer userData;
|
|
||||||
|
|
||||||
cpCollisionType type;
|
|
||||||
cpShapeFilter filter;
|
|
||||||
|
|
||||||
cpShape *next;
|
|
||||||
cpShape *prev;
|
|
||||||
|
|
||||||
cpHashValue hashid;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpCircleShape {
|
|
||||||
cpShape shape;
|
|
||||||
|
|
||||||
cpVect c, tc;
|
|
||||||
cpFloat r;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpSegmentShape {
|
|
||||||
cpShape shape;
|
|
||||||
|
|
||||||
cpVect a, b, n;
|
|
||||||
cpVect ta, tb, tn;
|
|
||||||
cpFloat r;
|
|
||||||
|
|
||||||
cpVect a_tangent, b_tangent;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpSplittingPlane {
|
|
||||||
cpVect v0, n;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define CP_POLY_SHAPE_INLINE_ALLOC 6
|
|
||||||
|
|
||||||
struct cpPolyShape {
|
|
||||||
cpShape shape;
|
|
||||||
|
|
||||||
cpFloat r;
|
|
||||||
|
|
||||||
int count;
|
|
||||||
// The untransformed planes are appended at the end of the transformed planes.
|
|
||||||
struct cpSplittingPlane *planes;
|
|
||||||
|
|
||||||
// Allocate a small number of splitting planes internally for simple poly.
|
|
||||||
struct cpSplittingPlane _planes[2*CP_POLY_SHAPE_INLINE_ALLOC];
|
|
||||||
};
|
|
||||||
|
|
||||||
cpShape *cpShapeInit(cpShape *shape, const cpShapeClass *klass, cpBody *body, struct cpShapeMassInfo massInfo);
|
|
||||||
|
|
||||||
static inline cpBool
|
|
||||||
cpShapeActive(cpShape *shape)
|
|
||||||
{
|
|
||||||
// checks if the shape is added to a shape list.
|
|
||||||
// TODO could this just check the space now?
|
|
||||||
return (shape->prev || (shape->body && shape->body->shapeList == shape));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: This function returns contact points with r1/r2 in absolute coordinates, not body relative.
|
|
||||||
struct cpCollisionInfo cpCollide(const cpShape *a, const cpShape *b, cpCollisionID id, struct cpContact *contacts);
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r1, cpVect a, cpVect b, cpFloat r2, cpSegmentQueryInfo *info)
|
|
||||||
{
|
|
||||||
cpVect da = cpvsub(a, center);
|
|
||||||
cpVect db = cpvsub(b, center);
|
|
||||||
cpFloat rsum = r1 + r2;
|
|
||||||
|
|
||||||
cpFloat qa = cpvdot(da, da) - 2.0f*cpvdot(da, db) + cpvdot(db, db);
|
|
||||||
cpFloat qb = cpvdot(da, db) - cpvdot(da, da);
|
|
||||||
cpFloat det = qb*qb - qa*(cpvdot(da, da) - rsum*rsum);
|
|
||||||
|
|
||||||
if(det >= 0.0f){
|
|
||||||
cpFloat t = (-qb - cpfsqrt(det))/(qa);
|
|
||||||
if(0.0f<= t && t <= 1.0f){
|
|
||||||
cpVect n = cpvnormalize(cpvlerp(da, db, t));
|
|
||||||
|
|
||||||
info->shape = shape;
|
|
||||||
info->point = cpvsub(cpvlerp(a, b, t), cpvmult(n, r2));
|
|
||||||
info->normal = n;
|
|
||||||
info->alpha = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpBool
|
|
||||||
cpShapeFilterReject(cpShapeFilter a, cpShapeFilter b)
|
|
||||||
{
|
|
||||||
// Reject the collision if:
|
|
||||||
return (
|
|
||||||
// They are in the same non-zero group.
|
|
||||||
(a.group != 0 && a.group == b.group) ||
|
|
||||||
// One of the category/mask combinations fails.
|
|
||||||
(a.categories & b.mask) == 0 ||
|
|
||||||
(b.categories & a.mask) == 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cpLoopIndexes(const cpVect *verts, int count, int *start, int *end);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Constraints
|
|
||||||
// TODO naming conventions here
|
|
||||||
|
|
||||||
typedef void (*cpConstraintPreStepImpl)(cpConstraint *constraint, cpFloat dt);
|
|
||||||
typedef void (*cpConstraintApplyCachedImpulseImpl)(cpConstraint *constraint, cpFloat dt_coef);
|
|
||||||
typedef void (*cpConstraintApplyImpulseImpl)(cpConstraint *constraint, cpFloat dt);
|
|
||||||
typedef cpFloat (*cpConstraintGetImpulseImpl)(cpConstraint *constraint);
|
|
||||||
|
|
||||||
typedef struct cpConstraintClass {
|
|
||||||
cpConstraintPreStepImpl preStep;
|
|
||||||
cpConstraintApplyCachedImpulseImpl applyCachedImpulse;
|
|
||||||
cpConstraintApplyImpulseImpl applyImpulse;
|
|
||||||
cpConstraintGetImpulseImpl getImpulse;
|
|
||||||
} cpConstraintClass;
|
|
||||||
|
|
||||||
struct cpConstraint {
|
|
||||||
const cpConstraintClass *klass;
|
|
||||||
|
|
||||||
cpSpace *space;
|
|
||||||
|
|
||||||
cpBody *a, *b;
|
|
||||||
cpConstraint *next_a, *next_b;
|
|
||||||
|
|
||||||
cpFloat maxForce;
|
|
||||||
cpFloat errorBias;
|
|
||||||
cpFloat maxBias;
|
|
||||||
|
|
||||||
cpBool collideBodies;
|
|
||||||
|
|
||||||
cpConstraintPreSolveFunc preSolve;
|
|
||||||
cpConstraintPostSolveFunc postSolve;
|
|
||||||
|
|
||||||
cpDataPointer userData;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpPinJoint {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpVect anchorA, anchorB;
|
|
||||||
cpFloat dist;
|
|
||||||
|
|
||||||
cpVect r1, r2;
|
|
||||||
cpVect n;
|
|
||||||
cpFloat nMass;
|
|
||||||
|
|
||||||
cpFloat jnAcc;
|
|
||||||
cpFloat bias;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpSlideJoint {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpVect anchorA, anchorB;
|
|
||||||
cpFloat min, max;
|
|
||||||
|
|
||||||
cpVect r1, r2;
|
|
||||||
cpVect n;
|
|
||||||
cpFloat nMass;
|
|
||||||
|
|
||||||
cpFloat jnAcc;
|
|
||||||
cpFloat bias;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpPivotJoint {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpVect anchorA, anchorB;
|
|
||||||
|
|
||||||
cpVect r1, r2;
|
|
||||||
cpMat2x2 k;
|
|
||||||
|
|
||||||
cpVect jAcc;
|
|
||||||
cpVect bias;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpGrooveJoint {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpVect grv_n, grv_a, grv_b;
|
|
||||||
cpVect anchorB;
|
|
||||||
|
|
||||||
cpVect grv_tn;
|
|
||||||
cpFloat clamp;
|
|
||||||
cpVect r1, r2;
|
|
||||||
cpMat2x2 k;
|
|
||||||
|
|
||||||
cpVect jAcc;
|
|
||||||
cpVect bias;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpDampedSpring {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpVect anchorA, anchorB;
|
|
||||||
cpFloat restLength;
|
|
||||||
cpFloat stiffness;
|
|
||||||
cpFloat damping;
|
|
||||||
cpDampedSpringForceFunc springForceFunc;
|
|
||||||
|
|
||||||
cpFloat target_vrn;
|
|
||||||
cpFloat v_coef;
|
|
||||||
|
|
||||||
cpVect r1, r2;
|
|
||||||
cpFloat nMass;
|
|
||||||
cpVect n;
|
|
||||||
|
|
||||||
cpFloat jAcc;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpDampedRotarySpring {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpFloat restAngle;
|
|
||||||
cpFloat stiffness;
|
|
||||||
cpFloat damping;
|
|
||||||
cpDampedRotarySpringTorqueFunc springTorqueFunc;
|
|
||||||
|
|
||||||
cpFloat target_wrn;
|
|
||||||
cpFloat w_coef;
|
|
||||||
|
|
||||||
cpFloat iSum;
|
|
||||||
cpFloat jAcc;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpRotaryLimitJoint {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpFloat min, max;
|
|
||||||
|
|
||||||
cpFloat iSum;
|
|
||||||
|
|
||||||
cpFloat bias;
|
|
||||||
cpFloat jAcc;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpRatchetJoint {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpFloat angle, phase, ratchet;
|
|
||||||
|
|
||||||
cpFloat iSum;
|
|
||||||
|
|
||||||
cpFloat bias;
|
|
||||||
cpFloat jAcc;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpGearJoint {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpFloat phase, ratio;
|
|
||||||
cpFloat ratio_inv;
|
|
||||||
|
|
||||||
cpFloat iSum;
|
|
||||||
|
|
||||||
cpFloat bias;
|
|
||||||
cpFloat jAcc;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cpSimpleMotor {
|
|
||||||
cpConstraint constraint;
|
|
||||||
cpFloat rate;
|
|
||||||
|
|
||||||
cpFloat iSum;
|
|
||||||
|
|
||||||
cpFloat jAcc;
|
|
||||||
};
|
|
||||||
|
|
||||||
void cpConstraintInit(cpConstraint *constraint, const struct cpConstraintClass *klass, cpBody *a, cpBody *b);
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
cpConstraintActivateBodies(cpConstraint *constraint)
|
|
||||||
{
|
|
||||||
cpBody *a = constraint->a; cpBodyActivate(a);
|
|
||||||
cpBody *b = constraint->b; cpBodyActivate(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpVect
|
|
||||||
relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2){
|
|
||||||
cpVect v1_sum = cpvadd(a->CP_PRIVATE(v), cpvmult(cpvperp(r1), a->CP_PRIVATE(w)));
|
|
||||||
cpVect v2_sum = cpvadd(b->CP_PRIVATE(v), cpvmult(cpvperp(r2), b->CP_PRIVATE(w)));
|
|
||||||
|
|
||||||
return cpvsub(v2_sum, v1_sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpFloat
|
|
||||||
normal_relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n){
|
|
||||||
return cpvdot(relative_velocity(a, b, r1, r2), n);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
apply_impulse(cpBody *body, cpVect j, cpVect r){
|
|
||||||
body->CP_PRIVATE(v) = cpvadd(body->CP_PRIVATE(v), cpvmult(j, body->CP_PRIVATE(m_inv)));
|
|
||||||
body->CP_PRIVATE(w) += body->CP_PRIVATE(i_inv)*cpvcross(r, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
apply_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j)
|
|
||||||
{
|
|
||||||
apply_impulse(a, cpvneg(j), r1);
|
|
||||||
apply_impulse(b, j, r2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
apply_bias_impulse(cpBody *body, cpVect j, cpVect r)
|
|
||||||
{
|
|
||||||
body->CP_PRIVATE(v_bias) = cpvadd(body->CP_PRIVATE(v_bias), cpvmult(j, body->CP_PRIVATE(m_inv)));
|
|
||||||
body->CP_PRIVATE(w_bias) += body->CP_PRIVATE(i_inv)*cpvcross(r, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
apply_bias_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j)
|
|
||||||
{
|
|
||||||
apply_bias_impulse(a, cpvneg(j), r1);
|
|
||||||
apply_bias_impulse(b, j, r2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpFloat
|
|
||||||
k_scalar_body(cpBody *body, cpVect r, cpVect n)
|
|
||||||
{
|
|
||||||
cpFloat rcn = cpvcross(r, n);
|
|
||||||
return body->CP_PRIVATE(m_inv) + body->CP_PRIVATE(i_inv)*rcn*rcn;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpFloat
|
|
||||||
k_scalar(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n)
|
|
||||||
{
|
|
||||||
cpFloat value = k_scalar_body(a, r1, n) + k_scalar_body(b, r2, n);
|
|
||||||
cpAssertSoft(value != 0.0, "Unsolvable collision or constraint.");
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpMat2x2
|
|
||||||
k_tensor(cpBody *a, cpBody *b, cpVect r1, cpVect r2)
|
|
||||||
{
|
|
||||||
cpFloat m_sum = a->CP_PRIVATE(m_inv) + b->CP_PRIVATE(m_inv);
|
|
||||||
|
|
||||||
// start with Identity*m_sum
|
|
||||||
cpFloat k11 = m_sum, k12 = 0.0f;
|
|
||||||
cpFloat k21 = 0.0f, k22 = m_sum;
|
|
||||||
|
|
||||||
// add the influence from r1
|
|
||||||
cpFloat a_i_inv = a->CP_PRIVATE(i_inv);
|
|
||||||
cpFloat r1xsq = r1.x * r1.x * a_i_inv;
|
|
||||||
cpFloat r1ysq = r1.y * r1.y * a_i_inv;
|
|
||||||
cpFloat r1nxy = -r1.x * r1.y * a_i_inv;
|
|
||||||
k11 += r1ysq; k12 += r1nxy;
|
|
||||||
k21 += r1nxy; k22 += r1xsq;
|
|
||||||
|
|
||||||
// add the influnce from r2
|
|
||||||
cpFloat b_i_inv = b->CP_PRIVATE(i_inv);
|
|
||||||
cpFloat r2xsq = r2.x * r2.x * b_i_inv;
|
|
||||||
cpFloat r2ysq = r2.y * r2.y * b_i_inv;
|
|
||||||
cpFloat r2nxy = -r2.x * r2.y * b_i_inv;
|
|
||||||
k11 += r2ysq; k12 += r2nxy;
|
|
||||||
k21 += r2nxy; k22 += r2xsq;
|
|
||||||
|
|
||||||
// invert
|
|
||||||
cpFloat det = k11*k22 - k12*k21;
|
|
||||||
cpAssertSoft(det != 0.0, "Unsolvable constraint.");
|
|
||||||
|
|
||||||
cpFloat det_inv = 1.0f/det;
|
|
||||||
return cpMat2x2New(
|
|
||||||
k22*det_inv, -k12*det_inv,
|
|
||||||
-k21*det_inv, k11*det_inv
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpFloat
|
|
||||||
bias_coef(cpFloat errorBias, cpFloat dt)
|
|
||||||
{
|
|
||||||
return 1.0f - cpfpow(errorBias, dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Spaces
|
|
||||||
|
|
||||||
typedef struct cpContactBufferHeader cpContactBufferHeader;
|
|
||||||
typedef void (*cpSpaceArbiterApplyImpulseFunc)(cpArbiter *arb);
|
|
||||||
|
|
||||||
struct cpSpace {
|
|
||||||
int iterations;
|
|
||||||
|
|
||||||
cpVect gravity;
|
|
||||||
cpFloat damping;
|
|
||||||
|
|
||||||
cpFloat idleSpeedThreshold;
|
|
||||||
cpFloat sleepTimeThreshold;
|
|
||||||
|
|
||||||
cpFloat collisionSlop;
|
|
||||||
cpFloat collisionBias;
|
|
||||||
cpTimestamp collisionPersistence;
|
|
||||||
|
|
||||||
cpDataPointer userData;
|
|
||||||
|
|
||||||
cpTimestamp stamp;
|
|
||||||
cpFloat curr_dt;
|
|
||||||
|
|
||||||
cpArray *dynamicBodies;
|
|
||||||
cpArray *staticBodies;
|
|
||||||
cpArray *rousedBodies;
|
|
||||||
cpArray *sleepingComponents;
|
|
||||||
|
|
||||||
cpHashValue shapeIDCounter;
|
|
||||||
cpSpatialIndex *staticShapes;
|
|
||||||
cpSpatialIndex *dynamicShapes;
|
|
||||||
|
|
||||||
cpArray *constraints;
|
|
||||||
|
|
||||||
cpArray *arbiters;
|
|
||||||
cpContactBufferHeader *contactBuffersHead;
|
|
||||||
cpHashSet *cachedArbiters;
|
|
||||||
cpArray *pooledArbiters;
|
|
||||||
|
|
||||||
cpArray *allocatedBuffers;
|
|
||||||
unsigned int locked;
|
|
||||||
|
|
||||||
cpBool usesWildcards;
|
|
||||||
cpHashSet *collisionHandlers;
|
|
||||||
cpCollisionHandler defaultHandler;
|
|
||||||
|
|
||||||
cpBool skipPostStep;
|
|
||||||
cpArray *postStepCallbacks;
|
|
||||||
|
|
||||||
cpBody *staticBody;
|
|
||||||
cpBody _staticBody;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define cpAssertSpaceUnlocked(space) \
|
|
||||||
cpAssertHard(!space->locked, \
|
|
||||||
"This operation cannot be done safely during a call to cpSpaceStep() or during a query. " \
|
|
||||||
"Put these calls into a post-step callback." \
|
|
||||||
);
|
|
||||||
|
|
||||||
void cpSpaceSetStaticBody(cpSpace *space, cpBody *body);
|
|
||||||
|
|
||||||
extern cpCollisionHandler cpCollisionHandlerDoNothing;
|
|
||||||
|
|
||||||
void cpSpaceProcessComponents(cpSpace *space, cpFloat dt);
|
|
||||||
|
|
||||||
void cpSpacePushFreshContactBuffer(cpSpace *space);
|
|
||||||
struct cpContact *cpContactBufferGetArray(cpSpace *space);
|
|
||||||
void cpSpacePushContacts(cpSpace *space, int count);
|
|
||||||
|
|
||||||
typedef struct cpPostStepCallback {
|
|
||||||
cpPostStepFunc func;
|
|
||||||
void *key;
|
|
||||||
void *data;
|
|
||||||
} cpPostStepCallback;
|
|
||||||
|
|
||||||
cpPostStepCallback *cpSpaceGetPostStepCallback(cpSpace *space, void *key);
|
|
||||||
|
|
||||||
cpBool cpSpaceArbiterSetFilter(cpArbiter *arb, cpSpace *space);
|
|
||||||
void cpSpaceFilterArbiters(cpSpace *space, cpBody *body, cpShape *filter);
|
|
||||||
|
|
||||||
void cpSpaceActivateBody(cpSpace *space, cpBody *body);
|
|
||||||
void cpSpaceLock(cpSpace *space);
|
|
||||||
void cpSpaceUnlock(cpSpace *space, cpBool runPostStep);
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
cpSpaceUncacheArbiter(cpSpace *space, cpArbiter *arb)
|
|
||||||
{
|
|
||||||
const cpShape *a = arb->a, *b = arb->b;
|
|
||||||
const cpShape *shape_pair[] = {a, b};
|
|
||||||
cpHashValue arbHashID = CP_HASH_PAIR((cpHashValue)a, (cpHashValue)b);
|
|
||||||
cpHashSetRemove(space->cachedArbiters, arbHashID, shape_pair);
|
|
||||||
cpArrayDeleteObj(space->arbiters, arb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpArray *
|
|
||||||
cpSpaceArrayForBodyType(cpSpace *space, cpBodyType type)
|
|
||||||
{
|
|
||||||
return (type == CP_BODY_TYPE_STATIC ? space->staticBodies : space->dynamicBodies);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cpShapeUpdateFunc(cpShape *shape, void *unused);
|
|
||||||
cpCollisionID cpSpaceCollideShapes(cpShape *a, cpShape *b, cpCollisionID id, cpSpace *space);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Foreach loops
|
|
||||||
|
|
||||||
static inline cpConstraint *
|
|
||||||
cpConstraintNext(cpConstraint *node, cpBody *body)
|
|
||||||
{
|
|
||||||
return (node->a == body ? node->next_a : node->next_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CP_BODY_FOREACH_CONSTRAINT(bdy, var)\
|
|
||||||
for(cpConstraint *var = bdy->constraintList; var; var = cpConstraintNext(var, bdy))
|
|
||||||
|
|
||||||
static inline cpArbiter *
|
|
||||||
cpArbiterNext(cpArbiter *node, cpBody *body)
|
|
||||||
{
|
|
||||||
return (node->body_a == body ? node->thread_a.next : node->thread_b.next);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CP_BODY_FOREACH_ARBITER(bdy, var)\
|
|
||||||
for(cpArbiter *var = bdy->arbiterList; var; var = cpArbiterNext(var, bdy))
|
|
||||||
|
|
||||||
#define CP_BODY_FOREACH_SHAPE(body, var)\
|
|
||||||
for(cpShape *var = body->shapeList; var; var = var->next)
|
|
||||||
|
|
||||||
#define CP_BODY_FOREACH_COMPONENT(root, var)\
|
|
||||||
for(cpBody *var = root; var; var = var->sleeping.next)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,242 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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 CHIPMUNK_TYPES_H
|
|
||||||
#define CHIPMUNK_TYPES_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <float.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#ifndef CP_USE_DOUBLES
|
|
||||||
// Use doubles by default for higher precision.
|
|
||||||
#define CP_USE_DOUBLES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// @defgroup basicTypes Basic Types
|
|
||||||
/// Most of these types can be configured at compile time.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
#if CP_USE_DOUBLES
|
|
||||||
/// Chipmunk's floating point type.
|
|
||||||
/// Can be reconfigured at compile time.
|
|
||||||
typedef double cpFloat;
|
|
||||||
#define cpfsqrt sqrt
|
|
||||||
#define cpfsin sin
|
|
||||||
#define cpfcos cos
|
|
||||||
#define cpfacos acos
|
|
||||||
#define cpfatan2 atan2
|
|
||||||
#define cpfmod fmod
|
|
||||||
#define cpfexp exp
|
|
||||||
#define cpfpow pow
|
|
||||||
#define cpffloor floor
|
|
||||||
#define cpfceil ceil
|
|
||||||
#define CPFLOAT_MIN DBL_MIN
|
|
||||||
#else
|
|
||||||
typedef float cpFloat;
|
|
||||||
#define cpfsqrt sqrtf
|
|
||||||
#define cpfsin sinf
|
|
||||||
#define cpfcos cosf
|
|
||||||
#define cpfacos acosf
|
|
||||||
#define cpfatan2 atan2f
|
|
||||||
#define cpfmod fmodf
|
|
||||||
#define cpfexp expf
|
|
||||||
#define cpfpow powf
|
|
||||||
#define cpffloor floorf
|
|
||||||
#define cpfceil ceilf
|
|
||||||
#define CPFLOAT_MIN FLT_MIN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef INFINITY
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
union MSVC_EVIL_FLOAT_HACK
|
|
||||||
{
|
|
||||||
unsigned __int8 Bytes[4];
|
|
||||||
float Value;
|
|
||||||
};
|
|
||||||
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
|
|
||||||
#define INFINITY (INFINITY_HACK.Value)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define INFINITY (__builtin_inf())
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef INFINITY
|
|
||||||
#define INFINITY (1e1000)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define CP_PI ((cpFloat)3.14159265358979323846264338327950288)
|
|
||||||
|
|
||||||
|
|
||||||
/// Return the max of two cpFloats.
|
|
||||||
static inline cpFloat cpfmax(cpFloat a, cpFloat b)
|
|
||||||
{
|
|
||||||
return (a > b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the min of two cpFloats.
|
|
||||||
static inline cpFloat cpfmin(cpFloat a, cpFloat b)
|
|
||||||
{
|
|
||||||
return (a < b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the absolute value of a cpFloat.
|
|
||||||
static inline cpFloat cpfabs(cpFloat f)
|
|
||||||
{
|
|
||||||
return (f < 0) ? -f : f;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clamp @c f to be between @c min and @c max.
|
|
||||||
static inline cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max)
|
|
||||||
{
|
|
||||||
return cpfmin(cpfmax(f, min), max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clamp @c f to be between 0 and 1.
|
|
||||||
static inline cpFloat cpfclamp01(cpFloat f)
|
|
||||||
{
|
|
||||||
return cpfmax(0.0f, cpfmin(f, 1.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Linearly interpolate (or extrapolate) between @c f1 and @c f2 by @c t percent.
|
|
||||||
static inline cpFloat cpflerp(cpFloat f1, cpFloat f2, cpFloat t)
|
|
||||||
{
|
|
||||||
return f1*(1.0f - t) + f2*t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Linearly interpolate from @c f1 to @c f2 by no more than @c d.
|
|
||||||
static inline cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d)
|
|
||||||
{
|
|
||||||
return f1 + cpfclamp(f2 - f1, -d, d);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Hash value type.
|
|
||||||
#ifdef CP_HASH_VALUE_TYPE
|
|
||||||
typedef CP_HASH_VALUE_TYPE cpHashValue;
|
|
||||||
#else
|
|
||||||
typedef uintptr_t cpHashValue;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Type used internally to cache colliding object info for cpCollideShapes().
|
|
||||||
/// Should be at least 32 bits.
|
|
||||||
typedef uint32_t cpCollisionID;
|
|
||||||
|
|
||||||
// Oh C, how we love to define our own boolean types to get compiler compatibility
|
|
||||||
/// Chipmunk's boolean type.
|
|
||||||
#ifdef CP_BOOL_TYPE
|
|
||||||
typedef CP_BOOL_TYPE cpBool;
|
|
||||||
#else
|
|
||||||
typedef unsigned char cpBool;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef cpTrue
|
|
||||||
/// true value.
|
|
||||||
#define cpTrue 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef cpFalse
|
|
||||||
/// false value.
|
|
||||||
#define cpFalse 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CP_DATA_POINTER_TYPE
|
|
||||||
typedef CP_DATA_POINTER_TYPE cpDataPointer;
|
|
||||||
#else
|
|
||||||
/// Type used for user data pointers.
|
|
||||||
typedef void * cpDataPointer;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CP_COLLISION_TYPE_TYPE
|
|
||||||
typedef CP_COLLISION_TYPE_TYPE cpCollisionType;
|
|
||||||
#else
|
|
||||||
/// Type used for cpSpace.collision_type.
|
|
||||||
typedef uintptr_t cpCollisionType;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CP_GROUP_TYPE
|
|
||||||
typedef CP_GROUP_TYPE cpGroup;
|
|
||||||
#else
|
|
||||||
/// Type used for cpShape.group.
|
|
||||||
typedef uintptr_t cpGroup;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CP_BITMASK_TYPE
|
|
||||||
typedef CP_BITMASK_TYPE cpBitmask;
|
|
||||||
#else
|
|
||||||
/// Type used for cpShapeFilter category and mask.
|
|
||||||
typedef unsigned int cpBitmask;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CP_TIMESTAMP_TYPE
|
|
||||||
typedef CP_TIMESTAMP_TYPE cpTimestamp;
|
|
||||||
#else
|
|
||||||
/// Type used for various timestamps in Chipmunk.
|
|
||||||
typedef unsigned int cpTimestamp;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CP_NO_GROUP
|
|
||||||
/// Value for cpShape.group signifying that a shape is in no group.
|
|
||||||
#define CP_NO_GROUP ((cpGroup)0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CP_ALL_CATEGORIES
|
|
||||||
/// Value for cpShape.layers signifying that a shape is in every layer.
|
|
||||||
#define CP_ALL_CATEGORIES (~(cpBitmask)0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CP_WILDCARD_COLLISION_TYPE
|
|
||||||
/// cpCollisionType value internally reserved for hashing wildcard handlers.
|
|
||||||
#define CP_WILDCARD_COLLISION_TYPE (~(cpCollisionType)0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
// CGPoints are structurally the same, and allow
|
|
||||||
// easy interoperability with other Cocoa libraries
|
|
||||||
#if CP_USE_CGTYPES
|
|
||||||
typedef CGPoint cpVect;
|
|
||||||
#else
|
|
||||||
/// Chipmunk's 2D vector type.
|
|
||||||
/// @addtogroup cpVect
|
|
||||||
typedef struct cpVect{cpFloat x,y;} cpVect;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CP_USE_CGTYPES
|
|
||||||
typedef CGAffineTransform cpTransform;
|
|
||||||
#else
|
|
||||||
/// Column major affine transform.
|
|
||||||
typedef struct cpTransform {
|
|
||||||
cpFloat a, b, c, d, tx, ty;
|
|
||||||
} cpTransform;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NUKE
|
|
||||||
typedef struct cpMat2x2 {
|
|
||||||
// Row major [[a, b][c d]]
|
|
||||||
cpFloat a, b, c, d;
|
|
||||||
} cpMat2x2;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This header defines a number of "unsafe" operations on Chipmunk objects.
|
|
||||||
* In this case "unsafe" is referring to operations which may reduce the
|
|
||||||
* physical accuracy or numerical stability of the simulation, but will not
|
|
||||||
* cause crashes.
|
|
||||||
*
|
|
||||||
* The prime example is mutating collision shapes. Chipmunk does not support
|
|
||||||
* this directly. Mutating shapes using this API will caused objects in contact
|
|
||||||
* to be pushed apart using Chipmunk's overlap solver, but not using real
|
|
||||||
* persistent velocities. Probably not what you meant, but perhaps close enough.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup unsafe Chipmunk Unsafe Shape Operations
|
|
||||||
/// These functions are used for mutating collision shapes.
|
|
||||||
/// Chipmunk does not have any way to get velocity information on changing shapes,
|
|
||||||
/// so the results will be unrealistic. You must explicity include the chipmunk_unsafe.h header to use them.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
#ifndef CHIPMUNK_UNSAFE_H
|
|
||||||
#define CHIPMUNK_UNSAFE_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Set the radius of a circle shape.
|
|
||||||
CP_EXPORT void cpCircleShapeSetRadius(cpShape *shape, cpFloat radius);
|
|
||||||
/// Set the offset of a circle shape.
|
|
||||||
CP_EXPORT void cpCircleShapeSetOffset(cpShape *shape, cpVect offset);
|
|
||||||
|
|
||||||
/// Set the endpoints of a segment shape.
|
|
||||||
CP_EXPORT void cpSegmentShapeSetEndpoints(cpShape *shape, cpVect a, cpVect b);
|
|
||||||
/// Set the radius of a segment shape.
|
|
||||||
CP_EXPORT void cpSegmentShapeSetRadius(cpShape *shape, cpFloat radius);
|
|
||||||
|
|
||||||
/// Set the vertexes of a poly shape.
|
|
||||||
CP_EXPORT void cpPolyShapeSetVerts(cpShape *shape, int count, cpVect *verts, cpTransform transform);
|
|
||||||
CP_EXPORT void cpPolyShapeSetVertsRaw(cpShape *shape, int count, cpVect *verts);
|
|
||||||
/// Set the radius of a poly shape.
|
|
||||||
CP_EXPORT void cpPolyShapeSetRadius(cpShape *shape, cpFloat radius);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,145 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpArbiter cpArbiter
|
|
||||||
/// The cpArbiter struct tracks pairs of colliding shapes.
|
|
||||||
/// They are also used in conjuction with collision handler callbacks
|
|
||||||
/// allowing you to retrieve information on the collision or change it.
|
|
||||||
/// A unique arbiter value is used for each pair of colliding objects. It persists until the shapes separate.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
#define CP_MAX_CONTACTS_PER_ARBITER 2
|
|
||||||
|
|
||||||
/// Get the restitution (elasticity) that will be applied to the pair of colliding objects.
|
|
||||||
CP_EXPORT cpFloat cpArbiterGetRestitution(const cpArbiter *arb);
|
|
||||||
/// Override the restitution (elasticity) that will be applied to the pair of colliding objects.
|
|
||||||
CP_EXPORT void cpArbiterSetRestitution(cpArbiter *arb, cpFloat restitution);
|
|
||||||
/// Get the friction coefficient that will be applied to the pair of colliding objects.
|
|
||||||
CP_EXPORT cpFloat cpArbiterGetFriction(const cpArbiter *arb);
|
|
||||||
/// Override the friction coefficient that will be applied to the pair of colliding objects.
|
|
||||||
CP_EXPORT void cpArbiterSetFriction(cpArbiter *arb, cpFloat friction);
|
|
||||||
|
|
||||||
// Get the relative surface velocity of the two shapes in contact.
|
|
||||||
CP_EXPORT cpVect cpArbiterGetSurfaceVelocity(cpArbiter *arb);
|
|
||||||
|
|
||||||
// Override the relative surface velocity of the two shapes in contact.
|
|
||||||
// By default this is calculated to be the difference of the two surface velocities clamped to the tangent plane.
|
|
||||||
CP_EXPORT void cpArbiterSetSurfaceVelocity(cpArbiter *arb, cpVect vr);
|
|
||||||
|
|
||||||
/// Get the user data pointer associated with this pair of colliding objects.
|
|
||||||
CP_EXPORT cpDataPointer cpArbiterGetUserData(const cpArbiter *arb);
|
|
||||||
/// Set a user data point associated with this pair of colliding objects.
|
|
||||||
/// If you need to perform any cleanup for this pointer, you must do it yourself, in the separate callback for instance.
|
|
||||||
CP_EXPORT void cpArbiterSetUserData(cpArbiter *arb, cpDataPointer userData);
|
|
||||||
|
|
||||||
/// Calculate the total impulse including the friction that was applied by this arbiter.
|
|
||||||
/// This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
|
|
||||||
CP_EXPORT cpVect cpArbiterTotalImpulse(const cpArbiter *arb);
|
|
||||||
/// Calculate the amount of energy lost in a collision including static, but not dynamic friction.
|
|
||||||
/// This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
|
|
||||||
CP_EXPORT cpFloat cpArbiterTotalKE(const cpArbiter *arb);
|
|
||||||
|
|
||||||
/// Mark a collision pair to be ignored until the two objects separate.
|
|
||||||
/// Pre-solve and post-solve callbacks will not be called, but the separate callback will be called.
|
|
||||||
CP_EXPORT cpBool cpArbiterIgnore(cpArbiter *arb);
|
|
||||||
|
|
||||||
/// Return the colliding shapes involved for this arbiter.
|
|
||||||
/// The order of their cpSpace.collision_type values will match
|
|
||||||
/// the order set when the collision handler was registered.
|
|
||||||
CP_EXPORT void cpArbiterGetShapes(const cpArbiter *arb, cpShape **a, cpShape **b);
|
|
||||||
|
|
||||||
/// A macro shortcut for defining and retrieving the shapes from an arbiter.
|
|
||||||
#define CP_ARBITER_GET_SHAPES(__arb__, __a__, __b__) cpShape *__a__, *__b__; cpArbiterGetShapes(__arb__, &__a__, &__b__);
|
|
||||||
|
|
||||||
/// Return the colliding bodies involved for this arbiter.
|
|
||||||
/// The order of the cpSpace.collision_type the bodies are associated with values will match
|
|
||||||
/// the order set when the collision handler was registered.
|
|
||||||
CP_EXPORT void cpArbiterGetBodies(const cpArbiter *arb, cpBody **a, cpBody **b);
|
|
||||||
|
|
||||||
/// A macro shortcut for defining and retrieving the bodies from an arbiter.
|
|
||||||
#define CP_ARBITER_GET_BODIES(__arb__, __a__, __b__) cpBody *__a__, *__b__; cpArbiterGetBodies(__arb__, &__a__, &__b__);
|
|
||||||
|
|
||||||
/// A struct that wraps up the important collision data for an arbiter.
|
|
||||||
struct cpContactPointSet {
|
|
||||||
/// The number of contact points in the set.
|
|
||||||
int count;
|
|
||||||
|
|
||||||
/// The normal of the collision.
|
|
||||||
cpVect normal;
|
|
||||||
|
|
||||||
/// The array of contact points.
|
|
||||||
struct {
|
|
||||||
/// The position of the contact on the surface of each shape.
|
|
||||||
cpVect pointA, pointB;
|
|
||||||
/// Penetration distance of the two shapes. Overlapping means it will be negative.
|
|
||||||
/// This value is calculated as cpvdot(cpvsub(point2, point1), normal) and is ignored by cpArbiterSetContactPointSet().
|
|
||||||
cpFloat distance;
|
|
||||||
} points[CP_MAX_CONTACTS_PER_ARBITER];
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Return a contact set from an arbiter.
|
|
||||||
CP_EXPORT cpContactPointSet cpArbiterGetContactPointSet(const cpArbiter *arb);
|
|
||||||
|
|
||||||
/// Replace the contact point set for an arbiter.
|
|
||||||
/// This can be a very powerful feature, but use it with caution!
|
|
||||||
CP_EXPORT void cpArbiterSetContactPointSet(cpArbiter *arb, cpContactPointSet *set);
|
|
||||||
|
|
||||||
/// Returns true if this is the first step a pair of objects started colliding.
|
|
||||||
CP_EXPORT cpBool cpArbiterIsFirstContact(const cpArbiter *arb);
|
|
||||||
/// Returns true if the separate callback is due to a shape being removed from the space.
|
|
||||||
CP_EXPORT cpBool cpArbiterIsRemoval(const cpArbiter *arb);
|
|
||||||
|
|
||||||
/// Get the number of contact points for this arbiter.
|
|
||||||
CP_EXPORT int cpArbiterGetCount(const cpArbiter *arb);
|
|
||||||
/// Get the normal of the collision.
|
|
||||||
CP_EXPORT cpVect cpArbiterGetNormal(const cpArbiter *arb);
|
|
||||||
/// Get the position of the @c ith contact point on the surface of the first shape.
|
|
||||||
CP_EXPORT cpVect cpArbiterGetPointA(const cpArbiter *arb, int i);
|
|
||||||
/// Get the position of the @c ith contact point on the surface of the second shape.
|
|
||||||
CP_EXPORT cpVect cpArbiterGetPointB(const cpArbiter *arb, int i);
|
|
||||||
/// Get the depth of the @c ith contact point.
|
|
||||||
CP_EXPORT cpFloat cpArbiterGetDepth(const cpArbiter *arb, int i);
|
|
||||||
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
|
|
||||||
/// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
|
|
||||||
CP_EXPORT cpBool cpArbiterCallWildcardBeginA(cpArbiter *arb, cpSpace *space);
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
|
|
||||||
/// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
|
|
||||||
CP_EXPORT cpBool cpArbiterCallWildcardBeginB(cpArbiter *arb, cpSpace *space);
|
|
||||||
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
|
|
||||||
/// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
|
|
||||||
CP_EXPORT cpBool cpArbiterCallWildcardPreSolveA(cpArbiter *arb, cpSpace *space);
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
|
|
||||||
/// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
|
|
||||||
CP_EXPORT cpBool cpArbiterCallWildcardPreSolveB(cpArbiter *arb, cpSpace *space);
|
|
||||||
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
|
|
||||||
CP_EXPORT void cpArbiterCallWildcardPostSolveA(cpArbiter *arb, cpSpace *space);
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
|
|
||||||
CP_EXPORT void cpArbiterCallWildcardPostSolveB(cpArbiter *arb, cpSpace *space);
|
|
||||||
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
|
|
||||||
CP_EXPORT void cpArbiterCallWildcardSeparateA(cpArbiter *arb, cpSpace *space);
|
|
||||||
/// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
|
|
||||||
CP_EXPORT void cpArbiterCallWildcardSeparateB(cpArbiter *arb, cpSpace *space);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,187 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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 CHIPMUNK_BB_H
|
|
||||||
#define CHIPMUNK_BB_H
|
|
||||||
|
|
||||||
#include "chipmunk_types.h"
|
|
||||||
#include "cpVect.h"
|
|
||||||
|
|
||||||
/// @defgroup cpBBB cpBB
|
|
||||||
/// Chipmunk's axis-aligned 2D bounding box type along with a few handy routines.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
|
|
||||||
typedef struct cpBB{
|
|
||||||
cpFloat l, b, r ,t;
|
|
||||||
} cpBB;
|
|
||||||
|
|
||||||
/// Convenience constructor for cpBB structs.
|
|
||||||
static inline cpBB cpBBNew(const cpFloat l, const cpFloat b, const cpFloat r, const cpFloat t)
|
|
||||||
{
|
|
||||||
cpBB bb = {l, b, r, t};
|
|
||||||
return bb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Constructs a cpBB centered on a point with the given extents (half sizes).
|
|
||||||
static inline cpBB
|
|
||||||
cpBBNewForExtents(const cpVect c, const cpFloat hw, const cpFloat hh)
|
|
||||||
{
|
|
||||||
return cpBBNew(c.x - hw, c.y - hh, c.x + hw, c.y + hh);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Constructs a cpBB for a circle with the given position and radius.
|
|
||||||
static inline cpBB cpBBNewForCircle(const cpVect p, const cpFloat r)
|
|
||||||
{
|
|
||||||
return cpBBNewForExtents(p, r, r);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if @c a and @c b intersect.
|
|
||||||
static inline cpBool cpBBIntersects(const cpBB a, const cpBB b)
|
|
||||||
{
|
|
||||||
return (a.l <= b.r && b.l <= a.r && a.b <= b.t && b.b <= a.t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if @c other lies completely within @c bb.
|
|
||||||
static inline cpBool cpBBContainsBB(const cpBB bb, const cpBB other)
|
|
||||||
{
|
|
||||||
return (bb.l <= other.l && bb.r >= other.r && bb.b <= other.b && bb.t >= other.t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if @c bb contains @c v.
|
|
||||||
static inline cpBool cpBBContainsVect(const cpBB bb, const cpVect v)
|
|
||||||
{
|
|
||||||
return (bb.l <= v.x && bb.r >= v.x && bb.b <= v.y && bb.t >= v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a bounding box that holds both bounding boxes.
|
|
||||||
static inline cpBB cpBBMerge(const cpBB a, const cpBB b){
|
|
||||||
return cpBBNew(
|
|
||||||
cpfmin(a.l, b.l),
|
|
||||||
cpfmin(a.b, b.b),
|
|
||||||
cpfmax(a.r, b.r),
|
|
||||||
cpfmax(a.t, b.t)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a bounding box that holds both @c bb and @c v.
|
|
||||||
static inline cpBB cpBBExpand(const cpBB bb, const cpVect v){
|
|
||||||
return cpBBNew(
|
|
||||||
cpfmin(bb.l, v.x),
|
|
||||||
cpfmin(bb.b, v.y),
|
|
||||||
cpfmax(bb.r, v.x),
|
|
||||||
cpfmax(bb.t, v.y)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the center of a bounding box.
|
|
||||||
static inline cpVect
|
|
||||||
cpBBCenter(cpBB bb)
|
|
||||||
{
|
|
||||||
return cpvlerp(cpv(bb.l, bb.b), cpv(bb.r, bb.t), 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the area of the bounding box.
|
|
||||||
static inline cpFloat cpBBArea(cpBB bb)
|
|
||||||
{
|
|
||||||
return (bb.r - bb.l)*(bb.t - bb.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Merges @c a and @c b and returns the area of the merged bounding box.
|
|
||||||
static inline cpFloat cpBBMergedArea(cpBB a, cpBB b)
|
|
||||||
{
|
|
||||||
return (cpfmax(a.r, b.r) - cpfmin(a.l, b.l))*(cpfmax(a.t, b.t) - cpfmin(a.b, b.b));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the fraction along the segment query the cpBB is hit. Returns INFINITY if it doesn't hit.
|
|
||||||
static inline cpFloat cpBBSegmentQuery(cpBB bb, cpVect a, cpVect b)
|
|
||||||
{
|
|
||||||
cpFloat idx = 1.0f/(b.x - a.x);
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning(disable: 4056)
|
|
||||||
#endif
|
|
||||||
cpFloat tx1 = (bb.l == a.x ? -INFINITY : (bb.l - a.x)*idx);
|
|
||||||
cpFloat tx2 = (bb.r == a.x ? INFINITY : (bb.r - a.x)*idx);
|
|
||||||
cpFloat txmin = cpfmin(tx1, tx2);
|
|
||||||
cpFloat txmax = cpfmax(tx1, tx2);
|
|
||||||
|
|
||||||
cpFloat idy = 1.0f/(b.y - a.y);
|
|
||||||
cpFloat ty1 = (bb.b == a.y ? -INFINITY : (bb.b - a.y)*idy);
|
|
||||||
cpFloat ty2 = (bb.t == a.y ? INFINITY : (bb.t - a.y)*idy);
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning(default: 4056)
|
|
||||||
#endif
|
|
||||||
cpFloat tymin = cpfmin(ty1, ty2);
|
|
||||||
cpFloat tymax = cpfmax(ty1, ty2);
|
|
||||||
|
|
||||||
if(tymin <= txmax && txmin <= tymax){
|
|
||||||
cpFloat min = cpfmax(txmin, tymin);
|
|
||||||
cpFloat max = cpfmin(txmax, tymax);
|
|
||||||
|
|
||||||
if(0.0 <= max && min <= 1.0) return cpfmax(min, 0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return INFINITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return true if the bounding box intersects the line segment with ends @c a and @c b.
|
|
||||||
static inline cpBool cpBBIntersectsSegment(cpBB bb, cpVect a, cpVect b)
|
|
||||||
{
|
|
||||||
return (cpBBSegmentQuery(bb, a, b) != INFINITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clamp a vector to a bounding box.
|
|
||||||
static inline cpVect
|
|
||||||
cpBBClampVect(const cpBB bb, const cpVect v)
|
|
||||||
{
|
|
||||||
return cpv(cpfclamp(v.x, bb.l, bb.r), cpfclamp(v.y, bb.b, bb.t));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Wrap a vector to a bounding box.
|
|
||||||
static inline cpVect
|
|
||||||
cpBBWrapVect(const cpBB bb, const cpVect v)
|
|
||||||
{
|
|
||||||
cpFloat dx = cpfabs(bb.r - bb.l);
|
|
||||||
cpFloat modx = cpfmod(v.x - bb.l, dx);
|
|
||||||
cpFloat x = (modx > 0.0f) ? modx : modx + dx;
|
|
||||||
|
|
||||||
cpFloat dy = cpfabs(bb.t - bb.b);
|
|
||||||
cpFloat mody = cpfmod(v.y - bb.b, dy);
|
|
||||||
cpFloat y = (mody > 0.0f) ? mody : mody + dy;
|
|
||||||
|
|
||||||
return cpv(x + bb.l, y + bb.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a bounding box offseted by @c v.
|
|
||||||
static inline cpBB
|
|
||||||
cpBBOffset(const cpBB bb, const cpVect v)
|
|
||||||
{
|
|
||||||
return cpBBNew(
|
|
||||||
bb.l + v.x,
|
|
||||||
bb.b + v.y,
|
|
||||||
bb.r + v.x,
|
|
||||||
bb.t + v.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
///@}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,189 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpBody cpBody
|
|
||||||
/// Chipmunk's rigid body type. Rigid bodies hold the physical properties of an object like
|
|
||||||
/// it's mass, and position and velocity of it's center of gravity. They don't have an shape on their own.
|
|
||||||
/// They are given a shape by creating collision shapes (cpShape) that point to the body.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
typedef enum cpBodyType {
|
|
||||||
/// A dynamic body is one that is affected by gravity, forces, and collisions.
|
|
||||||
/// This is the default body type.
|
|
||||||
CP_BODY_TYPE_DYNAMIC,
|
|
||||||
/// A kinematic body is an infinite mass, user controlled body that is not affected by gravity, forces or collisions.
|
|
||||||
/// Instead the body only moves based on it's velocity.
|
|
||||||
/// Dynamic bodies collide normally with kinematic bodies, though the kinematic body will be unaffected.
|
|
||||||
/// Collisions between two kinematic bodies, or a kinematic body and a static body produce collision callbacks, but no collision response.
|
|
||||||
CP_BODY_TYPE_KINEMATIC,
|
|
||||||
/// A static body is a body that never (or rarely) moves. If you move a static body, you must call one of the cpSpaceReindex*() functions.
|
|
||||||
/// Chipmunk uses this information to optimize the collision detection.
|
|
||||||
/// Static bodies do not produce collision callbacks when colliding with other static bodies.
|
|
||||||
CP_BODY_TYPE_STATIC,
|
|
||||||
} cpBodyType;
|
|
||||||
|
|
||||||
/// Rigid body velocity update function type.
|
|
||||||
typedef void (*cpBodyVelocityFunc)(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
|
|
||||||
/// Rigid body position update function type.
|
|
||||||
typedef void (*cpBodyPositionFunc)(cpBody *body, cpFloat dt);
|
|
||||||
|
|
||||||
/// Allocate a cpBody.
|
|
||||||
CP_EXPORT cpBody* cpBodyAlloc(void);
|
|
||||||
/// Initialize a cpBody.
|
|
||||||
CP_EXPORT cpBody* cpBodyInit(cpBody *body, cpFloat mass, cpFloat moment);
|
|
||||||
/// Allocate and initialize a cpBody.
|
|
||||||
CP_EXPORT cpBody* cpBodyNew(cpFloat mass, cpFloat moment);
|
|
||||||
|
|
||||||
/// Allocate and initialize a cpBody, and set it as a kinematic body.
|
|
||||||
CP_EXPORT cpBody* cpBodyNewKinematic(void);
|
|
||||||
/// Allocate and initialize a cpBody, and set it as a static body.
|
|
||||||
CP_EXPORT cpBody* cpBodyNewStatic(void);
|
|
||||||
|
|
||||||
/// Destroy a cpBody.
|
|
||||||
CP_EXPORT void cpBodyDestroy(cpBody *body);
|
|
||||||
/// Destroy and free a cpBody.
|
|
||||||
CP_EXPORT void cpBodyFree(cpBody *body);
|
|
||||||
|
|
||||||
// Defined in cpSpace.c
|
|
||||||
/// Wake up a sleeping or idle body.
|
|
||||||
CP_EXPORT void cpBodyActivate(cpBody *body);
|
|
||||||
/// Wake up any sleeping or idle bodies touching a static body.
|
|
||||||
CP_EXPORT void cpBodyActivateStatic(cpBody *body, cpShape *filter);
|
|
||||||
|
|
||||||
/// Force a body to fall asleep immediately.
|
|
||||||
CP_EXPORT void cpBodySleep(cpBody *body);
|
|
||||||
/// Force a body to fall asleep immediately along with other bodies in a group.
|
|
||||||
CP_EXPORT void cpBodySleepWithGroup(cpBody *body, cpBody *group);
|
|
||||||
|
|
||||||
/// Returns true if the body is sleeping.
|
|
||||||
CP_EXPORT cpBool cpBodyIsSleeping(const cpBody *body);
|
|
||||||
|
|
||||||
/// Get the type of the body.
|
|
||||||
CP_EXPORT cpBodyType cpBodyGetType(cpBody *body);
|
|
||||||
/// Set the type of the body.
|
|
||||||
CP_EXPORT void cpBodySetType(cpBody *body, cpBodyType type);
|
|
||||||
|
|
||||||
/// Get the space this body is added to.
|
|
||||||
CP_EXPORT cpSpace* cpBodyGetSpace(const cpBody *body);
|
|
||||||
|
|
||||||
/// Get the mass of the body.
|
|
||||||
CP_EXPORT cpFloat cpBodyGetMass(const cpBody *body);
|
|
||||||
/// Set the mass of the body.
|
|
||||||
CP_EXPORT void cpBodySetMass(cpBody *body, cpFloat m);
|
|
||||||
|
|
||||||
/// Get the moment of inertia of the body.
|
|
||||||
CP_EXPORT cpFloat cpBodyGetMoment(const cpBody *body);
|
|
||||||
/// Set the moment of inertia of the body.
|
|
||||||
CP_EXPORT void cpBodySetMoment(cpBody *body, cpFloat i);
|
|
||||||
|
|
||||||
/// Set the position of a body.
|
|
||||||
CP_EXPORT cpVect cpBodyGetPosition(const cpBody *body);
|
|
||||||
/// Set the position of the body.
|
|
||||||
CP_EXPORT void cpBodySetPosition(cpBody *body, cpVect pos);
|
|
||||||
|
|
||||||
/// Get the offset of the center of gravity in body local coordinates.
|
|
||||||
CP_EXPORT cpVect cpBodyGetCenterOfGravity(const cpBody *body);
|
|
||||||
/// Set the offset of the center of gravity in body local coordinates.
|
|
||||||
CP_EXPORT void cpBodySetCenterOfGravity(cpBody *body, cpVect cog);
|
|
||||||
|
|
||||||
/// Get the velocity of the body.
|
|
||||||
CP_EXPORT cpVect cpBodyGetVelocity(const cpBody *body);
|
|
||||||
/// Set the velocity of the body.
|
|
||||||
CP_EXPORT void cpBodySetVelocity(cpBody *body, cpVect velocity);
|
|
||||||
|
|
||||||
/// Get the force applied to the body for the next time step.
|
|
||||||
CP_EXPORT cpVect cpBodyGetForce(const cpBody *body);
|
|
||||||
/// Set the force applied to the body for the next time step.
|
|
||||||
CP_EXPORT void cpBodySetForce(cpBody *body, cpVect force);
|
|
||||||
|
|
||||||
/// Get the angle of the body.
|
|
||||||
CP_EXPORT cpFloat cpBodyGetAngle(const cpBody *body);
|
|
||||||
/// Set the angle of a body.
|
|
||||||
CP_EXPORT void cpBodySetAngle(cpBody *body, cpFloat a);
|
|
||||||
|
|
||||||
/// Get the angular velocity of the body.
|
|
||||||
CP_EXPORT cpFloat cpBodyGetAngularVelocity(const cpBody *body);
|
|
||||||
/// Set the angular velocity of the body.
|
|
||||||
CP_EXPORT void cpBodySetAngularVelocity(cpBody *body, cpFloat angularVelocity);
|
|
||||||
|
|
||||||
/// Get the torque applied to the body for the next time step.
|
|
||||||
CP_EXPORT cpFloat cpBodyGetTorque(const cpBody *body);
|
|
||||||
/// Set the torque applied to the body for the next time step.
|
|
||||||
CP_EXPORT void cpBodySetTorque(cpBody *body, cpFloat torque);
|
|
||||||
|
|
||||||
/// Get the rotation vector of the body. (The x basis vector of it's transform.)
|
|
||||||
CP_EXPORT cpVect cpBodyGetRotation(const cpBody *body);
|
|
||||||
|
|
||||||
/// Get the user data pointer assigned to the body.
|
|
||||||
CP_EXPORT cpDataPointer cpBodyGetUserData(const cpBody *body);
|
|
||||||
/// Set the user data pointer assigned to the body.
|
|
||||||
CP_EXPORT void cpBodySetUserData(cpBody *body, cpDataPointer userData);
|
|
||||||
|
|
||||||
/// Set the callback used to update a body's velocity.
|
|
||||||
CP_EXPORT void cpBodySetVelocityUpdateFunc(cpBody *body, cpBodyVelocityFunc velocityFunc);
|
|
||||||
/// Set the callback used to update a body's position.
|
|
||||||
/// NOTE: It's not generally recommended to override this unless you call the default position update function.
|
|
||||||
CP_EXPORT void cpBodySetPositionUpdateFunc(cpBody *body, cpBodyPositionFunc positionFunc);
|
|
||||||
|
|
||||||
/// Default velocity integration function..
|
|
||||||
CP_EXPORT void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
|
|
||||||
/// Default position integration function.
|
|
||||||
CP_EXPORT void cpBodyUpdatePosition(cpBody *body, cpFloat dt);
|
|
||||||
|
|
||||||
/// Convert body relative/local coordinates to absolute/world coordinates.
|
|
||||||
CP_EXPORT cpVect cpBodyLocalToWorld(const cpBody *body, const cpVect point);
|
|
||||||
/// Convert body absolute/world coordinates to relative/local coordinates.
|
|
||||||
CP_EXPORT cpVect cpBodyWorldToLocal(const cpBody *body, const cpVect point);
|
|
||||||
|
|
||||||
/// Apply a force to a body. Both the force and point are expressed in world coordinates.
|
|
||||||
CP_EXPORT void cpBodyApplyForceAtWorldPoint(cpBody *body, cpVect force, cpVect point);
|
|
||||||
/// Apply a force to a body. Both the force and point are expressed in body local coordinates.
|
|
||||||
CP_EXPORT void cpBodyApplyForceAtLocalPoint(cpBody *body, cpVect force, cpVect point);
|
|
||||||
|
|
||||||
/// Apply an impulse to a body. Both the impulse and point are expressed in world coordinates.
|
|
||||||
CP_EXPORT void cpBodyApplyImpulseAtWorldPoint(cpBody *body, cpVect impulse, cpVect point);
|
|
||||||
/// Apply an impulse to a body. Both the impulse and point are expressed in body local coordinates.
|
|
||||||
CP_EXPORT void cpBodyApplyImpulseAtLocalPoint(cpBody *body, cpVect impulse, cpVect point);
|
|
||||||
|
|
||||||
/// Get the velocity on a body (in world units) at a point on the body in world coordinates.
|
|
||||||
CP_EXPORT cpVect cpBodyGetVelocityAtWorldPoint(const cpBody *body, cpVect point);
|
|
||||||
/// Get the velocity on a body (in world units) at a point on the body in local coordinates.
|
|
||||||
CP_EXPORT cpVect cpBodyGetVelocityAtLocalPoint(const cpBody *body, cpVect point);
|
|
||||||
|
|
||||||
/// Get the amount of kinetic energy contained by the body.
|
|
||||||
CP_EXPORT cpFloat cpBodyKineticEnergy(const cpBody *body);
|
|
||||||
|
|
||||||
/// Body/shape iterator callback function type.
|
|
||||||
typedef void (*cpBodyShapeIteratorFunc)(cpBody *body, cpShape *shape, void *data);
|
|
||||||
/// Call @c func once for each shape attached to @c body and added to the space.
|
|
||||||
CP_EXPORT void cpBodyEachShape(cpBody *body, cpBodyShapeIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
/// Body/constraint iterator callback function type.
|
|
||||||
typedef void (*cpBodyConstraintIteratorFunc)(cpBody *body, cpConstraint *constraint, void *data);
|
|
||||||
/// Call @c func once for each constraint attached to @c body and added to the space.
|
|
||||||
CP_EXPORT void cpBodyEachConstraint(cpBody *body, cpBodyConstraintIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
/// Body/arbiter iterator callback function type.
|
|
||||||
typedef void (*cpBodyArbiterIteratorFunc)(cpBody *body, cpArbiter *arbiter, void *data);
|
|
||||||
/// Call @c func once for each arbiter that is currently active on the body.
|
|
||||||
CP_EXPORT void cpBodyEachArbiter(cpBody *body, cpBodyArbiterIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
///@}
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpConstraint cpConstraint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Callback function type that gets called before solving a joint.
|
|
||||||
typedef void (*cpConstraintPreSolveFunc)(cpConstraint *constraint, cpSpace *space);
|
|
||||||
/// Callback function type that gets called after solving a joint.
|
|
||||||
typedef void (*cpConstraintPostSolveFunc)(cpConstraint *constraint, cpSpace *space);
|
|
||||||
|
|
||||||
/// Destroy a constraint.
|
|
||||||
CP_EXPORT void cpConstraintDestroy(cpConstraint *constraint);
|
|
||||||
/// Destroy and free a constraint.
|
|
||||||
CP_EXPORT void cpConstraintFree(cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Get the cpSpace this constraint is added to.
|
|
||||||
CP_EXPORT cpSpace* cpConstraintGetSpace(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Get the first body the constraint is attached to.
|
|
||||||
CP_EXPORT cpBody* cpConstraintGetBodyA(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Get the second body the constraint is attached to.
|
|
||||||
CP_EXPORT cpBody* cpConstraintGetBodyB(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Get the maximum force that this constraint is allowed to use.
|
|
||||||
CP_EXPORT cpFloat cpConstraintGetMaxForce(const cpConstraint *constraint);
|
|
||||||
/// Set the maximum force that this constraint is allowed to use. (defaults to INFINITY)
|
|
||||||
CP_EXPORT void cpConstraintSetMaxForce(cpConstraint *constraint, cpFloat maxForce);
|
|
||||||
|
|
||||||
/// Get rate at which joint error is corrected.
|
|
||||||
CP_EXPORT cpFloat cpConstraintGetErrorBias(const cpConstraint *constraint);
|
|
||||||
/// Set rate at which joint error is corrected.
|
|
||||||
/// Defaults to pow(1.0 - 0.1, 60.0) meaning that it will
|
|
||||||
/// correct 10% of the error every 1/60th of a second.
|
|
||||||
CP_EXPORT void cpConstraintSetErrorBias(cpConstraint *constraint, cpFloat errorBias);
|
|
||||||
|
|
||||||
/// Get the maximum rate at which joint error is corrected.
|
|
||||||
CP_EXPORT cpFloat cpConstraintGetMaxBias(const cpConstraint *constraint);
|
|
||||||
/// Set the maximum rate at which joint error is corrected. (defaults to INFINITY)
|
|
||||||
CP_EXPORT void cpConstraintSetMaxBias(cpConstraint *constraint, cpFloat maxBias);
|
|
||||||
|
|
||||||
/// Get if the two bodies connected by the constraint are allowed to collide or not.
|
|
||||||
CP_EXPORT cpBool cpConstraintGetCollideBodies(const cpConstraint *constraint);
|
|
||||||
/// Set if the two bodies connected by the constraint are allowed to collide or not. (defaults to cpFalse)
|
|
||||||
CP_EXPORT void cpConstraintSetCollideBodies(cpConstraint *constraint, cpBool collideBodies);
|
|
||||||
|
|
||||||
/// Get the pre-solve function that is called before the solver runs.
|
|
||||||
CP_EXPORT cpConstraintPreSolveFunc cpConstraintGetPreSolveFunc(const cpConstraint *constraint);
|
|
||||||
/// Set the pre-solve function that is called before the solver runs.
|
|
||||||
CP_EXPORT void cpConstraintSetPreSolveFunc(cpConstraint *constraint, cpConstraintPreSolveFunc preSolveFunc);
|
|
||||||
|
|
||||||
/// Get the post-solve function that is called before the solver runs.
|
|
||||||
CP_EXPORT cpConstraintPostSolveFunc cpConstraintGetPostSolveFunc(const cpConstraint *constraint);
|
|
||||||
/// Set the post-solve function that is called before the solver runs.
|
|
||||||
CP_EXPORT void cpConstraintSetPostSolveFunc(cpConstraint *constraint, cpConstraintPostSolveFunc postSolveFunc);
|
|
||||||
|
|
||||||
/// Get the user definable data pointer for this constraint
|
|
||||||
CP_EXPORT cpDataPointer cpConstraintGetUserData(const cpConstraint *constraint);
|
|
||||||
/// Set the user definable data pointer for this constraint
|
|
||||||
CP_EXPORT void cpConstraintSetUserData(cpConstraint *constraint, cpDataPointer userData);
|
|
||||||
|
|
||||||
/// Get the last impulse applied by this constraint.
|
|
||||||
CP_EXPORT cpFloat cpConstraintGetImpulse(cpConstraint *constraint);
|
|
||||||
|
|
||||||
#include "cpPinJoint.h"
|
|
||||||
#include "cpSlideJoint.h"
|
|
||||||
#include "cpPivotJoint.h"
|
|
||||||
#include "cpGrooveJoint.h"
|
|
||||||
#include "cpDampedSpring.h"
|
|
||||||
#include "cpDampedRotarySpring.h"
|
|
||||||
#include "cpRotaryLimitJoint.h"
|
|
||||||
#include "cpRatchetJoint.h"
|
|
||||||
#include "cpGearJoint.h"
|
|
||||||
#include "cpSimpleMotor.h"
|
|
||||||
|
|
||||||
///@}
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpDampedRotarySpring cpDampedRotarySpring
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a damped rotary springs.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsDampedRotarySpring(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Function type used for damped rotary spring force callbacks.
|
|
||||||
typedef cpFloat (*cpDampedRotarySpringTorqueFunc)(struct cpConstraint *spring, cpFloat relativeAngle);
|
|
||||||
|
|
||||||
/// Allocate a damped rotary spring.
|
|
||||||
CP_EXPORT cpDampedRotarySpring* cpDampedRotarySpringAlloc(void);
|
|
||||||
/// Initialize a damped rotary spring.
|
|
||||||
CP_EXPORT cpDampedRotarySpring* cpDampedRotarySpringInit(cpDampedRotarySpring *joint, cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping);
|
|
||||||
/// Allocate and initialize a damped rotary spring.
|
|
||||||
CP_EXPORT cpConstraint* cpDampedRotarySpringNew(cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping);
|
|
||||||
|
|
||||||
/// Get the rest length of the spring.
|
|
||||||
CP_EXPORT cpFloat cpDampedRotarySpringGetRestAngle(const cpConstraint *constraint);
|
|
||||||
/// Set the rest length of the spring.
|
|
||||||
CP_EXPORT void cpDampedRotarySpringSetRestAngle(cpConstraint *constraint, cpFloat restAngle);
|
|
||||||
|
|
||||||
/// Get the stiffness of the spring in force/distance.
|
|
||||||
CP_EXPORT cpFloat cpDampedRotarySpringGetStiffness(const cpConstraint *constraint);
|
|
||||||
/// Set the stiffness of the spring in force/distance.
|
|
||||||
CP_EXPORT void cpDampedRotarySpringSetStiffness(cpConstraint *constraint, cpFloat stiffness);
|
|
||||||
|
|
||||||
/// Get the damping of the spring.
|
|
||||||
CP_EXPORT cpFloat cpDampedRotarySpringGetDamping(const cpConstraint *constraint);
|
|
||||||
/// Set the damping of the spring.
|
|
||||||
CP_EXPORT void cpDampedRotarySpringSetDamping(cpConstraint *constraint, cpFloat damping);
|
|
||||||
|
|
||||||
/// Get the damping of the spring.
|
|
||||||
CP_EXPORT cpDampedRotarySpringTorqueFunc cpDampedRotarySpringGetSpringTorqueFunc(const cpConstraint *constraint);
|
|
||||||
/// Set the damping of the spring.
|
|
||||||
CP_EXPORT void cpDampedRotarySpringSetSpringTorqueFunc(cpConstraint *constraint, cpDampedRotarySpringTorqueFunc springTorqueFunc);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpDampedSpring cpDampedSpring
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a slide joint.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsDampedSpring(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Function type used for damped spring force callbacks.
|
|
||||||
typedef cpFloat (*cpDampedSpringForceFunc)(cpConstraint *spring, cpFloat dist);
|
|
||||||
|
|
||||||
/// Allocate a damped spring.
|
|
||||||
CP_EXPORT cpDampedSpring* cpDampedSpringAlloc(void);
|
|
||||||
/// Initialize a damped spring.
|
|
||||||
CP_EXPORT cpDampedSpring* cpDampedSpringInit(cpDampedSpring *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB, cpFloat restLength, cpFloat stiffness, cpFloat damping);
|
|
||||||
/// Allocate and initialize a damped spring.
|
|
||||||
CP_EXPORT cpConstraint* cpDampedSpringNew(cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB, cpFloat restLength, cpFloat stiffness, cpFloat damping);
|
|
||||||
|
|
||||||
/// Get the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT cpVect cpDampedSpringGetAnchorA(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT void cpDampedSpringSetAnchorA(cpConstraint *constraint, cpVect anchorA);
|
|
||||||
|
|
||||||
/// Get the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT cpVect cpDampedSpringGetAnchorB(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT void cpDampedSpringSetAnchorB(cpConstraint *constraint, cpVect anchorB);
|
|
||||||
|
|
||||||
/// Get the rest length of the spring.
|
|
||||||
CP_EXPORT cpFloat cpDampedSpringGetRestLength(const cpConstraint *constraint);
|
|
||||||
/// Set the rest length of the spring.
|
|
||||||
CP_EXPORT void cpDampedSpringSetRestLength(cpConstraint *constraint, cpFloat restLength);
|
|
||||||
|
|
||||||
/// Get the stiffness of the spring in force/distance.
|
|
||||||
CP_EXPORT cpFloat cpDampedSpringGetStiffness(const cpConstraint *constraint);
|
|
||||||
/// Set the stiffness of the spring in force/distance.
|
|
||||||
CP_EXPORT void cpDampedSpringSetStiffness(cpConstraint *constraint, cpFloat stiffness);
|
|
||||||
|
|
||||||
/// Get the damping of the spring.
|
|
||||||
CP_EXPORT cpFloat cpDampedSpringGetDamping(const cpConstraint *constraint);
|
|
||||||
/// Set the damping of the spring.
|
|
||||||
CP_EXPORT void cpDampedSpringSetDamping(cpConstraint *constraint, cpFloat damping);
|
|
||||||
|
|
||||||
/// Get the damping of the spring.
|
|
||||||
CP_EXPORT cpDampedSpringForceFunc cpDampedSpringGetSpringForceFunc(const cpConstraint *constraint);
|
|
||||||
/// Set the damping of the spring.
|
|
||||||
CP_EXPORT void cpDampedSpringSetSpringForceFunc(cpConstraint *constraint, cpDampedSpringForceFunc springForceFunc);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpGearJoint cpGearJoint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a damped rotary springs.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsGearJoint(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a gear joint.
|
|
||||||
CP_EXPORT cpGearJoint* cpGearJointAlloc(void);
|
|
||||||
/// Initialize a gear joint.
|
|
||||||
CP_EXPORT cpGearJoint* cpGearJointInit(cpGearJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio);
|
|
||||||
/// Allocate and initialize a gear joint.
|
|
||||||
CP_EXPORT cpConstraint* cpGearJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio);
|
|
||||||
|
|
||||||
/// Get the phase offset of the gears.
|
|
||||||
CP_EXPORT cpFloat cpGearJointGetPhase(const cpConstraint *constraint);
|
|
||||||
/// Set the phase offset of the gears.
|
|
||||||
CP_EXPORT void cpGearJointSetPhase(cpConstraint *constraint, cpFloat phase);
|
|
||||||
|
|
||||||
/// Get the angular distance of each ratchet.
|
|
||||||
CP_EXPORT cpFloat cpGearJointGetRatio(const cpConstraint *constraint);
|
|
||||||
/// Set the ratio of a gear joint.
|
|
||||||
CP_EXPORT void cpGearJointSetRatio(cpConstraint *constraint, cpFloat ratio);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpGrooveJoint cpGrooveJoint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a slide joint.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsGrooveJoint(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a groove joint.
|
|
||||||
CP_EXPORT cpGrooveJoint* cpGrooveJointAlloc(void);
|
|
||||||
/// Initialize a groove joint.
|
|
||||||
CP_EXPORT cpGrooveJoint* cpGrooveJointInit(cpGrooveJoint *joint, cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchorB);
|
|
||||||
/// Allocate and initialize a groove joint.
|
|
||||||
CP_EXPORT cpConstraint* cpGrooveJointNew(cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchorB);
|
|
||||||
|
|
||||||
/// Get the first endpoint of the groove relative to the first body.
|
|
||||||
CP_EXPORT cpVect cpGrooveJointGetGrooveA(const cpConstraint *constraint);
|
|
||||||
/// Set the first endpoint of the groove relative to the first body.
|
|
||||||
CP_EXPORT void cpGrooveJointSetGrooveA(cpConstraint *constraint, cpVect grooveA);
|
|
||||||
|
|
||||||
/// Get the first endpoint of the groove relative to the first body.
|
|
||||||
CP_EXPORT cpVect cpGrooveJointGetGrooveB(const cpConstraint *constraint);
|
|
||||||
/// Set the first endpoint of the groove relative to the first body.
|
|
||||||
CP_EXPORT void cpGrooveJointSetGrooveB(cpConstraint *constraint, cpVect grooveB);
|
|
||||||
|
|
||||||
/// Get the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT cpVect cpGrooveJointGetAnchorB(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT void cpGrooveJointSetAnchorB(cpConstraint *constraint, cpVect anchorB);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
// Copyright 2013 Howling Moon Software. All rights reserved.
|
|
||||||
// See http://chipmunk2d.net/legal.php for more information.
|
|
||||||
|
|
||||||
/// cpHastySpace is exclusive to Chipmunk Pro
|
|
||||||
/// Currently it enables ARM NEON optimizations in the solver, but in the future will include other optimizations such as
|
|
||||||
/// a multi-threaded solver and multi-threaded collision broadphases.
|
|
||||||
|
|
||||||
struct cpHastySpace;
|
|
||||||
typedef struct cpHastySpace cpHastySpace;
|
|
||||||
|
|
||||||
/// Create a new hasty space.
|
|
||||||
/// On ARM platforms that support NEON, this will enable the vectorized solver.
|
|
||||||
/// cpHastySpace also supports multiple threads, but runs single threaded by default for determinism.
|
|
||||||
CP_EXPORT cpSpace *cpHastySpaceNew(void);
|
|
||||||
CP_EXPORT void cpHastySpaceFree(cpSpace *space);
|
|
||||||
|
|
||||||
/// Set the number of threads to use for the solver.
|
|
||||||
/// Currently Chipmunk is limited to 2 threads as using more generally provides very minimal performance gains.
|
|
||||||
/// Passing 0 as the thread count on iOS or OS X will cause Chipmunk to automatically detect the number of threads it should use.
|
|
||||||
/// On other platforms passing 0 for the thread count will set 1 thread.
|
|
||||||
CP_EXPORT void cpHastySpaceSetThreads(cpSpace *space, unsigned long threads);
|
|
||||||
|
|
||||||
/// Returns the number of threads the solver is using to run.
|
|
||||||
CP_EXPORT unsigned long cpHastySpaceGetThreads(cpSpace *space);
|
|
||||||
|
|
||||||
/// When stepping a hasty space, you must use this function.
|
|
||||||
CP_EXPORT void cpHastySpaceStep(cpSpace *space, cpFloat dt);
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
// Copyright 2013 Howling Moon Software. All rights reserved.
|
|
||||||
// See http://chipmunk2d.net/legal.php for more information.
|
|
||||||
|
|
||||||
/// Function type used as a callback from the marching squares algorithm to sample an image function.
|
|
||||||
/// It passes you the point to sample and your context pointer, and you return the density.
|
|
||||||
typedef cpFloat (*cpMarchSampleFunc)(cpVect point, void *data);
|
|
||||||
|
|
||||||
/// Function type used as a callback from the marching squares algorithm to output a line segment.
|
|
||||||
/// It passes you the two endpoints and your context pointer.
|
|
||||||
typedef void (*cpMarchSegmentFunc)(cpVect v0, cpVect v1, void *data);
|
|
||||||
|
|
||||||
/// Trace an anti-aliased contour of an image along a particular threshold.
|
|
||||||
/// The given number of samples will be taken and spread across the bounding box area using the sampling function and context.
|
|
||||||
/// The segment function will be called for each segment detected that lies along the density contour for @c threshold.
|
|
||||||
CP_EXPORT void cpMarchSoft(
|
|
||||||
cpBB bb, unsigned long x_samples, unsigned long y_samples, cpFloat threshold,
|
|
||||||
cpMarchSegmentFunc segment, void *segment_data,
|
|
||||||
cpMarchSampleFunc sample, void *sample_data
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Trace an aliased curve of an image along a particular threshold.
|
|
||||||
/// The given number of samples will be taken and spread across the bounding box area using the sampling function and context.
|
|
||||||
/// The segment function will be called for each segment detected that lies along the density contour for @c threshold.
|
|
||||||
CP_EXPORT void cpMarchHard(
|
|
||||||
cpBB bb, unsigned long x_samples, unsigned long y_samples, cpFloat threshold,
|
|
||||||
cpMarchSegmentFunc segment, void *segment_data,
|
|
||||||
cpMarchSampleFunc sample, void *sample_data
|
|
||||||
);
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpPinJoint cpPinJoint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a pin joint.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsPinJoint(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a pin joint.
|
|
||||||
CP_EXPORT cpPinJoint* cpPinJointAlloc(void);
|
|
||||||
/// Initialize a pin joint.
|
|
||||||
CP_EXPORT cpPinJoint* cpPinJointInit(cpPinJoint *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB);
|
|
||||||
/// Allocate and initialize a pin joint.
|
|
||||||
CP_EXPORT cpConstraint* cpPinJointNew(cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB);
|
|
||||||
|
|
||||||
/// Get the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT cpVect cpPinJointGetAnchorA(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT void cpPinJointSetAnchorA(cpConstraint *constraint, cpVect anchorA);
|
|
||||||
|
|
||||||
/// Get the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT cpVect cpPinJointGetAnchorB(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT void cpPinJointSetAnchorB(cpConstraint *constraint, cpVect anchorB);
|
|
||||||
|
|
||||||
/// Get the distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT cpFloat cpPinJointGetDist(const cpConstraint *constraint);
|
|
||||||
/// Set the distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT void cpPinJointSetDist(cpConstraint *constraint, cpFloat dist);
|
|
||||||
|
|
||||||
///@}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpPivotJoint cpPivotJoint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a slide joint.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsPivotJoint(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a pivot joint
|
|
||||||
CP_EXPORT cpPivotJoint* cpPivotJointAlloc(void);
|
|
||||||
/// Initialize a pivot joint.
|
|
||||||
CP_EXPORT cpPivotJoint* cpPivotJointInit(cpPivotJoint *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB);
|
|
||||||
/// Allocate and initialize a pivot joint.
|
|
||||||
CP_EXPORT cpConstraint* cpPivotJointNew(cpBody *a, cpBody *b, cpVect pivot);
|
|
||||||
/// Allocate and initialize a pivot joint with specific anchors.
|
|
||||||
CP_EXPORT cpConstraint* cpPivotJointNew2(cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB);
|
|
||||||
|
|
||||||
/// Get the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT cpVect cpPivotJointGetAnchorA(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT void cpPivotJointSetAnchorA(cpConstraint *constraint, cpVect anchorA);
|
|
||||||
|
|
||||||
/// Get the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT cpVect cpPivotJointGetAnchorB(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT void cpPivotJointSetAnchorB(cpConstraint *constraint, cpVect anchorB);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpPolyShape cpPolyShape
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Allocate a polygon shape.
|
|
||||||
CP_EXPORT cpPolyShape* cpPolyShapeAlloc(void);
|
|
||||||
/// Initialize a polygon shape with rounded corners.
|
|
||||||
/// A convex hull will be created from the vertexes.
|
|
||||||
CP_EXPORT cpPolyShape* cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int count, const cpVect *verts, cpTransform transform, cpFloat radius);
|
|
||||||
/// Initialize a polygon shape with rounded corners.
|
|
||||||
/// The vertexes must be convex with a counter-clockwise winding.
|
|
||||||
CP_EXPORT cpPolyShape* cpPolyShapeInitRaw(cpPolyShape *poly, cpBody *body, int count, const cpVect *verts, cpFloat radius);
|
|
||||||
/// Allocate and initialize a polygon shape with rounded corners.
|
|
||||||
/// A convex hull will be created from the vertexes.
|
|
||||||
CP_EXPORT cpShape* cpPolyShapeNew(cpBody *body, int count, const cpVect *verts, cpTransform transform, cpFloat radius);
|
|
||||||
/// Allocate and initialize a polygon shape with rounded corners.
|
|
||||||
/// The vertexes must be convex with a counter-clockwise winding.
|
|
||||||
CP_EXPORT cpShape* cpPolyShapeNewRaw(cpBody *body, int count, const cpVect *verts, cpFloat radius);
|
|
||||||
|
|
||||||
/// Initialize a box shaped polygon shape with rounded corners.
|
|
||||||
CP_EXPORT cpPolyShape* cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height, cpFloat radius);
|
|
||||||
/// Initialize an offset box shaped polygon shape with rounded corners.
|
|
||||||
CP_EXPORT cpPolyShape* cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box, cpFloat radius);
|
|
||||||
/// Allocate and initialize a box shaped polygon shape.
|
|
||||||
CP_EXPORT cpShape* cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height, cpFloat radius);
|
|
||||||
/// Allocate and initialize an offset box shaped polygon shape.
|
|
||||||
CP_EXPORT cpShape* cpBoxShapeNew2(cpBody *body, cpBB box, cpFloat radius);
|
|
||||||
|
|
||||||
/// Get the number of verts in a polygon shape.
|
|
||||||
CP_EXPORT int cpPolyShapeGetCount(const cpShape *shape);
|
|
||||||
/// Get the @c ith vertex of a polygon shape.
|
|
||||||
CP_EXPORT cpVect cpPolyShapeGetVert(const cpShape *shape, int index);
|
|
||||||
/// Get the radius of a polygon shape.
|
|
||||||
CP_EXPORT cpFloat cpPolyShapeGetRadius(const cpShape *shape);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
// Copyright 2013 Howling Moon Software. All rights reserved.
|
|
||||||
// See http://chipmunk2d.net/legal.php for more information.
|
|
||||||
|
|
||||||
// Polylines are just arrays of vertexes.
|
|
||||||
// They are looped if the first vertex is equal to the last.
|
|
||||||
// cpPolyline structs are intended to be passed by value and destroyed when you are done with them.
|
|
||||||
typedef struct cpPolyline {
|
|
||||||
int count, capacity;
|
|
||||||
cpVect verts[];
|
|
||||||
} cpPolyline;
|
|
||||||
|
|
||||||
/// Destroy and free a polyline instance.
|
|
||||||
CP_EXPORT void cpPolylineFree(cpPolyline *line);
|
|
||||||
|
|
||||||
/// Returns true if the first vertex is equal to the last.
|
|
||||||
CP_EXPORT cpBool cpPolylineIsClosed(cpPolyline *line);
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns a copy of a polyline simplified by using the Douglas-Peucker algorithm.
|
|
||||||
This works very well on smooth or gently curved shapes, but not well on straight edged or angular shapes.
|
|
||||||
*/
|
|
||||||
CP_EXPORT cpPolyline *cpPolylineSimplifyCurves(cpPolyline *line, cpFloat tol);
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns a copy of a polyline simplified by discarding "flat" vertexes.
|
|
||||||
This works well on straigt edged or angular shapes, not as well on smooth shapes.
|
|
||||||
*/
|
|
||||||
CP_EXPORT cpPolyline *cpPolylineSimplifyVertexes(cpPolyline *line, cpFloat tol);
|
|
||||||
|
|
||||||
/// Get the convex hull of a polyline as a looped polyline.
|
|
||||||
CP_EXPORT cpPolyline *cpPolylineToConvexHull(cpPolyline *line, cpFloat tol);
|
|
||||||
|
|
||||||
|
|
||||||
/// Polyline sets are collections of polylines, generally built by cpMarchSoft() or cpMarchHard().
|
|
||||||
typedef struct cpPolylineSet {
|
|
||||||
int count, capacity;
|
|
||||||
cpPolyline **lines;
|
|
||||||
} cpPolylineSet;
|
|
||||||
|
|
||||||
/// Allocate a new polyline set.
|
|
||||||
CP_EXPORT cpPolylineSet *cpPolylineSetAlloc(void);
|
|
||||||
|
|
||||||
/// Initialize a new polyline set.
|
|
||||||
CP_EXPORT cpPolylineSet *cpPolylineSetInit(cpPolylineSet *set);
|
|
||||||
|
|
||||||
/// Allocate and initialize a polyline set.
|
|
||||||
CP_EXPORT cpPolylineSet *cpPolylineSetNew(void);
|
|
||||||
|
|
||||||
/// Destroy a polyline set.
|
|
||||||
CP_EXPORT void cpPolylineSetDestroy(cpPolylineSet *set, cpBool freePolylines);
|
|
||||||
|
|
||||||
CP_EXPORT /// Destroy and free a polyline set.
|
|
||||||
void cpPolylineSetFree(cpPolylineSet *set, cpBool freePolylines);
|
|
||||||
|
|
||||||
/**
|
|
||||||
Add a line segment to a polyline set.
|
|
||||||
A segment will either start a new polyline, join two others, or add to or loop an existing polyline.
|
|
||||||
This is mostly intended to be used as a callback directly from cpMarchSoft() or cpMarchHard().
|
|
||||||
*/
|
|
||||||
CP_EXPORT void cpPolylineSetCollectSegment(cpVect v0, cpVect v1, cpPolylineSet *lines);
|
|
||||||
|
|
||||||
/**
|
|
||||||
Get an approximate convex decomposition from a polyline.
|
|
||||||
Returns a cpPolylineSet of convex hulls that match the original shape to within 'tol'.
|
|
||||||
NOTE: If the input is a self intersecting polygon, the output might end up overly simplified.
|
|
||||||
*/
|
|
||||||
|
|
||||||
CP_EXPORT cpPolylineSet *cpPolylineConvexDecomposition(cpPolyline *line, cpFloat tol);
|
|
||||||
|
|
||||||
#define cpPolylineConvexDecomposition_BETA cpPolylineConvexDecomposition
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpRatchetJoint cpRatchetJoint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a damped rotary springs.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsRatchetJoint(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a ratchet joint.
|
|
||||||
CP_EXPORT cpRatchetJoint* cpRatchetJointAlloc(void);
|
|
||||||
/// Initialize a ratched joint.
|
|
||||||
CP_EXPORT cpRatchetJoint* cpRatchetJointInit(cpRatchetJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet);
|
|
||||||
/// Allocate and initialize a ratchet joint.
|
|
||||||
CP_EXPORT cpConstraint* cpRatchetJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet);
|
|
||||||
|
|
||||||
/// Get the angle of the current ratchet tooth.
|
|
||||||
CP_EXPORT cpFloat cpRatchetJointGetAngle(const cpConstraint *constraint);
|
|
||||||
/// Set the angle of the current ratchet tooth.
|
|
||||||
CP_EXPORT void cpRatchetJointSetAngle(cpConstraint *constraint, cpFloat angle);
|
|
||||||
|
|
||||||
/// Get the phase offset of the ratchet.
|
|
||||||
CP_EXPORT cpFloat cpRatchetJointGetPhase(const cpConstraint *constraint);
|
|
||||||
/// Get the phase offset of the ratchet.
|
|
||||||
CP_EXPORT void cpRatchetJointSetPhase(cpConstraint *constraint, cpFloat phase);
|
|
||||||
|
|
||||||
/// Get the angular distance of each ratchet.
|
|
||||||
CP_EXPORT cpFloat cpRatchetJointGetRatchet(const cpConstraint *constraint);
|
|
||||||
/// Set the angular distance of each ratchet.
|
|
||||||
CP_EXPORT void cpRatchetJointSetRatchet(cpConstraint *constraint, cpFloat ratchet);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
#include "chipmunk/cpVect.h"
|
|
||||||
|
|
||||||
// This is a private header for functions (currently just one) that need strict floating point results.
|
|
||||||
// It was easier to put this in it's own file than to fiddle with 4 different compiler specific pragmas or attributes.
|
|
||||||
// "Fast math" should be disabled here.
|
|
||||||
|
|
||||||
// Check that the signed area of the triangle a, b, c is positive.
|
|
||||||
// Compiler optimizations for associativity break certain edge cases (ex: when a or b equals c) that lead to excessive EPA iteration.
|
|
||||||
cpBool cpCheckSignedArea(const cpVect a, const cpVect b, const cpVect c);
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpRotaryLimitJoint cpRotaryLimitJoint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a damped rotary springs.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsRotaryLimitJoint(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a damped rotary limit joint.
|
|
||||||
CP_EXPORT cpRotaryLimitJoint* cpRotaryLimitJointAlloc(void);
|
|
||||||
/// Initialize a damped rotary limit joint.
|
|
||||||
CP_EXPORT cpRotaryLimitJoint* cpRotaryLimitJointInit(cpRotaryLimitJoint *joint, cpBody *a, cpBody *b, cpFloat min, cpFloat max);
|
|
||||||
/// Allocate and initialize a damped rotary limit joint.
|
|
||||||
CP_EXPORT cpConstraint* cpRotaryLimitJointNew(cpBody *a, cpBody *b, cpFloat min, cpFloat max);
|
|
||||||
|
|
||||||
/// Get the minimum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT cpFloat cpRotaryLimitJointGetMin(const cpConstraint *constraint);
|
|
||||||
/// Set the minimum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT void cpRotaryLimitJointSetMin(cpConstraint *constraint, cpFloat min);
|
|
||||||
|
|
||||||
/// Get the maximum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT cpFloat cpRotaryLimitJointGetMax(const cpConstraint *constraint);
|
|
||||||
/// Set the maximum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT void cpRotaryLimitJointSetMax(cpConstraint *constraint, cpFloat max);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,199 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpShape cpShape
|
|
||||||
/// The cpShape struct defines the shape of a rigid body.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Point query info struct.
|
|
||||||
typedef struct cpPointQueryInfo {
|
|
||||||
/// The nearest shape, NULL if no shape was within range.
|
|
||||||
const cpShape *shape;
|
|
||||||
/// The closest point on the shape's surface. (in world space coordinates)
|
|
||||||
cpVect point;
|
|
||||||
/// The distance to the point. The distance is negative if the point is inside the shape.
|
|
||||||
cpFloat distance;
|
|
||||||
/// The gradient of the signed distance function.
|
|
||||||
/// The value should be similar to info.p/info.d, but accurate even for very small values of info.d.
|
|
||||||
cpVect gradient;
|
|
||||||
} cpPointQueryInfo;
|
|
||||||
|
|
||||||
/// Segment query info struct.
|
|
||||||
typedef struct cpSegmentQueryInfo {
|
|
||||||
/// The shape that was hit, or NULL if no collision occured.
|
|
||||||
const cpShape *shape;
|
|
||||||
/// The point of impact.
|
|
||||||
cpVect point;
|
|
||||||
/// The normal of the surface hit.
|
|
||||||
cpVect normal;
|
|
||||||
/// The normalized distance along the query segment in the range [0, 1].
|
|
||||||
cpFloat alpha;
|
|
||||||
} cpSegmentQueryInfo;
|
|
||||||
|
|
||||||
/// Fast collision filtering type that is used to determine if two objects collide before calling collision or query callbacks.
|
|
||||||
typedef struct cpShapeFilter {
|
|
||||||
/// Two objects with the same non-zero group value do not collide.
|
|
||||||
/// This is generally used to group objects in a composite object together to disable self collisions.
|
|
||||||
cpGroup group;
|
|
||||||
/// A bitmask of user definable categories that this object belongs to.
|
|
||||||
/// The category/mask combinations of both objects in a collision must agree for a collision to occur.
|
|
||||||
cpBitmask categories;
|
|
||||||
/// A bitmask of user definable category types that this object object collides with.
|
|
||||||
/// The category/mask combinations of both objects in a collision must agree for a collision to occur.
|
|
||||||
cpBitmask mask;
|
|
||||||
} cpShapeFilter;
|
|
||||||
|
|
||||||
/// Collision filter value for a shape that will collide with anything except CP_SHAPE_FILTER_NONE.
|
|
||||||
static const cpShapeFilter CP_SHAPE_FILTER_ALL = {CP_NO_GROUP, CP_ALL_CATEGORIES, CP_ALL_CATEGORIES};
|
|
||||||
/// Collision filter value for a shape that does not collide with anything.
|
|
||||||
static const cpShapeFilter CP_SHAPE_FILTER_NONE = {CP_NO_GROUP, ~CP_ALL_CATEGORIES, ~CP_ALL_CATEGORIES};
|
|
||||||
|
|
||||||
/// Create a new collision filter.
|
|
||||||
static inline cpShapeFilter
|
|
||||||
cpShapeFilterNew(cpGroup group, cpBitmask categories, cpBitmask mask)
|
|
||||||
{
|
|
||||||
cpShapeFilter filter = {group, categories, mask};
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destroy a shape.
|
|
||||||
CP_EXPORT void cpShapeDestroy(cpShape *shape);
|
|
||||||
/// Destroy and Free a shape.
|
|
||||||
CP_EXPORT void cpShapeFree(cpShape *shape);
|
|
||||||
|
|
||||||
/// Update, cache and return the bounding box of a shape based on the body it's attached to.
|
|
||||||
CP_EXPORT cpBB cpShapeCacheBB(cpShape *shape);
|
|
||||||
/// Update, cache and return the bounding box of a shape with an explicit transformation.
|
|
||||||
CP_EXPORT cpBB cpShapeUpdate(cpShape *shape, cpTransform transform);
|
|
||||||
|
|
||||||
/// Perform a nearest point query. It finds the closest point on the surface of shape to a specific point.
|
|
||||||
/// The value returned is the distance between the points. A negative distance means the point is inside the shape.
|
|
||||||
CP_EXPORT cpFloat cpShapePointQuery(const cpShape *shape, cpVect p, cpPointQueryInfo *out);
|
|
||||||
|
|
||||||
/// Perform a segment query against a shape. @c info must be a pointer to a valid cpSegmentQueryInfo structure.
|
|
||||||
CP_EXPORT cpBool cpShapeSegmentQuery(const cpShape *shape, cpVect a, cpVect b, cpFloat radius, cpSegmentQueryInfo *info);
|
|
||||||
|
|
||||||
/// Return contact information about two shapes.
|
|
||||||
CP_EXPORT cpContactPointSet cpShapesCollide(const cpShape *a, const cpShape *b);
|
|
||||||
|
|
||||||
/// The cpSpace this body is added to.
|
|
||||||
CP_EXPORT cpSpace* cpShapeGetSpace(const cpShape *shape);
|
|
||||||
|
|
||||||
/// The cpBody this shape is connected to.
|
|
||||||
CP_EXPORT cpBody* cpShapeGetBody(const cpShape *shape);
|
|
||||||
/// Set the cpBody this shape is connected to.
|
|
||||||
/// Can only be used if the shape is not currently added to a space.
|
|
||||||
CP_EXPORT void cpShapeSetBody(cpShape *shape, cpBody *body);
|
|
||||||
|
|
||||||
/// Get the mass of the shape if you are having Chipmunk calculate mass properties for you.
|
|
||||||
cpFloat cpShapeGetMass(cpShape *shape);
|
|
||||||
/// Set the mass of this shape to have Chipmunk calculate mass properties for you.
|
|
||||||
CP_EXPORT void cpShapeSetMass(cpShape *shape, cpFloat mass);
|
|
||||||
|
|
||||||
/// Get the density of the shape if you are having Chipmunk calculate mass properties for you.
|
|
||||||
CP_EXPORT cpFloat cpShapeGetDensity(cpShape *shape);
|
|
||||||
/// Set the density of this shape to have Chipmunk calculate mass properties for you.
|
|
||||||
CP_EXPORT void cpShapeSetDensity(cpShape *shape, cpFloat density);
|
|
||||||
|
|
||||||
/// Get the calculated moment of inertia for this shape.
|
|
||||||
CP_EXPORT cpFloat cpShapeGetMoment(cpShape *shape);
|
|
||||||
/// Get the calculated area of this shape.
|
|
||||||
CP_EXPORT cpFloat cpShapeGetArea(cpShape *shape);
|
|
||||||
/// Get the centroid of this shape.
|
|
||||||
CP_EXPORT cpVect cpShapeGetCenterOfGravity(cpShape *shape);
|
|
||||||
|
|
||||||
/// Get the bounding box that contains the shape given it's current position and angle.
|
|
||||||
CP_EXPORT cpBB cpShapeGetBB(const cpShape *shape);
|
|
||||||
|
|
||||||
/// Get if the shape is set to be a sensor or not.
|
|
||||||
CP_EXPORT cpBool cpShapeGetSensor(const cpShape *shape);
|
|
||||||
/// Set if the shape is a sensor or not.
|
|
||||||
CP_EXPORT void cpShapeSetSensor(cpShape *shape, cpBool sensor);
|
|
||||||
|
|
||||||
/// Get the elasticity of this shape.
|
|
||||||
CP_EXPORT cpFloat cpShapeGetElasticity(const cpShape *shape);
|
|
||||||
/// Set the elasticity of this shape.
|
|
||||||
CP_EXPORT void cpShapeSetElasticity(cpShape *shape, cpFloat elasticity);
|
|
||||||
|
|
||||||
/// Get the friction of this shape.
|
|
||||||
CP_EXPORT cpFloat cpShapeGetFriction(const cpShape *shape);
|
|
||||||
/// Set the friction of this shape.
|
|
||||||
CP_EXPORT void cpShapeSetFriction(cpShape *shape, cpFloat friction);
|
|
||||||
|
|
||||||
/// Get the surface velocity of this shape.
|
|
||||||
CP_EXPORT cpVect cpShapeGetSurfaceVelocity(const cpShape *shape);
|
|
||||||
/// Set the surface velocity of this shape.
|
|
||||||
CP_EXPORT void cpShapeSetSurfaceVelocity(cpShape *shape, cpVect surfaceVelocity);
|
|
||||||
|
|
||||||
/// Get the user definable data pointer of this shape.
|
|
||||||
CP_EXPORT cpDataPointer cpShapeGetUserData(const cpShape *shape);
|
|
||||||
/// Set the user definable data pointer of this shape.
|
|
||||||
CP_EXPORT void cpShapeSetUserData(cpShape *shape, cpDataPointer userData);
|
|
||||||
|
|
||||||
/// Set the collision type of this shape.
|
|
||||||
CP_EXPORT cpCollisionType cpShapeGetCollisionType(const cpShape *shape);
|
|
||||||
/// Get the collision type of this shape.
|
|
||||||
CP_EXPORT void cpShapeSetCollisionType(cpShape *shape, cpCollisionType collisionType);
|
|
||||||
|
|
||||||
/// Get the collision filtering parameters of this shape.
|
|
||||||
CP_EXPORT cpShapeFilter cpShapeGetFilter(const cpShape *shape);
|
|
||||||
/// Set the collision filtering parameters of this shape.
|
|
||||||
CP_EXPORT void cpShapeSetFilter(cpShape *shape, cpShapeFilter filter);
|
|
||||||
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @defgroup cpCircleShape cpCircleShape
|
|
||||||
|
|
||||||
/// Allocate a circle shape.
|
|
||||||
CP_EXPORT cpCircleShape* cpCircleShapeAlloc(void);
|
|
||||||
/// Initialize a circle shape.
|
|
||||||
CP_EXPORT cpCircleShape* cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
|
|
||||||
/// Allocate and initialize a circle shape.
|
|
||||||
CP_EXPORT cpShape* cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
|
|
||||||
|
|
||||||
/// Get the offset of a circle shape.
|
|
||||||
CP_EXPORT cpVect cpCircleShapeGetOffset(const cpShape *shape);
|
|
||||||
/// Get the radius of a circle shape.
|
|
||||||
CP_EXPORT cpFloat cpCircleShapeGetRadius(const cpShape *shape);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @defgroup cpSegmentShape cpSegmentShape
|
|
||||||
|
|
||||||
/// Allocate a segment shape.
|
|
||||||
CP_EXPORT cpSegmentShape* cpSegmentShapeAlloc(void);
|
|
||||||
/// Initialize a segment shape.
|
|
||||||
CP_EXPORT cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius);
|
|
||||||
/// Allocate and initialize a segment shape.
|
|
||||||
CP_EXPORT cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
|
|
||||||
|
|
||||||
/// Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.
|
|
||||||
CP_EXPORT void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next);
|
|
||||||
|
|
||||||
/// Get the first endpoint of a segment shape.
|
|
||||||
CP_EXPORT cpVect cpSegmentShapeGetA(const cpShape *shape);
|
|
||||||
/// Get the second endpoint of a segment shape.
|
|
||||||
CP_EXPORT cpVect cpSegmentShapeGetB(const cpShape *shape);
|
|
||||||
/// Get the normal of a segment shape.
|
|
||||||
CP_EXPORT cpVect cpSegmentShapeGetNormal(const cpShape *shape);
|
|
||||||
/// Get the first endpoint of a segment shape.
|
|
||||||
CP_EXPORT cpFloat cpSegmentShapeGetRadius(const cpShape *shape);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpSimpleMotor cpSimpleMotor
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Opaque struct type for damped rotary springs.
|
|
||||||
typedef struct cpSimpleMotor cpSimpleMotor;
|
|
||||||
|
|
||||||
/// Check if a constraint is a damped rotary springs.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsSimpleMotor(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a simple motor.
|
|
||||||
CP_EXPORT cpSimpleMotor* cpSimpleMotorAlloc(void);
|
|
||||||
/// initialize a simple motor.
|
|
||||||
CP_EXPORT cpSimpleMotor* cpSimpleMotorInit(cpSimpleMotor *joint, cpBody *a, cpBody *b, cpFloat rate);
|
|
||||||
/// Allocate and initialize a simple motor.
|
|
||||||
CP_EXPORT cpConstraint* cpSimpleMotorNew(cpBody *a, cpBody *b, cpFloat rate);
|
|
||||||
|
|
||||||
/// Get the rate of the motor.
|
|
||||||
CP_EXPORT cpFloat cpSimpleMotorGetRate(const cpConstraint *constraint);
|
|
||||||
/// Set the rate of the motor.
|
|
||||||
CP_EXPORT void cpSimpleMotorSetRate(cpConstraint *constraint, cpFloat rate);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpSlideJoint cpSlideJoint
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Check if a constraint is a slide joint.
|
|
||||||
CP_EXPORT cpBool cpConstraintIsSlideJoint(const cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Allocate a slide joint.
|
|
||||||
CP_EXPORT cpSlideJoint* cpSlideJointAlloc(void);
|
|
||||||
/// Initialize a slide joint.
|
|
||||||
CP_EXPORT cpSlideJoint* cpSlideJointInit(cpSlideJoint *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB, cpFloat min, cpFloat max);
|
|
||||||
/// Allocate and initialize a slide joint.
|
|
||||||
CP_EXPORT cpConstraint* cpSlideJointNew(cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB, cpFloat min, cpFloat max);
|
|
||||||
|
|
||||||
/// Get the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT cpVect cpSlideJointGetAnchorA(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the first anchor relative to the first body.
|
|
||||||
CP_EXPORT void cpSlideJointSetAnchorA(cpConstraint *constraint, cpVect anchorA);
|
|
||||||
|
|
||||||
/// Get the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT cpVect cpSlideJointGetAnchorB(const cpConstraint *constraint);
|
|
||||||
/// Set the location of the second anchor relative to the second body.
|
|
||||||
CP_EXPORT void cpSlideJointSetAnchorB(cpConstraint *constraint, cpVect anchorB);
|
|
||||||
|
|
||||||
/// Get the minimum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT cpFloat cpSlideJointGetMin(const cpConstraint *constraint);
|
|
||||||
/// Set the minimum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT void cpSlideJointSetMin(cpConstraint *constraint, cpFloat min);
|
|
||||||
|
|
||||||
/// Get the maximum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT cpFloat cpSlideJointGetMax(const cpConstraint *constraint);
|
|
||||||
/// Set the maximum distance the joint will maintain between the two anchors.
|
|
||||||
CP_EXPORT void cpSlideJointSetMax(cpConstraint *constraint, cpFloat max);
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,319 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// @defgroup cpSpace cpSpace
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
//MARK: Definitions
|
|
||||||
|
|
||||||
/// Collision begin event function callback type.
|
|
||||||
/// Returning false from a begin callback causes the collision to be ignored until
|
|
||||||
/// the the separate callback is called when the objects stop colliding.
|
|
||||||
typedef cpBool (*cpCollisionBeginFunc)(cpArbiter *arb, cpSpace *space, cpDataPointer userData);
|
|
||||||
/// Collision pre-solve event function callback type.
|
|
||||||
/// Returning false from a pre-step callback causes the collision to be ignored until the next step.
|
|
||||||
typedef cpBool (*cpCollisionPreSolveFunc)(cpArbiter *arb, cpSpace *space, cpDataPointer userData);
|
|
||||||
/// Collision post-solve event function callback type.
|
|
||||||
typedef void (*cpCollisionPostSolveFunc)(cpArbiter *arb, cpSpace *space, cpDataPointer userData);
|
|
||||||
/// Collision separate event function callback type.
|
|
||||||
typedef void (*cpCollisionSeparateFunc)(cpArbiter *arb, cpSpace *space, cpDataPointer userData);
|
|
||||||
|
|
||||||
/// Struct that holds function callback pointers to configure custom collision handling.
|
|
||||||
/// Collision handlers have a pair of types; when a collision occurs between two shapes that have these types, the collision handler functions are triggered.
|
|
||||||
struct cpCollisionHandler {
|
|
||||||
/// Collision type identifier of the first shape that this handler recognizes.
|
|
||||||
/// In the collision handler callback, the shape with this type will be the first argument. Read only.
|
|
||||||
const cpCollisionType typeA;
|
|
||||||
/// Collision type identifier of the second shape that this handler recognizes.
|
|
||||||
/// In the collision handler callback, the shape with this type will be the second argument. Read only.
|
|
||||||
const cpCollisionType typeB;
|
|
||||||
/// This function is called when two shapes with types that match this collision handler begin colliding.
|
|
||||||
cpCollisionBeginFunc beginFunc;
|
|
||||||
/// This function is called each step when two shapes with types that match this collision handler are colliding.
|
|
||||||
/// It's called before the collision solver runs so that you can affect a collision's outcome.
|
|
||||||
cpCollisionPreSolveFunc preSolveFunc;
|
|
||||||
/// This function is called each step when two shapes with types that match this collision handler are colliding.
|
|
||||||
/// It's called after the collision solver runs so that you can read back information about the collision to trigger events in your game.
|
|
||||||
cpCollisionPostSolveFunc postSolveFunc;
|
|
||||||
/// This function is called when two shapes with types that match this collision handler stop colliding.
|
|
||||||
cpCollisionSeparateFunc separateFunc;
|
|
||||||
/// This is a user definable context pointer that is passed to all of the collision handler functions.
|
|
||||||
cpDataPointer userData;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Make timestep a parameter?
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Memory and Initialization
|
|
||||||
|
|
||||||
/// Allocate a cpSpace.
|
|
||||||
CP_EXPORT cpSpace* cpSpaceAlloc(void);
|
|
||||||
/// Initialize a cpSpace.
|
|
||||||
CP_EXPORT cpSpace* cpSpaceInit(cpSpace *space);
|
|
||||||
/// Allocate and initialize a cpSpace.
|
|
||||||
CP_EXPORT cpSpace* cpSpaceNew(void);
|
|
||||||
|
|
||||||
/// Destroy a cpSpace.
|
|
||||||
CP_EXPORT void cpSpaceDestroy(cpSpace *space);
|
|
||||||
/// Destroy and free a cpSpace.
|
|
||||||
CP_EXPORT void cpSpaceFree(cpSpace *space);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Properties
|
|
||||||
|
|
||||||
/// Number of iterations to use in the impulse solver to solve contacts and other constraints.
|
|
||||||
CP_EXPORT int cpSpaceGetIterations(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetIterations(cpSpace *space, int iterations);
|
|
||||||
|
|
||||||
/// Gravity to pass to rigid bodies when integrating velocity.
|
|
||||||
CP_EXPORT cpVect cpSpaceGetGravity(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetGravity(cpSpace *space, cpVect gravity);
|
|
||||||
|
|
||||||
/// Damping rate expressed as the fraction of velocity bodies retain each second.
|
|
||||||
/// A value of 0.9 would mean that each body's velocity will drop 10% per second.
|
|
||||||
/// The default value is 1.0, meaning no damping is applied.
|
|
||||||
/// @note This damping value is different than those of cpDampedSpring and cpDampedRotarySpring.
|
|
||||||
CP_EXPORT cpFloat cpSpaceGetDamping(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetDamping(cpSpace *space, cpFloat damping);
|
|
||||||
|
|
||||||
/// Speed threshold for a body to be considered idle.
|
|
||||||
/// The default value of 0 means to let the space guess a good threshold based on gravity.
|
|
||||||
CP_EXPORT cpFloat cpSpaceGetIdleSpeedThreshold(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetIdleSpeedThreshold(cpSpace *space, cpFloat idleSpeedThreshold);
|
|
||||||
|
|
||||||
/// Time a group of bodies must remain idle in order to fall asleep.
|
|
||||||
/// Enabling sleeping also implicitly enables the the contact graph.
|
|
||||||
/// The default value of INFINITY disables the sleeping algorithm.
|
|
||||||
CP_EXPORT cpFloat cpSpaceGetSleepTimeThreshold(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetSleepTimeThreshold(cpSpace *space, cpFloat sleepTimeThreshold);
|
|
||||||
|
|
||||||
/// Amount of encouraged penetration between colliding shapes.
|
|
||||||
/// Used to reduce oscillating contacts and keep the collision cache warm.
|
|
||||||
/// Defaults to 0.1. If you have poor simulation quality,
|
|
||||||
/// increase this number as much as possible without allowing visible amounts of overlap.
|
|
||||||
CP_EXPORT cpFloat cpSpaceGetCollisionSlop(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetCollisionSlop(cpSpace *space, cpFloat collisionSlop);
|
|
||||||
|
|
||||||
/// Determines how fast overlapping shapes are pushed apart.
|
|
||||||
/// Expressed as a fraction of the error remaining after each second.
|
|
||||||
/// Defaults to pow(1.0 - 0.1, 60.0) meaning that Chipmunk fixes 10% of overlap each frame at 60Hz.
|
|
||||||
CP_EXPORT cpFloat cpSpaceGetCollisionBias(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetCollisionBias(cpSpace *space, cpFloat collisionBias);
|
|
||||||
|
|
||||||
/// Number of frames that contact information should persist.
|
|
||||||
/// Defaults to 3. There is probably never a reason to change this value.
|
|
||||||
CP_EXPORT cpTimestamp cpSpaceGetCollisionPersistence(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetCollisionPersistence(cpSpace *space, cpTimestamp collisionPersistence);
|
|
||||||
|
|
||||||
/// User definable data pointer.
|
|
||||||
/// Generally this points to your game's controller or game state
|
|
||||||
/// class so you can access it when given a cpSpace reference in a callback.
|
|
||||||
CP_EXPORT cpDataPointer cpSpaceGetUserData(const cpSpace *space);
|
|
||||||
CP_EXPORT void cpSpaceSetUserData(cpSpace *space, cpDataPointer userData);
|
|
||||||
|
|
||||||
/// The Space provided static body for a given cpSpace.
|
|
||||||
/// This is merely provided for convenience and you are not required to use it.
|
|
||||||
CP_EXPORT cpBody* cpSpaceGetStaticBody(const cpSpace *space);
|
|
||||||
|
|
||||||
/// Returns the current (or most recent) time step used with the given space.
|
|
||||||
/// Useful from callbacks if your time step is not a compile-time global.
|
|
||||||
CP_EXPORT cpFloat cpSpaceGetCurrentTimeStep(const cpSpace *space);
|
|
||||||
|
|
||||||
/// returns true from inside a callback when objects cannot be added/removed.
|
|
||||||
CP_EXPORT cpBool cpSpaceIsLocked(cpSpace *space);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Collision Handlers
|
|
||||||
|
|
||||||
/// Create or return the existing collision handler that is called for all collisions that are not handled by a more specific collision handler.
|
|
||||||
CP_EXPORT cpCollisionHandler *cpSpaceAddDefaultCollisionHandler(cpSpace *space);
|
|
||||||
/// Create or return the existing collision handler for the specified pair of collision types.
|
|
||||||
/// If wildcard handlers are used with either of the collision types, it's the responibility of the custom handler to invoke the wildcard handlers.
|
|
||||||
CP_EXPORT cpCollisionHandler *cpSpaceAddCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b);
|
|
||||||
/// Create or return the existing wildcard collision handler for the specified type.
|
|
||||||
CP_EXPORT cpCollisionHandler *cpSpaceAddWildcardHandler(cpSpace *space, cpCollisionType type);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Add/Remove objects
|
|
||||||
|
|
||||||
/// Add a collision shape to the simulation.
|
|
||||||
/// If the shape is attached to a static body, it will be added as a static shape.
|
|
||||||
CP_EXPORT cpShape* cpSpaceAddShape(cpSpace *space, cpShape *shape);
|
|
||||||
/// Add a rigid body to the simulation.
|
|
||||||
CP_EXPORT cpBody* cpSpaceAddBody(cpSpace *space, cpBody *body);
|
|
||||||
/// Add a constraint to the simulation.
|
|
||||||
CP_EXPORT cpConstraint* cpSpaceAddConstraint(cpSpace *space, cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Remove a collision shape from the simulation.
|
|
||||||
CP_EXPORT void cpSpaceRemoveShape(cpSpace *space, cpShape *shape);
|
|
||||||
/// Remove a rigid body from the simulation.
|
|
||||||
CP_EXPORT void cpSpaceRemoveBody(cpSpace *space, cpBody *body);
|
|
||||||
/// Remove a constraint from the simulation.
|
|
||||||
CP_EXPORT void cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint);
|
|
||||||
|
|
||||||
/// Test if a collision shape has been added to the space.
|
|
||||||
CP_EXPORT cpBool cpSpaceContainsShape(cpSpace *space, cpShape *shape);
|
|
||||||
/// Test if a rigid body has been added to the space.
|
|
||||||
CP_EXPORT cpBool cpSpaceContainsBody(cpSpace *space, cpBody *body);
|
|
||||||
/// Test if a constraint has been added to the space.
|
|
||||||
CP_EXPORT cpBool cpSpaceContainsConstraint(cpSpace *space, cpConstraint *constraint);
|
|
||||||
|
|
||||||
//MARK: Post-Step Callbacks
|
|
||||||
|
|
||||||
/// Post Step callback function type.
|
|
||||||
typedef void (*cpPostStepFunc)(cpSpace *space, void *key, void *data);
|
|
||||||
/// Schedule a post-step callback to be called when cpSpaceStep() finishes.
|
|
||||||
/// You can only register one callback per unique value for @c key.
|
|
||||||
/// Returns true only if @c key has never been scheduled before.
|
|
||||||
/// It's possible to pass @c NULL for @c func if you only want to mark @c key as being used.
|
|
||||||
CP_EXPORT cpBool cpSpaceAddPostStepCallback(cpSpace *space, cpPostStepFunc func, void *key, void *data);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Queries
|
|
||||||
|
|
||||||
// TODO: Queries and iterators should take a cpSpace parametery.
|
|
||||||
// TODO: They should also be abortable.
|
|
||||||
|
|
||||||
/// Nearest point query callback function type.
|
|
||||||
typedef void (*cpSpacePointQueryFunc)(cpShape *shape, cpVect point, cpFloat distance, cpVect gradient, void *data);
|
|
||||||
/// Query the space at a point and call @c func for each shape found.
|
|
||||||
CP_EXPORT void cpSpacePointQuery(cpSpace *space, cpVect point, cpFloat maxDistance, cpShapeFilter filter, cpSpacePointQueryFunc func, void *data);
|
|
||||||
/// Query the space at a point and return the nearest shape found. Returns NULL if no shapes were found.
|
|
||||||
CP_EXPORT cpShape *cpSpacePointQueryNearest(cpSpace *space, cpVect point, cpFloat maxDistance, cpShapeFilter filter, cpPointQueryInfo *out);
|
|
||||||
|
|
||||||
/// Segment query callback function type.
|
|
||||||
typedef void (*cpSpaceSegmentQueryFunc)(cpShape *shape, cpVect point, cpVect normal, cpFloat alpha, void *data);
|
|
||||||
/// Perform a directed line segment query (like a raycast) against the space calling @c func for each shape intersected.
|
|
||||||
CP_EXPORT void cpSpaceSegmentQuery(cpSpace *space, cpVect start, cpVect end, cpFloat radius, cpShapeFilter filter, cpSpaceSegmentQueryFunc func, void *data);
|
|
||||||
/// Perform a directed line segment query (like a raycast) against the space and return the first shape hit. Returns NULL if no shapes were hit.
|
|
||||||
CP_EXPORT cpShape *cpSpaceSegmentQueryFirst(cpSpace *space, cpVect start, cpVect end, cpFloat radius, cpShapeFilter filter, cpSegmentQueryInfo *out);
|
|
||||||
|
|
||||||
/// Rectangle Query callback function type.
|
|
||||||
typedef void (*cpSpaceBBQueryFunc)(cpShape *shape, void *data);
|
|
||||||
/// Perform a fast rectangle query on the space calling @c func for each shape found.
|
|
||||||
/// Only the shape's bounding boxes are checked for overlap, not their full shape.
|
|
||||||
CP_EXPORT void cpSpaceBBQuery(cpSpace *space, cpBB bb, cpShapeFilter filter, cpSpaceBBQueryFunc func, void *data);
|
|
||||||
|
|
||||||
/// Shape query callback function type.
|
|
||||||
typedef void (*cpSpaceShapeQueryFunc)(cpShape *shape, cpContactPointSet *points, void *data);
|
|
||||||
/// Query a space for any shapes overlapping the given shape and call @c func for each shape found.
|
|
||||||
CP_EXPORT cpBool cpSpaceShapeQuery(cpSpace *space, cpShape *shape, cpSpaceShapeQueryFunc func, void *data);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Iteration
|
|
||||||
|
|
||||||
/// Space/body iterator callback function type.
|
|
||||||
typedef void (*cpSpaceBodyIteratorFunc)(cpBody *body, void *data);
|
|
||||||
/// Call @c func for each body in the space.
|
|
||||||
CP_EXPORT void cpSpaceEachBody(cpSpace *space, cpSpaceBodyIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
/// Space/body iterator callback function type.
|
|
||||||
typedef void (*cpSpaceShapeIteratorFunc)(cpShape *shape, void *data);
|
|
||||||
/// Call @c func for each shape in the space.
|
|
||||||
CP_EXPORT void cpSpaceEachShape(cpSpace *space, cpSpaceShapeIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
/// Space/constraint iterator callback function type.
|
|
||||||
typedef void (*cpSpaceConstraintIteratorFunc)(cpConstraint *constraint, void *data);
|
|
||||||
/// Call @c func for each shape in the space.
|
|
||||||
CP_EXPORT void cpSpaceEachConstraint(cpSpace *space, cpSpaceConstraintIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Indexing
|
|
||||||
|
|
||||||
/// Update the collision detection info for the static shapes in the space.
|
|
||||||
CP_EXPORT void cpSpaceReindexStatic(cpSpace *space);
|
|
||||||
/// Update the collision detection data for a specific shape in the space.
|
|
||||||
CP_EXPORT void cpSpaceReindexShape(cpSpace *space, cpShape *shape);
|
|
||||||
/// Update the collision detection data for all shapes attached to a body.
|
|
||||||
CP_EXPORT void cpSpaceReindexShapesForBody(cpSpace *space, cpBody *body);
|
|
||||||
|
|
||||||
/// Switch the space to use a spatial has as it's spatial index.
|
|
||||||
CP_EXPORT void cpSpaceUseSpatialHash(cpSpace *space, cpFloat dim, int count);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Time Stepping
|
|
||||||
|
|
||||||
/// Step the space forward in time by @c dt.
|
|
||||||
CP_EXPORT void cpSpaceStep(cpSpace *space, cpFloat dt);
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Debug API
|
|
||||||
|
|
||||||
#ifndef CP_SPACE_DISABLE_DEBUG_API
|
|
||||||
|
|
||||||
/// Color type to use with the space debug drawing API.
|
|
||||||
typedef struct cpSpaceDebugColor {
|
|
||||||
float r, g, b, a;
|
|
||||||
} cpSpaceDebugColor;
|
|
||||||
|
|
||||||
/// Callback type for a function that draws a filled, stroked circle.
|
|
||||||
typedef void (*cpSpaceDebugDrawCircleImpl)(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer data);
|
|
||||||
/// Callback type for a function that draws a line segment.
|
|
||||||
typedef void (*cpSpaceDebugDrawSegmentImpl)(cpVect a, cpVect b, cpSpaceDebugColor color, cpDataPointer data);
|
|
||||||
/// Callback type for a function that draws a thick line segment.
|
|
||||||
typedef void (*cpSpaceDebugDrawFatSegmentImpl)(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer data);
|
|
||||||
/// Callback type for a function that draws a convex polygon.
|
|
||||||
typedef void (*cpSpaceDebugDrawPolygonImpl)(int count, const cpVect *verts, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer data);
|
|
||||||
/// Callback type for a function that draws a dot.
|
|
||||||
typedef void (*cpSpaceDebugDrawDotImpl)(cpFloat size, cpVect pos, cpSpaceDebugColor color, cpDataPointer data);
|
|
||||||
/// Callback type for a function that returns a color for a given shape. This gives you an opportunity to color shapes based on how they are used in your engine.
|
|
||||||
typedef cpSpaceDebugColor (*cpSpaceDebugDrawColorForShapeImpl)(cpShape *shape, cpDataPointer data);
|
|
||||||
|
|
||||||
typedef enum cpSpaceDebugDrawFlags {
|
|
||||||
CP_SPACE_DEBUG_DRAW_SHAPES = 1<<0,
|
|
||||||
CP_SPACE_DEBUG_DRAW_CONSTRAINTS = 1<<1,
|
|
||||||
CP_SPACE_DEBUG_DRAW_COLLISION_POINTS = 1<<2,
|
|
||||||
} cpSpaceDebugDrawFlags;
|
|
||||||
|
|
||||||
/// Struct used with cpSpaceDebugDraw() containing drawing callbacks and other drawing settings.
|
|
||||||
typedef struct cpSpaceDebugDrawOptions {
|
|
||||||
/// Function that will be invoked to draw circles.
|
|
||||||
cpSpaceDebugDrawCircleImpl drawCircle;
|
|
||||||
/// Function that will be invoked to draw line segments.
|
|
||||||
cpSpaceDebugDrawSegmentImpl drawSegment;
|
|
||||||
/// Function that will be invoked to draw thick line segments.
|
|
||||||
cpSpaceDebugDrawFatSegmentImpl drawFatSegment;
|
|
||||||
/// Function that will be invoked to draw convex polygons.
|
|
||||||
cpSpaceDebugDrawPolygonImpl drawPolygon;
|
|
||||||
/// Function that will be invoked to draw dots.
|
|
||||||
cpSpaceDebugDrawDotImpl drawDot;
|
|
||||||
|
|
||||||
/// Flags that request which things to draw (collision shapes, constraints, contact points).
|
|
||||||
cpSpaceDebugDrawFlags flags;
|
|
||||||
/// Outline color passed to the drawing function.
|
|
||||||
cpSpaceDebugColor shapeOutlineColor;
|
|
||||||
/// Function that decides what fill color to draw shapes using.
|
|
||||||
cpSpaceDebugDrawColorForShapeImpl colorForShape;
|
|
||||||
/// Color passed to drawing functions for constraints.
|
|
||||||
cpSpaceDebugColor constraintColor;
|
|
||||||
/// Color passed to drawing functions for collision points.
|
|
||||||
cpSpaceDebugColor collisionPointColor;
|
|
||||||
|
|
||||||
/// User defined context pointer passed to all of the callback functions as the 'data' argument.
|
|
||||||
cpDataPointer data;
|
|
||||||
} cpSpaceDebugDrawOptions;
|
|
||||||
|
|
||||||
/// Debug draw the current state of the space using the supplied drawing options.
|
|
||||||
CP_EXPORT void cpSpaceDebugDraw(cpSpace *space, cpSpaceDebugDrawOptions *options);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,227 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
@defgroup cpSpatialIndex cpSpatialIndex
|
|
||||||
|
|
||||||
Spatial indexes are data structures that are used to accelerate collision detection
|
|
||||||
and spatial queries. Chipmunk provides a number of spatial index algorithms to pick from
|
|
||||||
and they are programmed in a generic way so that you can use them for holding more than
|
|
||||||
just cpShape structs.
|
|
||||||
|
|
||||||
It works by using @c void pointers to the objects you add and using a callback to ask your code
|
|
||||||
for bounding boxes when it needs them. Several types of queries can be performed an index as well
|
|
||||||
as reindexing and full collision information. All communication to the spatial indexes is performed
|
|
||||||
through callback functions.
|
|
||||||
|
|
||||||
Spatial indexes should be treated as opaque structs.
|
|
||||||
This meanns you shouldn't be reading any of the struct fields.
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
//MARK: Spatial Index
|
|
||||||
|
|
||||||
/// Spatial index bounding box callback function type.
|
|
||||||
/// The spatial index calls this function and passes you a pointer to an object you added
|
|
||||||
/// when it needs to get the bounding box associated with that object.
|
|
||||||
typedef cpBB (*cpSpatialIndexBBFunc)(void *obj);
|
|
||||||
/// Spatial index/object iterator callback function type.
|
|
||||||
typedef void (*cpSpatialIndexIteratorFunc)(void *obj, void *data);
|
|
||||||
/// Spatial query callback function type.
|
|
||||||
typedef cpCollisionID (*cpSpatialIndexQueryFunc)(void *obj1, void *obj2, cpCollisionID id, void *data);
|
|
||||||
/// Spatial segment query callback function type.
|
|
||||||
typedef cpFloat (*cpSpatialIndexSegmentQueryFunc)(void *obj1, void *obj2, void *data);
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct cpSpatialIndexClass cpSpatialIndexClass;
|
|
||||||
typedef struct cpSpatialIndex cpSpatialIndex;
|
|
||||||
|
|
||||||
/// @private
|
|
||||||
struct cpSpatialIndex {
|
|
||||||
cpSpatialIndexClass *klass;
|
|
||||||
|
|
||||||
cpSpatialIndexBBFunc bbfunc;
|
|
||||||
|
|
||||||
cpSpatialIndex *staticIndex, *dynamicIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: Spatial Hash
|
|
||||||
|
|
||||||
typedef struct cpSpaceHash cpSpaceHash;
|
|
||||||
|
|
||||||
/// Allocate a spatial hash.
|
|
||||||
CP_EXPORT cpSpaceHash* cpSpaceHashAlloc(void);
|
|
||||||
/// Initialize a spatial hash.
|
|
||||||
CP_EXPORT cpSpatialIndex* cpSpaceHashInit(cpSpaceHash *hash, cpFloat celldim, int numcells, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
|
|
||||||
/// Allocate and initialize a spatial hash.
|
|
||||||
CP_EXPORT cpSpatialIndex* cpSpaceHashNew(cpFloat celldim, int cells, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
|
|
||||||
|
|
||||||
/// Change the cell dimensions and table size of the spatial hash to tune it.
|
|
||||||
/// The cell dimensions should roughly match the average size of your objects
|
|
||||||
/// and the table size should be ~10 larger than the number of objects inserted.
|
|
||||||
/// Some trial and error is required to find the optimum numbers for efficiency.
|
|
||||||
CP_EXPORT void cpSpaceHashResize(cpSpaceHash *hash, cpFloat celldim, int numcells);
|
|
||||||
|
|
||||||
//MARK: AABB Tree
|
|
||||||
|
|
||||||
typedef struct cpBBTree cpBBTree;
|
|
||||||
|
|
||||||
/// Allocate a bounding box tree.
|
|
||||||
CP_EXPORT cpBBTree* cpBBTreeAlloc(void);
|
|
||||||
/// Initialize a bounding box tree.
|
|
||||||
CP_EXPORT cpSpatialIndex* cpBBTreeInit(cpBBTree *tree, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
|
|
||||||
/// Allocate and initialize a bounding box tree.
|
|
||||||
CP_EXPORT cpSpatialIndex* cpBBTreeNew(cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
|
|
||||||
|
|
||||||
/// Perform a static top down optimization of the tree.
|
|
||||||
CP_EXPORT void cpBBTreeOptimize(cpSpatialIndex *index);
|
|
||||||
|
|
||||||
/// Bounding box tree velocity callback function.
|
|
||||||
/// This function should return an estimate for the object's velocity.
|
|
||||||
typedef cpVect (*cpBBTreeVelocityFunc)(void *obj);
|
|
||||||
/// Set the velocity function for the bounding box tree to enable temporal coherence.
|
|
||||||
CP_EXPORT void cpBBTreeSetVelocityFunc(cpSpatialIndex *index, cpBBTreeVelocityFunc func);
|
|
||||||
|
|
||||||
//MARK: Single Axis Sweep
|
|
||||||
|
|
||||||
typedef struct cpSweep1D cpSweep1D;
|
|
||||||
|
|
||||||
/// Allocate a 1D sort and sweep broadphase.
|
|
||||||
CP_EXPORT cpSweep1D* cpSweep1DAlloc(void);
|
|
||||||
/// Initialize a 1D sort and sweep broadphase.
|
|
||||||
CP_EXPORT cpSpatialIndex* cpSweep1DInit(cpSweep1D *sweep, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
|
|
||||||
/// Allocate and initialize a 1D sort and sweep broadphase.
|
|
||||||
CP_EXPORT cpSpatialIndex* cpSweep1DNew(cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex);
|
|
||||||
|
|
||||||
//MARK: Spatial Index Implementation
|
|
||||||
|
|
||||||
typedef void (*cpSpatialIndexDestroyImpl)(cpSpatialIndex *index);
|
|
||||||
|
|
||||||
typedef int (*cpSpatialIndexCountImpl)(cpSpatialIndex *index);
|
|
||||||
typedef void (*cpSpatialIndexEachImpl)(cpSpatialIndex *index, cpSpatialIndexIteratorFunc func, void *data);
|
|
||||||
|
|
||||||
typedef cpBool (*cpSpatialIndexContainsImpl)(cpSpatialIndex *index, void *obj, cpHashValue hashid);
|
|
||||||
typedef void (*cpSpatialIndexInsertImpl)(cpSpatialIndex *index, void *obj, cpHashValue hashid);
|
|
||||||
typedef void (*cpSpatialIndexRemoveImpl)(cpSpatialIndex *index, void *obj, cpHashValue hashid);
|
|
||||||
|
|
||||||
typedef void (*cpSpatialIndexReindexImpl)(cpSpatialIndex *index);
|
|
||||||
typedef void (*cpSpatialIndexReindexObjectImpl)(cpSpatialIndex *index, void *obj, cpHashValue hashid);
|
|
||||||
typedef void (*cpSpatialIndexReindexQueryImpl)(cpSpatialIndex *index, cpSpatialIndexQueryFunc func, void *data);
|
|
||||||
|
|
||||||
typedef void (*cpSpatialIndexQueryImpl)(cpSpatialIndex *index, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, void *data);
|
|
||||||
typedef void (*cpSpatialIndexSegmentQueryImpl)(cpSpatialIndex *index, void *obj, cpVect a, cpVect b, cpFloat t_exit, cpSpatialIndexSegmentQueryFunc func, void *data);
|
|
||||||
|
|
||||||
struct cpSpatialIndexClass {
|
|
||||||
cpSpatialIndexDestroyImpl destroy;
|
|
||||||
|
|
||||||
cpSpatialIndexCountImpl count;
|
|
||||||
cpSpatialIndexEachImpl each;
|
|
||||||
|
|
||||||
cpSpatialIndexContainsImpl contains;
|
|
||||||
cpSpatialIndexInsertImpl insert;
|
|
||||||
cpSpatialIndexRemoveImpl remove;
|
|
||||||
|
|
||||||
cpSpatialIndexReindexImpl reindex;
|
|
||||||
cpSpatialIndexReindexObjectImpl reindexObject;
|
|
||||||
cpSpatialIndexReindexQueryImpl reindexQuery;
|
|
||||||
|
|
||||||
cpSpatialIndexQueryImpl query;
|
|
||||||
cpSpatialIndexSegmentQueryImpl segmentQuery;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Destroy and free a spatial index.
|
|
||||||
void cpSpatialIndexFree(cpSpatialIndex *index);
|
|
||||||
/// Collide the objects in @c dynamicIndex against the objects in @c staticIndex using the query callback function.
|
|
||||||
void cpSpatialIndexCollideStatic(cpSpatialIndex *dynamicIndex, cpSpatialIndex *staticIndex, cpSpatialIndexQueryFunc func, void *data);
|
|
||||||
|
|
||||||
/// Destroy a spatial index.
|
|
||||||
static inline void cpSpatialIndexDestroy(cpSpatialIndex *index)
|
|
||||||
{
|
|
||||||
if(index->klass) index->klass->destroy(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the number of objects in the spatial index.
|
|
||||||
static inline int cpSpatialIndexCount(cpSpatialIndex *index)
|
|
||||||
{
|
|
||||||
return index->klass->count(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Iterate the objects in the spatial index. @c func will be called once for each object.
|
|
||||||
static inline void cpSpatialIndexEach(cpSpatialIndex *index, cpSpatialIndexIteratorFunc func, void *data)
|
|
||||||
{
|
|
||||||
index->klass->each(index, func, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the spatial index contains the given object.
|
|
||||||
/// Most spatial indexes use hashed storage, so you must provide a hash value too.
|
|
||||||
static inline cpBool cpSpatialIndexContains(cpSpatialIndex *index, void *obj, cpHashValue hashid)
|
|
||||||
{
|
|
||||||
return index->klass->contains(index, obj, hashid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add an object to a spatial index.
|
|
||||||
/// Most spatial indexes use hashed storage, so you must provide a hash value too.
|
|
||||||
static inline void cpSpatialIndexInsert(cpSpatialIndex *index, void *obj, cpHashValue hashid)
|
|
||||||
{
|
|
||||||
index->klass->insert(index, obj, hashid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove an object from a spatial index.
|
|
||||||
/// Most spatial indexes use hashed storage, so you must provide a hash value too.
|
|
||||||
static inline void cpSpatialIndexRemove(cpSpatialIndex *index, void *obj, cpHashValue hashid)
|
|
||||||
{
|
|
||||||
index->klass->remove(index, obj, hashid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Perform a full reindex of a spatial index.
|
|
||||||
static inline void cpSpatialIndexReindex(cpSpatialIndex *index)
|
|
||||||
{
|
|
||||||
index->klass->reindex(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reindex a single object in the spatial index.
|
|
||||||
static inline void cpSpatialIndexReindexObject(cpSpatialIndex *index, void *obj, cpHashValue hashid)
|
|
||||||
{
|
|
||||||
index->klass->reindexObject(index, obj, hashid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Perform a rectangle query against the spatial index, calling @c func for each potential match.
|
|
||||||
static inline void cpSpatialIndexQuery(cpSpatialIndex *index, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, void *data)
|
|
||||||
{
|
|
||||||
index->klass->query(index, obj, bb, func, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Perform a segment query against the spatial index, calling @c func for each potential match.
|
|
||||||
static inline void cpSpatialIndexSegmentQuery(cpSpatialIndex *index, void *obj, cpVect a, cpVect b, cpFloat t_exit, cpSpatialIndexSegmentQueryFunc func, void *data)
|
|
||||||
{
|
|
||||||
index->klass->segmentQuery(index, obj, a, b, t_exit, func, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Simultaneously reindex and find all colliding objects.
|
|
||||||
/// @c func will be called once for each potentially overlapping pair of objects found.
|
|
||||||
/// If the spatial index was initialized with a static index, it will collide it's objects against that as well.
|
|
||||||
static inline void cpSpatialIndexReindexQuery(cpSpatialIndex *index, cpSpatialIndexQueryFunc func, void *data)
|
|
||||||
{
|
|
||||||
index->klass->reindexQuery(index, func, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
///@}
|
|
||||||
|
|
@ -1,198 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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 CHIPMUNK_TRANSFORM_H
|
|
||||||
#define CHIPMUNK_TRANSFORM_H
|
|
||||||
|
|
||||||
#include "chipmunk_types.h"
|
|
||||||
#include "cpVect.h"
|
|
||||||
#include "cpBB.h"
|
|
||||||
|
|
||||||
/// Identity transform matrix.
|
|
||||||
static const cpTransform cpTransformIdentity = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
|
|
||||||
|
|
||||||
/// Construct a new transform matrix.
|
|
||||||
/// (a, b) is the x basis vector.
|
|
||||||
/// (c, d) is the y basis vector.
|
|
||||||
/// (tx, ty) is the translation.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformNew(cpFloat a, cpFloat b, cpFloat c, cpFloat d, cpFloat tx, cpFloat ty)
|
|
||||||
{
|
|
||||||
cpTransform t = {a, b, c, d, tx, ty};
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct a new transform matrix in transposed order.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformNewTranspose(cpFloat a, cpFloat c, cpFloat tx, cpFloat b, cpFloat d, cpFloat ty)
|
|
||||||
{
|
|
||||||
cpTransform t = {a, b, c, d, tx, ty};
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the inverse of a transform matrix.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformInverse(cpTransform t)
|
|
||||||
{
|
|
||||||
cpFloat inv_det = 1.0/(t.a*t.d - t.c*t.b);
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
t.d*inv_det, -t.c*inv_det, (t.c*t.ty - t.tx*t.d)*inv_det,
|
|
||||||
-t.b*inv_det, t.a*inv_det, (t.tx*t.b - t.a*t.ty)*inv_det
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Multiply two transformation matrices.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformMult(cpTransform t1, cpTransform t2)
|
|
||||||
{
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
t1.a*t2.a + t1.c*t2.b, t1.a*t2.c + t1.c*t2.d, t1.a*t2.tx + t1.c*t2.ty + t1.tx,
|
|
||||||
t1.b*t2.a + t1.d*t2.b, t1.b*t2.c + t1.d*t2.d, t1.b*t2.tx + t1.d*t2.ty + t1.ty
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Transform an absolute point. (i.e. a vertex)
|
|
||||||
static inline cpVect
|
|
||||||
cpTransformPoint(cpTransform t, cpVect p)
|
|
||||||
{
|
|
||||||
return cpv(t.a*p.x + t.c*p.y + t.tx, t.b*p.x + t.d*p.y + t.ty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Transform a vector (i.e. a normal)
|
|
||||||
static inline cpVect
|
|
||||||
cpTransformVect(cpTransform t, cpVect v)
|
|
||||||
{
|
|
||||||
return cpv(t.a*v.x + t.c*v.y, t.b*v.x + t.d*v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Transform a cpBB.
|
|
||||||
static inline cpBB
|
|
||||||
cpTransformbBB(cpTransform t, cpBB bb)
|
|
||||||
{
|
|
||||||
cpVect center = cpBBCenter(bb);
|
|
||||||
cpFloat hw = (bb.r - bb.l)*0.5;
|
|
||||||
cpFloat hh = (bb.t - bb.b)*0.5;
|
|
||||||
|
|
||||||
cpFloat a = t.a*hw, b = t.c*hh, d = t.b*hw, e = t.d*hh;
|
|
||||||
cpFloat hw_max = cpfmax(cpfabs(a + b), cpfabs(a - b));
|
|
||||||
cpFloat hh_max = cpfmax(cpfabs(d + e), cpfabs(d - e));
|
|
||||||
return cpBBNewForExtents(cpTransformPoint(t, center), hw_max, hh_max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a transation matrix.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformTranslate(cpVect translate)
|
|
||||||
{
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
1.0, 0.0, translate.x,
|
|
||||||
0.0, 1.0, translate.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a scale matrix.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformScale(cpFloat scaleX, cpFloat scaleY)
|
|
||||||
{
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
scaleX, 0.0, 0.0,
|
|
||||||
0.0, scaleY, 0.0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a rotation matrix.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformRotate(cpFloat radians)
|
|
||||||
{
|
|
||||||
cpVect rot = cpvforangle(radians);
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
rot.x, -rot.y, 0.0,
|
|
||||||
rot.y, rot.x, 0.0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a rigid transformation matrix. (transation + rotation)
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformRigid(cpVect translate, cpFloat radians)
|
|
||||||
{
|
|
||||||
cpVect rot = cpvforangle(radians);
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
rot.x, -rot.y, translate.x,
|
|
||||||
rot.y, rot.x, translate.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fast inverse of a rigid transformation matrix.
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformRigidInverse(cpTransform t)
|
|
||||||
{
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
t.d, -t.c, (t.c*t.ty - t.tx*t.d),
|
|
||||||
-t.b, t.a, (t.tx*t.b - t.a*t.ty)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//MARK: Miscellaneous (but useful) transformation matrices.
|
|
||||||
// See source for documentation...
|
|
||||||
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformWrap(cpTransform outer, cpTransform inner)
|
|
||||||
{
|
|
||||||
return cpTransformMult(cpTransformInverse(outer), cpTransformMult(inner, outer));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformWrapInverse(cpTransform outer, cpTransform inner)
|
|
||||||
{
|
|
||||||
return cpTransformMult(outer, cpTransformMult(inner, cpTransformInverse(outer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformOrtho(cpBB bb)
|
|
||||||
{
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
2.0/(bb.r - bb.l), 0.0, -(bb.r + bb.l)/(bb.r - bb.l),
|
|
||||||
0.0, 2.0/(bb.t - bb.b), -(bb.t + bb.b)/(bb.t - bb.b)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformBoneScale(cpVect v0, cpVect v1)
|
|
||||||
{
|
|
||||||
cpVect d = cpvsub(v1, v0);
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
d.x, -d.y, v0.x,
|
|
||||||
d.y, d.x, v0.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpTransform
|
|
||||||
cpTransformAxialScale(cpVect axis, cpVect pivot, cpFloat scale)
|
|
||||||
{
|
|
||||||
cpFloat A = axis.x*axis.y*(scale - 1.0);
|
|
||||||
cpFloat B = cpvdot(axis, pivot)*(1.0 - scale);
|
|
||||||
|
|
||||||
return cpTransformNewTranspose(
|
|
||||||
scale*axis.x*axis.x + axis.y*axis.y, A, axis.x*B,
|
|
||||||
A, axis.x*axis.x + scale*axis.y*axis.y, axis.y*B
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,230 +0,0 @@
|
||||||
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
|
|
||||||
*
|
|
||||||
* 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 CHIPMUNK_VECT_H
|
|
||||||
#define CHIPMUNK_VECT_H
|
|
||||||
|
|
||||||
#include "chipmunk_types.h"
|
|
||||||
|
|
||||||
/// @defgroup cpVect cpVect
|
|
||||||
/// Chipmunk's 2D vector type along with a handy 2D vector math lib.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// Constant for the zero vector.
|
|
||||||
static const cpVect cpvzero = {0.0f,0.0f};
|
|
||||||
|
|
||||||
/// Convenience constructor for cpVect structs.
|
|
||||||
static inline cpVect cpv(const cpFloat x, const cpFloat y)
|
|
||||||
{
|
|
||||||
cpVect v = {x, y};
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if two vectors are equal. (Be careful when comparing floating point numbers!)
|
|
||||||
static inline cpBool cpveql(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return (v1.x == v2.x && v1.y == v2.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add two vectors
|
|
||||||
static inline cpVect cpvadd(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return cpv(v1.x + v2.x, v1.y + v2.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Subtract two vectors.
|
|
||||||
static inline cpVect cpvsub(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return cpv(v1.x - v2.x, v1.y - v2.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Negate a vector.
|
|
||||||
static inline cpVect cpvneg(const cpVect v)
|
|
||||||
{
|
|
||||||
return cpv(-v.x, -v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Scalar multiplication.
|
|
||||||
static inline cpVect cpvmult(const cpVect v, const cpFloat s)
|
|
||||||
{
|
|
||||||
return cpv(v.x*s, v.y*s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Vector dot product.
|
|
||||||
static inline cpFloat cpvdot(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return v1.x*v2.x + v1.y*v2.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 2D vector cross product analog.
|
|
||||||
/// The cross product of 2D vectors results in a 3D vector with only a z component.
|
|
||||||
/// This function returns the magnitude of the z value.
|
|
||||||
static inline cpFloat cpvcross(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return v1.x*v2.y - v1.y*v2.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a perpendicular vector. (90 degree rotation)
|
|
||||||
static inline cpVect cpvperp(const cpVect v)
|
|
||||||
{
|
|
||||||
return cpv(-v.y, v.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a perpendicular vector. (-90 degree rotation)
|
|
||||||
static inline cpVect cpvrperp(const cpVect v)
|
|
||||||
{
|
|
||||||
return cpv(v.y, -v.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the vector projection of v1 onto v2.
|
|
||||||
static inline cpVect cpvproject(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return cpvmult(v2, cpvdot(v1, v2)/cpvdot(v2, v2));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the unit length vector for the given angle (in radians).
|
|
||||||
static inline cpVect cpvforangle(const cpFloat a)
|
|
||||||
{
|
|
||||||
return cpv(cpfcos(a), cpfsin(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the angular direction v is pointing in (in radians).
|
|
||||||
static inline cpFloat cpvtoangle(const cpVect v)
|
|
||||||
{
|
|
||||||
return cpfatan2(v.y, v.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Uses complex number multiplication to rotate v1 by v2. Scaling will occur if v1 is not a unit vector.
|
|
||||||
static inline cpVect cpvrotate(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return cpv(v1.x*v2.x - v1.y*v2.y, v1.x*v2.y + v1.y*v2.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Inverse of cpvrotate().
|
|
||||||
static inline cpVect cpvunrotate(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return cpv(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the squared length of v. Faster than cpvlength() when you only need to compare lengths.
|
|
||||||
static inline cpFloat cpvlengthsq(const cpVect v)
|
|
||||||
{
|
|
||||||
return cpvdot(v, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the length of v.
|
|
||||||
static inline cpFloat cpvlength(const cpVect v)
|
|
||||||
{
|
|
||||||
return cpfsqrt(cpvdot(v, v));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Linearly interpolate between v1 and v2.
|
|
||||||
static inline cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t)
|
|
||||||
{
|
|
||||||
return cpvadd(cpvmult(v1, 1.0f - t), cpvmult(v2, t));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a normalized copy of v.
|
|
||||||
static inline cpVect cpvnormalize(const cpVect v)
|
|
||||||
{
|
|
||||||
// Neat trick I saw somewhere to avoid div/0.
|
|
||||||
return cpvmult(v, 1.0f/(cpvlength(v) + CPFLOAT_MIN));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Spherical linearly interpolate between v1 and v2.
|
|
||||||
static inline cpVect
|
|
||||||
cpvslerp(const cpVect v1, const cpVect v2, const cpFloat t)
|
|
||||||
{
|
|
||||||
cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2));
|
|
||||||
cpFloat omega = cpfacos(cpfclamp(dot, -1.0f, 1.0f));
|
|
||||||
|
|
||||||
if(omega < 1e-3){
|
|
||||||
// If the angle between two vectors is very small, lerp instead to avoid precision issues.
|
|
||||||
return cpvlerp(v1, v2, t);
|
|
||||||
} else {
|
|
||||||
cpFloat denom = 1.0f/cpfsin(omega);
|
|
||||||
return cpvadd(cpvmult(v1, cpfsin((1.0f - t)*omega)*denom), cpvmult(v2, cpfsin(t*omega)*denom));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Spherical linearly interpolate between v1 towards v2 by no more than angle a radians
|
|
||||||
static inline cpVect
|
|
||||||
cpvslerpconst(const cpVect v1, const cpVect v2, const cpFloat a)
|
|
||||||
{
|
|
||||||
cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2));
|
|
||||||
cpFloat omega = cpfacos(cpfclamp(dot, -1.0f, 1.0f));
|
|
||||||
|
|
||||||
return cpvslerp(v1, v2, cpfmin(a, omega)/omega);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clamp v to length len.
|
|
||||||
static inline cpVect cpvclamp(const cpVect v, const cpFloat len)
|
|
||||||
{
|
|
||||||
return (cpvdot(v,v) > len*len) ? cpvmult(cpvnormalize(v), len) : v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Linearly interpolate between v1 towards v2 by distance d.
|
|
||||||
static inline cpVect cpvlerpconst(cpVect v1, cpVect v2, cpFloat d)
|
|
||||||
{
|
|
||||||
return cpvadd(v1, cpvclamp(cpvsub(v2, v1), d));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the distance between v1 and v2.
|
|
||||||
static inline cpFloat cpvdist(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return cpvlength(cpvsub(v1, v2));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the squared distance between v1 and v2. Faster than cpvdist() when you only need to compare distances.
|
|
||||||
static inline cpFloat cpvdistsq(const cpVect v1, const cpVect v2)
|
|
||||||
{
|
|
||||||
return cpvlengthsq(cpvsub(v1, v2));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the distance between v1 and v2 is less than dist.
|
|
||||||
static inline cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dist)
|
|
||||||
{
|
|
||||||
return cpvdistsq(v1, v2) < dist*dist;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
/// @defgroup cpMat2x2 cpMat2x2
|
|
||||||
/// 2x2 matrix type used for tensors and such.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
// NUKE
|
|
||||||
static inline cpMat2x2
|
|
||||||
cpMat2x2New(cpFloat a, cpFloat b, cpFloat c, cpFloat d)
|
|
||||||
{
|
|
||||||
cpMat2x2 m = {a, b, c, d};
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline cpVect
|
|
||||||
cpMat2x2Transform(cpMat2x2 m, cpVect v)
|
|
||||||
{
|
|
||||||
return cpv(v.x*m.a + v.y*m.b, v.x*m.c + v.y*m.d);
|
|
||||||
}
|
|
||||||
|
|
||||||
///@}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -0,0 +1,571 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||||
|
// Copyright (C) 2017 ARM Limited.
|
||||||
|
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _BASICTYPES_INCLUDED_
|
||||||
|
#define _BASICTYPES_INCLUDED_
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Basic type. Arrays, vectors, sampler details, etc., are orthogonal to this.
|
||||||
|
//
|
||||||
|
enum TBasicType {
|
||||||
|
EbtVoid,
|
||||||
|
EbtFloat,
|
||||||
|
EbtDouble,
|
||||||
|
EbtFloat16,
|
||||||
|
EbtInt8,
|
||||||
|
EbtUint8,
|
||||||
|
EbtInt16,
|
||||||
|
EbtUint16,
|
||||||
|
EbtInt,
|
||||||
|
EbtUint,
|
||||||
|
EbtInt64,
|
||||||
|
EbtUint64,
|
||||||
|
EbtBool,
|
||||||
|
EbtAtomicUint,
|
||||||
|
EbtSampler,
|
||||||
|
EbtStruct,
|
||||||
|
EbtBlock,
|
||||||
|
EbtAccStruct,
|
||||||
|
EbtReference,
|
||||||
|
EbtRayQuery,
|
||||||
|
|
||||||
|
// HLSL types that live only temporarily.
|
||||||
|
EbtString,
|
||||||
|
|
||||||
|
EbtNumTypes
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Storage qualifiers. Should align with different kinds of storage or
|
||||||
|
// resource or GLSL storage qualifier. Expansion is deprecated.
|
||||||
|
//
|
||||||
|
// N.B.: You probably DON'T want to add anything here, but rather just add it
|
||||||
|
// to the built-in variables. See the comment above TBuiltInVariable.
|
||||||
|
//
|
||||||
|
// A new built-in variable will normally be an existing qualifier, like 'in', 'out', etc.
|
||||||
|
// DO NOT follow the design pattern of, say EvqInstanceId, etc.
|
||||||
|
//
|
||||||
|
enum TStorageQualifier {
|
||||||
|
EvqTemporary, // For temporaries (within a function), read/write
|
||||||
|
EvqGlobal, // For globals read/write
|
||||||
|
EvqConst, // User-defined constant values, will be semantically constant and constant folded
|
||||||
|
EvqVaryingIn, // pipeline input, read only, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
|
||||||
|
EvqVaryingOut, // pipeline output, read/write, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
|
||||||
|
EvqUniform, // read only, shared with app
|
||||||
|
EvqBuffer, // read/write, shared with app
|
||||||
|
EvqShared, // compute shader's read/write 'shared' qualifier
|
||||||
|
|
||||||
|
EvqPayload,
|
||||||
|
EvqPayloadIn,
|
||||||
|
EvqHitAttr,
|
||||||
|
EvqCallableData,
|
||||||
|
EvqCallableDataIn,
|
||||||
|
|
||||||
|
// parameters
|
||||||
|
EvqIn, // also, for 'in' in the grammar before we know if it's a pipeline input or an 'in' parameter
|
||||||
|
EvqOut, // also, for 'out' in the grammar before we know if it's a pipeline output or an 'out' parameter
|
||||||
|
EvqInOut,
|
||||||
|
EvqConstReadOnly, // input; also other read-only types having neither a constant value nor constant-value semantics
|
||||||
|
|
||||||
|
// built-ins read by vertex shader
|
||||||
|
EvqVertexId,
|
||||||
|
EvqInstanceId,
|
||||||
|
|
||||||
|
// built-ins written by vertex shader
|
||||||
|
EvqPosition,
|
||||||
|
EvqPointSize,
|
||||||
|
EvqClipVertex,
|
||||||
|
|
||||||
|
// built-ins read by fragment shader
|
||||||
|
EvqFace,
|
||||||
|
EvqFragCoord,
|
||||||
|
EvqPointCoord,
|
||||||
|
|
||||||
|
// built-ins written by fragment shader
|
||||||
|
EvqFragColor,
|
||||||
|
EvqFragDepth,
|
||||||
|
|
||||||
|
// end of list
|
||||||
|
EvqLast
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Subcategories of the TStorageQualifier, simply to give a direct mapping
|
||||||
|
// between built-in variable names and an numerical value (the enum).
|
||||||
|
//
|
||||||
|
// For backward compatibility, there is some redundancy between the
|
||||||
|
// TStorageQualifier and these. Existing members should both be maintained accurately.
|
||||||
|
// However, any new built-in variable (and any existing non-redundant one)
|
||||||
|
// must follow the pattern that the specific built-in is here, and only its
|
||||||
|
// general qualifier is in TStorageQualifier.
|
||||||
|
//
|
||||||
|
// Something like gl_Position, which is sometimes 'in' and sometimes 'out'
|
||||||
|
// shows up as two different built-in variables in a single stage, but
|
||||||
|
// only has a single enum in TBuiltInVariable, so both the
|
||||||
|
// TStorageQualifier and the TBuitinVariable are needed to distinguish
|
||||||
|
// between them.
|
||||||
|
//
|
||||||
|
enum TBuiltInVariable {
|
||||||
|
EbvNone,
|
||||||
|
EbvNumWorkGroups,
|
||||||
|
EbvWorkGroupSize,
|
||||||
|
EbvWorkGroupId,
|
||||||
|
EbvLocalInvocationId,
|
||||||
|
EbvGlobalInvocationId,
|
||||||
|
EbvLocalInvocationIndex,
|
||||||
|
EbvNumSubgroups,
|
||||||
|
EbvSubgroupID,
|
||||||
|
EbvSubGroupSize,
|
||||||
|
EbvSubGroupInvocation,
|
||||||
|
EbvSubGroupEqMask,
|
||||||
|
EbvSubGroupGeMask,
|
||||||
|
EbvSubGroupGtMask,
|
||||||
|
EbvSubGroupLeMask,
|
||||||
|
EbvSubGroupLtMask,
|
||||||
|
EbvSubgroupSize2,
|
||||||
|
EbvSubgroupInvocation2,
|
||||||
|
EbvSubgroupEqMask2,
|
||||||
|
EbvSubgroupGeMask2,
|
||||||
|
EbvSubgroupGtMask2,
|
||||||
|
EbvSubgroupLeMask2,
|
||||||
|
EbvSubgroupLtMask2,
|
||||||
|
EbvVertexId,
|
||||||
|
EbvInstanceId,
|
||||||
|
EbvVertexIndex,
|
||||||
|
EbvInstanceIndex,
|
||||||
|
EbvBaseVertex,
|
||||||
|
EbvBaseInstance,
|
||||||
|
EbvDrawId,
|
||||||
|
EbvPosition,
|
||||||
|
EbvPointSize,
|
||||||
|
EbvClipVertex,
|
||||||
|
EbvClipDistance,
|
||||||
|
EbvCullDistance,
|
||||||
|
EbvNormal,
|
||||||
|
EbvVertex,
|
||||||
|
EbvMultiTexCoord0,
|
||||||
|
EbvMultiTexCoord1,
|
||||||
|
EbvMultiTexCoord2,
|
||||||
|
EbvMultiTexCoord3,
|
||||||
|
EbvMultiTexCoord4,
|
||||||
|
EbvMultiTexCoord5,
|
||||||
|
EbvMultiTexCoord6,
|
||||||
|
EbvMultiTexCoord7,
|
||||||
|
EbvFrontColor,
|
||||||
|
EbvBackColor,
|
||||||
|
EbvFrontSecondaryColor,
|
||||||
|
EbvBackSecondaryColor,
|
||||||
|
EbvTexCoord,
|
||||||
|
EbvFogFragCoord,
|
||||||
|
EbvInvocationId,
|
||||||
|
EbvPrimitiveId,
|
||||||
|
EbvLayer,
|
||||||
|
EbvViewportIndex,
|
||||||
|
EbvPatchVertices,
|
||||||
|
EbvTessLevelOuter,
|
||||||
|
EbvTessLevelInner,
|
||||||
|
EbvBoundingBox,
|
||||||
|
EbvTessCoord,
|
||||||
|
EbvColor,
|
||||||
|
EbvSecondaryColor,
|
||||||
|
EbvFace,
|
||||||
|
EbvFragCoord,
|
||||||
|
EbvPointCoord,
|
||||||
|
EbvFragColor,
|
||||||
|
EbvFragData,
|
||||||
|
EbvFragDepth,
|
||||||
|
EbvFragStencilRef,
|
||||||
|
EbvSampleId,
|
||||||
|
EbvSamplePosition,
|
||||||
|
EbvSampleMask,
|
||||||
|
EbvHelperInvocation,
|
||||||
|
|
||||||
|
EbvBaryCoordNoPersp,
|
||||||
|
EbvBaryCoordNoPerspCentroid,
|
||||||
|
EbvBaryCoordNoPerspSample,
|
||||||
|
EbvBaryCoordSmooth,
|
||||||
|
EbvBaryCoordSmoothCentroid,
|
||||||
|
EbvBaryCoordSmoothSample,
|
||||||
|
EbvBaryCoordPullModel,
|
||||||
|
|
||||||
|
EbvViewIndex,
|
||||||
|
EbvDeviceIndex,
|
||||||
|
|
||||||
|
EbvFragSizeEXT,
|
||||||
|
EbvFragInvocationCountEXT,
|
||||||
|
|
||||||
|
EbvSecondaryFragDataEXT,
|
||||||
|
EbvSecondaryFragColorEXT,
|
||||||
|
|
||||||
|
EbvViewportMaskNV,
|
||||||
|
EbvSecondaryPositionNV,
|
||||||
|
EbvSecondaryViewportMaskNV,
|
||||||
|
EbvPositionPerViewNV,
|
||||||
|
EbvViewportMaskPerViewNV,
|
||||||
|
EbvFragFullyCoveredNV,
|
||||||
|
EbvFragmentSizeNV,
|
||||||
|
EbvInvocationsPerPixelNV,
|
||||||
|
// ray tracing
|
||||||
|
EbvLaunchId,
|
||||||
|
EbvLaunchSize,
|
||||||
|
EbvInstanceCustomIndex,
|
||||||
|
EbvGeometryIndex,
|
||||||
|
EbvWorldRayOrigin,
|
||||||
|
EbvWorldRayDirection,
|
||||||
|
EbvObjectRayOrigin,
|
||||||
|
EbvObjectRayDirection,
|
||||||
|
EbvRayTmin,
|
||||||
|
EbvRayTmax,
|
||||||
|
EbvHitT,
|
||||||
|
EbvHitKind,
|
||||||
|
EbvObjectToWorld,
|
||||||
|
EbvObjectToWorld3x4,
|
||||||
|
EbvWorldToObject,
|
||||||
|
EbvWorldToObject3x4,
|
||||||
|
EbvIncomingRayFlags,
|
||||||
|
// barycentrics
|
||||||
|
EbvBaryCoordNV,
|
||||||
|
EbvBaryCoordNoPerspNV,
|
||||||
|
// mesh shaders
|
||||||
|
EbvTaskCountNV,
|
||||||
|
EbvPrimitiveCountNV,
|
||||||
|
EbvPrimitiveIndicesNV,
|
||||||
|
EbvClipDistancePerViewNV,
|
||||||
|
EbvCullDistancePerViewNV,
|
||||||
|
EbvLayerPerViewNV,
|
||||||
|
EbvMeshViewCountNV,
|
||||||
|
EbvMeshViewIndicesNV,
|
||||||
|
|
||||||
|
// sm builtins
|
||||||
|
EbvWarpsPerSM,
|
||||||
|
EbvSMCount,
|
||||||
|
EbvWarpID,
|
||||||
|
EbvSMID,
|
||||||
|
|
||||||
|
// HLSL built-ins that live only temporarily, until they get remapped
|
||||||
|
// to one of the above.
|
||||||
|
EbvFragDepthGreater,
|
||||||
|
EbvFragDepthLesser,
|
||||||
|
EbvGsOutputStream,
|
||||||
|
EbvOutputPatch,
|
||||||
|
EbvInputPatch,
|
||||||
|
|
||||||
|
// structbuffer types
|
||||||
|
EbvAppendConsume, // no need to differentiate append and consume
|
||||||
|
EbvRWStructuredBuffer,
|
||||||
|
EbvStructuredBuffer,
|
||||||
|
EbvByteAddressBuffer,
|
||||||
|
EbvRWByteAddressBuffer,
|
||||||
|
|
||||||
|
EbvLast
|
||||||
|
};
|
||||||
|
|
||||||
|
// In this enum, order matters; users can assume higher precision is a bigger value
|
||||||
|
// and EpqNone is 0.
|
||||||
|
enum TPrecisionQualifier {
|
||||||
|
EpqNone = 0,
|
||||||
|
EpqLow,
|
||||||
|
EpqMedium,
|
||||||
|
EpqHigh
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef GLSLANG_WEB
|
||||||
|
__inline const char* GetStorageQualifierString(TStorageQualifier q) { return ""; }
|
||||||
|
__inline const char* GetPrecisionQualifierString(TPrecisionQualifier p) { return ""; }
|
||||||
|
#else
|
||||||
|
// These will show up in error messages
|
||||||
|
__inline const char* GetStorageQualifierString(TStorageQualifier q)
|
||||||
|
{
|
||||||
|
switch (q) {
|
||||||
|
case EvqTemporary: return "temp"; break;
|
||||||
|
case EvqGlobal: return "global"; break;
|
||||||
|
case EvqConst: return "const"; break;
|
||||||
|
case EvqConstReadOnly: return "const (read only)"; break;
|
||||||
|
case EvqVaryingIn: return "in"; break;
|
||||||
|
case EvqVaryingOut: return "out"; break;
|
||||||
|
case EvqUniform: return "uniform"; break;
|
||||||
|
case EvqBuffer: return "buffer"; break;
|
||||||
|
case EvqShared: return "shared"; break;
|
||||||
|
case EvqIn: return "in"; break;
|
||||||
|
case EvqOut: return "out"; break;
|
||||||
|
case EvqInOut: return "inout"; break;
|
||||||
|
case EvqVertexId: return "gl_VertexId"; break;
|
||||||
|
case EvqInstanceId: return "gl_InstanceId"; break;
|
||||||
|
case EvqPosition: return "gl_Position"; break;
|
||||||
|
case EvqPointSize: return "gl_PointSize"; break;
|
||||||
|
case EvqClipVertex: return "gl_ClipVertex"; break;
|
||||||
|
case EvqFace: return "gl_FrontFacing"; break;
|
||||||
|
case EvqFragCoord: return "gl_FragCoord"; break;
|
||||||
|
case EvqPointCoord: return "gl_PointCoord"; break;
|
||||||
|
case EvqFragColor: return "fragColor"; break;
|
||||||
|
case EvqFragDepth: return "gl_FragDepth"; break;
|
||||||
|
case EvqPayload: return "rayPayloadNV"; break;
|
||||||
|
case EvqPayloadIn: return "rayPayloadInNV"; break;
|
||||||
|
case EvqHitAttr: return "hitAttributeNV"; break;
|
||||||
|
case EvqCallableData: return "callableDataNV"; break;
|
||||||
|
case EvqCallableDataIn: return "callableDataInNV"; break;
|
||||||
|
default: return "unknown qualifier";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline const char* GetBuiltInVariableString(TBuiltInVariable v)
|
||||||
|
{
|
||||||
|
switch (v) {
|
||||||
|
case EbvNone: return "";
|
||||||
|
case EbvNumWorkGroups: return "NumWorkGroups";
|
||||||
|
case EbvWorkGroupSize: return "WorkGroupSize";
|
||||||
|
case EbvWorkGroupId: return "WorkGroupID";
|
||||||
|
case EbvLocalInvocationId: return "LocalInvocationID";
|
||||||
|
case EbvGlobalInvocationId: return "GlobalInvocationID";
|
||||||
|
case EbvLocalInvocationIndex: return "LocalInvocationIndex";
|
||||||
|
case EbvNumSubgroups: return "NumSubgroups";
|
||||||
|
case EbvSubgroupID: return "SubgroupID";
|
||||||
|
case EbvSubGroupSize: return "SubGroupSize";
|
||||||
|
case EbvSubGroupInvocation: return "SubGroupInvocation";
|
||||||
|
case EbvSubGroupEqMask: return "SubGroupEqMask";
|
||||||
|
case EbvSubGroupGeMask: return "SubGroupGeMask";
|
||||||
|
case EbvSubGroupGtMask: return "SubGroupGtMask";
|
||||||
|
case EbvSubGroupLeMask: return "SubGroupLeMask";
|
||||||
|
case EbvSubGroupLtMask: return "SubGroupLtMask";
|
||||||
|
case EbvSubgroupSize2: return "SubgroupSize";
|
||||||
|
case EbvSubgroupInvocation2: return "SubgroupInvocationID";
|
||||||
|
case EbvSubgroupEqMask2: return "SubgroupEqMask";
|
||||||
|
case EbvSubgroupGeMask2: return "SubgroupGeMask";
|
||||||
|
case EbvSubgroupGtMask2: return "SubgroupGtMask";
|
||||||
|
case EbvSubgroupLeMask2: return "SubgroupLeMask";
|
||||||
|
case EbvSubgroupLtMask2: return "SubgroupLtMask";
|
||||||
|
case EbvVertexId: return "VertexId";
|
||||||
|
case EbvInstanceId: return "InstanceId";
|
||||||
|
case EbvVertexIndex: return "VertexIndex";
|
||||||
|
case EbvInstanceIndex: return "InstanceIndex";
|
||||||
|
case EbvBaseVertex: return "BaseVertex";
|
||||||
|
case EbvBaseInstance: return "BaseInstance";
|
||||||
|
case EbvDrawId: return "DrawId";
|
||||||
|
case EbvPosition: return "Position";
|
||||||
|
case EbvPointSize: return "PointSize";
|
||||||
|
case EbvClipVertex: return "ClipVertex";
|
||||||
|
case EbvClipDistance: return "ClipDistance";
|
||||||
|
case EbvCullDistance: return "CullDistance";
|
||||||
|
case EbvNormal: return "Normal";
|
||||||
|
case EbvVertex: return "Vertex";
|
||||||
|
case EbvMultiTexCoord0: return "MultiTexCoord0";
|
||||||
|
case EbvMultiTexCoord1: return "MultiTexCoord1";
|
||||||
|
case EbvMultiTexCoord2: return "MultiTexCoord2";
|
||||||
|
case EbvMultiTexCoord3: return "MultiTexCoord3";
|
||||||
|
case EbvMultiTexCoord4: return "MultiTexCoord4";
|
||||||
|
case EbvMultiTexCoord5: return "MultiTexCoord5";
|
||||||
|
case EbvMultiTexCoord6: return "MultiTexCoord6";
|
||||||
|
case EbvMultiTexCoord7: return "MultiTexCoord7";
|
||||||
|
case EbvFrontColor: return "FrontColor";
|
||||||
|
case EbvBackColor: return "BackColor";
|
||||||
|
case EbvFrontSecondaryColor: return "FrontSecondaryColor";
|
||||||
|
case EbvBackSecondaryColor: return "BackSecondaryColor";
|
||||||
|
case EbvTexCoord: return "TexCoord";
|
||||||
|
case EbvFogFragCoord: return "FogFragCoord";
|
||||||
|
case EbvInvocationId: return "InvocationID";
|
||||||
|
case EbvPrimitiveId: return "PrimitiveID";
|
||||||
|
case EbvLayer: return "Layer";
|
||||||
|
case EbvViewportIndex: return "ViewportIndex";
|
||||||
|
case EbvPatchVertices: return "PatchVertices";
|
||||||
|
case EbvTessLevelOuter: return "TessLevelOuter";
|
||||||
|
case EbvTessLevelInner: return "TessLevelInner";
|
||||||
|
case EbvBoundingBox: return "BoundingBox";
|
||||||
|
case EbvTessCoord: return "TessCoord";
|
||||||
|
case EbvColor: return "Color";
|
||||||
|
case EbvSecondaryColor: return "SecondaryColor";
|
||||||
|
case EbvFace: return "Face";
|
||||||
|
case EbvFragCoord: return "FragCoord";
|
||||||
|
case EbvPointCoord: return "PointCoord";
|
||||||
|
case EbvFragColor: return "FragColor";
|
||||||
|
case EbvFragData: return "FragData";
|
||||||
|
case EbvFragDepth: return "FragDepth";
|
||||||
|
case EbvFragStencilRef: return "FragStencilRef";
|
||||||
|
case EbvSampleId: return "SampleId";
|
||||||
|
case EbvSamplePosition: return "SamplePosition";
|
||||||
|
case EbvSampleMask: return "SampleMaskIn";
|
||||||
|
case EbvHelperInvocation: return "HelperInvocation";
|
||||||
|
|
||||||
|
case EbvBaryCoordNoPersp: return "BaryCoordNoPersp";
|
||||||
|
case EbvBaryCoordNoPerspCentroid: return "BaryCoordNoPerspCentroid";
|
||||||
|
case EbvBaryCoordNoPerspSample: return "BaryCoordNoPerspSample";
|
||||||
|
case EbvBaryCoordSmooth: return "BaryCoordSmooth";
|
||||||
|
case EbvBaryCoordSmoothCentroid: return "BaryCoordSmoothCentroid";
|
||||||
|
case EbvBaryCoordSmoothSample: return "BaryCoordSmoothSample";
|
||||||
|
case EbvBaryCoordPullModel: return "BaryCoordPullModel";
|
||||||
|
|
||||||
|
case EbvViewIndex: return "ViewIndex";
|
||||||
|
case EbvDeviceIndex: return "DeviceIndex";
|
||||||
|
|
||||||
|
case EbvFragSizeEXT: return "FragSizeEXT";
|
||||||
|
case EbvFragInvocationCountEXT: return "FragInvocationCountEXT";
|
||||||
|
|
||||||
|
case EbvSecondaryFragDataEXT: return "SecondaryFragDataEXT";
|
||||||
|
case EbvSecondaryFragColorEXT: return "SecondaryFragColorEXT";
|
||||||
|
|
||||||
|
case EbvViewportMaskNV: return "ViewportMaskNV";
|
||||||
|
case EbvSecondaryPositionNV: return "SecondaryPositionNV";
|
||||||
|
case EbvSecondaryViewportMaskNV: return "SecondaryViewportMaskNV";
|
||||||
|
case EbvPositionPerViewNV: return "PositionPerViewNV";
|
||||||
|
case EbvViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
|
||||||
|
case EbvFragFullyCoveredNV: return "FragFullyCoveredNV";
|
||||||
|
case EbvFragmentSizeNV: return "FragmentSizeNV";
|
||||||
|
case EbvInvocationsPerPixelNV: return "InvocationsPerPixelNV";
|
||||||
|
case EbvLaunchId: return "LaunchIdNV";
|
||||||
|
case EbvLaunchSize: return "LaunchSizeNV";
|
||||||
|
case EbvInstanceCustomIndex: return "InstanceCustomIndexNV";
|
||||||
|
case EbvGeometryIndex: return "GeometryIndexEXT";
|
||||||
|
case EbvWorldRayOrigin: return "WorldRayOriginNV";
|
||||||
|
case EbvWorldRayDirection: return "WorldRayDirectionNV";
|
||||||
|
case EbvObjectRayOrigin: return "ObjectRayOriginNV";
|
||||||
|
case EbvObjectRayDirection: return "ObjectRayDirectionNV";
|
||||||
|
case EbvRayTmin: return "ObjectRayTminNV";
|
||||||
|
case EbvRayTmax: return "ObjectRayTmaxNV";
|
||||||
|
case EbvHitT: return "HitTNV";
|
||||||
|
case EbvHitKind: return "HitKindNV";
|
||||||
|
case EbvIncomingRayFlags: return "IncomingRayFlagsNV";
|
||||||
|
case EbvObjectToWorld: return "ObjectToWorldNV";
|
||||||
|
case EbvWorldToObject: return "WorldToObjectNV";
|
||||||
|
|
||||||
|
case EbvBaryCoordNV: return "BaryCoordNV";
|
||||||
|
case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
|
||||||
|
|
||||||
|
case EbvTaskCountNV: return "TaskCountNV";
|
||||||
|
case EbvPrimitiveCountNV: return "PrimitiveCountNV";
|
||||||
|
case EbvPrimitiveIndicesNV: return "PrimitiveIndicesNV";
|
||||||
|
case EbvClipDistancePerViewNV: return "ClipDistancePerViewNV";
|
||||||
|
case EbvCullDistancePerViewNV: return "CullDistancePerViewNV";
|
||||||
|
case EbvLayerPerViewNV: return "LayerPerViewNV";
|
||||||
|
case EbvMeshViewCountNV: return "MeshViewCountNV";
|
||||||
|
case EbvMeshViewIndicesNV: return "MeshViewIndicesNV";
|
||||||
|
|
||||||
|
case EbvWarpsPerSM: return "WarpsPerSMNV";
|
||||||
|
case EbvSMCount: return "SMCountNV";
|
||||||
|
case EbvWarpID: return "WarpIDNV";
|
||||||
|
case EbvSMID: return "SMIDNV";
|
||||||
|
|
||||||
|
default: return "unknown built-in variable";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline const char* GetPrecisionQualifierString(TPrecisionQualifier p)
|
||||||
|
{
|
||||||
|
switch (p) {
|
||||||
|
case EpqNone: return ""; break;
|
||||||
|
case EpqLow: return "lowp"; break;
|
||||||
|
case EpqMedium: return "mediump"; break;
|
||||||
|
case EpqHigh: return "highp"; break;
|
||||||
|
default: return "unknown precision qualifier";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__inline bool isTypeSignedInt(TBasicType type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt8:
|
||||||
|
case EbtInt16:
|
||||||
|
case EbtInt:
|
||||||
|
case EbtInt64:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline bool isTypeUnsignedInt(TBasicType type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case EbtUint8:
|
||||||
|
case EbtUint16:
|
||||||
|
case EbtUint:
|
||||||
|
case EbtUint64:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline bool isTypeInt(TBasicType type)
|
||||||
|
{
|
||||||
|
return isTypeSignedInt(type) || isTypeUnsignedInt(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline bool isTypeFloat(TBasicType type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case EbtFloat:
|
||||||
|
case EbtDouble:
|
||||||
|
case EbtFloat16:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline int getTypeRank(TBasicType type)
|
||||||
|
{
|
||||||
|
int res = -1;
|
||||||
|
switch(type) {
|
||||||
|
case EbtInt8:
|
||||||
|
case EbtUint8:
|
||||||
|
res = 0;
|
||||||
|
break;
|
||||||
|
case EbtInt16:
|
||||||
|
case EbtUint16:
|
||||||
|
res = 1;
|
||||||
|
break;
|
||||||
|
case EbtInt:
|
||||||
|
case EbtUint:
|
||||||
|
res = 2;
|
||||||
|
break;
|
||||||
|
case EbtInt64:
|
||||||
|
case EbtUint64:
|
||||||
|
res = 3;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _BASICTYPES_INCLUDED_
|
||||||
|
|
@ -0,0 +1,292 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _COMMON_INCLUDED_
|
||||||
|
#define _COMMON_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__ANDROID__) || (defined(_MSC_VER) && _MSC_VER < 1700)
|
||||||
|
#include <sstream>
|
||||||
|
namespace std {
|
||||||
|
template<typename T>
|
||||||
|
std::string to_string(const T& val) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << val;
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) || defined MINGW_HAS_SECURE_API
|
||||||
|
#include <basetsd.h>
|
||||||
|
#ifndef snprintf
|
||||||
|
#define snprintf sprintf_s
|
||||||
|
#endif
|
||||||
|
#define safe_vsprintf(buf,max,format,args) vsnprintf_s((buf), (max), (max), (format), (args))
|
||||||
|
#elif defined (solaris)
|
||||||
|
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
|
||||||
|
#include <sys/int_types.h>
|
||||||
|
#define UINT_PTR uintptr_t
|
||||||
|
#else
|
||||||
|
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
|
||||||
|
#include <stdint.h>
|
||||||
|
#define UINT_PTR uintptr_t
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||||
|
#include <stdlib.h>
|
||||||
|
inline long long int strtoll (const char* str, char** endptr, int base)
|
||||||
|
{
|
||||||
|
return _strtoi64(str, endptr, base);
|
||||||
|
}
|
||||||
|
inline unsigned long long int strtoull (const char* str, char** endptr, int base)
|
||||||
|
{
|
||||||
|
return _strtoui64(str, endptr, base);
|
||||||
|
}
|
||||||
|
inline long long int atoll (const char* str)
|
||||||
|
{
|
||||||
|
return strtoll(str, NULL, 10);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define strdup _strdup
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* windows only pragma */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable : 4786) // Don't warn about too long identifiers
|
||||||
|
#pragma warning(disable : 4514) // unused inline method
|
||||||
|
#pragma warning(disable : 4201) // nameless union
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <list>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "PoolAlloc.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
|
||||||
|
//
|
||||||
|
#define POOL_ALLOCATOR_NEW_DELETE(A) \
|
||||||
|
void* operator new(size_t s) { return (A).allocate(s); } \
|
||||||
|
void* operator new(size_t, void *_Where) { return (_Where); } \
|
||||||
|
void operator delete(void*) { } \
|
||||||
|
void operator delete(void *, void *) { } \
|
||||||
|
void* operator new[](size_t s) { return (A).allocate(s); } \
|
||||||
|
void* operator new[](size_t, void *_Where) { return (_Where); } \
|
||||||
|
void operator delete[](void*) { } \
|
||||||
|
void operator delete[](void *, void *) { }
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Pool version of string.
|
||||||
|
//
|
||||||
|
typedef pool_allocator<char> TStringAllocator;
|
||||||
|
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
// Repackage the std::hash for use by unordered map/set with a TString key.
|
||||||
|
namespace std {
|
||||||
|
|
||||||
|
template<> struct hash<glslang::TString> {
|
||||||
|
std::size_t operator()(const glslang::TString& s) const
|
||||||
|
{
|
||||||
|
const unsigned _FNV_offset_basis = 2166136261U;
|
||||||
|
const unsigned _FNV_prime = 16777619U;
|
||||||
|
unsigned _Val = _FNV_offset_basis;
|
||||||
|
size_t _Count = s.size();
|
||||||
|
const char* _First = s.c_str();
|
||||||
|
for (size_t _Next = 0; _Next < _Count; ++_Next)
|
||||||
|
{
|
||||||
|
_Val ^= (unsigned)_First[_Next];
|
||||||
|
_Val *= _FNV_prime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _Val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
inline TString* NewPoolTString(const char* s)
|
||||||
|
{
|
||||||
|
void* memory = GetThreadPoolAllocator().allocate(sizeof(TString));
|
||||||
|
return new(memory) TString(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> inline T* NewPoolObject(T*)
|
||||||
|
{
|
||||||
|
return new(GetThreadPoolAllocator().allocate(sizeof(T))) T;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> inline T* NewPoolObject(T, int instances)
|
||||||
|
{
|
||||||
|
return new(GetThreadPoolAllocator().allocate(instances * sizeof(T))) T[instances];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Pool allocator versions of vectors, lists, and maps
|
||||||
|
//
|
||||||
|
template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
|
||||||
|
typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
|
||||||
|
TVector() : std::vector<T, pool_allocator<T> >() {}
|
||||||
|
TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
|
||||||
|
TVector(size_type i) : std::vector<T, pool_allocator<T> >(i) {}
|
||||||
|
TVector(size_type i, const T& val) : std::vector<T, pool_allocator<T> >(i, val) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class TList : public std::list<T, pool_allocator<T> > {
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class D, class CMP = std::less<K> >
|
||||||
|
class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<K const, D> > > {
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class D, class HASH = std::hash<K>, class PRED = std::equal_to<K> >
|
||||||
|
class TUnorderedMap : public std::unordered_map<K, D, HASH, PRED, pool_allocator<std::pair<K const, D> > > {
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Persistent string memory. Should only be used for strings that survive
|
||||||
|
// across compiles/links.
|
||||||
|
//
|
||||||
|
typedef std::basic_string<char> TPersistString;
|
||||||
|
|
||||||
|
//
|
||||||
|
// templatized min and max functions.
|
||||||
|
//
|
||||||
|
template <class T> T Min(const T a, const T b) { return a < b ? a : b; }
|
||||||
|
template <class T> T Max(const T a, const T b) { return a > b ? a : b; }
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create a TString object from an integer.
|
||||||
|
//
|
||||||
|
#if defined _MSC_VER || defined MINGW_HAS_SECURE_API
|
||||||
|
inline const TString String(const int i, const int base = 10)
|
||||||
|
{
|
||||||
|
char text[16]; // 32 bit ints are at most 10 digits in base 10
|
||||||
|
_itoa_s(i, text, sizeof(text), base);
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
inline const TString String(const int i, const int /*base*/ = 10)
|
||||||
|
{
|
||||||
|
char text[16]; // 32 bit ints are at most 10 digits in base 10
|
||||||
|
|
||||||
|
// we assume base 10 for all cases
|
||||||
|
snprintf(text, sizeof(text), "%d", i);
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct TSourceLoc {
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
name = nullptr; string = 0; line = 0; column = 0;
|
||||||
|
}
|
||||||
|
void init(int stringNum) { init(); string = stringNum; }
|
||||||
|
// Returns the name if it exists. Otherwise, returns the string number.
|
||||||
|
std::string getStringNameOrNum(bool quoteStringName = true) const
|
||||||
|
{
|
||||||
|
if (name != nullptr) {
|
||||||
|
TString qstr = quoteStringName ? ("\"" + *name + "\"") : *name;
|
||||||
|
std::string ret_str(qstr.c_str());
|
||||||
|
return ret_str;
|
||||||
|
}
|
||||||
|
return std::to_string((long long)string);
|
||||||
|
}
|
||||||
|
const char* getFilename() const
|
||||||
|
{
|
||||||
|
if (name == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
return name->c_str();
|
||||||
|
}
|
||||||
|
const char* getFilenameStr() const { return name == nullptr ? "" : name->c_str(); }
|
||||||
|
TString* name; // descriptive name for this string, when a textual name is available, otherwise nullptr
|
||||||
|
int string;
|
||||||
|
int line;
|
||||||
|
int column;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TPragmaTable : public TMap<TString, TString> {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
};
|
||||||
|
|
||||||
|
const int MaxTokenLength = 1024;
|
||||||
|
|
||||||
|
template <class T> bool IsPow2(T powerOf2)
|
||||||
|
{
|
||||||
|
if (powerOf2 <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return (powerOf2 & (powerOf2 - 1)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Round number up to a multiple of the given powerOf2, which is not
|
||||||
|
// a power, just a number that must be a power of 2.
|
||||||
|
template <class T> void RoundToPow2(T& number, int powerOf2)
|
||||||
|
{
|
||||||
|
assert(IsPow2(powerOf2));
|
||||||
|
number = (number + powerOf2 - 1) & ~(powerOf2 - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T> bool IsMultipleOfPow2(T number, int powerOf2)
|
||||||
|
{
|
||||||
|
assert(IsPow2(powerOf2));
|
||||||
|
return ! (number & (powerOf2 - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _COMMON_INCLUDED_
|
||||||
|
|
@ -0,0 +1,974 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2013 LunarG, Inc.
|
||||||
|
// Copyright (C) 2017 ARM Limited.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _CONSTANT_UNION_INCLUDED_
|
||||||
|
#define _CONSTANT_UNION_INCLUDED_
|
||||||
|
|
||||||
|
#include "../Include/Common.h"
|
||||||
|
#include "../Include/BaseTypes.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
class TConstUnion {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
|
||||||
|
TConstUnion() : iConst(0), type(EbtInt) { }
|
||||||
|
|
||||||
|
void setI8Const(signed char i)
|
||||||
|
{
|
||||||
|
i8Const = i;
|
||||||
|
type = EbtInt8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setU8Const(unsigned char u)
|
||||||
|
{
|
||||||
|
u8Const = u;
|
||||||
|
type = EbtUint8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setI16Const(signed short i)
|
||||||
|
{
|
||||||
|
i16Const = i;
|
||||||
|
type = EbtInt16;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setU16Const(unsigned short u)
|
||||||
|
{
|
||||||
|
u16Const = u;
|
||||||
|
type = EbtUint16;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIConst(int i)
|
||||||
|
{
|
||||||
|
iConst = i;
|
||||||
|
type = EbtInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUConst(unsigned int u)
|
||||||
|
{
|
||||||
|
uConst = u;
|
||||||
|
type = EbtUint;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setI64Const(long long i64)
|
||||||
|
{
|
||||||
|
i64Const = i64;
|
||||||
|
type = EbtInt64;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setU64Const(unsigned long long u64)
|
||||||
|
{
|
||||||
|
u64Const = u64;
|
||||||
|
type = EbtUint64;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDConst(double d)
|
||||||
|
{
|
||||||
|
dConst = d;
|
||||||
|
type = EbtDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBConst(bool b)
|
||||||
|
{
|
||||||
|
bConst = b;
|
||||||
|
type = EbtBool;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSConst(const TString* s)
|
||||||
|
{
|
||||||
|
sConst = s;
|
||||||
|
type = EbtString;
|
||||||
|
}
|
||||||
|
|
||||||
|
signed char getI8Const() const { return i8Const; }
|
||||||
|
unsigned char getU8Const() const { return u8Const; }
|
||||||
|
signed short getI16Const() const { return i16Const; }
|
||||||
|
unsigned short getU16Const() const { return u16Const; }
|
||||||
|
int getIConst() const { return iConst; }
|
||||||
|
unsigned int getUConst() const { return uConst; }
|
||||||
|
long long getI64Const() const { return i64Const; }
|
||||||
|
unsigned long long getU64Const() const { return u64Const; }
|
||||||
|
double getDConst() const { return dConst; }
|
||||||
|
bool getBConst() const { return bConst; }
|
||||||
|
const TString* getSConst() const { return sConst; }
|
||||||
|
|
||||||
|
bool operator==(const signed char i) const
|
||||||
|
{
|
||||||
|
if (i == i8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const unsigned char u) const
|
||||||
|
{
|
||||||
|
if (u == u8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const signed short i) const
|
||||||
|
{
|
||||||
|
if (i == i16Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const unsigned short u) const
|
||||||
|
{
|
||||||
|
if (u == u16Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const int i) const
|
||||||
|
{
|
||||||
|
if (i == iConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const unsigned int u) const
|
||||||
|
{
|
||||||
|
if (u == uConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const long long i64) const
|
||||||
|
{
|
||||||
|
if (i64 == i64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const unsigned long long u64) const
|
||||||
|
{
|
||||||
|
if (u64 == u64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const double d) const
|
||||||
|
{
|
||||||
|
if (d == dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const bool b) const
|
||||||
|
{
|
||||||
|
if (b == bConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
if (constant.type != type)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt:
|
||||||
|
if (constant.iConst == iConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtUint:
|
||||||
|
if (constant.uConst == uConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtBool:
|
||||||
|
if (constant.bConst == bConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtDouble:
|
||||||
|
if (constant.dConst == dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt16:
|
||||||
|
if (constant.i16Const == i16Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtUint16:
|
||||||
|
if (constant.u16Const == u16Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtInt8:
|
||||||
|
if (constant.i8Const == i8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtUint8:
|
||||||
|
if (constant.u8Const == u8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtInt64:
|
||||||
|
if (constant.i64Const == i64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtUint64:
|
||||||
|
if (constant.u64Const == u64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const signed char i) const
|
||||||
|
{
|
||||||
|
return !operator==(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const unsigned char u) const
|
||||||
|
{
|
||||||
|
return !operator==(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const signed short i) const
|
||||||
|
{
|
||||||
|
return !operator==(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const unsigned short u) const
|
||||||
|
{
|
||||||
|
return !operator==(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const int i) const
|
||||||
|
{
|
||||||
|
return !operator==(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const unsigned int u) const
|
||||||
|
{
|
||||||
|
return !operator==(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const long long i) const
|
||||||
|
{
|
||||||
|
return !operator==(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const unsigned long long u) const
|
||||||
|
{
|
||||||
|
return !operator==(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const float f) const
|
||||||
|
{
|
||||||
|
return !operator==(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const bool b) const
|
||||||
|
{
|
||||||
|
return !operator==(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
return !operator==(constant);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt:
|
||||||
|
if (iConst > constant.iConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint:
|
||||||
|
if (uConst > constant.uConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtDouble:
|
||||||
|
if (dConst > constant.dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8:
|
||||||
|
if (i8Const > constant.i8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint8:
|
||||||
|
if (u8Const > constant.u8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtInt16:
|
||||||
|
if (i16Const > constant.i16Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint16:
|
||||||
|
if (u16Const > constant.u16Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtInt64:
|
||||||
|
if (i64Const > constant.i64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint64:
|
||||||
|
if (u64Const > constant.u64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
assert(false && "Default missing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8:
|
||||||
|
if (i8Const < constant.i8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint8:
|
||||||
|
if (u8Const < constant.u8Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtInt16:
|
||||||
|
if (i16Const < constant.i16Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint16:
|
||||||
|
if (u16Const < constant.u16Const)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
case EbtInt64:
|
||||||
|
if (i64Const < constant.i64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint64:
|
||||||
|
if (u64Const < constant.u64Const)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
case EbtDouble:
|
||||||
|
if (dConst < constant.dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtInt:
|
||||||
|
if (iConst < constant.iConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtUint:
|
||||||
|
if (uConst < constant.uConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
assert(false && "Default missing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator+(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst + constant.uConst); break;
|
||||||
|
case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const + constant.i8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const + constant.i16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const + constant.i64Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const + constant.u8Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const + constant.u16Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const + constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator-(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst - constant.uConst); break;
|
||||||
|
case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const - constant.i8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const - constant.i16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const - constant.i64Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const - constant.u8Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const - constant.u16Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const - constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator*(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst * constant.uConst); break;
|
||||||
|
case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const * constant.i8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const * constant.i16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const * constant.i64Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const * constant.u8Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const * constant.u16Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const * constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator%(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst % constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const % constant.i8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI8Const(i8Const % constant.i16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const % constant.i64Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const % constant.u8Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const % constant.u16Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const % constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator>>(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
switch (type) {
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setI8Const(i8Const >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI8Const(i8Const >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setI8Const(i8Const >> constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setI8Const(i8Const >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setI8Const(i8Const >> constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setI8Const(i8Const >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setI8Const(i8Const >> constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint8:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setU8Const(u8Const >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setU8Const(u8Const >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU8Const(u8Const >> constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setU8Const(u8Const >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setU8Const(u8Const >> constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setU8Const(u8Const >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU8Const(u8Const >> constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtInt16:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setI16Const(i16Const >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setI16Const(i16Const >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setI16Const(i16Const >> constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setI16Const(i16Const >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setI16Const(i16Const >> constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setI16Const(i16Const >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setI16Const(i16Const >> constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint16:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setU16Const(u16Const >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU16Const(u16Const >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setU16Const(u16Const >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const >> constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setU16Const(u16Const >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setU16Const(u16Const >> constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setU16Const(u16Const >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU16Const(u16Const >> constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case EbtInt:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setIConst(iConst >> constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setIConst(iConst >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setIConst(iConst >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setIConst(iConst >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setIConst(iConst >> constant.u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setIConst(iConst >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setIConst(iConst >> constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt: returnValue.setUConst(uConst >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst >> constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setUConst(uConst >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setUConst(uConst >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setUConst(uConst >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setUConst(uConst >> constant.u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setUConst(uConst >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setUConst(uConst >> constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt64:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setI64Const(i64Const >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setI64Const(i64Const >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI64Const(i64Const >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setI64Const(i64Const >> constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setI64Const(i64Const >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setI64Const(i64Const >> constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setI64Const(i64Const >> constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint64:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setU64Const(u64Const >> constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU64Const(u64Const >> constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setU64Const(u64Const >> constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU64Const(u64Const >> constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setU64Const(u64Const >> constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setU64Const(u64Const >> constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setU64Const(u64Const >> constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const >> constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator<<(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
switch (type) {
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setI8Const(i8Const << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI8Const(i8Const << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setI8Const(i8Const << constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setI8Const(i8Const << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setI8Const(i8Const << constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setI8Const(i8Const << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setI8Const(i8Const << constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint8:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setU8Const(u8Const << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setU8Const(u8Const << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU8Const(u8Const << constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setU8Const(u8Const << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setU8Const(u8Const << constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setU8Const(u8Const << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU8Const(u8Const << constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtInt16:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setI16Const(i16Const << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setI16Const(i16Const << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setI16Const(i16Const << constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setI16Const(i16Const << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setI16Const(i16Const << constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setI16Const(i16Const << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setI16Const(i16Const << constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint16:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setU16Const(u16Const << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU16Const(u16Const << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setU16Const(u16Const << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const << constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setU16Const(u16Const << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setU16Const(u16Const << constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setU16Const(u16Const << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU16Const(u16Const << constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtInt64:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setI64Const(i64Const << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setI64Const(i64Const << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI64Const(i64Const << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setI64Const(i64Const << constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setI64Const(i64Const << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setI64Const(i64Const << constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setI64Const(i64Const << constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint64:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt8: returnValue.setU64Const(u64Const << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU64Const(u64Const << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setU64Const(u64Const << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU64Const(u64Const << constant.u16Const); break;
|
||||||
|
case EbtInt: returnValue.setU64Const(u64Const << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setU64Const(u64Const << constant.uConst); break;
|
||||||
|
case EbtInt64: returnValue.setU64Const(u64Const << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const << constant.u64Const); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case EbtInt:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setIConst(iConst << constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setIConst(iConst << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setIConst(iConst << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setIConst(iConst << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setIConst(iConst << constant.u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setIConst(iConst << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setIConst(iConst << constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EbtUint:
|
||||||
|
switch (constant.type) {
|
||||||
|
case EbtInt: returnValue.setUConst(uConst << constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst << constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setUConst(uConst << constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setUConst(uConst << constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setUConst(uConst << constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setUConst(uConst << constant.u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setUConst(uConst << constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setUConst(uConst << constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator&(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst & constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const & constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const & constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const & constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const & constant.u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const & constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const & constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator|(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst | constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const | constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const | constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const | constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const | constant.u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const | constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const | constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator^(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(uConst ^ constant.uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(i8Const ^ constant.i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(u8Const ^ constant.u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(i16Const ^ constant.i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(u16Const ^ constant.u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(i64Const ^ constant.i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(u64Const ^ constant.u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator~() const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
switch (type) {
|
||||||
|
case EbtInt: returnValue.setIConst(~iConst); break;
|
||||||
|
case EbtUint: returnValue.setUConst(~uConst); break;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
case EbtInt8: returnValue.setI8Const(~i8Const); break;
|
||||||
|
case EbtUint8: returnValue.setU8Const(~u8Const); break;
|
||||||
|
case EbtInt16: returnValue.setI16Const(~i16Const); break;
|
||||||
|
case EbtUint16: returnValue.setU16Const(~u16Const); break;
|
||||||
|
case EbtInt64: returnValue.setI64Const(~i64Const); break;
|
||||||
|
case EbtUint64: returnValue.setU64Const(~u64Const); break;
|
||||||
|
#endif
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator&&(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TConstUnion operator||(const TConstUnion& constant) const
|
||||||
|
{
|
||||||
|
TConstUnion returnValue;
|
||||||
|
assert(type == constant.type);
|
||||||
|
switch (type) {
|
||||||
|
case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
|
||||||
|
default: assert(false && "Default missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TBasicType getType() const { return type; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
union {
|
||||||
|
signed char i8Const; // used for i8vec, scalar int8s
|
||||||
|
unsigned char u8Const; // used for u8vec, scalar uint8s
|
||||||
|
signed short i16Const; // used for i16vec, scalar int16s
|
||||||
|
unsigned short u16Const; // used for u16vec, scalar uint16s
|
||||||
|
int iConst; // used for ivec, scalar ints
|
||||||
|
unsigned int uConst; // used for uvec, scalar uints
|
||||||
|
long long i64Const; // used for i64vec, scalar int64s
|
||||||
|
unsigned long long u64Const; // used for u64vec, scalar uint64s
|
||||||
|
bool bConst; // used for bvec, scalar bools
|
||||||
|
double dConst; // used for vec, dvec, mat, dmat, scalar floats and doubles
|
||||||
|
const TString* sConst; // string constant
|
||||||
|
};
|
||||||
|
|
||||||
|
TBasicType type;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Encapsulate having a pointer to an array of TConstUnion,
|
||||||
|
// which only needs to be allocated if its size is going to be
|
||||||
|
// bigger than 0.
|
||||||
|
//
|
||||||
|
// One convenience is being able to use [] to go inside the array, instead
|
||||||
|
// of C++ assuming it as an array of pointers to vectors.
|
||||||
|
//
|
||||||
|
// General usage is that the size is known up front, and it is
|
||||||
|
// created once with the proper size.
|
||||||
|
//
|
||||||
|
class TConstUnionArray {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
|
||||||
|
TConstUnionArray() : unionArray(nullptr) { }
|
||||||
|
virtual ~TConstUnionArray() { }
|
||||||
|
|
||||||
|
explicit TConstUnionArray(int size)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
unionArray = nullptr;
|
||||||
|
else
|
||||||
|
unionArray = new TConstUnionVector(size);
|
||||||
|
}
|
||||||
|
TConstUnionArray(const TConstUnionArray& a) = default;
|
||||||
|
TConstUnionArray(const TConstUnionArray& a, int start, int size)
|
||||||
|
{
|
||||||
|
unionArray = new TConstUnionVector(size);
|
||||||
|
for (int i = 0; i < size; ++i)
|
||||||
|
(*unionArray)[i] = a[start + i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use this constructor for a smear operation
|
||||||
|
TConstUnionArray(int size, const TConstUnion& val)
|
||||||
|
{
|
||||||
|
unionArray = new TConstUnionVector(size, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size() const { return unionArray ? (int)unionArray->size() : 0; }
|
||||||
|
TConstUnion& operator[](size_t index) { return (*unionArray)[index]; }
|
||||||
|
const TConstUnion& operator[](size_t index) const { return (*unionArray)[index]; }
|
||||||
|
bool operator==(const TConstUnionArray& rhs) const
|
||||||
|
{
|
||||||
|
// this includes the case that both are unallocated
|
||||||
|
if (unionArray == rhs.unionArray)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (! unionArray || ! rhs.unionArray)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return *unionArray == *rhs.unionArray;
|
||||||
|
}
|
||||||
|
bool operator!=(const TConstUnionArray& rhs) const { return ! operator==(rhs); }
|
||||||
|
|
||||||
|
double dot(const TConstUnionArray& rhs)
|
||||||
|
{
|
||||||
|
assert(rhs.unionArray->size() == unionArray->size());
|
||||||
|
double sum = 0.0;
|
||||||
|
|
||||||
|
for (size_t comp = 0; comp < unionArray->size(); ++comp)
|
||||||
|
sum += (*this)[comp].getDConst() * rhs[comp].getDConst();
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const { return unionArray == nullptr; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
typedef TVector<TConstUnion> TConstUnionVector;
|
||||||
|
TConstUnionVector* unionArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _CONSTANT_UNION_INCLUDED_
|
||||||
|
|
@ -0,0 +1,144 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _INFOSINK_INCLUDED_
|
||||||
|
#define _INFOSINK_INCLUDED_
|
||||||
|
|
||||||
|
#include "../Include/Common.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// TPrefixType is used to centralize how info log messages start.
|
||||||
|
// See below.
|
||||||
|
//
|
||||||
|
enum TPrefixType {
|
||||||
|
EPrefixNone,
|
||||||
|
EPrefixWarning,
|
||||||
|
EPrefixError,
|
||||||
|
EPrefixInternalError,
|
||||||
|
EPrefixUnimplemented,
|
||||||
|
EPrefixNote
|
||||||
|
};
|
||||||
|
|
||||||
|
enum TOutputStream {
|
||||||
|
ENull = 0,
|
||||||
|
EDebugger = 0x01,
|
||||||
|
EStdOut = 0x02,
|
||||||
|
EString = 0x04,
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// Encapsulate info logs for all objects that have them.
|
||||||
|
//
|
||||||
|
// The methods are a general set of tools for getting a variety of
|
||||||
|
// messages and types inserted into the log.
|
||||||
|
//
|
||||||
|
class TInfoSinkBase {
|
||||||
|
public:
|
||||||
|
TInfoSinkBase() : outputStream(4) {}
|
||||||
|
void erase() { sink.erase(); }
|
||||||
|
TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
|
||||||
|
TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
|
||||||
|
TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
|
||||||
|
TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
|
||||||
|
TInfoSinkBase& operator<<(unsigned int n) { append(String(n)); return *this; }
|
||||||
|
TInfoSinkBase& operator<<(float n) { const int size = 40; char buf[size];
|
||||||
|
snprintf(buf, size, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ? "%f" : "%g", n);
|
||||||
|
append(buf);
|
||||||
|
return *this; }
|
||||||
|
TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
|
||||||
|
TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
|
||||||
|
TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
|
||||||
|
TInfoSinkBase& operator+(const char* s) { append(s); return *this; }
|
||||||
|
const char* c_str() const { return sink.c_str(); }
|
||||||
|
void prefix(TPrefixType message) {
|
||||||
|
switch(message) {
|
||||||
|
case EPrefixNone: break;
|
||||||
|
case EPrefixWarning: append("WARNING: "); break;
|
||||||
|
case EPrefixError: append("ERROR: "); break;
|
||||||
|
case EPrefixInternalError: append("INTERNAL ERROR: "); break;
|
||||||
|
case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;
|
||||||
|
case EPrefixNote: append("NOTE: "); break;
|
||||||
|
default: append("UNKNOWN ERROR: "); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void location(const TSourceLoc& loc) {
|
||||||
|
const int maxSize = 24;
|
||||||
|
char locText[maxSize];
|
||||||
|
snprintf(locText, maxSize, ":%d", loc.line);
|
||||||
|
append(loc.getStringNameOrNum(false).c_str());
|
||||||
|
append(locText);
|
||||||
|
append(": ");
|
||||||
|
}
|
||||||
|
void message(TPrefixType message, const char* s) {
|
||||||
|
prefix(message);
|
||||||
|
append(s);
|
||||||
|
append("\n");
|
||||||
|
}
|
||||||
|
void message(TPrefixType message, const char* s, const TSourceLoc& loc) {
|
||||||
|
prefix(message);
|
||||||
|
location(loc);
|
||||||
|
append(s);
|
||||||
|
append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setOutputStream(int output = 4)
|
||||||
|
{
|
||||||
|
outputStream = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void append(const char* s);
|
||||||
|
|
||||||
|
void append(int count, char c);
|
||||||
|
void append(const TPersistString& t);
|
||||||
|
void append(const TString& t);
|
||||||
|
|
||||||
|
void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2)
|
||||||
|
sink.reserve(sink.capacity() + sink.capacity() / 2); }
|
||||||
|
void appendToStream(const char* s);
|
||||||
|
TPersistString sink;
|
||||||
|
int outputStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
class TInfoSink {
|
||||||
|
public:
|
||||||
|
glslang::TInfoSinkBase info;
|
||||||
|
glslang::TInfoSinkBase debug;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _INFOSINK_INCLUDED_
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __INITIALIZE_GLOBALS_INCLUDED_
|
||||||
|
#define __INITIALIZE_GLOBALS_INCLUDED_
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
bool InitializePoolIndex();
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // __INITIALIZE_GLOBALS_INCLUDED_
|
||||||
|
|
@ -0,0 +1,316 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _POOLALLOC_INCLUDED_
|
||||||
|
#define _POOLALLOC_INCLUDED_
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
# define GUARD_BLOCKS // define to enable guard block sanity checking
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// This header defines an allocator that can be used to efficiently
|
||||||
|
// allocate a large number of small requests for heap memory, with the
|
||||||
|
// intention that they are not individually deallocated, but rather
|
||||||
|
// collectively deallocated at one time.
|
||||||
|
//
|
||||||
|
// This simultaneously
|
||||||
|
//
|
||||||
|
// * Makes each individual allocation much more efficient; the
|
||||||
|
// typical allocation is trivial.
|
||||||
|
// * Completely avoids the cost of doing individual deallocation.
|
||||||
|
// * Saves the trouble of tracking down and plugging a large class of leaks.
|
||||||
|
//
|
||||||
|
// Individual classes can use this allocator by supplying their own
|
||||||
|
// new and delete methods.
|
||||||
|
//
|
||||||
|
// STL containers can use this allocator by using the pool_allocator
|
||||||
|
// class as the allocator (second) template argument.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
// If we are using guard blocks, we must track each individual
|
||||||
|
// allocation. If we aren't using guard blocks, these
|
||||||
|
// never get instantiated, so won't have any impact.
|
||||||
|
//
|
||||||
|
|
||||||
|
class TAllocation {
|
||||||
|
public:
|
||||||
|
TAllocation(size_t size, unsigned char* mem, TAllocation* prev = 0) :
|
||||||
|
size(size), mem(mem), prevAlloc(prev) {
|
||||||
|
// Allocations are bracketed:
|
||||||
|
// [allocationHeader][initialGuardBlock][userData][finalGuardBlock]
|
||||||
|
// This would be cleaner with if (guardBlockSize)..., but that
|
||||||
|
// makes the compiler print warnings about 0 length memsets,
|
||||||
|
// even with the if() protecting them.
|
||||||
|
# ifdef GUARD_BLOCKS
|
||||||
|
memset(preGuard(), guardBlockBeginVal, guardBlockSize);
|
||||||
|
memset(data(), userDataFill, size);
|
||||||
|
memset(postGuard(), guardBlockEndVal, guardBlockSize);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void check() const {
|
||||||
|
checkGuardBlock(preGuard(), guardBlockBeginVal, "before");
|
||||||
|
checkGuardBlock(postGuard(), guardBlockEndVal, "after");
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkAllocList() const;
|
||||||
|
|
||||||
|
// Return total size needed to accommodate user buffer of 'size',
|
||||||
|
// plus our tracking data.
|
||||||
|
inline static size_t allocationSize(size_t size) {
|
||||||
|
return size + 2 * guardBlockSize + headerSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset from surrounding buffer to get to user data buffer.
|
||||||
|
inline static unsigned char* offsetAllocation(unsigned char* m) {
|
||||||
|
return m + guardBlockSize + headerSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const;
|
||||||
|
|
||||||
|
// Find offsets to pre and post guard blocks, and user data buffer
|
||||||
|
unsigned char* preGuard() const { return mem + headerSize(); }
|
||||||
|
unsigned char* data() const { return preGuard() + guardBlockSize; }
|
||||||
|
unsigned char* postGuard() const { return data() + size; }
|
||||||
|
|
||||||
|
size_t size; // size of the user data area
|
||||||
|
unsigned char* mem; // beginning of our allocation (pts to header)
|
||||||
|
TAllocation* prevAlloc; // prior allocation in the chain
|
||||||
|
|
||||||
|
const static unsigned char guardBlockBeginVal;
|
||||||
|
const static unsigned char guardBlockEndVal;
|
||||||
|
const static unsigned char userDataFill;
|
||||||
|
|
||||||
|
const static size_t guardBlockSize;
|
||||||
|
# ifdef GUARD_BLOCKS
|
||||||
|
inline static size_t headerSize() { return sizeof(TAllocation); }
|
||||||
|
# else
|
||||||
|
inline static size_t headerSize() { return 0; }
|
||||||
|
# endif
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// There are several stacks. One is to track the pushing and popping
|
||||||
|
// of the user, and not yet implemented. The others are simply a
|
||||||
|
// repositories of free pages or used pages.
|
||||||
|
//
|
||||||
|
// Page stacks are linked together with a simple header at the beginning
|
||||||
|
// of each allocation obtained from the underlying OS. Multi-page allocations
|
||||||
|
// are returned to the OS. Individual page allocations are kept for future
|
||||||
|
// re-use.
|
||||||
|
//
|
||||||
|
// The "page size" used is not, nor must it match, the underlying OS
|
||||||
|
// page size. But, having it be about that size or equal to a set of
|
||||||
|
// pages is likely most optimal.
|
||||||
|
//
|
||||||
|
class TPoolAllocator {
|
||||||
|
public:
|
||||||
|
TPoolAllocator(int growthIncrement = 8*1024, int allocationAlignment = 16);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Don't call the destructor just to free up the memory, call pop()
|
||||||
|
//
|
||||||
|
~TPoolAllocator();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call push() to establish a new place to pop memory too. Does not
|
||||||
|
// have to be called to get things started.
|
||||||
|
//
|
||||||
|
void push();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call pop() to free all memory allocated since the last call to push(),
|
||||||
|
// or if no last call to push, frees all memory since first allocation.
|
||||||
|
//
|
||||||
|
void pop();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call popAll() to free all memory allocated.
|
||||||
|
//
|
||||||
|
void popAll();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call allocate() to actually acquire memory. Returns 0 if no memory
|
||||||
|
// available, otherwise a properly aligned pointer to 'numBytes' of memory.
|
||||||
|
//
|
||||||
|
void* allocate(size_t numBytes);
|
||||||
|
|
||||||
|
//
|
||||||
|
// There is no deallocate. The point of this class is that
|
||||||
|
// deallocation can be skipped by the user of it, as the model
|
||||||
|
// of use is to simultaneously deallocate everything at once
|
||||||
|
// by calling pop(), and to not have to solve memory leak problems.
|
||||||
|
//
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend struct tHeader;
|
||||||
|
|
||||||
|
struct tHeader {
|
||||||
|
tHeader(tHeader* nextPage, size_t pageCount) :
|
||||||
|
#ifdef GUARD_BLOCKS
|
||||||
|
lastAllocation(0),
|
||||||
|
#endif
|
||||||
|
nextPage(nextPage), pageCount(pageCount) { }
|
||||||
|
|
||||||
|
~tHeader() {
|
||||||
|
#ifdef GUARD_BLOCKS
|
||||||
|
if (lastAllocation)
|
||||||
|
lastAllocation->checkAllocList();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef GUARD_BLOCKS
|
||||||
|
TAllocation* lastAllocation;
|
||||||
|
#endif
|
||||||
|
tHeader* nextPage;
|
||||||
|
size_t pageCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tAllocState {
|
||||||
|
size_t offset;
|
||||||
|
tHeader* page;
|
||||||
|
};
|
||||||
|
typedef std::vector<tAllocState> tAllocStack;
|
||||||
|
|
||||||
|
// Track allocations if and only if we're using guard blocks
|
||||||
|
#ifndef GUARD_BLOCKS
|
||||||
|
void* initializeAllocation(tHeader*, unsigned char* memory, size_t) {
|
||||||
|
#else
|
||||||
|
void* initializeAllocation(tHeader* block, unsigned char* memory, size_t numBytes) {
|
||||||
|
new(memory) TAllocation(numBytes, memory, block->lastAllocation);
|
||||||
|
block->lastAllocation = reinterpret_cast<TAllocation*>(memory);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This is optimized entirely away if GUARD_BLOCKS is not defined.
|
||||||
|
return TAllocation::offsetAllocation(memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t pageSize; // granularity of allocation from the OS
|
||||||
|
size_t alignment; // all returned allocations will be aligned at
|
||||||
|
// this granularity, which will be a power of 2
|
||||||
|
size_t alignmentMask;
|
||||||
|
size_t headerSkip; // amount of memory to skip to make room for the
|
||||||
|
// header (basically, size of header, rounded
|
||||||
|
// up to make it aligned
|
||||||
|
size_t currentPageOffset; // next offset in top of inUseList to allocate from
|
||||||
|
tHeader* freeList; // list of popped memory
|
||||||
|
tHeader* inUseList; // list of all memory currently being used
|
||||||
|
tAllocStack stack; // stack of where to allocate from, to partition pool
|
||||||
|
|
||||||
|
int numCalls; // just an interesting statistic
|
||||||
|
size_t totalBytes; // just an interesting statistic
|
||||||
|
private:
|
||||||
|
TPoolAllocator& operator=(const TPoolAllocator&); // don't allow assignment operator
|
||||||
|
TPoolAllocator(const TPoolAllocator&); // don't allow default copy constructor
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// There could potentially be many pools with pops happening at
|
||||||
|
// different times. But a simple use is to have a global pop
|
||||||
|
// with everyone using the same global allocator.
|
||||||
|
//
|
||||||
|
extern TPoolAllocator& GetThreadPoolAllocator();
|
||||||
|
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator);
|
||||||
|
|
||||||
|
//
|
||||||
|
// This STL compatible allocator is intended to be used as the allocator
|
||||||
|
// parameter to templatized STL containers, like vector and map.
|
||||||
|
//
|
||||||
|
// It will use the pools for allocation, and not
|
||||||
|
// do any deallocation, but will still do destruction.
|
||||||
|
//
|
||||||
|
template<class T>
|
||||||
|
class pool_allocator {
|
||||||
|
public:
|
||||||
|
typedef size_t size_type;
|
||||||
|
typedef ptrdiff_t difference_type;
|
||||||
|
typedef T *pointer;
|
||||||
|
typedef const T *const_pointer;
|
||||||
|
typedef T& reference;
|
||||||
|
typedef const T& const_reference;
|
||||||
|
typedef T value_type;
|
||||||
|
template<class Other>
|
||||||
|
struct rebind {
|
||||||
|
typedef pool_allocator<Other> other;
|
||||||
|
};
|
||||||
|
pointer address(reference x) const { return &x; }
|
||||||
|
const_pointer address(const_reference x) const { return &x; }
|
||||||
|
|
||||||
|
pool_allocator() : allocator(GetThreadPoolAllocator()) { }
|
||||||
|
pool_allocator(TPoolAllocator& a) : allocator(a) { }
|
||||||
|
pool_allocator(const pool_allocator<T>& p) : allocator(p.allocator) { }
|
||||||
|
|
||||||
|
template<class Other>
|
||||||
|
pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }
|
||||||
|
|
||||||
|
pointer allocate(size_type n) {
|
||||||
|
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||||
|
pointer allocate(size_type n, const void*) {
|
||||||
|
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||||
|
|
||||||
|
void deallocate(void*, size_type) { }
|
||||||
|
void deallocate(pointer, size_type) { }
|
||||||
|
|
||||||
|
pointer _Charalloc(size_t n) {
|
||||||
|
return reinterpret_cast<pointer>(getAllocator().allocate(n)); }
|
||||||
|
|
||||||
|
void construct(pointer p, const T& val) { new ((void *)p) T(val); }
|
||||||
|
void destroy(pointer p) { p->T::~T(); }
|
||||||
|
|
||||||
|
bool operator==(const pool_allocator& rhs) const { return &getAllocator() == &rhs.getAllocator(); }
|
||||||
|
bool operator!=(const pool_allocator& rhs) const { return &getAllocator() != &rhs.getAllocator(); }
|
||||||
|
|
||||||
|
size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); }
|
||||||
|
size_type max_size(int size) const { return static_cast<size_type>(-1) / size; }
|
||||||
|
|
||||||
|
TPoolAllocator& getAllocator() const { return allocator; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
pool_allocator& operator=(const pool_allocator&) { return *this; }
|
||||||
|
TPoolAllocator& allocator;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _POOLALLOC_INCLUDED_
|
||||||
|
|
@ -0,0 +1,150 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2013 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _RESOURCE_LIMITS_INCLUDED_
|
||||||
|
#define _RESOURCE_LIMITS_INCLUDED_
|
||||||
|
|
||||||
|
struct TLimits {
|
||||||
|
bool nonInductiveForLoops;
|
||||||
|
bool whileLoops;
|
||||||
|
bool doWhileLoops;
|
||||||
|
bool generalUniformIndexing;
|
||||||
|
bool generalAttributeMatrixVectorIndexing;
|
||||||
|
bool generalVaryingIndexing;
|
||||||
|
bool generalSamplerIndexing;
|
||||||
|
bool generalVariableIndexing;
|
||||||
|
bool generalConstantMatrixVectorIndexing;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TBuiltInResource {
|
||||||
|
int maxLights;
|
||||||
|
int maxClipPlanes;
|
||||||
|
int maxTextureUnits;
|
||||||
|
int maxTextureCoords;
|
||||||
|
int maxVertexAttribs;
|
||||||
|
int maxVertexUniformComponents;
|
||||||
|
int maxVaryingFloats;
|
||||||
|
int maxVertexTextureImageUnits;
|
||||||
|
int maxCombinedTextureImageUnits;
|
||||||
|
int maxTextureImageUnits;
|
||||||
|
int maxFragmentUniformComponents;
|
||||||
|
int maxDrawBuffers;
|
||||||
|
int maxVertexUniformVectors;
|
||||||
|
int maxVaryingVectors;
|
||||||
|
int maxFragmentUniformVectors;
|
||||||
|
int maxVertexOutputVectors;
|
||||||
|
int maxFragmentInputVectors;
|
||||||
|
int minProgramTexelOffset;
|
||||||
|
int maxProgramTexelOffset;
|
||||||
|
int maxClipDistances;
|
||||||
|
int maxComputeWorkGroupCountX;
|
||||||
|
int maxComputeWorkGroupCountY;
|
||||||
|
int maxComputeWorkGroupCountZ;
|
||||||
|
int maxComputeWorkGroupSizeX;
|
||||||
|
int maxComputeWorkGroupSizeY;
|
||||||
|
int maxComputeWorkGroupSizeZ;
|
||||||
|
int maxComputeUniformComponents;
|
||||||
|
int maxComputeTextureImageUnits;
|
||||||
|
int maxComputeImageUniforms;
|
||||||
|
int maxComputeAtomicCounters;
|
||||||
|
int maxComputeAtomicCounterBuffers;
|
||||||
|
int maxVaryingComponents;
|
||||||
|
int maxVertexOutputComponents;
|
||||||
|
int maxGeometryInputComponents;
|
||||||
|
int maxGeometryOutputComponents;
|
||||||
|
int maxFragmentInputComponents;
|
||||||
|
int maxImageUnits;
|
||||||
|
int maxCombinedImageUnitsAndFragmentOutputs;
|
||||||
|
int maxCombinedShaderOutputResources;
|
||||||
|
int maxImageSamples;
|
||||||
|
int maxVertexImageUniforms;
|
||||||
|
int maxTessControlImageUniforms;
|
||||||
|
int maxTessEvaluationImageUniforms;
|
||||||
|
int maxGeometryImageUniforms;
|
||||||
|
int maxFragmentImageUniforms;
|
||||||
|
int maxCombinedImageUniforms;
|
||||||
|
int maxGeometryTextureImageUnits;
|
||||||
|
int maxGeometryOutputVertices;
|
||||||
|
int maxGeometryTotalOutputComponents;
|
||||||
|
int maxGeometryUniformComponents;
|
||||||
|
int maxGeometryVaryingComponents;
|
||||||
|
int maxTessControlInputComponents;
|
||||||
|
int maxTessControlOutputComponents;
|
||||||
|
int maxTessControlTextureImageUnits;
|
||||||
|
int maxTessControlUniformComponents;
|
||||||
|
int maxTessControlTotalOutputComponents;
|
||||||
|
int maxTessEvaluationInputComponents;
|
||||||
|
int maxTessEvaluationOutputComponents;
|
||||||
|
int maxTessEvaluationTextureImageUnits;
|
||||||
|
int maxTessEvaluationUniformComponents;
|
||||||
|
int maxTessPatchComponents;
|
||||||
|
int maxPatchVertices;
|
||||||
|
int maxTessGenLevel;
|
||||||
|
int maxViewports;
|
||||||
|
int maxVertexAtomicCounters;
|
||||||
|
int maxTessControlAtomicCounters;
|
||||||
|
int maxTessEvaluationAtomicCounters;
|
||||||
|
int maxGeometryAtomicCounters;
|
||||||
|
int maxFragmentAtomicCounters;
|
||||||
|
int maxCombinedAtomicCounters;
|
||||||
|
int maxAtomicCounterBindings;
|
||||||
|
int maxVertexAtomicCounterBuffers;
|
||||||
|
int maxTessControlAtomicCounterBuffers;
|
||||||
|
int maxTessEvaluationAtomicCounterBuffers;
|
||||||
|
int maxGeometryAtomicCounterBuffers;
|
||||||
|
int maxFragmentAtomicCounterBuffers;
|
||||||
|
int maxCombinedAtomicCounterBuffers;
|
||||||
|
int maxAtomicCounterBufferSize;
|
||||||
|
int maxTransformFeedbackBuffers;
|
||||||
|
int maxTransformFeedbackInterleavedComponents;
|
||||||
|
int maxCullDistances;
|
||||||
|
int maxCombinedClipAndCullDistances;
|
||||||
|
int maxSamples;
|
||||||
|
int maxMeshOutputVerticesNV;
|
||||||
|
int maxMeshOutputPrimitivesNV;
|
||||||
|
int maxMeshWorkGroupSizeX_NV;
|
||||||
|
int maxMeshWorkGroupSizeY_NV;
|
||||||
|
int maxMeshWorkGroupSizeZ_NV;
|
||||||
|
int maxTaskWorkGroupSizeX_NV;
|
||||||
|
int maxTaskWorkGroupSizeY_NV;
|
||||||
|
int maxTaskWorkGroupSizeZ_NV;
|
||||||
|
int maxMeshViewCountNV;
|
||||||
|
int maxDualSourceDrawBuffersEXT;
|
||||||
|
|
||||||
|
TLimits limits;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _RESOURCE_LIMITS_INCLUDED_
|
||||||
|
|
@ -0,0 +1,176 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _SHHANDLE_INCLUDED_
|
||||||
|
#define _SHHANDLE_INCLUDED_
|
||||||
|
|
||||||
|
//
|
||||||
|
// Machine independent part of the compiler private objects
|
||||||
|
// sent as ShHandle to the driver.
|
||||||
|
//
|
||||||
|
// This should not be included by driver code.
|
||||||
|
//
|
||||||
|
|
||||||
|
#define SH_EXPORTING
|
||||||
|
#include "../Public/ShaderLang.h"
|
||||||
|
#include "../MachineIndependent/Versions.h"
|
||||||
|
#include "InfoSink.h"
|
||||||
|
|
||||||
|
class TCompiler;
|
||||||
|
class TLinker;
|
||||||
|
class TUniformMap;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The base class used to back handles returned to the driver.
|
||||||
|
//
|
||||||
|
class TShHandleBase {
|
||||||
|
public:
|
||||||
|
TShHandleBase() { pool = new glslang::TPoolAllocator; }
|
||||||
|
virtual ~TShHandleBase() { delete pool; }
|
||||||
|
virtual TCompiler* getAsCompiler() { return 0; }
|
||||||
|
virtual TLinker* getAsLinker() { return 0; }
|
||||||
|
virtual TUniformMap* getAsUniformMap() { return 0; }
|
||||||
|
virtual glslang::TPoolAllocator* getPool() const { return pool; }
|
||||||
|
private:
|
||||||
|
glslang::TPoolAllocator* pool;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// The base class for the machine dependent linker to derive from
|
||||||
|
// for managing where uniforms live.
|
||||||
|
//
|
||||||
|
class TUniformMap : public TShHandleBase {
|
||||||
|
public:
|
||||||
|
TUniformMap() { }
|
||||||
|
virtual ~TUniformMap() { }
|
||||||
|
virtual TUniformMap* getAsUniformMap() { return this; }
|
||||||
|
virtual int getLocation(const char* name) = 0;
|
||||||
|
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||||
|
TInfoSink infoSink;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TIntermNode;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The base class for the machine dependent compiler to derive from
|
||||||
|
// for managing object code from the compile.
|
||||||
|
//
|
||||||
|
class TCompiler : public TShHandleBase {
|
||||||
|
public:
|
||||||
|
TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
|
||||||
|
virtual ~TCompiler() { }
|
||||||
|
EShLanguage getLanguage() { return language; }
|
||||||
|
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||||
|
|
||||||
|
virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile) = 0;
|
||||||
|
|
||||||
|
virtual TCompiler* getAsCompiler() { return this; }
|
||||||
|
virtual bool linkable() { return haveValidObjectCode; }
|
||||||
|
|
||||||
|
TInfoSink& infoSink;
|
||||||
|
protected:
|
||||||
|
TCompiler& operator=(TCompiler&);
|
||||||
|
|
||||||
|
EShLanguage language;
|
||||||
|
bool haveValidObjectCode;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Link operations are based on a list of compile results...
|
||||||
|
//
|
||||||
|
typedef glslang::TVector<TCompiler*> TCompilerList;
|
||||||
|
typedef glslang::TVector<TShHandleBase*> THandleList;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The base class for the machine dependent linker to derive from
|
||||||
|
// to manage the resulting executable.
|
||||||
|
//
|
||||||
|
|
||||||
|
class TLinker : public TShHandleBase {
|
||||||
|
public:
|
||||||
|
TLinker(EShExecutable e, TInfoSink& iSink) :
|
||||||
|
infoSink(iSink),
|
||||||
|
executable(e),
|
||||||
|
haveReturnableObjectCode(false),
|
||||||
|
appAttributeBindings(0),
|
||||||
|
fixedAttributeBindings(0),
|
||||||
|
excludedAttributes(0),
|
||||||
|
excludedCount(0),
|
||||||
|
uniformBindings(0) { }
|
||||||
|
virtual TLinker* getAsLinker() { return this; }
|
||||||
|
virtual ~TLinker() { }
|
||||||
|
virtual bool link(TCompilerList&, TUniformMap*) = 0;
|
||||||
|
virtual bool link(THandleList&) { return false; }
|
||||||
|
virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }
|
||||||
|
virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
|
||||||
|
virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
|
||||||
|
virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
|
||||||
|
virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
|
||||||
|
virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
|
||||||
|
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||||
|
TInfoSink& infoSink;
|
||||||
|
protected:
|
||||||
|
TLinker& operator=(TLinker&);
|
||||||
|
EShExecutable executable;
|
||||||
|
bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
|
||||||
|
|
||||||
|
const ShBindingTable* appAttributeBindings;
|
||||||
|
const ShBindingTable* fixedAttributeBindings;
|
||||||
|
const int* excludedAttributes;
|
||||||
|
int excludedCount;
|
||||||
|
ShBindingTable* uniformBindings; // created by the linker
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is the interface between the machine independent code
|
||||||
|
// and the machine dependent code.
|
||||||
|
//
|
||||||
|
// The machine dependent code should derive from the classes
|
||||||
|
// above. Then Construct*() and Delete*() will create and
|
||||||
|
// destroy the machine dependent objects, which contain the
|
||||||
|
// above machine independent information.
|
||||||
|
//
|
||||||
|
TCompiler* ConstructCompiler(EShLanguage, int);
|
||||||
|
|
||||||
|
TShHandleBase* ConstructLinker(EShExecutable, int);
|
||||||
|
TShHandleBase* ConstructBindings();
|
||||||
|
void DeleteLinker(TShHandleBase*);
|
||||||
|
void DeleteBindingList(TShHandleBase* bindingList);
|
||||||
|
|
||||||
|
TUniformMap* ConstructUniformMap();
|
||||||
|
void DeleteCompiler(TCompiler*);
|
||||||
|
|
||||||
|
void DeleteUniformMap(TUniformMap*);
|
||||||
|
|
||||||
|
#endif // _SHHANDLE_INCLUDED_
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,341 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Implement types for tracking GLSL arrays, arrays of arrays, etc.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _ARRAYS_INCLUDED
|
||||||
|
#define _ARRAYS_INCLUDED
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
// This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else.
|
||||||
|
const int UnsizedArraySize = 0;
|
||||||
|
|
||||||
|
class TIntermTyped;
|
||||||
|
extern bool SameSpecializationConstants(TIntermTyped*, TIntermTyped*);
|
||||||
|
|
||||||
|
// Specialization constants need both a nominal size and a node that defines
|
||||||
|
// the specialization constant being used. Array types are the same when their
|
||||||
|
// size and specialization constant nodes are the same.
|
||||||
|
struct TArraySize {
|
||||||
|
unsigned int size;
|
||||||
|
TIntermTyped* node; // nullptr means no specialization constant node
|
||||||
|
bool operator==(const TArraySize& rhs) const
|
||||||
|
{
|
||||||
|
if (size != rhs.size)
|
||||||
|
return false;
|
||||||
|
if (node == nullptr || rhs.node == nullptr)
|
||||||
|
return node == rhs.node;
|
||||||
|
|
||||||
|
return SameSpecializationConstants(node, rhs.node);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// TSmallArrayVector is used as the container for the set of sizes in TArraySizes.
|
||||||
|
// It has generic-container semantics, while TArraySizes has array-of-array semantics.
|
||||||
|
// That is, TSmallArrayVector should be more focused on mechanism and TArraySizes on policy.
|
||||||
|
//
|
||||||
|
struct TSmallArrayVector {
|
||||||
|
//
|
||||||
|
// TODO: memory: TSmallArrayVector is intended to be smaller.
|
||||||
|
// Almost all arrays could be handled by two sizes each fitting
|
||||||
|
// in 16 bits, needing a real vector only in the cases where there
|
||||||
|
// are more than 3 sizes or a size needing more than 16 bits.
|
||||||
|
//
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
|
||||||
|
TSmallArrayVector() : sizes(nullptr) { }
|
||||||
|
virtual ~TSmallArrayVector() { dealloc(); }
|
||||||
|
|
||||||
|
// For breaking into two non-shared copies, independently modifiable.
|
||||||
|
TSmallArrayVector& operator=(const TSmallArrayVector& from)
|
||||||
|
{
|
||||||
|
if (from.sizes == nullptr)
|
||||||
|
sizes = nullptr;
|
||||||
|
else {
|
||||||
|
alloc();
|
||||||
|
*sizes = *from.sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size() const
|
||||||
|
{
|
||||||
|
if (sizes == nullptr)
|
||||||
|
return 0;
|
||||||
|
return (int)sizes->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int frontSize() const
|
||||||
|
{
|
||||||
|
assert(sizes != nullptr && sizes->size() > 0);
|
||||||
|
return sizes->front().size;
|
||||||
|
}
|
||||||
|
|
||||||
|
TIntermTyped* frontNode() const
|
||||||
|
{
|
||||||
|
assert(sizes != nullptr && sizes->size() > 0);
|
||||||
|
return sizes->front().node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void changeFront(unsigned int s)
|
||||||
|
{
|
||||||
|
assert(sizes != nullptr);
|
||||||
|
// this should only happen for implicitly sized arrays, not specialization constants
|
||||||
|
assert(sizes->front().node == nullptr);
|
||||||
|
sizes->front().size = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_back(unsigned int e, TIntermTyped* n)
|
||||||
|
{
|
||||||
|
alloc();
|
||||||
|
TArraySize pair = { e, n };
|
||||||
|
sizes->push_back(pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_back(const TSmallArrayVector& newDims)
|
||||||
|
{
|
||||||
|
alloc();
|
||||||
|
sizes->insert(sizes->end(), newDims.sizes->begin(), newDims.sizes->end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop_front()
|
||||||
|
{
|
||||||
|
assert(sizes != nullptr && sizes->size() > 0);
|
||||||
|
if (sizes->size() == 1)
|
||||||
|
dealloc();
|
||||||
|
else
|
||||||
|
sizes->erase(sizes->begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'this' should currently not be holding anything, and copyNonFront
|
||||||
|
// will make it hold a copy of all but the first element of rhs.
|
||||||
|
// (This would be useful for making a type that is dereferenced by
|
||||||
|
// one dimension.)
|
||||||
|
void copyNonFront(const TSmallArrayVector& rhs)
|
||||||
|
{
|
||||||
|
assert(sizes == nullptr);
|
||||||
|
if (rhs.size() > 1) {
|
||||||
|
alloc();
|
||||||
|
sizes->insert(sizes->begin(), rhs.sizes->begin() + 1, rhs.sizes->end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int getDimSize(int i) const
|
||||||
|
{
|
||||||
|
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||||
|
return (*sizes)[i].size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDimSize(int i, unsigned int size) const
|
||||||
|
{
|
||||||
|
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||||
|
assert((*sizes)[i].node == nullptr);
|
||||||
|
(*sizes)[i].size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
TIntermTyped* getDimNode(int i) const
|
||||||
|
{
|
||||||
|
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||||
|
return (*sizes)[i].node;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const TSmallArrayVector& rhs) const
|
||||||
|
{
|
||||||
|
if (sizes == nullptr && rhs.sizes == nullptr)
|
||||||
|
return true;
|
||||||
|
if (sizes == nullptr || rhs.sizes == nullptr)
|
||||||
|
return false;
|
||||||
|
return *sizes == *rhs.sizes;
|
||||||
|
}
|
||||||
|
bool operator!=(const TSmallArrayVector& rhs) const { return ! operator==(rhs); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TSmallArrayVector(const TSmallArrayVector&);
|
||||||
|
|
||||||
|
void alloc()
|
||||||
|
{
|
||||||
|
if (sizes == nullptr)
|
||||||
|
sizes = new TVector<TArraySize>;
|
||||||
|
}
|
||||||
|
void dealloc()
|
||||||
|
{
|
||||||
|
delete sizes;
|
||||||
|
sizes = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
TVector<TArraySize>* sizes; // will either hold such a pointer, or in the future, hold the two array sizes
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Represent an array, or array of arrays, to arbitrary depth. This is not
|
||||||
|
// done through a hierarchy of types in a type tree, rather all contiguous arrayness
|
||||||
|
// in the type hierarchy is localized into this single cumulative object.
|
||||||
|
//
|
||||||
|
// The arrayness in TTtype is a pointer, so that it can be non-allocated and zero
|
||||||
|
// for the vast majority of types that are non-array types.
|
||||||
|
//
|
||||||
|
// Order Policy: these are all identical:
|
||||||
|
// - left to right order within a contiguous set of ...[..][..][..]... in the source language
|
||||||
|
// - index order 0, 1, 2, ... within the 'sizes' member below
|
||||||
|
// - outer-most to inner-most
|
||||||
|
//
|
||||||
|
struct TArraySizes {
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
|
||||||
|
TArraySizes() : implicitArraySize(1), variablyIndexed(false) { }
|
||||||
|
|
||||||
|
// For breaking into two non-shared copies, independently modifiable.
|
||||||
|
TArraySizes& operator=(const TArraySizes& from)
|
||||||
|
{
|
||||||
|
implicitArraySize = from.implicitArraySize;
|
||||||
|
variablyIndexed = from.variablyIndexed;
|
||||||
|
sizes = from.sizes;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// translate from array-of-array semantics to container semantics
|
||||||
|
int getNumDims() const { return sizes.size(); }
|
||||||
|
int getDimSize(int dim) const { return sizes.getDimSize(dim); }
|
||||||
|
TIntermTyped* getDimNode(int dim) const { return sizes.getDimNode(dim); }
|
||||||
|
void setDimSize(int dim, int size) { sizes.setDimSize(dim, size); }
|
||||||
|
int getOuterSize() const { return sizes.frontSize(); }
|
||||||
|
TIntermTyped* getOuterNode() const { return sizes.frontNode(); }
|
||||||
|
int getCumulativeSize() const
|
||||||
|
{
|
||||||
|
int size = 1;
|
||||||
|
for (int d = 0; d < sizes.size(); ++d) {
|
||||||
|
// this only makes sense in paths that have a known array size
|
||||||
|
assert(sizes.getDimSize(d) != UnsizedArraySize);
|
||||||
|
size *= sizes.getDimSize(d);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
void addInnerSize() { addInnerSize((unsigned)UnsizedArraySize); }
|
||||||
|
void addInnerSize(int s) { addInnerSize((unsigned)s, nullptr); }
|
||||||
|
void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); }
|
||||||
|
void addInnerSize(TArraySize pair) {
|
||||||
|
sizes.push_back(pair.size, pair.node);
|
||||||
|
}
|
||||||
|
void addInnerSizes(const TArraySizes& s) { sizes.push_back(s.sizes); }
|
||||||
|
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
|
||||||
|
int getImplicitSize() const { return implicitArraySize; }
|
||||||
|
void updateImplicitSize(int s) { implicitArraySize = std::max(implicitArraySize, s); }
|
||||||
|
bool isInnerUnsized() const
|
||||||
|
{
|
||||||
|
for (int d = 1; d < sizes.size(); ++d) {
|
||||||
|
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool clearInnerUnsized()
|
||||||
|
{
|
||||||
|
for (int d = 1; d < sizes.size(); ++d) {
|
||||||
|
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
|
||||||
|
setDimSize(d, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool isInnerSpecialization() const
|
||||||
|
{
|
||||||
|
for (int d = 1; d < sizes.size(); ++d) {
|
||||||
|
if (sizes.getDimNode(d) != nullptr)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool isOuterSpecialization()
|
||||||
|
{
|
||||||
|
return sizes.getDimNode(0) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasUnsized() const { return getOuterSize() == UnsizedArraySize || isInnerUnsized(); }
|
||||||
|
bool isSized() const { return getOuterSize() != UnsizedArraySize; }
|
||||||
|
void dereference() { sizes.pop_front(); }
|
||||||
|
void copyDereferenced(const TArraySizes& rhs)
|
||||||
|
{
|
||||||
|
assert(sizes.size() == 0);
|
||||||
|
if (rhs.sizes.size() > 1)
|
||||||
|
sizes.copyNonFront(rhs.sizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sameInnerArrayness(const TArraySizes& rhs) const
|
||||||
|
{
|
||||||
|
if (sizes.size() != rhs.sizes.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int d = 1; d < sizes.size(); ++d) {
|
||||||
|
if (sizes.getDimSize(d) != rhs.sizes.getDimSize(d) ||
|
||||||
|
sizes.getDimNode(d) != rhs.sizes.getDimNode(d))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVariablyIndexed() { variablyIndexed = true; }
|
||||||
|
bool isVariablyIndexed() const { return variablyIndexed; }
|
||||||
|
|
||||||
|
bool operator==(const TArraySizes& rhs) const { return sizes == rhs.sizes; }
|
||||||
|
bool operator!=(const TArraySizes& rhs) const { return sizes != rhs.sizes; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TSmallArrayVector sizes;
|
||||||
|
|
||||||
|
TArraySizes(const TArraySizes&);
|
||||||
|
|
||||||
|
// For tracking maximum referenced compile-time constant index.
|
||||||
|
// Applies only to the outer-most dimension. Potentially becomes
|
||||||
|
// the implicit size of the array, if not variably indexed and
|
||||||
|
// otherwise legal.
|
||||||
|
int implicitArraySize;
|
||||||
|
bool variablyIndexed; // true if array is indexed with a non compile-time constant
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _ARRAYS_INCLUDED_
|
||||||
|
|
@ -0,0 +1,233 @@
|
||||||
|
/**
|
||||||
|
This code is based on the glslang_c_interface implementation by Viktor Latypov
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
BSD 2-Clause License
|
||||||
|
|
||||||
|
Copyright (c) 2019, Viktor Latypov
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef GLSLANG_C_IFACE_H_INCLUDED
|
||||||
|
#define GLSLANG_C_IFACE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "glslang_c_shader_types.h"
|
||||||
|
|
||||||
|
typedef struct glslang_shader_s glslang_shader_t;
|
||||||
|
typedef struct glslang_program_s glslang_program_t;
|
||||||
|
|
||||||
|
/* TLimits counterpart */
|
||||||
|
typedef struct glslang_limits_s {
|
||||||
|
bool non_inductive_for_loops;
|
||||||
|
bool while_loops;
|
||||||
|
bool do_while_loops;
|
||||||
|
bool general_uniform_indexing;
|
||||||
|
bool general_attribute_matrix_vector_indexing;
|
||||||
|
bool general_varying_indexing;
|
||||||
|
bool general_sampler_indexing;
|
||||||
|
bool general_variable_indexing;
|
||||||
|
bool general_constant_matrix_vector_indexing;
|
||||||
|
} glslang_limits_t;
|
||||||
|
|
||||||
|
/* TBuiltInResource counterpart */
|
||||||
|
typedef struct glslang_resource_s {
|
||||||
|
int max_lights;
|
||||||
|
int max_clip_planes;
|
||||||
|
int max_texture_units;
|
||||||
|
int max_texture_coords;
|
||||||
|
int max_vertex_attribs;
|
||||||
|
int max_vertex_uniform_components;
|
||||||
|
int max_varying_floats;
|
||||||
|
int max_vertex_texture_image_units;
|
||||||
|
int max_combined_texture_image_units;
|
||||||
|
int max_texture_image_units;
|
||||||
|
int max_fragment_uniform_components;
|
||||||
|
int max_draw_buffers;
|
||||||
|
int max_vertex_uniform_vectors;
|
||||||
|
int max_varying_vectors;
|
||||||
|
int max_fragment_uniform_vectors;
|
||||||
|
int max_vertex_output_vectors;
|
||||||
|
int max_fragment_input_vectors;
|
||||||
|
int min_program_texel_offset;
|
||||||
|
int max_program_texel_offset;
|
||||||
|
int max_clip_distances;
|
||||||
|
int max_compute_work_group_count_x;
|
||||||
|
int max_compute_work_group_count_y;
|
||||||
|
int max_compute_work_group_count_z;
|
||||||
|
int max_compute_work_group_size_x;
|
||||||
|
int max_compute_work_group_size_y;
|
||||||
|
int max_compute_work_group_size_z;
|
||||||
|
int max_compute_uniform_components;
|
||||||
|
int max_compute_texture_image_units;
|
||||||
|
int max_compute_image_uniforms;
|
||||||
|
int max_compute_atomic_counters;
|
||||||
|
int max_compute_atomic_counter_buffers;
|
||||||
|
int max_varying_components;
|
||||||
|
int max_vertex_output_components;
|
||||||
|
int max_geometry_input_components;
|
||||||
|
int max_geometry_output_components;
|
||||||
|
int max_fragment_input_components;
|
||||||
|
int max_image_units;
|
||||||
|
int max_combined_image_units_and_fragment_outputs;
|
||||||
|
int max_combined_shader_output_resources;
|
||||||
|
int max_image_samples;
|
||||||
|
int max_vertex_image_uniforms;
|
||||||
|
int max_tess_control_image_uniforms;
|
||||||
|
int max_tess_evaluation_image_uniforms;
|
||||||
|
int max_geometry_image_uniforms;
|
||||||
|
int max_fragment_image_uniforms;
|
||||||
|
int max_combined_image_uniforms;
|
||||||
|
int max_geometry_texture_image_units;
|
||||||
|
int max_geometry_output_vertices;
|
||||||
|
int max_geometry_total_output_components;
|
||||||
|
int max_geometry_uniform_components;
|
||||||
|
int max_geometry_varying_components;
|
||||||
|
int max_tess_control_input_components;
|
||||||
|
int max_tess_control_output_components;
|
||||||
|
int max_tess_control_texture_image_units;
|
||||||
|
int max_tess_control_uniform_components;
|
||||||
|
int max_tess_control_total_output_components;
|
||||||
|
int max_tess_evaluation_input_components;
|
||||||
|
int max_tess_evaluation_output_components;
|
||||||
|
int max_tess_evaluation_texture_image_units;
|
||||||
|
int max_tess_evaluation_uniform_components;
|
||||||
|
int max_tess_patch_components;
|
||||||
|
int max_patch_vertices;
|
||||||
|
int max_tess_gen_level;
|
||||||
|
int max_viewports;
|
||||||
|
int max_vertex_atomic_counters;
|
||||||
|
int max_tess_control_atomic_counters;
|
||||||
|
int max_tess_evaluation_atomic_counters;
|
||||||
|
int max_geometry_atomic_counters;
|
||||||
|
int max_fragment_atomic_counters;
|
||||||
|
int max_combined_atomic_counters;
|
||||||
|
int max_atomic_counter_bindings;
|
||||||
|
int max_vertex_atomic_counter_buffers;
|
||||||
|
int max_tess_control_atomic_counter_buffers;
|
||||||
|
int max_tess_evaluation_atomic_counter_buffers;
|
||||||
|
int max_geometry_atomic_counter_buffers;
|
||||||
|
int max_fragment_atomic_counter_buffers;
|
||||||
|
int max_combined_atomic_counter_buffers;
|
||||||
|
int max_atomic_counter_buffer_size;
|
||||||
|
int max_transform_feedback_buffers;
|
||||||
|
int max_transform_feedback_interleaved_components;
|
||||||
|
int max_cull_distances;
|
||||||
|
int max_combined_clip_and_cull_distances;
|
||||||
|
int max_samples;
|
||||||
|
int max_mesh_output_vertices_nv;
|
||||||
|
int max_mesh_output_primitives_nv;
|
||||||
|
int max_mesh_work_group_size_x_nv;
|
||||||
|
int max_mesh_work_group_size_y_nv;
|
||||||
|
int max_mesh_work_group_size_z_nv;
|
||||||
|
int max_task_work_group_size_x_nv;
|
||||||
|
int max_task_work_group_size_y_nv;
|
||||||
|
int max_task_work_group_size_z_nv;
|
||||||
|
int max_mesh_view_count_nv;
|
||||||
|
int maxDualSourceDrawBuffersEXT;
|
||||||
|
|
||||||
|
glslang_limits_t limits;
|
||||||
|
} glslang_resource_t;
|
||||||
|
|
||||||
|
typedef struct glslang_input_s {
|
||||||
|
glslang_source_t language;
|
||||||
|
glslang_stage_t stage;
|
||||||
|
glslang_client_t client;
|
||||||
|
glslang_target_client_version_t client_version;
|
||||||
|
glslang_target_language_t target_language;
|
||||||
|
glslang_target_language_version_t target_language_version;
|
||||||
|
/** Shader source code */
|
||||||
|
const char* code;
|
||||||
|
int default_version;
|
||||||
|
glslang_profile_t default_profile;
|
||||||
|
int force_default_version_and_profile;
|
||||||
|
int forward_compatible;
|
||||||
|
glslang_messages_t messages;
|
||||||
|
const glslang_resource_t* resource;
|
||||||
|
} glslang_input_t;
|
||||||
|
|
||||||
|
/* Inclusion result structure allocated by C include_local/include_system callbacks */
|
||||||
|
typedef struct glsl_include_result_s {
|
||||||
|
/* Header file name or NULL if inclusion failed */
|
||||||
|
const char* header_name;
|
||||||
|
|
||||||
|
/* Header contents or NULL */
|
||||||
|
const char* header_data;
|
||||||
|
size_t header_length;
|
||||||
|
|
||||||
|
} glsl_include_result_t;
|
||||||
|
|
||||||
|
/* Callback for local file inclusion */
|
||||||
|
typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
|
||||||
|
size_t include_depth);
|
||||||
|
|
||||||
|
/* Callback for system file inclusion */
|
||||||
|
typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
|
||||||
|
const char* includer_name, size_t include_depth);
|
||||||
|
|
||||||
|
/* Callback for include result destruction */
|
||||||
|
typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
|
||||||
|
|
||||||
|
/* Collection of callbacks for GLSL preprocessor */
|
||||||
|
typedef struct glsl_include_callbacks_s {
|
||||||
|
glsl_include_system_func include_system;
|
||||||
|
glsl_include_local_func include_local;
|
||||||
|
glsl_free_include_result_func free_include_result;
|
||||||
|
} glsl_include_callbacks_t;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int glslang_initialize_process();
|
||||||
|
void glslang_finalize_process();
|
||||||
|
|
||||||
|
glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
|
||||||
|
void glslang_shader_delete(glslang_shader_t* shader);
|
||||||
|
int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
|
||||||
|
int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
|
||||||
|
const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
|
||||||
|
const char* glslang_shader_get_info_log(glslang_shader_t* shader);
|
||||||
|
const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
|
||||||
|
|
||||||
|
glslang_program_t* glslang_program_create();
|
||||||
|
void glslang_program_delete(glslang_program_t* program);
|
||||||
|
void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
|
||||||
|
int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
|
||||||
|
void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
|
||||||
|
size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
|
||||||
|
void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
|
||||||
|
unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
|
||||||
|
const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
|
||||||
|
const char* glslang_program_get_info_log(glslang_program_t* program);
|
||||||
|
const char* glslang_program_get_info_debug_log(glslang_program_t* program);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */
|
||||||
|
|
@ -0,0 +1,185 @@
|
||||||
|
/**
|
||||||
|
This code is based on the glslang_c_interface implementation by Viktor Latypov
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
BSD 2-Clause License
|
||||||
|
|
||||||
|
Copyright (c) 2019, Viktor Latypov
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef C_SHADER_TYPES_H_INCLUDED
|
||||||
|
#define C_SHADER_TYPES_H_INCLUDED
|
||||||
|
|
||||||
|
#define LAST_ELEMENT_MARKER(x) x
|
||||||
|
|
||||||
|
/* EShLanguage counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_STAGE_VERTEX,
|
||||||
|
GLSLANG_STAGE_TESSCONTROL,
|
||||||
|
GLSLANG_STAGE_TESSEVALUATION,
|
||||||
|
GLSLANG_STAGE_GEOMETRY,
|
||||||
|
GLSLANG_STAGE_FRAGMENT,
|
||||||
|
GLSLANG_STAGE_COMPUTE,
|
||||||
|
GLSLANG_STAGE_RAYGEN_NV,
|
||||||
|
GLSLANG_STAGE_INTERSECT_NV,
|
||||||
|
GLSLANG_STAGE_ANYHIT_NV,
|
||||||
|
GLSLANG_STAGE_CLOSESTHIT_NV,
|
||||||
|
GLSLANG_STAGE_MISS_NV,
|
||||||
|
GLSLANG_STAGE_CALLABLE_NV,
|
||||||
|
GLSLANG_STAGE_TASK_NV,
|
||||||
|
GLSLANG_STAGE_MESH_NV,
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_STAGE_COUNT),
|
||||||
|
} glslang_stage_t; // would be better as stage, but this is ancient now
|
||||||
|
|
||||||
|
/* EShLanguageMask counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_STAGE_VERTEX_MASK = (1 << GLSLANG_STAGE_VERTEX),
|
||||||
|
GLSLANG_STAGE_TESSCONTROL_MASK = (1 << GLSLANG_STAGE_TESSCONTROL),
|
||||||
|
GLSLANG_STAGE_TESSEVALUATION_MASK = (1 << GLSLANG_STAGE_TESSEVALUATION),
|
||||||
|
GLSLANG_STAGE_GEOMETRY_MASK = (1 << GLSLANG_STAGE_GEOMETRY),
|
||||||
|
GLSLANG_STAGE_FRAGMENT_MASK = (1 << GLSLANG_STAGE_FRAGMENT),
|
||||||
|
GLSLANG_STAGE_COMPUTE_MASK = (1 << GLSLANG_STAGE_COMPUTE),
|
||||||
|
GLSLANG_STAGE_RAYGEN_NV_MASK = (1 << GLSLANG_STAGE_RAYGEN_NV),
|
||||||
|
GLSLANG_STAGE_INTERSECT_NV_MASK = (1 << GLSLANG_STAGE_INTERSECT_NV),
|
||||||
|
GLSLANG_STAGE_ANYHIT_NV_MASK = (1 << GLSLANG_STAGE_ANYHIT_NV),
|
||||||
|
GLSLANG_STAGE_CLOSESTHIT_NV_MASK = (1 << GLSLANG_STAGE_CLOSESTHIT_NV),
|
||||||
|
GLSLANG_STAGE_MISS_NV_MASK = (1 << GLSLANG_STAGE_MISS_NV),
|
||||||
|
GLSLANG_STAGE_CALLABLE_NV_MASK = (1 << GLSLANG_STAGE_CALLABLE_NV),
|
||||||
|
GLSLANG_STAGE_TASK_NV_MASK = (1 << GLSLANG_STAGE_TASK_NV),
|
||||||
|
GLSLANG_STAGE_MESH_NV_MASK = (1 << GLSLANG_STAGE_MESH_NV),
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_STAGE_MASK_COUNT),
|
||||||
|
} glslang_stage_mask_t;
|
||||||
|
|
||||||
|
/* EShSource counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_SOURCE_NONE,
|
||||||
|
GLSLANG_SOURCE_GLSL,
|
||||||
|
GLSLANG_SOURCE_HLSL,
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_SOURCE_COUNT),
|
||||||
|
} glslang_source_t;
|
||||||
|
|
||||||
|
/* EShClient counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_CLIENT_NONE,
|
||||||
|
GLSLANG_CLIENT_VULKAN,
|
||||||
|
GLSLANG_CLIENT_OPENGL,
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_CLIENT_COUNT),
|
||||||
|
} glslang_client_t;
|
||||||
|
|
||||||
|
/* EShTargetLanguage counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_TARGET_NONE,
|
||||||
|
GLSLANG_TARGET_SPV,
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_TARGET_COUNT),
|
||||||
|
} glslang_target_language_t;
|
||||||
|
|
||||||
|
/* SH_TARGET_ClientVersion counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_TARGET_VULKAN_1_0 = (1 << 22),
|
||||||
|
GLSLANG_TARGET_VULKAN_1_1 = (1 << 22) | (1 << 12),
|
||||||
|
GLSLANG_TARGET_OPENGL_450 = 450,
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_TARGET_CLIENT_VERSION_COUNT),
|
||||||
|
} glslang_target_client_version_t;
|
||||||
|
|
||||||
|
/* SH_TARGET_LanguageVersion counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_TARGET_SPV_1_0 = (1 << 16),
|
||||||
|
GLSLANG_TARGET_SPV_1_1 = (1 << 16) | (1 << 8),
|
||||||
|
GLSLANG_TARGET_SPV_1_2 = (1 << 16) | (2 << 8),
|
||||||
|
GLSLANG_TARGET_SPV_1_3 = (1 << 16) | (3 << 8),
|
||||||
|
GLSLANG_TARGET_SPV_1_4 = (1 << 16) | (4 << 8),
|
||||||
|
GLSLANG_TARGET_SPV_1_5 = (1 << 16) | (5 << 8),
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_TARGET_LANGUAGE_VERSION_COUNT),
|
||||||
|
} glslang_target_language_version_t;
|
||||||
|
|
||||||
|
/* EShExecutable counterpart */
|
||||||
|
typedef enum { GLSLANG_EX_VERTEX_FRAGMENT, GLSLANG_EX_FRAGMENT } glslang_executable_t;
|
||||||
|
|
||||||
|
/* EShOptimizationLevel counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_OPT_NO_GENERATION,
|
||||||
|
GLSLANG_OPT_NONE,
|
||||||
|
GLSLANG_OPT_SIMPLE,
|
||||||
|
GLSLANG_OPT_FULL,
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_OPT_LEVEL_COUNT),
|
||||||
|
} glslang_optimization_level_t;
|
||||||
|
|
||||||
|
/* EShTextureSamplerTransformMode counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_TEX_SAMP_TRANS_KEEP,
|
||||||
|
GLSLANG_TEX_SAMP_TRANS_UPGRADE_TEXTURE_REMOVE_SAMPLER,
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_TEX_SAMP_TRANS_COUNT),
|
||||||
|
} glslang_texture_sampler_transform_mode_t;
|
||||||
|
|
||||||
|
/* EShMessages counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_MSG_DEFAULT_BIT = 0,
|
||||||
|
GLSLANG_MSG_RELAXED_ERRORS_BIT = (1 << 0),
|
||||||
|
GLSLANG_MSG_SUPPRESS_WARNINGS_BIT = (1 << 1),
|
||||||
|
GLSLANG_MSG_AST_BIT = (1 << 2),
|
||||||
|
GLSLANG_MSG_SPV_RULES_BIT = (1 << 3),
|
||||||
|
GLSLANG_MSG_VULKAN_RULES_BIT = (1 << 4),
|
||||||
|
GLSLANG_MSG_ONLY_PREPROCESSOR_BIT = (1 << 5),
|
||||||
|
GLSLANG_MSG_READ_HLSL_BIT = (1 << 6),
|
||||||
|
GLSLANG_MSG_CASCADING_ERRORS_BIT = (1 << 7),
|
||||||
|
GLSLANG_MSG_KEEP_UNCALLED_BIT = (1 << 8),
|
||||||
|
GLSLANG_MSG_HLSL_OFFSETS_BIT = (1 << 9),
|
||||||
|
GLSLANG_MSG_DEBUG_INFO_BIT = (1 << 10),
|
||||||
|
GLSLANG_MSG_HLSL_ENABLE_16BIT_TYPES_BIT = (1 << 11),
|
||||||
|
GLSLANG_MSG_HLSL_LEGALIZATION_BIT = (1 << 12),
|
||||||
|
GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT = (1 << 13),
|
||||||
|
GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT = (1 << 14),
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_MSG_COUNT),
|
||||||
|
} glslang_messages_t;
|
||||||
|
|
||||||
|
/* EShReflectionOptions counterpart */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_REFLECTION_DEFAULT_BIT = 0,
|
||||||
|
GLSLANG_REFLECTION_STRICT_ARRAY_SUFFIX_BIT = (1 << 0),
|
||||||
|
GLSLANG_REFLECTION_BASIC_ARRAY_SUFFIX_BIT = (1 << 1),
|
||||||
|
GLSLANG_REFLECTION_INTERMEDIATE_IOO_BIT = (1 << 2),
|
||||||
|
GLSLANG_REFLECTION_SEPARATE_BUFFERS_BIT = (1 << 3),
|
||||||
|
GLSLANG_REFLECTION_ALL_BLOCK_VARIABLES_BIT = (1 << 4),
|
||||||
|
GLSLANG_REFLECTION_UNWRAP_IO_BLOCKS_BIT = (1 << 5),
|
||||||
|
GLSLANG_REFLECTION_ALL_IO_VARIABLES_BIT = (1 << 6),
|
||||||
|
GLSLANG_REFLECTION_SHARED_STD140_SSBO_BIT = (1 << 7),
|
||||||
|
GLSLANG_REFLECTION_SHARED_STD140_UBO_BIT = (1 << 8),
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_REFLECTION_COUNT),
|
||||||
|
} glslang_reflection_options_t;
|
||||||
|
|
||||||
|
/* EProfile counterpart (from Versions.h) */
|
||||||
|
typedef enum {
|
||||||
|
GLSLANG_BAD_PROFILE = 0,
|
||||||
|
GLSLANG_NO_PROFILE = (1 << 0),
|
||||||
|
GLSLANG_CORE_PROFILE = (1 << 1),
|
||||||
|
GLSLANG_COMPATIBILITY_PROFILE = (1 << 2),
|
||||||
|
GLSLANG_ES_PROFILE = (1 << 3),
|
||||||
|
LAST_ELEMENT_MARKER(GLSLANG_PROFILE_COUNT),
|
||||||
|
} glslang_profile_t;
|
||||||
|
|
||||||
|
#undef LAST_ELEMENT_MARKER
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,3 @@
|
||||||
|
// This header is generated by the make-revision script.
|
||||||
|
|
||||||
|
#define GLSLANG_PATCH_LEVEL 3795
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2013-2016 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _INITIALIZE_INCLUDED_
|
||||||
|
#define _INITIALIZE_INCLUDED_
|
||||||
|
|
||||||
|
#include "../Include/ResourceLimits.h"
|
||||||
|
#include "../Include/Common.h"
|
||||||
|
#include "../Include/ShHandle.h"
|
||||||
|
#include "SymbolTable.h"
|
||||||
|
#include "Versions.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is made to hold parseable strings for almost all the built-in
|
||||||
|
// functions and variables for one specific combination of version
|
||||||
|
// and profile. (Some still need to be added programmatically.)
|
||||||
|
// This is a base class for language-specific derivations, which
|
||||||
|
// can be used for language independent builtins.
|
||||||
|
//
|
||||||
|
// The strings are organized by
|
||||||
|
// commonBuiltins: intersection of all stages' built-ins, processed just once
|
||||||
|
// stageBuiltins[]: anything a stage needs that's not in commonBuiltins
|
||||||
|
//
|
||||||
|
class TBuiltInParseables {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
TBuiltInParseables();
|
||||||
|
virtual ~TBuiltInParseables();
|
||||||
|
virtual void initialize(int version, EProfile, const SpvVersion& spvVersion) = 0;
|
||||||
|
virtual void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage) = 0;
|
||||||
|
virtual const TString& getCommonString() const { return commonBuiltins; }
|
||||||
|
virtual const TString& getStageString(EShLanguage language) const { return stageBuiltins[language]; }
|
||||||
|
|
||||||
|
virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable) = 0;
|
||||||
|
virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TString commonBuiltins;
|
||||||
|
TString stageBuiltins[EShLangCount];
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is a GLSL specific derivation of TBuiltInParseables. To present a stable
|
||||||
|
// interface and match other similar code, it is called TBuiltIns, rather
|
||||||
|
// than TBuiltInParseablesGlsl.
|
||||||
|
//
|
||||||
|
class TBuiltIns : public TBuiltInParseables {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
TBuiltIns();
|
||||||
|
virtual ~TBuiltIns();
|
||||||
|
void initialize(int version, EProfile, const SpvVersion& spvVersion);
|
||||||
|
void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage);
|
||||||
|
|
||||||
|
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable);
|
||||||
|
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion);
|
||||||
|
void relateTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage, TSymbolTable&);
|
||||||
|
void add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion);
|
||||||
|
void addSubpassSampling(TSampler, const TString& typeName, int version, EProfile profile);
|
||||||
|
void addQueryFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||||
|
void addImageFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||||
|
void addSamplingFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||||
|
void addGatherFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||||
|
|
||||||
|
// Helpers for making textual representations of the permutations
|
||||||
|
// of texturing/imaging functions.
|
||||||
|
const char* postfixes[5];
|
||||||
|
const char* prefixes[EbtNumTypes];
|
||||||
|
int dimMap[EsdNumDims];
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _INITIALIZE_INCLUDED_
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../Include/Common.h"
|
||||||
|
#include "reflection.h"
|
||||||
|
#include "localintermediate.h"
|
||||||
|
|
||||||
|
#include "gl_types.h"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// The traverser: mostly pass through, except
|
||||||
|
// - processing function-call nodes to push live functions onto the stack of functions to process
|
||||||
|
// - processing selection nodes to trim semantically dead code
|
||||||
|
//
|
||||||
|
// This is in the glslang namespace directly so it can be a friend of TReflection.
|
||||||
|
// This can be derived from to implement reflection database traversers or
|
||||||
|
// binding mappers: anything that wants to traverse the live subset of the tree.
|
||||||
|
//
|
||||||
|
|
||||||
|
class TLiveTraverser : public TIntermTraverser {
|
||||||
|
public:
|
||||||
|
TLiveTraverser(const TIntermediate& i, bool traverseAll = false,
|
||||||
|
bool preVisit = true, bool inVisit = false, bool postVisit = false) :
|
||||||
|
TIntermTraverser(preVisit, inVisit, postVisit),
|
||||||
|
intermediate(i), traverseAll(traverseAll)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
// Given a function name, find its subroot in the tree, and push it onto the stack of
|
||||||
|
// functions left to process.
|
||||||
|
//
|
||||||
|
void pushFunction(const TString& name)
|
||||||
|
{
|
||||||
|
TIntermSequence& globals = intermediate.getTreeRoot()->getAsAggregate()->getSequence();
|
||||||
|
for (unsigned int f = 0; f < globals.size(); ++f) {
|
||||||
|
TIntermAggregate* candidate = globals[f]->getAsAggregate();
|
||||||
|
if (candidate && candidate->getOp() == EOpFunction && candidate->getName() == name) {
|
||||||
|
functions.push_back(candidate);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef std::list<TIntermAggregate*> TFunctionStack;
|
||||||
|
TFunctionStack functions;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// To catch which function calls are not dead, and hence which functions must be visited.
|
||||||
|
virtual bool visitAggregate(TVisit, TIntermAggregate* node)
|
||||||
|
{
|
||||||
|
if (!traverseAll)
|
||||||
|
if (node->getOp() == EOpFunctionCall)
|
||||||
|
addFunctionCall(node);
|
||||||
|
|
||||||
|
return true; // traverse this subtree
|
||||||
|
}
|
||||||
|
|
||||||
|
// To prune semantically dead paths.
|
||||||
|
virtual bool visitSelection(TVisit /* visit */, TIntermSelection* node)
|
||||||
|
{
|
||||||
|
if (traverseAll)
|
||||||
|
return true; // traverse all code
|
||||||
|
|
||||||
|
TIntermConstantUnion* constant = node->getCondition()->getAsConstantUnion();
|
||||||
|
if (constant) {
|
||||||
|
// cull the path that is dead
|
||||||
|
if (constant->getConstArray()[0].getBConst() == true && node->getTrueBlock())
|
||||||
|
node->getTrueBlock()->traverse(this);
|
||||||
|
if (constant->getConstArray()[0].getBConst() == false && node->getFalseBlock())
|
||||||
|
node->getFalseBlock()->traverse(this);
|
||||||
|
|
||||||
|
return false; // don't traverse any more, we did it all above
|
||||||
|
} else
|
||||||
|
return true; // traverse the whole subtree
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track live functions as well as uniforms, so that we don't visit dead functions
|
||||||
|
// and only visit each function once.
|
||||||
|
void addFunctionCall(TIntermAggregate* call)
|
||||||
|
{
|
||||||
|
// // just use the map to ensure we process each function at most once
|
||||||
|
if (liveFunctions.find(call->getName()) == liveFunctions.end()) {
|
||||||
|
liveFunctions.insert(call->getName());
|
||||||
|
pushFunction(call->getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const TIntermediate& intermediate;
|
||||||
|
typedef std::unordered_set<TString> TLiveFunctions;
|
||||||
|
TLiveFunctions liveFunctions;
|
||||||
|
bool traverseAll;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// prevent copy & copy construct
|
||||||
|
TLiveTraverser(TLiveTraverser&);
|
||||||
|
TLiveTraverser& operator=(TLiveTraverser&);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace glslang
|
||||||
|
|
@ -0,0 +1,532 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||||
|
// Copyright (C) 2015-2018 Google, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// This header defines a two-level parse-helper hierarchy, derived from
|
||||||
|
// TParseVersions:
|
||||||
|
// - TParseContextBase: sharable across multiple parsers
|
||||||
|
// - TParseContext: GLSL specific helper
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _PARSER_HELPER_INCLUDED_
|
||||||
|
#define _PARSER_HELPER_INCLUDED_
|
||||||
|
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "parseVersions.h"
|
||||||
|
#include "../Include/ShHandle.h"
|
||||||
|
#include "SymbolTable.h"
|
||||||
|
#include "localintermediate.h"
|
||||||
|
#include "Scan.h"
|
||||||
|
#include "attribute.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
struct TPragma {
|
||||||
|
TPragma(bool o, bool d) : optimize(o), debug(d) { }
|
||||||
|
bool optimize;
|
||||||
|
bool debug;
|
||||||
|
TPragmaTable pragmaTable;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TScanContext;
|
||||||
|
class TPpContext;
|
||||||
|
|
||||||
|
typedef std::set<int> TIdSetType;
|
||||||
|
typedef std::map<const TTypeList*, std::map<size_t, const TTypeList*>> TStructRecord;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Sharable code (as well as what's in TParseVersions) across
|
||||||
|
// parse helpers.
|
||||||
|
//
|
||||||
|
class TParseContextBase : public TParseVersions {
|
||||||
|
public:
|
||||||
|
TParseContextBase(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins, int version,
|
||||||
|
EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
|
||||||
|
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages,
|
||||||
|
const TString* entryPoint = nullptr)
|
||||||
|
: TParseVersions(interm, version, profile, spvVersion, language, infoSink, forwardCompatible, messages),
|
||||||
|
scopeMangler("::"),
|
||||||
|
symbolTable(symbolTable),
|
||||||
|
statementNestingLevel(0), loopNestingLevel(0), structNestingLevel(0), controlFlowNestingLevel(0),
|
||||||
|
postEntryPointReturn(false),
|
||||||
|
contextPragma(true, false),
|
||||||
|
beginInvocationInterlockCount(0), endInvocationInterlockCount(0),
|
||||||
|
parsingBuiltins(parsingBuiltins), scanContext(nullptr), ppContext(nullptr),
|
||||||
|
limits(resources.limits),
|
||||||
|
globalUniformBlock(nullptr),
|
||||||
|
globalUniformBinding(TQualifier::layoutBindingEnd),
|
||||||
|
globalUniformSet(TQualifier::layoutSetEnd)
|
||||||
|
{
|
||||||
|
if (entryPoint != nullptr)
|
||||||
|
sourceEntryPointName = *entryPoint;
|
||||||
|
}
|
||||||
|
virtual ~TParseContextBase() { }
|
||||||
|
|
||||||
|
#if !defined(GLSLANG_WEB) || defined(GLSLANG_WEB_DEVEL)
|
||||||
|
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...);
|
||||||
|
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...);
|
||||||
|
virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...);
|
||||||
|
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
virtual void setLimits(const TBuiltInResource&) = 0;
|
||||||
|
|
||||||
|
void checkIndex(const TSourceLoc&, const TType&, int& index);
|
||||||
|
|
||||||
|
EShLanguage getLanguage() const { return language; }
|
||||||
|
void setScanContext(TScanContext* c) { scanContext = c; }
|
||||||
|
TScanContext* getScanContext() const { return scanContext; }
|
||||||
|
void setPpContext(TPpContext* c) { ppContext = c; }
|
||||||
|
TPpContext* getPpContext() const { return ppContext; }
|
||||||
|
|
||||||
|
virtual void setLineCallback(const std::function<void(int, int, bool, int, const char*)>& func) { lineCallback = func; }
|
||||||
|
virtual void setExtensionCallback(const std::function<void(int, const char*, const char*)>& func) { extensionCallback = func; }
|
||||||
|
virtual void setVersionCallback(const std::function<void(int, int, const char*)>& func) { versionCallback = func; }
|
||||||
|
virtual void setPragmaCallback(const std::function<void(int, const TVector<TString>&)>& func) { pragmaCallback = func; }
|
||||||
|
virtual void setErrorCallback(const std::function<void(int, const char*)>& func) { errorCallback = func; }
|
||||||
|
|
||||||
|
virtual void reservedPpErrorCheck(const TSourceLoc&, const char* name, const char* op) = 0;
|
||||||
|
virtual bool lineContinuationCheck(const TSourceLoc&, bool endOfComment) = 0;
|
||||||
|
virtual bool lineDirectiveShouldSetNextLine() const = 0;
|
||||||
|
virtual void handlePragma(const TSourceLoc&, const TVector<TString>&) = 0;
|
||||||
|
|
||||||
|
virtual bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) = 0;
|
||||||
|
|
||||||
|
virtual void notifyVersion(int line, int version, const char* type_string)
|
||||||
|
{
|
||||||
|
if (versionCallback)
|
||||||
|
versionCallback(line, version, type_string);
|
||||||
|
}
|
||||||
|
virtual void notifyErrorDirective(int line, const char* error_message)
|
||||||
|
{
|
||||||
|
if (errorCallback)
|
||||||
|
errorCallback(line, error_message);
|
||||||
|
}
|
||||||
|
virtual void notifyLineDirective(int curLineNo, int newLineNo, bool hasSource, int sourceNum, const char* sourceName)
|
||||||
|
{
|
||||||
|
if (lineCallback)
|
||||||
|
lineCallback(curLineNo, newLineNo, hasSource, sourceNum, sourceName);
|
||||||
|
}
|
||||||
|
virtual void notifyExtensionDirective(int line, const char* extension, const char* behavior)
|
||||||
|
{
|
||||||
|
if (extensionCallback)
|
||||||
|
extensionCallback(line, extension, behavior);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_HLSL
|
||||||
|
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
|
||||||
|
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Potentially rename shader entry point function
|
||||||
|
void renameShaderFunction(TString*& name) const
|
||||||
|
{
|
||||||
|
// Replace the entry point name given in the shader with the real entry point name,
|
||||||
|
// if there is a substitution.
|
||||||
|
if (name != nullptr && *name == sourceEntryPointName && intermediate.getEntryPointName().size() > 0)
|
||||||
|
name = NewPoolTString(intermediate.getEntryPointName().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
|
||||||
|
virtual void rValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
|
||||||
|
|
||||||
|
const char* const scopeMangler;
|
||||||
|
|
||||||
|
// Basic parsing state, easily accessible to the grammar
|
||||||
|
|
||||||
|
TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile
|
||||||
|
int statementNestingLevel; // 0 if outside all flow control or compound statements
|
||||||
|
int loopNestingLevel; // 0 if outside all loops
|
||||||
|
int structNestingLevel; // 0 if outside blocks and structures
|
||||||
|
int controlFlowNestingLevel; // 0 if outside all flow control
|
||||||
|
const TType* currentFunctionType; // the return type of the function that's currently being parsed
|
||||||
|
bool functionReturnsValue; // true if a non-void function has a return
|
||||||
|
// if inside a function, true if the function is the entry point and this is after a return statement
|
||||||
|
bool postEntryPointReturn;
|
||||||
|
// case, node, case, case, node, ...; ensure only one node between cases; stack of them for nesting
|
||||||
|
TList<TIntermSequence*> switchSequenceStack;
|
||||||
|
// the statementNestingLevel the current switch statement is at, which must match the level of its case statements
|
||||||
|
TList<int> switchLevel;
|
||||||
|
struct TPragma contextPragma;
|
||||||
|
int beginInvocationInterlockCount;
|
||||||
|
int endInvocationInterlockCount;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TParseContextBase(TParseContextBase&);
|
||||||
|
TParseContextBase& operator=(TParseContextBase&);
|
||||||
|
|
||||||
|
const bool parsingBuiltins; // true if parsing built-in symbols/functions
|
||||||
|
TVector<TSymbol*> linkageSymbols; // will be transferred to 'linkage', after all editing is done, order preserving
|
||||||
|
TScanContext* scanContext;
|
||||||
|
TPpContext* ppContext;
|
||||||
|
TBuiltInResource resources;
|
||||||
|
TLimits& limits;
|
||||||
|
TString sourceEntryPointName;
|
||||||
|
|
||||||
|
// These, if set, will be called when a line, pragma ... is preprocessed.
|
||||||
|
// They will be called with any parameters to the original directive.
|
||||||
|
std::function<void(int, int, bool, int, const char*)> lineCallback;
|
||||||
|
std::function<void(int, const TVector<TString>&)> pragmaCallback;
|
||||||
|
std::function<void(int, int, const char*)> versionCallback;
|
||||||
|
std::function<void(int, const char*, const char*)> extensionCallback;
|
||||||
|
std::function<void(int, const char*)> errorCallback;
|
||||||
|
|
||||||
|
// see implementation for detail
|
||||||
|
const TFunction* selectFunction(const TVector<const TFunction*>, const TFunction&,
|
||||||
|
std::function<bool(const TType&, const TType&, TOperator, int arg)>,
|
||||||
|
std::function<bool(const TType&, const TType&, const TType&)>,
|
||||||
|
/* output */ bool& tie);
|
||||||
|
|
||||||
|
virtual void parseSwizzleSelector(const TSourceLoc&, const TString&, int size,
|
||||||
|
TSwizzleSelectors<TVectorSelector>&);
|
||||||
|
|
||||||
|
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
|
||||||
|
TVariable* globalUniformBlock; // the actual block, inserted into the symbol table
|
||||||
|
unsigned int globalUniformBinding; // the block's binding number
|
||||||
|
unsigned int globalUniformSet; // the block's set number
|
||||||
|
int firstNewMember; // the index of the first member not yet inserted into the symbol table
|
||||||
|
// override this to set the language-specific name
|
||||||
|
virtual const char* getGlobalUniformBlockName() const { return ""; }
|
||||||
|
virtual void setUniformBlockDefaults(TType&) const { }
|
||||||
|
virtual void finalizeGlobalUniformBlockLayout(TVariable&) { }
|
||||||
|
virtual void outputMessage(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, TPrefixType prefix,
|
||||||
|
va_list args);
|
||||||
|
virtual void trackLinkage(TSymbol& symbol);
|
||||||
|
virtual void makeEditable(TSymbol*&);
|
||||||
|
virtual TVariable* getEditableVariable(const char* name);
|
||||||
|
virtual void finish();
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Manage the state for when to respect precision qualifiers and when to warn about
|
||||||
|
// the defaults being different than might be expected.
|
||||||
|
//
|
||||||
|
class TPrecisionManager {
|
||||||
|
public:
|
||||||
|
TPrecisionManager() : obey(false), warn(false), explicitIntDefault(false), explicitFloatDefault(false){ }
|
||||||
|
virtual ~TPrecisionManager() {}
|
||||||
|
|
||||||
|
void respectPrecisionQualifiers() { obey = true; }
|
||||||
|
bool respectingPrecisionQualifiers() const { return obey; }
|
||||||
|
bool shouldWarnAboutDefaults() const { return warn; }
|
||||||
|
void defaultWarningGiven() { warn = false; }
|
||||||
|
void warnAboutDefaults() { warn = true; }
|
||||||
|
void explicitIntDefaultSeen()
|
||||||
|
{
|
||||||
|
explicitIntDefault = true;
|
||||||
|
if (explicitFloatDefault)
|
||||||
|
warn = false;
|
||||||
|
}
|
||||||
|
void explicitFloatDefaultSeen()
|
||||||
|
{
|
||||||
|
explicitFloatDefault = true;
|
||||||
|
if (explicitIntDefault)
|
||||||
|
warn = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool obey; // respect precision qualifiers
|
||||||
|
bool warn; // need to give a warning about the defaults
|
||||||
|
bool explicitIntDefault; // user set the default for int/uint
|
||||||
|
bool explicitFloatDefault; // user set the default for float
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// GLSL-specific parse helper. Should have GLSL in the name, but that's
|
||||||
|
// too big of a change for comparing branches at the moment, and perhaps
|
||||||
|
// impacts downstream consumers as well.
|
||||||
|
//
|
||||||
|
class TParseContext : public TParseContextBase {
|
||||||
|
public:
|
||||||
|
TParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
|
||||||
|
bool forwardCompatible = false, EShMessages messages = EShMsgDefault,
|
||||||
|
const TString* entryPoint = nullptr);
|
||||||
|
virtual ~TParseContext();
|
||||||
|
|
||||||
|
bool obeyPrecisionQualifiers() const { return precisionManager.respectingPrecisionQualifiers(); }
|
||||||
|
void setPrecisionDefaults();
|
||||||
|
|
||||||
|
void setLimits(const TBuiltInResource&) override;
|
||||||
|
bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override;
|
||||||
|
void parserError(const char* s); // for bison's yyerror
|
||||||
|
|
||||||
|
void reservedErrorCheck(const TSourceLoc&, const TString&);
|
||||||
|
void reservedPpErrorCheck(const TSourceLoc&, const char* name, const char* op) override;
|
||||||
|
bool lineContinuationCheck(const TSourceLoc&, bool endOfComment) override;
|
||||||
|
bool lineDirectiveShouldSetNextLine() const override;
|
||||||
|
bool builtInName(const TString&);
|
||||||
|
|
||||||
|
void handlePragma(const TSourceLoc&, const TVector<TString>&) override;
|
||||||
|
TIntermTyped* handleVariable(const TSourceLoc&, TSymbol* symbol, const TString* string);
|
||||||
|
TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
|
||||||
|
void handleIndexLimits(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
void makeEditable(TSymbol*&) override;
|
||||||
|
void ioArrayCheck(const TSourceLoc&, const TType&, const TString& identifier);
|
||||||
|
#endif
|
||||||
|
bool isIoResizeArray(const TType&) const;
|
||||||
|
void fixIoArraySize(const TSourceLoc&, TType&);
|
||||||
|
void handleIoResizeArrayAccess(const TSourceLoc&, TIntermTyped* base);
|
||||||
|
void checkIoArraysConsistency(const TSourceLoc&, bool tailOnly = false);
|
||||||
|
int getIoArrayImplicitSize(const TQualifier&, TString* featureString = nullptr) const;
|
||||||
|
void checkIoArrayConsistency(const TSourceLoc&, int requiredSize, const char* feature, TType&, const TString&);
|
||||||
|
|
||||||
|
TIntermTyped* handleBinaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right);
|
||||||
|
TIntermTyped* handleUnaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* childNode);
|
||||||
|
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||||
|
TIntermTyped* handleDotSwizzle(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||||
|
void blockMemberExtensionCheck(const TSourceLoc&, const TIntermTyped* base, int member, const TString& memberName);
|
||||||
|
TFunction* handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
|
||||||
|
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&);
|
||||||
|
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*);
|
||||||
|
TIntermTyped* handleBuiltInFunctionCall(TSourceLoc, TIntermNode* arguments, const TFunction& function);
|
||||||
|
void computeBuiltinPrecisions(TIntermTyped&, const TFunction&);
|
||||||
|
TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*);
|
||||||
|
void checkLocation(const TSourceLoc&, TOperator);
|
||||||
|
TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
|
||||||
|
void addInputArgumentConversions(const TFunction&, TIntermNode*&) const;
|
||||||
|
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const;
|
||||||
|
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
|
||||||
|
void nonOpBuiltInCheck(const TSourceLoc&, const TFunction&, TIntermAggregate&);
|
||||||
|
void userFunctionCallCheck(const TSourceLoc&, TIntermAggregate&);
|
||||||
|
void samplerConstructorLocationCheck(const TSourceLoc&, const char* token, TIntermNode*);
|
||||||
|
TFunction* handleConstructorCall(const TSourceLoc&, const TPublicType&);
|
||||||
|
void handlePrecisionQualifier(const TSourceLoc&, TQualifier&, TPrecisionQualifier);
|
||||||
|
void checkPrecisionQualifier(const TSourceLoc&, TPrecisionQualifier);
|
||||||
|
void memorySemanticsCheck(const TSourceLoc&, const TFunction&, const TIntermOperator& callNode);
|
||||||
|
|
||||||
|
void assignError(const TSourceLoc&, const char* op, TString left, TString right);
|
||||||
|
void unaryOpError(const TSourceLoc&, const char* op, TString operand);
|
||||||
|
void binaryOpError(const TSourceLoc&, const char* op, TString left, TString right);
|
||||||
|
void variableCheck(TIntermTyped*& nodePtr);
|
||||||
|
bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
|
||||||
|
void rValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
|
||||||
|
void constantValueCheck(TIntermTyped* node, const char* token);
|
||||||
|
void integerCheck(const TIntermTyped* node, const char* token);
|
||||||
|
void globalCheck(const TSourceLoc&, const char* token);
|
||||||
|
bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&);
|
||||||
|
bool constructorTextureSamplerError(const TSourceLoc&, const TFunction&);
|
||||||
|
void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&, const char *sizeType);
|
||||||
|
bool arrayQualifierError(const TSourceLoc&, const TQualifier&);
|
||||||
|
bool arrayError(const TSourceLoc&, const TType&);
|
||||||
|
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
|
||||||
|
void structArrayCheck(const TSourceLoc&, const TType& structure);
|
||||||
|
void arraySizesCheck(const TSourceLoc&, const TQualifier&, TArraySizes*, const TIntermTyped* initializer, bool lastMember);
|
||||||
|
void arrayOfArrayVersionCheck(const TSourceLoc&, const TArraySizes*);
|
||||||
|
bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
|
||||||
|
void boolCheck(const TSourceLoc&, const TIntermTyped*);
|
||||||
|
void boolCheck(const TSourceLoc&, const TPublicType&);
|
||||||
|
void samplerCheck(const TSourceLoc&, const TType&, const TString& identifier, TIntermTyped* initializer);
|
||||||
|
void atomicUintCheck(const TSourceLoc&, const TType&, const TString& identifier);
|
||||||
|
void accStructCheck(const TSourceLoc & loc, const TType & type, const TString & identifier);
|
||||||
|
void transparentOpaqueCheck(const TSourceLoc&, const TType&, const TString& identifier);
|
||||||
|
void memberQualifierCheck(glslang::TPublicType&);
|
||||||
|
void globalQualifierFixCheck(const TSourceLoc&, TQualifier&);
|
||||||
|
void globalQualifierTypeCheck(const TSourceLoc&, const TQualifier&, const TPublicType&);
|
||||||
|
bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
|
||||||
|
void mergeQualifiers(const TSourceLoc&, TQualifier& dst, const TQualifier& src, bool force);
|
||||||
|
void setDefaultPrecision(const TSourceLoc&, TPublicType&, TPrecisionQualifier);
|
||||||
|
int computeSamplerTypeIndex(TSampler&);
|
||||||
|
TPrecisionQualifier getDefaultPrecision(TPublicType&);
|
||||||
|
void precisionQualifierCheck(const TSourceLoc&, TBasicType, TQualifier&);
|
||||||
|
void parameterTypeCheck(const TSourceLoc&, TStorageQualifier qualifier, const TType& type);
|
||||||
|
bool containsFieldWithBasicType(const TType& type ,TBasicType basicType);
|
||||||
|
TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&);
|
||||||
|
void redeclareBuiltinBlock(const TSourceLoc&, TTypeList& typeList, const TString& blockName, const TString* instanceName, TArraySizes* arraySizes);
|
||||||
|
void paramCheckFixStorage(const TSourceLoc&, const TStorageQualifier&, TType& type);
|
||||||
|
void paramCheckFix(const TSourceLoc&, const TQualifier&, TType& type);
|
||||||
|
void nestedBlockCheck(const TSourceLoc&);
|
||||||
|
void nestedStructCheck(const TSourceLoc&);
|
||||||
|
void arrayObjectCheck(const TSourceLoc&, const TType&, const char* op);
|
||||||
|
void opaqueCheck(const TSourceLoc&, const TType&, const char* op);
|
||||||
|
void referenceCheck(const TSourceLoc&, const TType&, const char* op);
|
||||||
|
void storage16BitAssignmentCheck(const TSourceLoc&, const TType&, const char* op);
|
||||||
|
void specializationCheck(const TSourceLoc&, const TType&, const char* op);
|
||||||
|
void structTypeCheck(const TSourceLoc&, TPublicType&);
|
||||||
|
void inductiveLoopCheck(const TSourceLoc&, TIntermNode* init, TIntermLoop* loop);
|
||||||
|
void arrayLimitCheck(const TSourceLoc&, const TString&, int size);
|
||||||
|
void limitCheck(const TSourceLoc&, int value, const char* limit, const char* feature);
|
||||||
|
|
||||||
|
void inductiveLoopBodyCheck(TIntermNode*, int loopIndexId, TSymbolTable&);
|
||||||
|
void constantIndexExpressionCheck(TIntermNode*);
|
||||||
|
|
||||||
|
void setLayoutQualifier(const TSourceLoc&, TPublicType&, TString&);
|
||||||
|
void setLayoutQualifier(const TSourceLoc&, TPublicType&, TString&, const TIntermTyped*);
|
||||||
|
void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly);
|
||||||
|
void layoutObjectCheck(const TSourceLoc&, const TSymbol&);
|
||||||
|
void layoutMemberLocationArrayCheck(const TSourceLoc&, bool memberWithLocation, TArraySizes* arraySizes);
|
||||||
|
void layoutTypeCheck(const TSourceLoc&, const TType&);
|
||||||
|
void layoutQualifierCheck(const TSourceLoc&, const TQualifier&);
|
||||||
|
void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&);
|
||||||
|
void fixOffset(const TSourceLoc&, TSymbol&);
|
||||||
|
|
||||||
|
const TFunction* findFunction(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||||
|
const TFunction* findFunctionExact(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||||
|
const TFunction* findFunction120(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||||
|
const TFunction* findFunction400(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||||
|
const TFunction* findFunctionExplicitTypes(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||||
|
void declareTypeDefaults(const TSourceLoc&, const TPublicType&);
|
||||||
|
TIntermNode* declareVariable(const TSourceLoc&, TString& identifier, const TPublicType&, TArraySizes* typeArray = 0, TIntermTyped* initializer = 0);
|
||||||
|
TIntermTyped* addConstructor(const TSourceLoc&, TIntermNode*, const TType&);
|
||||||
|
TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
|
||||||
|
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);
|
||||||
|
void inheritMemoryQualifiers(const TQualifier& from, TQualifier& to);
|
||||||
|
void declareBlock(const TSourceLoc&, TTypeList& typeList, const TString* instanceName = 0, TArraySizes* arraySizes = 0);
|
||||||
|
void blockStageIoCheck(const TSourceLoc&, const TQualifier&);
|
||||||
|
void blockQualifierCheck(const TSourceLoc&, const TQualifier&, bool instanceName);
|
||||||
|
void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
|
||||||
|
void fixXfbOffsets(TQualifier&, TTypeList&);
|
||||||
|
void fixBlockUniformOffsets(TQualifier&, TTypeList&);
|
||||||
|
void fixBlockUniformLayoutMatrix(TQualifier&, TTypeList*, TTypeList*);
|
||||||
|
void fixBlockUniformLayoutPacking(TQualifier&, TTypeList*, TTypeList*);
|
||||||
|
void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier);
|
||||||
|
void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&);
|
||||||
|
void invariantCheck(const TSourceLoc&, const TQualifier&);
|
||||||
|
void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&);
|
||||||
|
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
|
||||||
|
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body);
|
||||||
|
const TTypeList* recordStructCopy(TStructRecord&, const TType*, const TType*);
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
TAttributeType attributeFromName(const TString& name) const;
|
||||||
|
TAttributes* makeAttributes(const TString& identifier) const;
|
||||||
|
TAttributes* makeAttributes(const TString& identifier, TIntermNode* node) const;
|
||||||
|
TAttributes* mergeAttributes(TAttributes*, TAttributes*) const;
|
||||||
|
|
||||||
|
// Determine selection control from attributes
|
||||||
|
void handleSelectionAttributes(const TAttributes& attributes, TIntermNode*);
|
||||||
|
void handleSwitchAttributes(const TAttributes& attributes, TIntermNode*);
|
||||||
|
// Determine loop control from attributes
|
||||||
|
void handleLoopAttributes(const TAttributes& attributes, TIntermNode*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void checkAndResizeMeshViewDim(const TSourceLoc&, TType&, bool isBlockMember);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void nonInitConstCheck(const TSourceLoc&, TString& identifier, TType& type);
|
||||||
|
void inheritGlobalDefaults(TQualifier& dst) const;
|
||||||
|
TVariable* makeInternalVariable(const char* name, const TType&) const;
|
||||||
|
TVariable* declareNonArray(const TSourceLoc&, const TString& identifier, const TType&);
|
||||||
|
void declareArray(const TSourceLoc&, const TString& identifier, const TType&, TSymbol*&);
|
||||||
|
void checkRuntimeSizable(const TSourceLoc&, const TIntermTyped&);
|
||||||
|
bool isRuntimeLength(const TIntermTyped&) const;
|
||||||
|
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
|
||||||
|
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
void finish() override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
//
|
||||||
|
// Generally, bison productions, the scanner, and the PP need read/write access to these; just give them direct access
|
||||||
|
//
|
||||||
|
|
||||||
|
// Current state of parsing
|
||||||
|
bool inMain; // if inside a function, true if the function is main
|
||||||
|
const TString* blockName;
|
||||||
|
TQualifier currentBlockQualifier;
|
||||||
|
TPrecisionQualifier defaultPrecision[EbtNumTypes];
|
||||||
|
TBuiltInResource resources;
|
||||||
|
TLimits& limits;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TParseContext(TParseContext&);
|
||||||
|
TParseContext& operator=(TParseContext&);
|
||||||
|
|
||||||
|
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2 * 2 * 2)); // see computeSamplerTypeIndex()
|
||||||
|
TPrecisionQualifier defaultSamplerPrecision[maxSamplerIndex];
|
||||||
|
TPrecisionManager precisionManager;
|
||||||
|
TQualifier globalBufferDefaults;
|
||||||
|
TQualifier globalUniformDefaults;
|
||||||
|
TQualifier globalInputDefaults;
|
||||||
|
TQualifier globalOutputDefaults;
|
||||||
|
TString currentCaller; // name of last function body entered (not valid when at global scope)
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
int* atomicUintOffsets; // to become an array of the right size to hold an offset per binding point
|
||||||
|
bool anyIndexLimits;
|
||||||
|
TIdSetType inductiveLoopIds;
|
||||||
|
TVector<TIntermTyped*> needsIndexLimitationChecking;
|
||||||
|
TStructRecord matrixFixRecord;
|
||||||
|
TStructRecord packingFixRecord;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Geometry shader input arrays:
|
||||||
|
// - array sizing is based on input primitive and/or explicit size
|
||||||
|
//
|
||||||
|
// Tessellation control output arrays:
|
||||||
|
// - array sizing is based on output layout(vertices=...) and/or explicit size
|
||||||
|
//
|
||||||
|
// Both:
|
||||||
|
// - array sizing is retroactive
|
||||||
|
// - built-in block redeclarations interact with this
|
||||||
|
//
|
||||||
|
// Design:
|
||||||
|
// - use a per-context "resize-list", a list of symbols whose array sizes
|
||||||
|
// can be fixed
|
||||||
|
//
|
||||||
|
// - the resize-list starts empty at beginning of user-shader compilation, it does
|
||||||
|
// not have built-ins in it
|
||||||
|
//
|
||||||
|
// - on built-in array use: copyUp() symbol and add it to the resize-list
|
||||||
|
//
|
||||||
|
// - on user array declaration: add it to the resize-list
|
||||||
|
//
|
||||||
|
// - on block redeclaration: copyUp() symbol and add it to the resize-list
|
||||||
|
// * note, that appropriately gives an error if redeclaring a block that
|
||||||
|
// was already used and hence already copied-up
|
||||||
|
//
|
||||||
|
// - on seeing a layout declaration that sizes the array, fix everything in the
|
||||||
|
// resize-list, giving errors for mismatch
|
||||||
|
//
|
||||||
|
// - on seeing an array size declaration, give errors on mismatch between it and previous
|
||||||
|
// array-sizing declarations
|
||||||
|
//
|
||||||
|
TVector<TSymbol*> ioArraySymbolResizeList;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _PARSER_HELPER_INCLUDED_
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
void RemoveAllTreeNodes(TIntermNode*);
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
@ -0,0 +1,276 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2013 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
#ifndef _GLSLANG_SCAN_INCLUDED_
|
||||||
|
#define _GLSLANG_SCAN_INCLUDED_
|
||||||
|
|
||||||
|
#include "Versions.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
// Use a global end-of-input character, so no translation is needed across
|
||||||
|
// layers of encapsulation. Characters are all 8 bit, and positive, so there is
|
||||||
|
// no aliasing of character 255 onto -1, for example.
|
||||||
|
const int EndOfInput = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// A character scanner that seamlessly, on read-only strings, reads across an
|
||||||
|
// array of strings without assuming null termination.
|
||||||
|
//
|
||||||
|
class TInputScanner {
|
||||||
|
public:
|
||||||
|
TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr,
|
||||||
|
int b = 0, int f = 0, bool single = false) :
|
||||||
|
numSources(n),
|
||||||
|
// up to this point, common usage is "char*", but now we need positive 8-bit characters
|
||||||
|
sources(reinterpret_cast<const unsigned char* const *>(s)),
|
||||||
|
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single),
|
||||||
|
endOfFileReached(false)
|
||||||
|
{
|
||||||
|
loc = new TSourceLoc[numSources];
|
||||||
|
for (int i = 0; i < numSources; ++i) {
|
||||||
|
loc[i].init(i - stringBias);
|
||||||
|
}
|
||||||
|
if (names != nullptr) {
|
||||||
|
for (int i = 0; i < numSources; ++i)
|
||||||
|
loc[i].name = names[i] != nullptr ? NewPoolTString(names[i]) : nullptr;
|
||||||
|
}
|
||||||
|
loc[currentSource].line = 1;
|
||||||
|
logicalSourceLoc.init(1);
|
||||||
|
logicalSourceLoc.name = loc[0].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~TInputScanner()
|
||||||
|
{
|
||||||
|
delete [] loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// retrieve the next character and advance one character
|
||||||
|
int get()
|
||||||
|
{
|
||||||
|
int ret = peek();
|
||||||
|
if (ret == EndOfInput)
|
||||||
|
return ret;
|
||||||
|
++loc[currentSource].column;
|
||||||
|
++logicalSourceLoc.column;
|
||||||
|
if (ret == '\n') {
|
||||||
|
++loc[currentSource].line;
|
||||||
|
++logicalSourceLoc.line;
|
||||||
|
logicalSourceLoc.column = 0;
|
||||||
|
loc[currentSource].column = 0;
|
||||||
|
}
|
||||||
|
advance();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// retrieve the next character, no advance
|
||||||
|
int peek()
|
||||||
|
{
|
||||||
|
if (currentSource >= numSources) {
|
||||||
|
endOfFileReached = true;
|
||||||
|
return EndOfInput;
|
||||||
|
}
|
||||||
|
// Make sure we do not read off the end of a string.
|
||||||
|
// N.B. Sources can have a length of 0.
|
||||||
|
int sourceToRead = currentSource;
|
||||||
|
size_t charToRead = currentChar;
|
||||||
|
while(charToRead >= lengths[sourceToRead]) {
|
||||||
|
charToRead = 0;
|
||||||
|
sourceToRead += 1;
|
||||||
|
if (sourceToRead >= numSources) {
|
||||||
|
return EndOfInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Here, we care about making negative valued characters positive
|
||||||
|
return sources[sourceToRead][charToRead];
|
||||||
|
}
|
||||||
|
|
||||||
|
// go back one character
|
||||||
|
void unget()
|
||||||
|
{
|
||||||
|
// Do not roll back once we've reached the end of the file.
|
||||||
|
if (endOfFileReached)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (currentChar > 0) {
|
||||||
|
--currentChar;
|
||||||
|
--loc[currentSource].column;
|
||||||
|
--logicalSourceLoc.column;
|
||||||
|
if (loc[currentSource].column < 0) {
|
||||||
|
// We've moved back past a new line. Find the
|
||||||
|
// previous newline (or start of the file) to compute
|
||||||
|
// the column count on the now current line.
|
||||||
|
size_t chIndex = currentChar;
|
||||||
|
while (chIndex > 0) {
|
||||||
|
if (sources[currentSource][chIndex] == '\n') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
--chIndex;
|
||||||
|
}
|
||||||
|
logicalSourceLoc.column = (int)(currentChar - chIndex);
|
||||||
|
loc[currentSource].column = (int)(currentChar - chIndex);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
do {
|
||||||
|
--currentSource;
|
||||||
|
} while (currentSource > 0 && lengths[currentSource] == 0);
|
||||||
|
if (lengths[currentSource] == 0) {
|
||||||
|
// set to 0 if we've backed up to the start of an empty string
|
||||||
|
currentChar = 0;
|
||||||
|
} else
|
||||||
|
currentChar = lengths[currentSource] - 1;
|
||||||
|
}
|
||||||
|
if (peek() == '\n') {
|
||||||
|
--loc[currentSource].line;
|
||||||
|
--logicalSourceLoc.line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for #line override
|
||||||
|
void setLine(int newLine)
|
||||||
|
{
|
||||||
|
logicalSourceLoc.line = newLine;
|
||||||
|
loc[getLastValidSourceIndex()].line = newLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for #line override in filename based parsing
|
||||||
|
void setFile(const char* filename)
|
||||||
|
{
|
||||||
|
TString* fn_tstr = NewPoolTString(filename);
|
||||||
|
logicalSourceLoc.name = fn_tstr;
|
||||||
|
loc[getLastValidSourceIndex()].name = fn_tstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFile(const char* filename, int i)
|
||||||
|
{
|
||||||
|
TString* fn_tstr = NewPoolTString(filename);
|
||||||
|
if (i == getLastValidSourceIndex()) {
|
||||||
|
logicalSourceLoc.name = fn_tstr;
|
||||||
|
}
|
||||||
|
loc[i].name = fn_tstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setString(int newString)
|
||||||
|
{
|
||||||
|
logicalSourceLoc.string = newString;
|
||||||
|
loc[getLastValidSourceIndex()].string = newString;
|
||||||
|
logicalSourceLoc.name = nullptr;
|
||||||
|
loc[getLastValidSourceIndex()].name = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for #include content indentation
|
||||||
|
void setColumn(int col)
|
||||||
|
{
|
||||||
|
logicalSourceLoc.column = col;
|
||||||
|
loc[getLastValidSourceIndex()].column = col;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEndOfInput()
|
||||||
|
{
|
||||||
|
endOfFileReached = true;
|
||||||
|
currentSource = numSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool atEndOfInput() const { return endOfFileReached; }
|
||||||
|
|
||||||
|
const TSourceLoc& getSourceLoc() const
|
||||||
|
{
|
||||||
|
if (singleLogical) {
|
||||||
|
return logicalSourceLoc;
|
||||||
|
} else {
|
||||||
|
return loc[std::max(0, std::min(currentSource, numSources - finale - 1))];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Returns the index (starting from 0) of the most recent valid source string we are reading from.
|
||||||
|
int getLastValidSourceIndex() const { return std::min(currentSource, numSources - 1); }
|
||||||
|
|
||||||
|
void consumeWhiteSpace(bool& foundNonSpaceTab);
|
||||||
|
bool consumeComment();
|
||||||
|
void consumeWhitespaceComment(bool& foundNonSpaceTab);
|
||||||
|
bool scanVersion(int& version, EProfile& profile, bool& notFirstToken);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// advance one character
|
||||||
|
void advance()
|
||||||
|
{
|
||||||
|
++currentChar;
|
||||||
|
if (currentChar >= lengths[currentSource]) {
|
||||||
|
++currentSource;
|
||||||
|
if (currentSource < numSources) {
|
||||||
|
loc[currentSource].string = loc[currentSource - 1].string + 1;
|
||||||
|
loc[currentSource].line = 1;
|
||||||
|
loc[currentSource].column = 0;
|
||||||
|
}
|
||||||
|
while (currentSource < numSources && lengths[currentSource] == 0) {
|
||||||
|
++currentSource;
|
||||||
|
if (currentSource < numSources) {
|
||||||
|
loc[currentSource].string = loc[currentSource - 1].string + 1;
|
||||||
|
loc[currentSource].line = 1;
|
||||||
|
loc[currentSource].column = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentChar = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int numSources; // number of strings in source
|
||||||
|
const unsigned char* const *sources; // array of strings; must be converted to positive values on use, to avoid aliasing with -1 as EndOfInput
|
||||||
|
const size_t *lengths; // length of each string
|
||||||
|
int currentSource;
|
||||||
|
size_t currentChar;
|
||||||
|
|
||||||
|
// This is for reporting what string/line an error occurred on, and can be overridden by #line.
|
||||||
|
// It remembers the last state of each source string as it is left for the next one, so unget()
|
||||||
|
// can restore that state.
|
||||||
|
TSourceLoc* loc; // an array
|
||||||
|
|
||||||
|
int stringBias; // the first string that is the user's string number 0
|
||||||
|
int finale; // number of internal strings after user's last string
|
||||||
|
|
||||||
|
TSourceLoc logicalSourceLoc;
|
||||||
|
bool singleLogical; // treats the strings as a single logical string.
|
||||||
|
// locations will be reported from the first string.
|
||||||
|
|
||||||
|
// Set to true once peek() returns EndOfFile, so that we won't roll back
|
||||||
|
// once we've reached EndOfFile.
|
||||||
|
bool endOfFileReached;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _GLSLANG_SCAN_INCLUDED_
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2013 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// This holds context specific to the GLSL scanner, which
|
||||||
|
// sits between the preprocessor scanner and parser.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ParseHelper.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
class TPpContext;
|
||||||
|
class TPpToken;
|
||||||
|
class TParserToken;
|
||||||
|
|
||||||
|
class TScanContext {
|
||||||
|
public:
|
||||||
|
explicit TScanContext(TParseContextBase& pc) :
|
||||||
|
parseContext(pc),
|
||||||
|
afterType(false), afterStruct(false),
|
||||||
|
field(false), afterBuffer(false) { }
|
||||||
|
virtual ~TScanContext() { }
|
||||||
|
|
||||||
|
static void fillInKeywordMap();
|
||||||
|
static void deleteKeywordMap();
|
||||||
|
|
||||||
|
int tokenize(TPpContext*, TParserToken&);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TScanContext(TScanContext&);
|
||||||
|
TScanContext& operator=(TScanContext&);
|
||||||
|
|
||||||
|
int tokenizeIdentifier();
|
||||||
|
int identifierOrType();
|
||||||
|
int reservedWord();
|
||||||
|
int identifierOrReserved(bool reserved);
|
||||||
|
int es30ReservedFromGLSL(int version);
|
||||||
|
int nonreservedKeyword(int esVersion, int nonEsVersion);
|
||||||
|
int precisionKeyword();
|
||||||
|
int matNxM();
|
||||||
|
int dMat();
|
||||||
|
int firstGenerationImage(bool inEs310);
|
||||||
|
int secondGenerationImage();
|
||||||
|
|
||||||
|
TParseContextBase& parseContext;
|
||||||
|
bool afterType; // true if we've recognized a type, so can only be looking for an identifier
|
||||||
|
bool afterStruct; // true if we've recognized the STRUCT keyword, so can only be looking for an identifier
|
||||||
|
bool field; // true if we're on a field, right after a '.'
|
||||||
|
bool afterBuffer; // true if we've recognized the BUFFER keyword
|
||||||
|
TSourceLoc loc;
|
||||||
|
TParserToken* parserToken;
|
||||||
|
TPpToken* ppToken;
|
||||||
|
|
||||||
|
const char* tokenText;
|
||||||
|
int keyword;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
@ -0,0 +1,885 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2013 LunarG, Inc.
|
||||||
|
// Copyright (C) 2015-2018 Google, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _SYMBOL_TABLE_INCLUDED_
|
||||||
|
#define _SYMBOL_TABLE_INCLUDED_
|
||||||
|
|
||||||
|
//
|
||||||
|
// Symbol table for parsing. Has these design characteristics:
|
||||||
|
//
|
||||||
|
// * Same symbol table can be used to compile many shaders, to preserve
|
||||||
|
// effort of creating and loading with the large numbers of built-in
|
||||||
|
// symbols.
|
||||||
|
//
|
||||||
|
// --> This requires a copy mechanism, so initial pools used to create
|
||||||
|
// the shared information can be popped. Done through "clone"
|
||||||
|
// methods.
|
||||||
|
//
|
||||||
|
// * Name mangling will be used to give each function a unique name
|
||||||
|
// so that symbol table lookups are never ambiguous. This allows
|
||||||
|
// a simpler symbol table structure.
|
||||||
|
//
|
||||||
|
// * Pushing and popping of scope, so symbol table will really be a stack
|
||||||
|
// of symbol tables. Searched from the top, with new inserts going into
|
||||||
|
// the top.
|
||||||
|
//
|
||||||
|
// * Constants: Compile time constant symbols will keep their values
|
||||||
|
// in the symbol table. The parser can substitute constants at parse
|
||||||
|
// time, including doing constant folding and constant propagation.
|
||||||
|
//
|
||||||
|
// * No temporaries: Temporaries made from operations (+, --, .xy, etc.)
|
||||||
|
// are tracked in the intermediate representation, not the symbol table.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../Include/Common.h"
|
||||||
|
#include "../Include/intermediate.h"
|
||||||
|
#include "../Include/InfoSink.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Symbol base class. (Can build functions or variables out of these...)
|
||||||
|
//
|
||||||
|
|
||||||
|
class TVariable;
|
||||||
|
class TFunction;
|
||||||
|
class TAnonMember;
|
||||||
|
|
||||||
|
typedef TVector<const char*> TExtensionList;
|
||||||
|
|
||||||
|
class TSymbol {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
explicit TSymbol(const TString *n) : name(n), extensions(0), writable(true) { }
|
||||||
|
virtual TSymbol* clone() const = 0;
|
||||||
|
virtual ~TSymbol() { } // rely on all symbol owned memory coming from the pool
|
||||||
|
|
||||||
|
virtual const TString& getName() const { return *name; }
|
||||||
|
virtual void changeName(const TString* newName) { name = newName; }
|
||||||
|
virtual void addPrefix(const char* prefix)
|
||||||
|
{
|
||||||
|
TString newName(prefix);
|
||||||
|
newName.append(*name);
|
||||||
|
changeName(NewPoolTString(newName.c_str()));
|
||||||
|
}
|
||||||
|
virtual const TString& getMangledName() const { return getName(); }
|
||||||
|
virtual TFunction* getAsFunction() { return 0; }
|
||||||
|
virtual const TFunction* getAsFunction() const { return 0; }
|
||||||
|
virtual TVariable* getAsVariable() { return 0; }
|
||||||
|
virtual const TVariable* getAsVariable() const { return 0; }
|
||||||
|
virtual const TAnonMember* getAsAnonMember() const { return 0; }
|
||||||
|
virtual const TType& getType() const = 0;
|
||||||
|
virtual TType& getWritableType() = 0;
|
||||||
|
virtual void setUniqueId(int id) { uniqueId = id; }
|
||||||
|
virtual int getUniqueId() const { return uniqueId; }
|
||||||
|
virtual void setExtensions(int numExts, const char* const exts[])
|
||||||
|
{
|
||||||
|
assert(extensions == 0);
|
||||||
|
assert(numExts > 0);
|
||||||
|
extensions = NewPoolObject(extensions);
|
||||||
|
for (int e = 0; e < numExts; ++e)
|
||||||
|
extensions->push_back(exts[e]);
|
||||||
|
}
|
||||||
|
virtual int getNumExtensions() const { return extensions == nullptr ? 0 : (int)extensions->size(); }
|
||||||
|
virtual const char** getExtensions() const { return extensions->data(); }
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
virtual void dump(TInfoSink& infoSink, bool complete = false) const = 0;
|
||||||
|
void dumpExtensions(TInfoSink& infoSink) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
virtual bool isReadOnly() const { return ! writable; }
|
||||||
|
virtual void makeReadOnly() { writable = false; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit TSymbol(const TSymbol&);
|
||||||
|
TSymbol& operator=(const TSymbol&);
|
||||||
|
|
||||||
|
const TString *name;
|
||||||
|
unsigned int uniqueId; // For cross-scope comparing during code generation
|
||||||
|
|
||||||
|
// For tracking what extensions must be present
|
||||||
|
// (don't use if correct version/profile is present).
|
||||||
|
TExtensionList* extensions; // an array of pointers to existing constant char strings
|
||||||
|
|
||||||
|
//
|
||||||
|
// N.B.: Non-const functions that will be generally used should assert on this,
|
||||||
|
// to avoid overwriting shared symbol-table information.
|
||||||
|
//
|
||||||
|
bool writable;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Variable class, meaning a symbol that's not a function.
|
||||||
|
//
|
||||||
|
// There could be a separate class hierarchy for Constant variables;
|
||||||
|
// Only one of int, bool, or float, (or none) is correct for
|
||||||
|
// any particular use, but it's easy to do this way, and doesn't
|
||||||
|
// seem worth having separate classes, and "getConst" can't simply return
|
||||||
|
// different values for different types polymorphically, so this is
|
||||||
|
// just simple and pragmatic.
|
||||||
|
//
|
||||||
|
class TVariable : public TSymbol {
|
||||||
|
public:
|
||||||
|
TVariable(const TString *name, const TType& t, bool uT = false )
|
||||||
|
: TSymbol(name),
|
||||||
|
userType(uT),
|
||||||
|
constSubtree(nullptr),
|
||||||
|
memberExtensions(nullptr),
|
||||||
|
anonId(-1)
|
||||||
|
{ type.shallowCopy(t); }
|
||||||
|
virtual TVariable* clone() const;
|
||||||
|
virtual ~TVariable() { }
|
||||||
|
|
||||||
|
virtual TVariable* getAsVariable() { return this; }
|
||||||
|
virtual const TVariable* getAsVariable() const { return this; }
|
||||||
|
virtual const TType& getType() const { return type; }
|
||||||
|
virtual TType& getWritableType() { assert(writable); return type; }
|
||||||
|
virtual bool isUserType() const { return userType; }
|
||||||
|
virtual const TConstUnionArray& getConstArray() const { return constArray; }
|
||||||
|
virtual TConstUnionArray& getWritableConstArray() { assert(writable); return constArray; }
|
||||||
|
virtual void setConstArray(const TConstUnionArray& array) { constArray = array; }
|
||||||
|
virtual void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
|
||||||
|
virtual TIntermTyped* getConstSubtree() const { return constSubtree; }
|
||||||
|
virtual void setAnonId(int i) { anonId = i; }
|
||||||
|
virtual int getAnonId() const { return anonId; }
|
||||||
|
|
||||||
|
virtual void setMemberExtensions(int member, int numExts, const char* const exts[])
|
||||||
|
{
|
||||||
|
assert(type.isStruct());
|
||||||
|
assert(numExts > 0);
|
||||||
|
if (memberExtensions == nullptr) {
|
||||||
|
memberExtensions = NewPoolObject(memberExtensions);
|
||||||
|
memberExtensions->resize(type.getStruct()->size());
|
||||||
|
}
|
||||||
|
for (int e = 0; e < numExts; ++e)
|
||||||
|
(*memberExtensions)[member].push_back(exts[e]);
|
||||||
|
}
|
||||||
|
virtual bool hasMemberExtensions() const { return memberExtensions != nullptr; }
|
||||||
|
virtual int getNumMemberExtensions(int member) const
|
||||||
|
{
|
||||||
|
return memberExtensions == nullptr ? 0 : (int)(*memberExtensions)[member].size();
|
||||||
|
}
|
||||||
|
virtual const char** getMemberExtensions(int member) const { return (*memberExtensions)[member].data(); }
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
virtual void dump(TInfoSink& infoSink, bool complete = false) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit TVariable(const TVariable&);
|
||||||
|
TVariable& operator=(const TVariable&);
|
||||||
|
|
||||||
|
TType type;
|
||||||
|
bool userType;
|
||||||
|
|
||||||
|
// we are assuming that Pool Allocator will free the memory allocated to unionArray
|
||||||
|
// when this object is destroyed
|
||||||
|
|
||||||
|
TConstUnionArray constArray; // for compile-time constant value
|
||||||
|
TIntermTyped* constSubtree; // for specialization constant computation
|
||||||
|
TVector<TExtensionList>* memberExtensions; // per-member extension list, allocated only when needed
|
||||||
|
int anonId; // the ID used for anonymous blocks: TODO: see if uniqueId could serve a dual purpose
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// The function sub-class of symbols and the parser will need to
|
||||||
|
// share this definition of a function parameter.
|
||||||
|
//
|
||||||
|
struct TParameter {
|
||||||
|
TString *name;
|
||||||
|
TType* type;
|
||||||
|
TIntermTyped* defaultValue;
|
||||||
|
void copyParam(const TParameter& param)
|
||||||
|
{
|
||||||
|
if (param.name)
|
||||||
|
name = NewPoolTString(param.name->c_str());
|
||||||
|
else
|
||||||
|
name = 0;
|
||||||
|
type = param.type->clone();
|
||||||
|
defaultValue = param.defaultValue;
|
||||||
|
}
|
||||||
|
TBuiltInVariable getDeclaredBuiltIn() const { return type->getQualifier().declaredBuiltIn; }
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// The function sub-class of a symbol.
|
||||||
|
//
|
||||||
|
class TFunction : public TSymbol {
|
||||||
|
public:
|
||||||
|
explicit TFunction(TOperator o) :
|
||||||
|
TSymbol(0),
|
||||||
|
op(o),
|
||||||
|
defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0) { }
|
||||||
|
TFunction(const TString *name, const TType& retType, TOperator tOp = EOpNull) :
|
||||||
|
TSymbol(name),
|
||||||
|
mangledName(*name + '('),
|
||||||
|
op(tOp),
|
||||||
|
defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0)
|
||||||
|
{
|
||||||
|
returnType.shallowCopy(retType);
|
||||||
|
declaredBuiltIn = retType.getQualifier().builtIn;
|
||||||
|
}
|
||||||
|
virtual TFunction* clone() const override;
|
||||||
|
virtual ~TFunction();
|
||||||
|
|
||||||
|
virtual TFunction* getAsFunction() override { return this; }
|
||||||
|
virtual const TFunction* getAsFunction() const override { return this; }
|
||||||
|
|
||||||
|
// Install 'p' as the (non-'this') last parameter.
|
||||||
|
// Non-'this' parameters are reflected in both the list of parameters and the
|
||||||
|
// mangled name.
|
||||||
|
virtual void addParameter(TParameter& p)
|
||||||
|
{
|
||||||
|
assert(writable);
|
||||||
|
parameters.push_back(p);
|
||||||
|
p.type->appendMangledName(mangledName);
|
||||||
|
|
||||||
|
if (p.defaultValue != nullptr)
|
||||||
|
defaultParamCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install 'this' as the first parameter.
|
||||||
|
// 'this' is reflected in the list of parameters, but not the mangled name.
|
||||||
|
virtual void addThisParameter(TType& type, const char* name)
|
||||||
|
{
|
||||||
|
TParameter p = { NewPoolTString(name), new TType, nullptr };
|
||||||
|
p.type->shallowCopy(type);
|
||||||
|
parameters.insert(parameters.begin(), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void addPrefix(const char* prefix) override
|
||||||
|
{
|
||||||
|
TSymbol::addPrefix(prefix);
|
||||||
|
mangledName.insert(0, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void removePrefix(const TString& prefix)
|
||||||
|
{
|
||||||
|
assert(mangledName.compare(0, prefix.size(), prefix) == 0);
|
||||||
|
mangledName.erase(0, prefix.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const TString& getMangledName() const override { return mangledName; }
|
||||||
|
virtual const TType& getType() const override { return returnType; }
|
||||||
|
virtual TBuiltInVariable getDeclaredBuiltInType() const { return declaredBuiltIn; }
|
||||||
|
virtual TType& getWritableType() override { return returnType; }
|
||||||
|
virtual void relateToOperator(TOperator o) { assert(writable); op = o; }
|
||||||
|
virtual TOperator getBuiltInOp() const { return op; }
|
||||||
|
virtual void setDefined() { assert(writable); defined = true; }
|
||||||
|
virtual bool isDefined() const { return defined; }
|
||||||
|
virtual void setPrototyped() { assert(writable); prototyped = true; }
|
||||||
|
virtual bool isPrototyped() const { return prototyped; }
|
||||||
|
virtual void setImplicitThis() { assert(writable); implicitThis = true; }
|
||||||
|
virtual bool hasImplicitThis() const { return implicitThis; }
|
||||||
|
virtual void setIllegalImplicitThis() { assert(writable); illegalImplicitThis = true; }
|
||||||
|
virtual bool hasIllegalImplicitThis() const { return illegalImplicitThis; }
|
||||||
|
|
||||||
|
// Return total number of parameters
|
||||||
|
virtual int getParamCount() const { return static_cast<int>(parameters.size()); }
|
||||||
|
// Return number of parameters with default values.
|
||||||
|
virtual int getDefaultParamCount() const { return defaultParamCount; }
|
||||||
|
// Return number of fixed parameters (without default values)
|
||||||
|
virtual int getFixedParamCount() const { return getParamCount() - getDefaultParamCount(); }
|
||||||
|
|
||||||
|
virtual TParameter& operator[](int i) { assert(writable); return parameters[i]; }
|
||||||
|
virtual const TParameter& operator[](int i) const { return parameters[i]; }
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
virtual void dump(TInfoSink& infoSink, bool complete = false) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit TFunction(const TFunction&);
|
||||||
|
TFunction& operator=(const TFunction&);
|
||||||
|
|
||||||
|
typedef TVector<TParameter> TParamList;
|
||||||
|
TParamList parameters;
|
||||||
|
TType returnType;
|
||||||
|
TBuiltInVariable declaredBuiltIn;
|
||||||
|
|
||||||
|
TString mangledName;
|
||||||
|
TOperator op;
|
||||||
|
bool defined;
|
||||||
|
bool prototyped;
|
||||||
|
bool implicitThis; // True if this function is allowed to see all members of 'this'
|
||||||
|
bool illegalImplicitThis; // True if this function is not supposed to have access to dynamic members of 'this',
|
||||||
|
// even if it finds member variables in the symbol table.
|
||||||
|
// This is important for a static member function that has member variables in scope,
|
||||||
|
// but is not allowed to use them, or see hidden symbols instead.
|
||||||
|
int defaultParamCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Members of anonymous blocks are a kind of TSymbol. They are not hidden in
|
||||||
|
// the symbol table behind a container; rather they are visible and point to
|
||||||
|
// their anonymous container. (The anonymous container is found through the
|
||||||
|
// member, not the other way around.)
|
||||||
|
//
|
||||||
|
class TAnonMember : public TSymbol {
|
||||||
|
public:
|
||||||
|
TAnonMember(const TString* n, unsigned int m, TVariable& a, int an) : TSymbol(n), anonContainer(a), memberNumber(m), anonId(an) { }
|
||||||
|
virtual TAnonMember* clone() const override;
|
||||||
|
virtual ~TAnonMember() { }
|
||||||
|
|
||||||
|
virtual const TAnonMember* getAsAnonMember() const override { return this; }
|
||||||
|
virtual const TVariable& getAnonContainer() const { return anonContainer; }
|
||||||
|
virtual unsigned int getMemberNumber() const { return memberNumber; }
|
||||||
|
|
||||||
|
virtual const TType& getType() const override
|
||||||
|
{
|
||||||
|
const TTypeList& types = *anonContainer.getType().getStruct();
|
||||||
|
return *types[memberNumber].type;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual TType& getWritableType() override
|
||||||
|
{
|
||||||
|
assert(writable);
|
||||||
|
const TTypeList& types = *anonContainer.getType().getStruct();
|
||||||
|
return *types[memberNumber].type;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setExtensions(int numExts, const char* const exts[]) override
|
||||||
|
{
|
||||||
|
anonContainer.setMemberExtensions(memberNumber, numExts, exts);
|
||||||
|
}
|
||||||
|
virtual int getNumExtensions() const override { return anonContainer.getNumMemberExtensions(memberNumber); }
|
||||||
|
virtual const char** getExtensions() const override { return anonContainer.getMemberExtensions(memberNumber); }
|
||||||
|
|
||||||
|
virtual int getAnonId() const { return anonId; }
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
virtual void dump(TInfoSink& infoSink, bool complete = false) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit TAnonMember(const TAnonMember&);
|
||||||
|
TAnonMember& operator=(const TAnonMember&);
|
||||||
|
|
||||||
|
TVariable& anonContainer;
|
||||||
|
unsigned int memberNumber;
|
||||||
|
int anonId;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TSymbolTableLevel {
|
||||||
|
public:
|
||||||
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
TSymbolTableLevel() : defaultPrecision(0), anonId(0), thisLevel(false) { }
|
||||||
|
~TSymbolTableLevel();
|
||||||
|
|
||||||
|
bool insert(TSymbol& symbol, bool separateNameSpaces)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// returning true means symbol was added to the table with no semantic errors
|
||||||
|
//
|
||||||
|
const TString& name = symbol.getName();
|
||||||
|
if (name == "") {
|
||||||
|
symbol.getAsVariable()->setAnonId(anonId++);
|
||||||
|
// An empty name means an anonymous container, exposing its members to the external scope.
|
||||||
|
// Give it a name and insert its members in the symbol table, pointing to the container.
|
||||||
|
char buf[20];
|
||||||
|
snprintf(buf, 20, "%s%d", AnonymousPrefix, symbol.getAsVariable()->getAnonId());
|
||||||
|
symbol.changeName(NewPoolTString(buf));
|
||||||
|
|
||||||
|
return insertAnonymousMembers(symbol, 0);
|
||||||
|
} else {
|
||||||
|
// Check for redefinition errors:
|
||||||
|
// - STL itself will tell us if there is a direct name collision, with name mangling, at this level
|
||||||
|
// - additionally, check for function-redefining-variable name collisions
|
||||||
|
const TString& insertName = symbol.getMangledName();
|
||||||
|
if (symbol.getAsFunction()) {
|
||||||
|
// make sure there isn't a variable of this name
|
||||||
|
if (! separateNameSpaces && level.find(name) != level.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// insert, and whatever happens is okay
|
||||||
|
level.insert(tLevelPair(insertName, &symbol));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return level.insert(tLevelPair(insertName, &symbol)).second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add more members to an already inserted aggregate object
|
||||||
|
bool amend(TSymbol& symbol, int firstNewMember)
|
||||||
|
{
|
||||||
|
// See insert() for comments on basic explanation of insert.
|
||||||
|
// This operates similarly, but more simply.
|
||||||
|
// Only supporting amend of anonymous blocks so far.
|
||||||
|
if (IsAnonymous(symbol.getName()))
|
||||||
|
return insertAnonymousMembers(symbol, firstNewMember);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool insertAnonymousMembers(TSymbol& symbol, int firstMember)
|
||||||
|
{
|
||||||
|
const TTypeList& types = *symbol.getAsVariable()->getType().getStruct();
|
||||||
|
for (unsigned int m = firstMember; m < types.size(); ++m) {
|
||||||
|
TAnonMember* member = new TAnonMember(&types[m].type->getFieldName(), m, *symbol.getAsVariable(), symbol.getAsVariable()->getAnonId());
|
||||||
|
if (! level.insert(tLevelPair(member->getMangledName(), member)).second)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSymbol* find(const TString& name) const
|
||||||
|
{
|
||||||
|
tLevel::const_iterator it = level.find(name);
|
||||||
|
if (it == level.end())
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return (*it).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void findFunctionNameList(const TString& name, TVector<const TFunction*>& list)
|
||||||
|
{
|
||||||
|
size_t parenAt = name.find_first_of('(');
|
||||||
|
TString base(name, 0, parenAt + 1);
|
||||||
|
|
||||||
|
tLevel::const_iterator begin = level.lower_bound(base);
|
||||||
|
base[parenAt] = ')'; // assume ')' is lexically after '('
|
||||||
|
tLevel::const_iterator end = level.upper_bound(base);
|
||||||
|
for (tLevel::const_iterator it = begin; it != end; ++it)
|
||||||
|
list.push_back(it->second->getAsFunction());
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if there is already a function in the table having the given non-function-style name.
|
||||||
|
bool hasFunctionName(const TString& name) const
|
||||||
|
{
|
||||||
|
tLevel::const_iterator candidate = level.lower_bound(name);
|
||||||
|
if (candidate != level.end()) {
|
||||||
|
const TString& candidateName = (*candidate).first;
|
||||||
|
TString::size_type parenAt = candidateName.find_first_of('(');
|
||||||
|
if (parenAt != candidateName.npos && candidateName.compare(0, parenAt, name) == 0)
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if there is a variable at this level having the given non-function-style name.
|
||||||
|
// Return true if name is found, and set variable to true if the name was a variable.
|
||||||
|
bool findFunctionVariableName(const TString& name, bool& variable) const
|
||||||
|
{
|
||||||
|
tLevel::const_iterator candidate = level.lower_bound(name);
|
||||||
|
if (candidate != level.end()) {
|
||||||
|
const TString& candidateName = (*candidate).first;
|
||||||
|
TString::size_type parenAt = candidateName.find_first_of('(');
|
||||||
|
if (parenAt == candidateName.npos) {
|
||||||
|
// not a mangled name
|
||||||
|
if (candidateName == name) {
|
||||||
|
// found a variable name match
|
||||||
|
variable = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// a mangled name
|
||||||
|
if (candidateName.compare(0, parenAt, name) == 0) {
|
||||||
|
// found a function name match
|
||||||
|
variable = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use this to do a lazy 'push' of precision defaults the first time
|
||||||
|
// a precision statement is seen in a new scope. Leave it at 0 for
|
||||||
|
// when no push was needed. Thus, it is not the current defaults,
|
||||||
|
// it is what to restore the defaults to when popping a level.
|
||||||
|
void setPreviousDefaultPrecisions(const TPrecisionQualifier *p)
|
||||||
|
{
|
||||||
|
// can call multiple times at one scope, will only latch on first call,
|
||||||
|
// as we're tracking the previous scope's values, not the current values
|
||||||
|
if (defaultPrecision != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
defaultPrecision = new TPrecisionQualifier[EbtNumTypes];
|
||||||
|
for (int t = 0; t < EbtNumTypes; ++t)
|
||||||
|
defaultPrecision[t] = p[t];
|
||||||
|
}
|
||||||
|
|
||||||
|
void getPreviousDefaultPrecisions(TPrecisionQualifier *p)
|
||||||
|
{
|
||||||
|
// can be called for table level pops that didn't set the
|
||||||
|
// defaults
|
||||||
|
if (defaultPrecision == 0 || p == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int t = 0; t < EbtNumTypes; ++t)
|
||||||
|
p[t] = defaultPrecision[t];
|
||||||
|
}
|
||||||
|
|
||||||
|
void relateToOperator(const char* name, TOperator op);
|
||||||
|
void setFunctionExtensions(const char* name, int num, const char* const extensions[]);
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
void dump(TInfoSink& infoSink, bool complete = false) const;
|
||||||
|
#endif
|
||||||
|
TSymbolTableLevel* clone() const;
|
||||||
|
void readOnly();
|
||||||
|
|
||||||
|
void setThisLevel() { thisLevel = true; }
|
||||||
|
bool isThisLevel() const { return thisLevel; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit TSymbolTableLevel(TSymbolTableLevel&);
|
||||||
|
TSymbolTableLevel& operator=(TSymbolTableLevel&);
|
||||||
|
|
||||||
|
typedef std::map<TString, TSymbol*, std::less<TString>, pool_allocator<std::pair<const TString, TSymbol*> > > tLevel;
|
||||||
|
typedef const tLevel::value_type tLevelPair;
|
||||||
|
typedef std::pair<tLevel::iterator, bool> tInsertResult;
|
||||||
|
|
||||||
|
tLevel level; // named mappings
|
||||||
|
TPrecisionQualifier *defaultPrecision;
|
||||||
|
int anonId;
|
||||||
|
bool thisLevel; // True if this level of the symbol table is a structure scope containing member function
|
||||||
|
// that are supposed to see anonymous access to member variables.
|
||||||
|
};
|
||||||
|
|
||||||
|
class TSymbolTable {
|
||||||
|
public:
|
||||||
|
TSymbolTable() : uniqueId(0), noBuiltInRedeclarations(false), separateNameSpaces(false), adoptedLevels(0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// This symbol table cannot be used until push() is called.
|
||||||
|
//
|
||||||
|
}
|
||||||
|
~TSymbolTable()
|
||||||
|
{
|
||||||
|
// this can be called explicitly; safest to code it so it can be called multiple times
|
||||||
|
|
||||||
|
// don't deallocate levels passed in from elsewhere
|
||||||
|
while (table.size() > adoptedLevels)
|
||||||
|
pop(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adoptLevels(TSymbolTable& symTable)
|
||||||
|
{
|
||||||
|
for (unsigned int level = 0; level < symTable.table.size(); ++level) {
|
||||||
|
table.push_back(symTable.table[level]);
|
||||||
|
++adoptedLevels;
|
||||||
|
}
|
||||||
|
uniqueId = symTable.uniqueId;
|
||||||
|
noBuiltInRedeclarations = symTable.noBuiltInRedeclarations;
|
||||||
|
separateNameSpaces = symTable.separateNameSpaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// While level adopting is generic, the methods below enact a the following
|
||||||
|
// convention for levels:
|
||||||
|
// 0: common built-ins shared across all stages, all compiles, only one copy for all symbol tables
|
||||||
|
// 1: per-stage built-ins, shared across all compiles, but a different copy per stage
|
||||||
|
// 2: built-ins specific to a compile, like resources that are context-dependent, or redeclared built-ins
|
||||||
|
// 3: user-shader globals
|
||||||
|
//
|
||||||
|
protected:
|
||||||
|
static const int globalLevel = 3;
|
||||||
|
bool isSharedLevel(int level) { return level <= 1; } // exclude all per-compile levels
|
||||||
|
bool isBuiltInLevel(int level) { return level <= 2; } // exclude user globals
|
||||||
|
bool isGlobalLevel(int level) { return level <= globalLevel; } // include user globals
|
||||||
|
public:
|
||||||
|
bool isEmpty() { return table.size() == 0; }
|
||||||
|
bool atBuiltInLevel() { return isBuiltInLevel(currentLevel()); }
|
||||||
|
bool atGlobalLevel() { return isGlobalLevel(currentLevel()); }
|
||||||
|
|
||||||
|
void setNoBuiltInRedeclarations() { noBuiltInRedeclarations = true; }
|
||||||
|
void setSeparateNameSpaces() { separateNameSpaces = true; }
|
||||||
|
|
||||||
|
void push()
|
||||||
|
{
|
||||||
|
table.push_back(new TSymbolTableLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a new symbol-table level to represent the scope introduced by a structure
|
||||||
|
// containing member functions, such that the member functions can find anonymous
|
||||||
|
// references to member variables.
|
||||||
|
//
|
||||||
|
// 'thisSymbol' should have a name of "" to trigger anonymous structure-member
|
||||||
|
// symbol finds.
|
||||||
|
void pushThis(TSymbol& thisSymbol)
|
||||||
|
{
|
||||||
|
assert(thisSymbol.getName().size() == 0);
|
||||||
|
table.push_back(new TSymbolTableLevel);
|
||||||
|
table.back()->setThisLevel();
|
||||||
|
insert(thisSymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop(TPrecisionQualifier *p)
|
||||||
|
{
|
||||||
|
table[currentLevel()]->getPreviousDefaultPrecisions(p);
|
||||||
|
delete table.back();
|
||||||
|
table.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Insert a visible symbol into the symbol table so it can
|
||||||
|
// be found later by name.
|
||||||
|
//
|
||||||
|
// Returns false if the was a name collision.
|
||||||
|
//
|
||||||
|
bool insert(TSymbol& symbol)
|
||||||
|
{
|
||||||
|
symbol.setUniqueId(++uniqueId);
|
||||||
|
|
||||||
|
// make sure there isn't a function of this variable name
|
||||||
|
if (! separateNameSpaces && ! symbol.getAsFunction() && table[currentLevel()]->hasFunctionName(symbol.getName()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// check for not overloading or redefining a built-in function
|
||||||
|
if (noBuiltInRedeclarations) {
|
||||||
|
if (atGlobalLevel() && currentLevel() > 0) {
|
||||||
|
if (table[0]->hasFunctionName(symbol.getName()))
|
||||||
|
return false;
|
||||||
|
if (currentLevel() > 1 && table[1]->hasFunctionName(symbol.getName()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return table[currentLevel()]->insert(symbol, separateNameSpaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add more members to an already inserted aggregate object
|
||||||
|
bool amend(TSymbol& symbol, int firstNewMember)
|
||||||
|
{
|
||||||
|
// See insert() for comments on basic explanation of insert.
|
||||||
|
// This operates similarly, but more simply.
|
||||||
|
return table[currentLevel()]->amend(symbol, firstNewMember);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// To allocate an internal temporary, which will need to be uniquely
|
||||||
|
// identified by the consumer of the AST, but never need to
|
||||||
|
// found by doing a symbol table search by name, hence allowed an
|
||||||
|
// arbitrary name in the symbol with no worry of collision.
|
||||||
|
//
|
||||||
|
void makeInternalVariable(TSymbol& symbol)
|
||||||
|
{
|
||||||
|
symbol.setUniqueId(++uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Copy a variable or anonymous member's structure from a shared level so that
|
||||||
|
// it can be added (soon after return) to the symbol table where it can be
|
||||||
|
// modified without impacting other users of the shared table.
|
||||||
|
//
|
||||||
|
TSymbol* copyUpDeferredInsert(TSymbol* shared)
|
||||||
|
{
|
||||||
|
if (shared->getAsVariable()) {
|
||||||
|
TSymbol* copy = shared->clone();
|
||||||
|
copy->setUniqueId(shared->getUniqueId());
|
||||||
|
return copy;
|
||||||
|
} else {
|
||||||
|
const TAnonMember* anon = shared->getAsAnonMember();
|
||||||
|
assert(anon);
|
||||||
|
TVariable* container = anon->getAnonContainer().clone();
|
||||||
|
container->changeName(NewPoolTString(""));
|
||||||
|
container->setUniqueId(anon->getAnonContainer().getUniqueId());
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TSymbol* copyUp(TSymbol* shared)
|
||||||
|
{
|
||||||
|
TSymbol* copy = copyUpDeferredInsert(shared);
|
||||||
|
table[globalLevel]->insert(*copy, separateNameSpaces);
|
||||||
|
if (shared->getAsVariable())
|
||||||
|
return copy;
|
||||||
|
else {
|
||||||
|
// return the copy of the anonymous member
|
||||||
|
return table[globalLevel]->find(shared->getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normal find of a symbol, that can optionally say whether the symbol was found
|
||||||
|
// at a built-in level or the current top-scope level.
|
||||||
|
TSymbol* find(const TString& name, bool* builtIn = 0, bool* currentScope = 0, int* thisDepthP = 0)
|
||||||
|
{
|
||||||
|
int level = currentLevel();
|
||||||
|
TSymbol* symbol;
|
||||||
|
int thisDepth = 0;
|
||||||
|
do {
|
||||||
|
if (table[level]->isThisLevel())
|
||||||
|
++thisDepth;
|
||||||
|
symbol = table[level]->find(name);
|
||||||
|
--level;
|
||||||
|
} while (symbol == nullptr && level >= 0);
|
||||||
|
level++;
|
||||||
|
if (builtIn)
|
||||||
|
*builtIn = isBuiltInLevel(level);
|
||||||
|
if (currentScope)
|
||||||
|
*currentScope = isGlobalLevel(currentLevel()) || level == currentLevel(); // consider shared levels as "current scope" WRT user globals
|
||||||
|
if (thisDepthP != nullptr) {
|
||||||
|
if (! table[level]->isThisLevel())
|
||||||
|
thisDepth = 0;
|
||||||
|
*thisDepthP = thisDepth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find of a symbol that returns how many layers deep of nested
|
||||||
|
// structures-with-member-functions ('this' scopes) deep the symbol was
|
||||||
|
// found in.
|
||||||
|
TSymbol* find(const TString& name, int& thisDepth)
|
||||||
|
{
|
||||||
|
int level = currentLevel();
|
||||||
|
TSymbol* symbol;
|
||||||
|
thisDepth = 0;
|
||||||
|
do {
|
||||||
|
if (table[level]->isThisLevel())
|
||||||
|
++thisDepth;
|
||||||
|
symbol = table[level]->find(name);
|
||||||
|
--level;
|
||||||
|
} while (symbol == 0 && level >= 0);
|
||||||
|
|
||||||
|
if (! table[level + 1]->isThisLevel())
|
||||||
|
thisDepth = 0;
|
||||||
|
|
||||||
|
return symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isFunctionNameVariable(const TString& name) const
|
||||||
|
{
|
||||||
|
if (separateNameSpaces)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int level = currentLevel();
|
||||||
|
do {
|
||||||
|
bool variable;
|
||||||
|
bool found = table[level]->findFunctionVariableName(name, variable);
|
||||||
|
if (found)
|
||||||
|
return variable;
|
||||||
|
--level;
|
||||||
|
} while (level >= 0);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void findFunctionNameList(const TString& name, TVector<const TFunction*>& list, bool& builtIn)
|
||||||
|
{
|
||||||
|
// For user levels, return the set found in the first scope with a match
|
||||||
|
builtIn = false;
|
||||||
|
int level = currentLevel();
|
||||||
|
do {
|
||||||
|
table[level]->findFunctionNameList(name, list);
|
||||||
|
--level;
|
||||||
|
} while (list.empty() && level >= globalLevel);
|
||||||
|
|
||||||
|
if (! list.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Gather across all built-in levels; they don't hide each other
|
||||||
|
builtIn = true;
|
||||||
|
do {
|
||||||
|
table[level]->findFunctionNameList(name, list);
|
||||||
|
--level;
|
||||||
|
} while (level >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void relateToOperator(const char* name, TOperator op)
|
||||||
|
{
|
||||||
|
for (unsigned int level = 0; level < table.size(); ++level)
|
||||||
|
table[level]->relateToOperator(name, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFunctionExtensions(const char* name, int num, const char* const extensions[])
|
||||||
|
{
|
||||||
|
for (unsigned int level = 0; level < table.size(); ++level)
|
||||||
|
table[level]->setFunctionExtensions(name, num, extensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVariableExtensions(const char* name, int numExts, const char* const extensions[])
|
||||||
|
{
|
||||||
|
TSymbol* symbol = find(TString(name));
|
||||||
|
if (symbol == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
symbol->setExtensions(numExts, extensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVariableExtensions(const char* blockName, const char* name, int numExts, const char* const extensions[])
|
||||||
|
{
|
||||||
|
TSymbol* symbol = find(TString(blockName));
|
||||||
|
if (symbol == nullptr)
|
||||||
|
return;
|
||||||
|
TVariable* variable = symbol->getAsVariable();
|
||||||
|
assert(variable != nullptr);
|
||||||
|
|
||||||
|
const TTypeList& structure = *variable->getAsVariable()->getType().getStruct();
|
||||||
|
for (int member = 0; member < (int)structure.size(); ++member) {
|
||||||
|
if (structure[member].type->getFieldName().compare(name) == 0) {
|
||||||
|
variable->setMemberExtensions(member, numExts, extensions);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getMaxSymbolId() { return uniqueId; }
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
void dump(TInfoSink& infoSink, bool complete = false) const;
|
||||||
|
#endif
|
||||||
|
void copyTable(const TSymbolTable& copyOf);
|
||||||
|
|
||||||
|
void setPreviousDefaultPrecisions(TPrecisionQualifier *p) { table[currentLevel()]->setPreviousDefaultPrecisions(p); }
|
||||||
|
|
||||||
|
void readOnly()
|
||||||
|
{
|
||||||
|
for (unsigned int level = 0; level < table.size(); ++level)
|
||||||
|
table[level]->readOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TSymbolTable(TSymbolTable&);
|
||||||
|
TSymbolTable& operator=(TSymbolTableLevel&);
|
||||||
|
|
||||||
|
int currentLevel() const { return static_cast<int>(table.size()) - 1; }
|
||||||
|
|
||||||
|
std::vector<TSymbolTableLevel*> table;
|
||||||
|
int uniqueId; // for unique identification in code generation
|
||||||
|
bool noBuiltInRedeclarations;
|
||||||
|
bool separateNameSpaces;
|
||||||
|
unsigned int adoptedLevels;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _SYMBOL_TABLE_INCLUDED_
|
||||||
|
|
@ -0,0 +1,332 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||||
|
// Copyright (C) 2017 ARM Limited.
|
||||||
|
// Copyright (C) 2015-2018 Google, Inc.
|
||||||
|
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _VERSIONS_INCLUDED_
|
||||||
|
#define _VERSIONS_INCLUDED_
|
||||||
|
|
||||||
|
#define LAST_ELEMENT_MARKER(x) x
|
||||||
|
|
||||||
|
//
|
||||||
|
// Help manage multiple profiles, versions, extensions etc.
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Profiles are set up for masking operations, so queries can be done on multiple
|
||||||
|
// profiles at the same time.
|
||||||
|
//
|
||||||
|
// Don't maintain an ordinal set of enums (0,1,2,3...) to avoid all possible
|
||||||
|
// defects from mixing the two different forms.
|
||||||
|
//
|
||||||
|
typedef enum : unsigned {
|
||||||
|
EBadProfile = 0,
|
||||||
|
ENoProfile = (1 << 0), // only for desktop, before profiles showed up
|
||||||
|
ECoreProfile = (1 << 1),
|
||||||
|
ECompatibilityProfile = (1 << 2),
|
||||||
|
EEsProfile = (1 << 3),
|
||||||
|
LAST_ELEMENT_MARKER(EProfileCount),
|
||||||
|
} EProfile;
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Map from profile enum to externally readable text name.
|
||||||
|
//
|
||||||
|
inline const char* ProfileName(EProfile profile)
|
||||||
|
{
|
||||||
|
switch (profile) {
|
||||||
|
case ENoProfile: return "none";
|
||||||
|
case ECoreProfile: return "core";
|
||||||
|
case ECompatibilityProfile: return "compatibility";
|
||||||
|
case EEsProfile: return "es";
|
||||||
|
default: return "unknown profile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// What source rules, validation rules, target language, etc. are needed or
|
||||||
|
// desired for SPIR-V?
|
||||||
|
//
|
||||||
|
// 0 means a target or rule set is not enabled (ignore rules from that entity).
|
||||||
|
// Non-0 means to apply semantic rules arising from that version of its rule set.
|
||||||
|
// The union of all requested rule sets will be applied.
|
||||||
|
//
|
||||||
|
struct SpvVersion {
|
||||||
|
SpvVersion() : spv(0), vulkanGlsl(0), vulkan(0), openGl(0) {}
|
||||||
|
unsigned int spv; // the version of SPIR-V to target, as defined by "word 1" of the SPIR-V binary header
|
||||||
|
int vulkanGlsl; // the version of GLSL semantics for Vulkan, from GL_KHR_vulkan_glsl, for "#define VULKAN XXX"
|
||||||
|
int vulkan; // the version of Vulkan, for which SPIR-V execution environment rules to use
|
||||||
|
int openGl; // the version of GLSL semantics for OpenGL, from GL_ARB_gl_spirv, for "#define GL_SPIRV XXX"
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// The behaviors from the GLSL "#extension extension_name : behavior"
|
||||||
|
//
|
||||||
|
typedef enum {
|
||||||
|
EBhMissing = 0,
|
||||||
|
EBhRequire,
|
||||||
|
EBhEnable,
|
||||||
|
EBhWarn,
|
||||||
|
EBhDisable,
|
||||||
|
EBhDisablePartial // use as initial state of an extension that is only partially implemented
|
||||||
|
} TExtensionBehavior;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Symbolic names for extensions. Strings may be directly used when calling the
|
||||||
|
// functions, but better to have the compiler do spelling checks.
|
||||||
|
//
|
||||||
|
const char* const E_GL_OES_texture_3D = "GL_OES_texture_3D";
|
||||||
|
const char* const E_GL_OES_standard_derivatives = "GL_OES_standard_derivatives";
|
||||||
|
const char* const E_GL_EXT_frag_depth = "GL_EXT_frag_depth";
|
||||||
|
const char* const E_GL_OES_EGL_image_external = "GL_OES_EGL_image_external";
|
||||||
|
const char* const E_GL_OES_EGL_image_external_essl3 = "GL_OES_EGL_image_external_essl3";
|
||||||
|
const char* const E_GL_EXT_YUV_target = "GL_EXT_YUV_target";
|
||||||
|
const char* const E_GL_EXT_shader_texture_lod = "GL_EXT_shader_texture_lod";
|
||||||
|
const char* const E_GL_EXT_shadow_samplers = "GL_EXT_shadow_samplers";
|
||||||
|
|
||||||
|
const char* const E_GL_ARB_texture_rectangle = "GL_ARB_texture_rectangle";
|
||||||
|
const char* const E_GL_3DL_array_objects = "GL_3DL_array_objects";
|
||||||
|
const char* const E_GL_ARB_shading_language_420pack = "GL_ARB_shading_language_420pack";
|
||||||
|
const char* const E_GL_ARB_texture_gather = "GL_ARB_texture_gather";
|
||||||
|
const char* const E_GL_ARB_gpu_shader5 = "GL_ARB_gpu_shader5";
|
||||||
|
const char* const E_GL_ARB_separate_shader_objects = "GL_ARB_separate_shader_objects";
|
||||||
|
const char* const E_GL_ARB_compute_shader = "GL_ARB_compute_shader";
|
||||||
|
const char* const E_GL_ARB_tessellation_shader = "GL_ARB_tessellation_shader";
|
||||||
|
const char* const E_GL_ARB_enhanced_layouts = "GL_ARB_enhanced_layouts";
|
||||||
|
const char* const E_GL_ARB_texture_cube_map_array = "GL_ARB_texture_cube_map_array";
|
||||||
|
const char* const E_GL_ARB_texture_multisample = "GL_ARB_texture_multisample";
|
||||||
|
const char* const E_GL_ARB_shader_texture_lod = "GL_ARB_shader_texture_lod";
|
||||||
|
const char* const E_GL_ARB_explicit_attrib_location = "GL_ARB_explicit_attrib_location";
|
||||||
|
const char* const E_GL_ARB_explicit_uniform_location = "GL_ARB_explicit_uniform_location";
|
||||||
|
const char* const E_GL_ARB_shader_image_load_store = "GL_ARB_shader_image_load_store";
|
||||||
|
const char* const E_GL_ARB_shader_atomic_counters = "GL_ARB_shader_atomic_counters";
|
||||||
|
const char* const E_GL_ARB_shader_draw_parameters = "GL_ARB_shader_draw_parameters";
|
||||||
|
const char* const E_GL_ARB_shader_group_vote = "GL_ARB_shader_group_vote";
|
||||||
|
const char* const E_GL_ARB_derivative_control = "GL_ARB_derivative_control";
|
||||||
|
const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_image_samples";
|
||||||
|
const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
|
||||||
|
const char* const E_GL_ARB_gpu_shader_int64 = "GL_ARB_gpu_shader_int64";
|
||||||
|
const char* const E_GL_ARB_gpu_shader_fp64 = "GL_ARB_gpu_shader_fp64";
|
||||||
|
const char* const E_GL_ARB_shader_ballot = "GL_ARB_shader_ballot";
|
||||||
|
const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture2";
|
||||||
|
const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp";
|
||||||
|
const char* const E_GL_ARB_shader_stencil_export = "GL_ARB_shader_stencil_export";
|
||||||
|
// const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
|
||||||
|
const char* const E_GL_ARB_post_depth_coverage = "GL_ARB_post_depth_coverage";
|
||||||
|
const char* const E_GL_ARB_shader_viewport_layer_array = "GL_ARB_shader_viewport_layer_array";
|
||||||
|
const char* const E_GL_ARB_fragment_shader_interlock = "GL_ARB_fragment_shader_interlock";
|
||||||
|
const char* const E_GL_ARB_shader_clock = "GL_ARB_shader_clock";
|
||||||
|
const char* const E_GL_ARB_uniform_buffer_object = "GL_ARB_uniform_buffer_object";
|
||||||
|
const char* const E_GL_ARB_sample_shading = "GL_ARB_sample_shading";
|
||||||
|
const char* const E_GL_ARB_shader_bit_encoding = "GL_ARB_shader_bit_encoding";
|
||||||
|
const char* const E_GL_ARB_shader_image_size = "GL_ARB_shader_image_size";
|
||||||
|
const char* const E_GL_ARB_shader_storage_buffer_object = "GL_ARB_shader_storage_buffer_object";
|
||||||
|
const char* const E_GL_ARB_shading_language_packing = "GL_ARB_shading_language_packing";
|
||||||
|
const char* const E_GL_ARB_texture_query_lod = "GL_ARB_texture_query_lod";
|
||||||
|
const char* const E_GL_ARB_vertex_attrib_64bit = "GL_ARB_vertex_attrib_64bit";
|
||||||
|
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_basic = "GL_KHR_shader_subgroup_basic";
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_vote = "GL_KHR_shader_subgroup_vote";
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_arithmetic = "GL_KHR_shader_subgroup_arithmetic";
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_ballot = "GL_KHR_shader_subgroup_ballot";
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_shuffle = "GL_KHR_shader_subgroup_shuffle";
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_shuffle_relative = "GL_KHR_shader_subgroup_shuffle_relative";
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_clustered = "GL_KHR_shader_subgroup_clustered";
|
||||||
|
const char* const E_GL_KHR_shader_subgroup_quad = "GL_KHR_shader_subgroup_quad";
|
||||||
|
const char* const E_GL_KHR_memory_scope_semantics = "GL_KHR_memory_scope_semantics";
|
||||||
|
|
||||||
|
const char* const E_GL_EXT_shader_atomic_int64 = "GL_EXT_shader_atomic_int64";
|
||||||
|
|
||||||
|
const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers";
|
||||||
|
const char* const E_GL_EXT_shader_image_load_formatted = "GL_EXT_shader_image_load_formatted";
|
||||||
|
|
||||||
|
const char* const E_GL_EXT_shader_16bit_storage = "GL_EXT_shader_16bit_storage";
|
||||||
|
const char* const E_GL_EXT_shader_8bit_storage = "GL_EXT_shader_8bit_storage";
|
||||||
|
|
||||||
|
|
||||||
|
// EXT extensions
|
||||||
|
const char* const E_GL_EXT_device_group = "GL_EXT_device_group";
|
||||||
|
const char* const E_GL_EXT_multiview = "GL_EXT_multiview";
|
||||||
|
const char* const E_GL_EXT_post_depth_coverage = "GL_EXT_post_depth_coverage";
|
||||||
|
const char* const E_GL_EXT_control_flow_attributes = "GL_EXT_control_flow_attributes";
|
||||||
|
const char* const E_GL_EXT_nonuniform_qualifier = "GL_EXT_nonuniform_qualifier";
|
||||||
|
const char* const E_GL_EXT_samplerless_texture_functions = "GL_EXT_samplerless_texture_functions";
|
||||||
|
const char* const E_GL_EXT_scalar_block_layout = "GL_EXT_scalar_block_layout";
|
||||||
|
const char* const E_GL_EXT_fragment_invocation_density = "GL_EXT_fragment_invocation_density";
|
||||||
|
const char* const E_GL_EXT_buffer_reference = "GL_EXT_buffer_reference";
|
||||||
|
const char* const E_GL_EXT_buffer_reference2 = "GL_EXT_buffer_reference2";
|
||||||
|
const char* const E_GL_EXT_buffer_reference_uvec2 = "GL_EXT_buffer_reference_uvec2";
|
||||||
|
const char* const E_GL_EXT_demote_to_helper_invocation = "GL_EXT_demote_to_helper_invocation";
|
||||||
|
const char* const E_GL_EXT_shader_realtime_clock = "GL_EXT_shader_realtime_clock";
|
||||||
|
const char* const E_GL_EXT_debug_printf = "GL_EXT_debug_printf";
|
||||||
|
const char* const E_GL_EXT_ray_tracing = "GL_EXT_ray_tracing";
|
||||||
|
const char* const E_GL_EXT_ray_query = "GL_EXT_ray_query";
|
||||||
|
const char* const E_GL_EXT_ray_flags_primitive_culling = "GL_EXT_ray_flags_primitive_culling";
|
||||||
|
const char* const E_GL_EXT_blend_func_extended = "GL_EXT_blend_func_extended";
|
||||||
|
const char* const E_GL_EXT_shader_implicit_conversions = "GL_EXT_shader_implicit_conversions";
|
||||||
|
|
||||||
|
// Arrays of extensions for the above viewportEXTs duplications
|
||||||
|
|
||||||
|
const char* const post_depth_coverageEXTs[] = { E_GL_ARB_post_depth_coverage, E_GL_EXT_post_depth_coverage };
|
||||||
|
const int Num_post_depth_coverageEXTs = sizeof(post_depth_coverageEXTs) / sizeof(post_depth_coverageEXTs[0]);
|
||||||
|
|
||||||
|
// OVR extensions
|
||||||
|
const char* const E_GL_OVR_multiview = "GL_OVR_multiview";
|
||||||
|
const char* const E_GL_OVR_multiview2 = "GL_OVR_multiview2";
|
||||||
|
|
||||||
|
const char* const OVR_multiview_EXTs[] = { E_GL_OVR_multiview, E_GL_OVR_multiview2 };
|
||||||
|
const int Num_OVR_multiview_EXTs = sizeof(OVR_multiview_EXTs) / sizeof(OVR_multiview_EXTs[0]);
|
||||||
|
|
||||||
|
// #line and #include
|
||||||
|
const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive";
|
||||||
|
const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";
|
||||||
|
|
||||||
|
const char* const E_GL_AMD_shader_ballot = "GL_AMD_shader_ballot";
|
||||||
|
const char* const E_GL_AMD_shader_trinary_minmax = "GL_AMD_shader_trinary_minmax";
|
||||||
|
const char* const E_GL_AMD_shader_explicit_vertex_parameter = "GL_AMD_shader_explicit_vertex_parameter";
|
||||||
|
const char* const E_GL_AMD_gcn_shader = "GL_AMD_gcn_shader";
|
||||||
|
const char* const E_GL_AMD_gpu_shader_half_float = "GL_AMD_gpu_shader_half_float";
|
||||||
|
const char* const E_GL_AMD_texture_gather_bias_lod = "GL_AMD_texture_gather_bias_lod";
|
||||||
|
const char* const E_GL_AMD_gpu_shader_int16 = "GL_AMD_gpu_shader_int16";
|
||||||
|
const char* const E_GL_AMD_shader_image_load_store_lod = "GL_AMD_shader_image_load_store_lod";
|
||||||
|
const char* const E_GL_AMD_shader_fragment_mask = "GL_AMD_shader_fragment_mask";
|
||||||
|
const char* const E_GL_AMD_gpu_shader_half_float_fetch = "GL_AMD_gpu_shader_half_float_fetch";
|
||||||
|
|
||||||
|
const char* const E_GL_INTEL_shader_integer_functions2 = "GL_INTEL_shader_integer_functions2";
|
||||||
|
|
||||||
|
const char* const E_GL_NV_sample_mask_override_coverage = "GL_NV_sample_mask_override_coverage";
|
||||||
|
const char* const E_SPV_NV_geometry_shader_passthrough = "GL_NV_geometry_shader_passthrough";
|
||||||
|
const char* const E_GL_NV_viewport_array2 = "GL_NV_viewport_array2";
|
||||||
|
const char* const E_GL_NV_stereo_view_rendering = "GL_NV_stereo_view_rendering";
|
||||||
|
const char* const E_GL_NVX_multiview_per_view_attributes = "GL_NVX_multiview_per_view_attributes";
|
||||||
|
const char* const E_GL_NV_shader_atomic_int64 = "GL_NV_shader_atomic_int64";
|
||||||
|
const char* const E_GL_NV_conservative_raster_underestimation = "GL_NV_conservative_raster_underestimation";
|
||||||
|
const char* const E_GL_NV_shader_noperspective_interpolation = "GL_NV_shader_noperspective_interpolation";
|
||||||
|
const char* const E_GL_NV_shader_subgroup_partitioned = "GL_NV_shader_subgroup_partitioned";
|
||||||
|
const char* const E_GL_NV_shading_rate_image = "GL_NV_shading_rate_image";
|
||||||
|
const char* const E_GL_NV_ray_tracing = "GL_NV_ray_tracing";
|
||||||
|
const char* const E_GL_NV_fragment_shader_barycentric = "GL_NV_fragment_shader_barycentric";
|
||||||
|
const char* const E_GL_NV_compute_shader_derivatives = "GL_NV_compute_shader_derivatives";
|
||||||
|
const char* const E_GL_NV_shader_texture_footprint = "GL_NV_shader_texture_footprint";
|
||||||
|
const char* const E_GL_NV_mesh_shader = "GL_NV_mesh_shader";
|
||||||
|
|
||||||
|
// Arrays of extensions for the above viewportEXTs duplications
|
||||||
|
|
||||||
|
const char* const viewportEXTs[] = { E_GL_ARB_shader_viewport_layer_array, E_GL_NV_viewport_array2 };
|
||||||
|
const int Num_viewportEXTs = sizeof(viewportEXTs) / sizeof(viewportEXTs[0]);
|
||||||
|
|
||||||
|
const char* const E_GL_NV_cooperative_matrix = "GL_NV_cooperative_matrix";
|
||||||
|
const char* const E_GL_NV_shader_sm_builtins = "GL_NV_shader_sm_builtins";
|
||||||
|
const char* const E_GL_NV_integer_cooperative_matrix = "GL_NV_integer_cooperative_matrix";
|
||||||
|
|
||||||
|
// AEP
|
||||||
|
const char* const E_GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";
|
||||||
|
const char* const E_GL_KHR_blend_equation_advanced = "GL_KHR_blend_equation_advanced";
|
||||||
|
const char* const E_GL_OES_sample_variables = "GL_OES_sample_variables";
|
||||||
|
const char* const E_GL_OES_shader_image_atomic = "GL_OES_shader_image_atomic";
|
||||||
|
const char* const E_GL_OES_shader_multisample_interpolation = "GL_OES_shader_multisample_interpolation";
|
||||||
|
const char* const E_GL_OES_texture_storage_multisample_2d_array = "GL_OES_texture_storage_multisample_2d_array";
|
||||||
|
const char* const E_GL_EXT_geometry_shader = "GL_EXT_geometry_shader";
|
||||||
|
const char* const E_GL_EXT_geometry_point_size = "GL_EXT_geometry_point_size";
|
||||||
|
const char* const E_GL_EXT_gpu_shader5 = "GL_EXT_gpu_shader5";
|
||||||
|
const char* const E_GL_EXT_primitive_bounding_box = "GL_EXT_primitive_bounding_box";
|
||||||
|
const char* const E_GL_EXT_shader_io_blocks = "GL_EXT_shader_io_blocks";
|
||||||
|
const char* const E_GL_EXT_tessellation_shader = "GL_EXT_tessellation_shader";
|
||||||
|
const char* const E_GL_EXT_tessellation_point_size = "GL_EXT_tessellation_point_size";
|
||||||
|
const char* const E_GL_EXT_texture_buffer = "GL_EXT_texture_buffer";
|
||||||
|
const char* const E_GL_EXT_texture_cube_map_array = "GL_EXT_texture_cube_map_array";
|
||||||
|
const char* const E_GL_EXT_shader_integer_mix = "GL_EXT_shader_integer_mix";
|
||||||
|
|
||||||
|
// OES matching AEP
|
||||||
|
const char* const E_GL_OES_geometry_shader = "GL_OES_geometry_shader";
|
||||||
|
const char* const E_GL_OES_geometry_point_size = "GL_OES_geometry_point_size";
|
||||||
|
const char* const E_GL_OES_gpu_shader5 = "GL_OES_gpu_shader5";
|
||||||
|
const char* const E_GL_OES_primitive_bounding_box = "GL_OES_primitive_bounding_box";
|
||||||
|
const char* const E_GL_OES_shader_io_blocks = "GL_OES_shader_io_blocks";
|
||||||
|
const char* const E_GL_OES_tessellation_shader = "GL_OES_tessellation_shader";
|
||||||
|
const char* const E_GL_OES_tessellation_point_size = "GL_OES_tessellation_point_size";
|
||||||
|
const char* const E_GL_OES_texture_buffer = "GL_OES_texture_buffer";
|
||||||
|
const char* const E_GL_OES_texture_cube_map_array = "GL_OES_texture_cube_map_array";
|
||||||
|
|
||||||
|
// EXT
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types = "GL_EXT_shader_explicit_arithmetic_types";
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int8 = "GL_EXT_shader_explicit_arithmetic_types_int8";
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int16 = "GL_EXT_shader_explicit_arithmetic_types_int16";
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int32 = "GL_EXT_shader_explicit_arithmetic_types_int32";
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int64 = "GL_EXT_shader_explicit_arithmetic_types_int64";
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float16 = "GL_EXT_shader_explicit_arithmetic_types_float16";
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float32 = "GL_EXT_shader_explicit_arithmetic_types_float32";
|
||||||
|
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float64 = "GL_EXT_shader_explicit_arithmetic_types_float64";
|
||||||
|
|
||||||
|
const char* const E_GL_EXT_shader_subgroup_extended_types_int8 = "GL_EXT_shader_subgroup_extended_types_int8";
|
||||||
|
const char* const E_GL_EXT_shader_subgroup_extended_types_int16 = "GL_EXT_shader_subgroup_extended_types_int16";
|
||||||
|
const char* const E_GL_EXT_shader_subgroup_extended_types_int64 = "GL_EXT_shader_subgroup_extended_types_int64";
|
||||||
|
const char* const E_GL_EXT_shader_subgroup_extended_types_float16 = "GL_EXT_shader_subgroup_extended_types_float16";
|
||||||
|
|
||||||
|
// Arrays of extensions for the above AEP duplications
|
||||||
|
|
||||||
|
const char* const AEP_geometry_shader[] = { E_GL_EXT_geometry_shader, E_GL_OES_geometry_shader };
|
||||||
|
const int Num_AEP_geometry_shader = sizeof(AEP_geometry_shader)/sizeof(AEP_geometry_shader[0]);
|
||||||
|
|
||||||
|
const char* const AEP_geometry_point_size[] = { E_GL_EXT_geometry_point_size, E_GL_OES_geometry_point_size };
|
||||||
|
const int Num_AEP_geometry_point_size = sizeof(AEP_geometry_point_size)/sizeof(AEP_geometry_point_size[0]);
|
||||||
|
|
||||||
|
const char* const AEP_gpu_shader5[] = { E_GL_EXT_gpu_shader5, E_GL_OES_gpu_shader5 };
|
||||||
|
const int Num_AEP_gpu_shader5 = sizeof(AEP_gpu_shader5)/sizeof(AEP_gpu_shader5[0]);
|
||||||
|
|
||||||
|
const char* const AEP_primitive_bounding_box[] = { E_GL_EXT_primitive_bounding_box, E_GL_OES_primitive_bounding_box };
|
||||||
|
const int Num_AEP_primitive_bounding_box = sizeof(AEP_primitive_bounding_box)/sizeof(AEP_primitive_bounding_box[0]);
|
||||||
|
|
||||||
|
const char* const AEP_shader_io_blocks[] = { E_GL_EXT_shader_io_blocks, E_GL_OES_shader_io_blocks };
|
||||||
|
const int Num_AEP_shader_io_blocks = sizeof(AEP_shader_io_blocks)/sizeof(AEP_shader_io_blocks[0]);
|
||||||
|
|
||||||
|
const char* const AEP_tessellation_shader[] = { E_GL_EXT_tessellation_shader, E_GL_OES_tessellation_shader };
|
||||||
|
const int Num_AEP_tessellation_shader = sizeof(AEP_tessellation_shader)/sizeof(AEP_tessellation_shader[0]);
|
||||||
|
|
||||||
|
const char* const AEP_tessellation_point_size[] = { E_GL_EXT_tessellation_point_size, E_GL_OES_tessellation_point_size };
|
||||||
|
const int Num_AEP_tessellation_point_size = sizeof(AEP_tessellation_point_size)/sizeof(AEP_tessellation_point_size[0]);
|
||||||
|
|
||||||
|
const char* const AEP_texture_buffer[] = { E_GL_EXT_texture_buffer, E_GL_OES_texture_buffer };
|
||||||
|
const int Num_AEP_texture_buffer = sizeof(AEP_texture_buffer)/sizeof(AEP_texture_buffer[0]);
|
||||||
|
|
||||||
|
const char* const AEP_texture_cube_map_array[] = { E_GL_EXT_texture_cube_map_array, E_GL_OES_texture_cube_map_array };
|
||||||
|
const int Num_AEP_texture_cube_map_array = sizeof(AEP_texture_cube_map_array)/sizeof(AEP_texture_cube_map_array[0]);
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _VERSIONS_INCLUDED_
|
||||||
|
|
@ -0,0 +1,149 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2017 LunarG, Inc.
|
||||||
|
// Copyright (C) 2018 Google, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _ATTRIBUTE_INCLUDED_
|
||||||
|
#define _ATTRIBUTE_INCLUDED_
|
||||||
|
|
||||||
|
#include "../Include/Common.h"
|
||||||
|
#include "../Include/ConstantUnion.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
enum TAttributeType {
|
||||||
|
EatNone,
|
||||||
|
EatAllow_uav_condition,
|
||||||
|
EatBranch,
|
||||||
|
EatCall,
|
||||||
|
EatDomain,
|
||||||
|
EatEarlyDepthStencil,
|
||||||
|
EatFastOpt,
|
||||||
|
EatFlatten,
|
||||||
|
EatForceCase,
|
||||||
|
EatInstance,
|
||||||
|
EatMaxTessFactor,
|
||||||
|
EatNumThreads,
|
||||||
|
EatMaxVertexCount,
|
||||||
|
EatOutputControlPoints,
|
||||||
|
EatOutputTopology,
|
||||||
|
EatPartitioning,
|
||||||
|
EatPatchConstantFunc,
|
||||||
|
EatPatchSize,
|
||||||
|
EatUnroll,
|
||||||
|
EatLoop,
|
||||||
|
EatBinding,
|
||||||
|
EatGlobalBinding,
|
||||||
|
EatLocation,
|
||||||
|
EatInputAttachment,
|
||||||
|
EatBuiltIn,
|
||||||
|
EatPushConstant,
|
||||||
|
EatConstantId,
|
||||||
|
EatDependencyInfinite,
|
||||||
|
EatDependencyLength,
|
||||||
|
EatMinIterations,
|
||||||
|
EatMaxIterations,
|
||||||
|
EatIterationMultiple,
|
||||||
|
EatPeelCount,
|
||||||
|
EatPartialCount,
|
||||||
|
EatFormatRgba32f,
|
||||||
|
EatFormatRgba16f,
|
||||||
|
EatFormatR32f,
|
||||||
|
EatFormatRgba8,
|
||||||
|
EatFormatRgba8Snorm,
|
||||||
|
EatFormatRg32f,
|
||||||
|
EatFormatRg16f,
|
||||||
|
EatFormatR11fG11fB10f,
|
||||||
|
EatFormatR16f,
|
||||||
|
EatFormatRgba16,
|
||||||
|
EatFormatRgb10A2,
|
||||||
|
EatFormatRg16,
|
||||||
|
EatFormatRg8,
|
||||||
|
EatFormatR16,
|
||||||
|
EatFormatR8,
|
||||||
|
EatFormatRgba16Snorm,
|
||||||
|
EatFormatRg16Snorm,
|
||||||
|
EatFormatRg8Snorm,
|
||||||
|
EatFormatR16Snorm,
|
||||||
|
EatFormatR8Snorm,
|
||||||
|
EatFormatRgba32i,
|
||||||
|
EatFormatRgba16i,
|
||||||
|
EatFormatRgba8i,
|
||||||
|
EatFormatR32i,
|
||||||
|
EatFormatRg32i,
|
||||||
|
EatFormatRg16i,
|
||||||
|
EatFormatRg8i,
|
||||||
|
EatFormatR16i,
|
||||||
|
EatFormatR8i,
|
||||||
|
EatFormatRgba32ui,
|
||||||
|
EatFormatRgba16ui,
|
||||||
|
EatFormatRgba8ui,
|
||||||
|
EatFormatR32ui,
|
||||||
|
EatFormatRgb10a2ui,
|
||||||
|
EatFormatRg32ui,
|
||||||
|
EatFormatRg16ui,
|
||||||
|
EatFormatRg8ui,
|
||||||
|
EatFormatR16ui,
|
||||||
|
EatFormatR8ui,
|
||||||
|
EatFormatUnknown,
|
||||||
|
EatNonWritable,
|
||||||
|
EatNonReadable
|
||||||
|
};
|
||||||
|
|
||||||
|
class TIntermAggregate;
|
||||||
|
|
||||||
|
struct TAttributeArgs {
|
||||||
|
TAttributeType name;
|
||||||
|
const TIntermAggregate* args;
|
||||||
|
|
||||||
|
// Obtain attribute as integer
|
||||||
|
// Return false if it cannot be obtained
|
||||||
|
bool getInt(int& value, int argNum = 0) const;
|
||||||
|
|
||||||
|
// Obtain attribute as string, with optional to-lower transform
|
||||||
|
// Return false if it cannot be obtained
|
||||||
|
bool getString(TString& value, int argNum = 0, bool convertToLower = true) const;
|
||||||
|
|
||||||
|
// How many arguments were provided to the attribute?
|
||||||
|
int size() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const TConstUnion* getConstUnion(TBasicType basicType, int argNum) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef TList<TAttributeArgs> TAttributes;
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _ATTRIBUTE_INCLUDED_
|
||||||
|
|
@ -0,0 +1,210 @@
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2013 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define GL_FLOAT 0x1406
|
||||||
|
#define GL_FLOAT_VEC2 0x8B50
|
||||||
|
#define GL_FLOAT_VEC3 0x8B51
|
||||||
|
#define GL_FLOAT_VEC4 0x8B52
|
||||||
|
|
||||||
|
#define GL_DOUBLE 0x140A
|
||||||
|
#define GL_DOUBLE_VEC2 0x8FFC
|
||||||
|
#define GL_DOUBLE_VEC3 0x8FFD
|
||||||
|
#define GL_DOUBLE_VEC4 0x8FFE
|
||||||
|
|
||||||
|
#define GL_INT 0x1404
|
||||||
|
#define GL_INT_VEC2 0x8B53
|
||||||
|
#define GL_INT_VEC3 0x8B54
|
||||||
|
#define GL_INT_VEC4 0x8B55
|
||||||
|
|
||||||
|
#define GL_UNSIGNED_INT 0x1405
|
||||||
|
#define GL_UNSIGNED_INT_VEC2 0x8DC6
|
||||||
|
#define GL_UNSIGNED_INT_VEC3 0x8DC7
|
||||||
|
#define GL_UNSIGNED_INT_VEC4 0x8DC8
|
||||||
|
|
||||||
|
#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_ARB 0x140F
|
||||||
|
#define GL_UNSIGNED_INT64_VEC2_ARB 0x8FE5
|
||||||
|
#define GL_UNSIGNED_INT64_VEC3_ARB 0x8FE6
|
||||||
|
#define GL_UNSIGNED_INT64_VEC4_ARB 0x8FE7
|
||||||
|
|
||||||
|
#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_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_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
|
||||||
|
|
||||||
|
// Those constants are borrowed from extension NV_gpu_shader5
|
||||||
|
#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
|
||||||
|
|
||||||
|
#define GL_SAMPLER_1D 0x8B5D
|
||||||
|
#define GL_SAMPLER_2D 0x8B5E
|
||||||
|
#define GL_SAMPLER_3D 0x8B5F
|
||||||
|
#define GL_SAMPLER_CUBE 0x8B60
|
||||||
|
#define GL_SAMPLER_BUFFER 0x8DC2
|
||||||
|
#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_SAMPLER_1D_SHADOW 0x8B61
|
||||||
|
#define GL_SAMPLER_2D_SHADOW 0x8B62
|
||||||
|
#define GL_SAMPLER_2D_RECT 0x8B63
|
||||||
|
#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64
|
||||||
|
#define GL_SAMPLER_2D_MULTISAMPLE 0x9108
|
||||||
|
#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B
|
||||||
|
#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C
|
||||||
|
#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D
|
||||||
|
#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C
|
||||||
|
#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D
|
||||||
|
|
||||||
|
#define GL_FLOAT16_SAMPLER_1D_AMD 0x91CE
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_AMD 0x91CF
|
||||||
|
#define GL_FLOAT16_SAMPLER_3D_AMD 0x91D0
|
||||||
|
#define GL_FLOAT16_SAMPLER_CUBE_AMD 0x91D1
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_RECT_AMD 0x91D2
|
||||||
|
#define GL_FLOAT16_SAMPLER_1D_ARRAY_AMD 0x91D3
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_ARRAY_AMD 0x91D4
|
||||||
|
#define GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_AMD 0x91D5
|
||||||
|
#define GL_FLOAT16_SAMPLER_BUFFER_AMD 0x91D6
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_AMD 0x91D7
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_ARRAY_AMD 0x91D8
|
||||||
|
|
||||||
|
#define GL_FLOAT16_SAMPLER_1D_SHADOW_AMD 0x91D9
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_SHADOW_AMD 0x91DA
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_RECT_SHADOW_AMD 0x91DB
|
||||||
|
#define GL_FLOAT16_SAMPLER_1D_ARRAY_SHADOW_AMD 0x91DC
|
||||||
|
#define GL_FLOAT16_SAMPLER_2D_ARRAY_SHADOW_AMD 0x91DD
|
||||||
|
#define GL_FLOAT16_SAMPLER_CUBE_SHADOW_AMD 0x91DE
|
||||||
|
#define GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_SHADOW_AMD 0x91DF
|
||||||
|
|
||||||
|
#define GL_FLOAT16_IMAGE_1D_AMD 0x91E0
|
||||||
|
#define GL_FLOAT16_IMAGE_2D_AMD 0x91E1
|
||||||
|
#define GL_FLOAT16_IMAGE_3D_AMD 0x91E2
|
||||||
|
#define GL_FLOAT16_IMAGE_2D_RECT_AMD 0x91E3
|
||||||
|
#define GL_FLOAT16_IMAGE_CUBE_AMD 0x91E4
|
||||||
|
#define GL_FLOAT16_IMAGE_1D_ARRAY_AMD 0x91E5
|
||||||
|
#define GL_FLOAT16_IMAGE_2D_ARRAY_AMD 0x91E6
|
||||||
|
#define GL_FLOAT16_IMAGE_CUBE_MAP_ARRAY_AMD 0x91E7
|
||||||
|
#define GL_FLOAT16_IMAGE_BUFFER_AMD 0x91E8
|
||||||
|
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_AMD 0x91E9
|
||||||
|
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_ARRAY_AMD 0x91EA
|
||||||
|
|
||||||
|
#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_INT_SAMPLER_2D_RECT 0x8DCD
|
||||||
|
#define GL_INT_SAMPLER_BUFFER 0x8DD0
|
||||||
|
#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109
|
||||||
|
#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C
|
||||||
|
#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E
|
||||||
|
#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E
|
||||||
|
|
||||||
|
#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_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5
|
||||||
|
#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8
|
||||||
|
#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D
|
||||||
|
#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F
|
||||||
|
#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F
|
||||||
|
#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A
|
||||||
|
|
||||||
|
#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_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB
|
||||||
|
|
@ -0,0 +1,521 @@
|
||||||
|
/* A Bison parser, made by GNU Bison 3.0.4. */
|
||||||
|
|
||||||
|
/* Bison interface for Yacc-like parsers in C
|
||||||
|
|
||||||
|
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* As a special exception, you may create a larger work that contains
|
||||||
|
part or all of the Bison parser skeleton and distribute that work
|
||||||
|
under terms of your choice, so long as that work isn't itself a
|
||||||
|
parser generator using the skeleton or a modified version thereof
|
||||||
|
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||||
|
the parser skeleton itself, you may (at your option) remove this
|
||||||
|
special exception, which will cause the skeleton and the resulting
|
||||||
|
Bison output files to be licensed under the GNU General Public
|
||||||
|
License without this special exception.
|
||||||
|
|
||||||
|
This special exception was added by the Free Software Foundation in
|
||||||
|
version 2.2 of Bison. */
|
||||||
|
|
||||||
|
#ifndef YY_YY_GLSLANG_TAB_CPP_H_INCLUDED
|
||||||
|
# define YY_YY_GLSLANG_TAB_CPP_H_INCLUDED
|
||||||
|
/* Debug traces. */
|
||||||
|
#ifndef YYDEBUG
|
||||||
|
# define YYDEBUG 1
|
||||||
|
#endif
|
||||||
|
#if YYDEBUG
|
||||||
|
extern int yydebug;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Token type. */
|
||||||
|
#ifndef YYTOKENTYPE
|
||||||
|
# define YYTOKENTYPE
|
||||||
|
enum yytokentype
|
||||||
|
{
|
||||||
|
CONST = 258,
|
||||||
|
BOOL = 259,
|
||||||
|
INT = 260,
|
||||||
|
UINT = 261,
|
||||||
|
FLOAT = 262,
|
||||||
|
BVEC2 = 263,
|
||||||
|
BVEC3 = 264,
|
||||||
|
BVEC4 = 265,
|
||||||
|
IVEC2 = 266,
|
||||||
|
IVEC3 = 267,
|
||||||
|
IVEC4 = 268,
|
||||||
|
UVEC2 = 269,
|
||||||
|
UVEC3 = 270,
|
||||||
|
UVEC4 = 271,
|
||||||
|
VEC2 = 272,
|
||||||
|
VEC3 = 273,
|
||||||
|
VEC4 = 274,
|
||||||
|
MAT2 = 275,
|
||||||
|
MAT3 = 276,
|
||||||
|
MAT4 = 277,
|
||||||
|
MAT2X2 = 278,
|
||||||
|
MAT2X3 = 279,
|
||||||
|
MAT2X4 = 280,
|
||||||
|
MAT3X2 = 281,
|
||||||
|
MAT3X3 = 282,
|
||||||
|
MAT3X4 = 283,
|
||||||
|
MAT4X2 = 284,
|
||||||
|
MAT4X3 = 285,
|
||||||
|
MAT4X4 = 286,
|
||||||
|
SAMPLER2D = 287,
|
||||||
|
SAMPLER3D = 288,
|
||||||
|
SAMPLERCUBE = 289,
|
||||||
|
SAMPLER2DSHADOW = 290,
|
||||||
|
SAMPLERCUBESHADOW = 291,
|
||||||
|
SAMPLER2DARRAY = 292,
|
||||||
|
SAMPLER2DARRAYSHADOW = 293,
|
||||||
|
ISAMPLER2D = 294,
|
||||||
|
ISAMPLER3D = 295,
|
||||||
|
ISAMPLERCUBE = 296,
|
||||||
|
ISAMPLER2DARRAY = 297,
|
||||||
|
USAMPLER2D = 298,
|
||||||
|
USAMPLER3D = 299,
|
||||||
|
USAMPLERCUBE = 300,
|
||||||
|
USAMPLER2DARRAY = 301,
|
||||||
|
SAMPLER = 302,
|
||||||
|
SAMPLERSHADOW = 303,
|
||||||
|
TEXTURE2D = 304,
|
||||||
|
TEXTURE3D = 305,
|
||||||
|
TEXTURECUBE = 306,
|
||||||
|
TEXTURE2DARRAY = 307,
|
||||||
|
ITEXTURE2D = 308,
|
||||||
|
ITEXTURE3D = 309,
|
||||||
|
ITEXTURECUBE = 310,
|
||||||
|
ITEXTURE2DARRAY = 311,
|
||||||
|
UTEXTURE2D = 312,
|
||||||
|
UTEXTURE3D = 313,
|
||||||
|
UTEXTURECUBE = 314,
|
||||||
|
UTEXTURE2DARRAY = 315,
|
||||||
|
ATTRIBUTE = 316,
|
||||||
|
VARYING = 317,
|
||||||
|
FLOAT16_T = 318,
|
||||||
|
FLOAT32_T = 319,
|
||||||
|
DOUBLE = 320,
|
||||||
|
FLOAT64_T = 321,
|
||||||
|
INT64_T = 322,
|
||||||
|
UINT64_T = 323,
|
||||||
|
INT32_T = 324,
|
||||||
|
UINT32_T = 325,
|
||||||
|
INT16_T = 326,
|
||||||
|
UINT16_T = 327,
|
||||||
|
INT8_T = 328,
|
||||||
|
UINT8_T = 329,
|
||||||
|
I64VEC2 = 330,
|
||||||
|
I64VEC3 = 331,
|
||||||
|
I64VEC4 = 332,
|
||||||
|
U64VEC2 = 333,
|
||||||
|
U64VEC3 = 334,
|
||||||
|
U64VEC4 = 335,
|
||||||
|
I32VEC2 = 336,
|
||||||
|
I32VEC3 = 337,
|
||||||
|
I32VEC4 = 338,
|
||||||
|
U32VEC2 = 339,
|
||||||
|
U32VEC3 = 340,
|
||||||
|
U32VEC4 = 341,
|
||||||
|
I16VEC2 = 342,
|
||||||
|
I16VEC3 = 343,
|
||||||
|
I16VEC4 = 344,
|
||||||
|
U16VEC2 = 345,
|
||||||
|
U16VEC3 = 346,
|
||||||
|
U16VEC4 = 347,
|
||||||
|
I8VEC2 = 348,
|
||||||
|
I8VEC3 = 349,
|
||||||
|
I8VEC4 = 350,
|
||||||
|
U8VEC2 = 351,
|
||||||
|
U8VEC3 = 352,
|
||||||
|
U8VEC4 = 353,
|
||||||
|
DVEC2 = 354,
|
||||||
|
DVEC3 = 355,
|
||||||
|
DVEC4 = 356,
|
||||||
|
DMAT2 = 357,
|
||||||
|
DMAT3 = 358,
|
||||||
|
DMAT4 = 359,
|
||||||
|
F16VEC2 = 360,
|
||||||
|
F16VEC3 = 361,
|
||||||
|
F16VEC4 = 362,
|
||||||
|
F16MAT2 = 363,
|
||||||
|
F16MAT3 = 364,
|
||||||
|
F16MAT4 = 365,
|
||||||
|
F32VEC2 = 366,
|
||||||
|
F32VEC3 = 367,
|
||||||
|
F32VEC4 = 368,
|
||||||
|
F32MAT2 = 369,
|
||||||
|
F32MAT3 = 370,
|
||||||
|
F32MAT4 = 371,
|
||||||
|
F64VEC2 = 372,
|
||||||
|
F64VEC3 = 373,
|
||||||
|
F64VEC4 = 374,
|
||||||
|
F64MAT2 = 375,
|
||||||
|
F64MAT3 = 376,
|
||||||
|
F64MAT4 = 377,
|
||||||
|
DMAT2X2 = 378,
|
||||||
|
DMAT2X3 = 379,
|
||||||
|
DMAT2X4 = 380,
|
||||||
|
DMAT3X2 = 381,
|
||||||
|
DMAT3X3 = 382,
|
||||||
|
DMAT3X4 = 383,
|
||||||
|
DMAT4X2 = 384,
|
||||||
|
DMAT4X3 = 385,
|
||||||
|
DMAT4X4 = 386,
|
||||||
|
F16MAT2X2 = 387,
|
||||||
|
F16MAT2X3 = 388,
|
||||||
|
F16MAT2X4 = 389,
|
||||||
|
F16MAT3X2 = 390,
|
||||||
|
F16MAT3X3 = 391,
|
||||||
|
F16MAT3X4 = 392,
|
||||||
|
F16MAT4X2 = 393,
|
||||||
|
F16MAT4X3 = 394,
|
||||||
|
F16MAT4X4 = 395,
|
||||||
|
F32MAT2X2 = 396,
|
||||||
|
F32MAT2X3 = 397,
|
||||||
|
F32MAT2X4 = 398,
|
||||||
|
F32MAT3X2 = 399,
|
||||||
|
F32MAT3X3 = 400,
|
||||||
|
F32MAT3X4 = 401,
|
||||||
|
F32MAT4X2 = 402,
|
||||||
|
F32MAT4X3 = 403,
|
||||||
|
F32MAT4X4 = 404,
|
||||||
|
F64MAT2X2 = 405,
|
||||||
|
F64MAT2X3 = 406,
|
||||||
|
F64MAT2X4 = 407,
|
||||||
|
F64MAT3X2 = 408,
|
||||||
|
F64MAT3X3 = 409,
|
||||||
|
F64MAT3X4 = 410,
|
||||||
|
F64MAT4X2 = 411,
|
||||||
|
F64MAT4X3 = 412,
|
||||||
|
F64MAT4X4 = 413,
|
||||||
|
ATOMIC_UINT = 414,
|
||||||
|
ACCSTRUCTNV = 415,
|
||||||
|
ACCSTRUCTEXT = 416,
|
||||||
|
RAYQUERYEXT = 417,
|
||||||
|
FCOOPMATNV = 418,
|
||||||
|
ICOOPMATNV = 419,
|
||||||
|
UCOOPMATNV = 420,
|
||||||
|
SAMPLERCUBEARRAY = 421,
|
||||||
|
SAMPLERCUBEARRAYSHADOW = 422,
|
||||||
|
ISAMPLERCUBEARRAY = 423,
|
||||||
|
USAMPLERCUBEARRAY = 424,
|
||||||
|
SAMPLER1D = 425,
|
||||||
|
SAMPLER1DARRAY = 426,
|
||||||
|
SAMPLER1DARRAYSHADOW = 427,
|
||||||
|
ISAMPLER1D = 428,
|
||||||
|
SAMPLER1DSHADOW = 429,
|
||||||
|
SAMPLER2DRECT = 430,
|
||||||
|
SAMPLER2DRECTSHADOW = 431,
|
||||||
|
ISAMPLER2DRECT = 432,
|
||||||
|
USAMPLER2DRECT = 433,
|
||||||
|
SAMPLERBUFFER = 434,
|
||||||
|
ISAMPLERBUFFER = 435,
|
||||||
|
USAMPLERBUFFER = 436,
|
||||||
|
SAMPLER2DMS = 437,
|
||||||
|
ISAMPLER2DMS = 438,
|
||||||
|
USAMPLER2DMS = 439,
|
||||||
|
SAMPLER2DMSARRAY = 440,
|
||||||
|
ISAMPLER2DMSARRAY = 441,
|
||||||
|
USAMPLER2DMSARRAY = 442,
|
||||||
|
SAMPLEREXTERNALOES = 443,
|
||||||
|
SAMPLEREXTERNAL2DY2YEXT = 444,
|
||||||
|
ISAMPLER1DARRAY = 445,
|
||||||
|
USAMPLER1D = 446,
|
||||||
|
USAMPLER1DARRAY = 447,
|
||||||
|
F16SAMPLER1D = 448,
|
||||||
|
F16SAMPLER2D = 449,
|
||||||
|
F16SAMPLER3D = 450,
|
||||||
|
F16SAMPLER2DRECT = 451,
|
||||||
|
F16SAMPLERCUBE = 452,
|
||||||
|
F16SAMPLER1DARRAY = 453,
|
||||||
|
F16SAMPLER2DARRAY = 454,
|
||||||
|
F16SAMPLERCUBEARRAY = 455,
|
||||||
|
F16SAMPLERBUFFER = 456,
|
||||||
|
F16SAMPLER2DMS = 457,
|
||||||
|
F16SAMPLER2DMSARRAY = 458,
|
||||||
|
F16SAMPLER1DSHADOW = 459,
|
||||||
|
F16SAMPLER2DSHADOW = 460,
|
||||||
|
F16SAMPLER1DARRAYSHADOW = 461,
|
||||||
|
F16SAMPLER2DARRAYSHADOW = 462,
|
||||||
|
F16SAMPLER2DRECTSHADOW = 463,
|
||||||
|
F16SAMPLERCUBESHADOW = 464,
|
||||||
|
F16SAMPLERCUBEARRAYSHADOW = 465,
|
||||||
|
IMAGE1D = 466,
|
||||||
|
IIMAGE1D = 467,
|
||||||
|
UIMAGE1D = 468,
|
||||||
|
IMAGE2D = 469,
|
||||||
|
IIMAGE2D = 470,
|
||||||
|
UIMAGE2D = 471,
|
||||||
|
IMAGE3D = 472,
|
||||||
|
IIMAGE3D = 473,
|
||||||
|
UIMAGE3D = 474,
|
||||||
|
IMAGE2DRECT = 475,
|
||||||
|
IIMAGE2DRECT = 476,
|
||||||
|
UIMAGE2DRECT = 477,
|
||||||
|
IMAGECUBE = 478,
|
||||||
|
IIMAGECUBE = 479,
|
||||||
|
UIMAGECUBE = 480,
|
||||||
|
IMAGEBUFFER = 481,
|
||||||
|
IIMAGEBUFFER = 482,
|
||||||
|
UIMAGEBUFFER = 483,
|
||||||
|
IMAGE1DARRAY = 484,
|
||||||
|
IIMAGE1DARRAY = 485,
|
||||||
|
UIMAGE1DARRAY = 486,
|
||||||
|
IMAGE2DARRAY = 487,
|
||||||
|
IIMAGE2DARRAY = 488,
|
||||||
|
UIMAGE2DARRAY = 489,
|
||||||
|
IMAGECUBEARRAY = 490,
|
||||||
|
IIMAGECUBEARRAY = 491,
|
||||||
|
UIMAGECUBEARRAY = 492,
|
||||||
|
IMAGE2DMS = 493,
|
||||||
|
IIMAGE2DMS = 494,
|
||||||
|
UIMAGE2DMS = 495,
|
||||||
|
IMAGE2DMSARRAY = 496,
|
||||||
|
IIMAGE2DMSARRAY = 497,
|
||||||
|
UIMAGE2DMSARRAY = 498,
|
||||||
|
F16IMAGE1D = 499,
|
||||||
|
F16IMAGE2D = 500,
|
||||||
|
F16IMAGE3D = 501,
|
||||||
|
F16IMAGE2DRECT = 502,
|
||||||
|
F16IMAGECUBE = 503,
|
||||||
|
F16IMAGE1DARRAY = 504,
|
||||||
|
F16IMAGE2DARRAY = 505,
|
||||||
|
F16IMAGECUBEARRAY = 506,
|
||||||
|
F16IMAGEBUFFER = 507,
|
||||||
|
F16IMAGE2DMS = 508,
|
||||||
|
F16IMAGE2DMSARRAY = 509,
|
||||||
|
TEXTURECUBEARRAY = 510,
|
||||||
|
ITEXTURECUBEARRAY = 511,
|
||||||
|
UTEXTURECUBEARRAY = 512,
|
||||||
|
TEXTURE1D = 513,
|
||||||
|
ITEXTURE1D = 514,
|
||||||
|
UTEXTURE1D = 515,
|
||||||
|
TEXTURE1DARRAY = 516,
|
||||||
|
ITEXTURE1DARRAY = 517,
|
||||||
|
UTEXTURE1DARRAY = 518,
|
||||||
|
TEXTURE2DRECT = 519,
|
||||||
|
ITEXTURE2DRECT = 520,
|
||||||
|
UTEXTURE2DRECT = 521,
|
||||||
|
TEXTUREBUFFER = 522,
|
||||||
|
ITEXTUREBUFFER = 523,
|
||||||
|
UTEXTUREBUFFER = 524,
|
||||||
|
TEXTURE2DMS = 525,
|
||||||
|
ITEXTURE2DMS = 526,
|
||||||
|
UTEXTURE2DMS = 527,
|
||||||
|
TEXTURE2DMSARRAY = 528,
|
||||||
|
ITEXTURE2DMSARRAY = 529,
|
||||||
|
UTEXTURE2DMSARRAY = 530,
|
||||||
|
F16TEXTURE1D = 531,
|
||||||
|
F16TEXTURE2D = 532,
|
||||||
|
F16TEXTURE3D = 533,
|
||||||
|
F16TEXTURE2DRECT = 534,
|
||||||
|
F16TEXTURECUBE = 535,
|
||||||
|
F16TEXTURE1DARRAY = 536,
|
||||||
|
F16TEXTURE2DARRAY = 537,
|
||||||
|
F16TEXTURECUBEARRAY = 538,
|
||||||
|
F16TEXTUREBUFFER = 539,
|
||||||
|
F16TEXTURE2DMS = 540,
|
||||||
|
F16TEXTURE2DMSARRAY = 541,
|
||||||
|
SUBPASSINPUT = 542,
|
||||||
|
SUBPASSINPUTMS = 543,
|
||||||
|
ISUBPASSINPUT = 544,
|
||||||
|
ISUBPASSINPUTMS = 545,
|
||||||
|
USUBPASSINPUT = 546,
|
||||||
|
USUBPASSINPUTMS = 547,
|
||||||
|
F16SUBPASSINPUT = 548,
|
||||||
|
F16SUBPASSINPUTMS = 549,
|
||||||
|
LEFT_OP = 550,
|
||||||
|
RIGHT_OP = 551,
|
||||||
|
INC_OP = 552,
|
||||||
|
DEC_OP = 553,
|
||||||
|
LE_OP = 554,
|
||||||
|
GE_OP = 555,
|
||||||
|
EQ_OP = 556,
|
||||||
|
NE_OP = 557,
|
||||||
|
AND_OP = 558,
|
||||||
|
OR_OP = 559,
|
||||||
|
XOR_OP = 560,
|
||||||
|
MUL_ASSIGN = 561,
|
||||||
|
DIV_ASSIGN = 562,
|
||||||
|
ADD_ASSIGN = 563,
|
||||||
|
MOD_ASSIGN = 564,
|
||||||
|
LEFT_ASSIGN = 565,
|
||||||
|
RIGHT_ASSIGN = 566,
|
||||||
|
AND_ASSIGN = 567,
|
||||||
|
XOR_ASSIGN = 568,
|
||||||
|
OR_ASSIGN = 569,
|
||||||
|
SUB_ASSIGN = 570,
|
||||||
|
STRING_LITERAL = 571,
|
||||||
|
LEFT_PAREN = 572,
|
||||||
|
RIGHT_PAREN = 573,
|
||||||
|
LEFT_BRACKET = 574,
|
||||||
|
RIGHT_BRACKET = 575,
|
||||||
|
LEFT_BRACE = 576,
|
||||||
|
RIGHT_BRACE = 577,
|
||||||
|
DOT = 578,
|
||||||
|
COMMA = 579,
|
||||||
|
COLON = 580,
|
||||||
|
EQUAL = 581,
|
||||||
|
SEMICOLON = 582,
|
||||||
|
BANG = 583,
|
||||||
|
DASH = 584,
|
||||||
|
TILDE = 585,
|
||||||
|
PLUS = 586,
|
||||||
|
STAR = 587,
|
||||||
|
SLASH = 588,
|
||||||
|
PERCENT = 589,
|
||||||
|
LEFT_ANGLE = 590,
|
||||||
|
RIGHT_ANGLE = 591,
|
||||||
|
VERTICAL_BAR = 592,
|
||||||
|
CARET = 593,
|
||||||
|
AMPERSAND = 594,
|
||||||
|
QUESTION = 595,
|
||||||
|
INVARIANT = 596,
|
||||||
|
HIGH_PRECISION = 597,
|
||||||
|
MEDIUM_PRECISION = 598,
|
||||||
|
LOW_PRECISION = 599,
|
||||||
|
PRECISION = 600,
|
||||||
|
PACKED = 601,
|
||||||
|
RESOURCE = 602,
|
||||||
|
SUPERP = 603,
|
||||||
|
FLOATCONSTANT = 604,
|
||||||
|
INTCONSTANT = 605,
|
||||||
|
UINTCONSTANT = 606,
|
||||||
|
BOOLCONSTANT = 607,
|
||||||
|
IDENTIFIER = 608,
|
||||||
|
TYPE_NAME = 609,
|
||||||
|
CENTROID = 610,
|
||||||
|
IN = 611,
|
||||||
|
OUT = 612,
|
||||||
|
INOUT = 613,
|
||||||
|
STRUCT = 614,
|
||||||
|
VOID = 615,
|
||||||
|
WHILE = 616,
|
||||||
|
BREAK = 617,
|
||||||
|
CONTINUE = 618,
|
||||||
|
DO = 619,
|
||||||
|
ELSE = 620,
|
||||||
|
FOR = 621,
|
||||||
|
IF = 622,
|
||||||
|
DISCARD = 623,
|
||||||
|
RETURN = 624,
|
||||||
|
SWITCH = 625,
|
||||||
|
CASE = 626,
|
||||||
|
DEFAULT = 627,
|
||||||
|
UNIFORM = 628,
|
||||||
|
SHARED = 629,
|
||||||
|
BUFFER = 630,
|
||||||
|
FLAT = 631,
|
||||||
|
SMOOTH = 632,
|
||||||
|
LAYOUT = 633,
|
||||||
|
DOUBLECONSTANT = 634,
|
||||||
|
INT16CONSTANT = 635,
|
||||||
|
UINT16CONSTANT = 636,
|
||||||
|
FLOAT16CONSTANT = 637,
|
||||||
|
INT32CONSTANT = 638,
|
||||||
|
UINT32CONSTANT = 639,
|
||||||
|
INT64CONSTANT = 640,
|
||||||
|
UINT64CONSTANT = 641,
|
||||||
|
SUBROUTINE = 642,
|
||||||
|
DEMOTE = 643,
|
||||||
|
PAYLOADNV = 644,
|
||||||
|
PAYLOADINNV = 645,
|
||||||
|
HITATTRNV = 646,
|
||||||
|
CALLDATANV = 647,
|
||||||
|
CALLDATAINNV = 648,
|
||||||
|
PAYLOADEXT = 649,
|
||||||
|
PAYLOADINEXT = 650,
|
||||||
|
HITATTREXT = 651,
|
||||||
|
CALLDATAEXT = 652,
|
||||||
|
CALLDATAINEXT = 653,
|
||||||
|
PATCH = 654,
|
||||||
|
SAMPLE = 655,
|
||||||
|
NONUNIFORM = 656,
|
||||||
|
COHERENT = 657,
|
||||||
|
VOLATILE = 658,
|
||||||
|
RESTRICT = 659,
|
||||||
|
READONLY = 660,
|
||||||
|
WRITEONLY = 661,
|
||||||
|
DEVICECOHERENT = 662,
|
||||||
|
QUEUEFAMILYCOHERENT = 663,
|
||||||
|
WORKGROUPCOHERENT = 664,
|
||||||
|
SUBGROUPCOHERENT = 665,
|
||||||
|
NONPRIVATE = 666,
|
||||||
|
SHADERCALLCOHERENT = 667,
|
||||||
|
NOPERSPECTIVE = 668,
|
||||||
|
EXPLICITINTERPAMD = 669,
|
||||||
|
PERVERTEXNV = 670,
|
||||||
|
PERPRIMITIVENV = 671,
|
||||||
|
PERVIEWNV = 672,
|
||||||
|
PERTASKNV = 673,
|
||||||
|
PRECISE = 674
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Value type. */
|
||||||
|
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||||
|
|
||||||
|
union YYSTYPE
|
||||||
|
{
|
||||||
|
#line 97 "glslang.y" /* yacc.c:1909 */
|
||||||
|
|
||||||
|
struct {
|
||||||
|
glslang::TSourceLoc loc;
|
||||||
|
union {
|
||||||
|
glslang::TString *string;
|
||||||
|
int i;
|
||||||
|
unsigned int u;
|
||||||
|
long long i64;
|
||||||
|
unsigned long long u64;
|
||||||
|
bool b;
|
||||||
|
double d;
|
||||||
|
};
|
||||||
|
glslang::TSymbol* symbol;
|
||||||
|
} lex;
|
||||||
|
struct {
|
||||||
|
glslang::TSourceLoc loc;
|
||||||
|
glslang::TOperator op;
|
||||||
|
union {
|
||||||
|
TIntermNode* intermNode;
|
||||||
|
glslang::TIntermNodePair nodePair;
|
||||||
|
glslang::TIntermTyped* intermTypedNode;
|
||||||
|
glslang::TAttributes* attributes;
|
||||||
|
};
|
||||||
|
union {
|
||||||
|
glslang::TPublicType type;
|
||||||
|
glslang::TFunction* function;
|
||||||
|
glslang::TParameter param;
|
||||||
|
glslang::TTypeLoc typeLine;
|
||||||
|
glslang::TTypeList* typeList;
|
||||||
|
glslang::TArraySizes* arraySizes;
|
||||||
|
glslang::TIdentifierList* identifierList;
|
||||||
|
};
|
||||||
|
glslang::TArraySizes* typeParameters;
|
||||||
|
} interm;
|
||||||
|
|
||||||
|
#line 510 "glslang_tab.cpp.h" /* yacc.c:1909 */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef union YYSTYPE YYSTYPE;
|
||||||
|
# define YYSTYPE_IS_TRIVIAL 1
|
||||||
|
# define YYSTYPE_IS_DECLARED 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int yyparse (glslang::TParseContext* pParseContext);
|
||||||
|
|
||||||
|
#endif /* !YY_YY_GLSLANG_TAB_CPP_H_INCLUDED */
|
||||||
|
|
@ -0,0 +1,302 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
|
||||||
|
#ifndef _IOMAPPER_INCLUDED
|
||||||
|
#define _IOMAPPER_INCLUDED
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include "LiveTraverser.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
//
|
||||||
|
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
|
||||||
|
//
|
||||||
|
|
||||||
|
class TInfoSink;
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
class TIntermediate;
|
||||||
|
struct TVarEntryInfo {
|
||||||
|
int id;
|
||||||
|
TIntermSymbol* symbol;
|
||||||
|
bool live;
|
||||||
|
int newBinding;
|
||||||
|
int newSet;
|
||||||
|
int newLocation;
|
||||||
|
int newComponent;
|
||||||
|
int newIndex;
|
||||||
|
EShLanguage stage;
|
||||||
|
struct TOrderById {
|
||||||
|
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TOrderByPriority {
|
||||||
|
// ordering:
|
||||||
|
// 1) has both binding and set
|
||||||
|
// 2) has binding but no set
|
||||||
|
// 3) has no binding but set
|
||||||
|
// 4) has no binding and no set
|
||||||
|
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
|
||||||
|
const TQualifier& lq = l.symbol->getQualifier();
|
||||||
|
const TQualifier& rq = r.symbol->getQualifier();
|
||||||
|
|
||||||
|
// simple rules:
|
||||||
|
// has binding gives 2 points
|
||||||
|
// has set gives 1 point
|
||||||
|
// who has the most points is more important.
|
||||||
|
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
|
||||||
|
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
|
||||||
|
|
||||||
|
if (lPoints == rPoints)
|
||||||
|
return l.id < r.id;
|
||||||
|
return lPoints > rPoints;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Base class for shared TIoMapResolver services, used by several derivations.
|
||||||
|
struct TDefaultIoResolverBase : public glslang::TIoMapResolver {
|
||||||
|
public:
|
||||||
|
TDefaultIoResolverBase(const TIntermediate& intermediate);
|
||||||
|
typedef std::vector<int> TSlotSet;
|
||||||
|
typedef std::unordered_map<int, TSlotSet> TSlotSetMap;
|
||||||
|
|
||||||
|
// grow the reflection stage by stage
|
||||||
|
void notifyBinding(EShLanguage, TVarEntryInfo& /*ent*/) override {}
|
||||||
|
void notifyInOut(EShLanguage, TVarEntryInfo& /*ent*/) override {}
|
||||||
|
void beginNotifications(EShLanguage) override {}
|
||||||
|
void endNotifications(EShLanguage) override {}
|
||||||
|
void beginResolve(EShLanguage) override {}
|
||||||
|
void endResolve(EShLanguage) override {}
|
||||||
|
void beginCollect(EShLanguage) override {}
|
||||||
|
void endCollect(EShLanguage) override {}
|
||||||
|
void reserverResourceSlot(TVarEntryInfo& /*ent*/, TInfoSink& /*infoSink*/) override {}
|
||||||
|
void reserverStorageSlot(TVarEntryInfo& /*ent*/, TInfoSink& /*infoSink*/) override {}
|
||||||
|
int getBaseBinding(TResourceType res, unsigned int set) const;
|
||||||
|
const std::vector<std::string>& getResourceSetBinding() const;
|
||||||
|
virtual TResourceType getResourceType(const glslang::TType& type) = 0;
|
||||||
|
bool doAutoBindingMapping() const;
|
||||||
|
bool doAutoLocationMapping() const;
|
||||||
|
TSlotSet::iterator findSlot(int set, int slot);
|
||||||
|
bool checkEmpty(int set, int slot);
|
||||||
|
bool validateInOut(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
|
||||||
|
int reserveSlot(int set, int slot, int size = 1);
|
||||||
|
int getFreeSlot(int set, int base, int size = 1);
|
||||||
|
int resolveSet(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||||
|
int resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||||
|
int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) override;
|
||||||
|
int resolveInOutComponent(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||||
|
int resolveInOutIndex(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||||
|
void addStage(EShLanguage stage) override {
|
||||||
|
if (stage < EShLangCount)
|
||||||
|
stageMask[stage] = true;
|
||||||
|
}
|
||||||
|
uint32_t computeTypeLocationSize(const TType& type, EShLanguage stage);
|
||||||
|
|
||||||
|
TSlotSetMap slots;
|
||||||
|
bool hasError = false;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TDefaultIoResolverBase(TDefaultIoResolverBase&);
|
||||||
|
TDefaultIoResolverBase& operator=(TDefaultIoResolverBase&);
|
||||||
|
const TIntermediate& intermediate;
|
||||||
|
int nextUniformLocation;
|
||||||
|
int nextInputLocation;
|
||||||
|
int nextOutputLocation;
|
||||||
|
bool stageMask[EShLangCount + 1];
|
||||||
|
// Return descriptor set specific base if there is one, and the generic base otherwise.
|
||||||
|
int selectBaseBinding(int base, int descriptorSetBase) const {
|
||||||
|
return descriptorSetBase != -1 ? descriptorSetBase : base;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getLayoutSet(const glslang::TType& type) {
|
||||||
|
if (type.getQualifier().hasSet())
|
||||||
|
return type.getQualifier().layoutSet;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isSamplerType(const glslang::TType& type) {
|
||||||
|
return type.getBasicType() == glslang::EbtSampler && type.getSampler().isPureSampler();
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isTextureType(const glslang::TType& type) {
|
||||||
|
return (type.getBasicType() == glslang::EbtSampler &&
|
||||||
|
(type.getSampler().isTexture() || type.getSampler().isSubpass()));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isUboType(const glslang::TType& type) {
|
||||||
|
return type.getQualifier().storage == EvqUniform;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isImageType(const glslang::TType& type) {
|
||||||
|
return type.getBasicType() == glslang::EbtSampler && type.getSampler().isImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isSsboType(const glslang::TType& type) {
|
||||||
|
return type.getQualifier().storage == EvqBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return true if this is a SRV (shader resource view) type:
|
||||||
|
static bool isSrvType(const glslang::TType& type) {
|
||||||
|
return isTextureType(type) || type.getQualifier().storage == EvqBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return true if this is a UAV (unordered access view) type:
|
||||||
|
static bool isUavType(const glslang::TType& type) {
|
||||||
|
if (type.getQualifier().isReadOnly())
|
||||||
|
return false;
|
||||||
|
return (type.getBasicType() == glslang::EbtSampler && type.getSampler().isImage()) ||
|
||||||
|
(type.getQualifier().storage == EvqBuffer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Defaulf I/O resolver for OpenGL
|
||||||
|
struct TDefaultGlslIoResolver : public TDefaultIoResolverBase {
|
||||||
|
public:
|
||||||
|
typedef std::map<TString, int> TVarSlotMap; // <resourceName, location/binding>
|
||||||
|
typedef std::map<int, TVarSlotMap> TSlotMap; // <resourceKey, TVarSlotMap>
|
||||||
|
TDefaultGlslIoResolver(const TIntermediate& intermediate);
|
||||||
|
bool validateBinding(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
|
||||||
|
TResourceType getResourceType(const glslang::TType& type) override;
|
||||||
|
int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) override;
|
||||||
|
int resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||||
|
int resolveBinding(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||||
|
void beginResolve(EShLanguage /*stage*/) override;
|
||||||
|
void endResolve(EShLanguage stage) override;
|
||||||
|
void beginCollect(EShLanguage) override;
|
||||||
|
void endCollect(EShLanguage) override;
|
||||||
|
void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
|
||||||
|
void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
|
||||||
|
const TString& getAccessName(const TIntermSymbol*);
|
||||||
|
// in/out symbol and uniform symbol are stored in the same resourceSlotMap, the storage key is used to identify each type of symbol.
|
||||||
|
// We use stage and storage qualifier to construct a storage key. it can help us identify the same storage resource used in different stage.
|
||||||
|
// if a resource is a program resource and we don't need know it usage stage, we can use same stage to build storage key.
|
||||||
|
// Note: both stage and type must less then 0xffff.
|
||||||
|
int buildStorageKey(EShLanguage stage, TStorageQualifier type) {
|
||||||
|
assert(static_cast<uint32_t>(stage) <= 0x0000ffff && static_cast<uint32_t>(type) <= 0x0000ffff);
|
||||||
|
return (stage << 16) | type;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Use for mark pre stage, to get more interface symbol information.
|
||||||
|
EShLanguage preStage;
|
||||||
|
// Use for mark current shader stage for resolver
|
||||||
|
EShLanguage currentStage;
|
||||||
|
// Slot map for storage resource(location of uniform and interface symbol) It's a program share slot
|
||||||
|
TSlotMap resourceSlotMap;
|
||||||
|
// Slot map for other resource(image, ubo, ssbo), It's a program share slot.
|
||||||
|
TSlotMap storageSlotMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<TString, TVarEntryInfo> TVarLiveMap;
|
||||||
|
|
||||||
|
// override function "operator=", if a vector<const _Kty, _Ty> being sort,
|
||||||
|
// when use vc++, the sort function will call :
|
||||||
|
// pair& operator=(const pair<_Other1, _Other2>& _Right)
|
||||||
|
// {
|
||||||
|
// first = _Right.first;
|
||||||
|
// second = _Right.second;
|
||||||
|
// return (*this);
|
||||||
|
// }
|
||||||
|
// that will make a const type handing on left.
|
||||||
|
// override this function can avoid a compiler error.
|
||||||
|
// In the future, if the vc++ compiler can handle such a situation,
|
||||||
|
// this part of the code will be removed.
|
||||||
|
struct TVarLivePair : std::pair<const TString, TVarEntryInfo> {
|
||||||
|
TVarLivePair(const std::pair<const TString, TVarEntryInfo>& _Right) : pair(_Right.first, _Right.second) {}
|
||||||
|
TVarLivePair& operator=(const TVarLivePair& _Right) {
|
||||||
|
const_cast<TString&>(first) = _Right.first;
|
||||||
|
second = _Right.second;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
TVarLivePair(const TVarLivePair& src) : pair(src) { }
|
||||||
|
};
|
||||||
|
typedef std::vector<TVarLivePair> TVarLiveVector;
|
||||||
|
|
||||||
|
// I/O mapper
|
||||||
|
class TIoMapper {
|
||||||
|
public:
|
||||||
|
TIoMapper() {}
|
||||||
|
virtual ~TIoMapper() {}
|
||||||
|
// grow the reflection stage by stage
|
||||||
|
bool virtual addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*);
|
||||||
|
bool virtual doMap(TIoMapResolver*, TInfoSink&) { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// I/O mapper for OpenGL
|
||||||
|
class TGlslIoMapper : public TIoMapper {
|
||||||
|
public:
|
||||||
|
TGlslIoMapper() {
|
||||||
|
memset(inVarMaps, 0, sizeof(TVarLiveMap*) * EShLangCount);
|
||||||
|
memset(outVarMaps, 0, sizeof(TVarLiveMap*) * EShLangCount);
|
||||||
|
memset(uniformVarMap, 0, sizeof(TVarLiveMap*) * EShLangCount);
|
||||||
|
memset(intermediates, 0, sizeof(TIntermediate*) * EShLangCount);
|
||||||
|
}
|
||||||
|
virtual ~TGlslIoMapper() {
|
||||||
|
for (size_t stage = 0; stage < EShLangCount; stage++) {
|
||||||
|
if (inVarMaps[stage] != nullptr) {
|
||||||
|
delete inVarMaps[stage];
|
||||||
|
inVarMaps[stage] = nullptr;
|
||||||
|
}
|
||||||
|
if (outVarMaps[stage] != nullptr) {
|
||||||
|
delete outVarMaps[stage];
|
||||||
|
outVarMaps[stage] = nullptr;
|
||||||
|
}
|
||||||
|
if (uniformVarMap[stage] != nullptr) {
|
||||||
|
delete uniformVarMap[stage];
|
||||||
|
uniformVarMap[stage] = nullptr;
|
||||||
|
}
|
||||||
|
if (intermediates[stage] != nullptr)
|
||||||
|
intermediates[stage] = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// grow the reflection stage by stage
|
||||||
|
bool addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*) override;
|
||||||
|
bool doMap(TIoMapResolver*, TInfoSink&) override;
|
||||||
|
TVarLiveMap *inVarMaps[EShLangCount], *outVarMaps[EShLangCount],
|
||||||
|
*uniformVarMap[EShLangCount];
|
||||||
|
TIntermediate* intermediates[EShLangCount];
|
||||||
|
bool hadError = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _IOMAPPER_INCLUDED
|
||||||
|
|
||||||
|
#endif // GLSLANG_WEB
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,240 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015-2018 Google, Inc.
|
||||||
|
// Copyright (C) 2017 ARM Limited.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
// This is implemented in Versions.cpp
|
||||||
|
|
||||||
|
#ifndef _PARSE_VERSIONS_INCLUDED_
|
||||||
|
#define _PARSE_VERSIONS_INCLUDED_
|
||||||
|
|
||||||
|
#include "../Public/ShaderLang.h"
|
||||||
|
#include "../Include/InfoSink.h"
|
||||||
|
#include "Scan.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Base class for parse helpers.
|
||||||
|
// This just has version-related information and checking.
|
||||||
|
// This class should be sufficient for preprocessing.
|
||||||
|
//
|
||||||
|
class TParseVersions {
|
||||||
|
public:
|
||||||
|
TParseVersions(TIntermediate& interm, int version, EProfile profile,
|
||||||
|
const SpvVersion& spvVersion, EShLanguage language, TInfoSink& infoSink,
|
||||||
|
bool forwardCompatible, EShMessages messages)
|
||||||
|
:
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
forwardCompatible(forwardCompatible),
|
||||||
|
profile(profile),
|
||||||
|
#endif
|
||||||
|
infoSink(infoSink), version(version),
|
||||||
|
language(language),
|
||||||
|
spvVersion(spvVersion),
|
||||||
|
intermediate(interm), messages(messages), numErrors(0), currentScanner(0) { }
|
||||||
|
virtual ~TParseVersions() { }
|
||||||
|
void requireStage(const TSourceLoc&, EShLanguageMask, const char* featureDesc);
|
||||||
|
void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc);
|
||||||
|
#ifdef GLSLANG_WEB
|
||||||
|
const EProfile profile = EEsProfile;
|
||||||
|
bool isEsProfile() const { return true; }
|
||||||
|
void requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc)
|
||||||
|
{
|
||||||
|
if (! (EEsProfile & profileMask))
|
||||||
|
error(loc, "not supported with this profile:", featureDesc, ProfileName(profile));
|
||||||
|
}
|
||||||
|
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
|
||||||
|
const char* const extensions[], const char* featureDesc)
|
||||||
|
{
|
||||||
|
if ((EEsProfile & profileMask) && (minVersion == 0 || version < minVersion))
|
||||||
|
error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
|
||||||
|
}
|
||||||
|
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
|
||||||
|
const char* featureDesc)
|
||||||
|
{
|
||||||
|
profileRequires(loc, profileMask, minVersion, extension ? 1 : 0, &extension, featureDesc);
|
||||||
|
}
|
||||||
|
void initializeExtensionBehavior() { }
|
||||||
|
void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc) { }
|
||||||
|
void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc) { }
|
||||||
|
void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||||
|
const char* featureDesc) { }
|
||||||
|
void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||||
|
const char* featureDesc) { }
|
||||||
|
TExtensionBehavior getExtensionBehavior(const char*) { return EBhMissing; }
|
||||||
|
bool extensionTurnedOn(const char* const extension) { return false; }
|
||||||
|
bool extensionsTurnedOn(int numExtensions, const char* const extensions[]) { return false; }
|
||||||
|
void updateExtensionBehavior(int line, const char* const extension, const char* behavior) { }
|
||||||
|
void updateExtensionBehavior(const char* const extension, TExtensionBehavior) { }
|
||||||
|
void checkExtensionStage(const TSourceLoc&, const char* const extension) { }
|
||||||
|
void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior) { }
|
||||||
|
void fullIntegerCheck(const TSourceLoc&, const char* op) { }
|
||||||
|
void doubleCheck(const TSourceLoc&, const char* op) { }
|
||||||
|
bool float16Arithmetic() { return false; }
|
||||||
|
void requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc) { }
|
||||||
|
bool int16Arithmetic() { return false; }
|
||||||
|
void requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc) { }
|
||||||
|
bool int8Arithmetic() { return false; }
|
||||||
|
void requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc) { }
|
||||||
|
void int64Check(const TSourceLoc&, const char* op, bool builtIn = false) { }
|
||||||
|
void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false) { }
|
||||||
|
void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false) { }
|
||||||
|
bool relaxedErrors() const { return false; }
|
||||||
|
bool suppressWarnings() const { return true; }
|
||||||
|
bool isForwardCompatible() const { return false; }
|
||||||
|
#else
|
||||||
|
bool forwardCompatible; // true if errors are to be given for use of deprecated features
|
||||||
|
EProfile profile; // the declared profile in the shader (core by default)
|
||||||
|
bool isEsProfile() const { return profile == EEsProfile; }
|
||||||
|
void requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc);
|
||||||
|
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
|
||||||
|
const char* const extensions[], const char* featureDesc);
|
||||||
|
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
|
||||||
|
const char* featureDesc);
|
||||||
|
virtual void initializeExtensionBehavior();
|
||||||
|
virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc);
|
||||||
|
virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc);
|
||||||
|
virtual void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||||
|
const char* featureDesc);
|
||||||
|
virtual void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||||
|
const char* featureDesc);
|
||||||
|
virtual TExtensionBehavior getExtensionBehavior(const char*);
|
||||||
|
virtual bool extensionTurnedOn(const char* const extension);
|
||||||
|
virtual bool extensionsTurnedOn(int numExtensions, const char* const extensions[]);
|
||||||
|
virtual void updateExtensionBehavior(int line, const char* const extension, const char* behavior);
|
||||||
|
virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
|
||||||
|
virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||||
|
const char* featureDesc);
|
||||||
|
virtual void checkExtensionStage(const TSourceLoc&, const char* const extension);
|
||||||
|
virtual void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior);
|
||||||
|
virtual void fullIntegerCheck(const TSourceLoc&, const char* op);
|
||||||
|
|
||||||
|
virtual void unimplemented(const TSourceLoc&, const char* featureDesc);
|
||||||
|
virtual void doubleCheck(const TSourceLoc&, const char* op);
|
||||||
|
virtual void float16Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void float16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual bool float16Arithmetic();
|
||||||
|
virtual void requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
|
||||||
|
virtual void int16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual bool int16Arithmetic();
|
||||||
|
virtual void requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
|
||||||
|
virtual void int8ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual bool int8Arithmetic();
|
||||||
|
virtual void requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
|
||||||
|
virtual void float16OpaqueCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void explicitInt8Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void explicitInt16Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void explicitInt32Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void fcoopmatCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||||
|
virtual void intcoopmatCheck(const TSourceLoc&, const char *op, bool builtIn = false);
|
||||||
|
bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; }
|
||||||
|
bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; }
|
||||||
|
bool isForwardCompatible() const { return forwardCompatible; }
|
||||||
|
#endif // GLSLANG_WEB
|
||||||
|
virtual void spvRemoved(const TSourceLoc&, const char* op);
|
||||||
|
virtual void vulkanRemoved(const TSourceLoc&, const char* op);
|
||||||
|
virtual void requireVulkan(const TSourceLoc&, const char* op);
|
||||||
|
virtual void requireSpv(const TSourceLoc&, const char* op);
|
||||||
|
virtual void requireSpv(const TSourceLoc&, const char *op, unsigned int version);
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(GLSLANG_WEB) && !defined(GLSLANG_WEB_DEVEL)
|
||||||
|
void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) { addError(); }
|
||||||
|
void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) { }
|
||||||
|
void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) { addError(); }
|
||||||
|
void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) { }
|
||||||
|
#else
|
||||||
|
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) = 0;
|
||||||
|
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) = 0;
|
||||||
|
virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) = 0;
|
||||||
|
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
const char* szExtraInfoFormat, ...) = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void addError() { ++numErrors; }
|
||||||
|
int getNumErrors() const { return numErrors; }
|
||||||
|
|
||||||
|
void setScanner(TInputScanner* scanner) { currentScanner = scanner; }
|
||||||
|
TInputScanner* getScanner() const { return currentScanner; }
|
||||||
|
const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); }
|
||||||
|
void setCurrentLine(int line) { currentScanner->setLine(line); }
|
||||||
|
void setCurrentColumn(int col) { currentScanner->setColumn(col); }
|
||||||
|
void setCurrentSourceName(const char* name) { currentScanner->setFile(name); }
|
||||||
|
void setCurrentString(int string) { currentScanner->setString(string); }
|
||||||
|
|
||||||
|
void getPreamble(std::string&);
|
||||||
|
#ifdef ENABLE_HLSL
|
||||||
|
bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; }
|
||||||
|
bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; }
|
||||||
|
bool hlslDX9Compatible() const { return (messages & EShMsgHlslDX9Compatible) != 0; }
|
||||||
|
#else
|
||||||
|
bool isReadingHLSL() const { return false; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TInfoSink& infoSink;
|
||||||
|
|
||||||
|
// compilation mode
|
||||||
|
int version; // version, updated by #version in the shader
|
||||||
|
EShLanguage language; // really the stage
|
||||||
|
SpvVersion spvVersion;
|
||||||
|
TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||||
|
TMap<TString, unsigned int> extensionMinSpv; // for each extension string, store minimum spirv required
|
||||||
|
EShMessages messages; // errors/warnings/rule-sets
|
||||||
|
int numErrors; // number of compile-time errors encountered
|
||||||
|
TInputScanner* currentScanner;
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit TParseVersions(const TParseVersions&);
|
||||||
|
TParseVersions& operator=(const TParseVersions&);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _PARSE_VERSIONS_INCLUDED_
|
||||||
|
|
@ -0,0 +1,703 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2013 LunarG, Inc.
|
||||||
|
// Copyright (C) 2015-2018 Google, Inc.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
/****************************************************************************\
|
||||||
|
Copyright (c) 2002, NVIDIA Corporation.
|
||||||
|
|
||||||
|
NVIDIA Corporation("NVIDIA") supplies this software to you in
|
||||||
|
consideration of your agreement to the following terms, and your use,
|
||||||
|
installation, modification or redistribution of this NVIDIA software
|
||||||
|
constitutes acceptance of these terms. If you do not agree with these
|
||||||
|
terms, please do not use, install, modify or redistribute this NVIDIA
|
||||||
|
software.
|
||||||
|
|
||||||
|
In consideration of your agreement to abide by the following terms, and
|
||||||
|
subject to these terms, NVIDIA grants you a personal, non-exclusive
|
||||||
|
license, under NVIDIA's copyrights in this original NVIDIA software (the
|
||||||
|
"NVIDIA Software"), to use, reproduce, modify and redistribute the
|
||||||
|
NVIDIA Software, with or without modifications, in source and/or binary
|
||||||
|
forms; provided that if you redistribute the NVIDIA Software, you must
|
||||||
|
retain the copyright notice of NVIDIA, this notice and the following
|
||||||
|
text and disclaimers in all such redistributions of the NVIDIA Software.
|
||||||
|
Neither the name, trademarks, service marks nor logos of NVIDIA
|
||||||
|
Corporation may be used to endorse or promote products derived from the
|
||||||
|
NVIDIA Software without specific prior written permission from NVIDIA.
|
||||||
|
Except as expressly stated in this notice, no other rights or licenses
|
||||||
|
express or implied, are granted by NVIDIA herein, including but not
|
||||||
|
limited to any patent rights that may be infringed by your derivative
|
||||||
|
works or by other works in which the NVIDIA Software may be
|
||||||
|
incorporated. No hardware is licensed hereunder.
|
||||||
|
|
||||||
|
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
|
||||||
|
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
|
||||||
|
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
|
||||||
|
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
|
||||||
|
PRODUCTS.
|
||||||
|
|
||||||
|
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
|
||||||
|
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
|
||||||
|
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
|
||||||
|
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
|
||||||
|
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
\****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef PPCONTEXT_H
|
||||||
|
#define PPCONTEXT_H
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "../ParseHelper.h"
|
||||||
|
#include "PpTokens.h"
|
||||||
|
|
||||||
|
/* windows only pragma */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable : 4127)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
class TPpToken {
|
||||||
|
public:
|
||||||
|
TPpToken() { clear(); }
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
space = false;
|
||||||
|
i64val = 0;
|
||||||
|
loc.init();
|
||||||
|
name[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used for comparing macro definitions, so checks what is relevant for that.
|
||||||
|
bool operator==(const TPpToken& right) const
|
||||||
|
{
|
||||||
|
return space == right.space &&
|
||||||
|
ival == right.ival && dval == right.dval && i64val == right.i64val &&
|
||||||
|
strncmp(name, right.name, MaxTokenLength) == 0;
|
||||||
|
}
|
||||||
|
bool operator!=(const TPpToken& right) const { return ! operator==(right); }
|
||||||
|
|
||||||
|
TSourceLoc loc;
|
||||||
|
// True if a space (for white space or a removed comment) should also be
|
||||||
|
// recognized, in front of the token returned:
|
||||||
|
bool space;
|
||||||
|
// Numeric value of the token:
|
||||||
|
union {
|
||||||
|
int ival;
|
||||||
|
double dval;
|
||||||
|
long long i64val;
|
||||||
|
};
|
||||||
|
// Text string of the token:
|
||||||
|
char name[MaxTokenLength + 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
class TStringAtomMap {
|
||||||
|
//
|
||||||
|
// Implementation is in PpAtom.cpp
|
||||||
|
//
|
||||||
|
// Maintain a bi-directional mapping between relevant preprocessor strings and
|
||||||
|
// "atoms" which a unique integers (small, contiguous, not hash-like) per string.
|
||||||
|
//
|
||||||
|
public:
|
||||||
|
TStringAtomMap();
|
||||||
|
|
||||||
|
// Map string -> atom.
|
||||||
|
// Return 0 if no existing string.
|
||||||
|
int getAtom(const char* s) const
|
||||||
|
{
|
||||||
|
auto it = atomMap.find(s);
|
||||||
|
return it == atomMap.end() ? 0 : it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map a new or existing string -> atom, inventing a new atom if necessary.
|
||||||
|
int getAddAtom(const char* s)
|
||||||
|
{
|
||||||
|
int atom = getAtom(s);
|
||||||
|
if (atom == 0) {
|
||||||
|
atom = nextAtom++;
|
||||||
|
addAtomFixed(s, atom);
|
||||||
|
}
|
||||||
|
return atom;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map atom -> string.
|
||||||
|
const char* getString(int atom) const { return stringMap[atom]->c_str(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TStringAtomMap(TStringAtomMap&);
|
||||||
|
TStringAtomMap& operator=(TStringAtomMap&);
|
||||||
|
|
||||||
|
TUnorderedMap<TString, int> atomMap;
|
||||||
|
TVector<const TString*> stringMap; // these point into the TString in atomMap
|
||||||
|
int nextAtom;
|
||||||
|
|
||||||
|
// Bad source characters can lead to bad atoms, so gracefully handle those by
|
||||||
|
// pre-filling the table with them (to avoid if tests later).
|
||||||
|
TString badToken;
|
||||||
|
|
||||||
|
// Add bi-directional mappings:
|
||||||
|
// - string -> atom
|
||||||
|
// - atom -> string
|
||||||
|
void addAtomFixed(const char* s, int atom)
|
||||||
|
{
|
||||||
|
auto it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
|
||||||
|
if (stringMap.size() < (size_t)atom + 1)
|
||||||
|
stringMap.resize(atom + 100, &badToken);
|
||||||
|
stringMap[atom] = &it->first;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class TInputScanner;
|
||||||
|
|
||||||
|
enum MacroExpandResult {
|
||||||
|
MacroExpandNotStarted, // macro not expanded, which might not be an error
|
||||||
|
MacroExpandError, // a clear error occurred while expanding, no expansion
|
||||||
|
MacroExpandStarted, // macro expansion process has started
|
||||||
|
MacroExpandUndef // macro is undefined and will be expanded
|
||||||
|
};
|
||||||
|
|
||||||
|
// This class is the result of turning a huge pile of C code communicating through globals
|
||||||
|
// into a class. This was done to allowing instancing to attain thread safety.
|
||||||
|
// Don't expect too much in terms of OO design.
|
||||||
|
class TPpContext {
|
||||||
|
public:
|
||||||
|
TPpContext(TParseContextBase&, const std::string& rootFileName, TShader::Includer&);
|
||||||
|
virtual ~TPpContext();
|
||||||
|
|
||||||
|
void setPreamble(const char* preamble, size_t length);
|
||||||
|
|
||||||
|
int tokenize(TPpToken& ppToken);
|
||||||
|
int tokenPaste(int token, TPpToken&);
|
||||||
|
|
||||||
|
class tInput {
|
||||||
|
public:
|
||||||
|
tInput(TPpContext* p) : done(false), pp(p) { }
|
||||||
|
virtual ~tInput() { }
|
||||||
|
|
||||||
|
virtual int scan(TPpToken*) = 0;
|
||||||
|
virtual int getch() = 0;
|
||||||
|
virtual void ungetch() = 0;
|
||||||
|
virtual bool peekPasting() { return false; } // true when about to see ##
|
||||||
|
virtual bool peekContinuedPasting(int) { return false; } // true when non-spaced tokens can paste
|
||||||
|
virtual bool endOfReplacementList() { return false; } // true when at the end of a macro replacement list (RHS of #define)
|
||||||
|
virtual bool isMacroInput() { return false; }
|
||||||
|
|
||||||
|
// Will be called when we start reading tokens from this instance
|
||||||
|
virtual void notifyActivated() {}
|
||||||
|
// Will be called when we do not read tokens from this instance anymore
|
||||||
|
virtual void notifyDeleted() {}
|
||||||
|
protected:
|
||||||
|
bool done;
|
||||||
|
TPpContext* pp;
|
||||||
|
};
|
||||||
|
|
||||||
|
void setInput(TInputScanner& input, bool versionWillBeError);
|
||||||
|
|
||||||
|
void pushInput(tInput* in)
|
||||||
|
{
|
||||||
|
inputStack.push_back(in);
|
||||||
|
in->notifyActivated();
|
||||||
|
}
|
||||||
|
void popInput()
|
||||||
|
{
|
||||||
|
inputStack.back()->notifyDeleted();
|
||||||
|
delete inputStack.back();
|
||||||
|
inputStack.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// From PpTokens.cpp
|
||||||
|
//
|
||||||
|
|
||||||
|
// Capture the needed parts of a token stream for macro recording/playback.
|
||||||
|
class TokenStream {
|
||||||
|
public:
|
||||||
|
// Manage a stream of these 'Token', which capture the relevant parts
|
||||||
|
// of a TPpToken, plus its atom.
|
||||||
|
class Token {
|
||||||
|
public:
|
||||||
|
Token(int atom, const TPpToken& ppToken) :
|
||||||
|
atom(atom),
|
||||||
|
space(ppToken.space),
|
||||||
|
i64val(ppToken.i64val),
|
||||||
|
name(ppToken.name) { }
|
||||||
|
int get(TPpToken& ppToken)
|
||||||
|
{
|
||||||
|
ppToken.clear();
|
||||||
|
ppToken.space = space;
|
||||||
|
ppToken.i64val = i64val;
|
||||||
|
snprintf(ppToken.name, sizeof(ppToken.name), "%s", name.c_str());
|
||||||
|
return atom;
|
||||||
|
}
|
||||||
|
bool isAtom(int a) const { return atom == a; }
|
||||||
|
int getAtom() const { return atom; }
|
||||||
|
bool nonSpaced() const { return !space; }
|
||||||
|
protected:
|
||||||
|
Token() {}
|
||||||
|
int atom;
|
||||||
|
bool space; // did a space precede the token?
|
||||||
|
long long i64val;
|
||||||
|
TString name;
|
||||||
|
};
|
||||||
|
|
||||||
|
TokenStream() : currentPos(0) { }
|
||||||
|
|
||||||
|
void putToken(int token, TPpToken* ppToken);
|
||||||
|
bool peekToken(int atom) { return !atEnd() && stream[currentPos].isAtom(atom); }
|
||||||
|
bool peekContinuedPasting(int atom)
|
||||||
|
{
|
||||||
|
// This is basically necessary because, for example, the PP
|
||||||
|
// tokenizer only accepts valid numeric-literals plus suffixes, so
|
||||||
|
// separates numeric-literals plus bad suffix into two tokens, which
|
||||||
|
// should get both pasted together as one token when token pasting.
|
||||||
|
//
|
||||||
|
// The following code is a bit more generalized than the above example.
|
||||||
|
if (!atEnd() && atom == PpAtomIdentifier && stream[currentPos].nonSpaced()) {
|
||||||
|
switch(stream[currentPos].getAtom()) {
|
||||||
|
case PpAtomConstInt:
|
||||||
|
case PpAtomConstUint:
|
||||||
|
case PpAtomConstInt64:
|
||||||
|
case PpAtomConstUint64:
|
||||||
|
case PpAtomConstInt16:
|
||||||
|
case PpAtomConstUint16:
|
||||||
|
case PpAtomConstFloat:
|
||||||
|
case PpAtomConstDouble:
|
||||||
|
case PpAtomConstFloat16:
|
||||||
|
case PpAtomConstString:
|
||||||
|
case PpAtomIdentifier:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int getToken(TParseContextBase&, TPpToken*);
|
||||||
|
bool atEnd() { return currentPos >= stream.size(); }
|
||||||
|
bool peekTokenizedPasting(bool lastTokenPastes);
|
||||||
|
bool peekUntokenizedPasting();
|
||||||
|
void reset() { currentPos = 0; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TVector<Token> stream;
|
||||||
|
size_t currentPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// From Pp.cpp
|
||||||
|
//
|
||||||
|
|
||||||
|
struct MacroSymbol {
|
||||||
|
MacroSymbol() : functionLike(0), busy(0), undef(0) { }
|
||||||
|
TVector<int> args;
|
||||||
|
TokenStream body;
|
||||||
|
unsigned functionLike : 1; // 0 means object-like, 1 means function-like
|
||||||
|
unsigned busy : 1;
|
||||||
|
unsigned undef : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef TMap<int, MacroSymbol> TSymbolMap;
|
||||||
|
TSymbolMap macroDefs; // map atoms to macro definitions
|
||||||
|
MacroSymbol* lookupMacroDef(int atom)
|
||||||
|
{
|
||||||
|
auto existingMacroIt = macroDefs.find(atom);
|
||||||
|
return (existingMacroIt == macroDefs.end()) ? nullptr : &(existingMacroIt->second);
|
||||||
|
}
|
||||||
|
void addMacroDef(int atom, MacroSymbol& macroDef) { macroDefs[atom] = macroDef; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TPpContext(TPpContext&);
|
||||||
|
TPpContext& operator=(TPpContext&);
|
||||||
|
|
||||||
|
TStringAtomMap atomStrings;
|
||||||
|
char* preamble; // string to parse, all before line 1 of string 0, it is 0 if no preamble
|
||||||
|
int preambleLength;
|
||||||
|
char** strings; // official strings of shader, starting a string 0 line 1
|
||||||
|
size_t* lengths;
|
||||||
|
int numStrings; // how many official strings there are
|
||||||
|
int currentString; // which string we're currently parsing (-1 for preamble)
|
||||||
|
|
||||||
|
// Scanner data:
|
||||||
|
int previous_token;
|
||||||
|
TParseContextBase& parseContext;
|
||||||
|
|
||||||
|
// Get the next token from *stack* of input sources, popping input sources
|
||||||
|
// that are out of tokens, down until an input source is found that has a token.
|
||||||
|
// Return EndOfInput when there are no more tokens to be found by doing this.
|
||||||
|
int scanToken(TPpToken* ppToken)
|
||||||
|
{
|
||||||
|
int token = EndOfInput;
|
||||||
|
|
||||||
|
while (! inputStack.empty()) {
|
||||||
|
token = inputStack.back()->scan(ppToken);
|
||||||
|
if (token != EndOfInput || inputStack.empty())
|
||||||
|
break;
|
||||||
|
popInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
int getChar() { return inputStack.back()->getch(); }
|
||||||
|
void ungetChar() { inputStack.back()->ungetch(); }
|
||||||
|
bool peekPasting() { return !inputStack.empty() && inputStack.back()->peekPasting(); }
|
||||||
|
bool peekContinuedPasting(int a)
|
||||||
|
{
|
||||||
|
return !inputStack.empty() && inputStack.back()->peekContinuedPasting(a);
|
||||||
|
}
|
||||||
|
bool endOfReplacementList() { return inputStack.empty() || inputStack.back()->endOfReplacementList(); }
|
||||||
|
bool isMacroInput() { return inputStack.size() > 0 && inputStack.back()->isMacroInput(); }
|
||||||
|
|
||||||
|
static const int maxIfNesting = 65;
|
||||||
|
|
||||||
|
int ifdepth; // current #if-#else-#endif nesting in the cpp.c file (pre-processor)
|
||||||
|
bool elseSeen[maxIfNesting]; // Keep a track of whether an else has been seen at a particular depth
|
||||||
|
int elsetracker; // #if-#else and #endif constructs...Counter.
|
||||||
|
|
||||||
|
class tMacroInput : public tInput {
|
||||||
|
public:
|
||||||
|
tMacroInput(TPpContext* pp) : tInput(pp), prepaste(false), postpaste(false) { }
|
||||||
|
virtual ~tMacroInput()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < args.size(); ++i)
|
||||||
|
delete args[i];
|
||||||
|
for (size_t i = 0; i < expandedArgs.size(); ++i)
|
||||||
|
delete expandedArgs[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int scan(TPpToken*) override;
|
||||||
|
virtual int getch() override { assert(0); return EndOfInput; }
|
||||||
|
virtual void ungetch() override { assert(0); }
|
||||||
|
bool peekPasting() override { return prepaste; }
|
||||||
|
bool peekContinuedPasting(int a) override { return mac->body.peekContinuedPasting(a); }
|
||||||
|
bool endOfReplacementList() override { return mac->body.atEnd(); }
|
||||||
|
bool isMacroInput() override { return true; }
|
||||||
|
|
||||||
|
MacroSymbol *mac;
|
||||||
|
TVector<TokenStream*> args;
|
||||||
|
TVector<TokenStream*> expandedArgs;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool prepaste; // true if we are just before ##
|
||||||
|
bool postpaste; // true if we are right after ##
|
||||||
|
};
|
||||||
|
|
||||||
|
class tMarkerInput : public tInput {
|
||||||
|
public:
|
||||||
|
tMarkerInput(TPpContext* pp) : tInput(pp) { }
|
||||||
|
virtual int scan(TPpToken*) override
|
||||||
|
{
|
||||||
|
if (done)
|
||||||
|
return EndOfInput;
|
||||||
|
done = true;
|
||||||
|
|
||||||
|
return marker;
|
||||||
|
}
|
||||||
|
virtual int getch() override { assert(0); return EndOfInput; }
|
||||||
|
virtual void ungetch() override { assert(0); }
|
||||||
|
static const int marker = -3;
|
||||||
|
};
|
||||||
|
|
||||||
|
class tZeroInput : public tInput {
|
||||||
|
public:
|
||||||
|
tZeroInput(TPpContext* pp) : tInput(pp) { }
|
||||||
|
virtual int scan(TPpToken*) override;
|
||||||
|
virtual int getch() override { assert(0); return EndOfInput; }
|
||||||
|
virtual void ungetch() override { assert(0); }
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<tInput*> inputStack;
|
||||||
|
bool errorOnVersion;
|
||||||
|
bool versionSeen;
|
||||||
|
|
||||||
|
//
|
||||||
|
// from Pp.cpp
|
||||||
|
//
|
||||||
|
|
||||||
|
// Used to obtain #include content.
|
||||||
|
TShader::Includer& includer;
|
||||||
|
|
||||||
|
int CPPdefine(TPpToken * ppToken);
|
||||||
|
int CPPundef(TPpToken * ppToken);
|
||||||
|
int CPPelse(int matchelse, TPpToken * ppToken);
|
||||||
|
int extraTokenCheck(int atom, TPpToken* ppToken, int token);
|
||||||
|
int eval(int token, int precedence, bool shortCircuit, int& res, bool& err, TPpToken * ppToken);
|
||||||
|
int evalToToken(int token, bool shortCircuit, int& res, bool& err, TPpToken * ppToken);
|
||||||
|
int CPPif (TPpToken * ppToken);
|
||||||
|
int CPPifdef(int defined, TPpToken * ppToken);
|
||||||
|
int CPPinclude(TPpToken * ppToken);
|
||||||
|
int CPPline(TPpToken * ppToken);
|
||||||
|
int CPPerror(TPpToken * ppToken);
|
||||||
|
int CPPpragma(TPpToken * ppToken);
|
||||||
|
int CPPversion(TPpToken * ppToken);
|
||||||
|
int CPPextension(TPpToken * ppToken);
|
||||||
|
int readCPPline(TPpToken * ppToken);
|
||||||
|
int scanHeaderName(TPpToken* ppToken, char delimit);
|
||||||
|
TokenStream* PrescanMacroArg(TokenStream&, TPpToken*, bool newLineOkay);
|
||||||
|
MacroExpandResult MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay);
|
||||||
|
|
||||||
|
//
|
||||||
|
// From PpTokens.cpp
|
||||||
|
//
|
||||||
|
void pushTokenStreamInput(TokenStream&, bool pasting = false);
|
||||||
|
void UngetToken(int token, TPpToken*);
|
||||||
|
|
||||||
|
class tTokenInput : public tInput {
|
||||||
|
public:
|
||||||
|
tTokenInput(TPpContext* pp, TokenStream* t, bool prepasting) :
|
||||||
|
tInput(pp),
|
||||||
|
tokens(t),
|
||||||
|
lastTokenPastes(prepasting) { }
|
||||||
|
virtual int scan(TPpToken *ppToken) override { return tokens->getToken(pp->parseContext, ppToken); }
|
||||||
|
virtual int getch() override { assert(0); return EndOfInput; }
|
||||||
|
virtual void ungetch() override { assert(0); }
|
||||||
|
virtual bool peekPasting() override { return tokens->peekTokenizedPasting(lastTokenPastes); }
|
||||||
|
bool peekContinuedPasting(int a) override { return tokens->peekContinuedPasting(a); }
|
||||||
|
protected:
|
||||||
|
TokenStream* tokens;
|
||||||
|
bool lastTokenPastes; // true if the last token in the input is to be pasted, rather than consumed as a token
|
||||||
|
};
|
||||||
|
|
||||||
|
class tUngotTokenInput : public tInput {
|
||||||
|
public:
|
||||||
|
tUngotTokenInput(TPpContext* pp, int t, TPpToken* p) : tInput(pp), token(t), lval(*p) { }
|
||||||
|
virtual int scan(TPpToken *) override;
|
||||||
|
virtual int getch() override { assert(0); return EndOfInput; }
|
||||||
|
virtual void ungetch() override { assert(0); }
|
||||||
|
protected:
|
||||||
|
int token;
|
||||||
|
TPpToken lval;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// From PpScanner.cpp
|
||||||
|
//
|
||||||
|
class tStringInput : public tInput {
|
||||||
|
public:
|
||||||
|
tStringInput(TPpContext* pp, TInputScanner& i) : tInput(pp), input(&i) { }
|
||||||
|
virtual int scan(TPpToken*) override;
|
||||||
|
|
||||||
|
// Scanner used to get source stream characters.
|
||||||
|
// - Escaped newlines are handled here, invisibly to the caller.
|
||||||
|
// - All forms of newline are handled, and turned into just a '\n'.
|
||||||
|
int getch() override
|
||||||
|
{
|
||||||
|
int ch = input->get();
|
||||||
|
|
||||||
|
if (ch == '\\') {
|
||||||
|
// Move past escaped newlines, as many as sequentially exist
|
||||||
|
do {
|
||||||
|
if (input->peek() == '\r' || input->peek() == '\n') {
|
||||||
|
bool allowed = pp->parseContext.lineContinuationCheck(input->getSourceLoc(), pp->inComment);
|
||||||
|
if (! allowed && pp->inComment)
|
||||||
|
return '\\';
|
||||||
|
|
||||||
|
// escape one newline now
|
||||||
|
ch = input->get();
|
||||||
|
int nextch = input->get();
|
||||||
|
if (ch == '\r' && nextch == '\n')
|
||||||
|
ch = input->get();
|
||||||
|
else
|
||||||
|
ch = nextch;
|
||||||
|
} else
|
||||||
|
return '\\';
|
||||||
|
} while (ch == '\\');
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle any non-escaped newline
|
||||||
|
if (ch == '\r' || ch == '\n') {
|
||||||
|
if (ch == '\r' && input->peek() == '\n')
|
||||||
|
input->get();
|
||||||
|
return '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scanner used to backup the source stream characters. Newlines are
|
||||||
|
// handled here, invisibly to the caller, meaning have to undo exactly
|
||||||
|
// what getch() above does (e.g., don't leave things in the middle of a
|
||||||
|
// sequence of escaped newlines).
|
||||||
|
void ungetch() override
|
||||||
|
{
|
||||||
|
input->unget();
|
||||||
|
|
||||||
|
do {
|
||||||
|
int ch = input->peek();
|
||||||
|
if (ch == '\r' || ch == '\n') {
|
||||||
|
if (ch == '\n') {
|
||||||
|
// correct for two-character newline
|
||||||
|
input->unget();
|
||||||
|
if (input->peek() != '\r')
|
||||||
|
input->get();
|
||||||
|
}
|
||||||
|
// now in front of a complete newline, move past an escape character
|
||||||
|
input->unget();
|
||||||
|
if (input->peek() == '\\')
|
||||||
|
input->unget();
|
||||||
|
else {
|
||||||
|
input->get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TInputScanner* input;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Holds a reference to included file data, as well as a
|
||||||
|
// prologue and an epilogue string. This can be scanned using the tInput
|
||||||
|
// interface and acts as a single source string.
|
||||||
|
class TokenizableIncludeFile : public tInput {
|
||||||
|
public:
|
||||||
|
// Copies prologue and epilogue. The includedFile must remain valid
|
||||||
|
// until this TokenizableIncludeFile is no longer used.
|
||||||
|
TokenizableIncludeFile(const TSourceLoc& startLoc,
|
||||||
|
const std::string& prologue,
|
||||||
|
TShader::Includer::IncludeResult* includedFile,
|
||||||
|
const std::string& epilogue,
|
||||||
|
TPpContext* pp)
|
||||||
|
: tInput(pp),
|
||||||
|
prologue_(prologue),
|
||||||
|
epilogue_(epilogue),
|
||||||
|
includedFile_(includedFile),
|
||||||
|
scanner(3, strings, lengths, nullptr, 0, 0, true),
|
||||||
|
prevScanner(nullptr),
|
||||||
|
stringInput(pp, scanner)
|
||||||
|
{
|
||||||
|
strings[0] = prologue_.data();
|
||||||
|
strings[1] = includedFile_->headerData;
|
||||||
|
strings[2] = epilogue_.data();
|
||||||
|
|
||||||
|
lengths[0] = prologue_.size();
|
||||||
|
lengths[1] = includedFile_->headerLength;
|
||||||
|
lengths[2] = epilogue_.size();
|
||||||
|
|
||||||
|
scanner.setLine(startLoc.line);
|
||||||
|
scanner.setString(startLoc.string);
|
||||||
|
|
||||||
|
scanner.setFile(startLoc.getFilenameStr(), 0);
|
||||||
|
scanner.setFile(startLoc.getFilenameStr(), 1);
|
||||||
|
scanner.setFile(startLoc.getFilenameStr(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tInput methods:
|
||||||
|
int scan(TPpToken* t) override { return stringInput.scan(t); }
|
||||||
|
int getch() override { return stringInput.getch(); }
|
||||||
|
void ungetch() override { stringInput.ungetch(); }
|
||||||
|
|
||||||
|
void notifyActivated() override
|
||||||
|
{
|
||||||
|
prevScanner = pp->parseContext.getScanner();
|
||||||
|
pp->parseContext.setScanner(&scanner);
|
||||||
|
pp->push_include(includedFile_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void notifyDeleted() override
|
||||||
|
{
|
||||||
|
pp->parseContext.setScanner(prevScanner);
|
||||||
|
pp->pop_include();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
TokenizableIncludeFile& operator=(const TokenizableIncludeFile&);
|
||||||
|
|
||||||
|
// Stores the prologue for this string.
|
||||||
|
const std::string prologue_;
|
||||||
|
|
||||||
|
// Stores the epilogue for this string.
|
||||||
|
const std::string epilogue_;
|
||||||
|
|
||||||
|
// Points to the IncludeResult that this TokenizableIncludeFile represents.
|
||||||
|
TShader::Includer::IncludeResult* includedFile_;
|
||||||
|
|
||||||
|
// Will point to prologue_, includedFile_->headerData and epilogue_
|
||||||
|
// This is passed to scanner constructor.
|
||||||
|
// These do not own the storage and it must remain valid until this
|
||||||
|
// object has been destroyed.
|
||||||
|
const char* strings[3];
|
||||||
|
// Length of str_, passed to scanner constructor.
|
||||||
|
size_t lengths[3];
|
||||||
|
// Scans over str_.
|
||||||
|
TInputScanner scanner;
|
||||||
|
// The previous effective scanner before the scanner in this instance
|
||||||
|
// has been activated.
|
||||||
|
TInputScanner* prevScanner;
|
||||||
|
// Delegate object implementing the tInput interface.
|
||||||
|
tStringInput stringInput;
|
||||||
|
};
|
||||||
|
|
||||||
|
int ScanFromString(char* s);
|
||||||
|
void missingEndifCheck();
|
||||||
|
int lFloatConst(int len, int ch, TPpToken* ppToken);
|
||||||
|
int characterLiteral(TPpToken* ppToken);
|
||||||
|
|
||||||
|
void push_include(TShader::Includer::IncludeResult* result)
|
||||||
|
{
|
||||||
|
currentSourceFile = result->headerName;
|
||||||
|
includeStack.push(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop_include()
|
||||||
|
{
|
||||||
|
TShader::Includer::IncludeResult* include = includeStack.top();
|
||||||
|
includeStack.pop();
|
||||||
|
includer.releaseInclude(include);
|
||||||
|
if (includeStack.empty()) {
|
||||||
|
currentSourceFile = rootFileName;
|
||||||
|
} else {
|
||||||
|
currentSourceFile = includeStack.top()->headerName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool inComment;
|
||||||
|
std::string rootFileName;
|
||||||
|
std::stack<TShader::Includer::IncludeResult*> includeStack;
|
||||||
|
std::string currentSourceFile;
|
||||||
|
|
||||||
|
std::istringstream strtodStream;
|
||||||
|
bool disableEscapeSequences;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // PPCONTEXT_H
|
||||||
|
|
@ -0,0 +1,179 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
/****************************************************************************\
|
||||||
|
Copyright (c) 2002, NVIDIA Corporation.
|
||||||
|
|
||||||
|
NVIDIA Corporation("NVIDIA") supplies this software to you in
|
||||||
|
consideration of your agreement to the following terms, and your use,
|
||||||
|
installation, modification or redistribution of this NVIDIA software
|
||||||
|
constitutes acceptance of these terms. If you do not agree with these
|
||||||
|
terms, please do not use, install, modify or redistribute this NVIDIA
|
||||||
|
software.
|
||||||
|
|
||||||
|
In consideration of your agreement to abide by the following terms, and
|
||||||
|
subject to these terms, NVIDIA grants you a personal, non-exclusive
|
||||||
|
license, under NVIDIA's copyrights in this original NVIDIA software (the
|
||||||
|
"NVIDIA Software"), to use, reproduce, modify and redistribute the
|
||||||
|
NVIDIA Software, with or without modifications, in source and/or binary
|
||||||
|
forms; provided that if you redistribute the NVIDIA Software, you must
|
||||||
|
retain the copyright notice of NVIDIA, this notice and the following
|
||||||
|
text and disclaimers in all such redistributions of the NVIDIA Software.
|
||||||
|
Neither the name, trademarks, service marks nor logos of NVIDIA
|
||||||
|
Corporation may be used to endorse or promote products derived from the
|
||||||
|
NVIDIA Software without specific prior written permission from NVIDIA.
|
||||||
|
Except as expressly stated in this notice, no other rights or licenses
|
||||||
|
express or implied, are granted by NVIDIA herein, including but not
|
||||||
|
limited to any patent rights that may be infringed by your derivative
|
||||||
|
works or by other works in which the NVIDIA Software may be
|
||||||
|
incorporated. No hardware is licensed hereunder.
|
||||||
|
|
||||||
|
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
|
||||||
|
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
|
||||||
|
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
|
||||||
|
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
|
||||||
|
PRODUCTS.
|
||||||
|
|
||||||
|
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
|
||||||
|
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
|
||||||
|
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
|
||||||
|
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
|
||||||
|
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
\****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef PARSER_H
|
||||||
|
#define PARSER_H
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
// Multi-character tokens
|
||||||
|
enum EFixedAtoms {
|
||||||
|
// single character tokens get their own char value as their token; start here for multi-character tokens
|
||||||
|
PpAtomMaxSingle = 127,
|
||||||
|
|
||||||
|
// replace bad character tokens with this, to avoid accidental aliasing with the below
|
||||||
|
PpAtomBadToken,
|
||||||
|
|
||||||
|
// Operators
|
||||||
|
|
||||||
|
PPAtomAddAssign,
|
||||||
|
PPAtomSubAssign,
|
||||||
|
PPAtomMulAssign,
|
||||||
|
PPAtomDivAssign,
|
||||||
|
PPAtomModAssign,
|
||||||
|
|
||||||
|
PpAtomRight,
|
||||||
|
PpAtomLeft,
|
||||||
|
|
||||||
|
PpAtomRightAssign,
|
||||||
|
PpAtomLeftAssign,
|
||||||
|
PpAtomAndAssign,
|
||||||
|
PpAtomOrAssign,
|
||||||
|
PpAtomXorAssign,
|
||||||
|
|
||||||
|
PpAtomAnd,
|
||||||
|
PpAtomOr,
|
||||||
|
PpAtomXor,
|
||||||
|
|
||||||
|
PpAtomEQ,
|
||||||
|
PpAtomNE,
|
||||||
|
PpAtomGE,
|
||||||
|
PpAtomLE,
|
||||||
|
|
||||||
|
PpAtomDecrement,
|
||||||
|
PpAtomIncrement,
|
||||||
|
|
||||||
|
PpAtomColonColon,
|
||||||
|
|
||||||
|
PpAtomPaste,
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
|
||||||
|
PpAtomConstInt,
|
||||||
|
PpAtomConstUint,
|
||||||
|
PpAtomConstInt64,
|
||||||
|
PpAtomConstUint64,
|
||||||
|
PpAtomConstInt16,
|
||||||
|
PpAtomConstUint16,
|
||||||
|
PpAtomConstFloat,
|
||||||
|
PpAtomConstDouble,
|
||||||
|
PpAtomConstFloat16,
|
||||||
|
PpAtomConstString,
|
||||||
|
|
||||||
|
// Identifiers
|
||||||
|
PpAtomIdentifier,
|
||||||
|
|
||||||
|
// preprocessor "keywords"
|
||||||
|
|
||||||
|
PpAtomDefine,
|
||||||
|
PpAtomUndef,
|
||||||
|
|
||||||
|
PpAtomIf,
|
||||||
|
PpAtomIfdef,
|
||||||
|
PpAtomIfndef,
|
||||||
|
PpAtomElse,
|
||||||
|
PpAtomElif,
|
||||||
|
PpAtomEndif,
|
||||||
|
|
||||||
|
PpAtomLine,
|
||||||
|
PpAtomPragma,
|
||||||
|
PpAtomError,
|
||||||
|
|
||||||
|
// #version ...
|
||||||
|
PpAtomVersion,
|
||||||
|
PpAtomCore,
|
||||||
|
PpAtomCompatibility,
|
||||||
|
PpAtomEs,
|
||||||
|
|
||||||
|
// #extension
|
||||||
|
PpAtomExtension,
|
||||||
|
|
||||||
|
// __LINE__, __FILE__, __VERSION__
|
||||||
|
|
||||||
|
PpAtomLineMacro,
|
||||||
|
PpAtomFileMacro,
|
||||||
|
PpAtomVersionMacro,
|
||||||
|
|
||||||
|
// #include
|
||||||
|
PpAtomInclude,
|
||||||
|
|
||||||
|
PpAtomLast,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif /* not PARSER_H */
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015-2016 Google, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
//
|
||||||
|
// Visit the nodes in the glslang intermediate tree representation to
|
||||||
|
// propagate 'noContraction' qualifier.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../Include/intermediate.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
// Propagates the 'precise' qualifier for objects (objects marked with
|
||||||
|
// 'noContraction' qualifier) from the shader source specified 'precise'
|
||||||
|
// variables to all the involved objects, and add 'noContraction' qualifier for
|
||||||
|
// the involved arithmetic operations.
|
||||||
|
// Note that the same qualifier: 'noContraction' is used in both object nodes
|
||||||
|
// and arithmetic operation nodes, but has different meaning. For object nodes,
|
||||||
|
// 'noContraction' means the object is 'precise'; and for arithmetic operation
|
||||||
|
// nodes, it means the operation should not be contracted.
|
||||||
|
void PropagateNoContraction(const glslang::TIntermediate& intermediate);
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,223 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2013-2016 LunarG, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
|
||||||
|
#ifndef _REFLECTION_INCLUDED
|
||||||
|
#define _REFLECTION_INCLUDED
|
||||||
|
|
||||||
|
#include "../Public/ShaderLang.h"
|
||||||
|
#include "../Include/Types.h"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
//
|
||||||
|
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
class TIntermediate;
|
||||||
|
class TIntermAggregate;
|
||||||
|
class TReflectionTraverser;
|
||||||
|
|
||||||
|
// The full reflection database
|
||||||
|
class TReflection {
|
||||||
|
public:
|
||||||
|
TReflection(EShReflectionOptions opts, EShLanguage first, EShLanguage last)
|
||||||
|
: options(opts), firstStage(first), lastStage(last), badReflection(TObjectReflection::badReflection())
|
||||||
|
{
|
||||||
|
for (int dim=0; dim<3; ++dim)
|
||||||
|
localSize[dim] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~TReflection() {}
|
||||||
|
|
||||||
|
// grow the reflection stage by stage
|
||||||
|
bool addStage(EShLanguage, const TIntermediate&);
|
||||||
|
|
||||||
|
// for mapping a uniform index to a uniform object's description
|
||||||
|
int getNumUniforms() { return (int)indexToUniform.size(); }
|
||||||
|
const TObjectReflection& getUniform(int i) const
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < (int)indexToUniform.size())
|
||||||
|
return indexToUniform[i];
|
||||||
|
else
|
||||||
|
return badReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for mapping a block index to the block's description
|
||||||
|
int getNumUniformBlocks() const { return (int)indexToUniformBlock.size(); }
|
||||||
|
const TObjectReflection& getUniformBlock(int i) const
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < (int)indexToUniformBlock.size())
|
||||||
|
return indexToUniformBlock[i];
|
||||||
|
else
|
||||||
|
return badReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for mapping an pipeline input index to the input's description
|
||||||
|
int getNumPipeInputs() { return (int)indexToPipeInput.size(); }
|
||||||
|
const TObjectReflection& getPipeInput(int i) const
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < (int)indexToPipeInput.size())
|
||||||
|
return indexToPipeInput[i];
|
||||||
|
else
|
||||||
|
return badReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for mapping an pipeline output index to the output's description
|
||||||
|
int getNumPipeOutputs() { return (int)indexToPipeOutput.size(); }
|
||||||
|
const TObjectReflection& getPipeOutput(int i) const
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < (int)indexToPipeOutput.size())
|
||||||
|
return indexToPipeOutput[i];
|
||||||
|
else
|
||||||
|
return badReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for mapping from an atomic counter to the uniform index
|
||||||
|
int getNumAtomicCounters() const { return (int)atomicCounterUniformIndices.size(); }
|
||||||
|
const TObjectReflection& getAtomicCounter(int i) const
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < (int)atomicCounterUniformIndices.size())
|
||||||
|
return getUniform(atomicCounterUniformIndices[i]);
|
||||||
|
else
|
||||||
|
return badReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for mapping a buffer variable index to a buffer variable object's description
|
||||||
|
int getNumBufferVariables() { return (int)indexToBufferVariable.size(); }
|
||||||
|
const TObjectReflection& getBufferVariable(int i) const
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < (int)indexToBufferVariable.size())
|
||||||
|
return indexToBufferVariable[i];
|
||||||
|
else
|
||||||
|
return badReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for mapping a storage block index to the storage block's description
|
||||||
|
int getNumStorageBuffers() const { return (int)indexToBufferBlock.size(); }
|
||||||
|
const TObjectReflection& getStorageBufferBlock(int i) const
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < (int)indexToBufferBlock.size())
|
||||||
|
return indexToBufferBlock[i];
|
||||||
|
else
|
||||||
|
return badReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for mapping any name to its index (block names, uniform names and input/output names)
|
||||||
|
int getIndex(const char* name) const
|
||||||
|
{
|
||||||
|
TNameToIndex::const_iterator it = nameToIndex.find(name);
|
||||||
|
if (it == nameToIndex.end())
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// see getIndex(const char*)
|
||||||
|
int getIndex(const TString& name) const { return getIndex(name.c_str()); }
|
||||||
|
|
||||||
|
|
||||||
|
// for mapping any name to its index (only pipe input/output names)
|
||||||
|
int getPipeIOIndex(const char* name, const bool inOrOut) const
|
||||||
|
{
|
||||||
|
TNameToIndex::const_iterator it = inOrOut ? pipeInNameToIndex.find(name) : pipeOutNameToIndex.find(name);
|
||||||
|
if (it == (inOrOut ? pipeInNameToIndex.end() : pipeOutNameToIndex.end()))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// see gePipeIOIndex(const char*, const bool)
|
||||||
|
int getPipeIOIndex(const TString& name, const bool inOrOut) const { return getPipeIOIndex(name.c_str(), inOrOut); }
|
||||||
|
|
||||||
|
// Thread local size
|
||||||
|
unsigned getLocalSize(int dim) const { return dim <= 2 ? localSize[dim] : 0; }
|
||||||
|
|
||||||
|
void dump();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class glslang::TReflectionTraverser;
|
||||||
|
|
||||||
|
void buildCounterIndices(const TIntermediate&);
|
||||||
|
void buildUniformStageMask(const TIntermediate& intermediate);
|
||||||
|
void buildAttributeReflection(EShLanguage, const TIntermediate&);
|
||||||
|
|
||||||
|
// Need a TString hash: typedef std::unordered_map<TString, int> TNameToIndex;
|
||||||
|
typedef std::map<std::string, int> TNameToIndex;
|
||||||
|
typedef std::vector<TObjectReflection> TMapIndexToReflection;
|
||||||
|
typedef std::vector<int> TIndices;
|
||||||
|
|
||||||
|
TMapIndexToReflection& GetBlockMapForStorage(TStorageQualifier storage)
|
||||||
|
{
|
||||||
|
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
|
||||||
|
return indexToBufferBlock;
|
||||||
|
return indexToUniformBlock;
|
||||||
|
}
|
||||||
|
TMapIndexToReflection& GetVariableMapForStorage(TStorageQualifier storage)
|
||||||
|
{
|
||||||
|
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
|
||||||
|
return indexToBufferVariable;
|
||||||
|
return indexToUniform;
|
||||||
|
}
|
||||||
|
|
||||||
|
EShReflectionOptions options;
|
||||||
|
|
||||||
|
EShLanguage firstStage;
|
||||||
|
EShLanguage lastStage;
|
||||||
|
|
||||||
|
TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this
|
||||||
|
TNameToIndex nameToIndex; // maps names to indexes; can hold all types of data: uniform/buffer and which function names have been processed
|
||||||
|
TNameToIndex pipeInNameToIndex; // maps pipe in names to indexes, this is a fix to seperate pipe I/O from uniforms and buffers.
|
||||||
|
TNameToIndex pipeOutNameToIndex; // maps pipe out names to indexes, this is a fix to seperate pipe I/O from uniforms and buffers.
|
||||||
|
TMapIndexToReflection indexToUniform;
|
||||||
|
TMapIndexToReflection indexToUniformBlock;
|
||||||
|
TMapIndexToReflection indexToBufferVariable;
|
||||||
|
TMapIndexToReflection indexToBufferBlock;
|
||||||
|
TMapIndexToReflection indexToPipeInput;
|
||||||
|
TMapIndexToReflection indexToPipeOutput;
|
||||||
|
TIndices atomicCounterUniformIndices;
|
||||||
|
|
||||||
|
unsigned int localSize[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _REFLECTION_INCLUDED
|
||||||
|
|
||||||
|
#endif // GLSLANG_WEB
|
||||||
|
|
@ -0,0 +1,932 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2013-2016 LunarG, Inc.
|
||||||
|
// Copyright (C) 2015-2018 Google, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
#ifndef _COMPILER_INTERFACE_INCLUDED_
|
||||||
|
#define _COMPILER_INTERFACE_INCLUDED_
|
||||||
|
|
||||||
|
#include "../Include/ResourceLimits.h"
|
||||||
|
#include "../MachineIndependent/Versions.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define C_DECL __cdecl
|
||||||
|
//#ifdef SH_EXPORTING
|
||||||
|
// #define SH_IMPORT_EXPORT __declspec(dllexport)
|
||||||
|
//#else
|
||||||
|
// #define SH_IMPORT_EXPORT __declspec(dllimport)
|
||||||
|
//#endif
|
||||||
|
#define SH_IMPORT_EXPORT
|
||||||
|
#else
|
||||||
|
#define SH_IMPORT_EXPORT
|
||||||
|
#define C_DECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is the platform independent interface between an OGL driver
|
||||||
|
// and the shading language compiler/linker.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This should always increase, as some paths to do not consume
|
||||||
|
// a more major number.
|
||||||
|
// It should increment by one when new functionality is added.
|
||||||
|
#define GLSLANG_MINOR_VERSION 14
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call before doing any other compiler/linker operations.
|
||||||
|
//
|
||||||
|
// (Call once per process, not once per thread.)
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT int ShInitialize();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call this at process shutdown to clean up memory.
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT int ShFinalize();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Types of languages the compiler can consume.
|
||||||
|
//
|
||||||
|
typedef enum {
|
||||||
|
EShLangVertex,
|
||||||
|
EShLangTessControl,
|
||||||
|
EShLangTessEvaluation,
|
||||||
|
EShLangGeometry,
|
||||||
|
EShLangFragment,
|
||||||
|
EShLangCompute,
|
||||||
|
EShLangRayGen,
|
||||||
|
EShLangRayGenNV = EShLangRayGen,
|
||||||
|
EShLangIntersect,
|
||||||
|
EShLangIntersectNV = EShLangIntersect,
|
||||||
|
EShLangAnyHit,
|
||||||
|
EShLangAnyHitNV = EShLangAnyHit,
|
||||||
|
EShLangClosestHit,
|
||||||
|
EShLangClosestHitNV = EShLangClosestHit,
|
||||||
|
EShLangMiss,
|
||||||
|
EShLangMissNV = EShLangMiss,
|
||||||
|
EShLangCallable,
|
||||||
|
EShLangCallableNV = EShLangCallable,
|
||||||
|
EShLangTaskNV,
|
||||||
|
EShLangMeshNV,
|
||||||
|
LAST_ELEMENT_MARKER(EShLangCount),
|
||||||
|
} EShLanguage; // would be better as stage, but this is ancient now
|
||||||
|
|
||||||
|
typedef enum : unsigned {
|
||||||
|
EShLangVertexMask = (1 << EShLangVertex),
|
||||||
|
EShLangTessControlMask = (1 << EShLangTessControl),
|
||||||
|
EShLangTessEvaluationMask = (1 << EShLangTessEvaluation),
|
||||||
|
EShLangGeometryMask = (1 << EShLangGeometry),
|
||||||
|
EShLangFragmentMask = (1 << EShLangFragment),
|
||||||
|
EShLangComputeMask = (1 << EShLangCompute),
|
||||||
|
EShLangRayGenMask = (1 << EShLangRayGen),
|
||||||
|
EShLangRayGenNVMask = EShLangRayGenMask,
|
||||||
|
EShLangIntersectMask = (1 << EShLangIntersect),
|
||||||
|
EShLangIntersectNVMask = EShLangIntersectMask,
|
||||||
|
EShLangAnyHitMask = (1 << EShLangAnyHit),
|
||||||
|
EShLangAnyHitNVMask = EShLangAnyHitMask,
|
||||||
|
EShLangClosestHitMask = (1 << EShLangClosestHit),
|
||||||
|
EShLangClosestHitNVMask = EShLangClosestHitMask,
|
||||||
|
EShLangMissMask = (1 << EShLangMiss),
|
||||||
|
EShLangMissNVMask = EShLangMissMask,
|
||||||
|
EShLangCallableMask = (1 << EShLangCallable),
|
||||||
|
EShLangCallableNVMask = EShLangCallableMask,
|
||||||
|
EShLangTaskNVMask = (1 << EShLangTaskNV),
|
||||||
|
EShLangMeshNVMask = (1 << EShLangMeshNV),
|
||||||
|
LAST_ELEMENT_MARKER(EShLanguageMaskCount),
|
||||||
|
} EShLanguageMask;
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
class TType;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EShSourceNone,
|
||||||
|
EShSourceGlsl, // GLSL, includes ESSL (OpenGL ES GLSL)
|
||||||
|
EShSourceHlsl, // HLSL
|
||||||
|
LAST_ELEMENT_MARKER(EShSourceCount),
|
||||||
|
} EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EShClientNone, // use when there is no client, e.g. for validation
|
||||||
|
EShClientVulkan,
|
||||||
|
EShClientOpenGL,
|
||||||
|
LAST_ELEMENT_MARKER(EShClientCount),
|
||||||
|
} EShClient;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EShTargetNone,
|
||||||
|
EShTargetSpv, // SPIR-V (preferred spelling)
|
||||||
|
EshTargetSpv = EShTargetSpv, // legacy spelling
|
||||||
|
LAST_ELEMENT_MARKER(EShTargetCount),
|
||||||
|
} EShTargetLanguage;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EShTargetVulkan_1_0 = (1 << 22), // Vulkan 1.0
|
||||||
|
EShTargetVulkan_1_1 = (1 << 22) | (1 << 12), // Vulkan 1.1
|
||||||
|
EShTargetVulkan_1_2 = (1 << 22) | (2 << 12), // Vulkan 1.2
|
||||||
|
EShTargetOpenGL_450 = 450, // OpenGL
|
||||||
|
LAST_ELEMENT_MARKER(EShTargetClientVersionCount),
|
||||||
|
} EShTargetClientVersion;
|
||||||
|
|
||||||
|
typedef EShTargetClientVersion EshTargetClientVersion;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EShTargetSpv_1_0 = (1 << 16), // SPIR-V 1.0
|
||||||
|
EShTargetSpv_1_1 = (1 << 16) | (1 << 8), // SPIR-V 1.1
|
||||||
|
EShTargetSpv_1_2 = (1 << 16) | (2 << 8), // SPIR-V 1.2
|
||||||
|
EShTargetSpv_1_3 = (1 << 16) | (3 << 8), // SPIR-V 1.3
|
||||||
|
EShTargetSpv_1_4 = (1 << 16) | (4 << 8), // SPIR-V 1.4
|
||||||
|
EShTargetSpv_1_5 = (1 << 16) | (5 << 8), // SPIR-V 1.5
|
||||||
|
LAST_ELEMENT_MARKER(EShTargetLanguageVersionCount),
|
||||||
|
} EShTargetLanguageVersion;
|
||||||
|
|
||||||
|
struct TInputLanguage {
|
||||||
|
EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone
|
||||||
|
EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone
|
||||||
|
EShClient dialect;
|
||||||
|
int dialectVersion; // version of client's language definition, not the client (when not EShClientNone)
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TClient {
|
||||||
|
EShClient client;
|
||||||
|
EShTargetClientVersion version; // version of client itself (not the client's input dialect)
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TTarget {
|
||||||
|
EShTargetLanguage language;
|
||||||
|
EShTargetLanguageVersion version; // version to target, if SPIR-V, defined by "word 1" of the SPIR-V header
|
||||||
|
bool hlslFunctionality1; // can target hlsl_functionality1 extension(s)
|
||||||
|
};
|
||||||
|
|
||||||
|
// All source/client/target versions and settings.
|
||||||
|
// Can override previous methods of setting, when items are set here.
|
||||||
|
// Expected to grow, as more are added, rather than growing parameter lists.
|
||||||
|
struct TEnvironment {
|
||||||
|
TInputLanguage input; // definition of the input language
|
||||||
|
TClient client; // what client is the overall compilation being done for?
|
||||||
|
TTarget target; // what to generate
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* StageName(EShLanguage);
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
//
|
||||||
|
// Types of output the linker will create.
|
||||||
|
//
|
||||||
|
typedef enum {
|
||||||
|
EShExVertexFragment,
|
||||||
|
EShExFragment
|
||||||
|
} EShExecutable;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Optimization level for the compiler.
|
||||||
|
//
|
||||||
|
typedef enum {
|
||||||
|
EShOptNoGeneration,
|
||||||
|
EShOptNone,
|
||||||
|
EShOptSimple, // Optimizations that can be done quickly
|
||||||
|
EShOptFull, // Optimizations that will take more time
|
||||||
|
LAST_ELEMENT_MARKER(EshOptLevelCount),
|
||||||
|
} EShOptimizationLevel;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Texture and Sampler transformation mode.
|
||||||
|
//
|
||||||
|
typedef enum {
|
||||||
|
EShTexSampTransKeep, // keep textures and samplers as is (default)
|
||||||
|
EShTexSampTransUpgradeTextureRemoveSampler, // change texture w/o embeded sampler into sampled texture and throw away all samplers
|
||||||
|
LAST_ELEMENT_MARKER(EShTexSampTransCount),
|
||||||
|
} EShTextureSamplerTransformMode;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Message choices for what errors and warnings are given.
|
||||||
|
//
|
||||||
|
enum EShMessages : unsigned {
|
||||||
|
EShMsgDefault = 0, // default is to give all required errors and extra warnings
|
||||||
|
EShMsgRelaxedErrors = (1 << 0), // be liberal in accepting input
|
||||||
|
EShMsgSuppressWarnings = (1 << 1), // suppress all warnings, except those required by the specification
|
||||||
|
EShMsgAST = (1 << 2), // print the AST intermediate representation
|
||||||
|
EShMsgSpvRules = (1 << 3), // issue messages for SPIR-V generation
|
||||||
|
EShMsgVulkanRules = (1 << 4), // issue messages for Vulkan-requirements of GLSL for SPIR-V
|
||||||
|
EShMsgOnlyPreprocessor = (1 << 5), // only print out errors produced by the preprocessor
|
||||||
|
EShMsgReadHlsl = (1 << 6), // use HLSL parsing rules and semantics
|
||||||
|
EShMsgCascadingErrors = (1 << 7), // get cascading errors; risks error-recovery issues, instead of an early exit
|
||||||
|
EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions
|
||||||
|
EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules
|
||||||
|
EShMsgDebugInfo = (1 << 10), // save debug information
|
||||||
|
EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
|
||||||
|
EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages
|
||||||
|
EShMsgHlslDX9Compatible = (1 << 13), // enable HLSL DX9 compatible mode (for samplers and semantics)
|
||||||
|
EShMsgBuiltinSymbolTable = (1 << 14), // print the builtin symbol table
|
||||||
|
LAST_ELEMENT_MARKER(EShMsgCount),
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Options for building reflection
|
||||||
|
//
|
||||||
|
typedef enum {
|
||||||
|
EShReflectionDefault = 0, // default is original behaviour before options were added
|
||||||
|
EShReflectionStrictArraySuffix = (1 << 0), // reflection will follow stricter rules for array-of-structs suffixes
|
||||||
|
EShReflectionBasicArraySuffix = (1 << 1), // arrays of basic types will be appended with [0] as in GL reflection
|
||||||
|
EShReflectionIntermediateIO = (1 << 2), // reflect inputs and outputs to program, even with no vertex shader
|
||||||
|
EShReflectionSeparateBuffers = (1 << 3), // buffer variables and buffer blocks are reflected separately
|
||||||
|
EShReflectionAllBlockVariables = (1 << 4), // reflect all variables in blocks, even if they are inactive
|
||||||
|
EShReflectionUnwrapIOBlocks = (1 << 5), // unwrap input/output blocks the same as with uniform blocks
|
||||||
|
EShReflectionAllIOVariables = (1 << 6), // reflect all input/output variables, even if they are inactive
|
||||||
|
EShReflectionSharedStd140SSBO = (1 << 7), // Apply std140/shared rules for ubo to ssbo
|
||||||
|
EShReflectionSharedStd140UBO = (1 << 8), // Apply std140/shared rules for ubo to ssbo
|
||||||
|
LAST_ELEMENT_MARKER(EShReflectionCount),
|
||||||
|
} EShReflectionOptions;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Build a table for bindings. This can be used for locating
|
||||||
|
// attributes, uniforms, globals, etc., as needed.
|
||||||
|
//
|
||||||
|
typedef struct {
|
||||||
|
const char* name;
|
||||||
|
int binding;
|
||||||
|
} ShBinding;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int numBindings;
|
||||||
|
ShBinding* bindings; // array of bindings
|
||||||
|
} ShBindingTable;
|
||||||
|
|
||||||
|
//
|
||||||
|
// ShHandle held by but opaque to the driver. It is allocated,
|
||||||
|
// managed, and de-allocated by the compiler/linker. It's contents
|
||||||
|
// are defined by and used by the compiler and linker. For example,
|
||||||
|
// symbol table information and object code passed from the compiler
|
||||||
|
// to the linker can be stored where ShHandle points.
|
||||||
|
//
|
||||||
|
// If handle creation fails, 0 will be returned.
|
||||||
|
//
|
||||||
|
typedef void* ShHandle;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Driver calls these to create and destroy compiler/linker
|
||||||
|
// objects.
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int debugOptions); // one per shader
|
||||||
|
SH_IMPORT_EXPORT ShHandle ShConstructLinker(const EShExecutable, int debugOptions); // one per shader pair
|
||||||
|
SH_IMPORT_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object)
|
||||||
|
SH_IMPORT_EXPORT void ShDestruct(ShHandle);
|
||||||
|
|
||||||
|
//
|
||||||
|
// The return value of ShCompile is boolean, non-zero indicating
|
||||||
|
// success.
|
||||||
|
//
|
||||||
|
// The info-log should be written by ShCompile into
|
||||||
|
// ShHandle, so it can answer future queries.
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT int ShCompile(
|
||||||
|
const ShHandle,
|
||||||
|
const char* const shaderStrings[],
|
||||||
|
const int numStrings,
|
||||||
|
const int* lengths,
|
||||||
|
const EShOptimizationLevel,
|
||||||
|
const TBuiltInResource *resources,
|
||||||
|
int debugOptions,
|
||||||
|
int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
|
||||||
|
bool forwardCompatible = false, // give errors for use of deprecated features
|
||||||
|
EShMessages messages = EShMsgDefault // warnings and errors
|
||||||
|
);
|
||||||
|
|
||||||
|
SH_IMPORT_EXPORT int ShLinkExt(
|
||||||
|
const ShHandle, // linker object
|
||||||
|
const ShHandle h[], // compiler objects to link together
|
||||||
|
const int numHandles);
|
||||||
|
|
||||||
|
//
|
||||||
|
// ShSetEncrpytionMethod is a place-holder for specifying
|
||||||
|
// how source code is encrypted.
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT void ShSetEncryptionMethod(ShHandle);
|
||||||
|
|
||||||
|
//
|
||||||
|
// All the following return 0 if the information is not
|
||||||
|
// available in the object passed down, or the object is bad.
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT const char* ShGetInfoLog(const ShHandle);
|
||||||
|
SH_IMPORT_EXPORT const void* ShGetExecutable(const ShHandle);
|
||||||
|
SH_IMPORT_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing
|
||||||
|
SH_IMPORT_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings
|
||||||
|
//
|
||||||
|
// Tell the linker to never assign a vertex attribute to this list of physical attributes
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Returns the location ID of the named uniform.
|
||||||
|
// Returns -1 if error.
|
||||||
|
//
|
||||||
|
SH_IMPORT_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // end extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Deferred-Lowering C++ Interface
|
||||||
|
// -----------------------------------
|
||||||
|
//
|
||||||
|
// Below is a new alternate C++ interface, which deprecates the above
|
||||||
|
// opaque handle-based interface.
|
||||||
|
//
|
||||||
|
// The below is further designed to handle multiple compilation units per stage, where
|
||||||
|
// the intermediate results, including the parse tree, are preserved until link time,
|
||||||
|
// rather than the above interface which is designed to have each compilation unit
|
||||||
|
// lowered at compile time. In the above model, linking occurs on the lowered results,
|
||||||
|
// whereas in this model intra-stage linking can occur at the parse tree
|
||||||
|
// (treeRoot in TIntermediate) level, and then a full stage can be lowered.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
class TCompiler;
|
||||||
|
class TInfoSink;
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
const char* GetEsslVersionString();
|
||||||
|
const char* GetGlslVersionString();
|
||||||
|
int GetKhronosToolId();
|
||||||
|
|
||||||
|
class TIntermediate;
|
||||||
|
class TProgram;
|
||||||
|
class TPoolAllocator;
|
||||||
|
|
||||||
|
// Call this exactly once per process before using anything else
|
||||||
|
bool InitializeProcess();
|
||||||
|
|
||||||
|
// Call once per process to tear down everything
|
||||||
|
void FinalizeProcess();
|
||||||
|
|
||||||
|
// Resource type for IO resolver
|
||||||
|
enum TResourceType {
|
||||||
|
EResSampler,
|
||||||
|
EResTexture,
|
||||||
|
EResImage,
|
||||||
|
EResUbo,
|
||||||
|
EResSsbo,
|
||||||
|
EResUav,
|
||||||
|
EResCount
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Make one TShader per shader that you will link into a program. Then
|
||||||
|
// - provide the shader through setStrings() or setStringsWithLengths()
|
||||||
|
// - optionally call setEnv*(), see below for more detail
|
||||||
|
// - optionally use setPreamble() to set a special shader string that will be
|
||||||
|
// processed before all others but won't affect the validity of #version
|
||||||
|
// - optionally call addProcesses() for each setting/transform,
|
||||||
|
// see comment for class TProcesses
|
||||||
|
// - call parse(): source language and target environment must be selected
|
||||||
|
// either by correct setting of EShMessages sent to parse(), or by
|
||||||
|
// explicitly calling setEnv*()
|
||||||
|
// - query the info logs
|
||||||
|
//
|
||||||
|
// N.B.: Does not yet support having the same TShader instance being linked into
|
||||||
|
// multiple programs.
|
||||||
|
//
|
||||||
|
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||||
|
//
|
||||||
|
class TShader {
|
||||||
|
public:
|
||||||
|
explicit TShader(EShLanguage);
|
||||||
|
virtual ~TShader();
|
||||||
|
void setStrings(const char* const* s, int n);
|
||||||
|
void setStringsWithLengths(const char* const* s, const int* l, int n);
|
||||||
|
void setStringsWithLengthsAndNames(
|
||||||
|
const char* const* s, const int* l, const char* const* names, int n);
|
||||||
|
void setPreamble(const char* s) { preamble = s; }
|
||||||
|
void setEntryPoint(const char* entryPoint);
|
||||||
|
void setSourceEntryPoint(const char* sourceEntryPointName);
|
||||||
|
void addProcesses(const std::vector<std::string>&);
|
||||||
|
|
||||||
|
// IO resolver binding data: see comments in ShaderLang.cpp
|
||||||
|
void setShiftBinding(TResourceType res, unsigned int base);
|
||||||
|
void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||||
|
void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||||
|
void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||||
|
void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||||
|
void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||||
|
void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
|
||||||
|
void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||||
|
void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set);
|
||||||
|
void setResourceSetBinding(const std::vector<std::string>& base);
|
||||||
|
void setAutoMapBindings(bool map);
|
||||||
|
void setAutoMapLocations(bool map);
|
||||||
|
void addUniformLocationOverride(const char* name, int loc);
|
||||||
|
void setUniformLocationBase(int base);
|
||||||
|
void setInvertY(bool invert);
|
||||||
|
#ifdef ENABLE_HLSL
|
||||||
|
void setHlslIoMapping(bool hlslIoMap);
|
||||||
|
void setFlattenUniformArrays(bool flatten);
|
||||||
|
#endif
|
||||||
|
void setNoStorageFormat(bool useUnknownFormat);
|
||||||
|
void setNanMinMaxClamp(bool nanMinMaxClamp);
|
||||||
|
void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode);
|
||||||
|
|
||||||
|
// For setting up the environment (cleared to nothingness in the constructor).
|
||||||
|
// These must be called so that parsing is done for the right source language and
|
||||||
|
// target environment, either indirectly through TranslateEnvironment() based on
|
||||||
|
// EShMessages et. al., or directly by the user.
|
||||||
|
//
|
||||||
|
// setEnvInput: The input source language and stage. If generating code for a
|
||||||
|
// specific client, the input client semantics to use and the
|
||||||
|
// version of the that client's input semantics to use, otherwise
|
||||||
|
// use EShClientNone and version of 0, e.g. for validation mode.
|
||||||
|
// Note 'version' does not describe the target environment,
|
||||||
|
// just the version of the source dialect to compile under.
|
||||||
|
//
|
||||||
|
// See the definitions of TEnvironment, EShSource, EShLanguage,
|
||||||
|
// and EShClient for choices and more detail.
|
||||||
|
//
|
||||||
|
// setEnvClient: The client that will be hosting the execution, and it's version.
|
||||||
|
// Note 'version' is not the version of the languages involved, but
|
||||||
|
// the version of the client environment.
|
||||||
|
// Use EShClientNone and version of 0 if there is no client, e.g.
|
||||||
|
// for validation mode.
|
||||||
|
//
|
||||||
|
// See EShTargetClientVersion for choices.
|
||||||
|
//
|
||||||
|
// setEnvTarget: The language to translate to when generating code, and that
|
||||||
|
// language's version.
|
||||||
|
// Use EShTargetNone and version of 0 if there is no client, e.g.
|
||||||
|
// for validation mode.
|
||||||
|
//
|
||||||
|
void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version)
|
||||||
|
{
|
||||||
|
environment.input.languageFamily = lang;
|
||||||
|
environment.input.stage = envStage;
|
||||||
|
environment.input.dialect = client;
|
||||||
|
environment.input.dialectVersion = version;
|
||||||
|
}
|
||||||
|
void setEnvClient(EShClient client, EShTargetClientVersion version)
|
||||||
|
{
|
||||||
|
environment.client.client = client;
|
||||||
|
environment.client.version = version;
|
||||||
|
}
|
||||||
|
void setEnvTarget(EShTargetLanguage lang, EShTargetLanguageVersion version)
|
||||||
|
{
|
||||||
|
environment.target.language = lang;
|
||||||
|
environment.target.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getStrings(const char* const* &s, int& n) { s = strings; n = numStrings; }
|
||||||
|
|
||||||
|
#ifdef ENABLE_HLSL
|
||||||
|
void setEnvTargetHlslFunctionality1() { environment.target.hlslFunctionality1 = true; }
|
||||||
|
bool getEnvTargetHlslFunctionality1() const { return environment.target.hlslFunctionality1; }
|
||||||
|
#else
|
||||||
|
bool getEnvTargetHlslFunctionality1() const { return false; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Interface to #include handlers.
|
||||||
|
//
|
||||||
|
// To support #include, a client of Glslang does the following:
|
||||||
|
// 1. Call setStringsWithNames to set the source strings and associated
|
||||||
|
// names. For example, the names could be the names of the files
|
||||||
|
// containing the shader sources.
|
||||||
|
// 2. Call parse with an Includer.
|
||||||
|
//
|
||||||
|
// When the Glslang parser encounters an #include directive, it calls
|
||||||
|
// the Includer's include method with the requested include name
|
||||||
|
// together with the current string name. The returned IncludeResult
|
||||||
|
// contains the fully resolved name of the included source, together
|
||||||
|
// with the source text that should replace the #include directive
|
||||||
|
// in the source stream. After parsing that source, Glslang will
|
||||||
|
// release the IncludeResult object.
|
||||||
|
class Includer {
|
||||||
|
public:
|
||||||
|
// An IncludeResult contains the resolved name and content of a source
|
||||||
|
// inclusion.
|
||||||
|
struct IncludeResult {
|
||||||
|
IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) :
|
||||||
|
headerName(headerName), headerData(headerData), headerLength(headerLength), userData(userData) { }
|
||||||
|
// For a successful inclusion, the fully resolved name of the requested
|
||||||
|
// include. For example, in a file system-based includer, full resolution
|
||||||
|
// should convert a relative path name into an absolute path name.
|
||||||
|
// For a failed inclusion, this is an empty string.
|
||||||
|
const std::string headerName;
|
||||||
|
// The content and byte length of the requested inclusion. The
|
||||||
|
// Includer producing this IncludeResult retains ownership of the
|
||||||
|
// storage.
|
||||||
|
// For a failed inclusion, the header
|
||||||
|
// field points to a string containing error details.
|
||||||
|
const char* const headerData;
|
||||||
|
const size_t headerLength;
|
||||||
|
// Include resolver's context.
|
||||||
|
void* userData;
|
||||||
|
protected:
|
||||||
|
IncludeResult& operator=(const IncludeResult&);
|
||||||
|
IncludeResult();
|
||||||
|
};
|
||||||
|
|
||||||
|
// For both include methods below:
|
||||||
|
//
|
||||||
|
// Resolves an inclusion request by name, current source name,
|
||||||
|
// and include depth.
|
||||||
|
// On success, returns an IncludeResult containing the resolved name
|
||||||
|
// and content of the include.
|
||||||
|
// On failure, returns a nullptr, or an IncludeResult
|
||||||
|
// with an empty string for the headerName and error details in the
|
||||||
|
// header field.
|
||||||
|
// The Includer retains ownership of the contents
|
||||||
|
// of the returned IncludeResult value, and those contents must
|
||||||
|
// remain valid until the releaseInclude method is called on that
|
||||||
|
// IncludeResult object.
|
||||||
|
//
|
||||||
|
// Note "local" vs. "system" is not an "either/or": "local" is an
|
||||||
|
// extra thing to do over "system". Both might get called, as per
|
||||||
|
// the C++ specification.
|
||||||
|
|
||||||
|
// For the "system" or <>-style includes; search the "system" paths.
|
||||||
|
virtual IncludeResult* includeSystem(const char* /*headerName*/,
|
||||||
|
const char* /*includerName*/,
|
||||||
|
size_t /*inclusionDepth*/) { return nullptr; }
|
||||||
|
|
||||||
|
// For the "local"-only aspect of a "" include. Should not search in the
|
||||||
|
// "system" paths, because on returning a failure, the parser will
|
||||||
|
// call includeSystem() to look in the "system" locations.
|
||||||
|
virtual IncludeResult* includeLocal(const char* /*headerName*/,
|
||||||
|
const char* /*includerName*/,
|
||||||
|
size_t /*inclusionDepth*/) { return nullptr; }
|
||||||
|
|
||||||
|
// Signals that the parser will no longer use the contents of the
|
||||||
|
// specified IncludeResult.
|
||||||
|
virtual void releaseInclude(IncludeResult*) = 0;
|
||||||
|
virtual ~Includer() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fail all Includer searches
|
||||||
|
class ForbidIncluder : public Includer {
|
||||||
|
public:
|
||||||
|
virtual void releaseInclude(IncludeResult*) override { }
|
||||||
|
};
|
||||||
|
|
||||||
|
bool parse(const TBuiltInResource*, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||||
|
bool forwardCompatible, EShMessages, Includer&);
|
||||||
|
|
||||||
|
bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||||
|
bool forwardCompatible, EShMessages messages)
|
||||||
|
{
|
||||||
|
TShader::ForbidIncluder includer;
|
||||||
|
return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Equivalent to parse() without a default profile and without forcing defaults.
|
||||||
|
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
|
||||||
|
{
|
||||||
|
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages,
|
||||||
|
Includer& includer)
|
||||||
|
{
|
||||||
|
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages, includer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Doing just preprocessing to obtain a correct preprocessed shader string
|
||||||
|
// is not an officially supported or fully working path.
|
||||||
|
bool preprocess(const TBuiltInResource* builtInResources,
|
||||||
|
int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||||
|
bool forwardCompatible, EShMessages message, std::string* outputString,
|
||||||
|
Includer& includer);
|
||||||
|
|
||||||
|
const char* getInfoLog();
|
||||||
|
const char* getInfoDebugLog();
|
||||||
|
EShLanguage getStage() const { return stage; }
|
||||||
|
TIntermediate* getIntermediate() const { return intermediate; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TPoolAllocator* pool;
|
||||||
|
EShLanguage stage;
|
||||||
|
TCompiler* compiler;
|
||||||
|
TIntermediate* intermediate;
|
||||||
|
TInfoSink* infoSink;
|
||||||
|
// strings and lengths follow the standard for glShaderSource:
|
||||||
|
// strings is an array of numStrings pointers to string data.
|
||||||
|
// lengths can be null, but if not it is an array of numStrings
|
||||||
|
// integers containing the length of the associated strings.
|
||||||
|
// if lengths is null or lengths[n] < 0 the associated strings[n] is
|
||||||
|
// assumed to be null-terminated.
|
||||||
|
// stringNames is the optional names for all the strings. If stringNames
|
||||||
|
// is null, then none of the strings has name. If a certain element in
|
||||||
|
// stringNames is null, then the corresponding string does not have name.
|
||||||
|
const char* const* strings; // explicit code to compile, see previous comment
|
||||||
|
const int* lengths;
|
||||||
|
const char* const* stringNames;
|
||||||
|
int numStrings; // size of the above arrays
|
||||||
|
const char* preamble; // string of implicit code to compile before the explicitly provided code
|
||||||
|
|
||||||
|
// a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
|
||||||
|
std::string sourceEntryPointName;
|
||||||
|
|
||||||
|
TEnvironment environment;
|
||||||
|
|
||||||
|
friend class TProgram;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TShader& operator=(TShader&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
|
||||||
|
//
|
||||||
|
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
|
||||||
|
//
|
||||||
|
|
||||||
|
// Data needed for just a single object at the granularity exchanged by the reflection API
|
||||||
|
class TObjectReflection {
|
||||||
|
public:
|
||||||
|
TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
|
||||||
|
|
||||||
|
const TType* getType() const { return type; }
|
||||||
|
int getBinding() const;
|
||||||
|
void dump() const;
|
||||||
|
static TObjectReflection badReflection() { return TObjectReflection(); }
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
int offset;
|
||||||
|
int glDefineType;
|
||||||
|
int size; // data size in bytes for a block, array size for a (non-block) object that's an array
|
||||||
|
int index;
|
||||||
|
int counterIndex;
|
||||||
|
int numMembers;
|
||||||
|
int arrayStride; // stride of an array variable
|
||||||
|
int topLevelArraySize; // size of the top-level variable in a storage buffer member
|
||||||
|
int topLevelArrayStride; // stride of the top-level variable in a storage buffer member
|
||||||
|
EShLanguageMask stages;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TObjectReflection()
|
||||||
|
: offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), numMembers(-1), arrayStride(0),
|
||||||
|
topLevelArrayStride(0), stages(EShLanguageMask(0)), type(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const TType* type;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TReflection;
|
||||||
|
class TIoMapper;
|
||||||
|
struct TVarEntryInfo;
|
||||||
|
|
||||||
|
// Allows to customize the binding layout after linking.
|
||||||
|
// All used uniform variables will invoke at least validateBinding.
|
||||||
|
// If validateBinding returned true then the other resolveBinding,
|
||||||
|
// resolveSet, and resolveLocation are invoked to resolve the binding
|
||||||
|
// and descriptor set index respectively.
|
||||||
|
//
|
||||||
|
// Invocations happen in a particular order:
|
||||||
|
// 1) all shader inputs
|
||||||
|
// 2) all shader outputs
|
||||||
|
// 3) all uniforms with binding and set already defined
|
||||||
|
// 4) all uniforms with binding but no set defined
|
||||||
|
// 5) all uniforms with set but no binding defined
|
||||||
|
// 6) all uniforms with no binding and no set defined
|
||||||
|
//
|
||||||
|
// mapIO will use this resolver in two phases. The first
|
||||||
|
// phase is a notification phase, calling the corresponging
|
||||||
|
// notifiy callbacks, this phase ends with a call to endNotifications.
|
||||||
|
// Phase two starts directly after the call to endNotifications
|
||||||
|
// and calls all other callbacks to validate and to get the
|
||||||
|
// bindings, sets, locations, component and color indices.
|
||||||
|
//
|
||||||
|
// NOTE: that still limit checks are applied to bindings and sets
|
||||||
|
// and may result in an error.
|
||||||
|
class TIoMapResolver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~TIoMapResolver() {}
|
||||||
|
|
||||||
|
// Should return true if the resulting/current binding would be okay.
|
||||||
|
// Basic idea is to do aliasing binding checks with this.
|
||||||
|
virtual bool validateBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Should return a value >= 0 if the current binding should be overridden.
|
||||||
|
// Return -1 if the current binding (including no binding) should be kept.
|
||||||
|
virtual int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Should return a value >= 0 if the current set should be overridden.
|
||||||
|
// Return -1 if the current set (including no set) should be kept.
|
||||||
|
virtual int resolveSet(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Should return a value >= 0 if the current location should be overridden.
|
||||||
|
// Return -1 if the current location (including no location) should be kept.
|
||||||
|
virtual int resolveUniformLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Should return true if the resulting/current setup would be okay.
|
||||||
|
// Basic idea is to do aliasing checks and reject invalid semantic names.
|
||||||
|
virtual bool validateInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Should return a value >= 0 if the current location should be overridden.
|
||||||
|
// Return -1 if the current location (including no location) should be kept.
|
||||||
|
virtual int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Should return a value >= 0 if the current component index should be overridden.
|
||||||
|
// Return -1 if the current component index (including no index) should be kept.
|
||||||
|
virtual int resolveInOutComponent(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Should return a value >= 0 if the current color index should be overridden.
|
||||||
|
// Return -1 if the current color index (including no index) should be kept.
|
||||||
|
virtual int resolveInOutIndex(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Notification of a uniform variable
|
||||||
|
virtual void notifyBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Notification of a in or out variable
|
||||||
|
virtual void notifyInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||||
|
// Called by mapIO when it starts its notify pass for the given stage
|
||||||
|
virtual void beginNotifications(EShLanguage stage) = 0;
|
||||||
|
// Called by mapIO when it has finished the notify pass
|
||||||
|
virtual void endNotifications(EShLanguage stage) = 0;
|
||||||
|
// Called by mipIO when it starts its resolve pass for the given stage
|
||||||
|
virtual void beginResolve(EShLanguage stage) = 0;
|
||||||
|
// Called by mapIO when it has finished the resolve pass
|
||||||
|
virtual void endResolve(EShLanguage stage) = 0;
|
||||||
|
// Called by mapIO when it starts its symbol collect for teh given stage
|
||||||
|
virtual void beginCollect(EShLanguage stage) = 0;
|
||||||
|
// Called by mapIO when it has finished the symbol collect
|
||||||
|
virtual void endCollect(EShLanguage stage) = 0;
|
||||||
|
// Called by TSlotCollector to resolve storage locations or bindings
|
||||||
|
virtual void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
|
||||||
|
// Called by TSlotCollector to resolve resource locations or bindings
|
||||||
|
virtual void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
|
||||||
|
// Called by mapIO.addStage to set shader stage mask to mark a stage be added to this pipeline
|
||||||
|
virtual void addStage(EShLanguage stage) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GLSLANG_WEB
|
||||||
|
|
||||||
|
// Make one TProgram per set of shaders that will get linked together. Add all
|
||||||
|
// the shaders that are to be linked together. After calling shader.parse()
|
||||||
|
// for all shaders, call link().
|
||||||
|
//
|
||||||
|
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||||
|
//
|
||||||
|
class TProgram {
|
||||||
|
public:
|
||||||
|
TProgram();
|
||||||
|
virtual ~TProgram();
|
||||||
|
void addShader(TShader* shader) { stages[shader->stage].push_back(shader); }
|
||||||
|
std::list<TShader*>& getShaders(EShLanguage stage) { return stages[stage]; }
|
||||||
|
// Link Validation interface
|
||||||
|
bool link(EShMessages);
|
||||||
|
const char* getInfoLog();
|
||||||
|
const char* getInfoDebugLog();
|
||||||
|
|
||||||
|
TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; }
|
||||||
|
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
|
||||||
|
// Reflection Interface
|
||||||
|
|
||||||
|
// call first, to do liveness analysis, index mapping, etc.; returns false on failure
|
||||||
|
bool buildReflection(int opts = EShReflectionDefault);
|
||||||
|
unsigned getLocalSize(int dim) const; // return dim'th local size
|
||||||
|
int getReflectionIndex(const char *name) const;
|
||||||
|
int getReflectionPipeIOIndex(const char* name, const bool inOrOut) const;
|
||||||
|
int getNumUniformVariables() const;
|
||||||
|
const TObjectReflection& getUniform(int index) const;
|
||||||
|
int getNumUniformBlocks() const;
|
||||||
|
const TObjectReflection& getUniformBlock(int index) const;
|
||||||
|
int getNumPipeInputs() const;
|
||||||
|
const TObjectReflection& getPipeInput(int index) const;
|
||||||
|
int getNumPipeOutputs() const;
|
||||||
|
const TObjectReflection& getPipeOutput(int index) const;
|
||||||
|
int getNumBufferVariables() const;
|
||||||
|
const TObjectReflection& getBufferVariable(int index) const;
|
||||||
|
int getNumBufferBlocks() const;
|
||||||
|
const TObjectReflection& getBufferBlock(int index) const;
|
||||||
|
int getNumAtomicCounters() const;
|
||||||
|
const TObjectReflection& getAtomicCounter(int index) const;
|
||||||
|
|
||||||
|
// Legacy Reflection Interface - expressed in terms of above interface
|
||||||
|
|
||||||
|
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
|
||||||
|
int getNumLiveUniformVariables() const { return getNumUniformVariables(); }
|
||||||
|
|
||||||
|
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
|
||||||
|
int getNumLiveUniformBlocks() const { return getNumUniformBlocks(); }
|
||||||
|
|
||||||
|
// can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
|
||||||
|
int getNumLiveAttributes() const { return getNumPipeInputs(); }
|
||||||
|
|
||||||
|
// can be used for glGetUniformIndices()
|
||||||
|
int getUniformIndex(const char *name) const { return getReflectionIndex(name); }
|
||||||
|
|
||||||
|
int getPipeIOIndex(const char *name, const bool inOrOut) const
|
||||||
|
{ return getReflectionPipeIOIndex(name, inOrOut); }
|
||||||
|
|
||||||
|
// can be used for "name" part of glGetActiveUniform()
|
||||||
|
const char *getUniformName(int index) const { return getUniform(index).name.c_str(); }
|
||||||
|
|
||||||
|
// returns the binding number
|
||||||
|
int getUniformBinding(int index) const { return getUniform(index).getBinding(); }
|
||||||
|
|
||||||
|
// returns Shaders Stages where a Uniform is present
|
||||||
|
EShLanguageMask getUniformStages(int index) const { return getUniform(index).stages; }
|
||||||
|
|
||||||
|
// can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
|
||||||
|
int getUniformBlockIndex(int index) const { return getUniform(index).index; }
|
||||||
|
|
||||||
|
// can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
|
||||||
|
int getUniformType(int index) const { return getUniform(index).glDefineType; }
|
||||||
|
|
||||||
|
// can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
|
||||||
|
int getUniformBufferOffset(int index) const { return getUniform(index).offset; }
|
||||||
|
|
||||||
|
// can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
|
||||||
|
int getUniformArraySize(int index) const { return getUniform(index).size; }
|
||||||
|
|
||||||
|
// returns a TType*
|
||||||
|
const TType *getUniformTType(int index) const { return getUniform(index).getType(); }
|
||||||
|
|
||||||
|
// can be used for glGetActiveUniformBlockName()
|
||||||
|
const char *getUniformBlockName(int index) const { return getUniformBlock(index).name.c_str(); }
|
||||||
|
|
||||||
|
// can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
|
||||||
|
int getUniformBlockSize(int index) const { return getUniformBlock(index).size; }
|
||||||
|
|
||||||
|
// returns the block binding number
|
||||||
|
int getUniformBlockBinding(int index) const { return getUniformBlock(index).getBinding(); }
|
||||||
|
|
||||||
|
// returns block index of associated counter.
|
||||||
|
int getUniformBlockCounterIndex(int index) const { return getUniformBlock(index).counterIndex; }
|
||||||
|
|
||||||
|
// returns a TType*
|
||||||
|
const TType *getUniformBlockTType(int index) const { return getUniformBlock(index).getType(); }
|
||||||
|
|
||||||
|
// can be used for glGetActiveAttrib()
|
||||||
|
const char *getAttributeName(int index) const { return getPipeInput(index).name.c_str(); }
|
||||||
|
|
||||||
|
// can be used for glGetActiveAttrib()
|
||||||
|
int getAttributeType(int index) const { return getPipeInput(index).glDefineType; }
|
||||||
|
|
||||||
|
// returns a TType*
|
||||||
|
const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); }
|
||||||
|
|
||||||
|
void dumpReflection();
|
||||||
|
// I/O mapping: apply base offsets and map live unbound variables
|
||||||
|
// If resolver is not provided it uses the previous approach
|
||||||
|
// and respects auto assignment and offsets.
|
||||||
|
bool mapIO(TIoMapResolver* pResolver = nullptr, TIoMapper* pIoMapper = nullptr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool linkStage(EShLanguage, EShMessages);
|
||||||
|
|
||||||
|
TPoolAllocator* pool;
|
||||||
|
std::list<TShader*> stages[EShLangCount];
|
||||||
|
TIntermediate* intermediate[EShLangCount];
|
||||||
|
bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage
|
||||||
|
TInfoSink* infoSink;
|
||||||
|
#ifndef GLSLANG_WEB
|
||||||
|
TReflection* reflection;
|
||||||
|
#endif
|
||||||
|
bool linked;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TProgram(TProgram&);
|
||||||
|
TProgram& operator=(TProgram&);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace glslang
|
||||||
|
|
||||||
|
#endif // _COMPILER_INTERFACE_INCLUDED_
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2014-2016 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.
|
||||||
|
**
|
||||||
|
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||||
|
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||||
|
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLSLextAMD_H
|
||||||
|
#define GLSLextAMD_H
|
||||||
|
|
||||||
|
static const int GLSLextAMDVersion = 100;
|
||||||
|
static const int GLSLextAMDRevision = 7;
|
||||||
|
|
||||||
|
// SPV_AMD_shader_ballot
|
||||||
|
static const char* const E_SPV_AMD_shader_ballot = "SPV_AMD_shader_ballot";
|
||||||
|
|
||||||
|
enum ShaderBallotAMD {
|
||||||
|
ShaderBallotBadAMD = 0, // Don't use
|
||||||
|
|
||||||
|
SwizzleInvocationsAMD = 1,
|
||||||
|
SwizzleInvocationsMaskedAMD = 2,
|
||||||
|
WriteInvocationAMD = 3,
|
||||||
|
MbcntAMD = 4,
|
||||||
|
|
||||||
|
ShaderBallotCountAMD
|
||||||
|
};
|
||||||
|
|
||||||
|
// SPV_AMD_shader_trinary_minmax
|
||||||
|
static const char* const E_SPV_AMD_shader_trinary_minmax = "SPV_AMD_shader_trinary_minmax";
|
||||||
|
|
||||||
|
enum ShaderTrinaryMinMaxAMD {
|
||||||
|
ShaderTrinaryMinMaxBadAMD = 0, // Don't use
|
||||||
|
|
||||||
|
FMin3AMD = 1,
|
||||||
|
UMin3AMD = 2,
|
||||||
|
SMin3AMD = 3,
|
||||||
|
FMax3AMD = 4,
|
||||||
|
UMax3AMD = 5,
|
||||||
|
SMax3AMD = 6,
|
||||||
|
FMid3AMD = 7,
|
||||||
|
UMid3AMD = 8,
|
||||||
|
SMid3AMD = 9,
|
||||||
|
|
||||||
|
ShaderTrinaryMinMaxCountAMD
|
||||||
|
};
|
||||||
|
|
||||||
|
// SPV_AMD_shader_explicit_vertex_parameter
|
||||||
|
static const char* const E_SPV_AMD_shader_explicit_vertex_parameter = "SPV_AMD_shader_explicit_vertex_parameter";
|
||||||
|
|
||||||
|
enum ShaderExplicitVertexParameterAMD {
|
||||||
|
ShaderExplicitVertexParameterBadAMD = 0, // Don't use
|
||||||
|
|
||||||
|
InterpolateAtVertexAMD = 1,
|
||||||
|
|
||||||
|
ShaderExplicitVertexParameterCountAMD
|
||||||
|
};
|
||||||
|
|
||||||
|
// SPV_AMD_gcn_shader
|
||||||
|
static const char* const E_SPV_AMD_gcn_shader = "SPV_AMD_gcn_shader";
|
||||||
|
|
||||||
|
enum GcnShaderAMD {
|
||||||
|
GcnShaderBadAMD = 0, // Don't use
|
||||||
|
|
||||||
|
CubeFaceIndexAMD = 1,
|
||||||
|
CubeFaceCoordAMD = 2,
|
||||||
|
TimeAMD = 3,
|
||||||
|
|
||||||
|
GcnShaderCountAMD
|
||||||
|
};
|
||||||
|
|
||||||
|
// SPV_AMD_gpu_shader_half_float
|
||||||
|
static const char* const E_SPV_AMD_gpu_shader_half_float = "SPV_AMD_gpu_shader_half_float";
|
||||||
|
|
||||||
|
// SPV_AMD_texture_gather_bias_lod
|
||||||
|
static const char* const E_SPV_AMD_texture_gather_bias_lod = "SPV_AMD_texture_gather_bias_lod";
|
||||||
|
|
||||||
|
// SPV_AMD_gpu_shader_int16
|
||||||
|
static const char* const E_SPV_AMD_gpu_shader_int16 = "SPV_AMD_gpu_shader_int16";
|
||||||
|
|
||||||
|
// SPV_AMD_shader_image_load_store_lod
|
||||||
|
static const char* const E_SPV_AMD_shader_image_load_store_lod = "SPV_AMD_shader_image_load_store_lod";
|
||||||
|
|
||||||
|
// SPV_AMD_shader_fragment_mask
|
||||||
|
static const char* const E_SPV_AMD_shader_fragment_mask = "SPV_AMD_shader_fragment_mask";
|
||||||
|
|
||||||
|
// SPV_AMD_gpu_shader_half_float_fetch
|
||||||
|
static const char* const E_SPV_AMD_gpu_shader_half_float_fetch = "SPV_AMD_gpu_shader_half_float_fetch";
|
||||||
|
|
||||||
|
#endif // #ifndef GLSLextAMD_H
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2014-2016 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.
|
||||||
|
**
|
||||||
|
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||||
|
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||||
|
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLSLextEXT_H
|
||||||
|
#define GLSLextEXT_H
|
||||||
|
|
||||||
|
static const int GLSLextEXTVersion = 100;
|
||||||
|
static const int GLSLextEXTRevision = 2;
|
||||||
|
|
||||||
|
static const char* const E_SPV_EXT_shader_stencil_export = "SPV_EXT_shader_stencil_export";
|
||||||
|
static const char* const E_SPV_EXT_shader_viewport_index_layer = "SPV_EXT_shader_viewport_index_layer";
|
||||||
|
static const char* const E_SPV_EXT_fragment_fully_covered = "SPV_EXT_fragment_fully_covered";
|
||||||
|
static const char* const E_SPV_EXT_fragment_invocation_density = "SPV_EXT_fragment_invocation_density";
|
||||||
|
static const char* const E_SPV_EXT_demote_to_helper_invocation = "SPV_EXT_demote_to_helper_invocation";
|
||||||
|
|
||||||
|
#endif // #ifndef GLSLextEXT_H
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2014-2020 The Khronos Group Inc.
|
||||||
|
** Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||||
|
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||||
|
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLSLextKHR_H
|
||||||
|
#define GLSLextKHR_H
|
||||||
|
|
||||||
|
static const int GLSLextKHRVersion = 100;
|
||||||
|
static const int GLSLextKHRRevision = 2;
|
||||||
|
|
||||||
|
static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot";
|
||||||
|
static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote";
|
||||||
|
static const char* const E_SPV_KHR_device_group = "SPV_KHR_device_group";
|
||||||
|
static const char* const E_SPV_KHR_multiview = "SPV_KHR_multiview";
|
||||||
|
static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters";
|
||||||
|
static const char* const E_SPV_KHR_16bit_storage = "SPV_KHR_16bit_storage";
|
||||||
|
static const char* const E_SPV_KHR_8bit_storage = "SPV_KHR_8bit_storage";
|
||||||
|
static const char* const E_SPV_KHR_storage_buffer_storage_class = "SPV_KHR_storage_buffer_storage_class";
|
||||||
|
static const char* const E_SPV_KHR_post_depth_coverage = "SPV_KHR_post_depth_coverage";
|
||||||
|
static const char* const E_SPV_KHR_vulkan_memory_model = "SPV_KHR_vulkan_memory_model";
|
||||||
|
static const char* const E_SPV_EXT_physical_storage_buffer = "SPV_EXT_physical_storage_buffer";
|
||||||
|
static const char* const E_SPV_KHR_physical_storage_buffer = "SPV_KHR_physical_storage_buffer";
|
||||||
|
static const char* const E_SPV_EXT_fragment_shader_interlock = "SPV_EXT_fragment_shader_interlock";
|
||||||
|
static const char* const E_SPV_KHR_shader_clock = "SPV_KHR_shader_clock";
|
||||||
|
static const char* const E_SPV_KHR_non_semantic_info = "SPV_KHR_non_semantic_info";
|
||||||
|
static const char* const E_SPV_KHR_ray_tracing = "SPV_KHR_ray_tracing";
|
||||||
|
static const char* const E_SPV_KHR_ray_query = "SPV_KHR_ray_query";
|
||||||
|
#endif // #ifndef GLSLextKHR_H
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2014-2017 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.
|
||||||
|
**
|
||||||
|
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||||
|
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||||
|
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLSLextNV_H
|
||||||
|
#define GLSLextNV_H
|
||||||
|
|
||||||
|
enum BuiltIn;
|
||||||
|
enum Decoration;
|
||||||
|
enum Op;
|
||||||
|
enum Capability;
|
||||||
|
|
||||||
|
static const int GLSLextNVVersion = 100;
|
||||||
|
static const int GLSLextNVRevision = 11;
|
||||||
|
|
||||||
|
//SPV_NV_sample_mask_override_coverage
|
||||||
|
const char* const E_SPV_NV_sample_mask_override_coverage = "SPV_NV_sample_mask_override_coverage";
|
||||||
|
|
||||||
|
//SPV_NV_geometry_shader_passthrough
|
||||||
|
const char* const E_SPV_NV_geometry_shader_passthrough = "SPV_NV_geometry_shader_passthrough";
|
||||||
|
|
||||||
|
//SPV_NV_viewport_array2
|
||||||
|
const char* const E_SPV_NV_viewport_array2 = "SPV_NV_viewport_array2";
|
||||||
|
const char* const E_ARB_shader_viewport_layer_array = "SPV_ARB_shader_viewport_layer_array";
|
||||||
|
|
||||||
|
//SPV_NV_stereo_view_rendering
|
||||||
|
const char* const E_SPV_NV_stereo_view_rendering = "SPV_NV_stereo_view_rendering";
|
||||||
|
|
||||||
|
//SPV_NVX_multiview_per_view_attributes
|
||||||
|
const char* const E_SPV_NVX_multiview_per_view_attributes = "SPV_NVX_multiview_per_view_attributes";
|
||||||
|
|
||||||
|
//SPV_NV_shader_subgroup_partitioned
|
||||||
|
const char* const E_SPV_NV_shader_subgroup_partitioned = "SPV_NV_shader_subgroup_partitioned";
|
||||||
|
|
||||||
|
//SPV_NV_fragment_shader_barycentric
|
||||||
|
const char* const E_SPV_NV_fragment_shader_barycentric = "SPV_NV_fragment_shader_barycentric";
|
||||||
|
|
||||||
|
//SPV_NV_compute_shader_derivatives
|
||||||
|
const char* const E_SPV_NV_compute_shader_derivatives = "SPV_NV_compute_shader_derivatives";
|
||||||
|
|
||||||
|
//SPV_NV_shader_image_footprint
|
||||||
|
const char* const E_SPV_NV_shader_image_footprint = "SPV_NV_shader_image_footprint";
|
||||||
|
|
||||||
|
//SPV_NV_mesh_shader
|
||||||
|
const char* const E_SPV_NV_mesh_shader = "SPV_NV_mesh_shader";
|
||||||
|
|
||||||
|
//SPV_NV_raytracing
|
||||||
|
const char* const E_SPV_NV_ray_tracing = "SPV_NV_ray_tracing";
|
||||||
|
|
||||||
|
//SPV_NV_shading_rate
|
||||||
|
const char* const E_SPV_NV_shading_rate = "SPV_NV_shading_rate";
|
||||||
|
|
||||||
|
//SPV_NV_cooperative_matrix
|
||||||
|
const char* const E_SPV_NV_cooperative_matrix = "SPV_NV_cooperative_matrix";
|
||||||
|
|
||||||
|
//SPV_NV_shader_sm_builtins
|
||||||
|
const char* const E_SPV_NV_shader_sm_builtins = "SPV_NV_shader_sm_builtins";
|
||||||
|
|
||||||
|
#endif // #ifndef GLSLextNV_H
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2014-2016 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.
|
||||||
|
**
|
||||||
|
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||||
|
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||||
|
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLSLstd450_H
|
||||||
|
#define GLSLstd450_H
|
||||||
|
|
||||||
|
static const int GLSLstd450Version = 100;
|
||||||
|
static const int GLSLstd450Revision = 1;
|
||||||
|
|
||||||
|
enum GLSLstd450 {
|
||||||
|
GLSLstd450Bad = 0, // Don't use
|
||||||
|
|
||||||
|
GLSLstd450Round = 1,
|
||||||
|
GLSLstd450RoundEven = 2,
|
||||||
|
GLSLstd450Trunc = 3,
|
||||||
|
GLSLstd450FAbs = 4,
|
||||||
|
GLSLstd450SAbs = 5,
|
||||||
|
GLSLstd450FSign = 6,
|
||||||
|
GLSLstd450SSign = 7,
|
||||||
|
GLSLstd450Floor = 8,
|
||||||
|
GLSLstd450Ceil = 9,
|
||||||
|
GLSLstd450Fract = 10,
|
||||||
|
|
||||||
|
GLSLstd450Radians = 11,
|
||||||
|
GLSLstd450Degrees = 12,
|
||||||
|
GLSLstd450Sin = 13,
|
||||||
|
GLSLstd450Cos = 14,
|
||||||
|
GLSLstd450Tan = 15,
|
||||||
|
GLSLstd450Asin = 16,
|
||||||
|
GLSLstd450Acos = 17,
|
||||||
|
GLSLstd450Atan = 18,
|
||||||
|
GLSLstd450Sinh = 19,
|
||||||
|
GLSLstd450Cosh = 20,
|
||||||
|
GLSLstd450Tanh = 21,
|
||||||
|
GLSLstd450Asinh = 22,
|
||||||
|
GLSLstd450Acosh = 23,
|
||||||
|
GLSLstd450Atanh = 24,
|
||||||
|
GLSLstd450Atan2 = 25,
|
||||||
|
|
||||||
|
GLSLstd450Pow = 26,
|
||||||
|
GLSLstd450Exp = 27,
|
||||||
|
GLSLstd450Log = 28,
|
||||||
|
GLSLstd450Exp2 = 29,
|
||||||
|
GLSLstd450Log2 = 30,
|
||||||
|
GLSLstd450Sqrt = 31,
|
||||||
|
GLSLstd450InverseSqrt = 32,
|
||||||
|
|
||||||
|
GLSLstd450Determinant = 33,
|
||||||
|
GLSLstd450MatrixInverse = 34,
|
||||||
|
|
||||||
|
GLSLstd450Modf = 35, // second operand needs an OpVariable to write to
|
||||||
|
GLSLstd450ModfStruct = 36, // no OpVariable operand
|
||||||
|
GLSLstd450FMin = 37,
|
||||||
|
GLSLstd450UMin = 38,
|
||||||
|
GLSLstd450SMin = 39,
|
||||||
|
GLSLstd450FMax = 40,
|
||||||
|
GLSLstd450UMax = 41,
|
||||||
|
GLSLstd450SMax = 42,
|
||||||
|
GLSLstd450FClamp = 43,
|
||||||
|
GLSLstd450UClamp = 44,
|
||||||
|
GLSLstd450SClamp = 45,
|
||||||
|
GLSLstd450FMix = 46,
|
||||||
|
GLSLstd450IMix = 47, // Reserved
|
||||||
|
GLSLstd450Step = 48,
|
||||||
|
GLSLstd450SmoothStep = 49,
|
||||||
|
|
||||||
|
GLSLstd450Fma = 50,
|
||||||
|
GLSLstd450Frexp = 51, // second operand needs an OpVariable to write to
|
||||||
|
GLSLstd450FrexpStruct = 52, // no OpVariable operand
|
||||||
|
GLSLstd450Ldexp = 53,
|
||||||
|
|
||||||
|
GLSLstd450PackSnorm4x8 = 54,
|
||||||
|
GLSLstd450PackUnorm4x8 = 55,
|
||||||
|
GLSLstd450PackSnorm2x16 = 56,
|
||||||
|
GLSLstd450PackUnorm2x16 = 57,
|
||||||
|
GLSLstd450PackHalf2x16 = 58,
|
||||||
|
GLSLstd450PackDouble2x32 = 59,
|
||||||
|
GLSLstd450UnpackSnorm2x16 = 60,
|
||||||
|
GLSLstd450UnpackUnorm2x16 = 61,
|
||||||
|
GLSLstd450UnpackHalf2x16 = 62,
|
||||||
|
GLSLstd450UnpackSnorm4x8 = 63,
|
||||||
|
GLSLstd450UnpackUnorm4x8 = 64,
|
||||||
|
GLSLstd450UnpackDouble2x32 = 65,
|
||||||
|
|
||||||
|
GLSLstd450Length = 66,
|
||||||
|
GLSLstd450Distance = 67,
|
||||||
|
GLSLstd450Cross = 68,
|
||||||
|
GLSLstd450Normalize = 69,
|
||||||
|
GLSLstd450FaceForward = 70,
|
||||||
|
GLSLstd450Reflect = 71,
|
||||||
|
GLSLstd450Refract = 72,
|
||||||
|
|
||||||
|
GLSLstd450FindILsb = 73,
|
||||||
|
GLSLstd450FindSMsb = 74,
|
||||||
|
GLSLstd450FindUMsb = 75,
|
||||||
|
|
||||||
|
GLSLstd450InterpolateAtCentroid = 76,
|
||||||
|
GLSLstd450InterpolateAtSample = 77,
|
||||||
|
GLSLstd450InterpolateAtOffset = 78,
|
||||||
|
|
||||||
|
GLSLstd450NMin = 79,
|
||||||
|
GLSLstd450NMax = 80,
|
||||||
|
GLSLstd450NClamp = 81,
|
||||||
|
|
||||||
|
GLSLstd450Count
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #ifndef GLSLstd450_H
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 LunarG, Inc.
|
||||||
|
// Copyright (C) 2015-2018 Google, Inc.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER >= 1900
|
||||||
|
#pragma warning(disable : 4464) // relative include path contains '..'
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "SpvTools.h"
|
||||||
|
#include "glslang/Include/intermediate.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
|
namespace glslang {
|
||||||
|
|
||||||
|
void GetSpirvVersion(std::string&);
|
||||||
|
int GetSpirvGeneratorVersion();
|
||||||
|
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||||
|
SpvOptions* options = nullptr);
|
||||||
|
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||||
|
spv::SpvBuildLogger* logger, SpvOptions* options = nullptr);
|
||||||
|
void OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName);
|
||||||
|
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName, const char* varName);
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue