void Thin3DContext::CreatePresets() { // Build prebuilt objects T3DBlendStateDesc off = { false }; T3DBlendStateDesc additive = { true, T3DBlendEquation::ADD, T3DBlendFactor::ONE, T3DBlendFactor::ONE, T3DBlendEquation::ADD, T3DBlendFactor::ONE, T3DBlendFactor::ZERO }; T3DBlendStateDesc standard_alpha = { true, T3DBlendEquation::ADD, T3DBlendFactor::SRC_ALPHA, T3DBlendFactor::ONE_MINUS_SRC_ALPHA, T3DBlendEquation::ADD, T3DBlendFactor::ONE, T3DBlendFactor::ZERO }; T3DBlendStateDesc premul_alpha = { true, T3DBlendEquation::ADD, T3DBlendFactor::ONE, T3DBlendFactor::ONE_MINUS_SRC_ALPHA, T3DBlendEquation::ADD, T3DBlendFactor::ONE, T3DBlendFactor::ZERO }; bsPresets_[BS_OFF] = CreateBlendState(off); bsPresets_[BS_ADDITIVE] = CreateBlendState(additive); bsPresets_[BS_STANDARD_ALPHA] = CreateBlendState(standard_alpha); bsPresets_[BS_PREMUL_ALPHA] = CreateBlendState(premul_alpha); T3DSamplerStateDesc nearest = { CLAMP, CLAMP, NEAREST, NEAREST, NEAREST }; T3DSamplerStateDesc linear = { CLAMP, CLAMP, LINEAR, LINEAR, NEAREST }; sampsPresets_[SAMPS_NEAREST] = CreateSamplerState(nearest); sampsPresets_[SAMPS_LINEAR] = CreateSamplerState(linear); vsPresets_[VS_TEXTURE_COLOR_2D] = CreateVertexShader(glsl_vsTexCol, hlslVsTexCol, vulkan_vsTexCol); vsPresets_[VS_COLOR_2D] = CreateVertexShader(glsl_vsCol, hlslVsCol, vulkan_vsCol); fsPresets_[FS_TEXTURE_COLOR_2D] = CreateFragmentShader(glsl_fsTexCol, hlslFsTexCol, vulkan_fsTexCol); fsPresets_[FS_COLOR_2D] = CreateFragmentShader(glsl_fsCol, hlslFsCol, vulkan_fsCol); ssPresets_[SS_TEXTURE_COLOR_2D] = CreateShaderSet(vsPresets_[VS_TEXTURE_COLOR_2D], fsPresets_[FS_TEXTURE_COLOR_2D]); ssPresets_[SS_COLOR_2D] = CreateShaderSet(vsPresets_[VS_COLOR_2D], fsPresets_[FS_COLOR_2D]); }
GLRenderResourceManager::GLRenderResourceManager() { RasterizeDesc rasterDesc; DefaultRasterizeState = CreateRasterizeState(&rasterDesc); BlendDesc blendDesc; DefaultBlentState = CreateBlendState(&blendDesc, 1); DepthStencilDesc dsDesc; DefaultDepthStencilState = CreateDepthStencilState(&dsDesc, 0); SamplerDesc samplerDesc; DefaultSamplerState = CreateSamplerState(&samplerDesc); unsigned int pixelData[16]; memset(pixelData, 0xFF, 16 * sizeof(unsigned int)); BufferInitData data; data.Data = pixelData; data.RowPitch = 4 * 4; data.SlicePitch = 0; RenderTexture2D* tex = CreateTexture2D("DefaultTex", NULL, PF_R8G8B8A8_UNORM, 4, 4, false, false, SV_ShaderResource, 1, &data, 0); DefaultWhiteTexture2D = CreateSurfaceView(SV_ShaderResource, tex, PF_R8G8B8A8_UNORM); RegisterPropertyManager(ShaderPropertyManager::sManagerCamera); RegisterPropertyManager(ShaderPropertyManager::sManagerObject); RegisterPropertyManager(ShaderPropertyManager::sManagerMaterial); RegisterPropertyManager(ShaderPropertyManager::sManagerDirectionLight); RegisterPropertyManager(ShaderPropertyManager::sManagerPointLight); RegisterPropertyManager(ShaderPropertyManager::sManagerSpotLight); RegisterPropertyManager(ShaderPropertyManager::sManagerScene); RegisterPropertyManager(ShaderPropertyManager::sManagerShadowMapGen); RegisterPropertyManager(ShaderPropertyManager::sManagerGlobal); }
ProcessDateTime::ProcessDateTime() { SamplerInfo si; zero(&si, sizeof(si)); si.addressU = GS_ADDRESS_REPEAT; si.addressV = GS_ADDRESS_REPEAT; si.borderColor = 0; si.filter = GS_FILTER_LINEAR; ss = CreateSamplerState(si); globalOpacity = 100; bHasPre = false; texture = NULL; hFont = NULL; }
//-------------------------------------------------------------------------------------- // void RenderState::Impl::CreateSamplerState( // D3D11_FILTER filter, //フィルター // D3D11_TEXTURE_ADDRESS_MODE addressMode //アドレスモード // ID3D11SamplerState** pResult //受け取るインターフェイス // ); // 用途: サンプラーステートを作成するヘルパー関数 // 戻り値: なし //-------------------------------------------------------------------------------------- void RenderState::Impl::CreateSamplerState(D3D11_FILTER filter, D3D11_TEXTURE_ADDRESS_MODE addressMode, ID3D11SamplerState** pResult){ try{ auto Dev = App::GetApp()->GetDeviceResources(); auto pDx11Device = Dev->GetD3DDevice(); D3D11_SAMPLER_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Filter = filter; desc.AddressU = addressMode; desc.AddressV = addressMode; desc.AddressW = addressMode; desc.MaxAnisotropy = (pDx11Device->GetFeatureLevel() > D3D_FEATURE_LEVEL_9_1) ? 16 : 2; desc.MaxLOD = FLT_MAX; desc.ComparisonFunc = D3D11_COMPARISON_NEVER; HRESULT hr = pDx11Device->CreateSamplerState(&desc, pResult); if (FAILED(hr)){ // 初期化失敗 throw BaseException( L"サンプラーステート作成に失敗しました。", L"if(FAILED(pDx11Device->CreateSamplerState()))", L"RenderState::Impl::CreateSamplerState()" ); } } catch (...){ throw; } }
BOOL ShaderProcessor::ProcessShader(CTSTR input) { String curToken; BOOL bError = FALSE; SetCodeStart(input); TSTR lpLastPos = lpTemp; DWORD curInsideCount = 0; BOOL bNewCodeLine = TRUE; while(GetNextToken(curToken)) { TSTR lpCurPos = lpTemp-curToken.Length(); if(curToken[0] == '{') ++curInsideCount; else if(curToken[0] == '}') --curInsideCount; else if(curToken[0] == '(') ++curInsideCount; else if(curToken[0] == ')') --curInsideCount; else if(!curInsideCount && bNewCodeLine) //not inside any code, so this is some sort of declaration (function/struct/var) { if(curToken == TEXT("struct")) { //try to see if this is the vertex definition structure bool bFoundDefinitionStruct = false; HandMeAToken(curToken); ExpectTokenIgnore(TEXT("{")); curInsideCount = 1; do { HandMeAToken(curToken); if(curToken.Length() <= 6 && scmpi_n(curToken, TEXT("float"), 5) == 0) { String strType = curToken; String strName; HandMeAToken(strName); HandMeAToken(curToken); if(curToken[0] != ':') //cancel if not a vertex definition structure { bFoundDefinitionStruct = false; break; } String strSemantic; HandMeAToken(strSemantic); SemanticInfo semanticInfo; if(!GetSemanticInfo(strSemantic, semanticInfo)) { bFoundDefinitionStruct = false; break; } D3D10_INPUT_ELEMENT_DESC inputElement; inputElement.SemanticName = semanticInfo.lpName; inputElement.SemanticIndex = semanticInfo.index; inputElement.InputSlot = 0; inputElement.AlignedByteOffset = 0; inputElement.InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA; inputElement.InstanceDataStepRate = 0; if(strSemantic.CompareI(TEXT("color"))) inputElement.Format = DXGI_FORMAT_R8G8B8A8_UNORM; else { switch(strType[5]) { case 0: inputElement.Format = DXGI_FORMAT_R32_FLOAT; break; case '2': inputElement.Format = DXGI_FORMAT_R32G32_FLOAT; break; case '3': inputElement.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; break; //todo: check this some time case '4': inputElement.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; break; } } ExpectToken(TEXT(";"), TEXT(";")); PeekAtAToken(curToken); generatedLayout << inputElement; bFoundDefinitionStruct = true; } else { bFoundDefinitionStruct = false; break; //vertex definition structures should really only ever have float values } } while (curToken[0] != '}'); //set up the slots so they match up with vertex buffers if(bFoundDefinitionStruct) { UINT curSlot = 0; for(UINT i=0; i<generatedLayout.Num(); i++) { if(stricmp(generatedLayout[i].SemanticName, "SV_Position") == 0) { generatedLayout[i].InputSlot = curSlot++; break; } } for(UINT i=0; i<generatedLayout.Num(); i++) { if(stricmp(generatedLayout[i].SemanticName, "NORMAL") == 0) { generatedLayout[i].InputSlot = curSlot++; bHasNormals = true; break; } } for(UINT i=0; i<generatedLayout.Num(); i++) { if(stricmp(generatedLayout[i].SemanticName, "COLOR") == 0) { generatedLayout[i].InputSlot = curSlot++; bHasColors = true; break; } } for(UINT i=0; i<generatedLayout.Num(); i++) { if(stricmp(generatedLayout[i].SemanticName, "TANGENT") == 0) { generatedLayout[i].InputSlot = curSlot++; bHasTangents = true; break; } } bool bFoundTexCoord; do { bFoundTexCoord = false; for(UINT i=0; i<generatedLayout.Num(); i++) { if(generatedLayout[i].SemanticIndex == numTextureCoords && stricmp(generatedLayout[i].SemanticName, "TEXCOORD") == 0) { generatedLayout[i].InputSlot = curSlot++; numTextureCoords++; bFoundTexCoord = true; break; } } } while(bFoundTexCoord); } } else if( (curToken != TEXT("const")) && (curToken != TEXT("void")) && (curToken != TEXT(";")) ) { TSTR lpSavedPos = lpTemp; String savedToken = curToken; if(curToken == TEXT("uniform")) HandMeAToken(curToken); String strType = curToken; String strName; HandMeAToken(strName); PeekAtAToken(curToken); if(curToken[0] != '(') //verified variable { if(strType.CompareI(TEXT("samplerstate"))) { ShaderSampler &curSampler = *Samplers.CreateNew(); curSampler.name = strName; SamplerInfo info; ExpectToken(TEXT("{"), TEXT(";")); PeekAtAToken(curToken); while(curToken != TEXT("}")) { String strState; HandMeAToken(strState); ExpectToken(TEXT("="), TEXT(";")); String strValue; HandMeAToken(strValue); if(!AddState(info, strState, strValue)) EscapeLikeTheWind(TEXT(";")); ExpectToken(TEXT(";"), TEXT(";")); PeekAtAToken(curToken); } curSampler.sampler = CreateSamplerState(info); ExpectToken(TEXT("}"), TEXT("}")); ExpectTokenIgnore(TEXT(";")); //---------------------------------------- lpLastPos = lpTemp; continue; } else { ShaderParam *param = Params.CreateNew(); param->name = strName; if(curToken[0] == '[') { HandMeAToken(curToken); HandMeAToken(curToken); param->arrayCount = tstoi(curToken); ExpectToken(TEXT("]"), TEXT(";")); PeekAtAToken(curToken); } if(scmpi_n(strType, TEXT("texture"), 7) == 0) { TSTR lpType = strType.Array()+7; supr(lpType); if (!*lpType || (scmp(lpType, TEXT("1D")) && scmp(lpType, TEXT("2D")) && scmp(lpType, TEXT("3D")) && scmp(lpType, TEXT("CUBE"))) ) { bError = TRUE; } param->textureID = nTextures++; param->type = Parameter_Texture; strType = TEXT("sampler"); } else if(scmp_n(strType, TEXT("float"), 5) == 0) { CTSTR lpType = strType.Array()+5; if(*lpType == 0) param->type = Parameter_Float; else if(scmpi(lpType, TEXT("2")) == 0) param->type = Parameter_Vector2; else if(scmpi(lpType, TEXT("3")) == 0) param->type = Parameter_Vector3; else if(scmpi(lpType, TEXT("4")) == 0) param->type = Parameter_Vector4; else if(scmpi(lpType, TEXT("3x3")) == 0) param->type = Parameter_Matrix3x3; else if(scmpi(lpType, TEXT("4x4")) == 0) param->type = Parameter_Matrix; } else if(scmp(strType, TEXT("int")) == 0) param->type = Parameter_Int; else if(scmp(strType, TEXT("bool")) == 0) param->type = Parameter_Bool; if(curToken == TEXT("=")) { HandMeAToken(curToken); BufferOutputSerializer sOut(param->defaultValue); if(scmp(strType, TEXT("float")) == 0) { HandMeAToken(curToken); if(!ValidFloatString(curToken)) bError = TRUE; float fValue = (float)tstof(curToken); sOut << fValue; } else if(scmp(strType, TEXT("int")) == 0) { HandMeAToken(curToken); if(!ValidIntString(curToken)) bError = TRUE; int iValue = tstoi(curToken); sOut << iValue; } else if(scmp_n(strType, TEXT("float"), 5) == 0) { CTSTR lpFloatType = strType.Array()+5; int floatCount = 0; if(lpFloatType[0] == '1') floatCount = 1; else if(lpFloatType[0] == '2') floatCount = 2; else if(lpFloatType[0] == '3') floatCount = 3; else if(lpFloatType[0] == '4') floatCount = 4; else bError = TRUE; if(lpFloatType[1] == 'x') { if(lpFloatType[2] != '1') { if(lpFloatType[2] == '2') floatCount *= 2; else if(lpFloatType[2] == '3') floatCount *= 3; else if(lpFloatType[2] == '4') floatCount *= 4; else bError = TRUE; } } if(floatCount > 1) {ExpectToken(TEXT("{"), TEXT(";"));} int j; for(j=0; j<floatCount; j++) { if(j) { HandMeAToken(curToken); if(curToken[0] != ',') { bError = TRUE; break; } } HandMeAToken(curToken); if(!ValidFloatString(curToken)) { bError = TRUE; break; } float fValue = (float)tstof(curToken); sOut << fValue; } if(j != floatCount) //processing error occured { GotoToken(TEXT(";")); continue; } if(floatCount > 1) {ExpectToken(TEXT("}"), TEXT(";"));} } PeekAtAToken(curToken); } } //-------------------------- lpLastPos = lpTemp; bNewCodeLine = FALSE; continue; } lpTemp = lpSavedPos; curToken = savedToken; } } lpLastPos = lpTemp; bNewCodeLine = (curToken.IsValid() && ((curToken[0] == ';') || (curToken[0] == '}'))); } return !bError; }
void DeviceSource::Render(const Vect2 &pos, const Vect2 &size) { if(texture && bReadyToDraw) { Shader *oldShader = GetCurrentPixelShader(); SamplerState *sampler = NULL; if(colorConvertShader) { LoadPixelShader(colorConvertShader); if(bUseChromaKey) { float fSimilarity = float(keySimilarity)/1000.0f; float fBlendVal = float(max(keyBlend, 1)/1000.0f); float fSpillVal = (float(max(keySpillReduction, 1))/1000.0f); Vect2 pixelSize = 1.0f/GetSize(); colorConvertShader->SetColor (colorConvertShader->GetParameterByName(TEXT("keyBaseColor")), Color4(keyBaseColor)); colorConvertShader->SetColor (colorConvertShader->GetParameterByName(TEXT("chromaKey")), Color4(keyChroma)); colorConvertShader->SetVector2(colorConvertShader->GetParameterByName(TEXT("pixelSize")), pixelSize); colorConvertShader->SetFloat (colorConvertShader->GetParameterByName(TEXT("keySimilarity")), fSimilarity); colorConvertShader->SetFloat (colorConvertShader->GetParameterByName(TEXT("keyBlend")), fBlendVal); colorConvertShader->SetFloat (colorConvertShader->GetParameterByName(TEXT("keySpill")), fSpillVal); } } bool bFlip = bFlipVertical; if(colorType != DeviceOutputType_RGB) bFlip = !bFlip; float x, x2; if(bFlipHorizontal) { x2 = pos.x; x = x2+size.x; } else { x = pos.x; x2 = x+size.x; } float fOpacity = float(opacity)*0.01f; DWORD opacity255 = DWORD(fOpacity*255.0f); if(bUsePointFiltering) { SamplerInfo samplerinfo; samplerinfo.filter = GS_FILTER_POINT; sampler = CreateSamplerState(samplerinfo); LoadSamplerState(sampler, 0); } if(bFlip) DrawSprite(texture, (opacity255<<24) | 0xFFFFFF, x, pos.y, x2, pos.y+size.y); else DrawSprite(texture, (opacity255<<24) | 0xFFFFFF, x, pos.y+size.y, x2, pos.y); if(bUsePointFiltering) delete(sampler); if(colorConvertShader) LoadPixelShader(oldShader); } }
void CSLiveManager::BulidD3D() { Log::writeMessage(LOG_RTSPSERV, 1, "LiveSDK_Log:%s Invoke begin!", __FUNCTION__); bUseBack = BSParam.LiveSetting.bUseLiveSec; if (bUseBack) { if (BSParam.LiveSetting.Width < BSParam.LiveSetting.WidthSec || BSParam.LiveSetting.Height < BSParam.LiveSetting.HeightSec) { baseCX = BSParam.LiveSetting.WidthSec; baseCY = BSParam.LiveSetting.HeightSec; baseCX_back = BSParam.LiveSetting.Width; baseCY_back = BSParam.LiveSetting.Height; } else { baseCX = BSParam.LiveSetting.Width; baseCY = BSParam.LiveSetting.Height; baseCX_back = BSParam.LiveSetting.WidthSec; baseCY_back = BSParam.LiveSetting.HeightSec; } // baseCX_back = BSParam.LiveSetting.WidthSec; // baseCY_back = BSParam.LiveSetting.HeightSec; // baseCX = BSParam.LiveSetting.Width; // baseCY = BSParam.LiveSetting.Height; } else { if (baseCX == BSParam.LiveSetting.Width && baseCY == BSParam.LiveSetting.Height) return; baseCX = BSParam.LiveSetting.Width; baseCY = BSParam.LiveSetting.Height; } baseCX = MIN(MAX(baseCX, 128), 4096); baseCY = MIN(MAX(baseCY, 128), 4096); baseCX_back = MIN(MAX(baseCX_back, 128), 4096); baseCY_back = MIN(MAX(baseCY_back, 128), 4096); scaleCX = double(baseCX); scaleCY = double(baseCY); //align width to 128bit for fast SSE YUV4:2:0 conversion outputCX = scaleCX & 0xFFFFFFFC; outputCY = scaleCY & 0xFFFFFFFE; outputCX_back = baseCX_back & 0xFFFFFFFC; outputCY_back = baseCY_back & 0xFFFFFFFE; for (int i = 0; i < 2; ++i) { if (mainRenderTextures[i]) { delete mainRenderTextures[i]; mainRenderTextures[i] = NULL; } mainRenderTextures[i] = CreateRenderTarget(baseCX, baseCY, GS_BGRA, FALSE); } if (transitionTexture) { delete transitionTexture; transitionTexture = NULL; } transitionTexture = CreateRenderTarget(baseCX, baseCY, GS_BGRA, FALSE); if (transNewTexture) { delete transNewTexture; transNewTexture = NULL; } transNewTexture = CreateRenderTarget(baseCX, baseCY, GS_BGRA, FALSE); if (PreRenderTexture) { delete PreRenderTexture; PreRenderTexture = NULL; } PreRenderTexture = CreateRenderTarget(baseCX, baseCY, GS_BGRA, FALSE); if (yuvRenderTextures) { delete yuvRenderTextures; yuvRenderTextures = NULL; } yuvRenderTextures = CreateRenderTarget(outputCX, outputCY, GS_BGRA, FALSE); if (copyTextures) { delete copyTextures; copyTextures = NULL; } copyTextures = CreateTextureRead(outputCX, outputCY); if (copyRGBTexture) { delete copyRGBTexture; copyRGBTexture = NULL; } copyRGBTexture = CreateTextureRead(outputCX, outputCY); if (bUseBack) { if (yuvRenderTextures_back) { delete yuvRenderTextures_back; yuvRenderTextures_back = NULL; } yuvRenderTextures_back = CreateRenderTarget(outputCX_back, outputCY_back, GS_BGRA, FALSE); if (copyTextures_back) { delete copyTextures_back; copyTextures_back = NULL; } copyTextures_back = CreateTextureRead(outputCX_back, outputCY_back); } if (SDITexture) { delete SDITexture; SDITexture = NULL; } UINT Width, Heigth; SDITexture = CreateTextureFromFile(L"./img/SDIOUT.png",FALSE,Width,Heigth); if (ss) { delete ss; ss = NULL; } SamplerInfo si; zero(&si, sizeof(si)); si.filter = GS_FILTER_LINEAR; si.addressU = GS_ADDRESS_BORDER; si.addressV = GS_ADDRESS_BORDER; ss = CreateSamplerState(si); colorDesc.fullRange = false; colorDesc.primaries = ColorPrimaries_BT709; colorDesc.transfer = ColorTransfer_IEC6196621; colorDesc.matrix = outputCX >= 1280 || outputCY > 576 ? ColorMatrix_BT709 : ColorMatrix_SMPTE170M; Log::writeMessage(LOG_RTSPSERV, 1, "LiveSDK_Log:%s Invoke end!", __FUNCTION__); }