/**
 * @name	context_2d_bind
 * @brief	bind's the given context to gl and enables / disables scissors
 * @param	ctx - (context_2d *) context to bind
 * @retval	NONE
 */
void context_2d_bind(context_2d *ctx) {
	if (tealeaf_canvas_context_2d_bind(ctx)) {
		if (IS_SCISSOR_ENABLED(ctx)) {
			enable_scissor(ctx);
		} else {
			disable_scissor(ctx);
		}
	}
}
/**
 * @name	context_2d_restore
 * @brief	pop's off the global properties stacks and resets glScissors
 * @param	ctx - (context_2d *) context to restore
 * @retval	NONE
 */
void context_2d_restore(context_2d *ctx) {
	ctx->mvp--;

	if (!rect_2d_equals(&ctx->clipStack[ctx->mvp], &ctx->clipStack[ctx->mvp + 1])) {
		if (ctx->clipStack[ctx->mvp].width == -1) {
			disable_scissor(ctx);
		} else {
			enable_scissor(ctx);
		}
	}
}
/**
 * @name	context_2d_restore
 * @brief	pop's off the global properties stacks and resets glScissors
 * @param	ctx - (context_2d *) context to restore
 * @retval	NONE
 */
void context_2d_restore(context_2d *ctx) {
	int mvp = ctx->mvp - 1;
	
	// If stack still has items on it,
	if (mvp >= 0) {
		ctx->mvp = mvp;
		
		if (!rect_2d_equals(&ctx->clipStack[mvp], &ctx->clipStack[mvp + 1])) {
			if (ctx->clipStack[mvp].width == -1) {
				disable_scissor(ctx);
			} else {
				enable_scissor(ctx);
			}
		}
	}
}