Jump to content
  • Advertisement
Sign in to follow this  
Vortez

Why is my shader class not working on vmware?

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

Hi, i've build this shader class for my engine a long time ago, based on the nehe tutorial, it work well in most of the case, but on some computer and in vmware, with accelerated graphics enabled something is wrong, and i can't figure out what it is. There's 3 differant senario and it work on only 2 of them:

1-Real Computer: Work flawlessly
2-VMWare with no 3d accel.: Shaders don't work, but it's normal, the game know it can't use them and dosen't crash.
3-VMWare with 3d accel: Shader don't work, but the 4 tested extention are present, only fail at shader compilation, and the game crash afterward (the crash is not what's important for now, it's why it dosen't compile that bug me...)

Here's my code:


#include "Shader.h"

//-----------------------------------------------------------------------------
// Name : InitFunctionsPointers()
// Desc : Get all the function pointer adress necessary
//-----------------------------------------------------------------------------
void CShader::InitFunctionsPointers()
{
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) wglGetProcAddress("glUseProgramObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress("glCreateShaderObjectARB");
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) wglGetProcAddress("glCreateProgramObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) wglGetProcAddress("glDeleteObjectARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) wglGetProcAddress("glShaderSourceARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) wglGetProcAddress("glCompileShaderARB");
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) wglGetProcAddress("glAttachObjectARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) wglGetProcAddress("glLinkProgramARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) wglGetProcAddress("glGetObjectParameterivARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) wglGetProcAddress("glGetInfoLogARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) wglGetProcAddress("glGetUniformLocationARB");
glUniform1fARB = (PFNGLUNIFORM1FARBPROC) wglGetProcAddress("glUniform1fARB");
glUniform2fARB = (PFNGLUNIFORM2FARBPROC) wglGetProcAddress("glUniform2fARB");
glUniform3fARB = (PFNGLUNIFORM3FARBPROC) wglGetProcAddress("glUniform3fARB");
glUniform4fARB = (PFNGLUNIFORM4FARBPROC) wglGetProcAddress("glUniform4fARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC) wglGetProcAddress("glUniform1iARB");
glUniform2iARB = (PFNGLUNIFORM2IARBPROC) wglGetProcAddress("glUniform2iARB");
glUniform3iARB = (PFNGLUNIFORM3IARBPROC) wglGetProcAddress("glUniform3iARB");
glUniform4iARB = (PFNGLUNIFORM4IARBPROC) wglGetProcAddress("glUniform4iARB");
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Name : GetShaderFileSize(FILE *f)
// Desc : Return the size of the current opened file
//-----------------------------------------------------------------------------
UINT CShader::GetShaderFileSize(FILE *f)
{
fseek(f, 0, SEEK_END);
UINT RetVal = ftell(f);
fseek(f, 0, SEEK_SET);

return RetVal;
}

//-----------------------------------------------------------------------------
// Name : ReadShaderFile(char *fname, GLenum *pShaderID)
// Desc : Read the shader file source code
//-----------------------------------------------------------------------------
bool CShader::ReadShaderFile(char *fname, GLenum *pShaderID)
{
FILE *f = fopen(fname, "rb");

if(!f){
char c[256];
sprintf(c, "File \"%s\"Not found", fname);
MessageBox(0, c, "Error!", 0);
return false;
}

const UINT FileSize = GetShaderFileSize(f);

char *pBuf = new char [FileSize+1];
ZeroMemory(pBuf, FileSize+1);
fread(pBuf, 1, FileSize, f);

const char *pSourceCode = pBuf;
glShaderSourceARB(*pShaderID, 1, &pSourceCode, NULL); // pass vshader data

SAFE_DELETE_ARRAY(pBuf);

fclose(f);
return true;
}

//-----------------------------------------------------------------------------
// Name : LoadShaders(char *fname, int Type)
// Desc : Load the shader
//-----------------------------------------------------------------------------
bool CShader::LoadShaders(char *VertexShader_fname, char *FragmentShader_fname)
{
InitFunctionsPointers();

if(VertexShader_fname == NULL)
return false;

//Check if vertex shader extension is supported
if(!GLCompatibility.CheckExtension("GL_ARB_vertex_program") ||
!GLCompatibility.CheckExtension("GL_ARB_vertex_shader")){
MessageBox(0, "Vertex Shaders Not Supported...", "Error!", 0);
return false;
}

//Check if fragment shader extension is supported
if(FragmentShader_fname){
if(!GLCompatibility.CheckExtension("GL_ARB_fragment_program") ||
!GLCompatibility.CheckExtension("GL_ARB_fragment_shader")){
MessageBox(0, "Fragment Shaders Not Supported...", "Error!", 0);
return false;
}
}

m_Program = glCreateProgramObjectARB(); //"container for shaders"
if(!m_Program){
MessageBox(0, "Unable to create shader program object...", "Error!", 0);
return false;
}


{
// Vertex shader
m_vShaderID = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); // "vertex shader"
if(!m_vShaderID){
MessageBox(0, "Unable to create Vertex shader object...", "Error!", 0);
return false;
}

//glShaderSourceARB(m_vShaderID, vshaderCode, vshaderLen); // pass vshader data
if(!ReadShaderFile(VertexShader_fname, &m_vShaderID)){
MessageBox(0, "Unable to Read Vertex shader object...", "Error!", 0);
return false;
}

-------------> // COMPILATION FAIL HERE (in vmware with 3d accel. only) <-------------------------------------------------------
glCompileShaderARB(m_vShaderID); // compile vshader

int success = 0;
glGetObjectParameterivARB(m_vShaderID, GL_OBJECT_COMPILE_STATUS_ARB, &success);

-------------> if(!success){ // <- ...so success == false here
const int MaxInfoLogSize = 4096;
char infoLog[MaxInfoLogSize];

glGetInfoLogARB(m_vShaderID, MaxInfoLogSize, NULL, infoLog);

char c[MaxInfoLogSize+256];
sprintf(c, "%s\r\n\r\n%s", "Vertex shader compilation failed...", infoLog);
MessageBox(0, c, "Error!", 0);
return false;
}

//glAttachObjectARB(m_Program, m_vShaderID);
}

if(FragmentShader_fname != NULL){
// Optional Fragment (Pixel) shader
m_fShaderID = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); // "fragment shader"
if(!m_fShaderID){
MessageBox(0, "Unable to create Fragment shader object...", "Error!", 0);
return false;
}

//glShaderSourceARB(m_fShaderID, pshaderCode, pshaderLen); // pass pshader data
if(!ReadShaderFile(FragmentShader_fname, &m_fShaderID)){
MessageBox(0, "Unable to Read Fragment shader object...", "Error!", 0);
return false;
}

glCompileShaderARB(m_fShaderID); // compile pshader

int success = 0;
glGetObjectParameterivARB(m_fShaderID, GL_OBJECT_COMPILE_STATUS_ARB, &success);

if(!success){
const int MaxInfoLogSize = 4096;
char infoLog[MaxInfoLogSize];

glGetInfoLogARB(m_fShaderID, MaxInfoLogSize, NULL, infoLog);

char c[MaxInfoLogSize+256];
sprintf(c, "%s\r\n\r\n%s", "Fragment shader compilation failed...", infoLog);
MessageBox(0, c, "Error!", 0);
return false;
}

glAttachObjectARB(m_Program, m_fShaderID);
//check for errors <-here->
}
glAttachObjectARB(m_Program, m_vShaderID);

// Optional Initialize Attribute variables <-here->

glLinkProgramARB(m_Program);

// Initialize Uniform variables <-here->
InitShaderDataExt();

return true;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Name : FreeShader()
// Desc : Delete shader
//-----------------------------------------------------------------------------
void CShader::FreeShader()
{
//Destroy the shaders context
if(m_Program/* && m_IsShaderAvailable*/)
glDeleteObjectARB(m_Program);
}



What could i be doing wrong?? every glblablabla pointer are set right, i check for the 4 extentions like "GL_ARB_fragment_program" and such, and they're all there, And as i said above, everything work just fine on my real computer. Here's the shader source:


// Shader.vs
////////////////////

uniform vec3 LightPos0;

uniform vec4 Tex0Scale;
uniform vec4 Tex1Scale;
uniform vec4 Tex0Translate;
uniform vec4 Tex1Translate;

uniform int UsePerVertexFog;
uniform int UseLighting;
uniform int UseWaterWave;
uniform int UseAlphaBlendingForReflection;

uniform float WaveMovement;

float AlphaVal;

////////////////////////////////////
void main(void)
{

////////////////////////////////
//Generate the water's waves
////////////////////////////////
// Are we rendering the water mesh?
if(UseWaterWave == 1){
gl_Vertex.y = ((sin(WaveMovement + (gl_Vertex.x / 2.0)) + sin(WaveMovement + (gl_Vertex.z / 2.0))) * 25.0) - 1500.0;
}


////////////////////////////////
//That MUST be there...
////////////////////////////////
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;


////////////////////////////////
//Lightning...
////////////////////////////////
vec3 N = normalize(gl_NormalMatrix * gl_Normal);
vec4 V = gl_ModelViewMatrix * gl_Vertex;
vec3 L = normalize(LightPos0 - V.xyz);
vec3 H = normalize(L + vec3(0.0, 0.0, 1.0));
const float specularExp = 256.0;

// calculate diffuse lighting
float NdotL = dot(N, L);
vec4 diffuse = gl_Color * vec4(max(0.0, NdotL));

// calculate specular lighting
float NdotH = dot(N, H);
vec4 specular = vec4(pow(max(0.0, NdotH), specularExp));

// Use our lighting model?
if(UseWaterWave){
gl_FrontColor = diffuse; //gl_Color;
gl_FrontColor.a = 0.85;
} else {
if(UseLighting == 1){
// sum the diffuse and specular components
gl_FrontColor.rgba = diffuse + specular;
// Keep the alpha value
gl_FrontColor.a = gl_Color.a;
} else {
// Keep the original color
gl_FrontColor = gl_Color;
}
}

if(UseAlphaBlendingForReflection == 1){
gl_FrontColor = gl_Color;
if(gl_Vertex.y > 0.0){
AlphaVal = gl_Vertex.y / 180.0;
if(AlphaVal > 1.0){
AlphaVal = 1.0;
}
AlphaVal = 1.0 - AlphaVal;
AlphaVal = AlphaVal * 0.333;
//AlphaVal = AlphaVal / 2.0;
gl_FrontColor.a = AlphaVal;
}
}

///////////////////////
//Texture...
///////////////////////
// Translate, scale, and set texture coordnates
gl_TexCoord[0].x = (gl_MultiTexCoord0.x + Tex0Translate[0]) * Tex0Scale[0];
gl_TexCoord[0].y = (gl_MultiTexCoord0.y + Tex0Translate[1]) * Tex0Scale[1];
gl_TexCoord[1].x = (gl_MultiTexCoord1.x + Tex1Translate[0]) * Tex1Scale[0];
gl_TexCoord[1].y = (gl_MultiTexCoord1.y + Tex1Translate[1]) * Tex1Scale[1];


///////////////////////
//Fog...
///////////////////////
//Choose wich fog equation we want to use...
if(UsePerVertexFog == 1){
gl_FogFragCoord = gl_FogCoord; //Vertex fog, use the input fog coord
} else {
gl_FogFragCoord = length(V) / 20000.0; //Distance Fog(fake Per-Pixel fog, based on the distance of the vertex, not the fragment...)
}
}

Share this post


Link to post
Share on other sites
Advertisement
if anyone having trouble understanding my code just compile the vertex shader tutorial from nehe, and try it on a virtual machine.

Share this post


Link to post
Share on other sites
VMs and hardware acceleration are notorious for not playing well together. I would check to see if anything works with hardware acceleration on your particular VM, before worrying too much about your particular code.

Share this post


Link to post
Share on other sites
Getting any type of slightly advanced shader based code work on a VM is a nightmare. Due to past experiences we added a paragraph to our maintenance contracts that automatically voids all support claims if the customer runs our software on a VM. It was impossible to manage all the issues that came up when people tried this. VMWare Fusion was the worst. The amount of bugs in their 3D layer was beyond anything we ever experienced. The best performing VM was Parallels, but we still had major issues with it.

In short: it's probably the VM. There's unfortunately not much you can do about it.

Share this post


Link to post
Share on other sites
Thx for ur answer, the bug was not related to the shader but rather a poor (and buggy) implementation of glReadPixel() on the vm. Trying to read a pixel that was out of the screen boundary crashed in vm, but not otherwise, anyway i fixed it now.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!