Thoughts on Being Single for the Second Time

About two years ago I went through a divorce. I had known my marriage was over years before I was able to finally pull the trigger on it. I had actually tried leaving once a year earlier, but I was forced to go back to my husband because I wasn’t able to sustain myself quite yet and he promised to change. He didn’t and we followed through on the second attempt.

My ex-husband had an OKCupid account set up months before we filed for divorce the second time. He had his first date less than a week after he moved out of our house. A year after he moved out he had already replaced me with another woman with long red hair, two small dogs, and mental health issues.

During the year or two after our divorce I was a complete wreck. I was in much worse shape than I thought I would be. I had wanted the divorce. Our marriage was over. I thought I would feel free to finally do all the things I wanted to do. Instead, I felt like a death had happened. I had never been responsible for balancing my own budget and I had no idea how much money I earned or how much my bills were.

I had multiple rooms in my house that I simply never went into. My house felt incomprehensibly large even though it’s actually quite small. I used to have dreams that I was walking through my house and it was a giant labyrinth of gardens and piano rooms that I never knew were there because I only stayed in one small corner of my house.

The idea of trying to date anyone during this time seemed absolutely incomprehensible. I consistently see men who have recently gotten out of relationships try to get back on the horse and date again immediately. I don’t understand how they can do that.

I haven’t been on a date since I was 16 years old. I was diagnosed with bipolar disorder and was put on medication that made me gain sixty pounds in less than two years. My medication triggered panic attacks and caused a lot of mental health issues alongside the ones they were supposed to actually treat. I was a chubby, socially awkward woman with no social skills trying to navigate a social environment run on alcohol, which I couldn’t drink because of my medications.

I felt like having a boyfriend would give me some kind of validation that I was actually a person worthy of being liked. I used to develop crushes on other socially awkward guys who were less attractive than I was because I thought that they were low enough that I could get them. Most of them were either too socially awkward to return my advances or were appalled that a chubby socially awkward girl thought she was good enough for them while they drooled over anorexic teenagers with daddy issues.

Boys in college had been sold on the idea of the hook up. They had been told all through high school that when they got to college it would be a never ending stream of pussy. None of them wanted a relationship. They wanted to have sex with you and never speak to you again. I literally had guys come up to me and say to my face, “I hate you. I know you hate me. We should have sex. It will be fun.“

I was too priggish to give into any of these situations, but other girls I know did. They slept with guys to give themselves a sense of personal validation and were always disappointed when things never went any further.

I left college without having a boyfriend. I also left college without having any kind of stable career path. I was faced with a future alone with no meaning. Then I met my husband. We’d known one another since we were children. We were both tired of trying to find someone. I needed health insurance and to move out of my parent’s house. I thought I knew everything about him. I was terribly wrong and if you ever meet me IRL ask me about it and I’ll give more details than I am willing to give here!

After my misadventures in college, this seemed like as good as it was going to get. Sure, we weren’t really attracted to one another, but he would look me in the eye and talk to me. That was an improvement.

Things were fine for the first two years. Then he got weird. He started spending money we didn’t have on shit we didn’t need. I decided to go back to school for computer programming. I wanted an actual career and not just the menial white collar jobs I had held since we got married. I wanted a sense of self worth and to do interesting work I was proud of. I told him that if he would support me for two years that I could start bringing in four time more money than I had before. We could start a business. We could be partners. We could have our freedom and independence from The Man.

He wanted his freedom, but he didn’t want to work for it. It was the biggest disappointment in his life that he wasn’t born wealthy. This ate at his soul. He was bitter and resentful of having to go to work to earn a wage. He was always scheming about how to get rich quick without any effort. He would bully me about how I wasn’t developing the next Candy Crush. He would come to me in tears and tell me that he just needed me to earn a million dollars a year. He could find a way to be happy on just a million dollars a year.

He got incredibly paranoid. He was convinced I was cheating on him. He would follow me to networking events he previously had no interest in. He would skulk around behind me nursing a glass of scotch, watching me as I tried to network. He would go over and yell at me in front of people I was trying to connect with professionally. Once I came home from a business meeting to find him in the garage activating the GPS on my phone so he could track me down and physically bring me home. He would lay on the ground behind my car to prevent me from leaving the house.

He was jeopardizing everything I had worked so hard to accomplish and I simply could not tolerate his behavior anymore.

I feel I have been left in the lurch. I talk to other people who have built their careers on writing books and doing conference talks. I ask them for advice about how I can build this as a sustainable career while still paying my bills and I always get sheepish looks and the response, “Well, my wife has a really good job with benefits.“ I hear that and my heart sinks. I keep seeing and hearing that the career path I want to take can only be sustained by having a supportive partner who is willing to shore up the other person’s financial deficits.

I feel a great deal of anger at my ex-husband for destroying our marriage because he was unwilling to give up his $10,000 a year vacation habit. I have been borderline unemployed since September and I am just now reaching the end of my savings. We were $30,000 in debt with two incomes and bringing in over six figures while we were married because my ex couldn’t do without picking up an expensive hobby every couple of months. I had a plan that would have been mutually beneficial for both of us and now I am spinning plates frantically hoping that I can achieve what seems like the impossible all by myself.

I have no illusions about my book. I am writing about an incredibly niche topic that has almost no job prospects. I keep hoping if I develop skills around graphics programming that I can break into that area of expertise and have a long, stable career build on something most people don’t know that doesn’t fundamentally change, but I don’t know if I have enough time or runway to slog it out. I’m afraid of taking a dead end job and waking up seven years from now to find I didn’t keep up with the new changes in tech and that I am unemployable. Having the buffer of another person in case I made a terrible mistake and failed eased my mind. Having no safety net and throwing myself into a chasm right now is deeply worrying to me and I don’t have anyone I can even talk to about my anxiety because I am completely alone right now. Except for my parents. They have been fantastic, but I hate having to go to them with my hand out.

Being single at this point in my life is markedly different than it was when I was younger and I had no career. I am doing my best to not see getting remarried as an escape route for the path I have chosen to take. I would love to have a supportive partner around to help me out so I don’t have to do this alone, but having survived an unsupportive one, I know it’s better to be alone than live through that again.

I keep feeling like I am supposed to move on. Join OKCupid or Match.com. Go to speed dating. Relocate to San Francisco or Seattle to get access to a larger pool of eligible men. But I keep getting this nagging feeling that things have not fundamentally changed much since I was in college. Reading horror stories about how Tinder has basically supercharged the college hook up dynamic worries me. Seeing how many men are basically jumping into relationships to avoid being alone worries me too.

I like working. I see so many people doing frivolous crap all the time that I worry if I did move to a city and started trying to be social like everyone else that I would stop dedicating myself to my work. I would stop pushing and get left behind. It’s so hard to find another person who also likes working who is willing to just be in the same space I am while we’re both working.

I want to be with someone who wants to be with me. I would love to have someone to cook for besides just myself. I would like to have someone to build robots with me in my basement and then cuddle on the couch watching Star Trek. I don’t want that badly enough to grasp onto anything with a dick that comes along because I don’t want to be alone. I feel I have progressed from my college aged self who felt like having a boyfriend would be a validation to someone who is comfortable with themselves but would like to find another person to share things with.

I’m not willing to be with someone who did a visual assessment of me that I am just hot enough that they’re willing to have sex with me but they think I am unattractive enough to be approachable. I don’t want to be with someone who thinks that relationships are parking spaces and that you are supposed to always be parked somewhere or on the lookout for one.

As it looks increasingly like this will never happen, I am trying to accept being alone. I won’t settle for anything less than someone who likes me as a person and who I actively want to be with. There might be no one out there like that and I need to be okay with that.

Being alone sucks. But being with a destructive and unsupportive partner who doesn’t love you sucks more. It’s important to have a creative and fulfilling life rather than waiting for it to just happen to you. For better or worse, I am living a life I want to lead. I have no idea how sustainable it is in the long run, but for now I’m being true to myself. I am trying to have faith that if I do that then things will work out. Doesn’t mean I don’t indulge in feeling sorry for myself every once and a while.

Enough whinging. Back to work.

Persona 3 vs Persona 4

I am doing a lot of travel at the beginning of this year. I just got back from GDC and I am flying to London for iOSCon in a few weeks. While I was at GDC I was staying with a friend who generously let me squat on her couch. Her couch was an hour away from San Francisco by train, so I knew between my flights and all the time spent on trains I needed to find something to keep me entertained and occupied.

I couldn’t work on the plane or the train because I am sensitive to motion sickness. That crossed out reading too. The best option I could think about was playing video games. I didn’t want to take the 3DS because it has terrible battery life, so that left the PS Vita.

I decided to replay Persona 3. I finished up Persona 3 a little over a year ago. It took me 75 hours to get through it the first time. I really wanted to replay it again, but I thought it was stupid to confine myself to one game, so I have spent the last year trying to find something I like as much as Persona 3. I haven’t found it yet. And yes, that includes the venerable Persona 4 Golden.

I know this is probably an unpopular opinion, but I like Persona 3 better than Persona 4. I was told by many people to play Persona 3 so I could appreciate how much better Persona 4 was. I held off on Persona 4 for a bit while looking for another game, but I couldn’t wait anymore and started playing it. I was disappointed.

I have been trying to figure out why I don’t like P4 as much as P3. Since I started replaying P3 I have a better understanding of what it is about P4 that I don’t like as well. Fair warning, I am only about 20 hours into P4, so it’s possible that some of my gripes might be rectified.

Dungeons

I like the main dungeon in P3, Tartarus, better than the mechanic in P4 where you enter the dungeon through the TV. I was a huge Buffy fan, so the idea that your school is the base of all evil is a perfect metaphor for being a teenager.

I liked that there was an explanation about why the Shadows show up at the school. The Shadows are a result of an accident at the Kurijo Group. Mitsuru’s father was responsible for the accident. Yukari’s father died in that accident. It felt like people were being drawn to this problem because of their pasts.

In P4, you enter the dungeon through the TV. There seems to be no explanation about why these people in this one town are able to enter the TV to go fight shadows. It’s a small town and people just sort of happen to be there. There was no grand plan to right the wrongs of the past. There was an epic component missing from the grand scheme of things. I get that it’s supposed to be a less heavy and more fun iteration of Persona, but if you’re delving into Jungian psychology and the collective unconscious, I did appreciate the epic scope provided by P3.

Getting flashbacks to college

I also really liked that the students in P3 live in the dorms and there don’t seem to be any grown ups around. It really scratched a mental itch to get to have an immersive Japanese high school experience with all its stereotypes. Playing a game about a bunch of kids in a small town who live with their parents reminded me too much of my own real life to be a fun escape.

Combat

Persona 3 Combat

I don’t really like the tweaks to the combat system in P4. I don’t know why, but it’s difficult to see what various Shadows are weak to. In P3 I can directly control all of my players and get a good overview of what each shadow is weak to. When I do combat in P4 I don’t control my players and things happen so chaotically that I don’t actually know what moves my players made against the Shadows.

I also miss having the portals on various levels to take you back to the entrance in P3. In P4 you need to hold onto a consumable item that you must use to get back to the entrance.

All in all, I just found the combat in P3 to be more intuitive than in P4.

Quests

Completing a quest for the Fox and leveling up social link

One component in both P3 and P4 is that you go on quests and receive rewards. The quests are a side component of the main gameplay.

In P3, you receive a list of quests from Elizabeth/Theo. They’re all neatly gathered in one place. You get a crazy response from Elizabeth. It’s fun to complete the quest just to hear what she is going to say. A lot of the quests can be completed just by doing dungeon crawling. They’re not that hard to figure out.

In P4, your quests are spread all over the place. Unless you have an online guide, it’s practically impossible to find and complete every single quest. One is from a teacher wearing Egyptian wear hiding behind a corner. It’s difficult to keep track of all the quests and how to complete them. I believe some of the quests advance a social link, which makes it vital that you complete some of them.

I wound up playing through bits of P4 on the plane when there was a glitch on my memory card. I bombed nearly everything I did in the game because nothing was intuitive. I couldn’t look up the answers online and I failed at everything. If this was a normal game where dying is a way of learning, that would be one thing. Playing this game is an 80 hour commitment and I don’t want to shoot myself in the foot by screwing up all of the quests when I want to play for a few hours when I don’t have access to the internet.

I get stressed out trying to keep track of the quests and so I usually wind up ignoring them. Sometimes I will look something up and find there are ten things I missed. I get that some people might really enjoy just how many side quests there are and how much there is to do, but I don’t like the idea that I have to sit down with an online guide to accomplish everything happening in the game.

Skills

Scooting to the next town over, just like high school

Going along with having too much chaos with the quests is expanding the skills requirements.

In P3, you have three skills you must max out: Academics, Charm, and Courage. The first time I played through I didn’t understand that you had to max out all three of these. I focused on Academics because I knew we had midterms to study for. This lack of understanding bit me towards the end of the game as there were several social links I never finished because I didn’t have the requisite skill level to begin the social link.

P4 doubles the number of skills to six. In addition to that, it adds gardening and fishing and scooter riding and… It’s difficult to grasp the advantages of leveling up one skill over another. In addition to these skills you have to kill Shadows and level up your social links.

I get that part of the appeal of P4 is that there is more of everything, but I find it personally overwhelming. I find it difficult to know what to do on any given day and I feel like I am playing the game wrong because I don’t know what my character is supposed to do. I have major FOMO no matter what I do.

Female Protagonist

Female Protagonist and team leader

The last bit I would like to bring up is my appreciation that the portable version of P3 has the option to play as a female.

It shouldn’t make that much of a difference, but playing as a female character completely changes the feel of the game. The first time I played through as a female character I found Junpei to be creepy because I thought he was hitting on me rather than being friendly. This time around, knowing that he is not an option for a love path, I am really enjoying my character’s friendship with him.

You get to have the option to use Elizabeth’s brother Theo as your liaison with the Velvet Room. It’s fun getting another character to interact with.

Right now I am playing another game, Rune Factory 2: A Fantasy Harvest Moon. That game consists of two generations, where most of the main gameplay happens in the second generation. In that generation, you have the option to play as either male or female, but you don’t get that option in the first generation. Your main goal in the first generation is to find a girl to marry so you can knock her up with what will be your character in the second generation.

Playing as a boy puts me in a position I don’t like being in. I know the only goal I have as my character is to find the mother of my child. The characters are paper thin because they’re not really the point of the game, so I find myself asking questions I don’t like. Do I marry the girl the game wants me to marry who will never marry anyone else if I don’t marry her? Do I steal the shy girl who talks through her doll from her boyfriend because he’s an asshole? Do I try to marry the rich girl because she’s the hardest one to marry and thus prove my status? It’s a really creepy and superficial way of looking at things and it worries me that this is how boys see relationships in real life. Like, we’re not people. We’re various status symbols or a means to an end. Playing like this really depresses and upsets me. I know logically that it doesn’t make a whole lot of sense to give deep and complex personalities to something with such shallow gameplay, but having to think that way really upsets me.

P4 was remade for the Vita as Persona 4 Golden. They made a fighting game with the Persona 4 cast, along with a dancing game. These characters have been in so many games and done so much fan service that it really bothers me that they figured it just wasn’t worth it to add a female protagonist. Being able to play as a female is much more comfortable and it’s an indication that the creators care about making a nice game for everyone and not just the boys.

Conclusion

I will admit that the story and characters in P4 are better than P3. I know that the characters are a vitally important part of the game, but it’s still a game. It’s not a visual novel. It’s nice to do well in the game and constantly being confused as to what to do. In my opinion, P4 is too much of a good thing. I have preordered P5, so we’ll see how that one stacks up. For now, P3 for the win!

You Can’t Fix Other People

I started working on programming contracts three years ago. I started my first contract all bright eyed and bushy tailed. I was eager to prove myself and get things done and show myself to be a 10x programming ninja.

That didn’t happen. At least not right away. Things were really disorganized. There were broad ideas about things people knew they wanted to fix, but no real strategy about how to fix them. Depending on what day you were talking to the client, you would get different answers about what something should do or look like. It changed constantly. It was impossible to sit down and complete a task because it was likely the client would change their mind and it would need to be changed or scrapped altogether. On another contract I worked on the entire concept of the app changed three times over the course of five months.

I had a more senior developer I was working under that gave me some really valuable advice. I expressed my frustration at not being able to get anything done and my worry about being fired. I asked why someone would hire a contractor to work on a project if they didn’t know what they wanted to get done. He told me that is exactly why people hire contractors. They hire them when they are at a loss as to what they want to get done. They think the contractor will be some magic bullet who will somehow read their minds to figure out all the things that need to get done for the client so they can break through the mental berries they have preventing them from doing things.

I have talked a bit about my mental health issues. All of my mental health issues stem from this phenomenon. Inactivity is corrosive to my mental health. I have had several jobs/contracts/projects I have been brought onto where people didn’t know what they needed to get done. Sometimes I have dealt with the client directly, other times I have had managers “shielding” me from the client. Once I had an abusive manager who would bully the team into not talking to anyone else at the company because he was lying through his teeth about everything we were doing and he didn’t want to be found out.

It all starts the same way. I come onto a project enthused to get to work. Either from the beginning or after the initial rush to get things done disorganization sets in. People get behind. People stop communicating. People start second guessing themselves and changing their minds. I start to panic. I don’t want to be fired. I want to do my job. I can’t do my job. I am being paid to sit around all day doing nothing. No one is going to keep paying me to sit around all day doing nothing. I need to find something I can do to contribute. But I can’t. I don’t know what people want. I start to shut down. I can’t keep motivating myself. I feel trapped. I start crying for no reason. I can’t go into my office anymore because it triggers flashbacks.

Last year I had the worst nervous collapse I have had in years because of this situation. I had a period of months where I couldn’t do any work at all. I had to paint and remodel my office before I could work in there again.

One thing I have learned from these experiences is that it’s important to take care of myself. I need to make sure I don’t melt down.

I now have a queue of work I can give myself. I am working on a book. I have a few side projects I want to accomplish. If the client doesn’t have anything for me to do, instead of sitting in front of my work computer slowly burning myself out, I do something else. I don’t bill the client for that work, but I make sure that I take care of myself. If the client can’t figure out what they want, they’re going to fire me no matter what I do. I can’t force them to do anything. I hope when I have even more experience I will be better at getting the client to listen to my advice, but right now any attempts I make in that direction cause resentment and anger at me, so I avoid it like the plague.

It’s hard to make yourself work on other things or step away from the computer. It’s like being in school. You feel obligated to sit through the boring grammar lecture because you’re supposed to be there. Your mind wanders and you fight with people on Twitter because you don’t feel like you can get up and take a walk or read a book on something else or do anything else that will preserve your sanity.

Some of these situations remind me somewhat of my relationship with my ex. My ex kept thinking that stuff would fix him. He thought if he got married that having a wife would magically make all of his problems disappear. He used to yell at me for not fixing him. He thought if he was earning a lot of money it would solve all his problems, but he was always angry and resentful that other people were earning more. He thought if he could be his own boss, he would be happy, but he realized how hard he had to work for a lot less than he was getting and soured on that as well.

You can’t fix other people.

If you have enough experience in dealing with people plagued by indecision, you can start to help them organize their thoughts, but only if they let you. You can’t by force of will make someone happy if they don’t know what they need and they can’t tell you. All you can do is take care of yourself so that when you eventually move on (which you will because these jobs are always terrible) you’re able to help the next person you work with who will hopefully have a better understanding of what they want than this person does.

My Spring 2017 Conference Appearances

It’s a new year, which means I am in the process of seeing if I can break my conference record this year. Not sure what that record is, but I think it’s around ten conferences in a year. Last year was pretty busy and it will be tough to beat, but it was also something of a furlough year because I was mostly talking about mental health and software architecture. This year I am going full on Metal for the work I am doing on the Metal Programming Guide.

Everything is coming up Milhouse!

GDC: February 27-March 3

This year I am working at/attending GDC(Game Developers Conference). I get to be a Conference Associate, so while I am not speaking at the conference, I still get to help participate in creating a great conference experience for everyone. I am looking forward to meeting some new people in the graphics programming space. I think it’s important to keep meeting new and different sets of people rather than staying in a bubble of people you already know. I’ve wanted to attend this conference for a while and I am super happy I got a chance to do so this year.

iOSCon 2017: March 30-31

I get to attend my first European conference this year, iOSCon 2017. Some old friends, like Saul Mora, are going to be speaking there, as well as some new friends I haven’t had the chance to meet in person yet, like Manuel Chakravarty.

I am incredibly excited about this conference because I am debuting a new Metal talk here. I have noticed over the last few years that a lot of people are interested in Metal, but they are not quite sure about how to approach it. They’re not able to break it down in the minds into manageable tasks and they wind up quitting in frustration. My talk here will focus on foundational structures and concepts that are necessary to work with Metal in a fun and approachable way.

CocoaConf Chicago: April 21-22

If you’re in the States and can’t afford a hop across the Pond, I will also be presenting my new Metal talk at CocoaConf Chicago. This will be my fifth time attending CocoaConf Chicago and my fourth time speaking! Holy smokes! Time flies when you’re frantically trying to meet deadlines.

CocoaConf Chicago was the first purely iOS conference I ever attended. The speakers and the Kleins gave me a community of people without whom I would not be where I am today. It’s always a great joy and pleasure to see all of my friends there that I only get to see once a year.

Please Say Hello

One thing I always look forward to when I go to conferences is meeting new people. It may not always come off this way, but I feel socially awkward. One reason I made friends with so many speakers in the Cocoa community was because it was easy for me to start a conversation with them because I knew something they were speaking about. When I go and sit at a table full of strangers, I don’t know anything to start a conversation with anyone. I am happy for people to come up and start talking to me and I am telling you to please take that first step, because if you don’t I assume that I am probably annoying you and to avoid embarrassment I keep to myself.

I am planning to have my service dog Delia with me at CocoaConf and GDC. She is an emotional support animal and it is okay for people to pet her. It was technically possible for me to bring her with me to London, but with all of the various travel SNAFUs and the unstable political situations, I don’t feel safe or comfortable bringing her with me. I am terrified that I will forget to do something important and she will be taken away from me and I won’t get her back. So might be a little emotionally fragile in London, but I will follow the old British saying of “Keep Calm and Carry On.”

Looking forward to a great Spring 2017 conference season!

Quality over Quantity

Back in December I was approached about contributing to the Pragmatic Magazine. I was told the theme of the issue was Swift and I was asked if I had any good Swift posts that I would be willing to share.

I had a number of Swift posts that I was very proud of and I sent the links to the editor. Then I had a sinking realization that these posts were all from 2015.

Last year was a difficult year. I made a lot of mistakes and had a number of mental health issues. On paper my year seemed like it was incredibly successful, but I felt at the end of 2016 that I had not grown as I would have liked and I was not in a place I wanted to be.

One of my resolutions toward the end of last year was to have more technical content on my blog. I am in the process of writing a book. I intended to have companion blog posts where I share a number of things that I learned while I was writing the book. I have one post that has been partially written since November. It’s nowhere close to being done.

I keep wondering what’s the matter with me. I would like to produce more technical content. I keep meaning to, but things keep coming up. I know if I don’t make time to produce technical materials for blog posts or conference talks or to post on GitHub that I will be left behind. People always want examples of your work and you can’t keep pointing to work you did three years ago.

This morning I found a link to this article. The author talks about a lot of strategies about how to have a long and successful career in tech. This article helped to crystalize in my mind about why I am not producing more technical content.

Those blog posts that I submitted to the magazine were based on problems that took me months to solve. Each one of those posts and every project that I have written about that I am proud of all started the same way. I took something that was hopelessly unfamiliar and tried to force myself to learn it. These were all projects I did for Brad Larson when we were rewriting our code base in Swift.

One of these projects was wrapping libxml2 in Swift. The sample code was all written in Pascal. There was only one post written by anyone for this topic for the iPhone. That person was Jeff LaMarche. I was going to link to his blog post about it in this blog post, but it’s been taken down. So I had an incredibly undocumented technology that no one was using that it was my job to figure out.

I had about a week of complete and total panic and despair. I felt that I had been hired by mistake and that Brad would find out I was an inexperienced idiot and I would be fired in disgrace and I would never work again. I wondered about how hard it would be to find a nice easy call center job where I could cross stitch while talking on the phone all day answering the same questions over and over again. I thought this was hopeless, but it was my job to figure it out, so I had to try.

I spent a lot of time walking. I couldn’t look at my computer without getting a complete headache. I spent some time building robots. I would look at the docs periodically, but not for too long because doing so would cause a migraine.

After several weeks of doing this, suddenly things started to become clear. Instead of looking at a bunch of gibberish and having no idea about how to approach it, I finally had questions. I wondered what this one thing did. I wondered what the difference was between one object and another. I started to understand how to approach the problem.

I completed my task by learning all of this stuff over the course of about two months and I wrote my post. I was incredibly proud of the work that I did on that project and for finally figuring out how to solve it.

I never would have done that project if I wasn’t working for Brad.

First off, I never would have known what libxml2 even was. I would have just used the built in Cocoa framework and fought with it, but found plenty of sample code that I could copy and paste and go about my merry way. More importantly, if I had been doing this for myself, I would have taken one look at the lack of support, said fuck this, and done something else.

Forcing myself to confront something that seemed impossible and pushed me close to my breaking point mentally and emotionally. I have a faulty, tin-plated emotional system. If I get pushed too far I can’t function or learn. My brain shuts down. I had to confront my panic and my fear and force myself to approach this logically. At the beginning of Dune the main character has to take a Human Test. He is forced to put his hand in a box of pain and not remove it. Having mental health issues is like taking a Human Test. You have to think your way through your emotional issues and find some way of logically dealing with them so you don’t remove your hand and get scratched by the Gom Jabbar.

By being placed in a position where I could not simply give up, I was able to push through the initial phase of not knowing what the fuck I was doing to be able to see that there was an end to the Desert of Despair. I understand now that a lot of things I want to learn that seem difficult or impossible are not. I have been trying to teach myself Metal and 3D graphics math for the last two years. I know that even though the symbols seem incomprehensible and there are not a lot of approachable resources out there, I can bash my head against it enough to figure out a starting point. I can look at those symbols long enough over a long enough period of time that I can grasp some kernel of what I don’t understand that I can figure out.

I feel like our community doesn’t reward people for solving hard problems.

It pisses me off every year when Tim Cook announces some amazing new thing at WWDC and some jack ass in the audience gets some version of “Hello World!” working on it because everyone wants to be first. Everyone tries to cherry pick some easy problem that they can solve and post about so that they can show they’re keeping up with the Lattners. I have seen so much pressure in this community to pretend like you know everything. Companies place a lot of emphasis on what do you “know” not “how do you learn.” I admit that it’s a lot easier to test knowledge as opposed to problem solving and learning. I know that we’ve generally used knowledge of data structures and sorting algorithms as a proxy for how we learn. But memorizing some tips and rules doesn’t prepare you for the complete and total helplessness you feel when you confront something you must figure out that you don’t know how to do. You either rise to the occasion or you flee and become a Scrum Master.

I am realizing that most of the things I find interesting are difficult. I am in the process of learning some things that are complicated and poorly explained. I am hoping that after I push through everything I will have a wealth of material to write about on this blog. But I have to accept that what I want to do is hard. There is going to be a lot of invisible work that I do that isn’t being seen. There will be a lot of time spent thinking and processing and waiting for things to click.

Dan Barber is a prominent farm-to-table chef focused on sustainable food production. He wrote an article a while ago that really stuck with me. The gist of his article is that farmers are stripping their soil by only growing the most high profit crops. The soil gets progressively poorer and the food grown on it grows more and more tasteless because it’s nutritionally vacant. He found a farmer who grew an heirloom variety of wheat for bread flour. He thought the reason the flour was so delicious was because it was some heirloom variety, but it was because the farmer rotated his crops. He grew some less lucrative crops on his land that enriched the soil and only grew this wheat on the soil every three years.

I think one reason we have such a high burnout rate in tech is that we’re approaching development like we do farming. We will keep stripping our mental soil because it’s more lucrative to do so than it is to have furlough periods where we push ourselves to achieve truly difficult things. Start ups want to churn and burn developers because they don’t care about a person’s long term viability as an asset. It’s our responsibility as developers to take control of our careers.

Right now I am taking some time off to write a book. Even if the book is wildly successful I won’t make nearly as much money off of it as I would if I had worked somewhere during that amount of time. But taking this time to learn these things that I have wanted to learn for so long has been an extraordinary experience. The process of taking something that seems impossible and being able to make some traction with it makes me feel like I can conquer the world and anything is possible. Compared to a year ago, where I felt like I had to pretend I knew everything and I worked myself into a nervous breakdown.

Last year was a furlough year. I needed it to recover from some bad professional decisions. This year is a soil enriching year. I have so many projects I want to do and write about, but they’re going to take some time to figure out.

I would like to write more about tech on this blog, but I have to accept that I want to learn some difficult things that take a lot of time to figure out. I am not going to have a new post here every week that I am proud of. But if I can get four difficult technical posts on here this year, that’s not so bad.

Land of Misfit Frameworks

Right now I am in the process of writing a book on Metal. Metal came out the same year as Swift. One thing that has caused a lot of frustration among people like myself who are interested in Metal is the fact that there is not a lot of material out there on the framework. It’s gotten much better. Ray Wenderlich has released a video series on Metal. Apple dedicated a whopping five videos to Metal in 2016. If you’ve been checking the docs between when Metal came out and now, they have increased dramatically in both quantity and quality. Metal has come a long way over the last year.

There are frameworks that Apple released in the last few years that make Metal dramatically more useful. It integrates well with SceneKit, which makes it far easier to work with 3D graphics. In 2015, Apple introduced the Model I/O framework to make it easier to import 3D models from programs like Blender and Maya. Before that, you had to parse all these files by hand like a savage.

I had a sample project I wanted to do today that I didn’t realize I needed to import a model for. Most of the things that I need to do with Metal are made infinitely easier by Model I/O and SceneKit. But I don’t see people clamoring for more books on SceneKit or tutorials on Model I/O. There is almost no information out there about it outside of the Apple documentation. There is one piece of sample code and only one video from 2015.

I am not picking at Apple for not having more documentation. They have a lot on their plate and they’re doing the best they can. I am simply confused as to why I don’t see more people complaining about the lack of information about Model I/O. I don’t know if the lack of adoption of Model I/O is clamping the adoption of Metal or if it goes the other way.

I feel like there is a lack of understanding about what is out there and what the most optimal way is to get things done as efficiently as possible.

I know that SceneKit never got the amount of attention that it may have deserved. Everyone I talk to that would use SceneKit don’t want to because it’s not available on Android. I feel like most people I interact with use Unity because it was the best thing available five years ago and it’s just the thing they’re most comfortable with.

Apple has a lot of misfit frameworks. Gameplay Kit. Model I/O. SceneKit. These all work together and support one another. I want to see more stuff out in the world about these frameworks.

I am hoping that I can incorporate learning these frameworks into my exploration of Metal. I think that knowing these tools and using them in my projects will make my experience with Metal far richer and more productive than it would have been otherwise. I know this runs the risk of being a rabbit hole I fall down that prevents me from focusing and getting projects done. However, I think if I don’t raise my awareness of these frameworks, I will be missing the forrest for the trees. I will wind up wasting a bunch of time reinventing the wheel or creating useless things that don’t accomplish what they are capable of.

I am trying to remember that these are large topics. These take time to learn and adopt. Rome wasn’t built in a day. It’s important to remember this is a large topic and to not get frustrated when I realize things are large.

Rules for Engagement on Twitter

Hi.

Today I blocked several people for the first time ever on Twitter. These are people I have known for a long period of time and one of whom I have met in person and know to not be a sociopath. Here is why.

I have Post Traumatic Stress Disorder. When I was in college a stranger held me hostage in my dorm room and raped and tortured me for two and a half hours. For those of you fortunate enough to not have PTSD, one of the delightful aspects of having it is dealing with flashbacks. Flashbacks happen when you are in a situation that is reminiscent in some way of the circumstances that caused your trauma. It’s your brain’s way of protecting you. It senses that you are in a similar situation to one where bad things happened to you, so it tries to force you to flee from that situation to protect yourself.

I recently certified Delia as an Emotional Support Animal because one thing that triggers flashbacks is being trapped in an enclosed metal tube with a bunch of men I don’t know. I can fly without her, but the efforts it takes for me to calm myself down for several hours drains every ounce of energy I have. I get to my destination exhausted and it can take me up to a month to recover.

Another thing that triggers flashbacks is dealing with aggressive males who do not listen to me and continue to engage me when I want to be left alone.

There have been multiple times this year on Twitter where I have made a comment or asked a question and have been bombarded with well meaning but obnoxious advice from men. It ranges from speaking to me like I am a toddler and couldn’t possibly have considered the most obvious solution that they are giving me or trying to force me to use their preferred mode of whatever in spite of my pleas saying that I already considered it and it won’t work for reasons I don’t want to articulate in 20 tweets.

When this happens, I start to feel overwhelmed. I feel personally attacked and unsafe. It causes me tremendous amounts of emotional distress. I start to have flashbacks and experience all the emotions I experienced when I was being raped. I have had at least a half dozen times this past year where I have gotten so distressed from these interactions that I have had to make emergency appointments with my therapist and spend money I don’t have trying to recover to the point that I am able to work. I have been in constant fear of not being able to work and earn money and destroying my career this year because these well meaning but clueless men have insisted upon trying to be “helpful.”

I have tried multiple times over the last year to explain to people that what they are doing is causing me real harm and damage. Every time I have attempted to engage in a dialog in explaining where I am coming from, I get a bunch of defensiveness and people telling me that they’re engineers. They want to solve the problem. They’re not intending to cause me psychological damage and therefore I don’t have the right to be upset by their behavior.

I don’t give a shit what you intend. It’s the result of your actions that matters.

If you are driving around and you get distracted by your phone and run someone over who is paralyzed for life, it doesn’t matter that you didn’t intend to run them over. They’re still damaged. You don’t get to hide behind your intensions when what you are doing is causing me actual harm.

I am tired of being responsible for having to do the emotional legwork that men are unwilling to do. I have told them many times how to avoid causing me harm and I am being told it’s my problem and they won’t change because their desire to avoid hearing that they’re doing something harmful is greater than my need to be able to earn a living.

I don’t want to be a massive bitch and make people feel like they can’t talk to me without getting bitched out, so I am establishing my rules so that I can protect myself psychologically while still being able to engage with people on Twitter:

First Strike: I Ask You to Back Off

I understand that on Twitter things can escalate very quickly and tempers can flare. At this point something will have happened and I will start to feel overwhelmed but I can still avoid a total shutdown, but only if you stop engaging with me.

I will tell you that I am feeling overwhelmed and ask you to back off.

At this point, if you back off, we’re good. You can feel good about being an engineer and know that you have made a situation better. If you still want to make this point to me later, please wait a day. Ask me for my email and send me an email or give me a chance to engage in a better forum of communication.

Second Strike: I Send You a Link to this Blog Post

It’s possible you’re reading this because I sent you a link to this blog post. I am trying to explain to you why I can’t continue to engage with you. I am not trying to blame you or tell you that you’re an asshole. I am assuming that you mean well and I am trying to find some way to let you know that was you are doing is causing me harm with the hope that you will respect my need to be left alone. Again, if you read this post and you back off and leave me alone, no harm, no foul.

Third Strike: I Will Block You

If you have gotten to this point and you are still continuing to engage with me, then I will block you. I am doing this out of emotional self defense. You have shown that you are not willing to respect my need to feel safe. You are leaving me no other option than to block you to protect myself.

If you’re someone that I know personally and have invested in a relationship with, I will try to remember to unblock you later. I will emphatically ask you to please stop doing things that cause me psychological trauma.

I do not want to block people, but I also do not want to spend a hundred dollars seeing a therapist to be able to keep working. My need to be able to work supersedes your desire to feel helpful. If you want to be helpful, please back off if I tell you that you are forcing me to shut down. If you respect that, we’re cool.

Thank you.

Special Announcement: The Metal Programming Guide

Hello all. For the last few weeks I have been hinting that I have a new project that I had not yet announced yet. I wanted to make this announcement at MacTech, which I did yesterday, so I am now publicly announcing this.

I am working on a new book: The Metal Programming Guide. If you are familiar with the OpenGL series of books like the OpenGL Red Book and the OpenGL Blue Book, this is going to be The Red Book for Metal. The publisher for this project will be Pearson/Addison Wesley, so this is not a self-publishing effort on my part. I will have technical editors and people breathing down my neck if I miss deadlines!

Back in 2014, when Metal was announced, it excited me tremendously. I did a series of conference talks on it throughout that year, but a little thing called Swift kind of got in the way of my learning path for Metal.

This year has been something of a disaster for me on a personal level and I didn’t get to accomplish what I had hoped to this year. Being given an opportunity to finally get to master Metal and write a book about it has given me hope for the future. I have always felt like Metal was something I was meant to do, but I wasn’t really ready to tackle it until now.

Right now I am trying to balance doing some short term contract work with attempting to work on the book. I hope to not run out of money before I finish the book, but I also want to avoid doing full time work that would prevent me from making progress on the book. We are very early in the process right now, but I am giving it everything I have to try and get this done in a reasonable amount of time.

I am hoping to be able to make weekly posts on here and my podcast about various aspects of Metal programming that I am not able to include in the book due to lack of time/space/things being out of scope.

Even though I have been a co-author on a number of programming books already, it has always been my dream to do an immersive book on a topic such as Metal. I am excited to learn this amazing framework and share that knowledge with everyone else.

I’m announcing it here on this blog because I have absolute confidence that this project will be successful. I’ve been waiting to do this for a long time. I do not plan to drop the ball on this. Bring it on!

The Cost of Complacency

This is another cross post from my podcast Janie Rants. I will record this script later today and post it to that site as well.

Yesterday I, along with half of our nation, watched in growing horror as we saw the election results come in. Last year we laughed at the Republicans as they saw their establishment candidates knocked out one by one by an orange con man. We shook our heads in disbelief that any woman would vote for a man who was on tape talking about grabbing women by the pussy. He went on rants at 3:00 in the morning calling an ex-beauty queen a pig and an eating machine. Surely no one would trust this man with codes that could start a nuclear war?

I want to rewind everyone back a few weeks to October 27, 2016.

This feels like a lifetime ago, but this was when Apple announced their update to the new Retina MacBook Pro.

People like me have been waiting anxiously for an update to this line of computers. I have wanted to buy a new laptop for a while but I wanted to really max out the processor and the ram.

What did we get?

We got the same RAM. Close to the same processor. And a touch bar. Oh, and all of our ports are now gone and we have to spend an extra hundred bucks or two to buy all the dongles we need to plug our new iPhone 7s into our laptops.

A lot of people were really angry about this. Most people dismissed them because every time Apple announces something, everyone is angry. Everyone is angry that their pet thing didn’t get featured with an upgrade.

Most people who complained about the new Macbook Pro were chastised by the community. We’re told that Apple has a reason for doing what they’re doing and a lot of us didn’t like certain changes made to iOS but that after we got used to them we realized they had a purpose and Apple knew what it was doing, so we should have faith that there is a reason behind all of this too. Even if there isn’t a reason behind everything, what are you going to do about it? Apple is still the best choice even if it’s not as much better as it used to be.

I feel like those people who are telling us to stop complaining are like the establishment politicians from both the Republican and Democratic parties.

People in the Apple community are upset. We remember ten years ago when we saw all these amazing innovations coming from Apple. I recently received a vintage blueberry iBook from someone to decorate my living room. When I saw the computer for the first time, I laughed out loud with delight. The design of the computer was like nothing I have seen in such a long time. It was different and unique. It made me smile.

Nothing Apple has produced over the last five years has made me smile.

I got an aluminum Mac Book in 2004 that was nice. It looked modern. It was well built. It had a neat track pad. It was light enough that I could carry it places. It felt like a modern machine.

When I look at every computer that has come out since that one, they’re all variations on the same tune. Same with the iPhone.

Every year the devices get thinner and more fragile. There are more bugs in the tools and the frameworks. There is less time to create innovative applications because by the time you learn the new ropes, the system changes. The changes people actually want to see never get done. But there is an assumption that people will just keep buying Apple products because we’re locked into an ecosystem and we’re obligated to do so.

I feel like this is similar to the attitude we saw from the Democratic party in regards to Hillary Clinton.

I want to say I like Hillary Clinton. I think she would have been a solid president and I am incredibly sad that she lost. I think that thirty years of gas lighting and fake scandals and constant investigations turning up nothing have tarnish her reputation and it saddens me that an orange troll can be on tape talking about grabby women by the pussy and be taken more seriously than a religious woman who has dedicated her life to public service.

That being said, this election was about change. The election in 2008 was about change too. The Great Recession hit and destroyed our economy. The Democrats rode to the White House on the shoulders of Barack Obama, the great hope of our generation. He promised to close Guantanamo Bay and to stop sending our soldiers to die in the Middle East. He promised to clean up the corruption that resulted in the Great Recession.

He didn’t do any of these things.

He passed the Affordable Care Act, which is a landmark piece of legislation. One of the only reasons I can be an independent consultant is because of the Affordable Care Act.

But no one went to jail over the corruption that caused the Great Recession. Gitmo is still up and running.

We can rightfully make the argument that Obama was hamstrung by Congress for the last six years, but the biggest reason that we wound up with the Tea Party just two years after Obama’s historic election is because people felt betrayed that he didn’t do what they thought he would do. He didn’t clean up corruption. He didn’t throw the bankers in jail. He created a giveaway to the insurance industry to allow them to have a blank check for health care. We rejected Hillary in 2008 because Obama promised us hope and change and we got more of the same.

The health insurance marketplace opened on November 1st. My health insurance went up nearly a hundred dollars a month. I saw classmates who work on family farms show that the cost of insuring their wife and child in the most bare bones package available was a thousand dollars a month with a twelve thousand dollar deductible. That’s completely bogus.

Obama continued to get advice from the same corporate people that crashed the economy in the first place. He didn’t enact the bold action people elected him for because he trusted the advice he got from the people with the same college education and background that he had. I used to think Hillary would have been different, but now I am not so sure.

There is an economics experiment called the Ultimatum Game. In this game, there are two players. One player is given ten dollars and is told that they can split it any way they want to, but the other player can either approve it or deny it. If the player approves, the money is split accordingly and each player takes their money and leaves. If the player denies it, then no one gets anything.

A common way most people split the money is to take nine dollars and offer one to the other player. If you think about this rationally, the second player should approve of this deal because it gives them a dollar they would not otherwise have. But we’re people and we don’t think rationally. We don’t think it’s fair for the first player to get nine dollars when we only get one just because they got to choose the split. They have more to lose than we do if we reject the offer and we feel better about denying the other person their nine dollars than we do about losing our one dollar.

For the last several decades the American political system has been an ultimatum game. The establishment politicians have used social issues like abortion and civil rights to try and bludgeon us into agreeing to their deal. We’re supposed to vote for Hillary to avoid a future dictated by people like Paul Ryan wanting to enact his Ayn Randian vision of America where he will destroy our safety nets and let everyone die in a state of unmitigated poverty.

People who are shocked by this are not familiar with the ultimatum game. They thought everyone would nicely go along with the status quo because the status quo is better for them than the probable hell the next four years are going to be. But they’re going to be a lot worse for us than they are for them. It’s going to be worst of all for our Muslim brothers and sisters out there.

I consistently see people earning ten dollars an hour fighting against a fifteen dollar an hour minimum wage because they don’t think people working at McDonalds deserve fifteen dollars an hour when they’re only earning ten. They don’t care that they would increase their own wage by fifty percent by supporting a fifteen dollar and hour minimum wage, they just want to make sure that no one underneath them manages to get ahead of them. They want everyone to be brought down rather than being brought up.

A lot of anger and ill will right now at the Democratic party is reminiscent of a lot of the arguments I have been making about the tech industry. The party wanted Hillary because Hillary was a good culture fit. She would support their interests. They all met at the Christmas party and sent their kids to the same schools. They wanted someone they were comfortable and familiar with.

And that is exactly what everyone is angry about.

They don’t want to take their dollar while the banks get nine. They don’t like being told that they should be happy with their dollar because if Donald Trump is president then they won’t get any dollars.

Right now in the tech industry we have a massive glut of wealth that is going to a small group of people who are all in their early twenties who all went to Stanford or MIT who are all pitching the exact same shitty product that already exists in ten different forms somewhere else. Nothing innovative is happening because it’s a giant echo chamber where the same people are starting companies doing the same things and selling them off to the same other larger companies. No new ideas or people or perspectives can get in because they’re uncomfortable and we’re on the verge of a collapse because of it.

You can’t keep producing the same product over and over again that people aren’t interested in buying. You can skate by for some period of time on that apathy, but eventually a disruptive force will come and shake things up.

IBM didn’t take the PC market seriously. They didn’t think a small company like Apple could completely change the way we live our lives. Now Apple is falling into the same complacency trap that sucked up IBM and Xerox. They think everyone is locked into their ecosystem and that no one wants to buy Android phones because they’re inferior, so they aren’t listening to what we’re saying we actually want because they think we have no choice but to accept what they’re producing.

Let’s imagine that another company creates a fantastic competitor to the iPhone. It could be Google. It could be some upstart we’ve never heard of. Their products are innovative and exciting. You’re not trapped in a proprietary ecosystem where you must own an underpowered Mac to write applications for this new device. You can buy cheaper and better devices that are genuinely exciting and not just more of the same.

Or pretend that there is a customer rebellion and everyone refuses to buy iPhones. Some change is made and the customer base leaves out of spite.

It might not happen tomorrow, but it will happen. People don’t like being backed into a corner and told they have no choice. It happened to other companies and it is happening to Apple. Apple can listen to the rumblings of discontent coming from its user base and make a decision to embrace the things that made it great, but I don’t think they will. It’s easier to be complacent and keep doing the things your comfortable with that have always worked before, especially when you’re surrounded by people who all think the same way you do.

One of Steve Jobs’s favorite songs was “The Times, They Are A’Changing“ by Bob Dylan. I suggest that in the wake of this election we all take a deep look at our society and we stop blaming people who have been telling us for decades that they’re angry but were ignored because we assumed they would all just go away and die. The signs were there, but we didn’t want to see them. We didn’t want to fix things that were broken because they worked good enough, and now we’re facing a reckoning.

Come gather ’round people
Wherever you roam
And admit that the waters
Around you have grown
And accept it that soon
You’ll be drenched to the bone.
If your time to you
Is worth savin’
Then you better start swimmin’
Or you’ll sink like a stone
For the times they are a-changin’.

Primitive Drawing and Assembly in Metal

One of the main reasons I got interested in iOS was because I wanted to learn graphics and audio programming.

I got really interested in OpenGL, but after a year of trying to learn it I wasn’t making any progress.

Anyone who has tried to learn OpenGL have gone through the same frustrating experience I have. You find a tutorial on Ray Wenderlich and you write a bunch of code and at the end you have a spinning multicolored cube. That’s really cool!!

But then you realize that you have absolutely no idea how to do anything else.

For a really long time, I thought that I had to enter all of my vertices by hand because every tutorial I saw had you write your vertices by hand. My brain was scrambled by the idea of trying to create a large, complex 3D model by hand coding the vertices. It’s hard enough coding things with auto complete, what if you miss a value?! Do you have to keep building it and keeping track of the vertices and try to figure out which one needs to be moved when there are a thousand of them?!

Eventually I was told that you import a pattern file into your application, but until the release of Model/IO in iOS 9, you had to write your own parser from scratch to import a file from Blender or Maya.

So I faced an incredible amount of frustration trying to figure out how you get vertices into an application and how they work together to create something. I kept being told that those projects of the spinning cube introduce you to all the things you need to know in order to make OpenGL work, but it was something that was not intuitive.

I am seeing people go through similar frustration while trying to learn Metal. I am hoping to do a series of blog posts over the next few months about aspects of Metal and 3D graphics programming that I don’t feel I have seen explained very well in other places. This stuff is complicated and difficult to explain, so no judgement on anyone who produces technical materials on Metal or OpenGL.

Star Project

I decided to do a project that was slightly more complicated than a triangle or a cube but not as complicated as a 3D pug model. I want to figure out how to explain this stuff in a way that the reader can extrapolate and scale the complexity while still understanding how the fundamental concepts work.

I decided to try and draw a two-dimensional star. It’s slightly more complicated than a triangle but it’s still simple enough for a person to sit down and conceptualize.

Yes, I screwed up the vertex labels at the bottom.

Yes, I screwed up the vertex labels at the bottom.

I really hoped that I could find a simple CAD program to generate a pattern file for my 2D star, but after multiple frustrating conversations with various people, I decided to bite the bullet and just plot out the vertices by hand.

The Metal rendering space is slightly different than what one expects coming from something like Core Graphics. I am used to the idea that the phone has a normalized coordinate space where the height is one unit and the width is one unit.

Metal still utilizes a normalize coordinate space, but it’s two units high and two units wide, so the center of the screen is coordinate (0,0,0). So the upper left corner of the screen is at coordinate (-1, 1, 0). The lower right corner is (1, -1, 0). It’s not complicated to understand, but it’s slightly counterintuitive for someone coming from the idea that everything is a value between 0 and 1.

I created my coordinate space using graph paper. I made each square on the paper worth 0.2 units and made the space ten squares by ten squares.

I understand that because the phone screen is not perfectly square that the star is not going to look like this when it’s finally rendered. One of the things I want to do later is figure out how to constrain the drawing area to be square so that the star renders properly, but that’s a task for a later time.

Writing out vertices by hand like a savage.

Writing out vertices by hand like a savage.

In Metal and OpenGL, shapes are composed of triangles. All the big scary 3D models that make up a Pixar movie are composed of meshes of triangles. Everything can be broken down into triangles.

So let’s think about a star. It’s obvious that the points are composed of triangles, but what about the middle? The middle is a pentagon. This pentagon can be composed of five triangles by drawing out from the center to each of the vertices between the points.

So if you think about how to describe the star to the renderer, you are going to describe ten triangles using eleven vertices. There are five vertices at the points, the five between the points, and finally one in the middle.

Metal Primitives

When you package and pass your vertices to the vertex buffer, you need to describe to the vertex buffer what type of shape it’s drawing. I know I just went off on how everything can be broken down into triangles, but there are a few flavors of shapes you can draw with Metal.

Metal has a enum of Metal Primitive Types. There are five different primitives available to you:

  • Point: Rasterizes a point at each vertex. You have to define a point size in the vertex shader.
  • Line: Rasterizes a line between a pair of vertices. These lines are separate and not connected If there are an odd number, then the last vertex is ignored
  • Line Strip: Rasterizes a line between a bunch of adjacent vertices, resulting in a connected line.
  • Triangle: For every separate set of three vertices, rasterize a triangle. If the number of vertices is not a multiple of three, either one or two vertices is ignored.
  • Triangle Strip: For every three adjacent vertices, rasterize a triangle.

So the easiest way to think about how to describe the star to the vertex shader is to hand enter ten sets of three vertices that describe a triangle.

let vertexData:[Float] =
    [
        // Internal Triangles
        0.0, 0.0, 0.0, 1.0,
        -0.2, 0.2, 0.0, 1.0,
        0.2, 0.2, 0.0, 1.0,
        
        0.0, 0.0, 0.0, 1.0,
        0.2, 0.2, 0.0, 1.0,
        0.3, 0.0, 0.0, 1.0,
        
        0.0, 0.0, 0.0, 1.0,
        0.3, 0.0, 0.0, 1.0,
        0.0, -0.2, 0.0, 1.0,
        
        0.0, 0.0, 0.0, 1.0,
        0.0, -0.2, 0.0, 1.0,
        -0.3, 0.0, 0.0, 1.0,
        
        0.0, 0.0, 0.0, 1.0,
        -0.3, 0.0, 0.0, 1.0,
        -0.2, 0.2, 0.0, 1.0,
        
        // External Triangles
        0.0, 0.6, 0.0, 1.0,
        -0.2, 0.2, 0.0, 1.0,
        0.2, 0.2, 0.0, 1.0,
        
        0.6, 0.2, 0.0, 1.0,
        0.2, 0.2, 0.0, 1.0,
        0.3, 0.0, 0.0, 1.0,
        
        0.6, -0.4, 0.0, 1.0,
        0.0, -0.2, 0.0, 1.0,
        0.3, 0.0, 0.0, 1.0,
        
        -0.6, -0.4, 0.0, 1.0,
        0.0, -0.2, 0.0, 1.0,
        -0.3, 0.0, 0.0, 1.0,
        
        -0.6, 0.2, 0.0, 1.0,
        -0.2, 0.2, 0.0, 1.0,
        -0.3, 0.0, 0.0, 1.0
]

I want my star to be kind of flashy. I would like to set a pseudo-radial gradient on the star where the tips are red, but the middle is white. So I need to set up another array of floats describing the color data as it correlates to the positional data.

let vertexColorData:[Float] =
    [
        // Internal Triangles
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        // External Triangles
        1.0, 0.0, 0.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 0.0, 0.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 0.0, 0.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 0.0, 0.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        
        1.0, 0.0, 0.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0
]

Over in the view controller, you need to create a buffer to hold the position data and one for the color data for your vertices:

var vertexBuffer: MTLBuffer! = nil
var vertexColorBuffer: MTLBuffer! = nil

Now you need to connect those buffers to the arrays of vertex data. The buffers don’t know how much data they need to store, so you have to calculate how large these vertex arrays are so the buffers know how much space they need to allocate for the vertex data.

let dataSize = vertexData.count * MemoryLayout.size
vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize, options: [])
vertexBuffer.label = "vertices"

vertexColorBuffer = device.makeBuffer(bytes: vertexColorData, length: dataSize, options: [])
vertexColorBuffer.label = "colors"

img_5660Since the vertex position and color arrays are the same size, you can reuse the data size variable for both buffers.

At the end of the process, this data is scheduled by the render encoder to be sent to the vertex shader and be processed by the GPU.

renderEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
renderEncoder.setVertexBuffer(vertexColorBuffer, offset:0 , at: 1)
renderEncoder.drawPrimitives(type: .triangle,
                                   vertexStart: 0,
                                   vertexCount: vertexData.count)

Build and run the app on a phone and you get a nice star! Huzzah!

Wrap Up

I created a GitHub repo for this project here. Honestly, most of this project was basically me just using what comes in the template but changing the vertex data.

Looking this over, it seems kind of inefficient. The middle set of triangles feel like they could be a triangle strip. I would like to add a nice outline to the star to make it look nice and neat. I also would like the star to not be morphed by the screen.

I am planning to update this project periodically to make it more efficient and customizable.

At the very least, I hope this adds some understanding to how Metal breaks down larger shapes into triangles and how it’s able to go through and build the shapes back up again.