2017-05-19 1 views
-1

프래그먼트 셰이더를 컴파일하는 동안이 좌절감있는 오류를 실험하고 있습니다. 그대로 내가 쉐이더를 컴파일하려고하면 : $ 종료 기대, GLSL UNEXPECTED NEW_IDENTIFIER :

#version 450 core 
in vec2 tex_coord; 
in flat int vertex_id; 
out vec4 color; 
layout (binding = 20) uniform sampler2D buildingTex; 
layout (binding = 21) uniform sampler2D groundTex; 
const int cube_vertices = 36; 
const int ground_vertices = 4; 
void main(void) 
{ 

    if(vertex_id < cube_vertices) 
    { 
     float scaleF = .5f; 
     vec2 scale = vec2(scaleF,scaleF); 
     color = texture(buildingTex,tex_coord*scale); 
    } 
    if(vertex_id >= cube_vertices) 
    { 
     color = texture(groundTex,tex_coord); 
    } 


} 

compailer 함께 뿌려줍니다.

는 내 조각 쉐이더 다른 조각 쉐이더에 추가 그러나, 내가 다른 파일에했다, 그 후 나는 모든 행이 좋아하는 다음과 논평 :이 경우

// #version 450 core 

// in vec2 tex_coord; 
// in flat int vertex_id; 
// out vec4 color; 

// layout (binding = 20) uniform sampler2D buildingTex; 
// layout (binding = 21) uniform sampler2D groundTex; 

// int cube_vertices; 
// int ground_vertices; 


// void main(void) 
// { 

// if(vertex_id < cube_vertices) 
//  { 
//  float scaleF = .5f; 
//  vec2 scale = vec2(scaleF,scaleF); 
//  color = texture(buildingTex,tex_coord*scale); 
//  //color = vec4(1.0,1.0,1.0,1.0); 
//  } 
// if(vertex_id >= cube_vertices) 
//  { 
//  color = texture(groundTex,tex_coord); 
//  //color = vec4(1.0,0.0,0.0,1.0); 
//  } 




#version 450 core 
in vec2 tex_coord; 
in flat int vertex_id; 
out vec4 color; 
layout (binding = 20) uniform sampler2D buildingTex; 
layout (binding = 21) uniform sampler2D groundTex; 
const int cube_vertices = 36; 
const int ground_vertices = 4; 
void main(void) 
{ 

    if(vertex_id < cube_vertices) 
    { 
     float scaleF = .5f; 
     vec2 scale = vec2(scaleF,scaleF); 
     color = texture(buildingTex,tex_coord*scale); 
    } 
    if(vertex_id >= cube_vertices) 
    { 
     color = texture(groundTex,tex_coord); 
    } 


} 

이 쉐이더를 컴파일! 이전 코드의 주석 처리 된 행을 제거하려고 시도했지만, 일부만 제거 할 수있는 반면, 만질 수없는 일부는 쉐이더를 컴파일 할 수있는 것처럼 보입니다.

// #version 450 core 

// in vec2 tex_coord; 
// in flat int vertex_id; 
// out vec4 color; 

// layout (binding = 20) uniform sampler2D buildingTex; 
// layout (binding = 21) uniform sampler2D groundTex; 

// int cube_vertices; 
// if(vertex_id < cube_vertices) 


#version 450 core 
in vec2 tex_coord; 
in flat int vertex_id; 
out vec4 color; 
layout (binding = 20) uniform sampler2D buildingTex; 
layout (binding = 21) uniform sampler2D groundTex; 
const int cube_vertices = 36; 
const int ground_vertices = 4; 
void main(void) 
{ 

    if(vertex_id < cube_vertices) 
    { 
     float scaleF = .5f; 
     vec2 scale = vec2(scaleF,scaleF); 
     color = texture(buildingTex,tex_coord*scale); 
    } 
    if(vertex_id >= cube_vertices) 
    { 
     color = texture(groundTex,tex_coord); 
    } 


} 

내가 주석 코드에서 더 이상 제거 할 수없는 것 같다

이 순간에 쉐이더입니다.

내 인생에서 가장 비논리적 인 문제인 것처럼 보였으므로, 다른 사람들이이 같은 오류 경고를하는 질문이 내 사건과 일치하지 않는 방식으로 해결되었으므로 새로운 탐구를 시작합니다.

ps : 완전히 새로운 셰이더를 만들려고했으나 제대로 작동하지 않았습니다.

pps : 이멕스의 메이저 모드를 변경하지 않고 Mx를 통해 메이저 모드를 변경 한 후에 문제가 발생합니다.이 쉐이더 파일은 쉐이더 파일의 cpp 파일에 사용되는 일반 단축키를 사용합니다 (.vert, .frag ...), 기본 모드를 복원하고 이맥을 다시 시작하더라도 쉐이더는 컴파일되지 않습니다!

편집 :

이 요약 : 쉐이더 파일이 널 (null) 종료되어야한다, 나는 쉐이더 소스를로드하는 기능을 수정이 내가 쉐이더 영업에서

const char* Shader::loadShader(std::string shaderPath) 
    { 
    std::ifstream temp_ss(shaderPath,std::ifstream::in); 
    if(temp_ss) 
     { 
    char c; 
    char *ss = new char[shader_size]; 

    unsigned i = 0 ; 
    while(temp_ss.get(c)) 
     { 

     ss[i++] = c; 
     } 

    std::cout<<std::ends; 
    //ends adds a null, and then flushes the buffer 
    //if i don't use it , often, the window does not show anything 
    //I could use std::cout<<std::endl; in place of ends, 
    //but ends seem a more polite solution to me 



//CHECK SHADER 
    for(int i = 0; i < shader_size; i++) 
     if(ss[i] == '\0') 
     std::cout<<"shader.cpp::ERROR: NULL CHARACTER FOUND ON SHADER "<< 
      shaderPath<<std::endl; 

    return ss; 

     } 
    else 
     std::clog<<"shader.cpp::loadShader() : ERROR ::: no shaders found at the path : "<<shaderPath<<std::endl; 



    } 
+0

텍스트를 쉐이더에 가져 오기 위해 사용하는 코드가 필요합니다. 확률은 거기에 버그가 좋다. –

+0

가끔 복사 및 붙여 넣기가 원하지 않는 문자 (대부분 보이지 않음)를 전달합니다 (아무 것도 나타내지 않음). 하지만 컴파일러가이를 감지합니다. – Ripi2

+0

컴파일러는 일반적으로 오류 행을 알려줍니다. – Ripi2

답변

1

를로드하는 데 사용하는 방법입니다

const char* Shader::loadShader(std::string shaderPath) 
    { 
    std::ifstream temp_ss(shaderPath,std::ifstream::in); 
    if(temp_ss) 
     { 
    char c; 
    char *ss = new char[shader_size]; 

    unsigned i = 0 ; 
    while(temp_ss.get(c)) 
     { 

     ss[i++] = c; 
     } 

    //CHECK SHADER 
     bool nullTerminated = false; 
    for(int i = 0; i < shader_size; i++) 
     if(ss[i] == '\0') 
     nullTerminated = true; 

    if(!nullTerminated) 
     ss[shader_size++] = '\0'; 

    return ss; 

     } 
    else 
     std::clog<<"shader.cpp::loadShader() : ERROR ::: no shaders found at the path : "<<shaderPath<<std::endl; 



    } 

그리고 조각 셰이더가 다음과 같이 컴파일됩니다.

관련 문제