Jump to content
  • Advertisement
Sign in to follow this  
andy1984

template problem

This topic is 2806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Umm I'm having trouble making this template class that uses OpenGL stuf from glext.h. The error message says that "there are no arguments to 'glGenBuffersARB' that depend on a template parameter... bla". It treats all the functions from glext.h the same.

I only get this when I try to make the class as a template and implement stuff in the header file rather than the cpp file.

I'm just not too sure why this happens.


// Apparently this has to go right at the top
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>

#ifndef VBO_H
#define VBO_H

#include <vector>

...

template <typename T>
class Buffer
{
protected:
unsigned int m_id;
unsigned int m_type;
BufferNode m_node;
unsigned int m_usage;

static int s_supported;
// Check if VBOs are supported
static void checkSupported()
{
// Get Extensions String
std::string extensions = ((char const *)(glGetString(GL_EXTENSIONS)));
// Search The Extensions String For An Exact Copy
size_t found = extensions.find("GL_ARB_vertex_buffer_object");
if (found != std::string::npos)
s_supported = 1;
s_supported = -1;
};

public:
// Get the value of s_supported
static bool isSupported()
{
if (!s_supported)
checkSupported();
return s_supported == 1;
};
Buffer(unsigned int type, unsigned int size, unsigned int usage) :
m_id(0), m_type(type), m_node(0, size - 1), m_usage(usage)
{
// Make the buffer
glGenBuffersARB(1, &m_id);
bind();
glBufferDataARB(m_type, sizeof(T) * getSize(), 0, m_usage);
unbind();
};
~Buffer()
{
if (m_id)
glDeleteBuffersARB(1, &m_id);
};
unsigned int getId()
{
return m_id;
};
BufferNode* getNode()
{
return &m_node;
};
unsigned int getSize()
{
return m_node.getSize();
};
unsigned int getUsage()
{
return m_usage;
};
void bind()
{
glBindBufferARB(m_type, m_id);
};
void unbind()
{
glBindBufferARB(m_type, 0);
};
bool subData(BufferNode* node, unsigned int size, T* data)
{
if (!node || node->getSize() < size)
return false;
bind();
glBufferSubDataARB(m_id, node->getFirst(), size, data);
unbind();
return true;
};
};







Hope someone can clear this up for me.

Thanks,
Andy

Share this post


Link to post
Share on other sites
Advertisement
I haven't instantiated it, it just shows that error when I try to compile it. Its not really necessary that it be a template, I think I can change things around a little so all the opengl extension calls can go in a non-template class. I am still curious why it wont compile though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!