1
0
mirror of https://github.com/thes3m/XNI synced 2024-12-26 13:26:06 +01:00
2010-09-16 20:01:42 +00:00

92 lines
2.3 KiB
Objective-C

//
// BlendState.m
// XNI
//
// Created by Matej Jan on 16.9.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import "BlendState.h"
#import "Retronator.Xni.Framework.h"
#import "Retronator.Xni.Framework.Graphics.h"
static BlendState *additive = nil;
static BlendState *alphaBlend = nil;
static BlendState *nonPremultiplied = nil;
static BlendState *opaque = nil;
@implementation BlendState
- (id) init
{
self = [super init];
if (self != nil) {
alphaBlendFunction = BlendFunctionAdd;
alphaDestinationBlend = BlendOne;
alphaSourceBlend = BlendOne;
blendFactor = [[Color transparent] retain];
colorBlendFunction = BlendFunctionAdd;
colorDestinationBlend = BlendOne;
colorSourceBlend = BlendOne;
colorWriteChannels = ColorWriteChannelsNone;
colorWriteChannels1 = ColorWriteChannelsNone;
colorWriteChannels2 = ColorWriteChannelsNone;
colorWriteChannels3 = ColorWriteChannelsNone;
multiSampleMask = 0xffffffff;
}
return self;
}
+ (void) initialize {
if (!additive) {
additive = [[BlendState alloc] init];
}
if (!alphaBlend) {
alphaBlend = [[BlendState alloc] init];
alphaBlend.colorDestinationBlend = BlendInverseSourceAlpha;
alphaBlend.alphaDestinationBlend = BlendInverseSourceAlpha;
}
if (!nonPremultiplied) {
nonPremultiplied = [[BlendState alloc] init];
nonPremultiplied.colorSourceBlend = BlendSourceAlpha;
nonPremultiplied.alphaSourceBlend = BlendSourceAlpha;
nonPremultiplied.colorDestinationBlend = BlendInverseSourceAlpha;
nonPremultiplied.alphaDestinationBlend = BlendInverseSourceAlpha;
}
if (!opaque) {
opaque = [[BlendState alloc] init];
opaque.colorDestinationBlend = BlendZero;
opaque.alphaDestinationBlend = BlendZero;
}
}
@synthesize alphaBlendFunction;
@synthesize alphaDestinationBlend;
@synthesize alphaSourceBlend;
@synthesize blendFactor;
@synthesize colorBlendFunction;
@synthesize colorDestinationBlend;
@synthesize colorSourceBlend;
@synthesize colorWriteChannels;
@synthesize colorWriteChannels1;
@synthesize colorWriteChannels2;
@synthesize colorWriteChannels3;
@synthesize multiSampleMask;
+ (BlendState*) additive { return additive; }
+ (BlendState*) alphaBlend { return alphaBlend; }
+ (BlendState*) nonPremultiplied { return nonPremultiplied; }
+ (BlendState*) opaque { return opaque; }
- (void) dealloc
{
[blendFactor release];
[super dealloc];
}
@end