﻿import os

from ctypes import cast, c_void_p

runtimeDir = "../runtime/"


def loadMem(filePath):
    filePath = runtimeDir + filePath
    with open(filePath, "rb") as f:
        read_data = f.read()
        size = len(read_data)
        memory = bgfx.copy(cast(read_data, c_void_p), size)
        return memory
    return None


def loadShader(shaderName):
    shaderPath = "shaders/dx9/"
    rendererType = bgfx.get_renderer_type()
    shaderPath = {
        bgfx.BGFX_RENDERER_TYPE_DIRECT3D11: "shaders/dx11/",
        bgfx.BGFX_RENDERER_TYPE_DIRECT3D12: "shaders/dx11/",
        bgfx.BGFX_RENDERER_TYPE_OPENGL: "shaders/glsl/",
        bgfx.BGFX_RENDERER_TYPE_METAL: "shaders/metal/",
        bgfx.BGFX_RENDERER_TYPE_OPENGLES: "shaders/gles/",
    }.get(rendererType, "shaders/dx9/")
    filePath = shaderPath + shaderName + ".bin"
    fileMemory = loadMem(filePath)
    shader = bgfx.create_shader(fileMemory)
    return shader


def loadProgram(vsName, fsName):
    vsh = loadShader(vsName)
    fsh = bgfx.BGFX_INVALID_HANDLE
    if (fsName != None):
        fsh = loadShader(fsName)
    return bgfx.create_program(vsh, fsh, True)

@@ -40,16 +40,39 @@
 void_p%0A%0A
+import pybgfx as bgfx%0A%0A
 runtimeD
@@ -512,16 +512,22 @@
 RECT3D11
+.value
 : %22shade
@@ -579,16 +579,22 @@
 RECT3D12
+.value
 : %22shade
@@ -642,16 +642,22 @@
 E_OPENGL
+.value
 : %22shade
@@ -704,16 +704,22 @@
 PE_METAL
+.value
 : %22shade
@@ -770,16 +770,22 @@
 OPENGLES
+.value
 : %22shade

Fix bgfx_utils