Commit 715b6dd5 authored by Martin Finkel's avatar Martin Finkel
Browse files

WIP-2

parent 781898ce
......@@ -13,6 +13,7 @@
#include "Unity/IUnityGraphicsD3D11.h"
#include "Log.h"
#include <algorithm>
#include <dxgi1_2.h>
#include <comdef.h>
......@@ -93,6 +94,10 @@ struct render_context
ID3D11ShaderResourceView *textureShaderInput;
ID3D11RenderTargetView *textureRenderTarget;
ID3D11Texture2D *texture2;
ID3D11ShaderResourceView *textureShaderInput2;
ID3D11RenderTargetView *textureRenderTarget2;
CRITICAL_SECTION sizeLock; // the ReportSize callback cannot be called during/after the Cleanup_cb is called
unsigned width, height;
void (*ReportSize)(void *ReportOpaque, unsigned width, unsigned height);
......@@ -268,6 +273,18 @@ void RenderAPI_D3D11::CreateResources(struct render_context *ctx)
pMultithread->Release();
}
// D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc = {
// .Format = DXGI_FORMAT_R8G8B8A8_UNORM,
// .ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D,
// };
// hr = ctx->d3device->CreateRenderTargetView(ctx->texture2, &renderTargetViewDesc, &ctx->textureRenderTarget2);
// if (FAILED(hr))
// {
// DEBUG("FAILED ctx->d3device->CreateRenderTargetView(ctx->texture, &renderTargetViewDesc, &ctx->textureRenderTarget)");
// abort();
// }
DEBUG("Compiling shaders....\n");
ID3D10Blob *VS, *PS, *pErrBlob;
......@@ -487,7 +504,8 @@ void RenderAPI_D3D11::Swap_cb( void* opaque )
DEBUG("SWAP");
struct render_context *ctx = static_cast<struct render_context *>( opaque );
// ctx->swapchain->Present( 0, 0 );
// std::swap(ctx->texture2, ctx->texture);
ctx->updated = true;
}
......
#include "PlatformBase.h"
#include "RenderAPI.h"
#include "Log.h"
#include <map>
#include <windows.h>
......@@ -18,6 +19,7 @@ static int g_TextureHeight = 0;
static int g_TextureRowPitch = 0;
libvlc_instance_t * inst;
libvlc_media_player_t * mp;
static IUnityGraphics* s_Graphics = NULL;
static std::map<libvlc_media_player_t*,RenderAPI*> contexts = {};
......@@ -52,7 +54,7 @@ CreateAndInitMediaPlayer(libvlc_instance_t* libvlc)
return NULL;
}
libvlc_media_player_t *mp = libvlc_media_player_new(inst);
mp = libvlc_media_player_new(inst);
RenderAPI* s_CurrentAPI;
if (mp == NULL) {
......@@ -99,24 +101,10 @@ err:
return NULL;
}
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
SetupTextureInfo(UINT width, UINT height, void* hwnd)
{
if(hwnd == NULL)
DEBUG("HWND is NULL");
DEBUG("width: %u Height: %u Hwnd: %u", width, height, hwnd);
Width = width;
Height = height;
Hwnd = hwnd;
}
extern "C" void* UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
getVideoFrameVLC (libvlc_media_player_t* mp, bool * updated)
{
if(mp == NULL)
if(mp == NULL)
return nullptr;
RenderAPI* s_CurrentAPI = contexts.find(mp)->second;
......@@ -188,7 +176,43 @@ static void UNITY_INTERFACE_API OnRenderEvent(int eventID)
{
}
void TextureUpdateCallback(int eventID, void* data)
{
auto event = static_cast<UnityRenderingExtEventType>(eventID);
if (event == kUnityRenderingExtEventUpdateTextureBeginV2)
{
auto *pParams = reinterpret_cast<UnityRenderingExtTextureUpdateParamsV2*>(data);
if(mp == NULL)
return;
RenderAPI* s_CurrentAPI = contexts.find(mp)->second;
bool* updated;
if (!s_CurrentAPI) {
DEBUG("Error, no Render API");
if (updated)
*updated = false;
return;
}
void* tex = s_CurrentAPI->getVideoFrame(updated);
DEBUG("SWAPPING -===================");
std::swap(tex, pParams->texData);
}
else if (event == kUnityRenderingExtEventUpdateTextureEndV2)
{
}
}
extern "C" UnityRenderingEvent UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API GetRenderEventFunc()
{
return OnRenderEvent;
}
extern "C" UnityRenderingEventAndData UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API GetTextureUpdateCallback()
{
return TextureUpdateCallback;
}
\ No newline at end of file
#pragma once
#include "IUnityInterface.h"
#include <cstdint>
enum UnityRenderingExtEventType
{
kUnityRenderingExtEventSetStereoTarget, // issued during SetStereoTarget and carrying the current 'eye' index as parameter
kUnityRenderingExtEventSetStereoEye, // issued during stereo rendering at the beginning of each eye's rendering loop. It carries the current 'eye' index as parameter
kUnityRenderingExtEventStereoRenderingDone, // issued after the rendering has finished
kUnityRenderingExtEventBeforeDrawCall, // issued during BeforeDrawCall and carrying UnityRenderingExtBeforeDrawCallParams as parameter
kUnityRenderingExtEventAfterDrawCall, // issued during AfterDrawCall. This event doesn't carry any parameters
kUnityRenderingExtEventCustomGrab, // issued during GrabIntoRenderTexture since we can't simply copy the resources
// when custom rendering is used - we need to let plugin handle this. It carries over
// a UnityRenderingExtCustomBlitParams params = { X, source, dest, 0, 0 } ( X means it's irrelevant )
kUnityRenderingExtEventCustomBlit, // issued by plugin to insert custom blits. It carries over UnityRenderingExtCustomBlitParams as param.
kUnityRenderingExtEventUpdateTextureBegin, // Deprecated.
kUnityRenderingExtEventUpdateTextureEnd, // Deprecated.
kUnityRenderingExtEventUpdateTextureBeginV1 = kUnityRenderingExtEventUpdateTextureBegin, // Deprecated. Issued to update a texture. It carries over UnityRenderingExtTextureUpdateParamsV1
kUnityRenderingExtEventUpdateTextureEndV1 = kUnityRenderingExtEventUpdateTextureEnd, // Deprecated. Issued to signal the plugin that the texture update has finished. It carries over the same UnityRenderingExtTextureUpdateParamsV1 as kUnityRenderingExtEventUpdateTextureBeginV1
kUnityRenderingExtEventUpdateTextureBeginV2, // Issued to update a texture. It carries over UnityRenderingExtTextureUpdateParamsV2
kUnityRenderingExtEventUpdateTextureEndV2, // Issued to signal the plugin that the texture update has finished. It carries over the same UnityRenderingExtTextureUpdateParamsV2 as kUnityRenderingExtEventUpdateTextureBeginV2
// keep this last
kUnityRenderingExtEventCount,
kUnityRenderingExtUserEventsStart = kUnityRenderingExtEventCount
};
typedef enum UnityGfxRenderer
{
......@@ -47,3 +71,202 @@ UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL,0x8C5AD4926EB17B11ULL,IUnity
// Certain Unity APIs (GL.IssuePluginEvent, CommandBuffer.IssuePluginEvent) can callback into native plugins.
// Provide them with an address to a function of this signature.
typedef void (UNITY_INTERFACE_API * UnityRenderingEvent)(int eventId);
typedef void (UNITY_INTERFACE_API * UnityRenderingEventAndData)(int eventId, void* data);
void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityRenderingExtEvent(UnityRenderingExtEventType event, void* data);
enum UnityRenderingExtTextureFormat
{
kUnityRenderingExtFormatNone = 0, kUnityRenderingExtFormatFirst = kUnityRenderingExtFormatNone,
// sRGB formats
kUnityRenderingExtFormatR8_SRGB,
kUnityRenderingExtFormatR8G8_SRGB,
kUnityRenderingExtFormatR8G8B8_SRGB,
kUnityRenderingExtFormatR8G8B8A8_SRGB,
// 8 bit integer formats
kUnityRenderingExtFormatR8_UNorm,
kUnityRenderingExtFormatR8G8_UNorm,
kUnityRenderingExtFormatR8G8B8_UNorm,
kUnityRenderingExtFormatR8G8B8A8_UNorm,
kUnityRenderingExtFormatR8_SNorm,
kUnityRenderingExtFormatR8G8_SNorm,
kUnityRenderingExtFormatR8G8B8_SNorm,
kUnityRenderingExtFormatR8G8B8A8_SNorm,
kUnityRenderingExtFormatR8_UInt,
kUnityRenderingExtFormatR8G8_UInt,
kUnityRenderingExtFormatR8G8B8_UInt,
kUnityRenderingExtFormatR8G8B8A8_UInt,
kUnityRenderingExtFormatR8_SInt,
kUnityRenderingExtFormatR8G8_SInt,
kUnityRenderingExtFormatR8G8B8_SInt,
kUnityRenderingExtFormatR8G8B8A8_SInt,
// 16 bit integer formats
kUnityRenderingExtFormatR16_UNorm,
kUnityRenderingExtFormatR16G16_UNorm,
kUnityRenderingExtFormatR16G16B16_UNorm,
kUnityRenderingExtFormatR16G16B16A16_UNorm,
kUnityRenderingExtFormatR16_SNorm,
kUnityRenderingExtFormatR16G16_SNorm,
kUnityRenderingExtFormatR16G16B16_SNorm,
kUnityRenderingExtFormatR16G16B16A16_SNorm,
kUnityRenderingExtFormatR16_UInt,
kUnityRenderingExtFormatR16G16_UInt,
kUnityRenderingExtFormatR16G16B16_UInt,
kUnityRenderingExtFormatR16G16B16A16_UInt,
kUnityRenderingExtFormatR16_SInt,
kUnityRenderingExtFormatR16G16_SInt,
kUnityRenderingExtFormatR16G16B16_SInt,
kUnityRenderingExtFormatR16G16B16A16_SInt,
// 32 bit integer formats
kUnityRenderingExtFormatR32_UInt,
kUnityRenderingExtFormatR32G32_UInt,
kUnityRenderingExtFormatR32G32B32_UInt,
kUnityRenderingExtFormatR32G32B32A32_UInt,
kUnityRenderingExtFormatR32_SInt,
kUnityRenderingExtFormatR32G32_SInt,
kUnityRenderingExtFormatR32G32B32_SInt,
kUnityRenderingExtFormatR32G32B32A32_SInt,
// HDR formats
kUnityRenderingExtFormatR16_SFloat,
kUnityRenderingExtFormatR16G16_SFloat,
kUnityRenderingExtFormatR16G16B16_SFloat,
kUnityRenderingExtFormatR16G16B16A16_SFloat,
kUnityRenderingExtFormatR32_SFloat,
kUnityRenderingExtFormatR32G32_SFloat,
kUnityRenderingExtFormatR32G32B32_SFloat,
kUnityRenderingExtFormatR32G32B32A32_SFloat,
// Luminance and Alpha format
kUnityRenderingExtFormatL8_UNorm,
kUnityRenderingExtFormatA8_UNorm,
kUnityRenderingExtFormatA16_UNorm,
// BGR formats
kUnityRenderingExtFormatB8G8R8_SRGB,
kUnityRenderingExtFormatB8G8R8A8_SRGB,
kUnityRenderingExtFormatB8G8R8_UNorm,
kUnityRenderingExtFormatB8G8R8A8_UNorm,
kUnityRenderingExtFormatB8G8R8_SNorm,
kUnityRenderingExtFormatB8G8R8A8_SNorm,
kUnityRenderingExtFormatB8G8R8_UInt,
kUnityRenderingExtFormatB8G8R8A8_UInt,
kUnityRenderingExtFormatB8G8R8_SInt,
kUnityRenderingExtFormatB8G8R8A8_SInt,
// 16 bit packed formats
kUnityRenderingExtFormatR4G4B4A4_UNormPack16,
kUnityRenderingExtFormatB4G4R4A4_UNormPack16,
kUnityRenderingExtFormatR5G6B5_UNormPack16,
kUnityRenderingExtFormatB5G6R5_UNormPack16,
kUnityRenderingExtFormatR5G5B5A1_UNormPack16,
kUnityRenderingExtFormatB5G5R5A1_UNormPack16,
kUnityRenderingExtFormatA1R5G5B5_UNormPack16,
// Packed formats
kUnityRenderingExtFormatE5B9G9R9_UFloatPack32,
kUnityRenderingExtFormatB10G11R11_UFloatPack32,
kUnityRenderingExtFormatA2B10G10R10_UNormPack32,
kUnityRenderingExtFormatA2B10G10R10_UIntPack32,
kUnityRenderingExtFormatA2B10G10R10_SIntPack32,
kUnityRenderingExtFormatA2R10G10B10_UNormPack32,
kUnityRenderingExtFormatA2R10G10B10_UIntPack32,
kUnityRenderingExtFormatA2R10G10B10_SIntPack32,
kUnityRenderingExtFormatA2R10G10B10_XRSRGBPack32,
kUnityRenderingExtFormatA2R10G10B10_XRUNormPack32,
kUnityRenderingExtFormatR10G10B10_XRSRGBPack32,
kUnityRenderingExtFormatR10G10B10_XRUNormPack32,
kUnityRenderingExtFormatA10R10G10B10_XRSRGBPack32,
kUnityRenderingExtFormatA10R10G10B10_XRUNormPack32,
// ARGB formats... TextureFormat legacy
kUnityRenderingExtFormatA8R8G8B8_SRGB,
kUnityRenderingExtFormatA8R8G8B8_UNorm,
kUnityRenderingExtFormatA32R32G32B32_SFloat,
// Depth Stencil for formats
kUnityRenderingExtFormatD16_UNorm,
kUnityRenderingExtFormatD24_UNorm,
kUnityRenderingExtFormatD24_UNorm_S8_UInt,
kUnityRenderingExtFormatD32_SFloat,
kUnityRenderingExtFormatD32_SFloat_S8_Uint,
kUnityRenderingExtFormatS8_Uint,
// Compression formats
kUnityRenderingExtFormatRGBA_DXT1_SRGB,
kUnityRenderingExtFormatRGBA_DXT1_UNorm,
kUnityRenderingExtFormatRGBA_DXT3_SRGB,
kUnityRenderingExtFormatRGBA_DXT3_UNorm,
kUnityRenderingExtFormatRGBA_DXT5_SRGB,
kUnityRenderingExtFormatRGBA_DXT5_UNorm,
kUnityRenderingExtFormatR_BC4_UNorm,
kUnityRenderingExtFormatR_BC4_SNorm,
kUnityRenderingExtFormatRG_BC5_UNorm,
kUnityRenderingExtFormatRG_BC5_SNorm,
kUnityRenderingExtFormatRGB_BC6H_UFloat,
kUnityRenderingExtFormatRGB_BC6H_SFloat,
kUnityRenderingExtFormatRGBA_BC7_SRGB,
kUnityRenderingExtFormatRGBA_BC7_UNorm,
kUnityRenderingExtFormatRGB_PVRTC_2Bpp_SRGB,
kUnityRenderingExtFormatRGB_PVRTC_2Bpp_UNorm,
kUnityRenderingExtFormatRGB_PVRTC_4Bpp_SRGB,
kUnityRenderingExtFormatRGB_PVRTC_4Bpp_UNorm,
kUnityRenderingExtFormatRGBA_PVRTC_2Bpp_SRGB,
kUnityRenderingExtFormatRGBA_PVRTC_2Bpp_UNorm,
kUnityRenderingExtFormatRGBA_PVRTC_4Bpp_SRGB,
kUnityRenderingExtFormatRGBA_PVRTC_4Bpp_UNorm,
kUnityRenderingExtFormatRGB_ETC_UNorm,
kUnityRenderingExtFormatRGB_ETC2_SRGB,
kUnityRenderingExtFormatRGB_ETC2_UNorm,
kUnityRenderingExtFormatRGB_A1_ETC2_SRGB,
kUnityRenderingExtFormatRGB_A1_ETC2_UNorm,
kUnityRenderingExtFormatRGBA_ETC2_SRGB,
kUnityRenderingExtFormatRGBA_ETC2_UNorm,
kUnityRenderingExtFormatR_EAC_UNorm,
kUnityRenderingExtFormatR_EAC_SNorm,
kUnityRenderingExtFormatRG_EAC_UNorm,
kUnityRenderingExtFormatRG_EAC_SNorm,
kUnityRenderingExtFormatRGBA_ASTC4X4_SRGB,
kUnityRenderingExtFormatRGBA_ASTC4X4_UNorm,
kUnityRenderingExtFormatRGBA_ASTC5X5_SRGB,
kUnityRenderingExtFormatRGBA_ASTC5X5_UNorm,
kUnityRenderingExtFormatRGBA_ASTC6X6_SRGB,
kUnityRenderingExtFormatRGBA_ASTC6X6_UNorm,
kUnityRenderingExtFormatRGBA_ASTC8X8_SRGB,
kUnityRenderingExtFormatRGBA_ASTC8X8_UNorm,
kUnityRenderingExtFormatRGBA_ASTC10X10_SRGB,
kUnityRenderingExtFormatRGBA_ASTC10X10_UNorm,
kUnityRenderingExtFormatRGBA_ASTC12X12_SRGB,
kUnityRenderingExtFormatRGBA_ASTC12X12_UNorm,
// Video formats
kUnityRenderingExtFormatYUV2,
// Automatic formats, back-end decides
kUnityRenderingExtFormatLDRAuto,
kUnityRenderingExtFormatHDRAuto,
kUnityRenderingExtFormatDepthAuto,
kUnityRenderingExtFormatShadowAuto,
kUnityRenderingExtFormatVideoAuto, kUnityRenderingExtFormatLast = kUnityRenderingExtFormatVideoAuto, // Remove?
};
struct UnityRenderingExtTextureUpdateParamsV2
{
void* texData; // source data for the texture update. Must be set by the plugin
intptr_t textureID; // texture ID of the texture to be updated.
unsigned int userData; // user defined data. Set by the plugin
UnityRenderingExtTextureFormat format; // format of the texture to be updated
unsigned int width; // width of the texture
unsigned int height; // height of the texture
unsigned int bpp; // texture bytes per pixel.
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment