本文整理汇总了C++中CShader类的典型用法代码示例。如果您正苦于以下问题:C++ CShader类的具体用法?C++ CShader怎么用?C++ CShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: configure
void CRectangleSymbol::configure()
{
m_vertices[0].vertex = glm::vec2(m_size.x, m_size.y);
m_vertices[1].vertex = glm::vec2(m_size.x + m_size.z, m_size.y);
m_vertices[2].vertex = glm::vec2(m_size.x + m_size.z, m_size.y + m_size.w);
m_vertices[3].vertex = glm::vec2(m_size.x, m_size.y + m_size.w);
m_vertices[0].uv = glm::vec2(0.0f, 1.0f - 0.0f);
m_vertices[1].uv = glm::vec2(1.0f, 1.0f - 0.0f);
m_vertices[2].uv = glm::vec2(1.0f, 1.0f - 1.0f);
m_vertices[3].uv = glm::vec2(0.0f, 1.0f - 1.0f);
CShader *shader = CShaderFactory::getInstance()->getShader("text");
if (shader) {
m_vao.genBuffer();
m_vao.bind();
m_vertexVBO.genBuffer();
m_vertexVBO.setData(&m_vertices);
shader->setAttribute("a_position", 2, 0, sizeof(CVertex2D));
shader->setAttribute("a_uv", 2, 8, sizeof(CVertex2D));
// shader->setAttribute("a_color", 3, 16, sizeof(CVertex2D));
m_vao.disable();
}
}
示例2: QERApp_Shader_ForName
IShader *WINAPI QERApp_Shader_ForName (const char *name)
{
if (name == NULL || strlen (name) == 0)
{
// Hydra: This error can occur if the user loaded a map with/dropped an entity that
// did not set a texture name "(r g b)" - check the entity definition loader
g_FuncTable.m_pfnSysFPrintf (SYS_ERR, "FIXME: name == NULL || strlen(name) == 0 in QERApp_Shader_ForName\n");
return QERApp_Shader_ForName (SHADER_NOT_FOUND);
}
// entities that should be represented with plain colors instead of textures
// request a texture name with (r g b) (it's stored in their class_t)
if (name[0] == '(')
{
return QERApp_ColorShader_ForName (name);
}
CShader *pShader = static_cast < CShader * >(QERApp_Try_Shader_ForName (name));
if (pShader)
{
pShader->SetDisplayed (true);
return pShader;
}
return QERApp_CreateShader_ForTextureName (name);
}
示例3: CShader
void CScene::BuildObjects(ID3D11Device *pd3dDevice)
{
CShader *pShader = new CShader();
pShader->CreateShader(pd3dDevice);
m_nObjects = 51;
m_ppObjects = new CGameObject*[m_nObjects];
//가로x세로x높이가 15x15x15인 정육면체 메쉬를 생성한다.
CCubeMesh *pMesh = new CCubeMesh(pd3dDevice, 50.0f, 50.0f, 50.0f); // random color cube draw
CRotatingObject *pObject = new CRotatingObject();
//pObject->SetPosition(0, 0, 0);
pObject->SetMesh(pMesh);
pObject->SetShader(pShader);
m_ppObjects[0] = pObject;
for (int i = 1; i <= 50; ++i)
{
CCubeMesh *pMesh = new CCubeMesh(pd3dDevice, 5.0f, 5.0f, 5.0f); // random color cube draw
CRotatingObject *pObject = new CRotatingObject();
pObject->SetPosition(-10.0f, 0, 0);
pObject->SetMovingDirection(D3DXVECTOR3(float(rand() % 10) / 100.f, float(rand() % 10) / 100.f, float(rand() % 10) / 100.f));
pObject->SetMovingSpeed(0.03f);
pObject->SetMesh(pMesh);
pObject->SetShader(pShader);
m_ppObjects[i] = pObject;
}
}
示例4: m_TriangleProgram
GfxContext::GfxContext()
: m_TriangleProgram(nullptr)
{
// TODO: Shouldn't be done in here! Move to client's code!
auto cubeGeom = LoadGeometryFromObj("resources\\cube.obj", "cube");
auto cube = shared_ptr<SceneObject>(new SceneObject());
auto cube2 = shared_ptr<SceneObject>(new SceneObject());
cube->Attributes.Geometry = cubeGeom;
cube2->Attributes.Geometry = cubeGeom;
cube2->Move(float3(0.0f, 3.0f, 0.0f));
m_Scene.Add(cube);
m_Scene.Add(cube2);
CShader* fShader = new CShader(GL_FRAGMENT_SHADER, "resources/shaders/mvp.frag");
CShader* vShader = new CShader(GL_VERTEX_SHADER, "resources/shaders/mvp.vert");
fShader->Compile();
vShader->Compile();
m_TriangleProgram = new CProgram();
m_TriangleProgram->Attach(fShader);
m_TriangleProgram->Attach(vShader);
m_TriangleProgram->Link();
m_Textures["grass"] = LoadTextureDDS("resources/textures/test-rgb8-256b.dds");
glEnable(GL_DEPTH_TEST);
}
示例5: QERApp_LoadShadersFromDir
int WINAPI QERApp_LoadShadersFromDir (const char *path)
{
int count = 0;
// scan g_Shaders, and call QERApp_Shader_ForName for each in the given path
// this will load the texture if needed and will set it in use..
int nSize = g_Shaders.GetSize ();
for (int i = 0; i < nSize; i++)
{
CShader *pShader = reinterpret_cast < CShader * >(g_Shaders[i]);
if (strstr (pShader->getShaderFileName (), path) || strstr (pShader->getName (), path))
{
count++;
// request the shader, this will load the texture if needed and set "inuse"
//++timo FIXME: should we put an Activate member on CShader?
// this QERApp_Shader_ForName call is a kind of hack
IShader *pFoo = QERApp_Shader_ForName (pShader->getName ());
#ifdef _DEBUG
// check we activated the right shader
// NOTE: if there was something else loaded, the size of g_Shaders may have changed and strange behaviours are to be expected
if (pFoo != pShader)
Sys_Printf ("WARNING: unexpected pFoo != pShader in QERApp_LoadShadersFromDir\n");
#else
pFoo = NULL; // leo: shut up the compiler
#endif
}
}
return count;
}
示例6: FindShader
HRESULT CShaderManager::CreateShader(const SHADER_TYPE& eShader, const LPCTSTR pFileName)
{
CShader* pShader = FindShader(eShader);
if(pShader)
{
return S_OK;
}
switch(eShader)
{
case SHADER_DEFAULT:
pShader = new CDefaultShader;
break;
default:
break;
}
if(FAILED(pShader->Init(pFileName)))
{
return E_FAIL;
}
m_mapShader.insert(map<SHADER_TYPE, CShader*>::value_type(eShader, pShader));
return S_OK;
}
示例7: CShader
CShader* CCacheResourceManager::LoadShader(const std::string& name)
{
if(shaderResources.find(name) != shaderResources.end())
{
#ifdef DEBUG
std::cerr<<"CCacheResourceManager: [INFO] "<< name<<" loaded from cache.\n";
#endif
return shaderResources.find(name)->second;
}
CShader* ptr = new CShader();
string vshader = name;
string pshader = name;
StringManipulator::AddCharArrayToString(vshader, ".vsh");
StringManipulator::AddCharArrayToString(pshader, ".fsh");
if(!ptr->LoadShadersFromMemory(getContentFromPath(getPath(vshader)).c_str(),
getContentFromPath(getPath(pshader)).c_str()))
{
std::cerr<< "CCacheResourceManager: [ERROR] failed to load shader: "<< name << "...<\n";
delete ptr;
return NULL;
}
shaderResources[name] = ptr;
#ifdef DEBUG
std::cerr<< "CCacheResourceManager: [SUCCESS] "<<name <<" shader loaded...\n";
#endif
return ptr;
}
示例8: GetRenderInterfaces
//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
void CEntityTypeLight::Render( void )
{
BaseClass::Render();
if( IsSelected() )
{
CBaseGeometry *geom = GetRenderInterfaces()->GetRendererInterf()->GetLightList()->GetUnitSphere();
CPointLight *light = GetRenderInterfaces()->GetRendererInterf()->GetLightList()->GetPointLight(m_lightIndex);
//calculate light geometry scales
float fMaxDist = light->GetDist();
geom->SetScale(fMaxDist);
geom->SetAbsPos(GetAbsCenter());
geom->SetAbsAngles(GetAbsAngles());
CShader *pShd = GetShaderManager()->GetActiveShader();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
GetGLStateSaver()->Disable(GL_CULL_FACE);
pShd->EnableTexturing(false);
pShd->SetDrawColor(1, 1, 0, 1);
geom->RenderNoTextureBufferOnly(false);
pShd->SetDrawColor(1, 1, 1, 1);
GetGLStateSaver()->Enable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
}
示例9: QERApp_ColorShader_ForName
IShader *WINAPI QERApp_ColorShader_ForName( const char *name ){
CShader *pShader = new CShader();
pShader->CreateColor( name );
// hook it into the shader list
pShader->IncRef();
g_Shaders.Add( (void *) pShader );
return pShader;
}
示例10: glDepthFunc
bool CScene::RenderShadow()
{
std::list<axelynx::Camera *>::const_iterator ci = camlist.begin();
std::list<axelynx::Camera *>::const_iterator ei = camlist.end();
CShadowPass::SetShadowShader(defShader_);
CShadowPass::StartPass();
for(;ci!=ei;++ci)
{
if((*ci)->isEnabled())
{
frame_++;
(*ci)->Bind(zpassed?-1:0);
CMaterial::Free(); //материал зависит от камеры
if(zpassed)
{
CEarlyZ::StartRenderPass();
}
else
{
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
}
for(int i=0;i<256;++i)
{
if(visible_groups_[i])
scenegraph_[i]->Render(*ci);
}
(*ci)->UnBind();
CMaterial::Free(); //материал зависит от камеры
}
}
CShader *cs = CShader::Current();
if(cs)
cs->UnBind();
for(int i=0;i<16;++i)
{
CTexture *ct = CTexture::Current(i);
if(ct)
ct->UnBind();
}
if(zpassed)
CEarlyZ::EndRenderPass();
zpassed = false;
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDepthMask(GL_TRUE);
CShadowPass::EndPass();
return true;
}
示例11: sprintf
ERRCODE CRenderer::ProcessBufferQueue()
{
if(!queueMeshes->empty()) //В очереди ждет один или более мешей
{
//Пишем буферы меша (RAM) в видеопамять
PAIR_UINT pair = vbContainer->Write(queueMeshes->front()->GetBuffer(BUFFER_V)->GetType(),
queueMeshes->front()->GetBuffer(BUFFER_V)->GetSize(),
queueMeshes->front()->GetBuffer(BUFFER_V)->GetBuffer());
PAIR_UINT indpair = vbContainer->Write(queueMeshes->front()->GetBuffer(BUFFER_I)->GetType(),
queueMeshes->front()->GetBuffer(BUFFER_I)->GetSize(),
queueMeshes->front()->GetBuffer(BUFFER_I)->GetBuffer());
//Записываем координаты данных в видеопамяти
queueMeshes->front()->SetBufferCoords(BUFFER_V, pair.x, pair.y, queueMeshes->front()->GetBuffer(BUFFER_V)->GetSize());
queueMeshes->front()->SetBufferCoords(BUFFER_I, indpair.x, indpair.y, queueMeshes->front()->GetBuffer(BUFFER_I)->GetSize());
//Меш готов для рендера, записываем ссылку на него в массив мешей
CMesh* msh = queueMeshes->front();
queueMeshes->pop();
vecMeshes->push_back(msh);
//Удаляем указатель на меш из очереди
char* str = new char[50];
sprintf(str, "Written vertex data into VBO\n");
Log(str);
delete [] str;
}
if(!queueTextures2D->empty())
{
//TODO: Сохранить текстуру в опенгл и отдать CTexture2D хендл(ID) на сохраненную текстуру
CTexture2D* tex2D = queueTextures2D->front();
GLuint iT;
glGenTextures(1, &iT);
glBindTexture(GL_TEXTURE_2D, iT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex2D->GetWidth(), tex2D->GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tex2D->GetPixels());
glBindTexture(GL_TEXTURE_2D, 0);
tex2D->SetTexture2Did(iT);
queueTextures2D->pop();
vecTextures2D->push_back(tex2D);
}
if(!queueShaders->empty())
{
CShader* shader = queueShaders->front();
//TODO: Компилируем шейдер, отправляем ID в CShader
shader->Compile();
queueShaders->pop();
vecShaders->push_back(shader);
Log("Compiled shader program.\n");
}
return ERR_OK;
}
示例12: Shader_ForName
// NOTE: case sensitivity
// although we store shader names with case information, Radiant does case insensitive searches
// (we assume there's no case conflict with the names)
CShader* CShaderArray::Shader_ForName( const char * name) const
{
int i;
for ( i = 0; i < CPtrArray::GetSize(); i++ )
{
CShader *pShader = static_cast<CShader*>(CPtrArray::GetAt(i));
if (_stricmp(pShader->getName(), name) == 0)
return pShader;
}
return NULL;
}
示例13: glTranslatef
void CRenderer::ProcessNode(CNode* node)
{
std::vector<CNode*> *vec = node->GetNodeVector();
//Обновляем нод, рендерим сущности
//Log("Node is updated\n");
glTranslatef(node->GetPosX(), node->GetPosY(), node->GetPosZ());
for(int i = 0; i < node->GetObjVector()->size(); i++)
{
if(node->GetObjVector()->at(i)->GetType()==OBJECT_ENTITY)
{
//TO DO:
//Берем шейдер, соотвутствующий сущности и активируем его
//-----
CMaterial* mat;
CShader* sh;
if((mat = ((CEntity*)node->GetObjVector()->at(i))->GetMaterial())!=0)
{
if((sh = mat->GetShader())!=0)
{
if(sh->IsCompiled())
{
glUseProgram(sh->GetProgramId());
}
}
}
DrawMesh(((CEntity*)node->GetObjVector()->at(i))->GetMesh());
glUseProgram(0);
}
}
glDisable(GL_DEPTH_TEST);
glBegin(GL_LINES);
glColor3f(0.5, 1, 0.5);
glVertex3f(0, 0, 0);
glVertex3f(0, 1, 0);
glColor3f(1, 0.5, 0.5);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glColor3f(0.5, 0.5, 1);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 1);
glColor3f(1,1,1);
glEnd();
glEnable(GL_DEPTH_TEST);
for(int i = 0; i < vec->size(); i++)
{
ProcessNode(vec->at(i));
}
glTranslatef(-node->GetPosX(), -node->GetPosY(), -node->GetPosZ());
}
示例14: QERApp_Try_Shader_ForName
IShader* WINAPI QERApp_Try_Shader_ForName(const char* name)
{
// look for the shader
CShader* pShader = g_Shaders.Shader_ForName( name );
if (!pShader)
// not found
return NULL;
// we may need to load the texture or use the "shader without texture" one
pShader->Activate();
pShader->SetDisplayed( true );
return pShader;
}
示例15: DirectoryList
// 深度优先递归遍历目录中所有的文件
BOOL DirectoryList(LPCSTR Path, int nRenderType)
{
WIN32_FIND_DATA FindData;
HANDLE hError;
int FileCount = 0;
char FilePathName[LEN];
// 构造路径
char FullPathName[LEN];
strcpy(FilePathName, Path);
strcat(FilePathName, "\\*.*");
hError = FindFirstFile(FilePathName, &FindData);
if (hError == INVALID_HANDLE_VALUE)
{
return 0;
}
while(::FindNextFile(hError, &FindData))
{
// 过虑.和..
if (strcmp(FindData.cFileName, ".") == 0
|| strcmp(FindData.cFileName, "..") == 0 )
{
continue;
}
// 构造完整路径
wsprintf(FullPathName, "%s\\%s", Path,FindData.cFileName);
FileCount++;
// 输出本级的文件
//printf("\n%d %s ", FileCount, FullPathName);
char szName[255];
strcpy(szName,FindData.cFileName);
int nLen = strlen(szName);
if (nLen>3 && strcmp(szName+nLen-3,".fx")==0)
{
szName[nLen-3]=0;
CShader* pShader = CRenderSystem::getSingleton().registerShader(szName,FullPathName);
if (pShader)
{
pShader->setRenderType(nRenderType);
}
}
// if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// {
// printf("<Dir>");
// DirectoryList(FullPathName);
// }
}
return 0;
}