Exemple #1
0
GLvoid
glLightModeli(GLenum pname, GLint params)
{
    wes_vertbuffer_flush();

    switch(pname)
    {
        case GL_LIGHT_MODEL_TWO_SIDE:
            SetUniform1i(uLightModel.TwoSided, params); break;
        case GL_LIGHT_MODEL_LOCAL_VIEWER:
            SetUniform1i(uLightModel.LocalViewer, params); break;
        case GL_LIGHT_MODEL_COLOR_CONTROL:
            SetUniform1i(uLightModel.ColorControl, params); break;
    }
}
Exemple #2
0
	void Shader::ResolveAndSetUniform(ShaderUniformDeclaration* uniform, byte* data, int offset)
	{
		switch (uniform->GetType())
		{
			case ShaderUniformDeclaration::Type::FLOAT32:
				SetUniform1f(uniform->GetLocation(), *(float*)&data[offset]);
				break;
			case ShaderUniformDeclaration::Type::SAMPLER2D:
			case ShaderUniformDeclaration::Type::INT32:
				SetUniform1i(uniform->GetLocation(), *(int*)&data[offset]);
				break;
			case ShaderUniformDeclaration::Type::VEC2:
				SetUniform2f(uniform->GetLocation(), *(maths::vec2*)&data[offset]);
				break;
			case ShaderUniformDeclaration::Type::VEC3:
				SetUniform3f(uniform->GetLocation(), *(maths::vec3*)&data[offset]);
				break;
			case ShaderUniformDeclaration::Type::VEC4:
				SetUniform4f(uniform->GetLocation(), *(maths::vec4*)&data[offset]);
				break;
			case ShaderUniformDeclaration::Type::MAT3:
				// TODO: SetUniformMat3(uniform->GetLocation(), *(maths::mat3*)&data[offset]);
				break;
			case ShaderUniformDeclaration::Type::MAT4:
				SetUniformMat4(uniform->GetLocation(), *(maths::mat4*)&data[offset]);
				break;
			default:
				SP_ASSERT(false, "Unknown type!");
		}
	}
Exemple #3
0
GLvoid
glColorMaterial(GLenum face, GLenum mode)
{
    wes_vertbuffer_flush();

    GLint ind = (face == GL_FRONT) ? 0 : 1;
    if (mode == GL_AMBIENT){
        SetUniform1i(uMaterial[ind].ColorMaterial, 0);
    } else if (mode == GL_DIFFUSE){
        SetUniform1i(uMaterial[ind].ColorMaterial, 1);
    } else if (mode == GL_AMBIENT_AND_DIFFUSE){
        SetUniform1i(uMaterial[ind].ColorMaterial, 2);
    } else if (mode == GL_SPECULAR){
        SetUniform1i(uMaterial[ind].ColorMaterial, 3);
    } else if (mode == GL_EMISSION){
        SetUniform1i(uMaterial[ind].ColorMaterial, 4);
    }
}
Exemple #4
0
void SetTexture(GLuint textureID, int slotID) {
	extern GLuint g_nSmallWhiteTexture;
	if( UniformExists(textureLocation) ) {
		if (textureID == 0xFFFFFFFF ) {
			textureID = g_nSmallWhiteTexture;
		}
		glActiveTexture(GL_TEXTURE0 + slotID);
		glBindTexture(GL_TEXTURE_2D, textureID);
		SetUniform1i(textureLocation, slotID);
	}
}
Exemple #5
0
void Shader::Bind() {
  glUseProgram(shader_program);

  for(auto i : const_uniform1f) {
    SetUniform1f(i.first, i.second);
  }

  for(auto i : const_uniform1i) {
    SetUniform1i(i.first, i.second);
  }
}
Exemple #6
0
GLvoid
glFogi(GLenum pname, GLint param)
{
    wes_vertbuffer_flush();

    switch(pname)
    {
        case GL_FOG_MODE:
            if (param == GL_LINEAR){
                SetUniform1i(uFogMode, 0);
            } else if (param == GL_EXP){
                SetUniform1i(uFogMode, 1);
            } else if (param == GL_EXP2){
                SetUniform1i(uFogMode, 2);
            }
            break;

        case GL_FOG_COORD_SRC:
            SetUniform1i(uEnableFogCoord, (param == GL_FOG_COORD)); break;
    }
}
Exemple #7
0
GLint C4ShaderCall::AllocTexUnit(int iUniform)
{
	// Want to bind uniform automatically? If not, the caller will take
	// care of it.
	if (iUniform >= 0) {

		// If uniform isn't used, we should skip this. Also check texunit range.
		if (!pShader->HaveUniform(iUniform)) return 0;
		assert(iUnits < C4ShaderCall_MaxUnits);
		if (iUnits >= C4ShaderCall_MaxUnits) return 0;

		// Set the uniform
		SetUniform1i(iUniform, iUnits);
	}

	// Activate the texture
	GLint hTex = GL_TEXTURE0 + iUnits;
	glActiveTexture(hTex);
	iUnits++;
	return hTex;
}
Exemple #8
0
GLvoid
wes_setstate(GLenum e, GLboolean b)
{
    wes_vertbuffer_flush();

    switch(e)
    {
        case GL_RESCALE_NORMAL:     SetUniform1i(uEnableRescaleNormal, b);   break;
        case GL_NORMALIZE:          SetUniform1i(uEnableNormalize, b);       break;
        case GL_TEXTURE_GEN_S:
            SetUniformIndex(uEnableTextureGen[u_activetex], 0, b);   break;
        case GL_TEXTURE_GEN_T:
            SetUniformIndex(uEnableTextureGen[u_activetex], 1, b);   break;
        case GL_TEXTURE_GEN_R:
            SetUniformIndex(uEnableTextureGen[u_activetex], 2, b);   break;
        case GL_TEXTURE_GEN_Q:
            SetUniformIndex(uEnableTextureGen[u_activetex], 3, b);      break;
        case GL_CLIP_PLANE0:        SetUniform1i(uEnableClipPlane[0], b);    break;
        case GL_CLIP_PLANE1:        SetUniform1i(uEnableClipPlane[1], b);    break;
        case GL_CLIP_PLANE2:        SetUniform1i(uEnableClipPlane[2], b);    break;
        case GL_CLIP_PLANE3:        SetUniform1i(uEnableClipPlane[3], b);    break;
        case GL_CLIP_PLANE4:        SetUniform1i(uEnableClipPlane[4], b);    break;
        case GL_CLIP_PLANE5:        SetUniform1i(uEnableClipPlane[5], b);    break;

        case GL_LIGHTING:           SetUniform1i(uEnableLighting, b);        break;
        case GL_LIGHT0:             SetUniform1i(uEnableLight[0], b);        break;
        case GL_LIGHT1:             SetUniform1i(uEnableLight[1], b);        break;
        case GL_LIGHT2:             SetUniform1i(uEnableLight[2], b);        break;
        case GL_LIGHT3:             SetUniform1i(uEnableLight[3], b);        break;
        case GL_LIGHT4:             SetUniform1i(uEnableLight[4], b);        break;
        case GL_LIGHT5:             SetUniform1i(uEnableLight[5], b);        break;
        case GL_LIGHT6:             SetUniform1i(uEnableLight[6], b);        break;
        case GL_LIGHT7:             SetUniform1i(uEnableLight[7], b);        break;
        case GL_COLOR_MATERIAL:     SetUniform1i(uEnableColorMaterial, b);   break;

        case GL_FOG:
            u_progstate.uEnableFog = b;
            SetUniform1i(uEnableFog, b);
            break;

        case GL_ALPHA_TEST:
            u_progstate.uEnableAlphaTest = b;
            break;

        case GL_TEXTURE_2D:
            u_progstate.uTexture[u_activetex].Enable = b;
            if (b)  wes_gl->glEnable(e);
            else    wes_gl->glDisable(e);
            break;

        default:
            if (b)  wes_gl->glEnable(e);
            else    wes_gl->glDisable(e);

            break;
    }
}
Exemple #9
0
GLvoid wes_state_init()
{
    int i;

    u_activetex = 0;
    SetUniform1i(uEnableRescaleNormal, 0);
    SetUniform1i(uEnableNormalize, 0);
    for(i = 0; i != WES_CLIPPLANE_NUM; i++){
        SetUniform4i(uEnableTextureGen[i], 0, 0, 0, 0);
    }
    for(i = 0; i != WES_CLIPPLANE_NUM; i++){
        SetUniform1i(uEnableClipPlane[i], 0);
    }
    SetUniform1i(uEnableLighting, 0);
    SetUniform1i(uEnableColorMaterial, 0);
    SetUniform1i(uEnableFog, 0);
    SetUniform1i(uEnableFogCoord, 0);

    for(i = 0; i != WES_LIGHT_NUM; i++){
        SetUniform1i(uEnableLight[i], 0);
        SetUniform4f(uLight[i].Position, 0.0, 0.0, 1.0, 0.0);
        SetUniform3f(uLight[i].Attenuation, 1.0, 0.0, 0.0);
        SetUniform4f(uLight[i].ColorAmbient, 0.0, 0.0, 0.0, 1.0);
        SetUniform4f(uLight[i].ColorDiffuse, 0.0, 0.0, 0.0, 1.0);
        SetUniform4f(uLight[i].ColorSpec, 0.0, 0.0, 0.0, 1.0);
        SetUniform3f(uLight[i].SpotDir, 0.0, 0.0, -1.0);
        SetUniform2f(uLight[i].SpotVar, 0.0, 180.0);
    }
    /* GL_LIGHT0's default parameters differ in these cases: */
    SetUniform4f(uLight[0].ColorDiffuse, 1.0, 1.0, 1.0, 1.0);
    SetUniform4f(uLight[0].ColorSpec, 1.0, 1.0, 1.0, 1.0);

    SetUniform1f(uRescaleFactor, 1.0);

    for(i = 0; i != WES_FACE_NUM; i++){
        SetUniform4f(uMaterial[i].ColorAmbient, 0.2, 0.2, 0.2, 1.0);
        SetUniform4f(uMaterial[i].ColorDiffuse, 0.8, 0.8, 0.8, 1.0);
        SetUniform4f(uMaterial[i].ColorSpec, 0.0, 0.0, 0.0, 1.0);
        SetUniform4f(uMaterial[i].ColorEmissive, 0.0, 0.0, 0.0, 1.0);
        SetUniform1f(uMaterial[i].SpecExponent, 0.0);
        SetUniform1i(uMaterial[i].ColorMaterial, 0);
    }

    SetUniform4f(uLightModel.ColorAmbient, 0.0, 0.0, 0.0, 1.0);
    SetUniform1i(uLightModel.TwoSided, GL_FALSE);
    SetUniform1i(uLightModel.LocalViewer, GL_FALSE);
    SetUniform1i(uLightModel.ColorControl, 0);

    SetUniform1i(uFogMode, 1);
    SetUniform1f(uFogDensity, 1.0);
    SetUniform1f(uFogStart, 0.0);
    SetUniform1f(uFogEnd, 1.0);
    SetUniform4f(uFogColor, 0.0, 0.0, 0.0, 0.0);

    for(i = 0; i < WES_MULTITEX_NUM; i++){
        SetUniform1i(uTexUnit[i], i);
        SetUniform4f(uTexEnvColor[i], 0.0f, 0.0f, 0.0f, 0.0f);
    }
    SetUniform1f(uAlphaRef, 0.0);

    u_progstate.uEnableAlphaTest = 0;
    u_progstate.uEnableFog = 0;
    u_progstate.uEnableClipPlane = 0;
    u_progstate.uAlphaFunc = 8;
    for(i = 0; i < WES_MULTITEX_NUM; i++){
        u_progstate.uTexture[i].Enable = 0;
        u_progstate.uTexture[i].Mode = WES_FUNC_MODULATE;
        u_progstate.uTexture[i].RGBCombine = WES_FUNC_MODULATE;
        u_progstate.uTexture[i].AlphaCombine = WES_FUNC_MODULATE;
        u_progstate.uTexture[i].Arg[0].RGBSrc = WES_SRC_TEXTURE;
        u_progstate.uTexture[i].Arg[1].RGBSrc = WES_SRC_PREVIOUS;
        u_progstate.uTexture[i].Arg[2].RGBSrc = WES_SRC_CONSTANT;
        u_progstate.uTexture[i].Arg[0].AlphaSrc = WES_SRC_TEXTURE;
        u_progstate.uTexture[i].Arg[1].AlphaSrc = WES_SRC_PREVIOUS;
        u_progstate.uTexture[i].Arg[2].AlphaSrc = WES_SRC_CONSTANT;
        u_progstate.uTexture[i].Arg[0].RGBOp = WES_OP_COLOR;
        u_progstate.uTexture[i].Arg[1].RGBOp = WES_OP_COLOR;
        u_progstate.uTexture[i].Arg[2].RGBOp = WES_OP_ALPHA;
        u_progstate.uTexture[i].Arg[0].AlphaOp = WES_OP_ALPHA;
        u_progstate.uTexture[i].Arg[1].AlphaOp = WES_OP_ALPHA;
        u_progstate.uTexture[i].Arg[2].AlphaOp = WES_OP_ALPHA;
    }
    u_progstate.uTexture[0].Enable = 1;

    //wes_state_update();
}
Exemple #10
0
	void Shader::SetUniform1i(const String& name, int value)
	{
		SetUniform1i(GetUniformLocation(name), value);
	}