graphics

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit c3e4312f03801d5d437c12f683e8aa261a153f18
parent 4f7956bbd714c05077299eef813b346a98a62194
Author: Brian Swetland <swetland@frotz.net>
Date:   Sat,  9 Feb 2013 05:57:00 -0800

dxapp: initialize sampler0 with some default state, provide blend control

Diffstat:
Mcommon/dxapp.cc | 46+++++++++++++++++++++++++++++++++++++++++++++-
Mcommon/dxapp.h | 6+++++-
Mhello/hello.cc | 3+++
3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/common/dxapp.cc b/common/dxapp.cc @@ -15,6 +15,7 @@ #include <stdio.h> #include <stdarg.h> +#include <float.h> #include "util.h" #include "app.h" @@ -312,7 +313,6 @@ int App::reconfigure(int init) { device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); device->OMSetRenderTargets(1, &targetView, depthView); - return 0; } @@ -377,10 +377,54 @@ int App::initD3D(void) { if (FAILED(hr)) return -1; + D3D10_SAMPLER_DESC sd; + //sd.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR; + sd.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT; + sd.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP; + sd.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP; + sd.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP; + sd.MipLODBias = 0; + sd.MaxAnisotropy = 1; + sd.ComparisonFunc = D3D10_COMPARISON_NEVER; + sd.BorderColor[0] = 1; + sd.BorderColor[1] = 1; + sd.BorderColor[2] = 1; + sd.BorderColor[3] = 1; + sd.MinLOD = -FLT_MAX; + sd.MaxLOD = FLT_MAX; + hr = device->CreateSamplerState(&sd, &defaultSamplerState); + if (FAILED(hr)) + return -1; + + D3D10_BLEND_DESC bd; + memset(&bd, 0, sizeof(bd)); + bd.SrcBlend = D3D10_BLEND_SRC_ALPHA; + bd.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; + bd.BlendOp = D3D10_BLEND_OP_ADD; + bd.SrcBlendAlpha = D3D10_BLEND_ONE; + bd.DestBlendAlpha = D3D10_BLEND_ZERO; + bd.BlendOpAlpha = D3D10_BLEND_OP_ADD; + bd.BlendEnable[0] = true; + bd.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL; + device->CreateBlendState(&bd, &bsAlpha); + + bd.SrcBlend = D3D10_BLEND_ONE; + bd.DestBlend = D3D10_BLEND_ZERO; + bd.BlendEnable[0] = false; + device->CreateBlendState(&bd, &bsOpaque); + device->RSSetState(rsDefault); + device->PSSetSamplers(0, 1, &defaultSamplerState); return S_OK; } +void App::setBlend(int enable) { + if (enable) + device->OMSetBlendState(bsAlpha, NULL, 0xffffffff); + else + device->OMSetBlendState(bsOpaque, NULL, 0xffffffff); +} + // ---- static int _compile_shader(const char *fn, void *data, unsigned sz, diff --git a/common/dxapp.h b/common/dxapp.h @@ -183,6 +183,8 @@ public: void drawInstanced(unsigned numvertices, unsigned numinstances) { device->DrawInstanced(numvertices, numinstances, 0, 0); } + + void setBlend(int enabled); protected: int width; int height; @@ -204,7 +206,9 @@ protected: ID3D10RasterizerState *rsDefault; ID3D10DepthStencilState *dsDepthEnabled; ID3D10DepthStencilState *dsDepthDisabled; - + ID3D10SamplerState *defaultSamplerState; + ID3D10BlendState *bsAlpha; + ID3D10BlendState *bsOpaque; private: InputConfiguration *ic; LPDIRECTINPUT8 dinput; diff --git a/hello/hello.cc b/hello/hello.cc @@ -209,7 +209,10 @@ oops: text.printf(0, 1, "ry: %8.4f", ry); text.printf(0, 2, "zm: %8.4f", zoom); text.printf(0, -1, "hello.cc"); + + setBlend(1); text.render(this); + setBlend(0); } App *createApp(void) {