Code Monkey home page Code Monkey logo

efkbgfx's Introduction

A bgfx renderer for effekseer runtime

Status

It's ready to use, and it keeps up with the latest versions of bgfx and effekseer.

All the predefined materials works, but user defined materials are not supported now. It will be supported in future.

The callback APIs may change in future , but it will always be simple enough.

Contributors are welcome.

Build

Use luamake : https://github.com/actboy168/luamake

Or put source files (in renderer) into your project, and link effekseer library.

How to use

You should initialize a structure EffekseerRendererBGFX::InitArgs to create a bgfx renderer.

EFXBGFX_API EffekseerRenderer::RendererRef CreateRenderer(struct InitArgs *init);
EFXBGFX_API Effekseer::ModelRendererRef CreateModelRenderer(EffekseerRenderer::RendererRef renderer, struct InitArgs *init);

These APIs could create the renderer and model renderer for effekseer, See examples for the details.

struct InitArgs {
	int squareMaxCount;	// Max count of sprites
	bgfx_view_id_t viewid;	// The ViewID that effekseer will render to.
	bgfx_interface_vtbl_t *bgfx;	// The bgfx APIs. Use `bgfx_get_interface()`.

	// Some callback functions, See below for details.
	bgfx_shader_handle_t (*shader_load)(const char *mat, const char *name, const char *type, void *ud);
	bgfx_texture_handle_t (*texture_get)(int texture_type, void *parm, void *ud);	// background or depth (with param)
	int (*texture_load)(const char *name, int srgb, void *ud);
	void (*texture_unload)(int id, void *ud);
	bgfx_texture_handle_t (*texture_handle)(int id, void *ud);	// translate id to handle
	void * ud;
};
bgfx_shader_handle_t shader_load(const char *mat, const char *name, const char *type, void *ud);

When renderer need a shader, it will call this function.

  • mat is the material name, NULL for predefined material.
  • name is the shader name.
  • type is "vs" or "fs".
  • ud is arguments from InitArgs.

The predefined shaders for bgfx is at shaders dir, compile them with bgfx toolset by yourself.

This function should return a valid bgfx shader handle.

int texture_load(const char *name, int srgb, void *ud);

When renderer need a texture, it will call this function.

  • name is the texture name.
  • srgb true means it should be created as a SRGB texture.
  • ud is arguments from InitArgs.

This function should return a texture id. (-1 as invalid) You don't need load texture immediately, and you can just alloc an id for it.

void texture_unload(int id, void *ud);

If the texture loaded by texture_load has not be no longer used by renderer, this function will be called.

bgfx_texture_handle_t texture_handle(int id, void *ud);

When renderer use a texture, it will call this function to translate id to bgfx texture handle.

bgfx_texture_handle_t texture_get(int texture_type, void *parm, void *ud);

When renderer need the TEXTURE_BACKGROUND (usually it's a render target) or the TEXTURE_DEPTH, it will call this function. When the texture_type is TEXTURE_DEPTH, you should offer an additional argument DepthReconstructionParameter.

struct DepthReconstructionParameter {
	float DepthBufferScale;
	float DepthBufferOffset;
	float ProjectionMatrix33;
	float ProjectionMatrix34;
	float ProjectionMatrix43;
	float ProjectionMatrix44;
};

This function should return a valid bgfx texture handle.

This callback function can be NULL for optional. If you haven't offer this callback, some features of effekseer will be disabled.

efkbgfx's People

Contributors

junjie020 avatar cloudwu avatar actboy168 avatar aimoonchen avatar pourtheworld avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.