Jump to content
  • Advertisement
Sign in to follow this  
3dmodelerguy

tried to delete this post, DON'T READ

This topic is 4835 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

Ok I am using RenderMonkey to create my shaders for GLSL but i have some questions. Ok, now the game engine i am working on right now is going to support DirectX and OpenGL so I don't want to write to shaders, one in GLSL and one in HLSL that do the same thing. (1)So my first question is is there a why to get the asm version of the shader from Render monkey and if not is there a way to turn the GLSL shader code into asm shader code? (2)My second question is how do i use the asm version shader in OpenGL? Any link to content about this would be great. [Edited by - 3dmodelerguy on August 23, 2005 10:39:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
As far as getting the actual shader assembly from Render Monkey or CG I'm not sure as I would have to read the instructions. I think the below link is a place to start for pixel shaders.

http://oss.sgi.com/projects/ogl-sample/registry/ARB/fragment_shader.txt

below this paragraph is the example from the article and as far as I can tell from my 5 minute glance is that you can feed it a buffer full of shader assembly and it'll handle it. They also have an similar function for vertex shaders and I would bet pretty similar code. I think abstracting out the the below code snippet into some sort of object would allow for cross vendor/cross api shader programming as DX has their versions of the low level shader API. Let polymorphism works its magic. Addition to a scene graph would be trivial at that point. Anyway for what its worth. I'd love it if someone else who knew more about shaders could comment. Laters...


GLboolean init(GLcharARB *vertexShader, GLcharARB *fragmentShader)
{
const GLcharARB *pInfoLog;
GLboolean compiled = GL_FALSE;
GLboolean linked = GL_FALSE;
GLint length;

//
// Create shader and program objects.
//
ProgramObject = glCreateProgramObjectARB();
VertexShaderObject = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
FragmentShaderObject = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);


length = strlen(vertexShader);
glShaderSourceARB(VertexShaderObject, 1, &vertexShader, &length);
glShaderSourceARB(FragmentShaderObject, 1, &fragmentShader, NULL);

//
// OpenGL made a copy of the shaders, we can free our copy
//
free(vertexShader);
free(fragmentShader);

//
// Compile the vertex and fragment shader, and print out the
// compiler log file.
//
glCompileShaderARB(VertexShaderObject);
glGetObjectParameterivARB(VertexShaderObject,
GL_OBJECT_COMPILE_STATUS_ARB, &compiled);

glGetObjectParamterivARB(VertexShaderObject,
GL_OBJECT_INFO_LOG_LENGTH_ARB, &maxLength);
pInfoLog = (GLcharARB *) malloc(maxLength * sizeof(GLcharARB));
glGetInfoLogARB(VertexShaderObject, maxLength, &length, pInfoLog);
printf("%s", pInfoLog);
free(pInfoLog);

if (!compiled) {
printf("Compile failed\n");
return GL_FALSE;
}

glCompileShaderARB(FragmentShaderObject);
glGetObjectParameterivARB(FragmentShaderObject,
GL_OBJECT_COMPILE_STATUS_ARB, &compiled);

glGetObjectParamterivARB(FragmentShaderObject,
GL_OBJECT_INFO_LOG_LENGTH_ARB, &maxLength);
pInfoLog = (GLcharARB *) malloc(maxLength * sizeof(GLcharARB));
glGetInfoLogARB(FragmentShaderObject, maxLength, NULL, pInfoLog);
printf("%s", pInfoLog);
free(pInfoLog);

if (!compiled) {
printf("Compile failed\n");
return GL_FALSE;
}

//
// Populate the program object with the compiled shadera
//
glAttachObjectARB(ProgramObject, VertexShaderObject);
glAttachObjectARB(ProgramObject, FragmentShaderObject);

//
// We want the shader objects to go away as soon as it is detached
// from the program object it is attached to. We can simply call
// delete now to achieve that. Note that calling delete on a program
// object will result in all shaders attached to that program object
// to be detached. If delete has been called for the shader objects,
// calling delete on the program object will result in the shader
// objects being deleted as well.
//
glDeleteObjectARB(VertexShaderObject);
glDeleteObjectARB(FragmentShaderObject);

//
// Link the program object and print out the linker log file
//
glLinkProgramARB(ProgramObject);
glGetObjectParameterivARB(ProgramObject,
GL_OBJECT_LINK_STATUS_ARB, &linked);

glGetObjectParamterivARB(ProgramObject,
GL_OBJECT_INFO_LOG_LENGTH_ARB, &maxLength);
pInfoLog = (GLcharARB *) malloc(maxLength * sizeof(GLcharARB));
glGetInfoLogARB(ProgramObject, maxLength, NULL, pInfoLog);

printf("%s\n", pInfoLog);
free(pInfoLog);

//
// If all went well, make the program object part of the current state
//
if (linked) {
glUseProgramObjectARB(ProgramObject);
return GL_TRUE;
} else {
return GL_FALSE;
}
}



Share this post


Link to post
Share on other sites
Thank for the great info, but I already have the GLSL shaders working in OpenGL use most of those commands, except the pInfoLog, which i really don't see why it is there.

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!