Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgfx module #240

Merged
merged 9 commits into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ println "${deployment.type.name()} BUILD"

enum Artifacts {
CORE("lwjgl", true, "LWJGL", "The LWJGL core library."),
BGFX(
"lwjgl-bgfx", false, "LWJGL - bgfx bindings",
"A cross-platform, graphics API agnostic rendering library. It provides a high performance, low level abstraction for common platform graphics APIs like OpenGL, Direct3D and Apple Metal."
),
EGL(
"lwjgl-egl", false, "LWJGL - EGL bindings",
"An interface between Khronos rendering APIs such as OpenGL ES or OpenVG and the underlying native platform window system."
Expand Down
13 changes: 13 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<compilerarg value="-Xno-param-assertions"/>
<compilerarg value="-Xreport-perf"/>

<src path="${src.templates.kotlin}/org/lwjgl/bgfx" if:true="${binding.bgfx}"/>
<src path="${src.templates.kotlin}/org/lwjgl/egl" if:true="${binding.egl}"/>
<src path="${src.templates.kotlin}/org/lwjgl/egl/EGLTypes.kt" unless:true="${binding.egl}"/>
<src path="${src.templates.kotlin}/org/lwjgl/glfw" if:true="${binding.glfw}"/>
Expand Down Expand Up @@ -253,6 +254,7 @@
<include name="org/lwjgl/*.java"/>
<include name="org/lwjgl/system/**"/>

<include name="org/lwjgl/bgfx/**" if:true="${binding.bgfx}"/>
<include name="org/lwjgl/egl/**" if:true="${binding.egl}"/>
<include name="org/lwjgl/glfw/**" if:true="${binding.glfw}"/>
<include name="org/lwjgl/nanovg/**" if:true="${binding.nanovg}"/>
Expand All @@ -264,6 +266,7 @@
</patternset>

<patternset id="core.generated.files">
<include name="org/lwjgl/bgfx/**" if:true="${binding.bgfx}"/>
<include name="org/lwjgl/egl/**" if:true="${binding.egl}"/>
<include name="org/lwjgl/glfw/**" if:true="${binding.glfw}"/>
<include name="org/lwjgl/nanovg/**" if:true="${binding.nanovg}"/>
Expand Down Expand Up @@ -389,11 +392,13 @@
<classpath>
<pathelement path="${bin.core}"/>
<pathelement path="${lib}/testng.jar"/>
<pathelement path="${lib}/joml.jar"/>
</classpath>

<src path="${src.tests}/"/>

<!-- Demos -->
<include name="org/lwjgl/demo/bgfx/**" if:true="${binding.bgfx}"/>
<include name="org/lwjgl/demo/egl/**" if:true="${egl_glfw}"/>
<include name="org/lwjgl/demo/glfw/**" if:true="${binding.glfw}"/>
<include name="org/lwjgl/demo/nanovg/**" if:true="${nanovg}"/>
Expand Down Expand Up @@ -472,6 +477,7 @@
<java classname="${class}" classpathref="runtime.classpath" fork="true" failonerror="${failonerror}" spawn="${spawn}" taskname="Demo">
<classpath>
<pathelement path="${lib}/testng.jar"/>
<pathelement path="${lib}/joml.jar"/>
</classpath>

<jvmarg value="-Djava.library.path=${lib}"/>
Expand Down Expand Up @@ -807,6 +813,13 @@
</custom>
</release-module>

<!-- bgfx -->
<release-module package="org.lwjgl.bgfx" name="bgfx" java-only="true" title="bgfx" license="bgfx" if:true="${binding.bgfx}">
<sources>
<fileset dir="${src.core}"><include name="org/lwjgl/bgfx/**"/></fileset>
</sources>
</release-module>

<!-- EGL -->
<release-module package="org.lwjgl.egl" name="egl" java-only="true" title="EGL" license="khronos" if:true="${binding.egl}">
<sources>
Expand Down
2 changes: 1 addition & 1 deletion config/build-assets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ This script is included in /build.xml and depends on /build-definitions.xml
</sequential>
</macrodef>

</project>
</project>
1 change: 1 addition & 0 deletions config/build-bindings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This script is included in /config/build-definitions.xml.

<!-- // ========== BINDING FLAGS ======== // -->

<property name="binding.bgfx" value="true"/>
<property name="binding.egl" value="true"/>
<property name="binding.glfw" value="true"/>
<property name="binding.jawt" value="true"/>
Expand Down
26 changes: 26 additions & 0 deletions doc/3rdparty/bgfx_license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2010-2016 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
116 changes: 116 additions & 0 deletions modules/core/src/main/java/org/lwjgl/bgfx/BGFXUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
package org.lwjgl.bgfx;

import static org.lwjgl.bgfx.BGFX.*;

/** bgfx utilities. */
public final class BGFXUtil {

private BGFXUtil() {
}

public static long BGFX_STATE_ALPHA_REF(long _ref) {
return (_ref << BGFX_STATE_ALPHA_REF_SHIFT) & BGFX_STATE_ALPHA_REF_MASK;
}

public static long BGFX_STATE_POINT_SIZE(long _size) {
return (_size << BGFX_STATE_POINT_SIZE_SHIFT) & BGFX_STATE_POINT_SIZE_MASK;
}

public static long BGFX_STATE_BLEND_FUNC_SEPARATE(long _srcRGB, long _dstRGB, long _srcA, long _dstA) {
return ((_srcRGB | (_dstRGB << 4))) | ((_srcA | (_dstA << 4)) << 8);
}

public static long BGFX_STATE_BLEND_EQUATION_SEPARATE(long _rgb, long _a) {
return _rgb | (_a << 3);
}

public static long BGFX_STATE_BLEND_FUNC(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC_SEPARATE(_src, _dst, _src, _dst);
}

public static long BGFX_STATE_BLEND_EQUATION(long _equation) {
return BGFX_STATE_BLEND_EQUATION_SEPARATE(_equation, _equation);
}

public static long BGFX_STATE_BLEND_ADD(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE);
}

public static long BGFX_STATE_BLEND_ALPHA(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
}

public static long BGFX_STATE_BLEND_DARKEN(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE)
| BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_MIN);
}

public static long BGFX_STATE_BLEND_LIGHTEN(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ONE)
| BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_MAX);
}

public static long BGFX_STATE_BLEND_MULTIPLY(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO);
}

public static long BGFX_STATE_BLEND_NORMAL(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_ALPHA);
}

public static long BGFX_STATE_BLEND_SCREEN(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_COLOR);
}

public static long BGFX_STATE_BLEND_LINEAR_BURN(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_INV_DST_COLOR)
| BGFX_STATE_BLEND_EQUATION(BGFX_STATE_BLEND_EQUATION_SUB);
}

public static long BGFX_STATE_BLEND_FUNC_RT_x(long _src, long _dst) {
return (_src >> BGFX_STATE_BLEND_SHIFT) | ((_dst >> BGFX_STATE_BLEND_SHIFT) << 4);
}

public static long BGFX_STATE_BLEND_FUNC_RT_xE(long _src, long _dst, long _equation) {
return BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) | ((_equation >> BGFX_STATE_BLEND_EQUATION_SHIFT) << 8);
}

public static long BGFX_STATE_BLEND_FUNC_RT_1(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) << 0;
}

public static long BGFX_STATE_BLEND_FUNC_RT_2(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) << 11;
}

public static long BGFX_STATE_BLEND_FUNC_RT_3(long _src, long _dst) {
return BGFX_STATE_BLEND_FUNC_RT_x(_src, _dst) << 22;
}

public static long BGFX_STATE_BLEND_FUNC_RT_1E(long _src, long _dst, long _equation) {
return BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation) << 0;
}
public static long BGFX_STATE_BLEND_FUNC_RT_2E(long _src, long _dst, long _equation) {
return BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation) << 11;
}
public static long BGFX_STATE_BLEND_FUNC_RT_3E(long _src, long _dst, long _equation) {
return BGFX_STATE_BLEND_FUNC_RT_xE(_src, _dst, _equation) << 22;
}

public static int BGFX_STENCIL_FUNC_REF(int _ref) {
return (_ref << BGFX_STENCIL_FUNC_REF_SHIFT) & BGFX_STENCIL_FUNC_REF_MASK;
}

public static int BGFX_STENCIL_FUNC_RMASK(int _mask) {
return (_mask << BGFX_STENCIL_FUNC_RMASK_SHIFT) & BGFX_STENCIL_FUNC_RMASK_MASK;
}

public static int BGFX_TEXTURE_BORDER_COLOR(int _index) {
return (_index << BGFX_TEXTURE_BORDER_COLOR_SHIFT) & BGFX_TEXTURE_BORDER_COLOR_MASK;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public class Configuration<T> {
*/
public static final Configuration<Boolean> DEBUG_FUNCTIONS = new Configuration<>("org.lwjgl.util.DebugFunctions", StateInit.BOOLEAN);

// -- BGFX

/** Similar to {@link #LIBRARY_NAME} for the BGFX library (<b>org.lwjgl.bgfx.libname</b>). */
public static final Configuration<String> BGFX_LIBRARY_NAME = new Configuration<>("org.lwjgl.bgfx.libname", StateInit.STRING);

// -- EGL

/**
Expand Down
126 changes: 126 additions & 0 deletions modules/core/src/test/java/org/lwjgl/demo/bgfx/HelloBGFX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
package org.lwjgl.demo.bgfx;

import org.lwjgl.bgfx.BGFXPlatformData;
import org.lwjgl.glfw.GLFWNativeCocoa;
import org.lwjgl.glfw.GLFWNativeWin32;
import org.lwjgl.glfw.GLFWNativeX11;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.Platform;

import java.nio.ByteBuffer;

import static org.lwjgl.bgfx.BGFX.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryUtil.*;

/**
* bgfx demo: 25-C99
*
* <p>This demo is a Java port of
* <a href="https://github.com/bkaradzic/bgfx/tree/master/examples/25-c99">https://github.com/bkaradzic/bgfx/tree/master/examples/25-c99</a>.</p>
*/
public final class HelloBGFX {

private HelloBGFX() {}

@SuppressWarnings("UnnecessaryLocalVariable")
public static void main(String[] args) {

int renderer = BGFX_RENDERER_TYPE_COUNT;
int pciId = BGFX_PCI_ID_NONE;
int width = 1280;
int height = 720;
int debug = BGFX_DEBUG_TEXT;
int reset = BGFX_RESET_VSYNC;

if ( !glfwInit() ) {
throw new RuntimeException("Error initializing GLFW");
}

// the client (renderer) API is managed by bgfx
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

long window = glfwCreateWindow(width, height, "25-C99", 0, 0);

if ( window == 0 ) {
throw new RuntimeException("Error creating GLFW window");
}

try ( MemoryStack stack = MemoryStack.stackPush() ) {
BGFXPlatformData platformData = BGFXPlatformData.callocStack(stack);

switch ( Platform.get() ) {
case LINUX:
platformData.ndt(GLFWNativeX11.glfwGetX11Display());
platformData.nwh(GLFWNativeX11.glfwGetX11Window(window));
break;
case MACOSX:
platformData.ndt(NULL);
platformData.nwh(GLFWNativeCocoa.glfwGetCocoaWindow(window));
break;
case WINDOWS:
platformData.ndt(NULL);
platformData.nwh(GLFWNativeWin32.glfwGetWin32Window(window));
break;
}

platformData.context(NULL);
platformData.backBuffer(NULL);
platformData.backBufferDS(NULL);

bgfx_set_platform_data(platformData);
}

if ( !bgfx_init(renderer, pciId, 0, null, null) ) {
throw new RuntimeException("Error initializing bgfx renderer");
}

bgfx_reset(width, height, reset);

bgfx_set_debug(debug);

bgfx_set_view_clear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0);

ByteBuffer logo = Logo.createLogo();

while ( !glfwWindowShouldClose(window) ) {

glfwPollEvents();

bgfx_set_view_rect(0, 0, 0, width, height);

bgfx_touch(0);

bgfx_dbg_text_clear(0, false);

bgfx_dbg_text_image(Math.max(width / 2 / 8, 20) - 20,
Math.max(height / 2 / 16, 6) - 6,
40,
12,
logo,
160);

bgfx_dbg_text_printf(0,
1,
0x4f,
"bgfx/examples/25-c99");

bgfx_dbg_text_printf(0,
2,
0x6f,
"Description: Initialization and debug text with C99 API.");

bgfx_frame(false);
}

bgfx_shutdown();

glfwDestroyWindow(window);
glfwTerminate();
}

}
Loading