This commit is contained in:
Mikulas Florek 2018-06-30 15:18:27 +02:00
parent 15b406d1c3
commit 4f605c266e
80 changed files with 9697 additions and 13262 deletions

26
external/bgfx/LICENSE vendored
View file

@ -1,26 +0,0 @@
Copyright 2010-2015 Branimir Karadzic. All rights reserved.
https://github.com/bkaradzic/bgfx
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 COPYRIGHT HOLDER ``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 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.
https://github.com/bkaradzic/bgfx/blob/master/LICENSE

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,210 +0,0 @@
/*
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*
* vim: set tabstop=4 expandtab:
*/
#ifndef BGFX_PLATFORM_C99_H_HEADER_GUARD
#define BGFX_PLATFORM_C99_H_HEADER_GUARD
// NOTICE:
// This header file contains platform specific interfaces. It is only
// necessary to use this header in conjunction with creating windows.
#include <bx/platform.h>
#include "bgfx.h"
typedef enum bgfx_render_frame
{
BGFX_RENDER_FRAME_NO_CONTEXT,
BGFX_RENDER_FRAME_RENDER,
BGFX_RENDER_FRAME_TIMEOUT,
BGFX_RENDER_FRAME_EXITING,
BGFX_RENDER_FRAME_COUNT
} bgfx_render_frame_t;
/**
* WARNING: This call should be only used on platforms that don't
* allow creating separate rendering thread. If it is called before
* to bgfx_init, render thread won't be created by bgfx_init call.
*/
BGFX_C_API bgfx_render_frame_t bgfx_render_frame(int32_t _msecs);
typedef struct bgfx_platform_data
{
void* ndt;
void* nwh;
void* context;
void* backBuffer;
void* backBufferDS;
void* session;
} bgfx_platform_data_t;
/**/
BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t* _data);
typedef struct bgfx_internal_datauint8_t
{
const struct bgfx_caps* caps;
void* context;
} bgfx_internal_data_t;
/**/
BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data();
/**/
BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr);
/**/
BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags);
/**/
typedef struct bgfx_interface_vtbl
{
bgfx_render_frame_t (*render_frame)(int32_t _msecs);
void (*set_platform_data)(const bgfx_platform_data_t* _data);
const bgfx_internal_data_t* (*get_internal_data)();
uintptr_t (*override_internal_texture_ptr)(bgfx_texture_handle_t _handle, uintptr_t _ptr);
uintptr_t (*override_internal_texture)(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags);
void (*vertex_decl_begin)(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer);
void (*vertex_decl_add)(bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt);
void (*vertex_decl_skip)(bgfx_vertex_decl_t* _decl, uint8_t _num);
void (*vertex_decl_end)(bgfx_vertex_decl_t* _decl);
void (*vertex_pack)(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, void* _data, uint32_t _index);
void (*vertex_unpack)(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, const void* _data, uint32_t _index);
void (*vertex_convert)(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num);
uint16_t (*weld_vertices)(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon);
uint32_t (*topology_convert)(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32);
void (*topology_sort_tri_list)(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32);
uint8_t (*get_supported_renderers)(uint8_t _max, bgfx_renderer_type_t* _enum);
const char* (*get_renderer_name)(bgfx_renderer_type_t _type);
void (*init_ctor)(bgfx_init_t* _init);
bool (*init)(const bgfx_init_t* _init);
void (*shutdown)();
void (*reset)(uint32_t _width, uint32_t _height, uint32_t _flags);
uint32_t (*frame)(bool _capture);
bgfx_renderer_type_t (*get_renderer_type)();
const bgfx_caps_t* (*get_caps)();
const bgfx_hmd_t* (*get_hmd)();
const bgfx_stats_t* (*get_stats)();
const bgfx_memory_t* (*alloc)(uint32_t _size);
const bgfx_memory_t* (*copy)(const void* _data, uint32_t _size);
const bgfx_memory_t* (*make_ref)(const void* _data, uint32_t _size);
const bgfx_memory_t* (*make_ref_release)(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData);
void (*set_debug)(uint32_t _debug);
void (*dbg_text_clear)(uint8_t _attr, bool _small);
void (*dbg_text_printf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
void (*dbg_text_vprintf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList);
void (*dbg_text_image)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch);
bgfx_index_buffer_handle_t (*create_index_buffer)(const bgfx_memory_t* _mem, uint16_t _flags);
void (*destroy_index_buffer)(bgfx_index_buffer_handle_t _handle);
bgfx_vertex_buffer_handle_t (*create_vertex_buffer)(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
void (*destroy_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle);
bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer)(uint32_t _num, uint16_t _flags);
bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer_mem)(const bgfx_memory_t* _mem, uint16_t _flags);
void (*update_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem);
void (*destroy_dynamic_index_buffer)(bgfx_dynamic_index_buffer_handle_t _handle);
bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer)(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
bgfx_dynamic_vertex_buffer_handle_t (*create_dynamic_vertex_buffer_mem)(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
void (*update_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem);
void (*destroy_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle);
uint32_t (*get_avail_transient_index_buffer)(uint32_t _num);
uint32_t (*get_avail_transient_vertex_buffer)(uint32_t _num, const bgfx_vertex_decl_t* _decl);
uint32_t (*get_avail_instance_data_buffer)(uint32_t _num, uint16_t _stride);
void (*alloc_transient_index_buffer)(bgfx_transient_index_buffer_t* _tib, uint32_t _num);
void (*alloc_transient_vertex_buffer)(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl);
bool (*alloc_transient_buffers)(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_decl_t* _decl, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices);
void (*alloc_instance_data_buffer)(bgfx_instance_data_buffer_t* _idb, uint32_t _num, uint16_t _stride);
bgfx_indirect_buffer_handle_t (*create_indirect_buffer)(uint32_t _num);
void (*destroy_indirect_buffer)(bgfx_indirect_buffer_handle_t _handle);
bgfx_shader_handle_t (*create_shader)(const bgfx_memory_t* _mem);
uint16_t (*get_shader_uniforms)(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max);
void (*set_shader_name)(bgfx_shader_handle_t _handle, const char* _name);
void (*destroy_shader)(bgfx_shader_handle_t _handle);
bgfx_program_handle_t (*create_program)(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders);
bgfx_program_handle_t (*create_compute_program)(bgfx_shader_handle_t _csh, bool _destroyShaders);
void (*destroy_program)(bgfx_program_handle_t _handle);
bool (*is_texture_valid)(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags);
void (*calc_texture_size)(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format);
bgfx_texture_handle_t (*create_texture)(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info);
bgfx_texture_handle_t (*create_texture_2d)(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
bgfx_texture_handle_t (*create_texture_2d_scaled)(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags);
bgfx_texture_handle_t (*create_texture_3d)(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
bgfx_texture_handle_t (*create_texture_cube)(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);
void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
uint32_t (*read_texture)(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip);
void (*set_texture_name)(bgfx_texture_handle_t _handle, const char* _name);
void* (*get_direct_access_ptr)(bgfx_texture_handle_t _handle);
void (*destroy_texture)(bgfx_texture_handle_t _handle);
bgfx_frame_buffer_handle_t (*create_frame_buffer)(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags);
bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags);
bgfx_frame_buffer_handle_t (*create_frame_buffer_from_attachment)(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTextures);
bgfx_frame_buffer_handle_t (*create_frame_buffer_from_nwh)(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat);
bgfx_texture_handle_t (*get_texture)(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment);
void (*destroy_frame_buffer)(bgfx_frame_buffer_handle_t _handle);
bgfx_uniform_handle_t (*create_uniform)(const char* _name, bgfx_uniform_type_t _type, uint16_t _num);
void (*get_uniform_info)(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t* _info);
void (*destroy_uniform)(bgfx_uniform_handle_t _handle);
bgfx_occlusion_query_handle_t (*create_occlusion_query)();
bgfx_occlusion_query_result_t (*get_result)(bgfx_occlusion_query_handle_t _handle, int32_t* _result);
void (*destroy_occlusion_query)(bgfx_occlusion_query_handle_t _handle);
void (*set_palette_color)(uint8_t _index, const float _rgba[4]);
void (*set_view_name)(bgfx_view_id_t _id, const char* _name);
void (*set_view_rect)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_scissor)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_clear)(bgfx_view_id_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil);
void (*set_view_clear_mrt)(bgfx_view_id_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7);
void (*set_view_mode)(bgfx_view_id_t _id, bgfx_view_mode_t _mode);
void (*set_view_frame_buffer)(bgfx_view_id_t _id, bgfx_frame_buffer_handle_t _handle);
void (*set_view_transform)(bgfx_view_id_t _id, const void* _view, const void* _proj);
void (*set_view_transform_stereo)(bgfx_view_id_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR);
void (*set_view_order)(bgfx_view_id_t _id, uint16_t _num, const bgfx_view_id_t* _order);
void (*encoder_set_marker)(struct bgfx_encoder_s* _encoder, const char* _marker);
void (*encoder_set_state)(struct bgfx_encoder_s* _encoder, uint64_t _state, uint32_t _rgba);
void (*encoder_set_condition)(struct bgfx_encoder_s* _encoder, bgfx_occlusion_query_handle_t _handle, bool _visible);
void (*encoder_set_stencil)(struct bgfx_encoder_s* _encoder, uint32_t _fstencil, uint32_t _bstencil);
uint16_t (*encoder_set_scissor)(struct bgfx_encoder_s* _encoder, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*encoder_set_scissor_cached)(struct bgfx_encoder_s* _encoder, uint16_t _cache);
uint32_t (*encoder_set_transform)(struct bgfx_encoder_s* _encoder, const void* _mtx, uint16_t _num);
uint32_t (*encoder_alloc_transform)(struct bgfx_encoder_s* _encoder, bgfx_transform_t* _transform, uint16_t _num);
void (*encoder_set_transform_cached)(struct bgfx_encoder_s* _encoder, uint32_t _cache, uint16_t _num);
void (*encoder_set_uniform)(struct bgfx_encoder_s* _encoder, bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num);
void (*encoder_set_index_buffer)(struct bgfx_encoder_s* _encoder, bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
void (*encoder_set_dynamic_index_buffer)(struct bgfx_encoder_s* _encoder, bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices);
void (*encoder_set_transient_index_buffer)(struct bgfx_encoder_s* _encoder, const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices);
void (*encoder_set_vertex_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices);
void (*encoder_set_dynamic_vertex_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices);
void (*encoder_set_transient_vertex_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices);
void (*encoder_set_vertex_count)(struct bgfx_encoder_s* _encoder, uint32_t _numVertices);
void (*encoder_set_instance_data_buffer)(struct bgfx_encoder_s* _encoder, const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num);
void (*encoder_set_instance_data_from_vertex_buffer)(struct bgfx_encoder_s* _encoder, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*encoder_set_instance_data_from_dynamic_vertex_buffer)(struct bgfx_encoder_s* _encoder, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*encoder_set_texture)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
void (*encoder_touch)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id);
void (*encoder_submit)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, int32_t _depth, bool _preserveState);
void (*encoder_submit_occlusion_query)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth, bool _preserveState);
void (*encoder_submit_indirect)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState);
void (*encoder_set_image)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format);
void (*encoder_set_compute_index_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access);
void (*encoder_set_compute_vertex_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access);
void (*encoder_set_compute_dynamic_index_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access);
void (*encoder_set_compute_dynamic_vertex_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access);
void (*encoder_set_compute_indirect_buffer)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access);
void (*encoder_dispatch)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags);
void (*encoder_dispatch_indirect)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags);
void (*encoder_discard)(struct bgfx_encoder_s* _encoder);
void (*encoder_blit)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth);
void (*request_screen_shot)(bgfx_frame_buffer_handle_t _handle, const char* _filePath);
} bgfx_interface_vtbl_t;
typedef bgfx_interface_vtbl_t* (*PFN_BGFX_GET_INTERFACE)(uint32_t _version);
#endif // BGFX_PLATFORM_C99_H_HEADER_GUARD

View file

@ -1,512 +0,0 @@
/*
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(70)
/// Color RGB/alpha/depth write. When it's not specified write will be disabled.
#define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write.
#define BGFX_STATE_WRITE_G UINT64_C(0x0000000000000002) //!< Enable G write.
#define BGFX_STATE_WRITE_B UINT64_C(0x0000000000000004) //!< Enable B write.
#define BGFX_STATE_WRITE_A UINT64_C(0x0000000000000008) //!< Enable alpha write.
#define BGFX_STATE_WRITE_Z UINT64_C(0x0000004000000000) //!< Enable depth write.
/// Enable RGB write.
#define BGFX_STATE_WRITE_RGB (0 \
| BGFX_STATE_WRITE_R \
| BGFX_STATE_WRITE_G \
| BGFX_STATE_WRITE_B \
)
/// Write all channels mask.
#define BGFX_STATE_WRITE_MASK (0 \
| BGFX_STATE_WRITE_RGB \
| BGFX_STATE_WRITE_A \
| BGFX_STATE_WRITE_Z \
)
/// Depth test state. When `BGFX_STATE_DEPTH_` is not specified depth test will be disabled.
#define BGFX_STATE_DEPTH_TEST_LESS UINT64_C(0x0000000000000010) //!< Enable depth test, less.
#define BGFX_STATE_DEPTH_TEST_LEQUAL UINT64_C(0x0000000000000020) //!< Enable depth test, less or equal.
#define BGFX_STATE_DEPTH_TEST_EQUAL UINT64_C(0x0000000000000030) //!< Enable depth test, equal.
#define BGFX_STATE_DEPTH_TEST_GEQUAL UINT64_C(0x0000000000000040) //!< Enable depth test, greater or equal.
#define BGFX_STATE_DEPTH_TEST_GREATER UINT64_C(0x0000000000000050) //!< Enable depth test, greater.
#define BGFX_STATE_DEPTH_TEST_NOTEQUAL UINT64_C(0x0000000000000060) //!< Enable depth test, not equal.
#define BGFX_STATE_DEPTH_TEST_NEVER UINT64_C(0x0000000000000070) //!< Enable depth test, never.
#define BGFX_STATE_DEPTH_TEST_ALWAYS UINT64_C(0x0000000000000080) //!< Enable depth test, always.
#define BGFX_STATE_DEPTH_TEST_SHIFT 4 //!< Depth test state bit shift.
#define BGFX_STATE_DEPTH_TEST_MASK UINT64_C(0x00000000000000f0) //!< Depth test state bit mask.
/// Use BGFX_STATE_BLEND_FUNC(_src, _dst) or BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA)
/// helper macros.
#define BGFX_STATE_BLEND_ZERO UINT64_C(0x0000000000001000) //!< 0, 0, 0, 0
#define BGFX_STATE_BLEND_ONE UINT64_C(0x0000000000002000) //!< 1, 1, 1, 1
#define BGFX_STATE_BLEND_SRC_COLOR UINT64_C(0x0000000000003000) //!< Rs, Gs, Bs, As
#define BGFX_STATE_BLEND_INV_SRC_COLOR UINT64_C(0x0000000000004000) //!< 1-Rs, 1-Gs, 1-Bs, 1-As
#define BGFX_STATE_BLEND_SRC_ALPHA UINT64_C(0x0000000000005000) //!< As, As, As, As
#define BGFX_STATE_BLEND_INV_SRC_ALPHA UINT64_C(0x0000000000006000) //!< 1-As, 1-As, 1-As, 1-As
#define BGFX_STATE_BLEND_DST_ALPHA UINT64_C(0x0000000000007000) //!< Ad, Ad, Ad, Ad
#define BGFX_STATE_BLEND_INV_DST_ALPHA UINT64_C(0x0000000000008000) //!< 1-Ad, 1-Ad, 1-Ad ,1-Ad
#define BGFX_STATE_BLEND_DST_COLOR UINT64_C(0x0000000000009000) //!< Rd, Gd, Bd, Ad
#define BGFX_STATE_BLEND_INV_DST_COLOR UINT64_C(0x000000000000a000) //!< 1-Rd, 1-Gd, 1-Bd, 1-Ad
#define BGFX_STATE_BLEND_SRC_ALPHA_SAT UINT64_C(0x000000000000b000) //!< f, f, f, 1; f = min(As, 1-Ad)
#define BGFX_STATE_BLEND_FACTOR UINT64_C(0x000000000000c000) //!< Blend factor
#define BGFX_STATE_BLEND_INV_FACTOR UINT64_C(0x000000000000d000) //!< 1-Blend factor
#define BGFX_STATE_BLEND_SHIFT 12 //!< Blend state bit shift.
#define BGFX_STATE_BLEND_MASK UINT64_C(0x000000000ffff000) //!< Blend state bit mask.
/// Use BGFX_STATE_BLEND_EQUATION(_equation) or BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA)
/// helper macros.
#define BGFX_STATE_BLEND_EQUATION_ADD UINT64_C(0x0000000000000000) //!< Blend add: src + dst.
#define BGFX_STATE_BLEND_EQUATION_SUB UINT64_C(0x0000000010000000) //!< Blend subtract: src - dst.
#define BGFX_STATE_BLEND_EQUATION_REVSUB UINT64_C(0x0000000020000000) //!< Blend reverse subtract: dst - src.
#define BGFX_STATE_BLEND_EQUATION_MIN UINT64_C(0x0000000030000000) //!< Blend min: min(src, dst).
#define BGFX_STATE_BLEND_EQUATION_MAX UINT64_C(0x0000000040000000) //!< Blend max: max(src, dst).
#define BGFX_STATE_BLEND_EQUATION_SHIFT 28 //!< Blend equation bit shift.
#define BGFX_STATE_BLEND_EQUATION_MASK UINT64_C(0x00000003f0000000) //!< Blend equation bit mask.
#define BGFX_STATE_BLEND_INDEPENDENT UINT64_C(0x0000000400000000) //!< Enable blend independent.
#define BGFX_STATE_BLEND_ALPHA_TO_COVERAGE UINT64_C(0x0000000800000000) //!< Enable alpha to coverage.
/// Cull state. When `BGFX_STATE_CULL_*` is not specified culling will be disabled.
#define BGFX_STATE_CULL_CW UINT64_C(0x0000001000000000) //!< Cull clockwise triangles.
#define BGFX_STATE_CULL_CCW UINT64_C(0x0000002000000000) //!< Cull counter-clockwise triangles.
#define BGFX_STATE_CULL_SHIFT 36 //!< Culling mode bit shift.
#define BGFX_STATE_CULL_MASK UINT64_C(0x0000003000000000) //!< Culling mode bit mask.
/// See BGFX_STATE_ALPHA_REF(_ref) helper macro.
#define BGFX_STATE_ALPHA_REF_SHIFT 40 //!< Alpha reference bit shift.
#define BGFX_STATE_ALPHA_REF_MASK UINT64_C(0x0000ff0000000000) //!< Alpha reference bit mask.
#define BGFX_STATE_PT_TRISTRIP UINT64_C(0x0001000000000000) //!< Tristrip.
#define BGFX_STATE_PT_LINES UINT64_C(0x0002000000000000) //!< Lines.
#define BGFX_STATE_PT_LINESTRIP UINT64_C(0x0003000000000000) //!< Line strip.
#define BGFX_STATE_PT_POINTS UINT64_C(0x0004000000000000) //!< Points.
#define BGFX_STATE_PT_SHIFT 48 //!< Primitive type bit shift.
#define BGFX_STATE_PT_MASK UINT64_C(0x0007000000000000) //!< Primitive type bit mask.
/// See BGFX_STATE_POINT_SIZE(_size) helper macro.
#define BGFX_STATE_POINT_SIZE_SHIFT 52 //!< Point size bit shift.
#define BGFX_STATE_POINT_SIZE_MASK UINT64_C(0x00f0000000000000) //!< Point size bit mask.
/// Enable MSAA write when writing into MSAA frame buffer.
/// This flag is ignored when not writing into MSAA frame buffer.
#define BGFX_STATE_MSAA UINT64_C(0x0100000000000000) //!< Enable MSAA rasterization.
#define BGFX_STATE_LINEAA UINT64_C(0x0200000000000000) //!< Enable line AA rasterization.
#define BGFX_STATE_CONSERVATIVE_RASTER UINT64_C(0x0400000000000000) //!< Enable conservative rasterization.
/// Do not use!
#define BGFX_STATE_RESERVED_SHIFT 61 //!< Internal bits shift.
#define BGFX_STATE_RESERVED_MASK UINT64_C(0xe000000000000000) //!< Internal bits mask.
#define BGFX_STATE_NONE UINT64_C(0x0000000000000000) //!< No state.
#define BGFX_STATE_MASK UINT64_C(0xffffffffffffffff) //!< State mask.
/// Default state is write to RGB, alpha, and depth with depth test less enabled, with clockwise
/// culling and MSAA (when writing into MSAA frame buffer, otherwise this flag is ignored).
#define BGFX_STATE_DEFAULT (0 \
| BGFX_STATE_WRITE_RGB \
| BGFX_STATE_WRITE_A \
| BGFX_STATE_WRITE_Z \
| BGFX_STATE_DEPTH_TEST_LESS \
| BGFX_STATE_CULL_CW \
| BGFX_STATE_MSAA \
)
/// Alpha reference value.
#define BGFX_STATE_ALPHA_REF(_ref) ( ( (uint64_t)(_ref )<<BGFX_STATE_ALPHA_REF_SHIFT )&BGFX_STATE_ALPHA_REF_MASK)
/// Point size value.
#define BGFX_STATE_POINT_SIZE(_size) ( ( (uint64_t)(_size)<<BGFX_STATE_POINT_SIZE_SHIFT)&BGFX_STATE_POINT_SIZE_MASK)
/// Blend function separate.
#define BGFX_STATE_BLEND_FUNC_SEPARATE(_srcRGB, _dstRGB, _srcA, _dstA) (UINT64_C(0) \
| ( ( (uint64_t)(_srcRGB)|( (uint64_t)(_dstRGB)<<4) ) ) \
| ( ( (uint64_t)(_srcA )|( (uint64_t)(_dstA )<<4) )<<8) \
)
/// Blend equation separate.
#define BGFX_STATE_BLEND_EQUATION_SEPARATE(_equationRGB, _equationA) ( (uint64_t)(_equationRGB)|( (uint64_t)(_equationA)<<3) )
/// Blend function.
#define BGFX_STATE_BLEND_FUNC(_src, _dst) BGFX_STATE_BLEND_FUNC_SEPARATE(_src, _dst, _src, _dst)
/// Blend equation.
#define BGFX_STATE_BLEND_EQUATION(_equation) BGFX_STATE_BLEND_EQUATION_SEPARATE(_equation, _equation)
/// Utility predefined blend modes.
/// Additive blending.
#define BGFX_STATE_BLEND_ADD (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE) \
)
/// Alpha blend.
#define BGFX_STATE_BLEND_ALPHA (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) \
)
/// Selects darker color of blend.
#define BGFX_STATE_BLEND_DARKEN (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE) \
| BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_MIN) \
)
/// Selects lighter color of blend.
#define BGFX_STATE_BLEND_LIGHTEN (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE) \
| BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_MAX) \
)
/// Multiplies colors.
#define BGFX_STATE_BLEND_MULTIPLY (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO) \
)
/// Opaque pixels will cover the pixels directly below them without any math or algorithm applied to them.
#define BGFX_STATE_BLEND_NORMAL (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_ALPHA) \
)
/// Multiplies the inverse of the blend and base colors.
#define BGFX_STATE_BLEND_SCREEN (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_COLOR) \
)
/// Decreases the brightness of the base color based on the value of the blend color.
#define BGFX_STATE_BLEND_LINEAR_BURN (0 \
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_INV_DST_COLOR) \
| BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_SUB) \
)
///
#define BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) (0 \
| ( (uint32_t)( (_src)>>BGFX_STATE_BLEND_SHIFT) \
| ( (uint32_t)( (_dst)>>BGFX_STATE_BLEND_SHIFT)<<4) ) \
)
#define BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation) (0 \
| BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) \
| ( (uint32_t)( (_equation)>>BGFX_STATE_BLEND_EQUATION_SHIFT)<<8) \
)
#define BGFX_STATE_BLEND_FUNC_RT_1(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<< 0)
#define BGFX_STATE_BLEND_FUNC_RT_2(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<<11)
#define BGFX_STATE_BLEND_FUNC_RT_3(_src, _dst) (BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst)<<22)
#define BGFX_STATE_BLEND_FUNC_RT_1E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<< 0)
#define BGFX_STATE_BLEND_FUNC_RT_2E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<<11)
#define BGFX_STATE_BLEND_FUNC_RT_3E(_src, _dst, _equation) (BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation)<<22)
///
#define BGFX_STENCIL_FUNC_REF_SHIFT 0 //!<
#define BGFX_STENCIL_FUNC_REF_MASK UINT32_C(0x000000ff) //!<
#define BGFX_STENCIL_FUNC_RMASK_SHIFT 8 //!<
#define BGFX_STENCIL_FUNC_RMASK_MASK UINT32_C(0x0000ff00) //!<
#define BGFX_STENCIL_TEST_LESS UINT32_C(0x00010000) //!< Enable stencil test, less.
#define BGFX_STENCIL_TEST_LEQUAL UINT32_C(0x00020000) //!< Enable stencil test, less or equal.
#define BGFX_STENCIL_TEST_EQUAL UINT32_C(0x00030000) //!< Enable stencil test, equal.
#define BGFX_STENCIL_TEST_GEQUAL UINT32_C(0x00040000) //!< Enable stencil test, greater or equal.
#define BGFX_STENCIL_TEST_GREATER UINT32_C(0x00050000) //!< Enable stencil test, greater.
#define BGFX_STENCIL_TEST_NOTEQUAL UINT32_C(0x00060000) //!< Enable stencil test, not equal.
#define BGFX_STENCIL_TEST_NEVER UINT32_C(0x00070000) //!< Enable stencil test, never.
#define BGFX_STENCIL_TEST_ALWAYS UINT32_C(0x00080000) //!< Enable stencil test, always.
#define BGFX_STENCIL_TEST_SHIFT 16 //!< Stencil test bit shift.
#define BGFX_STENCIL_TEST_MASK UINT32_C(0x000f0000) //!< Stencil test bit mask.
#define BGFX_STENCIL_OP_FAIL_S_ZERO UINT32_C(0x00000000) //!< Zero.
#define BGFX_STENCIL_OP_FAIL_S_KEEP UINT32_C(0x00100000) //!< Keep.
#define BGFX_STENCIL_OP_FAIL_S_REPLACE UINT32_C(0x00200000) //!< Replace.
#define BGFX_STENCIL_OP_FAIL_S_INCR UINT32_C(0x00300000) //!< Increment and wrap.
#define BGFX_STENCIL_OP_FAIL_S_INCRSAT UINT32_C(0x00400000) //!< Increment and clamp.
#define BGFX_STENCIL_OP_FAIL_S_DECR UINT32_C(0x00500000) //!< Decrement and wrap.
#define BGFX_STENCIL_OP_FAIL_S_DECRSAT UINT32_C(0x00600000) //!< Decrement and clamp.
#define BGFX_STENCIL_OP_FAIL_S_INVERT UINT32_C(0x00700000) //!< Invert.
#define BGFX_STENCIL_OP_FAIL_S_SHIFT 20 //!< Stencil operation fail bit shift.
#define BGFX_STENCIL_OP_FAIL_S_MASK UINT32_C(0x00f00000) //!< Stencil operation fail bit mask.
#define BGFX_STENCIL_OP_FAIL_Z_ZERO UINT32_C(0x00000000) //!< Zero.
#define BGFX_STENCIL_OP_FAIL_Z_KEEP UINT32_C(0x01000000) //!< Keep.
#define BGFX_STENCIL_OP_FAIL_Z_REPLACE UINT32_C(0x02000000) //!< Replace.
#define BGFX_STENCIL_OP_FAIL_Z_INCR UINT32_C(0x03000000) //!< Increment and wrap.
#define BGFX_STENCIL_OP_FAIL_Z_INCRSAT UINT32_C(0x04000000) //!< Increment and clamp.
#define BGFX_STENCIL_OP_FAIL_Z_DECR UINT32_C(0x05000000) //!< Decrement and wrap.
#define BGFX_STENCIL_OP_FAIL_Z_DECRSAT UINT32_C(0x06000000) //!< Decrement and clamp.
#define BGFX_STENCIL_OP_FAIL_Z_INVERT UINT32_C(0x07000000) //!< Invert.
#define BGFX_STENCIL_OP_FAIL_Z_SHIFT 24 //!< Stencil operation depth fail bit shift
#define BGFX_STENCIL_OP_FAIL_Z_MASK UINT32_C(0x0f000000) //!< Stencil operation depth fail bit mask.
#define BGFX_STENCIL_OP_PASS_Z_ZERO UINT32_C(0x00000000) //!< Zero.
#define BGFX_STENCIL_OP_PASS_Z_KEEP UINT32_C(0x10000000) //!< Keep.
#define BGFX_STENCIL_OP_PASS_Z_REPLACE UINT32_C(0x20000000) //!< Replace.
#define BGFX_STENCIL_OP_PASS_Z_INCR UINT32_C(0x30000000) //!< Increment and wrap.
#define BGFX_STENCIL_OP_PASS_Z_INCRSAT UINT32_C(0x40000000) //!< Increment and clamp.
#define BGFX_STENCIL_OP_PASS_Z_DECR UINT32_C(0x50000000) //!< Decrement and wrap.
#define BGFX_STENCIL_OP_PASS_Z_DECRSAT UINT32_C(0x60000000) //!< Decrement and clamp.
#define BGFX_STENCIL_OP_PASS_Z_INVERT UINT32_C(0x70000000) //!< Invert.
#define BGFX_STENCIL_OP_PASS_Z_SHIFT 28 //!< Stencil operation depth pass bit shift
#define BGFX_STENCIL_OP_PASS_Z_MASK UINT32_C(0xf0000000) //!< Stencil operation depth pass bit mask.
#define BGFX_STENCIL_NONE UINT32_C(0x00000000) //!<
#define BGFX_STENCIL_MASK UINT32_C(0xffffffff) //!<
#define BGFX_STENCIL_DEFAULT UINT32_C(0x00000000) //!<
/// Set stencil ref value.
#define BGFX_STENCIL_FUNC_REF(_ref) ( ((uint32_t)(_ref)<<BGFX_STENCIL_FUNC_REF_SHIFT)&BGFX_STENCIL_FUNC_REF_MASK)
/// Set stencil rmask value.
#define BGFX_STENCIL_FUNC_RMASK(_mask) ( ((uint32_t)(_mask)<<BGFX_STENCIL_FUNC_RMASK_SHIFT)&BGFX_STENCIL_FUNC_RMASK_MASK)
///
#define BGFX_CLEAR_NONE UINT16_C(0x0000) //!< No clear flags.
#define BGFX_CLEAR_COLOR UINT16_C(0x0001) //!< Clear color.
#define BGFX_CLEAR_DEPTH UINT16_C(0x0002) //!< Clear depth.
#define BGFX_CLEAR_STENCIL UINT16_C(0x0004) //!< Clear stencil.
#define BGFX_CLEAR_DISCARD_COLOR_0 UINT16_C(0x0008) //!< Discard frame buffer attachment 0.
#define BGFX_CLEAR_DISCARD_COLOR_1 UINT16_C(0x0010) //!< Discard frame buffer attachment 1.
#define BGFX_CLEAR_DISCARD_COLOR_2 UINT16_C(0x0020) //!< Discard frame buffer attachment 2.
#define BGFX_CLEAR_DISCARD_COLOR_3 UINT16_C(0x0040) //!< Discard frame buffer attachment 3.
#define BGFX_CLEAR_DISCARD_COLOR_4 UINT16_C(0x0080) //!< Discard frame buffer attachment 4.
#define BGFX_CLEAR_DISCARD_COLOR_5 UINT16_C(0x0100) //!< Discard frame buffer attachment 5.
#define BGFX_CLEAR_DISCARD_COLOR_6 UINT16_C(0x0200) //!< Discard frame buffer attachment 6.
#define BGFX_CLEAR_DISCARD_COLOR_7 UINT16_C(0x0400) //!< Discard frame buffer attachment 7.
#define BGFX_CLEAR_DISCARD_DEPTH UINT16_C(0x0800) //!< Discard frame buffer depth attachment.
#define BGFX_CLEAR_DISCARD_STENCIL UINT16_C(0x1000) //!< Discard frame buffer stencil attachment.
#define BGFX_CLEAR_DISCARD_COLOR_MASK (0 \
| BGFX_CLEAR_DISCARD_COLOR_0 \
| BGFX_CLEAR_DISCARD_COLOR_1 \
| BGFX_CLEAR_DISCARD_COLOR_2 \
| BGFX_CLEAR_DISCARD_COLOR_3 \
| BGFX_CLEAR_DISCARD_COLOR_4 \
| BGFX_CLEAR_DISCARD_COLOR_5 \
| BGFX_CLEAR_DISCARD_COLOR_6 \
| BGFX_CLEAR_DISCARD_COLOR_7 \
)
#define BGFX_CLEAR_DISCARD_MASK (0 \
| BGFX_CLEAR_DISCARD_COLOR_MASK \
| BGFX_CLEAR_DISCARD_DEPTH \
| BGFX_CLEAR_DISCARD_STENCIL \
)
///
#define BGFX_DEBUG_NONE UINT32_C(0x00000000) //!< No debug.
#define BGFX_DEBUG_WIREFRAME UINT32_C(0x00000001) //!< Enable wireframe for all primitives.
#define BGFX_DEBUG_IFH UINT32_C(0x00000002) //!< Enable infinitely fast hardware test. No draw calls will be submitted to driver. Its useful when profiling to quickly assess bottleneck between CPU and GPU.
#define BGFX_DEBUG_STATS UINT32_C(0x00000004) //!< Enable statistics display.
#define BGFX_DEBUG_TEXT UINT32_C(0x00000008) //!< Enable debug text display.
#define BGFX_DEBUG_PROFILER UINT32_C(0x00000010) //!< Enable profiler.
///
#define BGFX_BUFFER_NONE UINT16_C(0x0000) //!<
#define BGFX_BUFFER_COMPUTE_FORMAT_8x1 UINT16_C(0x0001) //!< 1 8-bit value
#define BGFX_BUFFER_COMPUTE_FORMAT_8x2 UINT16_C(0x0002) //!< 2 8-bit values
#define BGFX_BUFFER_COMPUTE_FORMAT_8x4 UINT16_C(0x0003) //!< 4 8-bit values
#define BGFX_BUFFER_COMPUTE_FORMAT_16x1 UINT16_C(0x0004) //!< 1 16-bit value
#define BGFX_BUFFER_COMPUTE_FORMAT_16x2 UINT16_C(0x0005) //!< 2 16-bit values
#define BGFX_BUFFER_COMPUTE_FORMAT_16x4 UINT16_C(0x0006) //!< 4 16-bit values
#define BGFX_BUFFER_COMPUTE_FORMAT_32x1 UINT16_C(0x0007) //!< 1 32-bit value
#define BGFX_BUFFER_COMPUTE_FORMAT_32x2 UINT16_C(0x0008) //!< 2 32-bit values
#define BGFX_BUFFER_COMPUTE_FORMAT_32x4 UINT16_C(0x0009) //!< 4 32-bit values
#define BGFX_BUFFER_COMPUTE_FORMAT_SHIFT 0 //!<
#define BGFX_BUFFER_COMPUTE_FORMAT_MASK UINT16_C(0x000f) //!<
#define BGFX_BUFFER_COMPUTE_TYPE_INT UINT16_C(0x0010) //!< Type `int`.
#define BGFX_BUFFER_COMPUTE_TYPE_UINT UINT16_C(0x0020) //!< Type `uint`.
#define BGFX_BUFFER_COMPUTE_TYPE_FLOAT UINT16_C(0x0030) //!< Type `float`.
#define BGFX_BUFFER_COMPUTE_TYPE_SHIFT 4 //!<
#define BGFX_BUFFER_COMPUTE_TYPE_MASK UINT16_C(0x0030) //!<
#define BGFX_BUFFER_COMPUTE_READ UINT16_C(0x0100) //!< Buffer will be read by shader.
#define BGFX_BUFFER_COMPUTE_WRITE UINT16_C(0x0200) //!< Buffer will be used for writing.
#define BGFX_BUFFER_DRAW_INDIRECT UINT16_C(0x0400) //!< Buffer will be used for storing draw indirect commands.
#define BGFX_BUFFER_ALLOW_RESIZE UINT16_C(0x0800) //!< Allow dynamic index/vertex buffer resize during update.
#define BGFX_BUFFER_INDEX32 UINT16_C(0x1000) //!< Index buffer contains 32-bit indices.
#define BGFX_BUFFER_COMPUTE_READ_WRITE (0 \
| BGFX_BUFFER_COMPUTE_READ \
| BGFX_BUFFER_COMPUTE_WRITE \
)
///
#define BGFX_TEXTURE_NONE UINT32_C(0x00000000) //!<
#define BGFX_TEXTURE_U_MIRROR UINT32_C(0x00000001) //!< Wrap U mode: Mirror
#define BGFX_TEXTURE_U_CLAMP UINT32_C(0x00000002) //!< Wrap U mode: Clamp
#define BGFX_TEXTURE_U_BORDER UINT32_C(0x00000003) //!< Wrap U mode: Border
#define BGFX_TEXTURE_U_SHIFT 0 //!<
#define BGFX_TEXTURE_U_MASK UINT32_C(0x00000003) //!<
#define BGFX_TEXTURE_V_MIRROR UINT32_C(0x00000004) //!< Wrap V mode: Mirror
#define BGFX_TEXTURE_V_CLAMP UINT32_C(0x00000008) //!< Wrap V mode: Clamp
#define BGFX_TEXTURE_V_BORDER UINT32_C(0x0000000c) //!< Wrap V mode: Border
#define BGFX_TEXTURE_V_SHIFT 2 //!<
#define BGFX_TEXTURE_V_MASK UINT32_C(0x0000000c) //!<
#define BGFX_TEXTURE_W_MIRROR UINT32_C(0x00000010) //!< Wrap W mode: Mirror
#define BGFX_TEXTURE_W_CLAMP UINT32_C(0x00000020) //!< Wrap W mode: Clamp
#define BGFX_TEXTURE_W_BORDER UINT32_C(0x00000030) //!< Wrap W mode: Border
#define BGFX_TEXTURE_W_SHIFT 4 //!<
#define BGFX_TEXTURE_W_MASK UINT32_C(0x00000030) //!<
#define BGFX_TEXTURE_MIN_POINT UINT32_C(0x00000040) //!< Min sampling mode: Point
#define BGFX_TEXTURE_MIN_ANISOTROPIC UINT32_C(0x00000080) //!< Min sampling mode: Anisotropic
#define BGFX_TEXTURE_MIN_SHIFT 6 //!<
#define BGFX_TEXTURE_MIN_MASK UINT32_C(0x000000c0) //!<
#define BGFX_TEXTURE_MAG_POINT UINT32_C(0x00000100) //!< Mag sampling mode: Point
#define BGFX_TEXTURE_MAG_ANISOTROPIC UINT32_C(0x00000200) //!< Mag sampling mode: Anisotropic
#define BGFX_TEXTURE_MAG_SHIFT 8 //!<
#define BGFX_TEXTURE_MAG_MASK UINT32_C(0x00000300) //!<
#define BGFX_TEXTURE_MIP_POINT UINT32_C(0x00000400) //!< Mip sampling mode: Point
#define BGFX_TEXTURE_MIP_SHIFT 10 //!<
#define BGFX_TEXTURE_MIP_MASK UINT32_C(0x00000400) //!<
#define BGFX_TEXTURE_MSAA_SAMPLE UINT32_C(0x00000800) //!< Texture will be used for MSAA sampling.
#define BGFX_TEXTURE_RT UINT32_C(0x00001000) //!<
#define BGFX_TEXTURE_RT_MSAA_X2 UINT32_C(0x00002000) //!< Render target MSAAx2 mode.
#define BGFX_TEXTURE_RT_MSAA_X4 UINT32_C(0x00003000) //!< Render target MSAAx4 mode.
#define BGFX_TEXTURE_RT_MSAA_X8 UINT32_C(0x00004000) //!< Render target MSAAx8 mode.
#define BGFX_TEXTURE_RT_MSAA_X16 UINT32_C(0x00005000) //!< Render target MSAAx16 mode.
#define BGFX_TEXTURE_RT_MSAA_SHIFT 12 //!<
#define BGFX_TEXTURE_RT_MSAA_MASK UINT32_C(0x00007000) //!<
#define BGFX_TEXTURE_RT_WRITE_ONLY UINT32_C(0x00008000) //!< Render target will be used for writing only.
#define BGFX_TEXTURE_RT_MASK UINT32_C(0x0000f000) //!<
#define BGFX_TEXTURE_COMPARE_LESS UINT32_C(0x00010000) //!< Compare when sampling depth texture: less.
#define BGFX_TEXTURE_COMPARE_LEQUAL UINT32_C(0x00020000) //!< Compare when sampling depth texture: less or equal.
#define BGFX_TEXTURE_COMPARE_EQUAL UINT32_C(0x00030000) //!< Compare when sampling depth texture: equal.
#define BGFX_TEXTURE_COMPARE_GEQUAL UINT32_C(0x00040000) //!< Compare when sampling depth texture: greater or equal.
#define BGFX_TEXTURE_COMPARE_GREATER UINT32_C(0x00050000) //!< Compare when sampling depth texture: greater.
#define BGFX_TEXTURE_COMPARE_NOTEQUAL UINT32_C(0x00060000) //!< Compare when sampling depth texture: not equal.
#define BGFX_TEXTURE_COMPARE_NEVER UINT32_C(0x00070000) //!< Compare when sampling depth texture: never.
#define BGFX_TEXTURE_COMPARE_ALWAYS UINT32_C(0x00080000) //!< Compare when sampling depth texture: always.
#define BGFX_TEXTURE_COMPARE_SHIFT 16 //!<
#define BGFX_TEXTURE_COMPARE_MASK UINT32_C(0x000f0000) //!<
#define BGFX_TEXTURE_COMPUTE_WRITE UINT32_C(0x00100000) //!< Texture will be used for compute write.
#define BGFX_TEXTURE_SRGB UINT32_C(0x00200000) //!< Sample texture as sRGB.
#define BGFX_TEXTURE_BLIT_DST UINT32_C(0x00400000) //!< Texture will be used as blit destination.
#define BGFX_TEXTURE_READ_BACK UINT32_C(0x00800000) //!< Texture will be used for read back from GPU.
#define BGFX_TEXTURE_BORDER_COLOR_SHIFT 24 //!<
#define BGFX_TEXTURE_BORDER_COLOR_MASK UINT32_C(0x0f000000) //!<
#define BGFX_TEXTURE_RESERVED_SHIFT 28 //!<
#define BGFX_TEXTURE_RESERVED_MASK UINT32_C(0xf0000000) //!<
#define BGFX_TEXTURE_BORDER_COLOR(_index) ( (_index << BGFX_TEXTURE_BORDER_COLOR_SHIFT) & BGFX_TEXTURE_BORDER_COLOR_MASK)
#define BGFX_TEXTURE_SAMPLER_BITS_MASK (0 \
| BGFX_TEXTURE_U_MASK \
| BGFX_TEXTURE_V_MASK \
| BGFX_TEXTURE_W_MASK \
| BGFX_TEXTURE_MIN_MASK \
| BGFX_TEXTURE_MAG_MASK \
| BGFX_TEXTURE_MIP_MASK \
| BGFX_TEXTURE_COMPARE_MASK \
)
///
#define BGFX_RESET_NONE UINT32_C(0x00000000) //!< No reset flags.
#define BGFX_RESET_FULLSCREEN UINT32_C(0x00000001) //!< Not supported yet.
#define BGFX_RESET_FULLSCREEN_SHIFT 0 //!< Fullscreen bit shift.
#define BGFX_RESET_FULLSCREEN_MASK UINT32_C(0x00000001) //!< Fullscreen bit mask.
#define BGFX_RESET_MSAA_X2 UINT32_C(0x00000010) //!< Enable 2x MSAA.
#define BGFX_RESET_MSAA_X4 UINT32_C(0x00000020) //!< Enable 4x MSAA.
#define BGFX_RESET_MSAA_X8 UINT32_C(0x00000030) //!< Enable 8x MSAA.
#define BGFX_RESET_MSAA_X16 UINT32_C(0x00000040) //!< Enable 16x MSAA.
#define BGFX_RESET_MSAA_SHIFT 4 //!< MSAA mode bit shift.
#define BGFX_RESET_MSAA_MASK UINT32_C(0x00000070) //!< MSAA mode bit mask.
#define BGFX_RESET_VSYNC UINT32_C(0x00000080) //!< Enable V-Sync.
#define BGFX_RESET_MAXANISOTROPY UINT32_C(0x00000100) //!< Turn on/off max anisotropy.
#define BGFX_RESET_CAPTURE UINT32_C(0x00000200) //!< Begin screen capture.
#define BGFX_RESET_HMD UINT32_C(0x00000400) //!< HMD stereo rendering.
#define BGFX_RESET_HMD_DEBUG UINT32_C(0x00000800) //!< HMD stereo rendering debug mode.
#define BGFX_RESET_HMD_RECENTER UINT32_C(0x00001000) //!< HMD calibration.
#define BGFX_RESET_FLUSH_AFTER_RENDER UINT32_C(0x00002000) //!< Flush rendering after submitting to GPU.
#define BGFX_RESET_FLIP_AFTER_RENDER UINT32_C(0x00004000) //!< This flag specifies where flip occurs. Default behavior is that flip occurs before rendering new frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`.
#define BGFX_RESET_SRGB_BACKBUFFER UINT32_C(0x00008000) //!< Enable sRGB backbuffer.
#define BGFX_RESET_HIDPI UINT32_C(0x00010000) //!< Enable HiDPI rendering.
#define BGFX_RESET_DEPTH_CLAMP UINT32_C(0x00020000) //!< Enable depth clamp.
#define BGFX_RESET_SUSPEND UINT32_C(0x00040000) //!< Suspend rendering.
#define BGFX_RESET_RESERVED_SHIFT 31 //!< Internal bits shift.
#define BGFX_RESET_RESERVED_MASK UINT32_C(0x80000000) //!< Internal bits mask.
///
#define BGFX_CAPS_ALPHA_TO_COVERAGE UINT64_C(0x0000000000000001) //!< Alpha to coverage is supported.
#define BGFX_CAPS_BLEND_INDEPENDENT UINT64_C(0x0000000000000002) //!< Blend independent is supported.
#define BGFX_CAPS_COMPUTE UINT64_C(0x0000000000000004) //!< Compute shaders are supported.
#define BGFX_CAPS_CONSERVATIVE_RASTER UINT64_C(0x0000000000000008) //!< Conservative rasterization is supported.
#define BGFX_CAPS_DRAW_INDIRECT UINT64_C(0x0000000000000010) //!< Draw indirect is supported.
#define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000000000020) //!< Fragment depth is accessible in fragment shader.
#define BGFX_CAPS_FRAGMENT_ORDERING UINT64_C(0x0000000000000040) //!< Fragment ordering is available in fragment shader.
#define BGFX_CAPS_GRAPHICS_DEBUGGER UINT64_C(0x0000000000000080) //!< Graphics debugger is present.
#define BGFX_CAPS_HIDPI UINT64_C(0x0000000000000100) //!< HiDPI rendering is supported.
#define BGFX_CAPS_HMD UINT64_C(0x0000000000000200) //!< Head Mounted Display is available.
#define BGFX_CAPS_INDEX32 UINT64_C(0x0000000000000400) //!< 32-bit indices are supported.
#define BGFX_CAPS_INSTANCING UINT64_C(0x0000000000000800) //!< Instancing is supported.
#define BGFX_CAPS_OCCLUSION_QUERY UINT64_C(0x0000000000001000) //!< Occlusion query is supported.
#define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000000002000) //!< Renderer is on separate thread.
#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000004000) //!< Multiple windows are supported.
#define BGFX_CAPS_TEXTURE_2D_ARRAY UINT64_C(0x0000000000008000) //!< 2D texture array is supported.
#define BGFX_CAPS_TEXTURE_3D UINT64_C(0x0000000000010000) //!< 3D textures are supported.
#define BGFX_CAPS_TEXTURE_BLIT UINT64_C(0x0000000000020000) //!< Texture blit is supported.
#define BGFX_CAPS_TEXTURE_COMPARE_ALL UINT64_C(0x00000000000c0000) //!< All texture compare modes are supported.
#define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000080000) //!< Texture compare less equal mode is supported.
#define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000100000) //!< Cubemap texture array is supported.
#define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000000200000) //!< CPU direct access to GPU texture memory.
#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000000400000) //!< Read-back texture is supported.
#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000000800000) //!< Vertex attribute half-float is supported.
#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000000800000) //!< Vertex attribute 10_10_10_2 is supported.
#define BGFX_CAPS_VERTEX_ID UINT64_C(0x0000000001000000) //!< Rendering with VertexID only is supported.
///
#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT16_C(0x0000) //!< Texture format is not supported.
#define BGFX_CAPS_FORMAT_TEXTURE_2D UINT16_C(0x0001) //!< Texture format is supported.
#define BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB UINT16_C(0x0002) //!< Texture as sRGB format is supported.
#define BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED UINT16_C(0x0004) //!< Texture format is emulated.
#define BGFX_CAPS_FORMAT_TEXTURE_3D UINT16_C(0x0008) //!< Texture format is supported.
#define BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB UINT16_C(0x0010) //!< Texture as sRGB format is supported.
#define BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED UINT16_C(0x0020) //!< Texture format is emulated.
#define BGFX_CAPS_FORMAT_TEXTURE_CUBE UINT16_C(0x0040) //!< Texture format is supported.
#define BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB UINT16_C(0x0080) //!< Texture as sRGB format is supported.
#define BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED UINT16_C(0x0100) //!< Texture format is emulated.
#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT16_C(0x0200) //!< Texture format can be used from vertex shader.
#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT16_C(0x0400) //!< Texture format can be used as image from compute shader.
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT16_C(0x0800) //!< Texture format can be used as frame buffer.
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT16_C(0x1000) //!< Texture format can be used as MSAA frame buffer.
#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT16_C(0x2000) //!< Texture can be sampled as MSAA.
#define BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN UINT16_C(0x4000) //!< Texture format supports auto-generated mips.
///
#define BGFX_VIEW_NONE UINT8_C(0x00) //!<
#define BGFX_VIEW_STEREO UINT8_C(0x01) //!< View will be rendered in stereo mode.
///
#define BGFX_SUBMIT_EYE_LEFT UINT8_C(0x01) //!< Submit to left eye.
#define BGFX_SUBMIT_EYE_RIGHT UINT8_C(0x02) //!< Submit to right eye.
#define BGFX_SUBMIT_EYE_MASK UINT8_C(0x03) //!<
#define BGFX_SUBMIT_EYE_FIRST BGFX_SUBMIT_EYE_LEFT
#define BGFX_SUBMIT_RESERVED_SHIFT 7 //!< Internal bits shift.
#define BGFX_SUBMIT_RESERVED_MASK UINT8_C(0x80) //!< Internal bits mask.
///
#define BGFX_PCI_ID_NONE UINT16_C(0x0000) //!< Autoselect adapter.
#define BGFX_PCI_ID_SOFTWARE_RASTERIZER UINT16_C(0x0001) //!< Software rasterizer.
#define BGFX_PCI_ID_AMD UINT16_C(0x1002) //!< AMD adapter.
#define BGFX_PCI_ID_INTEL UINT16_C(0x8086) //!< Intel adapter.
#define BGFX_PCI_ID_NVIDIA UINT16_C(0x10de) //!< nVidia adapter.
///
#define BGFX_HMD_NONE UINT8_C(0x00) //!< None.
#define BGFX_HMD_DEVICE_RESOLUTION UINT8_C(0x01) //!< Has HMD native resolution.
#define BGFX_HMD_RENDERING UINT8_C(0x02) //!< Rendering to HMD.
///
#define BGFX_CUBE_MAP_POSITIVE_X UINT8_C(0x00) //!< Cubemap +x.
#define BGFX_CUBE_MAP_NEGATIVE_X UINT8_C(0x01) //!< Cubemap -x.
#define BGFX_CUBE_MAP_POSITIVE_Y UINT8_C(0x02) //!< Cubemap +y.
#define BGFX_CUBE_MAP_NEGATIVE_Y UINT8_C(0x03) //!< Cubemap -y.
#define BGFX_CUBE_MAP_POSITIVE_Z UINT8_C(0x04) //!< Cubemap +z.
#define BGFX_CUBE_MAP_NEGATIVE_Z UINT8_C(0x05) //!< Cubemap -z.
#endif // BGFX_DEFINES_H_HEADER_GUARD

View file

@ -1,143 +0,0 @@
/*
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#ifndef BGFX_EMBEDDED_SHADER_H_HEADER_GUARD
#define BGFX_EMBEDDED_SHADER_H_HEADER_GUARD
#include <bx/macros.h>
#include "bgfx.h"
#define BGFX_EMBEDDED_SHADER_DXBC(...)
#define BGFX_EMBEDDED_SHADER_DX9BC(...)
#define BGFX_EMBEDDED_SHADER_PSSL(...)
#define BGFX_EMBEDDED_SHADER_ESSL(...)
#define BGFX_EMBEDDED_SHADER_GLSL(...)
#define BGFX_EMBEDDED_SHADER_SPIRV(...)
#define BGFX_EMBEDDED_SHADER_METAL(...)
#define BGFX_PLATFORM_SUPPORTS_DX9BC (0 \
|| BX_PLATFORM_WINDOWS \
)
#define BGFX_PLATFORM_SUPPORTS_DXBC (0 \
|| BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_WINRT \
|| BX_PLATFORM_XBOXONE \
)
#define BGFX_PLATFORM_SUPPORTS_PSSL (0 \
|| BX_PLATFORM_PS4 \
)
#define BGFX_PLATFORM_SUPPORTS_ESSL (0 \
|| BX_PLATFORM_ANDROID \
|| BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_OSX \
|| BX_PLATFORM_RPI \
|| BX_PLATFORM_STEAMLINK \
|| BX_PLATFORM_WINDOWS \
)
#define BGFX_PLATFORM_SUPPORTS_GLSL (0 \
|| BX_PLATFORM_BSD \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_OSX \
|| BX_PLATFORM_WINDOWS \
)
#define BGFX_PLATFORM_SUPPORTS_METAL (0 \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_OSX \
)
#define BGFX_PLATFORM_SUPPORTS_SPIRV (0 \
|| BX_PLATFORM_ANDROID \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_WINDOWS \
)
#if BGFX_PLATFORM_SUPPORTS_DX9BC
# undef BGFX_EMBEDDED_SHADER_DX9BC
# define BGFX_EMBEDDED_SHADER_DX9BC(_renderer, _name) \
{ _renderer, BX_CONCATENATE(_name, _dx9 ), BX_COUNTOF(BX_CONCATENATE(_name, _dx9 ) ) },
#endif // BGFX_PLATFORM_SUPPORTS_DX9BC
#if BGFX_PLATFORM_SUPPORTS_DXBC
# undef BGFX_EMBEDDED_SHADER_DXBC
# define BGFX_EMBEDDED_SHADER_DXBC(_renderer, _name) \
{ _renderer, BX_CONCATENATE(_name, _dx11), BX_COUNTOF(BX_CONCATENATE(_name, _dx11) ) },
#endif // BGFX_PLATFORM_SUPPORTS_DXBC
#if BGFX_PLATFORM_SUPPORTS_PSSL
# undef BGFX_EMBEDDED_SHADER_PSSL
# define BGFX_EMBEDDED_SHADER_PSSL(_renderer, _name) \
{ _renderer, BX_CONCATENATE(_name, _pssl), BX_CONCATENATE(_name, _pssl_size) },
#endif // BGFX_PLATFORM_SUPPORTS_PSSL
#if BGFX_PLATFORM_SUPPORTS_ESSL
# undef BGFX_EMBEDDED_SHADER_ESSL
# define BGFX_EMBEDDED_SHADER_ESSL(_renderer, _name) \
{ _renderer, BX_CONCATENATE(_name, _glsl), BX_COUNTOF(BX_CONCATENATE(_name, _glsl) ) },
#endif // BGFX_PLATFORM_SUPPORTS_ESSL
#if BGFX_PLATFORM_SUPPORTS_GLSL
# undef BGFX_EMBEDDED_SHADER_GLSL
# define BGFX_EMBEDDED_SHADER_GLSL(_renderer, _name) \
{ _renderer, BX_CONCATENATE(_name, _glsl), BX_COUNTOF(BX_CONCATENATE(_name, _glsl) ) },
#endif // BGFX_PLATFORM_SUPPORTS_GLSL
#if BGFX_PLATFORM_SUPPORTS_SPIRV
# undef BGFX_EMBEDDED_SHADER_SPIRV
# define BGFX_EMBEDDED_SHADER_SPIRV(_renderer, _name) \
{ _renderer, BX_CONCATENATE(_name, _spv), BX_COUNTOF(BX_CONCATENATE(_name, _spv) ) },
#endif // BGFX_PLATFORM_SUPPORTS_SPIRV
#if BGFX_PLATFORM_SUPPORTS_METAL
# undef BGFX_EMBEDDED_SHADER_METAL
# define BGFX_EMBEDDED_SHADER_METAL(_renderer, _name) \
{ _renderer, BX_CONCATENATE(_name, _mtl), BX_COUNTOF(BX_CONCATENATE(_name, _mtl) ) },
#endif // BGFX_PLATFORM_SUPPORTS_METAL
#define BGFX_EMBEDDED_SHADER(_name) \
{ \
#_name, \
{ \
BGFX_EMBEDDED_SHADER_DX9BC(bgfx::RendererType::Direct3D9, _name) \
BGFX_EMBEDDED_SHADER_DXBC (bgfx::RendererType::Direct3D11, _name) \
BGFX_EMBEDDED_SHADER_DXBC (bgfx::RendererType::Direct3D12, _name) \
BGFX_EMBEDDED_SHADER_PSSL (bgfx::RendererType::Gnm, _name) \
BGFX_EMBEDDED_SHADER_METAL(bgfx::RendererType::Metal, _name) \
BGFX_EMBEDDED_SHADER_ESSL (bgfx::RendererType::OpenGLES, _name) \
BGFX_EMBEDDED_SHADER_GLSL (bgfx::RendererType::OpenGL, _name) \
BGFX_EMBEDDED_SHADER_SPIRV(bgfx::RendererType::Vulkan, _name) \
{ bgfx::RendererType::Noop, (const uint8_t*)"VSH\x5\x0\x0\x0\x0\x0\x0", 10 }, \
{ bgfx::RendererType::Count, NULL, 0 } \
} \
}
#define BGFX_EMBEDDED_SHADER_END() \
{ \
NULL, \
{ \
{ bgfx::RendererType::Count, NULL, 0 } \
} \
}
namespace bgfx
{
struct EmbeddedShader
{
struct Data
{
RendererType::Enum type;
const uint8_t* data;
uint32_t size;
};
const char* name;
Data data[RendererType::Count];
};
ShaderHandle createEmbeddedShader(const bgfx::EmbeddedShader* _es, RendererType::Enum _type, const char* _name);
} // namespace bgfx
#endif // BGFX_EMBEDDED_SHADER_H_HEADER_GUARD

View file

@ -1,141 +0,0 @@
/*
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#ifndef BGFX_PLATFORM_H_HEADER_GUARD
#define BGFX_PLATFORM_H_HEADER_GUARD
// NOTICE:
// This header file contains platform specific interfaces. It is only
// necessary to use this header in conjunction with creating windows.
#include <bx/platform.h>
#include "bgfx.h"
namespace bgfx
{
/// Render frame enum.
///
/// @attention C99 equivalent is `bgfx_render_frame_t`.
///
struct RenderFrame
{
enum Enum
{
NoContext,
Render,
Timeout,
Exiting,
Count
};
};
/// Render frame.
///
/// @param _msecs Timeout in milliseconds.
///
/// @returns Current renderer state. See: `bgfx::RenderFrame`.
///
/// @attention `bgfx::renderFrame` is blocking call. It waits for
/// `bgfx::frame` to be called from API thread to process frame.
/// If timeout value is passed call will timeout and return even
/// if `bgfx::frame` is not called.
///
/// @warning This call should be only used on platforms that don't
/// allow creating separate rendering thread. If it is called before
/// to bgfx::init, render thread won't be created by bgfx::init call.
RenderFrame::Enum renderFrame(int32_t _msecs = -1);
/// Platform data.
///
/// @attention C99 equivalent is `bgfx_platform_data_t`.
///
struct PlatformData
{
void* ndt; //!< Native display type.
void* nwh; //!< Native window handle.
void* context; //!< GL context, or D3D device.
void* backBuffer; //!< GL backbuffer, or D3D render target view.
void* backBufferDS; //!< Backbuffer depth/stencil.
void* session; //!< ovrSession, for Oculus SDK
};
/// Set platform data.
///
/// @warning Must be called before `bgfx::init`.
///
/// @attention C99 equivalent is `bgfx_set_platform_data`.
///
void setPlatformData(const PlatformData& _data);
/// Internal data.
///
/// @attention C99 equivalent is `bgfx_internal_data_t`.
///
struct InternalData
{
const struct Caps* caps; //!< Renderer capabilities.
void* context; //!< GL context, or D3D device.
};
/// Get internal data for interop.
///
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_get_internal_data`.
///
const InternalData* getInternalData();
/// Override internal texture with externally created texture. Previously
/// created internal texture will released.
///
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
///
/// @param[in] _handle Texture handle.
/// @param[in] _ptr Native API pointer to texture.
///
/// @returns Native API pointer to texture. If result is 0, texture is not created yet from the
/// main thread.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_override_internal_texture_ptr`.
///
uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr);
/// Override internal texture by creating new texture. Previously created
/// internal texture will released.
///
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
///
/// @param[in] _handle Texture handle.
/// @param[in] _width Width.
/// @param[in] _height Height.
/// @param[in] _numMips Number of mip-maps.
/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
/// is repeat.
/// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap
/// mode.
/// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
/// sampling.
///
/// @returns Native API pointer to texture. If result is 0, texture is not created yet from the
/// main thread.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_override_internal_texture`.
///
uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE);
} // namespace bgfx
#endif // BGFX_PLATFORM_H_HEADER_GUARD

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1095,7 +1095,8 @@ struct DockContext
}
m_docks.clear();
if (lua_getglobal(L, "docks") == LUA_TTABLE)
lua_getglobal(L, "docks");
if (lua_type(L, -1) == LUA_TTABLE)
{
lua_pushnil(L);
while (lua_next(L, -2) != 0)
@ -1107,7 +1108,8 @@ struct DockContext
}
lua_pop(L, 1);
if (lua_getglobal(L, "docks") == LUA_TTABLE)
lua_getglobal(L, "docks");
if (lua_type(L, -1) == LUA_TTABLE)
{
lua_pushnil(L);
while (lua_next(L, -2) != 0)
@ -1115,55 +1117,70 @@ struct DockContext
if (lua_istable(L, -1))
{
int idx = 0;
if (lua_getfield(L, -1, "index") == LUA_TNUMBER)
lua_getfield(L, -1, "index");
if (lua_type(L, -1) == LUA_TNUMBER)
idx = (int)lua_tointeger(L, -1);
Dock& dock = *m_docks[idx];
lua_pop(L, 1);
if (lua_getfield(L, -1, "label") == LUA_TSTRING)
lua_getfield(L, -1, "label");
if (lua_type(L, -1) == LUA_TSTRING)
{
dock.label = ImStrdup(lua_tostring(L, -1));
dock.id = ImHash(dock.label, 0);
}
lua_pop(L, 1);
if (lua_getfield(L, -1, "x") == LUA_TNUMBER)
lua_getfield(L, -1, "x");
if (lua_type(L, -1) == LUA_TNUMBER)
dock.pos.x = (float)lua_tonumber(L, -1);
if (lua_getfield(L, -2, "y") == LUA_TNUMBER)
lua_getfield(L, -2, "y");
if (lua_type(L, -1) == LUA_TNUMBER)
dock.pos.y = (float)lua_tonumber(L, -1);
if (lua_getfield(L, -3, "size_x") == LUA_TNUMBER)
lua_getfield(L, -3, "size_x");
if (lua_type(L, -1) == LUA_TNUMBER)
dock.size.x = (float)lua_tonumber(L, -1);
if (lua_getfield(L, -4, "size_y") == LUA_TNUMBER)
lua_getfield(L, -4, "size_y");
if (lua_type(L, -1) == LUA_TNUMBER)
dock.size.y = (float)lua_tonumber(L, -1);
if (lua_getfield(L, -5, "active") == LUA_TNUMBER)
lua_getfield(L, -5, "active");
if (lua_type(L, -1) == LUA_TNUMBER)
dock.active = lua_tointeger(L, -1) != 0;
if (lua_getfield(L, -6, "opened") == LUA_TNUMBER)
lua_getfield(L, -6, "opened");
if (lua_type(L, -1) == LUA_TNUMBER)
dock.opened = lua_tointeger(L, -1) != 0;
if (lua_getfield(L, -7, "location") == LUA_TSTRING)
lua_getfield(L, -7, "location");
if (lua_type(L, -1) == LUA_TSTRING)
strcpy(dock.location, lua_tostring(L, -1));
if (lua_getfield(L, -8, "status") == LUA_TNUMBER)
lua_getfield(L, -8, "status");
if (lua_type(L, -1) == LUA_TNUMBER)
{
dock.status = (Status_)lua_tointeger(L, -1);
}
lua_pop(L, 8);
if (lua_getfield(L, -1, "prev") == LUA_TNUMBER)
lua_getfield(L, -1, "prev");
if (lua_type(L, -1) == LUA_TNUMBER)
{
dock.prev_tab = getDockByIndex(lua_tointeger(L, -1));
}
if (lua_getfield(L, -2, "next") == LUA_TNUMBER)
lua_getfield(L, -2, "next");
if (lua_type(L, -1) == LUA_TNUMBER)
{
dock.next_tab = getDockByIndex(lua_tointeger(L, -1));
}
if (lua_getfield(L, -3, "child0") == LUA_TNUMBER)
lua_getfield(L, -3, "child0");
if (lua_type(L, -1) == LUA_TNUMBER)
{
dock.children[0] = getDockByIndex(lua_tointeger(L, -1));
}
if (lua_getfield(L, -4, "child1") == LUA_TNUMBER)
lua_getfield(L, -4, "child1");
if (lua_type(L, -1) == LUA_TNUMBER)
{
dock.children[1] = getDockByIndex(lua_tointeger(L, -1));
}
if (lua_getfield(L, -5, "parent") == LUA_TNUMBER)
lua_getfield(L, -5, "parent");
if (lua_type(L, -1) == LUA_TNUMBER)
{
dock.parent = getDockByIndex(lua_tointeger(L, -1));
}

View file

@ -1,6 +0,0 @@
Copyright © 19942015 Lua.org, PUC-Rio.
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.

View file

@ -1,256 +0,0 @@
/*
** $Id: lauxlib.h,v 1.129 2015/11/23 11:29:43 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#include <stddef.h>
#include <stdio.h>
#include "lua.h"
/* extra error code for 'luaL_load' */
#define LUA_ERRFILE (LUA_ERRERR+1)
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);
#define luaL_checkversion(L) \
luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,
lua_Integer def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int arg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
const char *const lst[]);
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
/* predefined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
const char *mode);
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
lua_CFunction openf, int glb);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_newlibtable(L,l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#define luaL_newlib(L,l) \
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
#define luaL_argcheck(L, cond,arg,extramsg) \
((void)((cond) || luaL_argerror(L, (arg), (extramsg))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
typedef struct luaL_Buffer {
char *b; /* buffer address */
size_t size; /* buffer size */
size_t n; /* number of characters in buffer */
lua_State *L;
char initb[LUAL_BUFFERSIZE]; /* initial buffer */
} luaL_Buffer;
#define luaL_addchar(B,c) \
((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
((B)->b[(B)->n++] = (c)))
#define luaL_addsize(B,s) ((B)->n += (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
/* }====================================================== */
/*
** {======================================================
** File handles for IO library
** =======================================================
*/
/*
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
*/
#define LUA_FILEHANDLE "FILE*"
typedef struct luaL_Stream {
FILE *f; /* stream (NULL for incompletely created streams) */
lua_CFunction closef; /* to close stream (NULL for closed streams) */
} luaL_Stream;
/* }====================================================== */
/* compatibility with old module system */
#if defined(LUA_COMPAT_MODULE)
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
#endif
/*
** {==================================================================
** "Abstraction Layer" for basic report of messages and errors
** ===================================================================
*/
/* print a string */
#if !defined(lua_writestring)
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
#endif
/* print a newline and flush the output */
#if !defined(lua_writeline)
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
#endif
/* print an error message */
#if !defined(lua_writestringerror)
#define lua_writestringerror(s,p) \
(fprintf(stderr, (s), (p)), fflush(stderr))
#endif
/* }================================================================== */
/*
** {============================================================
** Compatibility with deprecated conversions
** =============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
#define luaL_optunsigned(L,a,d) \
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#endif
/* }============================================================ */
#endif

View file

@ -1,486 +0,0 @@
/*
** $Id: lua.h,v 1.329 2015/11/13 17:18:42 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "3"
#define LUA_VERSION_NUM 503
#define LUA_VERSION_RELEASE "2"
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
#define LUA_SIGNATURE "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
#define LUA_MULTRET (-1)
/*
** Pseudo-indices
** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
** space after that to help overflow detection)
*/
#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
/* thread status */
#define LUA_OK 0
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRGCMM 5
#define LUA_ERRERR 6
typedef struct lua_State lua_State;
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_NUMTAGS 9
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/* predefined values in the registry */
#define LUA_RIDX_MAINTHREAD 1
#define LUA_RIDX_GLOBALS 2
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/* type for continuation-function contexts */
typedef LUA_KCONTEXT lua_KContext;
/*
** Type for C functions registered with Lua
*/
typedef int (*lua_CFunction) (lua_State *L);
/*
** Type for continuation functions
*/
typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
/*
** Type for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/*
** RCS ident string
*/
extern const char lua_ident[];
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API const lua_Number *(lua_version) (lua_State *L);
/*
** basic stack manipulation
*/
LUA_API int (lua_absindex) (lua_State *L, int idx);
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
LUA_API int (lua_checkstack) (lua_State *L, int n);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isinteger) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** Comparison and arithmetic functions
*/
#define LUA_OPADD 0 /* ORDER TM, ORDER OP */
#define LUA_OPSUB 1
#define LUA_OPMUL 2
#define LUA_OPMOD 3
#define LUA_OPPOW 4
#define LUA_OPDIV 5
#define LUA_OPIDIV 6
#define LUA_OPBAND 7
#define LUA_OPBOR 8
#define LUA_OPBXOR 9
#define LUA_OPSHL 10
#define LUA_OPSHR 11
#define LUA_OPUNM 12
#define LUA_OPBNOT 13
LUA_API void (lua_arith) (lua_State *L, int op);
#define LUA_OPEQ 0
#define LUA_OPLT 1
#define LUA_OPLE 2
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API int (lua_getglobal) (lua_State *L, const char *name);
LUA_API int (lua_gettable) (lua_State *L, int idx);
LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawget) (lua_State *L, int idx);
LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API int (lua_getuservalue) (lua_State *L, int idx);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_setglobal) (lua_State *L, const char *name);
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API void (lua_setuservalue) (lua_State *L, int idx);
/*
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
lua_KContext ctx, lua_KFunction k);
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
lua_KContext ctx, lua_KFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname, const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
/*
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
lua_KFunction k);
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
LUA_API int (lua_status) (lua_State *L);
LUA_API int (lua_isyieldable) (lua_State *L);
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
#define LUA_GCISRUNNING 9
LUA_API int (lua_gc) (lua_State *L, int what, int data);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API void (lua_len) (lua_State *L, int idx);
LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
#define lua_pushglobaltable(L) \
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
/* }============================================================== */
/*
** {==============================================================
** compatibility macros for unsigned conversions
** ===============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
#endif
/* }============================================================== */
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILCALL 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
/* Functions to be called by the debugger in specific events */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
int fidx2, int n2);
LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook (lua_gethook) (lua_State *L);
LUA_API int (lua_gethookmask) (lua_State *L);
LUA_API int (lua_gethookcount) (lua_State *L);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
const char *source; /* (S) */
int currentline; /* (l) */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
unsigned char nups; /* (u) number of upvalues */
unsigned char nparams;/* (u) number of parameters */
char isvararg; /* (u) */
char istailcall; /* (t) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
struct CallInfo *i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2015 Lua.org, PUC-Rio.
*
* 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.
******************************************************************************/
#endif

View file

@ -1,9 +0,0 @@
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

View file

@ -1,767 +0,0 @@
/*
** $Id: luaconf.h,v 1.254 2015/10/21 18:17:40 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
#ifndef luaconf_h
#define luaconf_h
#include <limits.h>
#include <stddef.h>
/*
** ===================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
*/
/*
** {====================================================================
** System Configuration: macros to adapt (if needed) Lua to some
** particular platform, for instance compiling it with 32-bit numbers or
** restricting it to C89.
** =====================================================================
*/
/*
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
** can also define LUA_32BITS in the make file, but changing here you
** ensure that all software connected to Lua will be compiled with the
** same configuration.
*/
/* #define LUA_32BITS */
/*
@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
** Define it if you want Lua to avoid the use of a few C99 features
** or Windows-specific features on Windows.
*/
/* #define LUA_USE_C89 */
/*
** By default, Lua on Windows use (some) specific Windows features
*/
#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
#define LUA_USE_WINDOWS /* enable goodies for regular Windows */
#endif
#if defined(LUA_USE_WINDOWS)
#define LUA_DL_DLL /* enable support for DLL */
#define LUA_USE_C89 /* broadly, Windows is C89 */
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#define LUA_USE_READLINE /* needs some extra libraries */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* MacOS does not need -ldl */
#define LUA_USE_READLINE /* needs an extra library: -lreadline */
#endif
/*
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
** C89 ('long' and 'double'); Windows always has '__int64', so it does
** not need to use this case.
*/
#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
#define LUA_C89_NUMBERS
#endif
/*
@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.
*/
/* avoid undefined shifts */
#if ((INT_MAX >> 15) >> 15) >= 1
#define LUAI_BITSINT 32
#else
/* 'int' always must have at least 16 bits */
#define LUAI_BITSINT 16
#endif
/*
@@ LUA_INT_TYPE defines the type for Lua integers.
@@ LUA_FLOAT_TYPE defines the type for Lua floats.
** Lua should work fine with any mix of these options (if supported
** by your C compiler). The usual configurations are 64-bit integers
** and 'double' (the default), 32-bit integers and 'float' (for
** restricted platforms), and 'long'/'double' (for C compilers not
** compliant with C99, which may not have support for 'long long').
*/
/* predefined options for LUA_INT_TYPE */
#define LUA_INT_INT 1
#define LUA_INT_LONG 2
#define LUA_INT_LONGLONG 3
/* predefined options for LUA_FLOAT_TYPE */
#define LUA_FLOAT_FLOAT 1
#define LUA_FLOAT_DOUBLE 2
#define LUA_FLOAT_LONGDOUBLE 3
#if defined(LUA_32BITS) /* { */
/*
** 32-bit integers and 'float'
*/
#if LUAI_BITSINT >= 32 /* use 'int' if big enough */
#define LUA_INT_TYPE LUA_INT_INT
#else /* otherwise use 'long' */
#define LUA_INT_TYPE LUA_INT_LONG
#endif
#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
#elif defined(LUA_C89_NUMBERS) /* }{ */
/*
** largest types available for C89 ('long' and 'double')
*/
#define LUA_INT_TYPE LUA_INT_LONG
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif /* } */
/*
** default configuration for 64-bit Lua ('long long' and 'double')
*/
#if !defined(LUA_INT_TYPE)
#define LUA_INT_TYPE LUA_INT_LONGLONG
#endif
#if !defined(LUA_FLOAT_TYPE)
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif
/* }================================================================== */
/*
** {==================================================================
** Configuration for Paths.
** ===================================================================
*/
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
** Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
** C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
".\\?.lua;" ".\\?\\init.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" \
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
LUA_CDIR"loadall.dll;" ".\\?.dll"
#else /* }{ */
#define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
"./?.lua;" "./?/init.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
#endif /* } */
/*
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
/* }================================================================== */
/*
** {==================================================================
** Marks for exported symbols in the C code
** ===================================================================
*/
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL) /* { */
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
#else /* }{ */
#define LUA_API __declspec(dllimport)
#endif /* } */
#else /* }{ */
#define LUA_API extern
#endif /* } */
/* more often than not the libs go together with the core */
#define LUALIB_API LUA_API
#define LUAMOD_API LUALIB_API
/*
@@ LUAI_FUNC is a mark for all extern functions that are not to be
** exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
** that are not to be exported to outside modules (LUAI_DDEF for
** definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
#else /* }{ */
#define LUAI_FUNC extern
#endif /* } */
#define LUAI_DDEC LUAI_FUNC
#define LUAI_DDEF /* empty */
/* }================================================================== */
/*
** {==================================================================
** Compatibility with previous versions
** ===================================================================
*/
/*
@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.
@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
#if defined(LUA_COMPAT_5_2) /* { */
/*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.
*/
#define LUA_COMPAT_MATHLIB
/*
@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.
*/
#define LUA_COMPAT_BITLIB
/*
@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.
*/
#define LUA_COMPAT_IPAIRS
/*
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
** luaL_checkint, luaL_checklong, etc.)
*/
#define LUA_COMPAT_APIINTCASTS
#endif /* } */
#if defined(LUA_COMPAT_5_1) /* { */
/* Incompatibilities from 5.2 -> 5.3 */
#define LUA_COMPAT_MATHLIB
#define LUA_COMPAT_APIINTCASTS
/*
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
** You can replace it with 'table.unpack'.
*/
#define LUA_COMPAT_UNPACK
/*
@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
** You can replace it with 'package.searchers'.
*/
#define LUA_COMPAT_LOADERS
/*
@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
** You can call your C function directly (with light C functions).
*/
#define lua_cpcall(L,f,u) \
(lua_pushcfunction(L, (f)), \
lua_pushlightuserdata(L,(u)), \
lua_pcall(L,1,0,0))
/*
@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
** You can rewrite 'log10(x)' as 'log(x, 10)'.
*/
#define LUA_COMPAT_LOG10
/*
@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
** library. You can rewrite 'loadstring(s)' as 'load(s)'.
*/
#define LUA_COMPAT_LOADSTRING
/*
@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
*/
#define LUA_COMPAT_MAXN
/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
*/
#define lua_strlen(L,i) lua_rawlen(L, (i))
#define lua_objlen(L,i) lua_rawlen(L, (i))
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
/*
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
*/
#define LUA_COMPAT_MODULE
#endif /* } */
/*
@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
@@ a float mark ('.0').
** This macro is not on by default even in compatibility mode,
** because this is not really an incompatibility.
*/
/* #define LUA_COMPAT_FLOATSTRING */
/* }================================================================== */
/*
** {==================================================================
** Configuration for Numbers.
** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
** satisfy your needs.
** ===================================================================
*/
/*
@@ LUA_NUMBER is the floating-point type used by Lua.
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@@ over a floating number.
@@ l_mathlim(x) corrects limit name 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL.
@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
@@ LUA_NUMBER_FMT is the format for writing floats.
@@ lua_number2str converts a float to a string.
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
@@ l_floor takes the floor of a float.
@@ lua_str2number converts a decimal numeric string to a number.
*/
/* The following definitions are good for most cases here */
#define l_floor(x) (l_mathop(floor)(x))
#define lua_number2str(s,sz,n) l_sprintf((s), sz, LUA_NUMBER_FMT, (n))
/*
@@ lua_numbertointeger converts a float number to an integer, or
** returns 0 if float is not within the range of a lua_Integer.
** (The range comparisons are tricky because of rounding. The tests
** here assume a two-complement representation, where MININTEGER always
** has an exact representation as a float; MAXINTEGER may not have one,
** and therefore its conversion to float may have an ill-defined value.)
*/
#define lua_numbertointeger(n,p) \
((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
(n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
(*(p) = (LUA_INTEGER)(n), 1))
/* now the variable definitions */
#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
#define LUA_NUMBER float
#define l_mathlim(n) (FLT_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.7g"
#define l_mathop(op) op##f
#define lua_str2number(s,p) strtof((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
#define LUA_NUMBER long double
#define l_mathlim(n) (LDBL_##n)
#define LUAI_UACNUMBER long double
#define LUA_NUMBER_FRMLEN "L"
#define LUA_NUMBER_FMT "%.19Lg"
#define l_mathop(op) op##l
#define lua_str2number(s,p) strtold((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
#define LUA_NUMBER double
#define l_mathlim(n) (DBL_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.14g"
#define l_mathop(op) op
#define lua_str2number(s,p) strtod((s), (p))
#else /* }{ */
#error "numeric float type not defined"
#endif /* } */
/*
@@ LUA_INTEGER is the integer type used by Lua.
**
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
**
@@ LUAI_UACINT is the result of an 'usual argument conversion'
@@ over a lUA_INTEGER.
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
@@ LUA_INTEGER_FMT is the format for writing integers.
@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
@@ lua_integer2str converts an integer to a string.
*/
/* The following definitions are good for most cases here */
#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
#define lua_integer2str(s,sz,n) l_sprintf((s), sz, LUA_INTEGER_FMT, (n))
#define LUAI_UACINT LUA_INTEGER
/*
** use LUAI_UACINT here to avoid problems with promotions (which
** can turn a comparison between unsigneds into a signed comparison)
*/
#define LUA_UNSIGNED unsigned LUAI_UACINT
/* now the variable definitions */
#if LUA_INT_TYPE == LUA_INT_INT /* { int */
#define LUA_INTEGER int
#define LUA_INTEGER_FRMLEN ""
#define LUA_MAXINTEGER INT_MAX
#define LUA_MININTEGER INT_MIN
#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
#define LUA_INTEGER long
#define LUA_INTEGER_FRMLEN "l"
#define LUA_MAXINTEGER LONG_MAX
#define LUA_MININTEGER LONG_MIN
#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
/* use presence of macro LLONG_MAX as proxy for C99 compliance */
#if defined(LLONG_MAX) /* { */
/* use ISO C99 stuff */
#define LUA_INTEGER long long
#define LUA_INTEGER_FRMLEN "ll"
#define LUA_MAXINTEGER LLONG_MAX
#define LUA_MININTEGER LLONG_MIN
#elif defined(LUA_USE_WINDOWS) /* }{ */
/* in Windows, can use specific Windows types */
#define LUA_INTEGER __int64
#define LUA_INTEGER_FRMLEN "I64"
#define LUA_MAXINTEGER _I64_MAX
#define LUA_MININTEGER _I64_MIN
#else /* }{ */
#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
#endif /* } */
#else /* }{ */
#error "numeric integer type not defined"
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Dependencies with C99 and other C details
** ===================================================================
*/
/*
@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
** (All uses in Lua have only one format item.)
*/
#if !defined(LUA_USE_C89)
#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
#else
#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
#endif
/*
@@ lua_strx2number converts an hexadecimal numeric string to a number.
** In C99, 'strtod' does that conversion. Otherwise, you can
** leave 'lua_strx2number' undefined and Lua will provide its own
** implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_strx2number(s,p) lua_str2number(s,p)
#endif
/*
@@ lua_number2strx converts a float to an hexadecimal numeric string.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
** provide its own implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_number2strx(L,b,sz,f,n) l_sprintf(b,sz,f,n)
#endif
/*
** 'strtof' and 'opf' variants for math functions are not valid in
** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
** availability of these variants. ('math.h' is already included in
** all files that use these macros.)
*/
#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
#undef l_mathop /* variants not available */
#undef lua_str2number
#define l_mathop(op) (lua_Number)op /* no variant */
#define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
#endif
/*
@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
** functions. It must be a numerical type; Lua will use 'intptr_t' if
** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
** 'intptr_t' in C89)
*/
#define LUA_KCONTEXT ptrdiff_t
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 199901L
#include <stdint.h>
#if defined(INTPTR_MAX) /* even in C99 this type is optional */
#undef LUA_KCONTEXT
#define LUA_KCONTEXT intptr_t
#endif
#endif
/*
@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
** Change that if you do not want to use C locales. (Code using this
** macro must include header 'locale.h'.)
*/
#if !defined(lua_getlocaledecpoint)
#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
#endif
/* }================================================================== */
/*
** {==================================================================
** Language Variations
** =====================================================================
*/
/*
@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
** coercion from strings to numbers.
*/
/* #define LUA_NOCVTN2S */
/* #define LUA_NOCVTS2N */
/*
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
** Define it as a help when debugging C code.
*/
#if defined(LUA_USE_APICHECK)
#include <assert.h>
#define luai_apicheck(l,e) assert(e)
#endif
/* }================================================================== */
/*
** {==================================================================
** Macros that affect the API and must be stable (that is, must be the
** same when you compile Lua and when you compile code that links to
** Lua). You probably do not want/need to change them.
** =====================================================================
*/
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
*/
#if LUAI_BITSINT >= 32
#define LUAI_MAXSTACK 1000000
#else
#define LUAI_MAXSTACK 15000
#endif
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
#define LUA_EXTRASPACE (sizeof(void *))
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
#define LUA_IDSIZE 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** CHANGE it if it uses too much C-stack space. (For long double,
** 'string.format("%.99f", 1e4932)' needs ~5030 bytes, so a
** smaller buffer would force a memory allocation for each call to
** 'string.format'.)
*/
#if defined(LUA_FLOAT_LONGDOUBLE)
#define LUAL_BUFFERSIZE 8192
#else
#define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
#endif
/* }================================================================== */
/*
@@ LUA_QL describes how error messages quote program elements.
** Lua does not use these macros anymore; they are here for
** compatibility only.
*/
#define LUA_QL(x) "'" x "'"
#define LUA_QS LUA_QL("%s")
/* =================================================================== */
/*
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
*/
#endif

View file

@ -1,58 +0,0 @@
/*
** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
#ifndef lualib_h
#define lualib_h
#include "lua.h"
LUAMOD_API int (luaopen_base) (lua_State *L);
#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io"
LUAMOD_API int (luaopen_io) (lua_State *L);
#define LUA_OSLIBNAME "os"
LUAMOD_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string"
LUAMOD_API int (luaopen_string) (lua_State *L);
#define LUA_UTF8LIBNAME "utf8"
LUAMOD_API int (luaopen_utf8) (lua_State *L);
#define LUA_BITLIBNAME "bit32"
LUAMOD_API int (luaopen_bit32) (lua_State *L);
#define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L);
#define LUA_DBLIBNAME "debug"
LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
#if !defined(lua_assert)
#define lua_assert(x) ((void)0)
#endif
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

167
external/luajit/include/lauxlib.h vendored Normal file
View file

@ -0,0 +1,167 @@
/*
** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#include <stddef.h>
#include <stdio.h>
#include "lua.h"
#define luaL_getn(L,i) ((int)lua_objlen(L, i))
#define luaL_setn(L,i,j) ((void)0) /* no op! */
/* extra error code for `luaL_load' */
#define LUA_ERRFILE (LUA_ERRERR+1)
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
const luaL_Reg *l);
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
lua_Integer def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
const char *const lst[]);
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
const char *name);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
const char *fname, int szhint);
/* From Lua 5.2. */
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname);
LUALIB_API int luaL_execresult(lua_State *L, int stat);
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
const char *mode);
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
int level);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_argcheck(L, cond,numarg,extramsg) \
((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
typedef struct luaL_Buffer {
char *p; /* current position in buffer */
int lvl; /* number of strings in the stack (level) */
lua_State *L;
char buffer[LUAL_BUFFERSIZE];
} luaL_Buffer;
#define luaL_addchar(B,c) \
((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
(*(B)->p++ = (char)(c)))
/* compatibility only */
#define luaL_putchar(B,c) luaL_addchar(B,c)
#define luaL_addsize(B,n) ((B)->p += (n))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
/* }====================================================== */
/* compatibility with ref system */
/* pre-defined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
(lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
#define luaL_reg luaL_Reg
#endif

393
external/luajit/include/lua.h vendored Normal file
View file

@ -0,0 +1,393 @@
/*
** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"
#define LUA_VERSION "Lua 5.1"
#define LUA_RELEASE "Lua 5.1.4"
#define LUA_VERSION_NUM 501
#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
/* mark for precompiled code (`<esc>Lua') */
#define LUA_SIGNATURE "\033Lua"
/* option for multiple returns in `lua_pcall' and `lua_call' */
#define LUA_MULTRET (-1)
/*
** pseudo-indices
*/
#define LUA_REGISTRYINDEX (-10000)
#define LUA_ENVIRONINDEX (-10001)
#define LUA_GLOBALSINDEX (-10002)
#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
/* thread status; 0 is OK */
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRERR 5
typedef struct lua_State lua_State;
typedef int (*lua_CFunction) (lua_State *L);
/*
** functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
/*
** prototype for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
/*
** basic stack manipulation
*/
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_remove) (lua_State *L, int idx);
LUA_API void (lua_insert) (lua_State *L, int idx);
LUA_API void (lua_replace) (lua_State *L, int idx);
LUA_API int (lua_checkstack) (lua_State *L, int sz);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_objlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
LUA_API void (lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API void (lua_gettable) (lua_State *L, int idx);
LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_rawget) (lua_State *L, int idx);
LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API void (lua_getfenv) (lua_State *L, int idx);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API int (lua_setfenv) (lua_State *L, int idx);
/*
** `load' and `call' functions (load and run Lua code)
*/
LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
/*
** coroutine functions
*/
LUA_API int (lua_yield) (lua_State *L, int nresults);
LUA_API int (lua_resume) (lua_State *L, int narg);
LUA_API int (lua_status) (lua_State *L);
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
LUA_API int (lua_gc) (lua_State *L, int what, int data);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_strlen(L,i) lua_objlen(L, (i))
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) \
lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
/*
** compatibility macros and functions
*/
#define lua_open() luaL_newstate()
#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
#define lua_Chunkreader lua_Reader
#define lua_Chunkwriter lua_Writer
/* hack */
LUA_API void lua_setlevel (lua_State *from, lua_State *to);
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILRET 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
/* Functions to be called by the debuger in specific events */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook lua_gethook (lua_State *L);
LUA_API int lua_gethookmask (lua_State *L);
LUA_API int lua_gethookcount (lua_State *L);
/* From Lua 5.2. */
LUA_API void *lua_upvalueid (lua_State *L, int idx, int n);
LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2);
LUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname, const char *mode);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) `global', `local', `field', `method' */
const char *what; /* (S) `Lua', `C', `main', `tail' */
const char *source; /* (S) */
int currentline; /* (l) */
int nups; /* (u) number of upvalues */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
int i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#endif

9
external/luajit/include/lua.hpp vendored Normal file
View file

@ -0,0 +1,9 @@
// C++ wrapper for LuaJIT header files.
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "luajit.h"
}

156
external/luajit/include/luaconf.h vendored Normal file
View file

@ -0,0 +1,156 @@
/*
** Configuration header.
** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
*/
#ifndef luaconf_h
#define luaconf_h
#ifndef WINVER
#define WINVER 0x0501
#endif
#include <limits.h>
#include <stddef.h>
/* Default path for loading Lua and C modules with require(). */
#if defined(_WIN32)
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_PATH_DEFAULT \
".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;"
#define LUA_CPATH_DEFAULT \
".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
#else
/*
** Note to distribution maintainers: do NOT patch the following lines!
** Please read ../doc/install.html#distro and pass PREFIX=/usr instead.
*/
#ifndef LUA_MULTILIB
#define LUA_MULTILIB "lib"
#endif
#ifndef LUA_LMULTILIB
#define LUA_LMULTILIB "lib"
#endif
#define LUA_LROOT "/usr/local"
#define LUA_LUADIR "/lua/5.1/"
#define LUA_LJDIR "/luajit-2.0.5/"
#ifdef LUA_ROOT
#define LUA_JROOT LUA_ROOT
#define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR
#define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR
#define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua"
#define LUA_RCPATH ";" LUA_RCDIR "?.so"
#else
#define LUA_JROOT LUA_LROOT
#define LUA_RLPATH
#define LUA_RCPATH
#endif
#define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua"
#define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR
#define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR
#define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua"
#define LUA_LCPATH1 ";" LUA_LCDIR "?.so"
#define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so"
#define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH
#define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2
#endif
/* Environment variable names for path overrides and initialization code. */
#define LUA_PATH "LUA_PATH"
#define LUA_CPATH "LUA_CPATH"
#define LUA_INIT "LUA_INIT"
/* Special file system characters. */
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
#define LUA_PATHSEP ";"
#define LUA_PATH_MARK "?"
#define LUA_EXECDIR "!"
#define LUA_IGMARK "-"
#define LUA_PATH_CONFIG \
LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \
LUA_EXECDIR "\n" LUA_IGMARK
/* Quoting in error messages. */
#define LUA_QL(x) "'" x "'"
#define LUA_QS LUA_QL("%s")
/* Various tunables. */
#define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */
#define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */
#define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */
#define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */
#define LUA_MAXCAPTURES 32 /* Max. pattern captures. */
/* Compatibility with older library function names. */
#define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */
#define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */
/* Configuration for the frontend (the luajit executable). */
#if defined(luajit_c)
#define LUA_PROGNAME "luajit" /* Fallback frontend name. */
#define LUA_PROMPT "> " /* Interactive prompt. */
#define LUA_PROMPT2 ">> " /* Continuation prompt. */
#define LUA_MAXINPUT 512 /* Max. input line length. */
#endif
/* Note: changing the following defines breaks the Lua 5.1 ABI. */
#define LUA_INTEGER ptrdiff_t
#define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */
/*
** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using
** unreasonable amounts of stack space, but still retain ABI compatibility.
** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it.
*/
#define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ)
/* The following defines are here only for compatibility with luaconf.h
** from the standard Lua distribution. They must not be changed for LuaJIT.
*/
#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER double
#define LUAI_UACNUMBER double
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32
#define LUA_INTFRMLEN "l"
#define LUA_INTFRM_T long
/* Linkage of public API functions. */
#if defined(LUA_BUILD_AS_DLL)
#if defined(LUA_CORE) || defined(LUA_LIB)
#define LUA_API __declspec(dllexport)
#else
#define LUA_API __declspec(dllimport)
#endif
#else
#define LUA_API extern
#endif
#define LUALIB_API LUA_API
/* Support for internal assertions. */
#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)
#include <assert.h>
#endif
#ifdef LUA_USE_ASSERT
#define lua_assert(x) assert(x)
#endif
#ifdef LUA_USE_APICHECK
#define luai_apicheck(L, o) { (void)L; assert(o); }
#else
#define luai_apicheck(L, o) { (void)L; }
#endif
#endif

70
external/luajit/include/luajit.h vendored Normal file
View file

@ -0,0 +1,70 @@
/*
** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/
**
** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
*/
#ifndef _LUAJIT_H
#define _LUAJIT_H
#include "lua.h"
#define LUAJIT_VERSION "LuaJIT 2.0.5"
#define LUAJIT_VERSION_NUM 20005 /* Version 2.0.5 = 02.00.05. */
#define LUAJIT_VERSION_SYM luaJIT_version_2_0_5
#define LUAJIT_COPYRIGHT "Copyright (C) 2005-2017 Mike Pall"
#define LUAJIT_URL "http://luajit.org/"
/* Modes for luaJIT_setmode. */
#define LUAJIT_MODE_MASK 0x00ff
enum {
LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */
LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */
LUAJIT_MODE_FUNC, /* Change mode for a function. */
LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */
LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */
LUAJIT_MODE_TRACE, /* Flush a compiled trace. */
LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */
LUAJIT_MODE_MAX
};
/* Flags or'ed in to the mode. */
#define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */
#define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */
#define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */
/* LuaJIT public C API. */
/* Control the JIT engine. */
LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
/* Enforce (dynamic) linker error for version mismatches. Call from main. */
LUA_API void LUAJIT_VERSION_SYM(void);
#endif

43
external/luajit/include/lualib.h vendored Normal file
View file

@ -0,0 +1,43 @@
/*
** Standard library header.
** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
*/
#ifndef _LUALIB_H
#define _LUALIB_H
#include "lua.h"
#define LUA_FILEHANDLE "FILE*"
#define LUA_COLIBNAME "coroutine"
#define LUA_MATHLIBNAME "math"
#define LUA_STRLIBNAME "string"
#define LUA_TABLIBNAME "table"
#define LUA_IOLIBNAME "io"
#define LUA_OSLIBNAME "os"
#define LUA_LOADLIBNAME "package"
#define LUA_DBLIBNAME "debug"
#define LUA_BITLIBNAME "bit"
#define LUA_JITLIBNAME "jit"
#define LUA_FFILIBNAME "ffi"
LUALIB_API int luaopen_base(lua_State *L);
LUALIB_API int luaopen_math(lua_State *L);
LUALIB_API int luaopen_string(lua_State *L);
LUALIB_API int luaopen_table(lua_State *L);
LUALIB_API int luaopen_io(lua_State *L);
LUALIB_API int luaopen_os(lua_State *L);
LUALIB_API int luaopen_package(lua_State *L);
LUALIB_API int luaopen_debug(lua_State *L);
LUALIB_API int luaopen_bit(lua_State *L);
LUALIB_API int luaopen_jit(lua_State *L);
LUALIB_API int luaopen_ffi(lua_State *L);
LUALIB_API void luaL_openlibs(lua_State *L);
#ifndef lua_assert
#define lua_assert(x) ((void)0)
#endif
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -336,13 +336,13 @@ end
function useLua()
if _OPTIONS["static-plugins"] then
linkLib("lua")
linkLib "luajit"
else
configuration { "windows" }
defines { "LUA_BUILD_AS_DLL" }
configuration {}
end
includedirs { "../external/lua/include" }
includedirs { "../external/luajit/include" }
end
function copyDlls(src_dir, platform_dir, dest_dir)
@ -593,9 +593,9 @@ project "engine"
end
defines { "BUILDING_ENGINE" }
includedirs { "../external/lua/include" }
includedirs { "../external/luajit/include" }
linkLib "lua"
linkLib "luajit"
configuration { "vs20*" }
if not _OPTIONS["static-plugins"] then
@ -611,7 +611,7 @@ if has_plugin("physics") then
files { "../src/physics/**.h", "../src/physics/**.cpp" }
includedirs { "../external/physx/include/", "../external/bgfx/include" }
includedirs { "../external/physx/include/" }
defines { "BUILDING_PHYSICS" }
links { "engine", "editor", "renderer" }
useLua()
@ -626,17 +626,16 @@ if has_plugin("renderer") then
libType()
files { "../src/renderer/**.h", "../src/renderer/**.cpp", "../src/renderer/**.c"}
includedirs { "../src", "../external/bgfx/include", "../external/cmft/include", "../external/crnlib/include" }
includedirs { "../src", "../external/cmft/include", "../external/crnlib/include" }
defines { "BUILDING_RENDERER" }
links { "engine" }
if build_studio then
links { "editor", "shaderc" }
links { "editor" }
linkLib "crnlib"
linkLib "cmft"
end
links { "opengl32" }
linkLib "bgfx"
configuration { "linux-*" }
links { "GL", "X11" }
configuration {}
@ -654,7 +653,6 @@ if has_plugin("animation") then
files { "../src/animation/**.h", "../src/animation/**.cpp" }
includedirs { "../src" }
includedirs { "../external/bgfx/include" }
defines { "BUILDING_ANIMATION" }
links { "engine", "renderer" }
@ -680,7 +678,7 @@ if build_steam then
"../src/steam/**.cpp",
"../src/steam/**.h"
}
includedirs { "../src", "../src/steam", "../../steamworks_sdk/public/steam", "../external/bgfx/include" }
includedirs { "../src", "../src/steam", "../../steamworks_sdk/public/steam" }
libdirs { "../../steamworks_sdk/redistributable_bin/win64" }
defines { "BUILDING_STEAM" }
links { "engine", "steam_api64" }
@ -697,7 +695,7 @@ if has_plugin("audio") then
"../src/audio/**.cpp",
"../external/stb/stb_vorbis.cpp"
}
includedirs { "../src", "../src/audio", "../external/bgfx/include" }
includedirs { "../src", "../src/audio" }
defines { "BUILDING_AUDIO" }
links { "engine" }
@ -719,7 +717,6 @@ if has_plugin("navigation") then
files { "../src/navigation/**.h", "../src/navigation/**.cpp", "../external/recast/src/**.cpp" }
includedirs { "../src", "../src/navigation", "../external/recast/include" }
includedirs { "../external/bgfx/include" }
links { "engine", "renderer" }
linkLib "recast"
@ -736,9 +733,8 @@ if has_plugin("gui") then
libType()
files { "../src/gui/**.h", "../src/gui/**.cpp" }
includedirs { "../src", "../src/gui", "../external/bgfx/include" }
includedirs { "../src", "../src/gui" }
links { "engine", "renderer" }
linkLib "bgfx"
defines { "BUILDING_GUI" }
@ -759,7 +755,7 @@ if has_plugin("lua_script") then
libType()
files { "../src/lua_script/**.h", "../src/lua_script/**.cpp" }
includedirs { "../src", "../src/lua_script", "../external/bgfx/include" }
includedirs { "../src", "../src/lua_script" }
defines { "BUILDING_LUA_SCRIPT" }
links { "engine", "renderer" }
@ -777,13 +773,12 @@ if build_unit_tests then
debugdir "../../LumixEngine_data"
files { "../src/unit_tests/**.h", "../src/unit_tests/**.cpp" }
includedirs { "../src", "../src/unit_tests", "../external/bgfx/include" }
includedirs { "../src", "../src/unit_tests" }
links { "animation", "engine", "renderer" }
if _OPTIONS["static-plugins"] then
configuration { "vs*" }
links { "winmm", "psapi" }
configuration {}
linkLib "bgfx"
end
useLua()
@ -814,7 +809,7 @@ if build_app then
defines { "LUMIXENGINE_PLUGINS=" .. def }
end
includedirs { "../src", "../src/app", "../external/bgfx/include" }
includedirs { "../src", "../src/app" }
if _OPTIONS["static-plugins"] then
for _, plugin in ipairs(plugins) do
forceLink ("s_" .. plugin .. "_plugin_register")
@ -851,11 +846,9 @@ if build_app then
if build_studio then
linkLib "crnlib"
linkLib "cmft"
links {"shaderc"}
end
linkLib "bgfx"
linkLib "lua"
linkLib "luajit"
linkLib "recast"
files { "../src/app/main.cpp" }
@ -965,11 +958,10 @@ if build_studio then
links { "editor", "engine", "shaderc" }
links { "editor", "engine" }
linkLib "crnlib"
linkLib "cmft"
linkLib "bgfx"
linkLib "lua"
linkLib "luajit"
linkLib "recast"
if has_plugin("renderer") then

View file

@ -400,9 +400,12 @@ void AssetBrowser::thumbnail(FileInfo& tile)
{
ImGui::BeginGroup();
ImVec2 img_size((float)TILE_SIZE, (float)TILE_SIZE);
RenderInterface* ri = m_app.getWorldEditor().getRenderInterface();
if (tile.tex)
{
ImGui::Image(tile.tex, img_size);
if(ri->isValid(tile.tex)) {
ImGui::Image(tile.tex, img_size);
}
}
else
{
@ -410,7 +413,6 @@ void AssetBrowser::thumbnail(FileInfo& tile)
StaticString<MAX_PATH_LENGTH> path(".lumix/asset_tiles/", tile.file_path_hash, ".dds");
if (PlatformInterface::fileExists(path))
{
RenderInterface* ri = m_app.getWorldEditor().getRenderInterface();
if (PlatformInterface::getLastModified(path) >= PlatformInterface::getLastModified(tile.filepath))
{
tile.tex = ri->loadTexture(Path(path));

View file

@ -217,7 +217,7 @@ struct GizmoImpl LUMIX_FINAL : public Gizmo
Vec3 intersection = getMousePlaneIntersection(m_editor.getMousePos(), gizmo_mtx, m_transform_axis);
Vec3 delta_vec = intersection - m_start_axis_point;
Vec2 p = ri->worldToScreenPixels(entity_pos);
Vec2 p = ri->worldToScreenPixels(m_editor.getEditCamera().entity, entity_pos);
StaticString<128> tmp("", delta_vec.x, "; ", delta_vec.y, "; ", delta_vec.z);
ri->addText2D(p.x + 31, p.y + 31, 16, 0xff000000, tmp);
ri->addText2D(p.x + 30, p.y + 30, 16, 0xffffFFFF, tmp);
@ -477,7 +477,7 @@ struct GizmoImpl LUMIX_FINAL : public Gizmo
Vec3 origin = (m_start_plane_point - entity_pos).normalized();
renderArc(entity_pos, n * scale, origin * scale, m_angle_accum, 0x8800a5ff);
float angle_degrees = Math::radiansToDegrees(m_angle_accum);
Vec2 p = ri->worldToScreenPixels(entity_pos);
Vec2 p = ri->worldToScreenPixels(m_editor.getEditCamera().entity, entity_pos);
StaticString<128> tmp("", angle_degrees, " deg");
Vec2 screen_delta = (m_start_mouse_pos - p).normalized();
Vec2 text_pos = m_start_mouse_pos + screen_delta * 15;

View file

@ -48,6 +48,7 @@ public:
virtual ImTextureID createTexture(const char* name, const void* pixels, int w, int h) = 0;
virtual void destroyTexture(ImTextureID handle) = 0;
virtual ImTextureID loadTexture(const Path& path) = 0;
virtual bool isValid(ImTextureID texture) = 0;
virtual void unloadTexture(ImTextureID handle) = 0;
virtual void addDebugCube(const Vec3& minimum, const Vec3& maximum, u32 color, float life) = 0;
virtual void addDebugCross(const Vec3& pos, float size, u32 color, float life) = 0;
@ -67,7 +68,7 @@ public:
virtual void addRectFilled2D(const Vec2& a, const Vec2& b, u32 color) = 0;
virtual void getModelInstaces(Array<Entity>& entity, const Frustum& frustum, const Vec3& lod_ref_point, Entity camera) = 0;
virtual Frustum getFrustum(Entity camera, const Vec2& a, const Vec2& b) = 0;
virtual Vec2 worldToScreenPixels(const Vec3& world) = 0;
virtual Vec2 worldToScreenPixels(Entity camera, const Vec3& world) = 0;
};

View file

@ -22,18 +22,24 @@ static const char SETTINGS_PATH[] = "studio.ini";
static void loadStyle(lua_State* L)
{
if (lua_getglobal(L, "style") == LUA_TTABLE)
lua_getglobal(L, "style");
if (lua_type(L, -1) == LUA_TTABLE)
{
auto& style = ImGui::GetStyle();
for (int i = 0; i < ImGuiCol_COUNT; ++i)
{
const char* name = ImGui::GetStyleColorName(i);
if (lua_getfield(L, -1, name) == LUA_TTABLE)
lua_getfield(L, -1, name);
if (lua_type(L, -1) == LUA_TTABLE)
{
if (lua_rawgeti(L, -1, 1) == LUA_TNUMBER) style.Colors[i].x = (float)lua_tonumber(L, -1);
if (lua_rawgeti(L, -2, 2) == LUA_TNUMBER) style.Colors[i].y = (float)lua_tonumber(L, -1);
if (lua_rawgeti(L, -3, 3) == LUA_TNUMBER) style.Colors[i].z = (float)lua_tonumber(L, -1);
if (lua_rawgeti(L, -4, 4) == LUA_TNUMBER) style.Colors[i].w = (float)lua_tonumber(L, -1);
lua_rawgeti(L, -1, 1);
if (lua_type(L, -1) == LUA_TNUMBER) style.Colors[i].x = (float)lua_tonumber(L, -1);
lua_rawgeti(L, -2, 2);
if (lua_type(L, -1) == LUA_TNUMBER) style.Colors[i].y = (float)lua_tonumber(L, -1);
lua_rawgeti(L, -3, 3);
if (lua_type(L, -1) == LUA_TNUMBER) style.Colors[i].z = (float)lua_tonumber(L, -1);
lua_rawgeti(L, -4, 4);
if (lua_type(L, -1) == LUA_TNUMBER) style.Colors[i].w = (float)lua_tonumber(L, -1);
lua_pop(L, 4);
}
lua_pop(L, 1);
@ -87,7 +93,8 @@ static void shortcutInput(int& shortcut)
static int getIntegerField(lua_State* L, const char* name, int default_value)
{
int value = default_value;
if (lua_getfield(L, -1, name) == LUA_TNUMBER)
lua_getfield(L, -1, name);
if (lua_type(L, -1) == LUA_TNUMBER)
{
value = (int)lua_tointeger(L, -1);
}
@ -99,7 +106,8 @@ static int getIntegerField(lua_State* L, const char* name, int default_value)
static float getFloat(lua_State* L, const char* name, float default_value)
{
float value = default_value;
if (lua_getglobal(L, name) == LUA_TNUMBER)
lua_getglobal(L, name);
if (lua_type(L, -1) == LUA_TNUMBER)
{
value = (float)lua_tonumber(L, -1);
}
@ -111,7 +119,8 @@ static float getFloat(lua_State* L, const char* name, float default_value)
static bool getBoolean(lua_State* L, const char* name, bool default_value)
{
bool value = default_value;
if (lua_getglobal(L, name) == LUA_TBOOLEAN)
lua_getglobal(L, name);
if (lua_type(L, -1) == LUA_TBOOLEAN)
{
value = lua_toboolean(L, -1) != 0;
}
@ -123,7 +132,8 @@ static bool getBoolean(lua_State* L, const char* name, bool default_value)
static int getInteger(lua_State* L, const char* name, int default_value)
{
int value = default_value;
if (lua_getglobal(L, name) == LUA_TNUMBER)
lua_getglobal(L, name);
if (lua_type(L, -1) == LUA_TNUMBER)
{
value = (int)lua_tointeger(L, -1);
}
@ -170,8 +180,8 @@ bool Settings::load()
{
auto L = m_state;
bool has_settings = PlatformInterface::fileExists(SETTINGS_PATH);
bool errors = luaL_loadfile(L, has_settings ? SETTINGS_PATH : DEFAULT_SETTINGS_PATH) != LUA_OK;
errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK;
bool errors = luaL_loadfile(L, has_settings ? SETTINGS_PATH : DEFAULT_SETTINGS_PATH) != 0;
errors = errors || lua_pcall(L, 0, 0, 0) != 0;
if (errors)
{
g_log_error.log("Editor") << SETTINGS_PATH << ": " << lua_tostring(L, -1);
@ -179,7 +189,8 @@ bool Settings::load()
return false;
}
if (lua_getglobal(L, "window") == LUA_TTABLE)
lua_getglobal(L, "window");
if (lua_type(L, -1) == LUA_TTABLE)
{
m_window.x = getIntegerField(L, "x", 0);
m_window.y = getIntegerField(L, "y", 0);
@ -208,21 +219,25 @@ bool Settings::load()
if (!m_editor->getEngine().getPatchFileDevice())
{
if (lua_getglobal(L, "data_dir") == LUA_TSTRING) copyString(m_data_dir, lua_tostring(L, -1));
lua_getglobal(L, "data_dir");
if (lua_type(L, -1) == LUA_TSTRING) copyString(m_data_dir, lua_tostring(L, -1));
lua_pop(L, 1);
m_editor->getEngine().setPatchPath(m_data_dir);
}
auto& actions = m_app.getActions();
if (lua_getglobal(L, "actions") == LUA_TTABLE)
lua_getglobal(L, "actions");
if (lua_type(L, -1) == LUA_TTABLE)
{
for (int i = 0; i < actions.size(); ++i)
{
if (lua_getfield(L, -1, actions[i]->name) == LUA_TTABLE)
lua_getfield(L, -1, actions[i]->name);
if (lua_type(L, -1) == LUA_TTABLE)
{
for (int j = 0; j < lengthOf(actions[i]->shortcut); ++j)
{
if (lua_rawgeti(L, -1, 1 + j) == LUA_TNUMBER)
lua_rawgeti(L, -1, 1 + j);
if (lua_type(L, -1) == LUA_TNUMBER)
{
actions[i]->shortcut[j] = (int)lua_tointeger(L, -1);
}
@ -235,12 +250,14 @@ bool Settings::load()
lua_pop(L, 1);
m_app.getToolbarActions().clear();
if (lua_getglobal(L, "toolbar") == LUA_TTABLE)
lua_getglobal(L, "toolbar");
if (lua_type(L, -1) == LUA_TTABLE)
{
int len = (int)lua_rawlen(L, -1);
int len = (int)lua_objlen(L, -1);
for (int i = 0; i < len; ++i)
{
if (lua_rawgeti(L, -1, i + 1) == LUA_TSTRING)
lua_rawgeti(L, -1, i + 1);
if (lua_type(L, -1) == LUA_TSTRING)
{
const char* action_name = lua_tostring(L, -1);
Action* action = m_app.getAction(action_name);
@ -287,7 +304,8 @@ bool Settings::getValue(const char* name, bool default_value) const
{
bool v = default_value;
lua_getglobal(m_state, "custom");
if (lua_getfield(m_state, -1, name) == LUA_TBOOLEAN)
lua_getfield(m_state, -1, name);
if (lua_type(m_state, -1) == LUA_TBOOLEAN)
{
v = lua_toboolean(m_state, -1) != 0;
}

View file

@ -61,15 +61,15 @@ struct LuaPlugin : public StudioApp::GUIPlugin
// environment's metatable & __index
lua_pushvalue(L, -1); // [env, env]
lua_setmetatable(L, -2); // [env]
lua_pushglobaltable(L); // [evn, _G]
lua_pushvalue(L, LUA_GLOBALSINDEX);
lua_setfield(L, -2, "__index"); // [env]
bool errors = luaL_loadbuffer(L, src, stringLength(src), filename) != LUA_OK; // [env, func]
bool errors = luaL_loadbuffer(L, src, stringLength(src), filename) != 0; // [env, func]
lua_pushvalue(L, -2); // [env, func, env]
lua_setupvalue(L, -2, 1); // function's environment [env, func]
lua_setfenv(L, -2); // function's environment [env, func]
errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK; // [env]
errors = errors || lua_pcall(L, 0, 0, 0) != 0; // [env]
if (errors)
{
g_log_error.log("Editor") << filename << ": " << lua_tostring(L, -1);
@ -78,7 +78,8 @@ struct LuaPlugin : public StudioApp::GUIPlugin
lua_pop(L, 1); // []
const char* name = "LuaPlugin";
if (lua_getglobal(L, "plugin_name") == LUA_TSTRING)
lua_getglobal(L, "plugin_name");
if (lua_type(L, -1) == LUA_TSTRING)
{
name = lua_tostring(L, -1);
}
@ -112,9 +113,10 @@ struct LuaPlugin : public StudioApp::GUIPlugin
void onWindowGUI() override
{
if (!m_is_open) return;
if (lua_getglobal(L, "onGUI") == LUA_TFUNCTION)
lua_getglobal(L, "onGUI");
if (lua_type(L, -1) == LUA_TFUNCTION)
{
if (lua_pcall(L, 0, 0, 0) != LUA_OK)
if (lua_pcall(L, 0, 0, 0) != 0)
{
g_log_error.log("Editor") << "LuaPlugin:" << lua_tostring(L, -1);
lua_pop(L, 1);
@ -181,7 +183,7 @@ public:
m_engine = Engine::create(current_dir, data_dir_path, nullptr, m_allocator);
createLua();
ffr_preinit();
ffr::preinit();
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
m_window = SDL_CreateWindow("Lumix Studio", 0, 0, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
@ -1823,8 +1825,8 @@ public:
{
lua_State* L = m_engine->getState();
bool errors =
luaL_loadbuffer(L, src, stringLength(src), script_name) != LUA_OK;
errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK;
luaL_loadbuffer(L, src, stringLength(src), script_name) != 0;
errors = errors || lua_pcall(L, 0, 0, 0) != 0;
if (errors)
{
g_log_error.log("Editor") << script_name << ": " << lua_tostring(L, -1);
@ -1880,7 +1882,7 @@ public:
void visit(const Reflection::Property<int>& prop) override
{
if (!equalStrings(property_name, prop.name)) return;
if (!lua_isinteger(L, -1)) return;
if (!lua_isnumber(L, -1)) return;
int val = (int)lua_tointeger(L, -1);
editor->setProperty(cmp.type, 0, prop, &cmp.entity, 1, &val, sizeof(val));

View file

@ -474,7 +474,7 @@ public:
g_log_error.getCallback().bind<showLogInVS>();
m_platform_data = {};
m_state = lua_newstate(luaAllocator, &m_allocator);
m_state = luaL_newstate();
luaL_openlibs(m_state);
registerLuaAPI();
@ -587,7 +587,7 @@ public:
void visit(const Reflection::Property<int>& prop) override
{
if (!equalStrings(property_name, prop.name)) return;
if (lua_isinteger(L, -1))
if (lua_isnumber(L, -1))
{
int i = (int)lua_tointeger(L, -1);
InputBlob input_blob(&i, sizeof(i));
@ -600,7 +600,7 @@ public:
void visit(const Reflection::Property<Entity>& prop) override
{
if (!equalStrings(property_name, prop.name)) return;
if (lua_isinteger(L, -1))
if (lua_isnumber(L, -1))
{
int i = (int)lua_tointeger(L, -1);
InputBlob input_blob(&i, sizeof(i));
@ -745,7 +745,8 @@ public:
Entity e = ctx->createEntity(Vec3(0, 0, 0), Quat(0, 0, 0, 1));
lua_pushvalue(L, 3);
if (lua_getfield(L, -1, "parent") != LUA_TNIL)
lua_getfield(L, -1, "parent");
if (lua_type(L, -1) != LUA_TNIL)
{
Entity parent = LuaWrapper::toType<Entity>(L, -1);
ctx->setParent(parent, e);
@ -913,12 +914,13 @@ public:
}
else
{
if (lua_rawgeti(L, LUA_REGISTRYINDEX, lua_func) != LUA_TFUNCTION)
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_func);
if (lua_type(L, -1) != LUA_TFUNCTION)
{
ASSERT(false);
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK)
if (lua_pcall(L, 0, 0, 0) != 0)
{
g_log_error.log("Engine") << lua_tostring(L, -1);
lua_pop(L, 1);
@ -1159,12 +1161,14 @@ public:
void installLuaPackageLoader() const
{
if (lua_getglobal(m_state, "package") != LUA_TTABLE)
lua_getglobal(m_state, "package");
if (lua_type(m_state, -1) != LUA_TTABLE)
{
g_log_error.log("Engine") << "Lua \"package\" is not a table";
return;
}
if (lua_getfield(m_state, -1, "searchers") != LUA_TTABLE)
lua_getfield(m_state, -1, "searchers");
if (lua_type(m_state, -1) != LUA_TTABLE)
{
g_log_error.log("Engine") << "Lua \"package.searchers\" is not a table";
return;
@ -1201,7 +1205,7 @@ public:
msg << tmp;
lua_pushstring(L, msg);
}
else if (luaL_loadbuffer(L, (const char*)file->getBuffer(), file->size(), tmp) != LUA_OK)
else if (luaL_loadbuffer(L, (const char*)file->getBuffer(), file->size(), tmp) != 0)
{
g_log_error.log("Engine") << "Failed to load package " << tmp << ": " << lua_tostring(L, -1);
}
@ -1209,24 +1213,7 @@ public:
return 1;
}
static void* luaAllocator(void* ud, void* ptr, size_t osize, size_t nsize)
{
auto& allocator = *static_cast<IAllocator*>(ud);
if (nsize == 0)
{
allocator.deallocate(ptr);
return nullptr;
}
if (nsize > 0 && ptr == nullptr) return allocator.allocate(nsize);
void* new_mem = allocator.allocate(nsize);
copyMemory(new_mem, ptr, Math::minimum(osize, nsize));
allocator.deallocate(ptr);
return new_mem;
}
~EngineImpl()
{
for (Resource* res : m_lua_resources)
@ -1645,14 +1632,14 @@ public:
void runScript(const char* src, int src_length, const char* path) override
{
if (luaL_loadbuffer(m_state, src, src_length, path) != LUA_OK)
if (luaL_loadbuffer(m_state, src, src_length, path) != 0)
{
g_log_error.log("Engine") << path << ": " << lua_tostring(m_state, -1);
lua_pop(m_state, 1);
return;
}
if (lua_pcall(m_state, 0, 0, 0) != LUA_OK)
if (lua_pcall(m_state, 0, 0, 0) != 0)
{
g_log_error.log("Engine") << path << ": " << lua_tostring(m_state, -1);
lua_pop(m_state, 1);

View file

@ -13,6 +13,31 @@ namespace Lumix
namespace LuaWrapper
{
inline bool execute(lua_State* L
, StringView content
, const char* name
, int nresults)
{
if (luaL_loadbuffer(L, content.begin, content.length(), name) != 0) {
g_log_error.log("Engine") << name << ": " << lua_tostring(L, -1);
lua_pop(L, 1);
return false;
}
if (lua_pcall(L, 0, nresults, 0) != 0)
{
g_log_error.log("Engine") << name << ": " << lua_tostring(L, -1);
lua_pop(L, 1);
return false;
}
return true;
}
inline int getField(lua_State* L, int idx, const char* k)
{
lua_getfield(L, idx, k);
return lua_type(L, -1);
}
template <typename T> inline T toType(lua_State* L, int index)
{
@ -190,51 +215,51 @@ template <typename T> inline bool isType(lua_State* L, int index)
}
template <> inline bool isType<int>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
return lua_isnumber(L, index) != 0;
}
template <> inline bool isType<u16>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
return lua_isnumber(L, index) != 0;
}
template <> inline bool isType<Entity>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
return lua_isnumber(L, index) != 0;
}
template <> inline bool isType<ComponentType>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
return lua_isnumber(L, index) != 0;
}
template <> inline bool isType<Vec3>(lua_State* L, int index)
{
return lua_istable(L, index) != 0 && lua_rawlen(L, index) == 3;
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 3;
}
template <> inline bool isType<Vec4>(lua_State* L, int index)
{
return lua_istable(L, index) != 0 && lua_rawlen(L, index) == 4;
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 4;
}
template <> inline bool isType<Vec2>(lua_State* L, int index)
{
return lua_istable(L, index) != 0 && lua_rawlen(L, index) == 2;
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 2;
}
template <> inline bool isType<Matrix>(lua_State* L, int index)
{
return lua_istable(L, index) != 0 && lua_rawlen(L, index) == 16;
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 16;
}
template <> inline bool isType<Quat>(lua_State* L, int index)
{
return lua_istable(L, index) != 0 && lua_rawlen(L, index) == 4;
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 4;
}
template <> inline bool isType<u32>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
return lua_isnumber(L, index) != 0;
}
template <> inline bool isType<u64>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
return lua_isnumber(L, index) != 0;
}
template <> inline bool isType<i64>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
return lua_isnumber(L, index) != 0;
}
template <> inline bool isType<bool>(lua_State* L, int index)
{
@ -385,7 +410,8 @@ template <> inline void push(lua_State* L, void* value)
inline void createSystemVariable(lua_State* L, const char* system, const char* var_name, void* value)
{
if (lua_getglobal(L, system) == LUA_TNIL)
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
@ -400,7 +426,8 @@ inline void createSystemVariable(lua_State* L, const char* system, const char* v
inline void createSystemVariable(lua_State* L, const char* system, const char* var_name, int value)
{
if (lua_getglobal(L, system) == LUA_TNIL)
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
@ -415,7 +442,8 @@ inline void createSystemVariable(lua_State* L, const char* system, const char* v
inline void createSystemFunction(lua_State* L, const char* system, const char* var_name, lua_CFunction fn)
{
if (lua_getglobal(L, system) == LUA_TNIL)
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
@ -430,7 +458,8 @@ inline void createSystemFunction(lua_State* L, const char* system, const char* v
inline void createSystemClosure(lua_State* L, const char* system, void* system_ptr, const char* var_name, lua_CFunction fn)
{
if (lua_getglobal(L, system) == LUA_TNIL)
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
@ -502,7 +531,7 @@ inline void checkTableArg(lua_State* L, int index)
template <typename T>
inline void getOptionalField(lua_State* L, int idx, const char* field_name, T* out)
{
if (lua_getfield(L, idx, field_name) != LUA_TNIL && isType<T>(L, -1))
if (LuaWrapper::getField(L, idx, field_name) != LUA_TNIL && isType<T>(L, -1))
{
*out = toType<T>(L, -1);
}
@ -510,6 +539,17 @@ inline void getOptionalField(lua_State* L, int idx, const char* field_name, T* o
}
inline void getOptionalStringField(lua_State* L, int idx, const char* field_name, char* out, int max_size)
{
if (LuaWrapper::getField(L, idx, field_name) != LUA_TNIL && isType<const char*>(L, -1))
{
const char* src = toType<const char*>(L, -1);;
copyString(out, max_size, src);
}
lua_pop(L, 1);
}
namespace details
{

View file

@ -149,6 +149,29 @@ template <int size> struct StaticString
};
struct StringView
{
StringView() : begin(nullptr), end(nullptr) {}
StringView(const char* begin)
: begin(begin)
, end(begin + stringLength(begin))
{
}
StringView(const char* begin, int len)
: begin(begin)
, end(begin + len)
{
}
size_t length() const { return end - begin; }
const char* begin;
const char* end;
};
class LUMIX_ENGINE_API string
{
public:

View file

@ -699,7 +699,7 @@ struct ConsolePlugin LUMIX_FINAL : public StudioApp::GUIPlugin
copyNString(tmp, lengthOf(tmp), data->Buf + start_word, data->CursorPos - start_word);
that->autocomplete.clear();
lua_pushglobaltable(L);
lua_pushvalue(L, LUA_GLOBALSINDEX);
that->autocompleteSubstep(L, tmp, data);
lua_pop(L, 1);
if (!that->autocomplete.empty())
@ -738,8 +738,9 @@ struct ConsolePlugin LUMIX_FINAL : public StudioApp::GUIPlugin
if (ImGui::Button("Execute"))
{
lua_State* L = app.getWorldEditor().getEngine().getState();
bool errors = luaL_loadbuffer(L, buf, stringLength(buf), nullptr) != LUA_OK;
errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK;
bool errors = luaL_loadbuffer(L, buf, stringLength(buf), nullptr) != 0;
errors = errors || lua_pcall(L, 0, 0, 0) != 0;
if (errors)
{
@ -763,8 +764,8 @@ struct ConsolePlugin LUMIX_FINAL : public StudioApp::GUIPlugin
file.read(&data[0], size);
file.close();
lua_State* L = app.getWorldEditor().getEngine().getState();
bool errors = luaL_loadbuffer(L, &data[0], data.size(), tmp) != LUA_OK;
errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK;
bool errors = luaL_loadbuffer(L, &data[0], data.size(), tmp) != 0;
errors = errors || lua_pcall(L, 0, 0, 0) != 0;
if (errors)
{

View file

@ -122,8 +122,8 @@ namespace Lumix
static const u32 INDEX_HASH = crc32("__index");
static const u32 THIS_HASH = crc32("this");
lua_State* L = inst.m_state;
bool is_env_valid = lua_rawgeti(L, LUA_REGISTRYINDEX, inst.m_environment) == LUA_TTABLE; // [env]
ASSERT(is_env_valid);
lua_rawgeti(L, LUA_REGISTRYINDEX, inst.m_environment); // [env]
ASSERT(lua_type(L, -1) == LUA_TTABLE);
lua_pushnil(L); // [env, nil]
auto& allocator = m_scene.m_system.m_allocator;
BinaryArray valid_properties(m_scene.m_system.m_engine.getLIFOAllocator());
@ -213,7 +213,7 @@ namespace Lumix
// environment's metatable & __index
lua_pushvalue(script.m_state, -1); // [env, env]
lua_setmetatable(script.m_state, -2); // [env]
lua_pushglobaltable(script.m_state); // [evn, _G]
lua_pushvalue(script.m_state, LUA_GLOBALSINDEX); // [evn, _G]
lua_setfield(script.m_state, -2, "__index"); // [env]
// set this
@ -222,14 +222,14 @@ namespace Lumix
}
else
{
bool is_env_valid = lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment) == LUA_TTABLE; // [env]
ASSERT(is_env_valid);
lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment); // [env]
ASSERT(lua_type(script.m_state, -1) == LUA_TTABLE);
}
bool errors = luaL_loadbuffer(script.m_state,
script.m_script->getSourceCode(),
stringLength(script.m_script->getSourceCode()),
script.m_script->getPath().c_str()) != LUA_OK; // [env, func]
script.m_script->getPath().c_str()) != 0; // [env, func]
if (errors)
{
@ -240,10 +240,10 @@ namespace Lumix
}
lua_pushvalue(script.m_state, -2); // [env, func, env]
lua_setupvalue(script.m_state, -2, 1); // function's environment [env, func]
lua_setfenv(script.m_state, -2);
m_scene.m_current_script_instance = &script;
errors = errors || lua_pcall(script.m_state, 0, 0, 0) != LUA_OK; // [env]
errors = errors || lua_pcall(script.m_state, 0, 0, 0) != 0; // [env]
if (errors)
{
g_log_error.log("Lua Script") << script.m_script->getPath() << ": "
@ -300,8 +300,8 @@ namespace Lumix
void addEnvironment(int env) override
{
bool is_valid = lua_rawgeti(state, LUA_REGISTRYINDEX, env) == LUA_TTABLE;
ASSERT(is_valid);
lua_rawgeti(state, LUA_REGISTRYINDEX, env);
ASSERT(lua_type(state, -1) == LUA_TTABLE);
++parameter_count;
}
@ -350,9 +350,10 @@ namespace Lumix
auto& script = script_cmp->m_scripts[scr_index];
if (!script.m_state) return nullptr;
bool is_env_valid = lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment) == LUA_TTABLE;
ASSERT(is_env_valid);
if (lua_getfield(script.m_state, -1, function) != LUA_TFUNCTION)
lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment);
ASSERT(lua_type(script.m_state, -1) == LUA_TTABLE);
lua_getfield(script.m_state, -1, function);
if (lua_type(script.m_state, -1) != LUA_TFUNCTION)
{
lua_pop(script.m_state, 2);
return nullptr;
@ -377,7 +378,7 @@ namespace Lumix
auto& script = m_function_call.cmp->m_scripts[m_function_call.scr_index];
if (!script.m_state) return;
if (lua_pcall(script.m_state, m_function_call.parameter_count, 0, 0) != LUA_OK)
if (lua_pcall(script.m_state, m_function_call.parameter_count, 0, 0) != 0)
{
g_log_warning.log("Lua Script") << lua_tostring(script.m_state, -1);
lua_pop(script.m_state, 1);
@ -507,8 +508,8 @@ namespace Lumix
{
resource_type = ResourceType(LuaWrapper::checkArg<const char*>(L, 3));
}
int tmp = lua_getglobal(L, "g_scene_lua_script");
ASSERT(tmp == LUA_TLIGHTUSERDATA);
lua_getglobal(L, "g_scene_lua_script");
ASSERT(lua_type(L, -1) == LUA_TLIGHTUSERDATA);
auto* scene = LuaWrapper::toType<LuaScriptSceneImpl*>(L, -1);
u32 prop_name_hash = crc32(prop_name);
for (auto& prop : scene->m_current_script_instance->m_properties)
@ -571,8 +572,8 @@ namespace Lumix
}
else
{
bool is_valid = lua_rawgeti(L, LUA_REGISTRYINDEX, env) == LUA_TTABLE;
ASSERT(is_valid);
lua_rawgeti(L, LUA_REGISTRYINDEX, env);
ASSERT(lua_type(L, -1) == LUA_TTABLE);
}
return 1;
}
@ -879,8 +880,8 @@ namespace Lumix
void applyResourceProperty(ScriptInstance& script, const char* name, Property& prop, const char* value)
{
bool is_env_valid = lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment) == LUA_TTABLE;
ASSERT(is_env_valid);
lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment);
ASSERT(lua_type(script.m_state, -1));
lua_getfield(script.m_state, -1, name);
int res_idx = LuaWrapper::toType<int>(script.m_state, -1);
m_system.m_engine.unloadLuaResource(res_idx);
@ -911,7 +912,7 @@ namespace Lumix
if (prop.type == Property::STRING) tmp << "\"" << value << "\"";
else tmp << value;
bool errors = luaL_loadbuffer(state, tmp, stringLength(tmp), nullptr) != LUA_OK;
bool errors = luaL_loadbuffer(state, tmp, stringLength(tmp), nullptr) != 0;
if (errors)
{
g_log_error.log("Lua Script") << script.m_script->getPath() << ": " << lua_tostring(state, -1);
@ -919,11 +920,11 @@ namespace Lumix
return;
}
bool is_env_valid = lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment) == LUA_TTABLE;
ASSERT(is_env_valid);
lua_setupvalue(script.m_state, -2, 1);
lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment);
ASSERT(lua_type(script.m_state, -1) == LUA_TTABLE);
lua_setfenv(script.m_state, -2);
errors = errors || lua_pcall(state, 0, 0, 0) != LUA_OK;
errors = errors || lua_pcall(state, 0, 0, 0) != 0;
if (errors)
{
@ -1018,15 +1019,16 @@ namespace Lumix
void destroyInstance(ScriptComponent& scr, ScriptInstance& inst)
{
bool is_env_valid = lua_rawgeti(inst.m_state, LUA_REGISTRYINDEX, inst.m_environment) == LUA_TTABLE;
ASSERT(is_env_valid);
if (lua_getfield(inst.m_state, -1, "onDestroy") != LUA_TFUNCTION)
lua_rawgeti(inst.m_state, LUA_REGISTRYINDEX, inst.m_environment);
ASSERT(lua_type(inst.m_state, -1) == LUA_TTABLE);
lua_getfield(inst.m_state, -1, "onDestroy");
if (lua_type(inst.m_state, -1) != LUA_TFUNCTION)
{
lua_pop(inst.m_state, 2);
}
else
{
if (lua_pcall(inst.m_state, 0, 0, 0) != LUA_OK)
if (lua_pcall(inst.m_state, 0, 0, 0) != 0)
{
g_log_error.log("Lua Script") << lua_tostring(inst.m_state, -1);
lua_pop(inst.m_state, 1);
@ -1068,14 +1070,16 @@ namespace Lumix
if (!instance.m_state) return;
if (is_restart) disableScript(instance);
if (lua_rawgeti(instance.m_state, LUA_REGISTRYINDEX, instance.m_environment) != LUA_TTABLE)
lua_rawgeti(instance.m_state, LUA_REGISTRYINDEX, instance.m_environment);
if (lua_type(instance.m_state, -1) != LUA_TTABLE)
{
ASSERT(false);
lua_pop(instance.m_state, 1);
return;
}
if (lua_getfield(instance.m_state, -1, "update") == LUA_TFUNCTION)
lua_getfield(instance.m_state, -1, "update");
if (lua_type(instance.m_state, -1) == LUA_TFUNCTION)
{
auto& update_data = m_updates.emplace();
update_data.script = instance.m_script;
@ -1083,7 +1087,8 @@ namespace Lumix
update_data.environment = instance.m_environment;
}
lua_pop(instance.m_state, 1);
if (lua_getfield(instance.m_state, -1, "onInputEvent") == LUA_TFUNCTION)
lua_getfield(instance.m_state, -1, "onInputEvent");
if (lua_type(instance.m_state, -1) == LUA_TFUNCTION)
{
auto& callback = m_input_handlers.emplace();
callback.script = instance.m_script;
@ -1094,13 +1099,14 @@ namespace Lumix
if (!is_restart)
{
if (lua_getfield(instance.m_state, -1, "init") != LUA_TFUNCTION)
lua_getfield(instance.m_state, -1, "init");
if (lua_type(instance.m_state, -1) != LUA_TFUNCTION)
{
lua_pop(instance.m_state, 2);
return;
}
if (lua_pcall(instance.m_state, 0, 0, 0) != LUA_OK)
if (lua_pcall(instance.m_state, 0, 0, 0) != 0)
{
g_log_error.log("Lua Script") << lua_tostring(instance.m_state, -1);
lua_pop(instance.m_state, 1);
@ -1224,7 +1230,8 @@ namespace Lumix
*out = '\0';
lua_rawgeti(scr.m_state, LUA_REGISTRYINDEX, scr.m_environment);
if (lua_getfield(scr.m_state, -1, prop_name) == LUA_TNIL)
lua_getfield(scr.m_state, -1, prop_name);
if (lua_type(scr.m_state, -1) == LUA_TNIL)
{
copyString(out, max_size, prop.stored_value.c_str());
lua_pop(scr.m_state, 2);
@ -1289,7 +1296,8 @@ namespace Lumix
if (prop.type == Property::ENTITY)
{
lua_rawgeti(inst.m_state, LUA_REGISTRYINDEX, inst.m_environment);
if (lua_getfield(inst.m_state, -1, name) == LUA_TNIL)
lua_getfield(inst.m_state, -1, name);
if (lua_type(inst.m_state, -1) == LUA_TNIL)
{
serializer.write("prop_value", prop.stored_value.c_str());
}
@ -1493,12 +1501,13 @@ namespace Lumix
timer.time -= time_delta;
if (timer.time < 0)
{
if (lua_rawgeti(timer.state, LUA_REGISTRYINDEX, timer.func) != LUA_TFUNCTION)
lua_rawgeti(timer.state, LUA_REGISTRYINDEX, timer.func);
if (lua_type(timer.state, -1) != LUA_TFUNCTION)
{
ASSERT(false);
}
if (lua_pcall(timer.state, 0, 0, 0) != LUA_OK)
if (lua_pcall(timer.state, 0, 0, 0) != 0)
{
g_log_error.log("Lua Script") << lua_tostring(timer.state, -1);
lua_pop(timer.state, 1);
@ -1574,11 +1583,13 @@ namespace Lumix
}
if (lua_rawgeti(L, LUA_REGISTRYINDEX, callback.environment) != LUA_TTABLE) // [lua_event, environment]
lua_rawgeti(L, LUA_REGISTRYINDEX, callback.environment);
if (lua_type(L, -1) != LUA_TTABLE) // [lua_event, environment]
{
ASSERT(false);
}
if (lua_getfield(L, -1, "onInputEvent") != LUA_TFUNCTION) // [lua_event, environment, func]
lua_getfield(L, -1, "onInputEvent");
if (lua_type(L, -1) != LUA_TFUNCTION) // [lua_event, environment, func]
{
lua_pop(L, 3); // []
return;
@ -1586,7 +1597,7 @@ namespace Lumix
lua_pushvalue(L, -3); // [lua_event, environment, func, lua_event]
if (lua_pcall(L, 1, 0, 0) != LUA_OK)// [lua_event, environment]
if (lua_pcall(L, 1, 0, 0) != 0)// [lua_event, environment]
{
g_log_error.log("Lua Script") << lua_tostring(L, -1);
lua_pop(L, 1); // []
@ -1625,18 +1636,20 @@ namespace Lumix
for (int i = 0; i < m_updates.size(); ++i)
{
CallbackData update_item = m_updates[i];
if (lua_rawgeti(update_item.state, LUA_REGISTRYINDEX, update_item.environment) != LUA_TTABLE)
lua_rawgeti(update_item.state, LUA_REGISTRYINDEX, update_item.environment);
if (lua_type(update_item.state, -1) != LUA_TTABLE)
{
ASSERT(false);
}
if (lua_getfield(update_item.state, -1, "update") != LUA_TFUNCTION)
lua_getfield(update_item.state, -1, "update");
if (lua_type(update_item.state, -1) != LUA_TFUNCTION)
{
lua_pop(update_item.state, 2);
continue;
}
lua_pushnumber(update_item.state, time_delta);
if (lua_pcall(update_item.state, 1, 0, 0) != LUA_OK)
if (lua_pcall(update_item.state, 1, 0, 0) != 0)
{
g_log_error.log("Lua Script") << lua_tostring(update_item.state, -1);
lua_pop(update_item.state, 1);
@ -1759,8 +1772,8 @@ namespace Lumix
{
if (!inst.m_state) return;
bool is_env_valid = lua_rawgeti(inst.m_state, LUA_REGISTRYINDEX, inst.m_environment) == LUA_TTABLE; // [env]
ASSERT(is_env_valid);
lua_rawgeti(inst.m_state, LUA_REGISTRYINDEX, inst.m_environment); // [env]
ASSERT(lua_type(inst.m_state, -1) == LUA_TTABLE);
lua_pushboolean(inst.m_state, enabled); // [env, enabled]
lua_setfield(inst.m_state, -2, "enabled"); // [env]
lua_pop(inst.m_state, 1); // []

View file

@ -14,7 +14,6 @@
#include "engine/universe/universe.h"
#include "gui/gui_system.h"
#include "imgui/imgui.h"
#include "renderer/frame_buffer.h"
#include "renderer/pipeline.h"
#include "renderer/render_scene.h"
#include "renderer/renderer.h"
@ -58,7 +57,7 @@ GameView::GameView(StudioApp& app)
, m_time_multiplier(1.0f)
, m_paused(false)
, m_show_stats(false)
, m_texture_handle(BGFX_INVALID_HANDLE)
, m_texture_handle(ffr::INVALID_TEXTURE)
, m_gui_interface(nullptr)
, m_editor(app.getWorldEditor())
{
@ -166,7 +165,10 @@ void GameView::captureMouse(bool capture)
void GameView::onFullscreenGUI()
{
processInputEvents();
// TODO
ASSERT(false);
/*
processInputEvents();
ImGuiIO& io = ImGui::GetIO();
bool open = true;
@ -184,7 +186,7 @@ void GameView::onFullscreenGUI()
m_pipeline->resize(int(size.x), int(size.y));
m_texture_handle = m_pipeline->getRenderbuffer("default", 0);
m_texture_handle = m_pipeline->getOutput();
if (bgfx::getCaps()->originBottomLeft)
{
ImGui::Image(&m_texture_handle, size, ImVec2(0, 1), ImVec2(1, 0));
@ -204,7 +206,7 @@ void GameView::onFullscreenGUI()
if (m_is_fullscreen && (io.KeysDown[ImGui::GetKeyIndex(ImGuiKey_Escape)] || !m_editor.isGameMode()))
{
setFullscreen(false);
}
}*/
}
@ -225,6 +227,9 @@ void GameView::setFullscreen(bool fullscreen)
void GameView::onStatsGUI(const ImVec2& view_pos)
{
// TODO
ASSERT(false);
/*
if (!m_show_stats || !m_is_open) return;
float toolbar_height = 24 + ImGui::GetStyle().FramePadding.y * 2;
@ -257,7 +262,7 @@ void GameView::onStatsGUI(const ImVec2& view_pos)
ImGui::LabelText("Waiting for render thread", "%.2f", wait_render_time);
}
ImGui::End();
ImGui::PopStyleColor();
ImGui::PopStyleColor();*/
}
@ -363,7 +368,9 @@ void GameView::processInputEvents()
void GameView::onWindowGUI()
{
PROFILE_FUNCTION();
// TODO
/*
PROFILE_FUNCTION();
if (!m_pipeline->isReady()) return;
auto& io = ImGui::GetIO();
@ -399,7 +406,7 @@ void GameView::onWindowGUI()
{
m_pipeline->resize(int(size.x), int(size.y));
m_pipeline->render();
m_texture_handle = m_pipeline->getRenderbuffer("default", 0);
m_texture_handle = m_pipeline->getOutput();
view_pos = ImGui::GetCursorScreenPos();
if (bgfx::getCaps()->originBottomLeft)
@ -469,7 +476,7 @@ void GameView::onWindowGUI()
}
}
ImGui::EndDock();
if(is_game_view_visible) onStatsGUI(view_pos);
if(is_game_view_visible) onStatsGUI(view_pos);*/
}

View file

@ -3,7 +3,7 @@
#include "editor/studio_app.h"
#include "engine/vec.h"
#include <bgfx/bgfx.h>
#include "renderer/ffr/ffr.h"
struct ImVec2;
@ -36,7 +36,7 @@ public:
bool isOpen() const { return m_is_open; }
void onAction() { m_is_open = !m_is_open; }
void onWindowGUI() override;
const bgfx::TextureHandle& getTextureHandle() const { return m_texture_handle; }
const ffr::TextureHandle& getTextureHandle() const { return m_texture_handle; }
public:
bool m_is_open;
@ -59,7 +59,7 @@ private:
StudioApp& m_studio_app;
Vec2 m_pos;
Vec2 m_size;
bgfx::TextureHandle m_texture_handle;
ffr::TextureHandle m_texture_handle;
struct GUIInterface* m_gui_interface;
bool m_is_mouse_captured;
bool m_is_mouse_hovering_window;

View file

@ -23,7 +23,6 @@
#include "imgui/imgui.h"
#include "ofbx.h"
#include "physics/physics_geometry_manager.h"
#include "renderer/frame_buffer.h"
#include "renderer/model.h"
#include "renderer/pipeline.h"
#include "renderer/render_scene.h"
@ -1665,8 +1664,6 @@ struct FBXImporter
header.magic = 0x5f4c4d4f; // == '_LMO';
header.version = (u32)Model::FileVersion::LATEST;
write(header);
u32 flags = 0;
write(flags);
}
@ -1913,7 +1910,8 @@ int setAnimationParams(lua_State* L)
auto& anim = dlg->m_fbx_importer->animations[anim_idx];
if (lua_getfield(L, 2, "root_bone") == LUA_TSTRING)
lua_getfield(L, 2, "root_bone");
if (lua_type(L, -1) == LUA_TSTRING)
{
const char* name = lua_tostring(L, -1);
for (int i = 0; i < dlg->m_fbx_importer->bones.size(); ++i)
@ -1929,7 +1927,8 @@ int setAnimationParams(lua_State* L)
LuaWrapper::getOptionalField(L, 2, "import", &anim.import);
if (lua_getfield(L, 2, "output_filename") == LUA_TSTRING)
lua_getfield(L, 2, "output_filename");
if (lua_type(L, -1) == LUA_TSTRING)
{
copyString(anim.output_filename.data, LuaWrapper::toType<const char*>(L, -1));
}
@ -1944,25 +1943,29 @@ int setParams(lua_State* L)
auto* dlg = LuaWrapper::toType<ImportAssetDialog*>(L, lua_upvalueindex(1));
LuaWrapper::checkTableArg(L, 1);
if (lua_getfield(L, 1, "output_dir") == LUA_TSTRING)
lua_getfield(L, 1, "output_dir");
if (lua_type(L, -1) == LUA_TSTRING)
{
copyString(dlg->m_output_dir, LuaWrapper::toType<const char*>(L, -1));
}
lua_pop(L, 1);
if (lua_getfield(L, 1, "mesh_output_filename") == LUA_TSTRING)
lua_getfield(L, 1, "mesh_output_filename");
if (lua_type(L, -1) == LUA_TSTRING)
{
copyString(dlg->m_mesh_output_filename, LuaWrapper::toType<const char*>(L, -1));
}
lua_pop(L, 1);
if (lua_getfield(L, 1, "texture_output_dir") == LUA_TSTRING)
lua_getfield(L, 1, "texture_output_dir");
if (lua_type(L, -1) == LUA_TSTRING)
{
copyString(dlg->m_texture_output_dir, LuaWrapper::toType<const char*>(L, -1));
}
lua_pop(L, 1);
if (lua_getfield(L, 1, "origin") == LUA_TSTRING)
lua_getfield(L, 1, "origin");
if (lua_type(L, -1) == LUA_TSTRING)
{
const char* str = LuaWrapper::toType<const char*>(L, -1);
if (equalIStrings(str, "center"))
@ -1973,7 +1976,7 @@ int setParams(lua_State* L)
g_log_error.log("Editor") << "Unknown origin value " << str;
}
lua_pop(L, 1);
if (lua_getfield(L, 1, "origin_bottom") == LUA_TBOOLEAN && LuaWrapper::toType<bool>(L, -1))
if (LuaWrapper::getField(L, 1, "origin_bottom") == LUA_TBOOLEAN && LuaWrapper::toType<bool>(L, -1))
{
dlg->m_fbx_importer->origin = FBXImporter::Origin::BOTTOM;
}
@ -1986,7 +1989,7 @@ int setParams(lua_State* L)
LuaWrapper::getOptionalField(L, 1, "time_scale", &dlg->m_fbx_importer->time_scale);
LuaWrapper::getOptionalField(L, 1, "to_dds", &dlg->m_convert_to_dds);
LuaWrapper::getOptionalField(L, 1, "normal_map", &dlg->m_is_normal_map);
if (lua_getfield(L, 1, "orientation") == LUA_TSTRING)
if (LuaWrapper::getField(L, 1, "orientation") == LUA_TSTRING)
{
const char* tmp = LuaWrapper::toType<const char*>(L, -1);
if (equalStrings(tmp, "+y")) dlg->m_fbx_importer->orientation = FBXImporter::Orientation::Y_UP;
@ -1995,7 +1998,7 @@ int setParams(lua_State* L)
else if (equalStrings(tmp, "-z")) dlg->m_fbx_importer->orientation = FBXImporter::Orientation::Z_MINUS_UP;
}
lua_pop(L, 1);
if (lua_getfield(L, 1, "root_orientation") == LUA_TSTRING)
if (LuaWrapper::getField(L, 1, "root_orientation") == LUA_TSTRING)
{
const char* tmp = LuaWrapper::toType<const char*>(L, -1);
if (equalStrings(tmp, "+y")) dlg->m_fbx_importer->root_orientation = FBXImporter::Orientation::Y_UP;
@ -2006,7 +2009,7 @@ int setParams(lua_State* L)
lua_pop(L, 1);
if (lua_getfield(L, 1, "lods") == LUA_TTABLE)
if (LuaWrapper::getField(L, 1, "lods") == LUA_TTABLE)
{
lua_pushnil(L);
int lod_index = 0;
@ -3061,7 +3064,10 @@ static bool createBillboard(ImportAssetDialog& dialog,
const Path& out_path_normal,
int texture_size)
{
auto& engine = dialog.getEditor().getEngine();
// TODO
ASSERT(false);
/*
auto& engine = dialog.getEditor().getEngine();
auto& universe = engine.createUniverse(false);
auto* renderer = static_cast<Renderer*>(engine.getPluginManager().getPlugin("renderer"));
@ -3174,7 +3180,7 @@ static bool createBillboard(ImportAssetDialog& dialog,
bgfx::destroy(normal_texture);
Pipeline::destroy(pipeline);
engine.destroyUniverse(universe);
*/
return true;
}

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,7 @@
#include "engine/universe/component.h"
#include "engine/universe/universe.h"
#include "imgui/imgui.h"
#include "renderer/frame_buffer.h"
#include "renderer/ffr/ffr.h"
#include "renderer/model.h"
#include "renderer/pipeline.h"
#include "renderer/render_scene.h"
@ -184,13 +184,15 @@ void SceneView::update(float)
void SceneView::renderIcons()
{
ffr::pushDebugGroup("icons");
m_editor.renderIcons();
ffr::popDebugGroup();
}
void SceneView::renderSelection()
{
const Array<Entity>& entities = m_editor.getSelectedEntities();
/*const Array<Entity>& entities = m_editor.getSelectedEntities();
RenderScene* scene = m_pipeline->getScene();
Universe& universe = scene->getUniverse();
for (Entity e : entities)
@ -205,15 +207,19 @@ void SceneView::renderSelection()
m_pipeline->renderModel(*model, pose, mtx);
scene->unlockPose(e, false);
}
}
}*/
ASSERT(false);
// TODO
}
void SceneView::renderGizmos()
{
ffr::pushDebugGroup("gizmos");
auto& entities = m_editor.getSelectedEntities();
if(entities.empty() || entities[0] != m_editor.getEditCamera().entity)
m_editor.getGizmo().render();
ffr::popDebugGroup();
}
@ -427,7 +433,7 @@ void SceneView::onWindowGUI()
m_is_open = true;
onToolbar();
auto size = ImGui::GetContentRegionAvail();
m_texture_handle = m_pipeline->getRenderbuffer("default", 0);
m_texture_handle = m_pipeline->getOutput();
if (size.x > 0 && size.y > 0)
{
m_pipeline->resize(int(size.x), int(size.y));
@ -437,13 +443,16 @@ void SceneView::onWindowGUI()
m_width = int(size.x);
m_height = int(size.y);
auto content_min = ImGui::GetCursorScreenPos();
if (bgfx::getCaps()->originBottomLeft)
{
ImGui::Image(&m_texture_handle, size, ImVec2(0, 1), ImVec2(1, 0));
}
else
{
ImGui::Image(&m_texture_handle, size);
if(m_texture_handle.isValid()) {
// TODO
//if (bgfx::getCaps()->originBottomLeft)
{
ImGui::Image(&m_texture_handle, size, ImVec2(0, 1), ImVec2(1, 0));
}
/*else
{
ImGui::Image(&m_texture_handle, size);
}*/
}
if (ImGui::BeginDragDropTarget())
{
@ -502,6 +511,8 @@ void SceneView::onWindowGUI()
ImGui::EndDock();
// TODO
/*
if(m_show_stats && m_is_open)
{
float toolbar_height = 24 + ImGui::GetStyle().FramePadding.y * 2;
@ -537,7 +548,7 @@ void SceneView::onWindowGUI()
}
ImGui::End();
ImGui::PopStyleColor();
}
}*/
}

View file

@ -4,7 +4,7 @@
#include "editor/studio_app.h"
#include "editor/utils.h"
#include "editor/world_editor.h"
#include <bgfx/bgfx.h>
#include "renderer/ffr/ffr.h"
namespace Lumix
@ -30,7 +30,7 @@ class SceneView : public StudioApp::GUIPlugin
void setScene(RenderScene* scene);
void onWindowGUI() override;
Pipeline* getPipeline() { return m_pipeline; }
const bgfx::TextureHandle& getTextureHandle() const { return m_texture_handle; }
const ffr::TextureHandle& getTextureHandle() const { return m_texture_handle; }
void addDropHandler(DropHandler handler);
void removeDropHandler(DropHandler handler);
const char* getName() const override { return "scene_view"; }
@ -70,7 +70,7 @@ class SceneView : public StudioApp::GUIPlugin
float m_camera_speed;
WorldEditor& m_editor;
Pipeline* m_pipeline;
bgfx::TextureHandle m_texture_handle;
ffr::TextureHandle m_texture_handle;
bool m_show_stats;
LogUI& m_log_ui;
Array<DropHandler> m_drop_handlers;

View file

@ -24,14 +24,6 @@
#include <stb/mf_resource.h>
namespace bgfx
{
int compileShader(int _argc, const char* _argv[]);
typedef void(*UserErrorFn)(void*, const char*, va_list);
void setShaderCErrorFunction(UserErrorFn fn, void* user_ptr);
}
namespace Lumix
{
@ -49,6 +41,8 @@ ShaderCompiler::ShaderCompiler(StudioApp& app, LogUI& log_ui)
, m_mutex(false)
, m_load_hook(*m_editor.getEngine().getResourceManager().get(Shader::TYPE), *this)
{
// TODO
/*
JobSystem::JobDecl job;
job.task = [](void* data) { ((ShaderCompiler*)data)->compileTask(); };
job.data = this;
@ -67,7 +61,7 @@ ShaderCompiler::ShaderCompiler(StudioApp& app, LogUI& log_ui)
Engine& engine = m_editor.getEngine();
ResourceManagerBase* shader_manager = engine.getResourceManager().get(ShaderBinary::TYPE);
shader_manager->setLoadHook(m_load_hook);
shader_manager->setLoadHook(m_load_hook);*/
}
@ -462,6 +456,9 @@ ShaderCompiler::~ShaderCompiler()
void ShaderCompiler::reloadShaders()
{
// TODO
ASSERT(false);
/*
m_to_reload.removeDuplicates();
auto shader_manager = m_editor.getEngine().getResourceManager().get(Shader::TYPE);
@ -483,7 +480,7 @@ void ShaderCompiler::reloadShaders()
if(!any_hooked) shader_manager->reload(Path(shd_path.c_str()));
}
m_to_reload.clear();
m_to_reload.clear();*/
}
@ -531,6 +528,10 @@ void ShaderCompiler::compilePass(const char* shd_path,
const ShaderCombinations::Defines& all_defines,
bool debug)
{
// TODO
ASSERT(false);
/*
const char* base_path = m_editor.getEngine().getDiskFileDevice()->getBasePath();
for (int mask = 0; mask < 1 << lengthOf(all_defines); ++mask)
@ -598,7 +599,7 @@ void ShaderCompiler::compilePass(const char* shd_path,
g_log_error.log("Renderer") << "Failed to compile " << source_path << "(" << out_path << "), defines = \"" << defines << "\"";
}
}
}
}*/
}

View file

@ -1,361 +0,0 @@
#include "ffr.h"
#include <assert.h>
#include <malloc.h>
#include <stdio.h>
#include <Windows.h>
#include <gl/GL.h>
#include "renderdoc_app.h"
#define FFR_GL_IMPORT(prototype, name) static prototype name;
#define FFR_GL_IMPORT_TYPEDEFS
#include "gl_ext.h"
#undef FFR_GL_IMPORT_TYPEDEFS
#undef FFR_GL_IMPORT
#define LOG(level, msg) do { (*s_ffr.init.log)(s_ffr.init.user_ptr, (FFR_LOG_##level), (msg)); } while(0)
#define CHECK_GL(gl) \
do { \
gl; \
GLenum err = glGetError(); \
if (err != GL_NO_ERROR) { \
char buf[1024]; \
sprintf_s(buf, sizeof(buf), "%s %d", "OpenGL error ", err); \
LOG(ERROR, buf); \
} \
} while(0)
static struct {
ffr_init_params init;
RENDERDOC_API_1_1_2* rdoc_api;
GLuint vao;
GLuint tex_buffers[32];
} s_ffr;
static void default_log(void* user_ptr, ffr_log_level level, const char* msg)
{
printf("%s", msg);
if (IsDebuggerPresent()) {
OutputDebugString("ffr: ");
OutputDebugString(msg);
OutputDebugString("\n");
}
}
static void try_load_renderdoc()
{
HMODULE lib = LoadLibrary("renderdoc.dll");
if (!lib) return;
pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)GetProcAddress(lib, "RENDERDOC_GetAPI");
if (RENDERDOC_GetAPI) {
RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&s_ffr.rdoc_api);
}
/**/
//FreeLibrary(lib);
}
static int load_gl()
{
#define FFR_GL_IMPORT(prototype, name) \
do { \
name = (prototype)wglGetProcAddress(#name); \
if (!name) { \
(*s_ffr.init.log)(s_ffr.init.user_ptr, (FFR_LOG_FATAL), ("Failed to load GL function " #name ".")); \
return 0; \
} \
} while(0)
#include "gl_ext.h"
#undef FFR_GL_IMPORT
return 1;
}
static void* default_alloc(void* user_ptr, size_t size, size_t align)
{
return _aligned_malloc(size, align);
}
static void default_free(void* user_ptr, void* mem)
{
_aligned_free(mem);
}
void ffr_viewport(ffr_uint x, ffr_uint y, ffr_uint w, ffr_uint h)
{
glViewport(x, y, w, h);
}
void ffr_blend()
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void ffr_scissor(ffr_uint x, ffr_uint y, ffr_uint w, ffr_uint h)
{
glScissor(x, y, w, h);
}
void ffr_draw(const ffr_draw_call* dc)
{
const GLuint prg = dc->shader.value;
CHECK_GL(glUseProgram(prg));
GLuint pt;
switch (dc->primitive_type) {
case FFR_PRIMITIVE_TYPE_TRIANGLES: pt = GL_TRIANGLES; break;
case FFR_PRIMITIVE_TYPE_TRIANGLE_STRIP: pt = GL_TRIANGLE_STRIP; break;
default: assert(0); break;
}
for (ffr_uint i = 0; i < dc->tex_buffers_count; ++i) {
const GLuint buf = dc->tex_buffers[i].value;
CHECK_GL(glActiveTexture(GL_TEXTURE0 + i));
CHECK_GL(glBindTexture(GL_TEXTURE_BUFFER, s_ffr.tex_buffers[i]));
CHECK_GL(glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, buf));
const GLint uniform_loc = glGetUniformLocation(prg, "test");
CHECK_GL(glUniform1i(uniform_loc, i));
}
for (ffr_uint i = 0; i < dc->textures_count; ++i) {
const GLuint t = dc->textures[i].value;
glBindTexture(GL_TEXTURE_2D, t);
const GLint uniform_loc = glGetUniformLocation(prg, "test");
CHECK_GL(glUniform1i(uniform_loc, i));
}
if (dc->vertex_decl) {
const ffr_vertex_decl* decl = dc->vertex_decl;
const GLsizei stride = decl->size;
const GLuint vb = dc->vertex_buffer.value;
const ffr_uint vb_offset = dc->vertex_buffer_offset;
glBindBuffer(GL_ARRAY_BUFFER, vb);
for (ffr_uint i = 0; i < decl->attributes_count; ++i) {
const ffr_attribute* attr = &decl->attributes[i];
const void* offset = (void*)(intptr_t)(attr->offset + vb_offset);
GLenum gl_attr_type;
switch (attr->type) {
case FFR_ATTRIBUTE_TYPE_FLOAT: gl_attr_type = GL_FLOAT; break;
case FFR_ATTRIBUTE_TYPE_UBYTE: gl_attr_type = GL_UNSIGNED_BYTE; break;
}
glVertexAttribPointer(i, attr->size, gl_attr_type, attr->normalized, stride, offset);
glEnableVertexAttribArray(i);
}
}
if (dc->index_buffer.value != 0xffFFffFF) {
const GLuint ib = dc->index_buffer.value;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib);
glDrawElements(pt, dc->indices_count, GL_UNSIGNED_SHORT, (void*)(intptr_t)(dc->indices_offset * sizeof(short)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
else {
CHECK_GL(glDrawArrays(pt, dc->indices_offset, dc->indices_count));
}
}
void ffr_update_buffer(ffr_buffer_handle buffer, const void* data, size_t offset, size_t size)
{
const GLuint buf = buffer.value;
CHECK_GL(glBindBuffer(GL_ARRAY_BUFFER, buf));
CHECK_GL(glBufferSubData(GL_ARRAY_BUFFER, offset, size, data));
CHECK_GL(glBindBuffer(GL_ARRAY_BUFFER, 0));
}
ffr_buffer_handle ffr_create_buffer(size_t size, const void* data)
{
GLuint buf;
CHECK_GL(glGenBuffers(1, &buf));
CHECK_GL(glBindBuffer(GL_ARRAY_BUFFER, buf));
CHECK_GL(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
CHECK_GL(glBindBuffer(GL_ARRAY_BUFFER, 0));
return (ffr_buffer_handle) { buf };
}
void ffr_destroy_program(ffr_program_handle program)
{
glDeleteProgram(program.value);
}
ffr_texture_handle ffr_create_texture(ffr_uint w, ffr_uint h, const void* data)
{
GLuint t;
CHECK_GL(glGenTextures(1, &t));
CHECK_GL(glBindTexture(GL_TEXTURE_2D, t));
CHECK_GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data));
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
return (ffr_texture_handle) { t };
}
void ffr_destroy_texture(ffr_texture_handle texture)
{
glDeleteTextures(1, &texture.value);
}
void ffr_destroy_buffer(ffr_buffer_handle buffer)
{
glDeleteBuffers(1, &buffer.value);
}
void ffr_clear(ffr_uint flags, const float* color, float depth)
{
GLbitfield gl_flags = 0;
if (flags & FFR_CLEAR_FLAG_COLOR) {
glClearColor(color[0], color[1], color[2], color[3]);
gl_flags |= GL_COLOR_BUFFER_BIT;
}
if (flags & FFR_CLEAR_FLAG_DEPTH) {
glClearDepth(depth);
gl_flags |= GL_DEPTH_BUFFER_BIT;
}
glClear(gl_flags);
}
ffr_program_handle ffr_create_program(const char** srcs, const ffr_shader_type* types, int num)
{
enum { MAX_SHADERS_PER_PROGRAM = 16 };
if (num > MAX_SHADERS_PER_PROGRAM) {
LOG(ERROR, "Too many shaders per program.");
return (ffr_program_handle)FFR_INVALID_HANDLE;
}
const GLuint prg = glCreateProgram();
for (int i = 0; i < num; ++i) {
GLenum shader_type;
switch (types[i]) {
case FFR_SHADER_TYPE_FRAGMENT: shader_type = GL_FRAGMENT_SHADER; break;
case FFR_SHADER_TYPE_VERTEX: shader_type = GL_VERTEX_SHADER; break;
default: assert(0); break;
}
const GLuint shd = glCreateShader(shader_type);
CHECK_GL(glShaderSource(shd, 1, &srcs[i], 0));
CHECK_GL(glCompileShader(shd));
GLint compile_status;
CHECK_GL(glGetShaderiv(shd, GL_COMPILE_STATUS, &compile_status));
if (compile_status == GL_FALSE) {
GLint log_len = 0;
CHECK_GL(glGetShaderiv(shd, GL_INFO_LOG_LENGTH, &log_len));
if (log_len > 0) {
char* log_buf = s_ffr.init.alloc(s_ffr.init.user_ptr, log_len, 16);
CHECK_GL(glGetShaderInfoLog(shd, log_len, &log_len, log_buf));
LOG(ERROR, log_buf);
s_ffr.init.free(s_ffr.init.user_ptr, log_buf);
}
else {
LOG(ERROR, "Failed to compile shader.");
}
CHECK_GL(glDeleteShader(shd));
return (ffr_program_handle)FFR_INVALID_HANDLE;
}
CHECK_GL(glAttachShader(prg, shd));
CHECK_GL(glDeleteShader(shd));
}
CHECK_GL(glLinkProgram(prg));
GLint linked;
CHECK_GL(glGetProgramiv(prg, GL_LINK_STATUS, &linked));
if (linked == GL_FALSE) {
GLint log_len = 0;
CHECK_GL(glGetProgramiv(prg, GL_INFO_LOG_LENGTH, &log_len));
if (log_len > 0) {
char* log_buf = s_ffr.init.alloc(s_ffr.init.user_ptr, log_len, 16);
CHECK_GL(glGetProgramInfoLog(prg, log_len, &log_len, log_buf));
LOG(ERROR, log_buf);
s_ffr.init.free(s_ffr.init.user_ptr, log_buf);
}
else {
LOG(ERROR, "Failed to link program.");
}
CHECK_GL(glDeleteProgram(prg));
return (ffr_program_handle)FFR_INVALID_HANDLE;
}
return (ffr_program_handle) { prg };
}
static void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, const void *userParam)
{
OutputDebugString("GL: ");
OutputDebugString(message);
OutputDebugString("\n");
}
void ffr_preinit()
{
try_load_renderdoc();
}
ffr_init_result ffr_init(const ffr_init_params* params)
{
if (params) {
s_ffr.init = *params;
}
else {
s_ffr.init.user_ptr = 0;
s_ffr.init.log = default_log;
s_ffr.init.alloc = default_alloc;
s_ffr.init.free = default_free;
}
if (!load_gl()) return FFR_INIT_FAIL;
CHECK_GL(glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE));
CHECK_GL(glDebugMessageCallback(gl_debug_callback, 0));
CHECK_GL(glGenVertexArrays(1, &s_ffr.vao));
CHECK_GL(glBindVertexArray(s_ffr.vao));
CHECK_GL(glGenTextures(_countof(s_ffr.tex_buffers), s_ffr.tex_buffers));
LOG(INFO, "init successful");
return FFR_INIT_SUCCESS;
}
void ffr_set_framebuffer(ffr_framebuffer_handle fb)
{
assert(fb.value = 0xffFFffFF);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void ffr_shutdown()
{
}

1046
src/renderer/ffr/ffr.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,123 +1,165 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "engine/lumix.h"
typedef unsigned int ffr_uint;
namespace Lumix {
struct IAllocator;
namespace ffr {
typedef struct { ffr_uint value; } ffr_buffer_handle;
typedef struct { ffr_uint value; } ffr_program_handle;
typedef struct { ffr_uint value; } ffr_framebuffer_handle;
typedef struct { ffr_uint value; } ffr_texture_handle;
struct BufferHandle { uint value; bool isValid() const { return value != 0xFFffFFff; } };
struct ProgramHandle { uint value; bool isValid() const { return value != 0xFFffFFff; } };
struct FramebufferHandle { uint value; bool isValid() const { return value != 0xFFffFFff; } };
struct TextureHandle { uint value; bool isValid() const { return value != 0xFFffFFff; } };
#define FFR_INVALID_HANDLE { 0xffFFffFF }
const BufferHandle INVALID_BUFFER = { 0xffFFffFF };
const ProgramHandle INVALID_PROGRAM = { 0xffFFffFF };
const TextureHandle INVALID_TEXTURE = { 0xffFFffFF };
const FramebufferHandle INVALID_FRAMEBUFFER = { 0xffFFffFF };
typedef enum {
FFR_LOG_INFO,
FFR_LOG_WARNING,
FFR_LOG_ERROR,
FFR_LOG_FATAL
} ffr_log_level;
enum class LogLevel : uint {
INFO,
WARNING,
ERROR,
FATAL
};
typedef enum {
FFR_INIT_SUCCESS,
FFR_INIT_FAIL
} ffr_init_result;
enum class StateFlags : u32 {
DEPTH_TEST = 1 << 0,
CULL_FACE = 1 << 1,
WIREFRAME = 1 << 2
};
typedef enum {
FFR_PRIMITIVE_TYPE_TRIANGLES,
FFR_PRIMITIVE_TYPE_TRIANGLE_STRIP
} ffr_primitive_type;
enum class PrimitiveType : uint {
TRIANGLES,
TRIANGLE_STRIP,
LINES
};
typedef enum {
FFR_SHADER_TYPE_VERTEX,
FFR_SHADER_TYPE_FRAGMENT,
} ffr_shader_type;
enum class ShaderType : uint {
VERTEX,
FRAGMENT,
};
typedef enum {
FFR_CLEAR_FLAG_COLOR = 1 << 0,
FFR_CLEAR_FLAG_DEPTH = 1 << 1
} ffr_clear_flag;
enum class ClearFlags : uint {
COLOR = 1 << 0,
DEPTH = 1 << 1
};
typedef enum {
FFR_ATTRIBUTE_TYPE_UBYTE,
FFR_ATTRIBUTE_TYPE_FLOAT
} ffr_attribute_type;
enum class AttributeType : uint {
U8,
FLOAT,
I16
};
typedef struct {
void* user_ptr;
void (*log)(void* user_ptr, ffr_log_level level, const char* msg);
void* (*alloc)(void* user_ptr, size_t size, size_t align);
void (*free)(void* user_ptr, void* mem);
} ffr_init_params;
enum class TextureFormat : uint {
D32,
D24,
D24S8,
RGBA8,
RGBA16F,
R16F,
R16,
R32F
};
typedef struct {
ffr_uint size;
ffr_uint offset;
ffr_uint normalized;
ffr_attribute_type type;
} ffr_attribute;
struct Attribute {
uint components_num;
uint offset;
bool normalized;
bool as_int;
AttributeType type;
};
typedef struct {
ffr_uint size;
ffr_uint attributes_count;
ffr_attribute attributes[16];
} ffr_vertex_decl;
struct VertexDecl {
enum { MAX_ATTRIBUTES = 16 };
void addAttribute(uint components_num, AttributeType type, bool normalized, bool as_int);
uint size = 0;
uint attributes_count = 0;
Attribute attributes[MAX_ATTRIBUTES];
};
typedef struct {
ffr_program_handle shader;
ffr_primitive_type primitive_type;
ffr_uint tex_buffers_count;
const ffr_buffer_handle* tex_buffers;
ffr_uint textures_count;
const ffr_texture_handle* textures;
ffr_uint indices_offset;
ffr_uint indices_count;
ffr_buffer_handle index_buffer;
ffr_buffer_handle vertex_buffer;
ffr_uint vertex_buffer_offset;
const ffr_vertex_decl* vertex_decl;
} ffr_draw_call;
struct DrawCall {
ProgramHandle shader;
PrimitiveType primitive_type;
uint tex_buffers_count;
const BufferHandle* tex_buffers;
uint textures_count;
const TextureHandle* textures;
uint indices_offset;
uint indices_count;
BufferHandle index_buffer;
BufferHandle vertex_buffer;
uint vertex_buffer_offset;
const VertexDecl* vertex_decl;
u32 state;
};
struct TextureInfo {
int width;
int height;
int depth;
int layers;
int mips;
bool is_cubemap;
};
void ffr_preinit();
ffr_init_result ffr_init(const ffr_init_params* params);
void ffr_shutdown();
void preinit();
bool init(IAllocator& allocator);
inline bool isHomogenousDepth() { return true; }
void shutdown();
void ffr_clear(ffr_uint flags, const float* color, float depth);
void clear(uint flags, const float* color, float depth);
void ffr_scissor(ffr_uint x, ffr_uint y, ffr_uint w, ffr_uint h);
void ffr_viewport(ffr_uint x, ffr_uint y, ffr_uint w, ffr_uint h);
void ffr_blend();
void scissor(uint x, uint y, uint w, uint h);
void viewport(uint x, uint y, uint w, uint h);
void blend();
ffr_program_handle ffr_create_program(const char** srcs, const ffr_shader_type* types, int num);
ffr_buffer_handle ffr_create_buffer(size_t size, const void* data);
ffr_texture_handle ffr_create_texture(ffr_uint w, ffr_uint h, const void* data);
ProgramHandle createProgram(const char** srcs, const ShaderType* types, int num);
BufferHandle createBuffer(size_t size, const void* data);
TextureHandle createTexture(uint w, uint h, TextureFormat format, const void* data);
TextureHandle loadTexture(const void* data, int size, TextureInfo* info);
FramebufferHandle createFramebuffer(uint renderbuffers_count, const TextureHandle* renderbuffers);
void ffr_update_buffer(ffr_buffer_handle buffer, const void* data, size_t offset, size_t size);
void setState(u32 flags);
void uniformBlockBinding(ProgramHandle program, uint index, uint binding);
void update(BufferHandle buffer, const void* data, size_t offset, size_t size);
void bindUniformBuffer(uint index, BufferHandle buffer);
void ffr_destroy_program(ffr_program_handle program);
void ffr_destroy_buffer(ffr_buffer_handle buffer);
void ffr_destroy_texture(ffr_texture_handle texture);
void destroy(ProgramHandle program);
void destroy(BufferHandle buffer);
void destroy(TextureHandle texture);
void destroy(FramebufferHandle fb);
void ffr_draw(const ffr_draw_call* draw_call);
void draw(const DrawCall& draw_call);
void ffr_set_framebuffer(ffr_framebuffer_handle fb);
void pushDebugGroup(const char* msg);
void popDebugGroup();
void setUniform1i(ProgramHandle program, const char* uniform_name, int value);
void setUniform2f(ProgramHandle program, const char* uniform_name, uint count, const float* value);
void setUniform4f(ProgramHandle program, const char* uniform_name, uint count, const float* value);
void setUniformMatrix4f(ProgramHandle program, const char* uniform_name, uint count, const float* value);
#ifdef __cplusplus
}
#endif
void setFramebuffer(FramebufferHandle fb);
} // namespace ffr
} // namespace Lumix

View file

@ -1,106 +1,49 @@
#ifndef GL_FRAGMENT_SHADER
#define GL_FRAGMENT_SHADER 0x8B30
#endif
#ifndef GL_VERTEX_SHADER
#define GL_VERTEX_SHADER 0x8B31
#endif
#ifndef GL_COMPILE_STATUS
#define GL_COMPILE_STATUS 0x8B81
#endif
#ifndef GL_INFO_LOG_LENGTH
#define GL_INFO_LOG_LENGTH 0x8B84
#endif
#ifndef GL_LINK_STATUS
#define GL_LINK_STATUS 0x8B82
#endif
#ifndef GL_ELEMENT_ARRAY_BUFFER
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#endif
#ifndef GL_ARRAY_BUFFER
#define GL_ARRAY_BUFFER 0x8892
#endif
#ifndef GL_STATIC_DRAW
#define GL_STATIC_DRAW 0x88E4
#endif
#ifndef GL_TEXTURE0
#define GL_TEXTURE0 0x84C0
#endif
#ifndef GL_TEXTURE_BUFFER
#define GL_TEXTURE_BUFFER 0x8C2A
#endif
#ifndef GL_R32F
#define GL_R32F 0x822E
#endif
#ifndef GL_RGBA32F
#define GL_RGBA32F 0x8814
#endif
#ifndef GL_FRAMEBUFFER
#define GL_FRAMEBUFFER 0x8D40
#endif
#ifdef FFR_GL_IMPORT_TYPEDEFS
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, const void *userParam);
typedef void (APIENTRY* PFNGLACTIVETEXTUREPROC) (GLenum texture);
typedef void (APIENTRY* PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
typedef void (APIENTRY* PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRY* PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer);
typedef void (APIENTRY* PFNGLBINDVERTEXARRAYPROC) (GLuint array);
typedef void (APIENTRY* PFNGLBUFFERDATAPROC) (GLenum target, ptrdiff_t size, const void *data, GLenum usage);
typedef void (APIENTRY* PFNGLBUFFERSUBDATAPROC) (GLenum target, ptrdiff_t offset, ptrdiff_t size, const void *data);
typedef void (APIENTRY* PFNGLCOMPILESHADERPROC) (GLuint shader);
typedef GLuint (APIENTRY* PFNGLCREATEPROGRAMPROC) (void);
typedef GLuint (APIENTRY* PFNGLCREATESHADERPROC) (GLenum type);
typedef void (APIENTRY* PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam);
typedef void (APIENTRY* PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
typedef void (APIENTRY* PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRY* PFNGLDELETEPROGRAMPROC) (GLuint program);
typedef void (APIENTRY* PFNGLDELETESHADERPROC) (GLuint shader);
typedef void (APIENTRY* PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
typedef void (APIENTRY* PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY* PFNGLGENERATEMIPMAPPROC) (GLenum target);
typedef void (APIENTRY* PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
typedef void (APIENTRY* PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
typedef void (APIENTRY* PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog);
typedef void (APIENTRY* PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog);
typedef void (APIENTRY* PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
typedef GLint (APIENTRY* PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const char *name);
typedef void (APIENTRY* PFNGLLINKPROGRAMPROC) (GLuint program);
typedef void (APIENTRY* PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char ** tring, const GLint * length);
typedef void (APIENTRY* PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer);
typedef void (APIENTRY* PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
typedef void (APIENTRY* PFNGLUSEPROGRAMPROC) (GLuint program);
typedef void (APIENTRY* PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
#endif
#include "glcorearb.h"
FFR_GL_IMPORT(PFNGLACTIVETEXTUREPROC, glActiveTexture);
FFR_GL_IMPORT(PFNGLATTACHSHADERPROC, glAttachShader);
FFR_GL_IMPORT(PFNGLBINDBUFFERPROC, glBindBuffer);
FFR_GL_IMPORT(PFNGLBINDBUFFERRANGEPROC, glBindBufferRange);
FFR_GL_IMPORT(PFNGLBINDBUFFERBASEPROC, glBindBufferBase);
FFR_GL_IMPORT(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer);
FFR_GL_IMPORT(PFNGLBINDVERTEXARRAYPROC, glBindVertexArray);
FFR_GL_IMPORT(PFNGLBUFFERDATAPROC, glBufferData);
FFR_GL_IMPORT(PFNGLBUFFERSUBDATAPROC, glBufferSubData);
FFR_GL_IMPORT(PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus);
FFR_GL_IMPORT(PFNGLCOMPILESHADERPROC, glCompileShader);
FFR_GL_IMPORT(PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D);
FFR_GL_IMPORT(PFNGLCREATEFRAMEBUFFERSPROC, glCreateFramebuffers);
FFR_GL_IMPORT(PFNGLCREATEPROGRAMPROC, glCreateProgram);
FFR_GL_IMPORT(PFNGLCREATESHADERPROC, glCreateShader);
FFR_GL_IMPORT(PFNGLDEBUGMESSAGECALLBACKPROC, glDebugMessageCallback);
FFR_GL_IMPORT(PFNGLDEBUGMESSAGECONTROLPROC, glDebugMessageControl);
FFR_GL_IMPORT(PFNGLDELETEBUFFERSPROC, glDeleteBuffers);
FFR_GL_IMPORT(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers);
FFR_GL_IMPORT(PFNGLDELETEPROGRAMPROC, glDeleteProgram);
FFR_GL_IMPORT(PFNGLDELETESHADERPROC, glDeleteShader);
FFR_GL_IMPORT(PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray);
FFR_GL_IMPORT(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D);
FFR_GL_IMPORT(PFNGLGENBUFFERSPROC, glGenBuffers);
FFR_GL_IMPORT(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers);
FFR_GL_IMPORT(PFNGLGENERATEMIPMAPPROC, glGenerateMipmap);
FFR_GL_IMPORT(PFNGLGENRENDERBUFFERSPROC, glGenRenderbuffers);
FFR_GL_IMPORT(PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays);
FFR_GL_IMPORT(PFNGLGETDEBUGMESSAGELOGPROC, glGetDebugMessageLog);
FFR_GL_IMPORT(PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog);
FFR_GL_IMPORT(PFNGLGETPROGRAMIVPROC, glGetProgramiv);
FFR_GL_IMPORT(PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog);
FFR_GL_IMPORT(PFNGLGETSHADERIVPROC, glGetShaderiv);
FFR_GL_IMPORT(PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation);
FFR_GL_IMPORT(PFNGLLINKPROGRAMPROC, glLinkProgram);
FFR_GL_IMPORT(PFNGLNAMEDFRAMEBUFFERTEXTUREPROC, glNamedFramebufferTexture);
FFR_GL_IMPORT(PFNGLPOPDEBUGGROUPPROC, glPopDebugGroup);
FFR_GL_IMPORT(PFNGLPUSHDEBUGGROUPPROC, glPushDebugGroup);
FFR_GL_IMPORT(PFNGLSHADERSOURCEPROC, glShaderSource);
FFR_GL_IMPORT(PFNGLTEXBUFFERPROC, glTexBuffer);
FFR_GL_IMPORT(PFNGLUNIFORM1IPROC, glUniform1i);
FFR_GL_IMPORT(PFNGLUNIFORM2FVPROC, glUniform2fv);
FFR_GL_IMPORT(PFNGLUNIFORM4FVPROC, glUniform4fv);
FFR_GL_IMPORT(PFNGLUNIFORMMATRIX4FVPROC, glUniformMatrix4fv);
FFR_GL_IMPORT(PFNGLUNIFORMBLOCKBINDINGPROC, glUniformBlockBinding);
FFR_GL_IMPORT(PFNGLUSEPROGRAMPROC, glUseProgram);
FFR_GL_IMPORT(PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer);
FFR_GL_IMPORT(PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer);

5703
src/renderer/ffr/glcorearb.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,282 @@
#ifndef __khrplatform_h_
#define __khrplatform_h_
/*
** Copyright (c) 2008-2018 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/* Khronos platform-specific types and definitions.
*
* The master copy of khrplatform.h is maintained in the Khronos EGL
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
* The last semantic modification to khrplatform.h was at commit ID:
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
*
* Adopters may modify this file to suit their platform. Adopters are
* encouraged to submit platform specific modifications to the Khronos
* group so that they can be included in future versions of this file.
* Please submit changes by filing pull requests or issues on
* the EGL Registry repository linked above.
*
*
* See the Implementer's Guidelines for information about where this file
* should be located on your system and for more details of its use:
* http://www.khronos.org/registry/implementers_guide.pdf
*
* This file should be included as
* #include <KHR/khrplatform.h>
* by Khronos client API header files that use its types and defines.
*
* The types in khrplatform.h should only be used to define API-specific types.
*
* Types defined in khrplatform.h:
* khronos_int8_t signed 8 bit
* khronos_uint8_t unsigned 8 bit
* khronos_int16_t signed 16 bit
* khronos_uint16_t unsigned 16 bit
* khronos_int32_t signed 32 bit
* khronos_uint32_t unsigned 32 bit
* khronos_int64_t signed 64 bit
* khronos_uint64_t unsigned 64 bit
* khronos_intptr_t signed same number of bits as a pointer
* khronos_uintptr_t unsigned same number of bits as a pointer
* khronos_ssize_t signed size
* khronos_usize_t unsigned size
* khronos_float_t signed 32 bit floating point
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for
* booleans cannot use this as the base type for their boolean.
*
* Tokens defined in khrplatform.h:
*
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
*
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
*
* Calling convention macros defined in this file:
* KHRONOS_APICALL
* KHRONOS_APIENTRY
* KHRONOS_APIATTRIBUTES
*
* These may be used in function prototypes as:
*
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
* int arg1,
* int arg2) KHRONOS_APIATTRIBUTES;
*/
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APICALL
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
#elif defined(__ANDROID__)
# define KHRONOS_APICALL __attribute__((visibility("default")))
#else
# define KHRONOS_APICALL
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIENTRY
*-------------------------------------------------------------------------
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else
# define KHRONOS_APIENTRY
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIATTRIBUTES
*-------------------------------------------------------------------------
* This follows the closing parenthesis of the function prototype arguments.
*/
#if defined (__ARMCC_2__)
#define KHRONOS_APIATTRIBUTES __softfp
#else
#define KHRONOS_APIATTRIBUTES
#endif
/*-------------------------------------------------------------------------
* basic type definitions
*-----------------------------------------------------------------------*/
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
/*
* Using <stdint.h>
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__VMS ) || defined(__sgi)
/*
* Using <inttypes.h>
*/
#include <inttypes.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
/*
* Win32
*/
typedef __int32 khronos_int32_t;
typedef unsigned __int32 khronos_uint32_t;
typedef __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__sun__) || defined(__digital__)
/*
* Sun or Digital
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#if defined(__arch64__) || defined(_LP64)
typedef long int khronos_int64_t;
typedef unsigned long int khronos_uint64_t;
#else
typedef long long int khronos_int64_t;
typedef unsigned long long int khronos_uint64_t;
#endif /* __arch64__ */
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif 0
/*
* Hypothetical platform with no float or int64 support
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#define KHRONOS_SUPPORT_INT64 0
#define KHRONOS_SUPPORT_FLOAT 0
#else
/*
* Generic fallback
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#endif
/*
* Types that are (so far) the same on all platforms
*/
typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t;
/*
* Types that differ between LLP64 and LP64 architectures - in LLP64,
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
* to be the only LLP64 architecture in current use.
*/
#ifdef _WIN64
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t;
#else
typedef signed long int khronos_intptr_t;
typedef unsigned long int khronos_uintptr_t;
typedef signed long int khronos_ssize_t;
typedef unsigned long int khronos_usize_t;
#endif
#if KHRONOS_SUPPORT_FLOAT
/*
* Float type
*/
typedef float khronos_float_t;
#endif
#if KHRONOS_SUPPORT_INT64
/* Time types
*
* These types can be used to represent a time interval in nanoseconds or
* an absolute Unadjusted System Time. Unadjusted System Time is the number
* of nanoseconds since some arbitrary system event (e.g. since the last
* time the system booted). The Unadjusted System Time is an unsigned
* 64 bit value that wraps back to 0 every 584 years. Time intervals
* may be either signed or unsigned.
*/
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t;
#endif
/*
* Dummy value used to pad enum types to 32 bits.
*/
#ifndef KHRONOS_MAX_ENUM
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
#endif
/*
* Enumerated boolean type
*
* Values other than zero should be considered to be true. Therefore
* comparisons should not be made against KHRONOS_TRUE.
*/
typedef enum {
KHRONOS_FALSE = 0,
KHRONOS_TRUE = 1,
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
} khronos_boolean_enum_t;
#endif /* __khrplatform_h_ */

View file

@ -1,154 +0,0 @@
#include "renderer/frame_buffer.h"
#include "engine/json_serializer.h"
#include "engine/log.h"
#include "engine/string.h"
#include <bgfx/bgfx.h>
#include <lua.hpp>
#include <lauxlib.h>
namespace Lumix
{
FrameBuffer::FrameBuffer(const Declaration& decl)
: m_declaration(decl)
{
m_autodestroy_handle = true;
bgfx::TextureHandle texture_handles[16];
for (int i = 0; i < decl.m_renderbuffers_count; ++i)
{
const RenderBuffer& renderbuffer = decl.m_renderbuffers[i];
if (renderbuffer.m_shared)
{
texture_handles[i] = renderbuffer.m_shared->m_handle;
}
else
{
texture_handles[i] = bgfx::createTexture2D((uint16_t)decl.m_width,
(uint16_t)decl.m_height,
false,
1,
renderbuffer.m_format,
RenderBuffer::DEFAULT_FLAGS);
}
bgfx::setName(texture_handles[i], StaticString<128>(m_declaration.m_name, " - ", i));
m_declaration.m_renderbuffers[i].m_handle = texture_handles[i];
}
m_window_handle = nullptr;
m_handle = bgfx::createFrameBuffer((uint8_t)decl.m_renderbuffers_count, texture_handles);
ASSERT(bgfx::isValid(m_handle));
}
FrameBuffer::FrameBuffer(const char* name, int width, int height, void* window_handle)
{
m_autodestroy_handle = false;
copyString(m_declaration.m_name, name);
m_declaration.m_width = width;
m_declaration.m_height = height;
m_declaration.m_renderbuffers_count = 0;
m_window_handle = window_handle;
m_handle = bgfx::createFrameBuffer(window_handle, (uint16_t)width, (uint16_t)height);
ASSERT(bgfx::isValid(m_handle));
}
FrameBuffer::~FrameBuffer()
{
if (m_autodestroy_handle)
{
destroyRenderbuffers();
bgfx::destroy(m_handle);
}
}
void FrameBuffer::destroyRenderbuffers()
{
for (int i = 0; i < m_declaration.m_renderbuffers_count; ++i)
{
RenderBuffer& rb = m_declaration.m_renderbuffers[i];
if(!rb.m_shared) bgfx::destroy(rb.m_handle);
}
}
void FrameBuffer::resize(int width, int height)
{
if (bgfx::isValid(m_handle))
{
destroyRenderbuffers();
bgfx::destroy(m_handle);
}
m_declaration.m_width = width;
m_declaration.m_height = height;
if (m_window_handle)
{
m_handle = bgfx::createFrameBuffer(m_window_handle, (uint16_t)width, (uint16_t)height);
}
else
{
bgfx::TextureHandle texture_handles[16];
for (int i = 0; i < m_declaration.m_renderbuffers_count; ++i)
{
const RenderBuffer& renderbuffer = m_declaration.m_renderbuffers[i];
if (renderbuffer.m_shared)
{
texture_handles[i] = renderbuffer.m_shared->m_handle;
}
else
{
texture_handles[i] = bgfx::createTexture2D(
(uint16_t)width, (uint16_t)height, false, 1, renderbuffer.m_format, RenderBuffer::DEFAULT_FLAGS);
}
bgfx::setName(texture_handles[i], StaticString<128>(m_declaration.m_name, " - ", i));
m_declaration.m_renderbuffers[i].m_handle = texture_handles[i];
}
m_window_handle = nullptr;
m_handle = bgfx::createFrameBuffer((uint8_t)m_declaration.m_renderbuffers_count, texture_handles);
}
}
static bgfx::TextureFormat::Enum getFormat(const char* name)
{
static const struct { const char* name; bgfx::TextureFormat::Enum value; } FORMATS[] = {
{ "depth32", bgfx::TextureFormat::D32 },
{ "depth24", bgfx::TextureFormat::D24 },
{ "depth24stencil8", bgfx::TextureFormat::D24S8 },
{ "rgba8", bgfx::TextureFormat::RGBA8 },
{ "rgba16f", bgfx::TextureFormat::RGBA16F },
{ "r16f", bgfx::TextureFormat::R16F },
{ "r16", bgfx::TextureFormat::R16 },
{ "r32f", bgfx::TextureFormat::R32F },
};
for (auto& i : FORMATS)
{
if (equalStrings(i.name, name)) return i.value;
}
g_log_error.log("Renderer") << "Uknown texture format " << name;
return bgfx::TextureFormat::RGBA8;
}
void FrameBuffer::RenderBuffer::parse(lua_State* L)
{
if (lua_getfield(L, -1, "format") == LUA_TSTRING)
{
m_format = getFormat(lua_tostring(L, -1));
}
else
{
m_format = bgfx::TextureFormat::RGBA8;
}
lua_pop(L, 1);
}
} // namespace Lumix

View file

@ -1,88 +0,0 @@
#pragma once
#include "engine/lumix.h"
#include "engine/vec.h"
#include <bgfx/bgfx.h>
struct lua_State;
namespace Lumix
{
class JsonSerializer;
class FrameBuffer
{
public:
struct RenderBuffer
{
static const u32 DEFAULT_FLAGS = BGFX_TEXTURE_RT
| BGFX_TEXTURE_U_CLAMP
| BGFX_TEXTURE_V_CLAMP
| BGFX_TEXTURE_MIP_POINT
| BGFX_TEXTURE_MIN_POINT
| BGFX_TEXTURE_MAG_POINT;
bgfx::TextureFormat::Enum m_format;
bgfx::TextureHandle m_handle;
RenderBuffer* m_shared = nullptr;
void parse(lua_State* state);
};
struct Declaration
{
i32 m_width;
i32 m_height;
Vec2 m_size_ratio = Vec2(-1, -1);
RenderBuffer m_renderbuffers[16];
i32 m_renderbuffers_count = 0;
char m_name[64];
};
public:
explicit FrameBuffer(const Declaration& decl);
FrameBuffer(const char* name, int width, int height, void* window_handle);
~FrameBuffer();
bgfx::FrameBufferHandle getHandle() const { return m_handle; }
int getWidth() const { return m_declaration.m_width; }
int getHeight() const { return m_declaration.m_height; }
void resize(int width, int height);
Vec2 getSizeRatio() const { return m_declaration.m_size_ratio; }
const char* getName() const { return m_declaration.m_name; }
int getRenderbuffersCounts() const { return m_declaration.m_renderbuffers_count; }
RenderBuffer& getRenderbuffer(int idx)
{
ASSERT(idx < m_declaration.m_renderbuffers_count);
return m_declaration.m_renderbuffers[idx];
}
bgfx::TextureHandle& getRenderbufferHandle(int idx)
{
static bgfx::TextureHandle invalid = BGFX_INVALID_HANDLE;
if (idx >= m_declaration.m_renderbuffers_count ) return invalid;
return m_declaration.m_renderbuffers[idx].m_handle;
}
private:
void destroyRenderbuffers();
private:
bool m_autodestroy_handle;
void* m_window_handle;
bgfx::FrameBufferHandle m_handle;
Declaration m_declaration;
};
} // namespace Lumix

View file

@ -1,8 +1,8 @@
#include "renderer/material.h"
#include "engine/crc32.h"
#include "engine/fs/file_system.h"
#include "engine/json_serializer.h"
#include "engine/log.h"
#include "engine/lua_wrapper.h"
#include "engine/path_utils.h"
#include "engine/profiler.h"
#include "engine/resource_manager.h"
@ -13,7 +13,6 @@
#include "renderer/shader.h"
#include "renderer/texture.h"
namespace Lumix
{
@ -40,7 +39,9 @@ Material::Material(const Path& path, ResourceManagerBase& resource_manager, IAll
, m_uniforms(allocator)
, m_allocator(allocator)
, m_texture_count(0)
, m_render_states(BGFX_STATE_CULL_CW)
// TODO
/*
, m_render_states(BGFX_STATE_CULL_CW)*/
, m_color(1, 1, 1, 1)
, m_metallic(0)
, m_roughness(1.0f)
@ -134,10 +135,12 @@ void Material::setDefine(u8 define_idx, bool enabled)
void Material::unload()
{
// TODO
/*
if(m_command_buffer != &DEFAULT_COMMAND_BUFFER) m_allocator.deallocate(m_command_buffer);
m_command_buffer = &DEFAULT_COMMAND_BUFFER;
m_uniforms.clear();
*/
ResourceManagerBase* texture_manager = m_resource_manager.getOwner().get(Texture::TYPE);
for (int i = 0; i < m_texture_count; i++)
{
@ -163,8 +166,11 @@ void Material::unload()
}
bool Material::save(JsonSerializer& serializer)
bool Material::save(OutputBlob& blob)
{
// TODO
ASSERT(false);
/*
if(!isReady()) return false;
if(!m_shader) return false;
@ -294,13 +300,16 @@ bool Material::save(JsonSerializer& serializer)
serializer.serializeArrayItem(m_color.z);
serializer.serializeArrayItem(m_color.w);
serializer.endArray();
serializer.endObject();
serializer.endObject();*/
return true;
}
void Material::deserializeCustomFlags(JsonDeserializer& serializer)
void Material::deserializeCustomFlags(lua_State* L)
{
// TODO
ASSERT(false);
/*
m_custom_flags = 0;
serializer.deserializeArrayBegin();
while (!serializer.isArrayEnd())
@ -309,13 +318,16 @@ void Material::deserializeCustomFlags(JsonDeserializer& serializer)
serializer.deserializeArrayItem(tmp, lengthOf(tmp), "");
setCustomFlag(getCustomFlag(tmp));
}
serializer.deserializeArrayEnd();
serializer.deserializeArrayEnd();*/
}
void Material::deserializeDefines(JsonDeserializer& serializer)
void Material::deserializeDefines(lua_State* L)
{
auto& renderer = static_cast<MaterialManager&>(m_resource_manager).getRenderer();
// TODO
ASSERT(false);
/*
auto& renderer = static_cast<MaterialManager&>(m_resource_manager).getRenderer();
serializer.deserializeArrayBegin();
m_define_mask = 0;
while (!serializer.isArrayEnd())
@ -324,13 +336,16 @@ void Material::deserializeDefines(JsonDeserializer& serializer)
serializer.deserializeArrayItem(tmp, lengthOf(tmp), "");
m_define_mask |= 1 << renderer.getShaderDefineIdx(tmp);
}
serializer.deserializeArrayEnd();
serializer.deserializeArrayEnd();*/
}
void Material::deserializeUniforms(JsonDeserializer& serializer)
void Material::deserializeUniforms(lua_State* L)
{
serializer.deserializeArrayBegin();
// TODO
ASSERT(false);
/*
serializer.deserializeArrayBegin();
m_uniforms.clear();
while (!serializer.isArrayEnd())
{
@ -398,7 +413,7 @@ void Material::deserializeUniforms(JsonDeserializer& serializer)
}
serializer.deserializeObjectEnd();
}
serializer.deserializeArrayEnd();
serializer.deserializeArrayEnd();*/
}
@ -440,7 +455,6 @@ void Material::setRenderLayer(int layer)
void Material::setTexture(int i, Texture* texture)
{
Texture* old_texture = i < m_texture_count ? m_textures[i] : nullptr;
if (!texture && m_shader && m_shader->m_texture_slots[i].default_texture)
{
texture = m_shader->m_texture_slots[i].default_texture;
@ -469,8 +483,9 @@ void Material::setTexture(int i, Texture* texture)
}
}
createCommandBuffer();
m_shader_instance = &m_shader->getInstance(m_define_mask);
// TODO
//createCommandBuffer();
//m_shader_instance = &m_shader->getInstance(m_define_mask);
}
}
@ -484,7 +499,7 @@ void Material::setShader(const Path& path)
void Material::createCommandBuffer()
{
if (m_command_buffer != &DEFAULT_COMMAND_BUFFER) m_allocator.deallocate(m_command_buffer);
/* if (m_command_buffer != &DEFAULT_COMMAND_BUFFER) m_allocator.deallocate(m_command_buffer);
m_command_buffer = &DEFAULT_COMMAND_BUFFER;
if (!m_shader) return;
@ -532,12 +547,16 @@ void Material::createCommandBuffer()
generator.end();
m_command_buffer = (u8*)m_allocator.allocate(generator.getSize());
generator.getData(m_command_buffer);
generator.getData(m_command_buffer);*/
ASSERT(false);
// TODO
}
void Material::onBeforeReady()
{
// TODO
/*
if (!m_shader) return;
for(int i = 0; i < m_shader->m_uniforms.size(); ++i)
@ -593,7 +612,7 @@ void Material::onBeforeReady()
}
createCommandBuffer();
m_shader_instance = &m_shader->getInstance(m_define_mask);
m_shader_instance = &m_shader->getInstance(m_define_mask);*/
}
@ -621,7 +640,7 @@ void Material::setShader(Shader* shader)
}
const char* Material::getTextureUniform(int i)
const char* Material::getTextureUniform(int i) const
{
if (i < m_shader->m_texture_slot_count) return m_shader->m_texture_slots[i].uniform;
return "";
@ -630,6 +649,9 @@ const char* Material::getTextureUniform(int i)
Texture* Material::getTextureByUniform(const char* uniform) const
{
// TODO
ASSERT(false);
/*
if (!m_shader) return nullptr;
for (int i = 0, c = m_shader->m_texture_slot_count; i < c; ++i)
@ -638,13 +660,16 @@ Texture* Material::getTextureByUniform(const char* uniform) const
{
return m_textures[i];
}
}
}*/
return nullptr;
}
bool Material::isTextureDefine(u8 define_idx) const
{
// TODO
ASSERT(false);
/*
if (!m_shader) return false;
for (int i = 0, c = m_shader->m_texture_slot_count; i < c; ++i)
@ -653,13 +678,16 @@ bool Material::isTextureDefine(u8 define_idx) const
{
return true;
}
}
}*/
return false;
}
bool Material::deserializeTexture(JsonDeserializer& serializer, const char* material_dir)
bool Material::deserializeTexture(lua_State* L, const char* material_dir)
{
char path[MAX_PATH_LENGTH];
// TODO
ASSERT(false);
/*
char path[MAX_PATH_LENGTH];
serializer.deserializeObjectBegin();
char label[256];
bool keep_data = false;
@ -764,7 +792,7 @@ bool Material::deserializeTexture(JsonDeserializer& serializer, const char* mate
}
}
serializer.deserializeObjectEnd();
++m_texture_count;
++m_texture_count;*/
return true;
}
@ -772,38 +800,94 @@ bool Material::deserializeTexture(JsonDeserializer& serializer, const char* mate
void Material::setAlphaRef(float value)
{
m_alpha_ref = value;
u8 val = u8(value * 255.0f);
m_render_states &= ~BGFX_STATE_ALPHA_REF_MASK;
m_render_states |= BGFX_STATE_ALPHA_REF(val);
}
void Material::enableBackfaceCulling(bool enable)
{
if (enable)
// TODO
ASSERT(false);
/*
if (enable)
{
m_render_states |= BGFX_STATE_CULL_CW;
}
else
{
m_render_states &= ~BGFX_STATE_CULL_MASK;
}
}*/
}
bool Material::isBackfaceCulling() const
{
return (m_render_states & BGFX_STATE_CULL_MASK) != 0;
// TODO
ASSERT(false);
/*
return (m_render_states & BGFX_STATE_CULL_MASK) != 0;*/
return true;
}
namespace LuaAPI
{
int shader(lua_State* L)
{
const char* path = LuaWrapper::checkArg<const char*>(L, 1);
lua_getfield(L, LUA_GLOBALSINDEX, "this");
Material* material = (Material*)lua_touserdata(L, -1);
lua_pop(L, 1);
material->setShader(Path(path));
return 0;
}
int texture(lua_State* L)
{
const char* path = LuaWrapper::checkArg<const char*>(L, 1);
lua_getfield(L, LUA_GLOBALSINDEX, "this");
Material* material = (Material*)lua_touserdata(L, -1);
lua_pop(L, 1);
const int idx = material->getTextureCount();
material->setTexturePath(idx, Path(path));
return 0;
}
} // namespace LuaAPI
bool Material::load(FS::IFile& file)
{
PROFILE_FUNCTION();
m_render_states = BGFX_STATE_CULL_CW;
lua_State* L = luaL_newstate();
lua_pushlightuserdata(L, this);
lua_setfield(L, LUA_GLOBALSINDEX, "this");
lua_pushcclosure(L, LuaAPI::shader, 0);
lua_setfield(L, LUA_GLOBALSINDEX, "shader");
lua_pushcclosure(L, LuaAPI::texture, 0);
lua_setfield(L, LUA_GLOBALSINDEX, "texture");
setAlphaRef(DEFAULT_ALPHA_REF_VALUE);
const StringView content((const char*)file.getBuffer(), (int)file.size());
if (!LuaWrapper::execute(L, content, getPath().c_str(), 0)) {
lua_close(L);
return false;
}
lua_close(L);
return true;
// TODO
ASSERT(false);
/*
m_render_states = BGFX_STATE_CULL_CW;
m_uniforms.clear();
JsonDeserializer serializer(file, getPath(), m_allocator);
serializer.deserializeObjectBegin();
char label[256];
@ -851,6 +935,9 @@ bool Material::load(FS::IFile& file)
{
bool b = true;
serializer.deserialize(b, true);
// TODO
ASSERT(false);
/*
if (b)
{
m_render_states |= BGFX_STATE_CULL_CW;
@ -858,7 +945,7 @@ bool Material::load(FS::IFile& file)
else
{
m_render_states &= ~BGFX_STATE_CULL_MASK;
}
}*//*
}
else if (equalStrings(label, "color"))
{
@ -897,12 +984,11 @@ bool Material::load(FS::IFile& file)
}
else
{
g_log_error.log("Renderer") << "Unknown parameter " << label << " in material "
<< getPath();
g_log_error.log("Renderer") << "Unknown parameter " << label << " in material " << getPath();
}
}
serializer.deserializeObjectEnd();
*/
if (!m_shader)
{
g_log_error.log("Renderer") << "Material " << getPath() << " without a shader";

View file

@ -6,6 +6,8 @@
#include "engine/vec.h"
struct lua_State;
namespace Lumix
{
@ -14,8 +16,6 @@ namespace FS
struct IFile;
}
class JsonDeserializer;
class JsonSerializer;
class ResourceManager;
class Shader;
struct ShaderInstance;
@ -26,12 +26,6 @@ class LUMIX_RENDERER_API Material LUMIX_FINAL : public Resource
{
friend class MaterialManager;
public:
enum class DepthFunc
{
LEQUAL,
LESS
};
struct Uniform
{
u32 name_hash;
@ -74,12 +68,12 @@ public:
int getTextureCount() const { return m_texture_count; }
Texture* getTexture(int i) const { return i < m_texture_count ? m_textures[i] : nullptr; }
const char* getTextureUniform(int i);
const char* getTextureUniform(int i) const;
Texture* getTextureByUniform(const char* uniform) const;
bool isTextureDefine(u8 define_idx) const;
void setTexture(int i, Texture* texture);
void setTexturePath(int i, const Path& path);
bool save(JsonSerializer& serializer);
bool save(OutputBlob& blob);
int getUniformCount() const { return m_uniforms.size(); }
Uniform& getUniform(int index) { return m_uniforms[index]; }
const Uniform& getUniform(int index) const { return m_uniforms[index]; }
@ -110,10 +104,10 @@ private:
void unload() override;
bool load(FS::IFile& file) override;
bool deserializeTexture(JsonDeserializer& serializer, const char* material_dir);
void deserializeUniforms(JsonDeserializer& serializer);
void deserializeDefines(JsonDeserializer& serializer);
void deserializeCustomFlags(JsonDeserializer& serializer);
bool deserializeTexture(lua_State* L, const char* material_dir);
void deserializeUniforms(lua_State* L);
void deserializeDefines(lua_State* L);
void deserializeCustomFlags(lua_State* L);
private:
static const int MAX_TEXTURE_COUNT = 16;

View file

@ -24,8 +24,9 @@ namespace Lumix
Mesh::Mesh(Material* mat,
const bgfx::VertexDecl& vertex_decl,
const ffr::VertexDecl& vertex_decl,
const char* name,
const AttributeSemantic* semantics,
IAllocator& allocator)
: name(name, allocator)
, vertex_decl(vertex_decl)
@ -35,6 +36,12 @@ Mesh::Mesh(Material* mat,
, uvs(allocator)
, skin(allocator)
{
for(AttributeSemantic& attr : attributes_semantic) {
attr = AttributeSemantic::NONE;
}
for(uint i = 0; i < vertex_decl.attributes_count; ++i) {
attributes_semantic[i] = semantics[i];
}
}
@ -52,10 +59,31 @@ void Mesh::set(const Mesh& rhs)
vertex_buffer_handle = rhs.vertex_buffer_handle;
index_buffer_handle = rhs.index_buffer_handle;
name = rhs.name;
copyMemory(attributes_semantic, rhs.attributes_semantic, sizeof(attributes_semantic));
// all except material
}
int Mesh::getAttributeOffset(AttributeSemantic attr) const
{
for (int i = 0; i < lengthOf(attributes_semantic); ++i) {
if(attributes_semantic[i] == attr) {
return vertex_decl.attributes[i].offset;
}
}
return -1;
}
bool Mesh::hasAttribute(AttributeSemantic attribute) const
{
for(const AttributeSemantic& attr : attributes_semantic) {
if(attr == attribute) return true;
}
return false;
}
void Mesh::setMaterial(Material* new_material, Model& model, Renderer& renderer)
{
if (material) material->getResourceManager().unload(*material);
@ -256,116 +284,44 @@ void Model::getPose(Pose& pose)
}
bool Model::parseVertexDecl(FS::IFile& file, bgfx::VertexDecl* vertex_decl)
static bool parseVertexDecl(FS::IFile& file, ffr::VertexDecl* vertex_decl, Mesh::AttributeSemantic* semantics)
{
vertex_decl->begin();
u32 attribute_count;
file.read(&attribute_count, sizeof(attribute_count));
for (u32 i = 0; i < attribute_count; ++i)
{
char tmp[50];
u32 len;
file.read(&len, sizeof(len));
if (len > sizeof(tmp) - 1)
{
return false;
}
file.read(tmp, len);
tmp[len] = '\0';
if (equalStrings(tmp, "in_position"))
{
vertex_decl->add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
}
else if (equalStrings(tmp, "in_colors"))
{
vertex_decl->add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true, false);
}
else if (equalStrings(tmp, "in_tex_coords"))
{
vertex_decl->add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
}
else if (equalStrings(tmp, "in_normal"))
{
vertex_decl->add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
}
else if (equalStrings(tmp, "in_tangents"))
{
vertex_decl->add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
}
else if (equalStrings(tmp, "in_weights"))
{
vertex_decl->add(bgfx::Attrib::Weight, 4, bgfx::AttribType::Float);
}
else if (equalStrings(tmp, "in_indices"))
{
vertex_decl->add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Int16, false, true);
}
else
{
ASSERT(false);
return false;
}
u32 type;
file.read(&type, sizeof(type));
}
vertex_decl->end();
return true;
}
bool Model::parseVertexDeclEx(FS::IFile& file, bgfx::VertexDecl* vertex_decl)
{
vertex_decl->begin();
u32 attribute_count;
file.read(&attribute_count, sizeof(attribute_count));
vertex_decl->attributes_count = 0;
for (u32 i = 0; i < attribute_count; ++i)
{
i32 attr;
file.read(&attr, sizeof(attr));
semantics[i] = (Mesh::AttributeSemantic)attr;
if (attr == (i32)Attrs::Position)
{
vertex_decl->add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
}
else if (attr == (i32)Attrs::Color0)
{
vertex_decl->add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true, false);
}
else if (attr == (i32)Attrs::TexCoord0)
{
vertex_decl->add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
}
else if (attr == (i32)Attrs::Normal)
{
vertex_decl->add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
}
else if (attr == (i32)Attrs::Tangent)
{
vertex_decl->add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
}
else if (attr == (i32)Attrs::Weight)
{
vertex_decl->add(bgfx::Attrib::Weight, 4, bgfx::AttribType::Float);
}
else if (attr == (i32)Attrs::Indices)
{
vertex_decl->add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Int16, false, true);
}
else
{
ASSERT(false);
return false;
switch(semantics[i]) {
case Mesh::AttributeSemantic::POSITION:
vertex_decl->addAttribute(3, ffr::AttributeType::FLOAT, false, false);
break;
case Mesh::AttributeSemantic::COLOR0:
vertex_decl->addAttribute(4, ffr::AttributeType::U8, true, false);
break;
case Mesh::AttributeSemantic::TEXCOORD0:
vertex_decl->addAttribute(2, ffr::AttributeType::FLOAT, false, false);
break;
case Mesh::AttributeSemantic::NORMAL:
vertex_decl->addAttribute(4, ffr::AttributeType::U8, true, true);
break;
case Mesh::AttributeSemantic::TANGENT:
vertex_decl->addAttribute(4, ffr::AttributeType::U8, true, true);
break;
case Mesh::AttributeSemantic::WEIGHTS:
vertex_decl->addAttribute(4, ffr::AttributeType::FLOAT, false, false);
break;
case Mesh::AttributeSemantic::INDICES:
vertex_decl->addAttribute(4, ffr::AttributeType::I16, false, true);
break;
default: ASSERT(false); break;
}
}
vertex_decl->end();
return true;
}
@ -505,10 +461,8 @@ int Model::getBoneIdx(const char* name)
}
bool Model::parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& file, FileVersion version, u32 global_flags)
bool Model::parseMeshes(FS::IFile& file, FileVersion version)
{
if (version <= FileVersion::MULTIPLE_VERTEX_DECLS) return parseMeshesOld(global_vertex_decl, file, version, global_flags);
int object_count = 0;
file.read(&object_count, sizeof(object_count));
if (object_count <= 0) return false;
@ -519,8 +473,10 @@ bool Model::parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& f
m_meshes.reserve(object_count);
for (int i = 0; i < object_count; ++i)
{
bgfx::VertexDecl vertex_decl;
if (!parseVertexDeclEx(file, &vertex_decl)) return false;
ffr::VertexDecl vertex_decl;
Mesh::AttributeSemantic semantics[ffr::VertexDecl::MAX_ATTRIBUTES];
for(auto& i : semantics) i = Mesh::AttributeSemantic::NONE;
if (!parseVertexDecl(file, &vertex_decl, semantics)) return false;
i32 str_size;
file.read(&str_size, sizeof(str_size));
@ -543,7 +499,7 @@ bool Model::parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& f
mesh_name[str_size] = 0;
file.read(mesh_name, str_size);
m_meshes.emplace(material, vertex_decl, mesh_name, m_allocator);
m_meshes.emplace(material, vertex_decl, mesh_name, semantics, m_allocator);
addDependency(*material);
}
@ -561,8 +517,7 @@ bool Model::parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& f
if (index_size == 2) mesh.flags.set(Mesh::Flags::INDICES_16_BIT);
mesh.indices_count = indices_count;
const bgfx::Memory* indices_mem = bgfx::copy(&mesh.indices[0], mesh.indices.size());
mesh.index_buffer_handle = bgfx::createIndexBuffer(indices_mem);
mesh.index_buffer_handle = ffr::createBuffer(mesh.indices.size(), &mesh.indices[0]);
}
for (int i = 0; i < object_count; ++i)
@ -570,22 +525,22 @@ bool Model::parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& f
Mesh& mesh = m_meshes[i];
int data_size;
file.read(&data_size, sizeof(data_size));
const bgfx::Memory* vertices_mem = bgfx::alloc(data_size);
file.read(vertices_mem->data, vertices_mem->size);
Array<u8> vertices_mem(m_allocator);
vertices_mem.resize(data_size);
file.read(&vertices_mem[0], data_size);
const bgfx::VertexDecl& vertex_decl = mesh.vertex_decl;
int position_attribute_offset = vertex_decl.getOffset(bgfx::Attrib::Position);
int uv_attribute_offset = vertex_decl.getOffset(bgfx::Attrib::TexCoord0);
int weights_attribute_offset = vertex_decl.getOffset(bgfx::Attrib::Weight);
int bone_indices_attribute_offset = vertex_decl.getOffset(bgfx::Attrib::Indices);
bool keep_skin = vertex_decl.has(bgfx::Attrib::Weight) && vertex_decl.has(bgfx::Attrib::Indices);
int position_attribute_offset = mesh.getAttributeOffset(Mesh::AttributeSemantic::POSITION);
int uv_attribute_offset = mesh.getAttributeOffset(Mesh::AttributeSemantic::TEXCOORD0);
int weights_attribute_offset = mesh.getAttributeOffset(Mesh::AttributeSemantic::WEIGHTS);
int bone_indices_attribute_offset = mesh.getAttributeOffset(Mesh::AttributeSemantic::INDICES);
bool keep_skin = mesh.hasAttribute(Mesh::AttributeSemantic::WEIGHTS) && mesh.hasAttribute(Mesh::AttributeSemantic::INDICES);
int vertex_size = mesh.vertex_decl.getStride();
int mesh_vertex_count = vertices_mem->size / mesh.vertex_decl.getStride();
int vertex_size = mesh.vertex_decl.size;
int mesh_vertex_count = vertices_mem.size() / mesh.vertex_decl.size;
mesh.vertices.resize(mesh_vertex_count);
mesh.uvs.resize(mesh_vertex_count);
if (keep_skin) mesh.skin.resize(mesh_vertex_count);
const u8* vertices = vertices_mem->data;
const u8* vertices = &vertices_mem[0];
for (int j = 0; j < mesh_vertex_count; ++j)
{
int offset = j * vertex_size;
@ -599,7 +554,7 @@ bool Model::parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& f
mesh.vertices[j] = *(const Vec3*)&vertices[offset + position_attribute_offset];
mesh.uvs[j] = *(const Vec2*)&vertices[offset + uv_attribute_offset];
}
mesh.vertex_buffer_handle = bgfx::createVertexBuffer(vertices_mem, mesh.vertex_decl);
mesh.vertex_buffer_handle = ffr::createBuffer(vertices_mem.size(), &vertices_mem[0]);
}
file.read(&m_bounding_radius, sizeof(m_bounding_radius));
file.read(&m_aabb, sizeof(m_aabb));
@ -608,185 +563,6 @@ bool Model::parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& f
}
bool Model::parseMeshesOld(bgfx::VertexDecl global_vertex_decl, FS::IFile& file, FileVersion version, u32 global_flags)
{
int object_count = 0;
file.read(&object_count, sizeof(object_count));
if (object_count <= 0) return false;
m_meshes.reserve(object_count);
char model_dir[MAX_PATH_LENGTH];
PathUtils::getDir(model_dir, MAX_PATH_LENGTH, getPath().c_str());
struct Offsets
{
i32 attribute_array_offset;
i32 attribute_array_size;
i32 indices_offset;
i32 mesh_tri_count;
};
Array<Offsets> mesh_offsets(m_allocator);
for (int i = 0; i < object_count; ++i)
{
i32 str_size;
file.read(&str_size, sizeof(str_size));
char material_name[MAX_PATH_LENGTH];
file.read(material_name, str_size);
if (str_size >= MAX_PATH_LENGTH) return false;
material_name[str_size] = 0;
char material_path[MAX_PATH_LENGTH];
copyString(material_path, model_dir);
catString(material_path, material_name);
catString(material_path, ".mat");
auto* material_manager = m_resource_manager.getOwner().get(Material::TYPE);
Material* material = static_cast<Material*>(material_manager->load(Path(material_path)));
Offsets& offsets = mesh_offsets.emplace();
file.read(&offsets.attribute_array_offset, sizeof(offsets.attribute_array_offset));
file.read(&offsets.attribute_array_size, sizeof(offsets.attribute_array_size));
file.read(&offsets.indices_offset, sizeof(offsets.indices_offset));
file.read(&offsets.mesh_tri_count, sizeof(offsets.mesh_tri_count));
file.read(&str_size, sizeof(str_size));
if (str_size >= MAX_PATH_LENGTH)
{
material_manager->unload(*material);
return false;
}
char mesh_name[MAX_PATH_LENGTH];
mesh_name[str_size] = 0;
file.read(mesh_name, str_size);
bgfx::VertexDecl vertex_decl = global_vertex_decl;
if (version <= FileVersion::SINGLE_VERTEX_DECL)
{
parseVertexDecl(file, &vertex_decl);
if (i != 0 && global_vertex_decl.m_hash != vertex_decl.m_hash)
{
g_log_error.log("Renderer") << "Model " << getPath().c_str()
<< " contains meshes with different vertex declarations.";
}
if(i == 0) global_vertex_decl = vertex_decl;
}
m_meshes.emplace(material,
vertex_decl,
mesh_name,
m_allocator);
addDependency(*material);
}
i32 indices_count = 0;
file.read(&indices_count, sizeof(indices_count));
if (indices_count <= 0) return false;
u32 INDICES_16BIT_FLAG = 1;
int index_size = global_flags & INDICES_16BIT_FLAG ? 2 : 4;
Array<u8> indices(m_allocator);
indices.resize(indices_count * index_size);
file.read(&indices[0], indices.size());
i32 vertices_size = 0;
file.read(&vertices_size, sizeof(vertices_size));
if (vertices_size <= 0) return false;
Array<u8> vertices(m_allocator);
vertices.resize(vertices_size);
file.read(&vertices[0], vertices.size());
int vertex_count = 0;
for (const Offsets& offsets : mesh_offsets)
{
vertex_count += offsets.attribute_array_size / global_vertex_decl.getStride();
}
if (version > FileVersion::BOUNDING_SHAPES_PRECOMPUTED)
{
file.read(&m_bounding_radius, sizeof(m_bounding_radius));
file.read(&m_aabb, sizeof(m_aabb));
}
float bounding_radius_squared = 0;
Vec3 min_vertex(0, 0, 0);
Vec3 max_vertex(0, 0, 0);
int vertex_size = global_vertex_decl.getStride();
int position_attribute_offset = global_vertex_decl.getOffset(bgfx::Attrib::Position);
int uv_attribute_offset = global_vertex_decl.getOffset(bgfx::Attrib::TexCoord0);
int weights_attribute_offset = global_vertex_decl.getOffset(bgfx::Attrib::Weight);
int bone_indices_attribute_offset = global_vertex_decl.getOffset(bgfx::Attrib::Indices);
bool keep_skin = global_vertex_decl.has(bgfx::Attrib::Weight) && global_vertex_decl.has(bgfx::Attrib::Indices);
for (int i = 0; i < m_meshes.size(); ++i)
{
Offsets& offsets = mesh_offsets[i];
Mesh& mesh = m_meshes[i];
mesh.indices_count = offsets.mesh_tri_count * 3;
mesh.indices.resize(mesh.indices_count * index_size);
copyMemory(&mesh.indices[0], &indices[offsets.indices_offset * index_size], mesh.indices_count * index_size);
int mesh_vertex_count = offsets.attribute_array_size / global_vertex_decl.getStride();
int mesh_attributes_array_offset = offsets.attribute_array_offset;
mesh.vertices.resize(mesh_vertex_count);
mesh.uvs.resize(mesh_vertex_count);
if (keep_skin) mesh.skin.resize(mesh_vertex_count);
for (int j = 0; j < mesh_vertex_count; ++j)
{
int offset = mesh_attributes_array_offset + j * vertex_size;
if (keep_skin)
{
mesh.skin[j].weights = *(const Vec4*)&vertices[offset + weights_attribute_offset];
copyMemory(mesh.skin[j].indices,
&vertices[offset + bone_indices_attribute_offset],
sizeof(mesh.skin[j].indices));
}
mesh.vertices[j] = *(const Vec3*)&vertices[offset + position_attribute_offset];
mesh.uvs[j] = *(const Vec2*)&vertices[offset + uv_attribute_offset];
float sq_len = mesh.vertices[j].squaredLength();
bounding_radius_squared = Math::maximum(bounding_radius_squared, sq_len > 0 ? sq_len : 0);
min_vertex.x = Math::minimum(min_vertex.x, mesh.vertices[j].x);
min_vertex.y = Math::minimum(min_vertex.y, mesh.vertices[j].y);
min_vertex.z = Math::minimum(min_vertex.z, mesh.vertices[j].z);
max_vertex.x = Math::maximum(max_vertex.x, mesh.vertices[j].x);
max_vertex.y = Math::maximum(max_vertex.y, mesh.vertices[j].y);
max_vertex.z = Math::maximum(max_vertex.z, mesh.vertices[j].z);
}
}
if (version <= FileVersion::BOUNDING_SHAPES_PRECOMPUTED)
{
m_bounding_radius = sqrt(bounding_radius_squared);
m_aabb = AABB(min_vertex, max_vertex);
}
for (int i = 0; i < m_meshes.size(); ++i)
{
Mesh& mesh = m_meshes[i];
Offsets offsets = mesh_offsets[i];
ASSERT(!bgfx::isValid(mesh.index_buffer_handle));
if (global_flags & INDICES_16BIT_FLAG)
{
mesh.flags.set(Mesh::Flags::INDICES_16_BIT);
}
int indices_size = index_size * mesh.indices_count;
const bgfx::Memory* mem = bgfx::copy(&indices[offsets.indices_offset * index_size], indices_size);
mesh.index_buffer_handle = bgfx::createIndexBuffer(mem, index_size == 4 ? BGFX_BUFFER_INDEX32 : 0);
if (!bgfx::isValid(mesh.index_buffer_handle)) return false;
ASSERT(!bgfx::isValid(mesh.vertex_buffer_handle));
const bgfx::Memory* vertices_mem = bgfx::copy(&vertices[offsets.attribute_array_offset], offsets.attribute_array_size);
mesh.vertex_buffer_handle = bgfx::createVertexBuffer(vertices_mem, mesh.vertex_decl);
if (!bgfx::isValid(mesh.vertex_buffer_handle)) return false;
}
return true;
}
bool Model::parseLODs(FS::IFile& file)
{
i32 lod_count;
@ -808,7 +584,7 @@ bool Model::parseLODs(FS::IFile& file)
bool Model::load(FS::IFile& file)
{
PROFILE_FUNCTION();
/*FileHeader header;
FileHeader header;
file.read(&header, sizeof(header));
if (header.magic != FILE_MAGIC)
@ -823,19 +599,7 @@ bool Model::load(FS::IFile& file)
return false;
}
u32 global_flags = 0; // backward compatibility
if(header.version > (u32)FileVersion::WITH_FLAGS)
{
file.read(&global_flags, sizeof(global_flags));
}
bgfx::VertexDecl global_vertex_decl;
if (header.version > (u32)FileVersion::SINGLE_VERTEX_DECL && header.version <= (u32)FileVersion::MULTIPLE_VERTEX_DECLS)
{
parseVertexDeclEx(file, &global_vertex_decl);
}
if (parseMeshes(global_vertex_decl, file, (FileVersion)header.version, global_flags)
if (parseMeshes(file, (FileVersion)header.version)
&& parseBones(file)
&& parseLODs(file))
{
@ -843,7 +607,7 @@ bool Model::load(FS::IFile& file)
return true;
}
g_log_error.log("Renderer") << "Error loading model " << getPath().c_str();*/
g_log_error.log("Renderer") << "Error loading model " << getPath().c_str();
return false;
}
@ -896,8 +660,8 @@ void Model::unload()
}
for (Mesh& mesh : m_meshes)
{
if (bgfx::isValid(mesh.index_buffer_handle)) bgfx::destroy(mesh.index_buffer_handle);
if (bgfx::isValid(mesh.vertex_buffer_handle)) bgfx::destroy(mesh.vertex_buffer_handle);
if (mesh.index_buffer_handle.isValid()) ffr::destroy(mesh.index_buffer_handle);
if (mesh.vertex_buffer_handle.isValid()) ffr::destroy(mesh.vertex_buffer_handle);
}
m_meshes.clear();
m_bones.clear();

View file

@ -9,7 +9,7 @@
#include "engine/string.h"
#include "engine/vec.h"
#include "engine/resource.h"
#include <bgfx/bgfx.h>
#include "ffr/ffr.h"
struct lua_State;
@ -48,6 +48,22 @@ struct LUMIX_RENDERER_API RayCastModelHit
struct LUMIX_RENDERER_API Mesh
{
enum class AttributeSemantic : u8
{
POSITION,
NORMAL,
TANGENT,
BITANGENT,
COLOR0,
COLOR1,
INDICES,
WEIGHTS,
TEXCOORD0,
TEXCOORD1,
NONE = 0xff
};
struct Skin
{
Vec4 weights;
@ -69,15 +85,16 @@ struct LUMIX_RENDERER_API Mesh
};
Mesh(Material* mat,
const bgfx::VertexDecl& vertex_decl,
const ffr::VertexDecl& vertex_decl,
const char* name,
const AttributeSemantic* semantics,
IAllocator& allocator);
void set(const Mesh& rhs);
void setMaterial(Material* material, Model& model, Renderer& renderer);
bool areIndices16() const { return flags.isSet(Flags::INDICES_16_BIT); }
int getAttributeOffset(AttributeSemantic attr) const;
bool hasAttribute(AttributeSemantic attr) const;
Type type;
Array<u8> indices;
@ -87,9 +104,10 @@ struct LUMIX_RENDERER_API Mesh
FlagSet<Flags, u8> flags;
u64 layer_mask;
int indices_count;
bgfx::VertexDecl vertex_decl;
bgfx::VertexBufferHandle vertex_buffer_handle = BGFX_INVALID_HANDLE;
bgfx::IndexBufferHandle index_buffer_handle = BGFX_INVALID_HANDLE;
ffr::VertexDecl vertex_decl;
AttributeSemantic attributes_semantic[ffr::VertexDecl::MAX_ATTRIBUTES];
ffr::BufferHandle vertex_buffer_handle = ffr::INVALID_BUFFER;
ffr::BufferHandle index_buffer_handle = ffr::INVALID_BUFFER;
string name;
Material* material;
};
@ -106,27 +124,7 @@ class LUMIX_RENDERER_API Model LUMIX_FINAL : public Resource
{
public:
typedef HashMap<u32, int> BoneMap;
enum class Attrs
{
Position,
Normal,
Tangent,
Bitangent,
Color0,
Color1,
Indices,
Weight,
TexCoord0,
TexCoord1,
TexCoord2,
TexCoord3,
TexCoord4,
TexCoord5,
TexCoord6,
TexCoord7,
};
#pragma pack(1)
struct FileHeader
{
@ -137,12 +135,6 @@ public:
enum class FileVersion : u32
{
FIRST,
WITH_FLAGS,
SINGLE_VERTEX_DECL,
BOUNDING_SHAPES_PRECOMPUTED,
MULTIPLE_VERTEX_DECLS,
LATEST // keep this last
};
@ -211,18 +203,15 @@ public:
static void registerLuaAPI(lua_State* L);
public:
static const u32 FILE_MAGIC = 0x5f4c4d4f; // == '_LMO'
static const u32 FILE_MAGIC = 0x5f4c4d4f; // == '_LM2'
static const int MAX_LOD_COUNT = 4;
private:
Model(const Model&);
void operator=(const Model&);
bool parseVertexDecl(FS::IFile& file, bgfx::VertexDecl* vertex_decl);
bool parseVertexDeclEx(FS::IFile& file, bgfx::VertexDecl* vertex_decl);
bool parseBones(FS::IFile& file);
bool parseMeshes(const bgfx::VertexDecl& global_vertex_decl, FS::IFile& file, FileVersion version, u32 global_flags);
bool parseMeshesOld(bgfx::VertexDecl global_vertex_decl, FS::IFile& file, FileVersion version, u32 global_flags);
bool parseMeshes(FS::IFile& file, FileVersion version);
bool parseLODs(FS::IFile& file);
int getBoneIdx(const char* name);

View file

@ -339,7 +339,7 @@ LUMIX_FORCE_INLINE void rasterizeOccludingTriangle(Vec4 (&vertices)[64 * 3], int
if (triangle_mask & POSITIVE_Y) clipTriangles(Vec4(0.0f, -1.0f, 0.0f, 1.0f), vertices, triangles, triangles_count);
if (triangle_mask & NEGATIVE_Y) clipTriangles(Vec4(0.0f, 1.0f, 0.0f, 1.0f), vertices, triangles, triangles_count);
if (triangle_mask & POSITIVE_Z) clipTriangles(Vec4(0.0f, 0.0f, -1.0f, 1.0f), vertices, triangles, triangles_count);
bool is_homogenous_depth = bgfx::getCaps()->homogeneousDepth;
bool is_homogenous_depth = ffr::isHomogenousDepth();
if (triangle_mask & NEGATIVE_Z) clipTriangles(Vec4(0.0f, 0.0f, 1.0f, is_homogenous_depth ? 1.0f : 0.0f), vertices, triangles, triangles_count);
for (int i = 0; i < triangles_count; ++i)

View file

@ -13,7 +13,6 @@
#include "renderer/render_scene.h"
#include "engine/universe/universe.h"
#include <cmath>
#include <bgfx/bgfx.h>
namespace Lumix
@ -656,7 +655,8 @@ void ScriptedParticleEmitter::update(float dt)
}
}
// TODO
/*
bgfx::InstanceDataBuffer ScriptedParticleEmitter::generateInstanceBuffer() const
{
bgfx::InstanceDataBuffer buffer;
@ -716,7 +716,7 @@ bgfx::InstanceDataBuffer ScriptedParticleEmitter::generateInstanceBuffer() const
break;
}
}
}
}*/
template <typename T>

File diff suppressed because it is too large Load diff

View file

@ -1,153 +1,67 @@
#pragma once
#include "engine/lumix.h"
#include "engine/delegate.h"
#include "engine/matrix.h"
struct lua_State;
namespace bgfx
{
struct DynamicVertexBufferHandle;
struct DynamicIndexBufferHandle;
struct TextureHandle;
struct UniformHandle;
struct ProgramHandle;
struct TransientVertexBuffer;
struct TransientIndexBuffer;
struct VertexDecl;
struct VertexBufferHandle;
struct IndexBufferHandle;
struct InstanceDataBuffer;
}
namespace Lumix
{
namespace ffr { struct TextureHandle; }
struct Draw2D;
class FrameBuffer;
struct IAllocator;
struct Matrix;
class Material;
class Model;
class Path;
struct Pose;
class Renderer;
class RenderScene;
struct Vec4;
struct CommandBufferGenerator
{
CommandBufferGenerator();
void setTexture(u8 stage,
const bgfx::UniformHandle& uniform,
const bgfx::TextureHandle& texture,
u32 flags = 0xffffFFFF);
void setUniform(const bgfx::UniformHandle& uniform, const Vec4& value);
void setUniform(const bgfx::UniformHandle& uniform, const Vec4* values, int count);
void setUniform(const bgfx::UniformHandle& uniform, const Matrix* values, int count);
void setTimeUniform(const bgfx::UniformHandle& uniform);
void setLocalShadowmap(const bgfx::TextureHandle& shadowmap);
void setGlobalShadowmap();
int getSize() const { return int(pointer - buffer); }
void getData(u8* data);
void clear();
void beginAppend();
void end();
u8 buffer[1024];
u8* pointer;
};
template <typename T> class Delegate;
class LUMIX_RENDERER_API Pipeline
{
public:
struct Stats
{
int draw_call_count;
int instance_count;
int triangle_count;
};
public:
struct Stats
{
int draw_call_count;
int instance_count;
int triangle_count;
};
struct CustomCommandHandler
{
Delegate<void> callback;
char name[30];
u32 hash;
};
struct CustomCommandHandler
{
Delegate<void> callback;
char name[30];
u32 hash;
};
public:
static void registerLuaAPI(lua_State* state);
public:
static void registerLuaAPI(lua_State* state);
static Pipeline* create(Renderer& renderer, const Path& path, const char* define, IAllocator& allocator);
static void destroy(Pipeline* pipeline);
virtual ~Pipeline() {}
virtual ~Pipeline() {}
static Pipeline* create(Renderer& renderer, const Path& path, const char* define, IAllocator& allocator);
static void destroy(Pipeline* pipeline);
virtual void load() = 0;
virtual bool render() = 0;
virtual void resize(int width, int height) = 0;
virtual void setScene(RenderScene* scene) = 0;
virtual RenderScene* getScene() const = 0;
virtual int getWidth() const = 0;
virtual int getHeight() const = 0;
virtual CustomCommandHandler& addCustomCommandHandler(const char* name) = 0;
virtual void setWindowHandle(void* data) = 0;
virtual bool isReady() const = 0;
virtual const Stats& getStats() const = 0;
virtual Path& getPath() = 0;
virtual void callLuaFunction(const char* func) = 0;
virtual void renderModel(class Model& model, const Matrix& mtx) = 0;
virtual void load() = 0;
virtual bool render() = 0;
virtual void resize(int width, int height) = 0;
virtual bgfx::TextureHandle& getRenderbuffer(const char* framebuffer_name, int renderbuffer_idx) = 0;
virtual void setScene(RenderScene* scene) = 0;
virtual RenderScene* getScene() = 0;
virtual int getWidth() = 0;
virtual int getHeight() = 0;
virtual CustomCommandHandler& addCustomCommandHandler(const char* name) = 0;
virtual void setViewProjection(const Matrix& mtx, int width, int height) = 0;
virtual void setScissor(int x, int y, int width, int height) = 0;
virtual bool checkAvailTransientBuffers(u32 num_vertices,
const bgfx::VertexDecl& decl,
u32 num_indices) = 0;
virtual void allocTransientBuffers(bgfx::TransientVertexBuffer* tvb,
u32 num_vertices,
const bgfx::VertexDecl& decl,
bgfx::TransientIndexBuffer* tib,
u32 num_indices) = 0;
virtual bgfx::TextureHandle createTexture(int width, int height, const u32* rgba_data) = 0;
virtual void destroyTexture(bgfx::TextureHandle texture) = 0;
virtual void setTexture(int slot,
bgfx::TextureHandle texture,
bgfx::UniformHandle uniform) = 0;
virtual void destroyUniform(bgfx::UniformHandle uniform) = 0;
virtual bgfx::UniformHandle createTextureUniform(const char* name) = 0;
virtual void render(const bgfx::DynamicVertexBufferHandle& vertex_buffer,
const bgfx::DynamicIndexBufferHandle& index_buffer,
int first_index,
int num_indices,
int first_vertex,
int num_vertices,
u64 render_states,
struct ShaderInstance& shader_instance) = 0;
virtual void render(const bgfx::TransientVertexBuffer& vertex_buffer,
const bgfx::TransientIndexBuffer& index_buffer,
const Matrix& mtx,
int first_index,
int num_indices,
u64 render_states,
ShaderInstance& shader_instance) = 0;
virtual void renderModel(Model& model, Pose* pose, const Matrix& mtx) = 0;
virtual void toggleStats() = 0;
virtual void setWindowHandle(void* data) = 0;
virtual bool isReady() const = 0;
virtual const Stats& getStats() = 0;
virtual Path& getPath() = 0;
virtual void callLuaFunction(const char* func) = 0;
virtual Entity getAppliedCamera() const = 0;
virtual void render(const bgfx::VertexBufferHandle& vertex_buffer,
const bgfx::IndexBufferHandle& index_buffer,
const bgfx::InstanceDataBuffer& instance_buffer,
int count,
Material& material) = 0;
virtual Draw2D& getDraw2D() = 0;
virtual Draw2D& getDraw2D() = 0;
virtual ffr::TextureHandle getOutput() = 0;
};
} // namespace Lumix
} // namespace Lumix

View file

@ -20,7 +20,6 @@
#include "lua_script/lua_script_system.h"
#include "renderer/culling_system.h"
#include "renderer/font_manager.h"
#include "renderer/frame_buffer.h"
#include "renderer/material.h"
#include "renderer/material_manager.h"
#include "renderer/model.h"
@ -1163,6 +1162,9 @@ public:
void deserializeEnvironmentProbe(IDeserializer& serializer, Entity entity, int scene_version)
{
// TODO
ASSERT(false);
/*
auto* texture_manager = m_engine.getResourceManager().get(Texture::TYPE);
StaticString<MAX_PATH_LENGTH> probe_dir("universes/", m_universe.getName(), "/probes/");
EnvironmentProbe& probe = m_environment_probes.insert(entity);
@ -1195,7 +1197,7 @@ public:
probe.radiance->setFlag(BGFX_TEXTURE_MIN_ANISOTROPIC, true);
probe.radiance->setFlag(BGFX_TEXTURE_MAG_ANISOTROPIC, true);
m_universe.onComponentCreated(entity, ENVIRONMENT_PROBE_TYPE, this);
m_universe.onComponentCreated(entity, ENVIRONMENT_PROBE_TYPE, this);*/
}
@ -1669,6 +1671,9 @@ public:
void deserializeEnvironmentProbes(InputBlob& serializer)
{
// TODO
ASSERT(false);
/*
i32 count;
serializer.read(count);
m_environment_probes.reserve(count);
@ -1703,7 +1708,7 @@ public:
probe.radiance->setFlag(BGFX_TEXTURE_MAG_ANISOTROPIC, true);
m_universe.onComponentCreated(entity, ENVIRONMENT_PROBE_TYPE, this);
}
}*/
}
@ -3091,56 +3096,6 @@ public:
}
static bgfx::TextureHandle* LUA_getTextureHandle(RenderScene* scene, int resource_idx)
{
Resource* res = scene->getEngine().getLuaResource(resource_idx);
if (!res) return nullptr;
return &static_cast<Texture*>(res)->handle;
}
static void LUA_setTexturePixel(Texture* texture, int x, int y, u32 value)
{
if (!texture) return;
if (!texture->isReady()) return;
if (texture->data.empty()) return;
if (texture->bytes_per_pixel != 4) return;
x = Math::clamp(x, 0, texture->width - 1);
y = Math::clamp(y, 0, texture->height - 1);
((u32*)&texture->data[0])[x + y * texture->width] = value;
}
static void LUA_updateTextureData(Texture* texture, int x, int y, int w, int h)
{
if (!texture) return;
if (!texture->isReady()) return;
if (texture->data.empty()) return;
texture->onDataUpdated(x, y, w, h);
}
static int LUA_getTextureWidth(Texture* texture)
{
if (!texture) return 0;
if (!texture->isReady()) return 0;
return texture->width;
}
static int LUA_getTextureHeight(Texture* texture)
{
if (!texture) return 0;
if (!texture->isReady()) return 0;
return texture->height;
}
static float LUA_getTerrainHeightAt(RenderSceneImpl* render_scene, Entity entity, int x, int z)
{
return render_scene->m_terrains[entity]->getHeight(x, z);
@ -3208,20 +3163,15 @@ public:
}
// TODO
/*
static bgfx::TextureHandle* LUA_getRenderBuffer(Pipeline* pipeline,
const char* framebuffer_name,
int renderbuffer_idx)
{
bgfx::TextureHandle& handle = pipeline->getRenderbuffer(framebuffer_name, renderbuffer_idx);
bgfx::TextureHandle& handle = pipeline->getRenderbuffer(framebuffer_name, renderbuffer_idx);
return &handle;
}
static Texture* LUA_getMaterialTexture(Material* material, int texture_index)
{
if (!material) return nullptr;
return material->getTexture(texture_index);
}
}*/
static void LUA_setModelInstancePath(IScene* scene, int component, const char* path)
@ -3662,12 +3612,11 @@ public:
Matrix getCameraProjection(Entity entity) override
{
Camera& camera = m_cameras[entity];
const Camera& camera = m_cameras[entity];
Matrix mtx;
float ratio = camera.screen_height > 0 ? camera.screen_width / camera.screen_height : 1;
bool is_homogenous_depth = bgfx::getCaps()->homogeneousDepth;
if (camera.is_ortho)
{
const float ratio = camera.screen_height > 0 ? camera.screen_width / camera.screen_height : 1;
const bool is_homogenous_depth = ffr::isHomogenousDepth();
if (camera.is_ortho) {
mtx.setOrtho(-camera.ortho_size * ratio,
camera.ortho_size * ratio,
-camera.ortho_size,
@ -3677,8 +3626,7 @@ public:
is_homogenous_depth,
true);
}
else
{
else {
mtx.setPerspective(camera.fov, ratio, camera.near, camera.far, is_homogenous_depth, true);
}
return mtx;
@ -4473,6 +4421,9 @@ public:
void reloadEnvironmentProbe(Entity entity) override
{
// TODO
ASSERT(false);
/*
auto& probe = m_environment_probes[entity];
auto* texture_manager = m_engine.getResourceManager().get(Texture::TYPE);
if (probe.texture) texture_manager->unload(*probe.texture);
@ -4495,7 +4446,7 @@ public:
probe.radiance = static_cast<Texture*>(texture_manager->load(Path(path)));
probe.radiance->setFlag(BGFX_TEXTURE_SRGB, true);
probe.radiance->setFlag(BGFX_TEXTURE_MIN_ANISOTROPIC, true);
probe.radiance->setFlag(BGFX_TEXTURE_MAG_ANISOTROPIC, true);
probe.radiance->setFlag(BGFX_TEXTURE_MAG_ANISOTROPIC, true);*/
}
@ -4752,7 +4703,10 @@ public:
void allocateCustomMeshes(ModelInstance& r, int count)
{
if (hasCustomMeshes(r) && r.mesh_count == count) return;
// TODO
ASSERT(false);
/*
if (hasCustomMeshes(r) && r.mesh_count == count) return;
ASSERT(r.model);
auto& rm = r.model->getResourceManager();
@ -4793,7 +4747,7 @@ public:
}
r.meshes = new_meshes;
r.mesh_count = count;
r.flags.set(ModelInstance::CUSTOM_MESHES);
r.flags.set(ModelInstance::CUSTOM_MESHES);*/
}
@ -5101,6 +5055,9 @@ public:
void createEnvironmentProbe(Entity entity)
{
// TODO
ASSERT(false);
/*
EnvironmentProbe& probe = m_environment_probes.insert(entity);
auto* texture_manager = m_engine.getResourceManager().get(Texture::TYPE);
probe.texture = static_cast<Texture*>(texture_manager->load(Path("pipelines/pbr/default_probe.dds")));
@ -5111,7 +5068,7 @@ public:
probe.radiance->setFlag(BGFX_TEXTURE_SRGB, true);
probe.guid = Math::randGUID();
m_universe.onComponentCreated(entity, ENVIRONMENT_PROBE_TYPE, this);
m_universe.onComponentCreated(entity, ENVIRONMENT_PROBE_TYPE, this);*/
}
@ -5382,14 +5339,9 @@ void RenderScene::registerLuaAPI(lua_State* L)
REGISTER_FUNCTION(setPipelineScene);
REGISTER_FUNCTION(getPipelineScene);
REGISTER_FUNCTION(pipelineRender);
REGISTER_FUNCTION(getRenderBuffer);
REGISTER_FUNCTION(getMaterialTexture);
REGISTER_FUNCTION(getTextureWidth);
REGISTER_FUNCTION(getTextureHeight);
REGISTER_FUNCTION(getTexturePixel);
REGISTER_FUNCTION(setTexturePixel);
REGISTER_FUNCTION(getTextureHandle);
REGISTER_FUNCTION(updateTextureData);
// TODO
/*
REGISTER_FUNCTION(getRenderBuffer);*/
REGISTER_FUNCTION(setModelInstanceMaterial);
REGISTER_FUNCTION(setModelInstancePath);
REGISTER_FUNCTION(getModelBoneIndex);

View file

@ -30,54 +30,14 @@
#include <Windows.h>
#include "gl/GL.h"
#include "ffr/ffr.h"
#include <bgfx/bgfx.h>
#include <cstdio>
namespace bx
{
struct AllocatorI
{
virtual ~AllocatorI() = default;
/// Allocated, resizes memory block or frees memory.
///
/// @param[in] _ptr If _ptr is NULL new block will be allocated.
/// @param[in] _size If _ptr is set, and _size is 0, memory will be freed.
/// @param[in] _align Alignment.
/// @param[in] _file Debug file path info.
/// @param[in] _line Debug file line info.
virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) = 0;
};
} // namespace bx
namespace bgfx
{
struct PlatformData
{
void* ndt; //< Native display type
void* nwh; //< Native window handle
void* context; //< GL context, or D3D device
void* backBuffer; //< GL backbuffer, or D3D render target view
void* backBufferDS; //< Backbuffer depth/stencil.
};
void setPlatformData(const PlatformData& _pd);
} // namespace bgfx
namespace Lumix
{
static const ComponentType MODEL_INSTANCE_TYPE = Reflection::getComponentType("renderable");
static thread_local bgfx::Encoder* s_encoder = nullptr;
struct BoneProperty : Reflection::IEnumProperty
{
@ -308,52 +268,6 @@ static void registerProperties(IAllocator& allocator)
}
struct BGFXAllocator LUMIX_FINAL : public bx::AllocatorI
{
explicit BGFXAllocator(IAllocator& source)
: m_source(source)
{
}
static const size_t NATURAL_ALIGNEMENT = 8;
void* realloc(void* _ptr, size_t _size, size_t _alignment, const char*, u32) override
{
if (0 == _size)
{
if (_ptr)
{
if (NATURAL_ALIGNEMENT >= _alignment)
{
m_source.deallocate(_ptr);
return nullptr;
}
m_source.deallocate_aligned(_ptr);
}
return nullptr;
}
else if (!_ptr)
{
if (NATURAL_ALIGNEMENT >= _alignment) return m_source.allocate(_size);
return m_source.allocate_aligned(_size, _alignment);
}
if (NATURAL_ALIGNEMENT >= _alignment) return m_source.reallocate(_ptr, _size);
return m_source.reallocate_aligned(_ptr, _size, _alignment);
}
IAllocator& m_source;
};
struct RendererImpl LUMIX_FINAL : public Renderer
{
explicit RendererImpl(Engine& engine)
@ -364,16 +278,14 @@ struct RendererImpl LUMIX_FINAL : public Renderer
, m_material_manager(*this, m_allocator)
, m_shader_manager(*this, m_allocator)
, m_font_manager(nullptr)
, m_shader_binary_manager(*this, m_allocator)
, m_passes(m_allocator)
, m_shader_defines(m_allocator)
, m_layers(m_allocator)
, m_bgfx_allocator(m_allocator)
, m_vsync(true)
, m_main_pipeline(nullptr)
, m_encoder_list_mutex(false)
{
ffr_init(nullptr);
ffr::init(m_allocator);
registerProperties(engine.getAllocator());
char cmd_line[4096];
@ -396,7 +308,6 @@ struct RendererImpl LUMIX_FINAL : public Renderer
m_shader_manager.create(Shader::TYPE, manager);
m_font_manager = LUMIX_NEW(m_allocator, FontManager)(*this, m_allocator);
m_font_manager->create(FontResource::TYPE, manager);
m_shader_binary_manager.create(ShaderBinary::TYPE, manager);
m_current_pass_hash = crc32("MAIN");
m_view_counter = 0;
@ -407,11 +318,16 @@ struct RendererImpl LUMIX_FINAL : public Renderer
m_layers.emplace("transparent");
m_layers.emplace("water");
m_layers.emplace("fur");
m_global_uniforms_buffer = ffr::createBuffer(64*1024, nullptr);
ffr::bindUniformBuffer(0, m_global_uniforms_buffer);
}
~RendererImpl()
{
ffr::destroy(m_global_uniforms_buffer);
m_shader_manager.unload(*m_default_shader);
m_texture_manager.destroy();
m_model_manager.destroy();
@ -419,7 +335,6 @@ struct RendererImpl LUMIX_FINAL : public Renderer
m_shader_manager.destroy();
m_font_manager->destroy();
LUMIX_DELETE(m_allocator, m_font_manager);
m_shader_binary_manager.destroy();
frame(false);
frame(false);
@ -432,12 +347,6 @@ struct RendererImpl LUMIX_FINAL : public Renderer
}
bgfx::Encoder* getEncoder() override
{
return nullptr;
}
Pipeline* getMainPipeline() override
{
return m_main_pipeline;
@ -465,9 +374,11 @@ struct RendererImpl LUMIX_FINAL : public Renderer
ShaderManager& getShaderManager() override { return m_shader_manager; }
TextureManager& getTextureManager() override { return m_texture_manager; }
FontManager& getFontManager() override { return *m_font_manager; }
// TODO
/*
const bgfx::VertexDecl& getBasicVertexDecl() const override { static bgfx::VertexDecl v; return v; }
const bgfx::VertexDecl& getBasic2DVertexDecl() const override { static bgfx::VertexDecl v; return v; }
*/
void createScenes(Universe& ctx) override
{
@ -482,8 +393,11 @@ struct RendererImpl LUMIX_FINAL : public Renderer
int getShaderDefinesCount() const override { return m_shader_defines.size(); }
const char* getShaderDefine(int define_idx) override { return m_shader_defines[define_idx]; }
const char* getPassName(int idx) override { return m_passes[idx]; }
// TODO
/*
const bgfx::UniformHandle& getMaterialColorUniform() const override { static bgfx::UniformHandle v; return v; }
const bgfx::UniformHandle& getRoughnessMetallicEmissionUniform() const override { static bgfx::UniformHandle v; return v; }
*/
void makeScreenshot(const Path& filename) override { }
void resize(int w, int h) override { }
int getViewCounter() const override { return m_view_counter; }
@ -531,6 +445,11 @@ struct RendererImpl LUMIX_FINAL : public Renderer
}
ffr::BufferHandle getGlobalUniformsBuffer() const {
return m_global_uniforms_buffer;
}
void frame(bool capture) override
{
}
@ -549,15 +468,14 @@ struct RendererImpl LUMIX_FINAL : public Renderer
MaterialManager m_material_manager;
FontManager* m_font_manager;
ShaderManager m_shader_manager;
ShaderBinaryManager m_shader_binary_manager;
ModelManager m_model_manager;
u32 m_current_pass_hash;
int m_view_counter;
bool m_vsync;
Shader* m_default_shader;
BGFXAllocator m_bgfx_allocator;
Pipeline* m_main_pipeline;
MT::SpinMutex m_encoder_list_mutex;
ffr::BufferHandle m_global_uniforms_buffer;
};

View file

@ -4,18 +4,12 @@
#include "engine/iplugin.h"
namespace bgfx
{
struct Encoder;
struct UniformHandle;
struct VertexDecl;
}
namespace Lumix
{
namespace ffr { struct BufferHandle; }
class Engine;
struct Font;
struct FontAtlas;
@ -38,6 +32,7 @@ class LUMIX_RENDERER_API Renderer : public IPlugin
virtual ~Renderer() {}
virtual void frame(bool capture) = 0;
virtual void resize(int width, int height) = 0;
virtual ffr::BufferHandle getGlobalUniformsBuffer() const = 0;
virtual int getViewCounter() const = 0;
virtual void viewCounterAdd() = 0;
virtual void makeScreenshot(const Path& filename) = 0;
@ -46,22 +41,26 @@ class LUMIX_RENDERER_API Renderer : public IPlugin
virtual u8 getShaderDefineIdx(const char* define) = 0;
virtual const char* getShaderDefine(int define_idx) = 0;
virtual int getShaderDefinesCount() const = 0;
virtual const bgfx::VertexDecl& getBasicVertexDecl() const = 0;
virtual const bgfx::VertexDecl& getBasic2DVertexDecl() const = 0;
// TODO
/*
virtual const bgfx::VertexDecl& getBasicVertexDecl() const = 0;
virtual const bgfx::VertexDecl& getBasic2DVertexDecl() const = 0;*/
virtual FontManager& getFontManager() = 0;
virtual MaterialManager& getMaterialManager() = 0;
virtual ShaderManager& getShaderManager() = 0;
virtual ModelManager& getModelManager() = 0;
virtual TextureManager& getTextureManager() = 0;
virtual Shader* getDefaultShader() = 0;
// TODO
/*
virtual const bgfx::UniformHandle& getMaterialColorUniform() const = 0;
virtual const bgfx::UniformHandle& getRoughnessMetallicEmissionUniform() const = 0;
*/
virtual int getLayersCount() const = 0;
virtual int getLayer(const char* name) = 0;
virtual const char* getLayerName(int idx) const = 0;
virtual void setMainPipeline(Pipeline* pipeline) = 0;
virtual Pipeline* getMainPipeline() = 0;
virtual bgfx::Encoder* getEncoder() = 0;
virtual Engine& getEngine() = 0;
};

View file

@ -9,7 +9,6 @@
#include "renderer/renderer.h"
#include "renderer/shader_manager.h"
#include "renderer/texture.h"
#include <bgfx/bgfx.h>
#include <lua.hpp>
#include <lauxlib.h>
@ -19,7 +18,6 @@ namespace Lumix
const ResourceType Shader::TYPE("shader");
const ResourceType ShaderBinary::TYPE("shader_binary");
Shader::Shader(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
@ -30,6 +28,8 @@ Shader::Shader(const Path& path, ResourceManagerBase& resource_manager, IAllocat
, m_uniforms(m_allocator)
, m_render_states(0)
, m_all_defines_mask(0)
, m_sources(m_allocator)
, m_program_handle(ffr::INVALID_PROGRAM)
{
}
@ -62,6 +62,25 @@ ShaderInstance& Shader::getInstance(u32 mask)
}
ffr::ProgramHandle Shader::getProgramHandle()
{
if (!m_program_handle.isValid()) {
const char* codes[64];
ffr::ShaderType types[64];
ASSERT(lengthOf(types) >= m_sources.size());
for (int i = 0; i < m_sources.size(); ++i) {
codes[i] = m_sources[i].code.c_str();
types[i] = m_sources[i].type;
}
m_program_handle = ffr::createProgram(codes, types, m_sources.size());
if(m_program_handle.isValid()) {
ffr::uniformBlockBinding(m_program_handle, 0, 0);
}
}
return m_program_handle;
}
Renderer& Shader::getRenderer()
{
return static_cast<ShaderManager&>(m_resource_manager).getRenderer();
@ -86,6 +105,9 @@ static u32 getDefineMaskFromDense(const Shader& shader, u32 dense)
bool Shader::generateInstances()
{
// TODO
ASSERT(false);
/*
bool is_opengl = bgfx::getRendererType() == bgfx::RendererType::OpenGL ||
bgfx::getRendererType() == bgfx::RendererType::OpenGLES;
m_instances.clear();
@ -128,7 +150,7 @@ bool Shader::generateInstances()
addDependency(*fs_binary);
instance.binaries[pass_idx * 2 + 1] = fs_binary;
}
}
}*/
return true;
}
@ -143,7 +165,8 @@ static void registerCFunction(lua_State* L, const char* name, lua_CFunction func
static Shader* getShader(lua_State* L)
{
Shader* ret = nullptr;
if (lua_getglobal(L, "shader") == LUA_TLIGHTUSERDATA)
lua_getglobal(L, "shader");
if (lua_type(L, -1) == LUA_TLIGHTUSERDATA)
{
ret = LuaWrapper::toType<Shader*>(L, -1);
}
@ -155,8 +178,8 @@ static Shader* getShader(lua_State* L)
static ShaderCombinations& getShaderCombinations(lua_State* L)
{
ShaderCombinations* ret = nullptr;
int res = lua_getglobal(L, "combinations");
ASSERT(res == LUA_TLIGHTUSERDATA);
lua_getglobal(L, "combinations");
ASSERT(lua_type(L, -1) == LUA_TLIGHTUSERDATA);
return *LuaWrapper::toType<ShaderCombinations*>(L, -1);
}
@ -164,48 +187,60 @@ static ShaderCombinations& getShaderCombinations(lua_State* L)
static Renderer& getRendererGlobal(lua_State* L)
{
Renderer* ret = nullptr;
int res = lua_getglobal(L, "renderer");
ASSERT(res == LUA_TLIGHTUSERDATA);
lua_getglobal(L, "renderer");
ASSERT(lua_type(L, -1) == LUA_TLIGHTUSERDATA);
return *LuaWrapper::toType<Renderer*>(L, -1);
}
static void default_texture(lua_State* state, const char* path)
{
// TODO
ASSERT(false);
/*
Shader* shader = getShader(state);
if (!shader) return;
if (shader->m_texture_slot_count == 0) return;
Shader::TextureSlot& slot = shader->m_texture_slots[shader->m_texture_slot_count - 1];
ResourceManagerBase* texture_manager = shader->getResourceManager().getOwner().get(Texture::TYPE);
slot.default_texture = (Texture*)texture_manager->load(Path(path));
slot.default_texture = (Texture*)texture_manager->load(Path(path));*/
}
static void texture_slot(lua_State* state, const char* name, const char* uniform)
{
Shader* shader = getShader(state);
// TODO
ASSERT(false);
/*
Shader* shader = getShader(state);
if (!shader) return;
Shader::TextureSlot& slot = shader->m_texture_slots[shader->m_texture_slot_count];
copyString(slot.name, name);
slot.uniform_handle = bgfx::createUniform(uniform, bgfx::UniformType::Int1);
copyString(slot.uniform, uniform);
++shader->m_texture_slot_count;
++shader->m_texture_slot_count;*/
}
static void texture_define(lua_State* L, const char* define)
{
Shader* shader = getShader(L);
// TODO
ASSERT(false);
/*
Shader* shader = getShader(L);
if (!shader) return;
Renderer& renderer = shader->getRenderer();
auto& slot = shader->m_texture_slots[shader->m_texture_slot_count - 1];
slot.define_idx = renderer.getShaderDefineIdx(lua_tostring(L, -1));
slot.define_idx = renderer.getShaderDefineIdx(lua_tostring(L, -1));*/
}
static void uniform(lua_State* L, const char* name, const char* type)
{
// TODO
ASSERT(false);
/*
auto* shader = getShader(L);
if (!shader) return;
auto& u = shader->m_uniforms.emplace();
@ -254,7 +289,7 @@ static void uniform(lua_State* L, const char* name, const char* type)
else
{
g_log_error.log("Renderer") << "Unknown uniform type " << type << " in " << shader->getPath().c_str();
}
}*/
}
@ -291,6 +326,9 @@ static int indexOfDefine(ShaderCombinations& combination, u8 define_idx)
static void alpha_blending(lua_State* L, const char* mode)
{
// TODO
ASSERT(false);
/*
Shader* shader = getShader(L);
if (!shader) return;
if (equalStrings(mode, "add"))
@ -304,13 +342,16 @@ static void alpha_blending(lua_State* L, const char* mode)
else
{
g_log_error.log("Renderer") << "Uknown blend mode " << mode << " in " << shader->getPath().c_str();
}
}*/
}
static void depth_test(lua_State* L, bool enabled)
{
Shader* shader = nullptr;
// TODO
ASSERT(false);
/*
Shader* shader = nullptr;
if (lua_getglobal(L, "shader") == LUA_TLIGHTUSERDATA)
{
shader = LuaWrapper::toType<Shader*>(L, -1);
@ -324,7 +365,7 @@ static void depth_test(lua_State* L, bool enabled)
else
{
shader->m_render_states &= ~BGFX_STATE_DEPTH_TEST_MASK;
}
}*/
}
@ -335,10 +376,11 @@ static void fs(lua_State* L)
Renderer& renderer = getRendererGlobal(L);
LuaWrapper::checkTableArg(L, 1);
const int len = (int)lua_rawlen(L, 1);
const int len = (int)lua_objlen(L, 1);
for (int i = 0; i < len; ++i) {
if (lua_rawgeti(L, 1, i + 1) == LUA_TSTRING) {
lua_rawgeti(L, 1, i + 1);
if (lua_type(L, -1) == LUA_TSTRING) {
const char* tmp = lua_tostring(L, -1);
const int define_idx = renderer.getShaderDefineIdx(tmp);
cmb.all_defines_mask |= 1 << define_idx;
@ -364,10 +406,11 @@ static void vs(lua_State* L)
Renderer& renderer = getRendererGlobal(L);
LuaWrapper::checkTableArg(L, 1);
int len = (int)lua_rawlen(L, 1);
int len = (int)lua_objlen(L, 1);
for (int i = 0; i < len; ++i)
{
if (lua_rawgeti(L, 1, i + 1) == LUA_TSTRING)
lua_rawgeti(L, 1, i + 1);
if (lua_type(L, -1) == LUA_TSTRING)
{
const char* tmp = lua_tostring(L, -1);
int define_idx = renderer.getShaderDefineIdx(tmp);
@ -399,15 +442,89 @@ static void registerFunctions(Shader* shader, ShaderCombinations* combinations,
}
namespace LuaAPI
{
int texture_slot(lua_State* L)
{
LuaWrapper::checkTableArg(L, 1);
lua_getfield(L, LUA_GLOBALSINDEX, "this");
Shader* shader = (Shader*)lua_touserdata(L, -1);
lua_pop(L, 1);
if(shader->m_texture_slot_count >= lengthOf(shader->m_texture_slots)) {
g_log_error.log("Renderer") << "Too many texture slots in " << shader->getPath();
return 0;
}
Shader::TextureSlot& slot = shader->m_texture_slots[shader->m_texture_slot_count];
LuaWrapper::getOptionalStringField(L, -1, "uniform", slot.uniform, lengthOf(slot.uniform));
++shader->m_texture_slot_count;
return 0;
}
int vertex_shader(lua_State* L)
{
const char* src = LuaWrapper::checkArg<const char*>(L, 1);
lua_getfield(L, LUA_GLOBALSINDEX, "this");
Shader* shader = (Shader*)lua_touserdata(L, -1);
lua_pop(L, 1);
Shader::Source& srcobj = shader->m_sources.emplace(shader->m_allocator);
srcobj.type = ffr::ShaderType::VERTEX;
srcobj.code = src;
return 0;
}
int fragment_shader(lua_State* L)
{
const char* src = LuaWrapper::checkArg<const char*>(L, 1);
lua_getfield(L, LUA_GLOBALSINDEX, "this");
Shader* shader = (Shader*)lua_touserdata(L, -1);
lua_pop(L, 1);
Shader::Source& srcobj = shader->m_sources.emplace(shader->m_allocator);
srcobj.type = ffr::ShaderType::FRAGMENT;
srcobj.code = src;
return 0;
}
} // namespace LuaAPI
bool Shader::load(FS::IFile& file)
{
lua_State* L = luaL_newstate();
lua_pushlightuserdata(L, this);
lua_setfield(L, LUA_GLOBALSINDEX, "this");
lua_pushcclosure(L, LuaAPI::vertex_shader, 0);
lua_setfield(L, LUA_GLOBALSINDEX, "vertex_shader");
lua_pushcclosure(L, LuaAPI::fragment_shader, 0);
lua_setfield(L, LUA_GLOBALSINDEX, "fragment_shader");
lua_pushcclosure(L, LuaAPI::texture_slot, 0);
lua_setfield(L, LUA_GLOBALSINDEX, "texture_slot");
const StringView content((const char*)file.getBuffer(), (int)file.size());
if (!LuaWrapper::execute(L, content, getPath().c_str(), 0)) {
lua_close(L);
return false;
}
lua_close(L);
return true;
/*lua_State* L = luaL_newstate();
luaL_openlibs(L);
registerFunctions(this, &m_combinations, &getRenderer(), L);
m_render_states = BGFX_STATE_DEPTH_TEST_GEQUAL;
bool errors = luaL_loadbuffer(L, (const char*)file.getBuffer(), file.size(), "") != LUA_OK;
errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK;
bool errors = luaL_loadbuffer(L, (const char*)file.getBuffer(), file.size(), "") != 0;
errors = errors || lua_pcall(L, 0, 0, 0) != 0;
if (errors)
{
g_log_error.log("Renderer") << getPath().c_str() << ": " << lua_tostring(L, -1);
@ -429,7 +546,12 @@ bool Shader::load(FS::IFile& file)
void Shader::unload()
{
m_combinations.pass_count = 0;
m_sources.clear();
ffr::destroy(m_program_handle);
m_program_handle = ffr::INVALID_PROGRAM;
// TODO
/*
m_combinations.pass_count = 0;
m_combinations.define_count = 0;
m_combinations.all_defines_mask = 0;
@ -459,9 +581,11 @@ void Shader::unload()
m_instances.clear();
m_all_defines_mask = 0;
m_render_states = 0;
m_render_states = 0;*/
}
// TODO
/*
bgfx::ProgramHandle ShaderInstance::getProgramHandle(int pass_idx)
{
@ -486,11 +610,14 @@ bgfx::ProgramHandle ShaderInstance::getProgramHandle(int pass_idx)
return program_handles[pass_idx];
}
*/
ShaderInstance::~ShaderInstance()
{
for (int i = 0; i < lengthOf(program_handles); ++i)
// TODO
ASSERT(false);
/*
for (int i = 0; i < lengthOf(program_handles); ++i)
{
if (bgfx::isValid(program_handles[i]))
{
@ -504,13 +631,15 @@ ShaderInstance::~ShaderInstance()
shader.removeDependency(*binary);
binary->getResourceManager().unload(*binary);
}
}*/
}
void Shader::onBeforeEmpty()
{
for (ShaderInstance& inst : m_instances)
// TODO
/*
for (ShaderInstance& inst : m_instances)
{
for (int i = 0; i < lengthOf(inst.program_handles); ++i)
{
@ -520,7 +649,7 @@ void Shader::onBeforeEmpty()
inst.program_handles[i] = BGFX_INVALID_HANDLE;
}
}
}
}*/
}
@ -529,12 +658,15 @@ bool Shader::getShaderCombinations(const char* shd_path,
const char* shader_content,
ShaderCombinations* output)
{
lua_State* L = luaL_newstate();
// TODO
ASSERT(false);
/*
lua_State* L = luaL_newstate();
luaL_openlibs(L);
registerFunctions(nullptr, output, &renderer, L);
bool errors = luaL_loadbuffer(L, shader_content, stringLength(shader_content), "") != LUA_OK;
errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK;
bool errors = luaL_loadbuffer(L, shader_content, stringLength(shader_content), "") != 0;
errors = errors || lua_pcall(L, 0, 0, 0) != 0;
if (errors)
{
g_log_error.log("Renderer") << shd_path << " - " << lua_tostring(L, -1);
@ -542,40 +674,9 @@ bool Shader::getShaderCombinations(const char* shd_path,
lua_close(L);
return false;
}
lua_close(L);
lua_close(L);*/
return true;
}
ShaderBinary::ShaderBinary(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_handle(BGFX_INVALID_HANDLE)
{
}
void ShaderBinary::unload()
{
if (bgfx::isValid(m_handle)) bgfx::destroy(m_handle);
m_handle = BGFX_INVALID_HANDLE;
}
bool ShaderBinary::load(FS::IFile& file)
{
/*auto* mem = bgfx::alloc((u32)file.size() + 1);
file.read(mem->data, file.size());
mem->data[file.size()] = '\0';
m_handle = bgfx::createShader(mem);
m_size = file.size();
if (!bgfx::isValid(m_handle))
{
g_log_error.log("Renderer") << getPath().c_str() << ": Failed to create bgfx shader";*/
return false;
/*}
bgfx::setName(m_handle, getPath().c_str());
return true;*/
}
} // namespace Lumix

View file

@ -2,8 +2,7 @@
#include "engine/array.h"
#include "engine/resource.h"
#include "engine/string.h"
#include <bgfx/bgfx.h>
#include "ffr/ffr.h"
struct lua_State;
@ -29,15 +28,15 @@ struct ShaderInstance
{
for (int i = 0; i < lengthOf(program_handles); ++i)
{
program_handles[i] = BGFX_INVALID_HANDLE;
program_handles[i] = ffr::INVALID_PROGRAM;
binaries[i * 2] = nullptr;
binaries[i * 2 + 1] = nullptr;
}
}
~ShaderInstance();
bgfx::ProgramHandle getProgramHandle(int pass_idx);
ffr::ProgramHandle getProgramHandle(int pass_idx);
bgfx::ProgramHandle program_handles[32];
ffr::ProgramHandle program_handles[32];
ShaderBinary* binaries[64];
u32 define_mask;
Shader& shader;
@ -60,28 +59,6 @@ struct LUMIX_RENDERER_API ShaderCombinations
};
class LUMIX_RENDERER_API ShaderBinary LUMIX_FINAL : public Resource
{
public:
ShaderBinary(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
ResourceType getType() const override { return TYPE; }
bgfx::ShaderHandle getHandle() { return m_handle; }
Shader* m_shader;
static const ResourceType TYPE;
private:
void unload() override;
bool load(FS::IFile& file) override;
private:
bgfx::ShaderHandle m_handle;
};
class LUMIX_RENDERER_API Shader LUMIX_FINAL : public Resource
{
friend struct ShaderInstance;
@ -93,15 +70,16 @@ public:
{
name[0] = uniform[0] = '\0';
define_idx = -1;
uniform_handle = BGFX_INVALID_HANDLE;
//uniform_handle = BGFX_INVALID_HANDLE;
default_texture = nullptr;
}
// TODO
//bgfx::UniformHandle uniform_handle;
char name[30];
char uniform[30];
int define_idx;
bgfx::UniformHandle uniform_handle;
Texture* default_texture;
int define_idx = -1;
Texture* default_texture = nullptr;
};
@ -122,9 +100,16 @@ public:
char name[32];
u32 name_hash;
Type type;
bgfx::UniformHandle handle;
// TODO
/*
bgfx::UniformHandle handle;*/
};
struct Source {
Source(IAllocator& allocator) : code(allocator) {}
ffr::ShaderType type;
string code;
};
public:
static const int MAX_TEXTURE_SLOT_COUNT = 16;
@ -138,6 +123,7 @@ public:
bool hasDefine(u8 define_idx) const;
ShaderInstance& getInstance(u32 mask);
Renderer& getRenderer();
ffr::ProgramHandle getProgramHandle();
static bool getShaderCombinations(const char* shd_path,
Renderer& renderer,
@ -154,6 +140,8 @@ public:
TextureSlot m_texture_slots[MAX_TEXTURE_SLOT_COUNT];
int m_texture_slot_count;
Array<Uniform> m_uniforms;
Array<Source> m_sources;
ffr::ProgramHandle m_program_handle;
static const ResourceType TYPE;

View file

@ -53,26 +53,4 @@ u8* ShaderManager::getBuffer(i32 size)
}
ShaderBinaryManager::ShaderBinaryManager(Renderer& renderer, IAllocator& allocator)
: ResourceManagerBase(allocator)
, m_allocator(allocator)
{
}
ShaderBinaryManager::~ShaderBinaryManager() = default;
Resource* ShaderBinaryManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, ShaderBinary)(path, *this, m_allocator);
}
void ShaderBinaryManager::destroyResource(Resource& resource)
{
LUMIX_DELETE(m_allocator, static_cast<ShaderBinary*>(&resource));
}
} // namespace Lumix

View file

@ -7,20 +7,6 @@ namespace Lumix
class Renderer;
class LUMIX_RENDERER_API ShaderBinaryManager LUMIX_FINAL : public ResourceManagerBase
{
public:
ShaderBinaryManager(Renderer& renderer, IAllocator& allocator);
~ShaderBinaryManager();
protected:
Resource* createResource(const Path& path) override;
void destroyResource(Resource& resource) override;
private:
IAllocator& m_allocator;
};
class LUMIX_RENDERER_API ShaderManager LUMIX_FINAL : public ResourceManagerBase
{
public:

View file

@ -907,7 +907,7 @@ static void generateSubgrid(Array<Sample>& samples, Array<short>& indices, int&
void Terrain::generateGeometry()
{
LUMIX_DELETE(m_allocator, m_mesh);
/*LUMIX_DELETE(m_allocator, m_mesh);
m_mesh = nullptr;
Array<Sample> points(m_allocator);
points.resize(GRID_SIZE * GRID_SIZE * 4);
@ -930,6 +930,9 @@ void Terrain::generateGeometry()
m_mesh->index_buffer_handle = bgfx::createIndexBuffer(indices_mem);
m_mesh->indices_count = indices.size();
m_mesh->flags.set(Mesh::Flags::INDICES_16_BIT);
*/
// TODO
ASSERT(false);
}
TerrainQuad* Terrain::generateQuadTree(float size)

View file

@ -7,7 +7,6 @@
#include "engine/resource_manager_base.h"
#include "renderer/texture.h"
#include "renderer/texture_manager.h"
#include <bgfx/bgfx.h>
#include <cmath>
namespace Lumix
@ -28,7 +27,7 @@ Texture::Texture(const Path& path, ResourceManagerBase& resource_manager, IAlloc
{
bgfx_flags = 0;
is_cubemap = false;
handle = BGFX_INVALID_HANDLE;
handle = ffr::INVALID_TEXTURE;
}
@ -68,7 +67,15 @@ void Texture::destroy()
bool Texture::create(int w, int h, const void* data)
{
return false;
handle = ffr::createTexture(w, h, ffr::TextureFormat::RGBA8, data);
mips = 1;
width = w;
height = h;
const bool isReady = handle.isValid();
onCreated(isReady ? State::READY : State::FAILURE);
return isReady;
}
@ -265,7 +272,9 @@ void Texture::save()
void Texture::onDataUpdated(int x, int y, int w, int h)
{
PROFILE_FUNCTION();
ASSERT(false);
// TODO
/*PROFILE_FUNCTION();
const bgfx::Memory* mem;
@ -298,13 +307,15 @@ void Texture::onDataUpdated(int x, int y, int w, int h)
bytes_per_pixel * w);
}
}
bgfx::updateTexture2D(handle, 0, 0, (uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h, mem);
bgfx::updateTexture2D(handle, 0, 0, (uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h, mem);*/
}
bool loadRaw(Texture& texture, FS::IFile& file)
{
PROFILE_FUNCTION();
ASSERT(false);
// TODO
/*PROFILE_FUNCTION();
size_t size = file.size();
texture.bytes_per_pixel = 2;
texture.width = (int)sqrt(size / texture.bytes_per_pixel);
@ -339,7 +350,9 @@ bool loadRaw(Texture& texture, FS::IFile& file)
texture.layers = 1;
texture.mips = 1;
texture.is_cubemap = false;
return bgfx::isValid(texture.handle);
return bgfx::isValid(texture.handle);*/
return false;
}
@ -564,27 +577,13 @@ bool Texture::loadTGA(FS::IFile& file)
bytes_per_pixel = 4;
mips = 1;
handle = bgfx::createTexture2D(
header.width,
header.height,
false,
0,
bgfx::TextureFormat::RGBA8,
bgfx_flags,
nullptr);
bgfx::setName(handle, getPath().c_str());
handle = ffr::createTexture(header.width, header.height, ffr::TextureFormat::RGBA8, image_dest);
// TODO
//bgfx::setName(handle, getPath().c_str());
// update must be here because texture is immutable otherwise
bgfx::updateTexture2D(handle,
0,
0,
0,
0,
header.width,
header.height,
bgfx::copy(image_dest, header.width * header.height * 4));
depth = 1;
layers = 1;
return bgfx::isValid(handle);
return handle.isValid();
}
@ -608,32 +607,32 @@ void Texture::removeDataReference()
}
static bool loadDDSorKTX(Texture& texture, FS::IFile& file)
static bool loadDDS(Texture& texture, FS::IFile& file)
{
bgfx::TextureInfo info;
const auto* mem = bgfx::copy(file.getBuffer(), (u32)file.size());
texture.handle = bgfx::createTexture(mem, texture.bgfx_flags, 0, &info);
bgfx::setName(texture.handle, texture.getPath().c_str());
texture.width = info.width;
texture.mips = info.numMips;
texture.height = info.height;
texture.depth = info.depth;
texture.layers = info.numLayers;
texture.is_cubemap = info.cubeMap;
return bgfx::isValid(texture.handle);
ffr::TextureInfo info;
texture.handle = ffr::loadTexture(file.getBuffer(), (int)file.size(), &info);
if (texture.handle.isValid()) {
texture.width = info.width;
texture.height = info.height;
texture.mips = info.mips;
texture.depth = info.depth;
texture.layers = info.layers;
texture.is_cubemap = info.is_cubemap;
}
return texture.handle.isValid();
}
bool Texture::load(FS::IFile& file)
{
PROFILE_FUNCTION();
/*
const char* path = getPath().c_str();
size_t len = getPath().length();
bool loaded = false;
if (len > 3 && (equalStrings(path + len - 4, ".dds") || equalStrings(path + len - 4, ".ktx")))
if (len > 3 && (equalStrings(path + len - 4, ".dds")))
{
loaded = loadDDSorKTX(*this, file);
loaded = loadDDS(*this, file);
}
else if (len > 3 && equalStrings(path + len - 4, ".raw"))
{
@ -650,18 +649,15 @@ bool Texture::load(FS::IFile& file)
}
m_size = file.size();
return true;*/
return false;
return true;
}
void Texture::unload()
{
if (bgfx::isValid(handle))
{
bgfx::destroy(handle);
handle = BGFX_INVALID_HANDLE;
if (handle.isValid()) {
ffr::destroy(handle);
handle = ffr::INVALID_TEXTURE;
}
data.clear();
}

View file

@ -2,7 +2,7 @@
#include "engine/resource.h"
#include <bgfx/bgfx.h>
#include "ffr/ffr.h"
namespace Lumix
@ -75,7 +75,7 @@ class LUMIX_RENDERER_API Texture LUMIX_FINAL : public Resource
int mips;
bool is_cubemap;
u32 bgfx_flags;
bgfx::TextureHandle handle;
ffr::TextureHandle handle;
IAllocator& allocator;
int data_reference;
Array<u8> data;