RID BlendStateParser::parse(JSONReader& reader, int childIndex) { BlendStateDescriptor descriptor; const char* entry = reader.get_string(childIndex, "src_blend"); descriptor.srcBlend = findBlendStateMapping(entry); entry = reader.get_string(childIndex, "dest_blend"); descriptor.destBlend = findBlendStateMapping(entry); entry = reader.get_string(childIndex, "src_blend_alpha"); descriptor.srcAlphaBlend = findBlendStateMapping(entry); entry = reader.get_string(childIndex, "dest_blend_alpha"); descriptor.destAlphaBlend = findBlendStateMapping(entry); reader.get(childIndex, "alpha_enabled", &descriptor.alphaEnabled); const char* name = reader.get_string(childIndex, "name"); return createBlendState(name, descriptor); }
bool Controller::init(RenderDX11* _renderer, string _workingDirectory) { m_terrain = new Terrain(); HRESULT hr; bool res; if(!_renderer) // no rendering available, go home return false; if(_workingDirectory == "") // dont set the current environment as a working directory you bozo return false; m_pWorkingDirectory = _workingDirectory; m_renderer = _renderer; /* --- Overview of how the data linking and abstraction works --- Property { struct<T>[] } --- Refs by Id (explicit) ---> Resources<T>[Id] Composition { Interface<Property>[] } --- Refs by Datatype (Id is implicit) ---> Property<T>[Id] LLC: Create raw data MLL: Create 'property struct', link to desired raw data HLC: Create 'composition struct', link to all desired properties (note: as of now only one property per type is allowed) */ /************************ LOW LEVEL CREATION *************************/ /* init default render resources */ // blendstates unsigned int ref; hr = createBlendState(ref, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, TRUE); hr = createBlendState(ref, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, FALSE); hr = createBlendState(ref, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_SRC_ALPHA, TRUE); D3D11_SAMPLER_DESC sampDesc; ZeroMemory( &sampDesc, sizeof(sampDesc)); sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; sampDesc.MinLOD = 0; sampDesc.MaxLOD = D3D11_FLOAT32_MAX; hr = createSamplerState(ref, sampDesc); sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; hr = createSamplerState(ref, sampDesc); // cbuffers unsigned onceRef, changeRef; hr = createCBuffer(onceRef, sizeof(CBOnce)); hr = createCBuffer(changeRef, sizeof(CBOnChange)); m_renderer->cbOnceID = onceRef; m_renderer->cbOnChangeID = changeRef; // shaders unsigned int vRef, pRef; hr = createShader<ID3D11VertexShader>(vRef, standardLayout, "defaultVS", "vs_4_0"); hr = createShader<ID3D11PixelShader>(pRef, standardLayout, "defaultPS", "ps_4_0"); // SRV's hr = createSRV(ref, "grass.png"); hr = createSRV(ref, "bozo.jpg"); /*************************** MEDIUM LEVEL LINKING ****************************/ /* Init default properties */ unsigned int sRef, mRef, tRef; // Shader Shader* s = new Shader(vRef, pRef); CModel<Shader>* cs = new CModel<Shader>("default_shader", s); // Mesh createCube(vRef, pRef); // notice reuse of paramaters Mesh* m = new Mesh(vRef, pRef, 36, ref); CModel<Mesh>* cm = new CModel<Mesh>("default_mesh", m); // Transform Transform* t = new Transform(elm::vec3(100,100,100), elm::vec3(0), elm::vec3(10)); CModel<Transform>* ct = new CModel<Transform>("default_transform", t); /* register properties */ addProperty(cs); addProperty(cm); addProperty(ct); /***************************** HIGH LEVEL COMPOSITION ******************************/ // Composition Composition* c = new Composition(); c->setName("default_object"); c->setProperty<Shader>(cs); c->setProperty<Mesh>(cm); c->setProperty<Transform>(ct); addComposition(c); return true; }
int createBlendState(D3D11_BLEND srcBlend, D3D11_BLEND destBlend) { return createBlendState(srcBlend,destBlend,srcBlend,destBlend); }