Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Nov 2005
Offline Last Active Jul 21 2014 07:23 PM

Topics I've Started

(Super) Smart Pointer

11 July 2014 - 09:42 AM

Imagine an RTS game, you have 20 marines shooting at one building and it blows up. All the marines have AI pointers "targetedEnemy" pointing at the building. The building blows up and is removed from the world and deleted.

Is there any good design for this?----> Updating the 20 marines "targetedEnemy" pointers that is to be NULL so they can go looking for new enemies?

shared_ptr doesn't seem to work because that is reference counted. It WOULD work if I decide that the marine AI checked their enemies health and if health < 0, call reset on the pointer. After the 20 marines all call reset() then the object would officially be deleted.

The other option I thought of was creating a new pointer type (unless one exists), where anytime I deconstruct a copy of the pointer, it has maintainted a list of people pointing to it and sets all pointers in the list to NULL.

Something like this:


template <class T>;
class SuperPointer


       T*  data;
       vector<T**> owners;
       ~SuperPointer(){ // loop through owners setting them to NULL };


Anyone can essentially delete the data, it will update all respective pointers who are pointing to the data. Maybe there is a better way to think about this or there is some other pointer that does this?

c++ function pointers

08 July 2014 - 11:11 PM

8 Years never needed a function pointer and I can't find a good example.

#include <iostream>
using namespace std;

// Basic Function
int AddOne(int a)
    return a + 1;

// I want a function that returns a pointer to AddOne so I can call it

// This declaration does not work, what is the delcaration to return the function as a pointer.
int (*)(int) GiveMeFunctionPointer()
    return &AddOne;

void main()
    int (*foo)(int) = &AddOne; // Cool foo is a pointer to a function taking an int

    int (*foo2)(int) = GiveMeFunctionPointer(); // This is what I want to use...

    cout << foo(2);

Geometry Shaders

05 March 2014 - 03:39 PM

I think I have found a use for geometry shaders now. My question is:

I have a model of triangles: I Draw it.

I have a model of triangles, that goes through a geometry shader that spits out the same exact triangles as is from step 1.

Is this much/any slower than simply drawing the model? Is there a big overhead? I simply want to add a check before a triangle gets transformed, so that certain triangles never hit the vertex shader. But I don't know if it is too much overhead even to have the most basic geometry shader, that takes in a triangle and simply spits out the same one.

Is that even possible to discard triangles in a geometry shader?

GL_RGBA32F performance

22 February 2014 - 12:02 AM

I was using an FBO with GL_RGBA32F to store a computed normal map (generate 1x from a height map).
I changed it to a standard GL_RGB, unsigned byte texure, but comparing performances I decided to see how bad performance would be if I did all textures this way:

I changed my textures to this, from the standard GL_RGB internal format. I got 9 FPS, down from 170. I only have 39 textures. Explanation? Its not a bandwidth issue I don't think. Unless I go into gDebugger maybe I've used up all my GFX RAM and its swapping textures in system RAM. I do use some big shadow maps and VBO's so it could be possible.

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F_ARB, this->width, this->height, 0, GL_RGB, GL_UNSIGNED_BYTE, this->pixels);

Using Texture Arrays

19 February 2014 - 11:19 PM

I'm currently binding diffuse,normal,spec etc to TEXTURE_0,1,2

Is there any downside to throwing those 3 things into a texture array per object? I save a handful of opengl calls so that is a positive, but is there any downside to having a bunch of texture arrays? My instinct would be no. But I don't know if there is some cache issue where texture unit 0 1 2 have their own cache and throwing these into a texture array changes some memory layout or something.