Add culled option for simple programs

This commit is contained in:
Atlante45 2015-06-19 16:50:38 +02:00
parent 67473ac254
commit 9c7f24eeb6
3 changed files with 27 additions and 6 deletions

View file

@ -113,7 +113,7 @@ void Circle3DOverlay::render(RenderArgs* args) {
auto& batch = *args->_batch; auto& batch = *args->_batch;
batch._glLineWidth(_lineWidth); batch._glLineWidth(_lineWidth);
batch.setModelTransform(transform); batch.setModelTransform(transform);
DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch); DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch, false, false);
// for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise
// we just draw a line... // we just draw a line...

View file

@ -68,8 +68,19 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
state->setBlendFunction(false, state->setBlendFunction(false,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
gpu::StatePointer stateCullNone = gpu::StatePointer(new gpu::State());
stateCullNone->setCullMode(gpu::State::CULL_NONE);
stateCullNone->setDepthTest(true, true, gpu::LESS_EQUAL);
stateCullNone->setBlendFunction(false,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); _simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
_simpleProgramCullNone = gpu::PipelinePointer(gpu::Pipeline::create(program, stateCullNone));
_simpleProgramTextured = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, state)); _simpleProgramTextured = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, state));
_simpleProgramTexturedCullNone = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, stateCullNone));
_viewState = viewState; _viewState = viewState;
loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations); loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations);
@ -106,13 +117,21 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET)); lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET));
} }
void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured) { void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled) {
// DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, true, true); // DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, true, true);
if (textured) { if (textured) {
if (culled) {
batch.setPipeline(_simpleProgramTextured); batch.setPipeline(_simpleProgramTextured);
} else { } else {
batch.setPipeline(_simpleProgramTexturedCullNone);
}
} else {
if (culled) {
batch.setPipeline(_simpleProgram); batch.setPipeline(_simpleProgram);
} else {
batch.setPipeline(_simpleProgramCullNone);
}
} }
} }

View file

@ -34,7 +34,7 @@ public:
void init(AbstractViewStateInterface* viewState); void init(AbstractViewStateInterface* viewState);
/// Sets up the state necessary to render static untextured geometry with the simple program. /// Sets up the state necessary to render static untextured geometry with the simple program.
void bindSimpleProgram(gpu::Batch& batch, bool textured = false); void bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true);
/// Tears down the state necessary to render static untextured geometry with the simple program. /// Tears down the state necessary to render static untextured geometry with the simple program.
void releaseSimpleProgram(gpu::Batch& batch); void releaseSimpleProgram(gpu::Batch& batch);
@ -100,7 +100,9 @@ private:
static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations); static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations);
gpu::PipelinePointer _simpleProgram; gpu::PipelinePointer _simpleProgram;
gpu::PipelinePointer _simpleProgramCullNone;
gpu::PipelinePointer _simpleProgramTextured; gpu::PipelinePointer _simpleProgramTextured;
gpu::PipelinePointer _simpleProgramTexturedCullNone;
ProgramObject _directionalSkyboxLight; ProgramObject _directionalSkyboxLight;
LightLocations _directionalSkyboxLightLocations; LightLocations _directionalSkyboxLightLocations;