增加GLEW Core

This commit is contained in:
hyzboy 2018-11-30 13:57:57 +08:00
parent b8b818e6f2
commit 9c0c1edc62
20 changed files with 58313 additions and 109 deletions

View File

@ -18,7 +18,12 @@ include_directories(3rdpty/MathGeoLib/src)
include_directories(inc)
add_subdirectory(3rdpty/MathGeoLib)
add_subdirectory(src)
SET(ULRE ULRE.RenderDevice
ULRE.RenderDriver
MathGeoLib
glfw
GL)
add_subdirectory(example)

View File

@ -1 +1,3 @@
add_executable(DirectGLRender main.cpp)
target_link_libraries(DirectGLRender PRIVATE ${ULRE})

View File

@ -1 +1,56 @@

#include<hgl/render/RenderDevice.h>
#include<hgl/render/RenderWindow.h>
#include<iostream>
#include<GLFW/glfw3.h>
#include<GL/glext.h>
using namespace hgl;
void draw()
{
glClearColor(0,0,0,1); //设置清屏颜色
glClear(GL_COLOR_BUFFER_BIT); //清屏
}
int main(void)
{
RenderDevice *device=CreateRenderDeviceGLFW();
if(!device)
{
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
return -1;
}
if(!device->Init())
{
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
return -2;
}
WindowSetup ws;
ws.Name=U8_TEXT("Direct OpenGL Render");
RenderSetup rs;
RenderWindow *win=device->CreateWindow(1280,720,&ws,&rs);
win->MakeToCurrent(); //切换当前窗口到前台
win->Show();
while(win->IsOpen())
{
draw();
win->SwapBuffer(); //交换前后台显示缓冲区
win->PollEvent(); //处理窗口事件
}
delete win;
delete device;
return 0;
}

View File

@ -2,7 +2,7 @@
#include<hgl/render/RenderWindow.h>
#include<iostream>
#include<GLFW/glfw3.h>
#include<GL/glext.h>
#include<GL/glcorearb.h>
using namespace hgl;

View File

@ -1,3 +1,3 @@
add_executable(EnumRenderDevice main.cpp)
target_link_libraries(EnumRenderDevice PRIVATE MathGeoLib glfw GL ULRE.RenderDevice)
target_link_libraries(EnumRenderDevice PRIVATE ${ULRE})

View File

@ -1,3 +1,3 @@
add_executable(NullWindow main.cpp)
target_link_libraries(NullWindow PRIVATE MathGeoLib glfw GL ULRE.RenderDevice)
target_link_libraries(NullWindow PRIVATE ${ULRE})

View File

@ -1,5 +1,5 @@
add_executable(OutputGLInfo main.cpp)
target_link_libraries(OutputGLInfo PRIVATE glfw GL ULRE.RenderDevice)
target_link_libraries(OutputGLInfo PRIVATE ${ULRE})

View File

@ -3,7 +3,7 @@
#include<iostream>
#include<string.h>
#include<GLFW/glfw3.h>
#include<GL/glext.h>
#include<GL/glcorearb.h>
using namespace hgl;

2618
inc/hgl/render/GL/eglew.h Normal file

File diff suppressed because it is too large Load Diff

23686
inc/hgl/render/GL/glew.h Normal file

File diff suppressed because it is too large Load Diff

1775
inc/hgl/render/GL/glxew.h Normal file

File diff suppressed because it is too large Load Diff

1447
inc/hgl/render/GL/wglew.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,6 @@
#define HGL_LIST_CPP
#include<string.h>
#include<hgl/LogInfo.h>
//--------------------------------------------------------------------------------------------------
// 代码中的部分memcpy可替换为memmove,但这样会引起CodeGuard/Valgrind之类的内存调试器报错
//--------------------------------------------------------------------------------------------------
@ -12,10 +11,7 @@ namespace hgl
bool List<T>::Get(int index,T &ti)const
{
if(!items||index<0||index>=count)
{
LOG_ERROR(OS_TEXT("List<>::Get(index=")+OSString(index)+OS_TEXT(") error,DataCount=")+OSString(count));
return(false);
}
memcpy(&ti,items+index,sizeof(T));
return(true);

View File

@ -1,7 +1,6 @@
#ifndef HGL_LIST_INCLUDE
#define HGL_LIST_INCLUDE
#include<hgl/LogInfo.h>
#include<stdlib.h>
#include<initializer_list>

View File

@ -1,3 +1,4 @@
add_library(ULRE.RenderDriver STATIC GLSL.cpp
Shader.cpp)
add_library(ULRE.RenderDriver STATIC GLCore/glew.c
GLCore/OpenGLCoreExtensions.c
GLCore/RenderDriverGLCore.cpp)

View File

@ -0,0 +1,51 @@
#include<hgl/render/GL/glew.h>
#include<GLFW/glfw3.h>
#include<malloc.h>
#include<string.h>
//供glew使用请在glew.c中删除原本的glewGetExtension函数
//旧的glGetString(GL_EXTENSIONS)方式会被报告为错误但GLEW 1.5.8未改用新式处理方案,所以暂且如此
static int opengl_core_ext_number = 0;
static char **opengl_core_ext_string = 0;
GLboolean glewGetExtension(const char *name)
{
int i;
if (opengl_core_ext_number == 0)return(GL_FALSE);
for (i = 0; i < opengl_core_ext_number; i++)
if (!strcmp(opengl_core_ext_string[i], name))
return(GL_TRUE);
return(GL_FALSE);
}
void InitOpenGLCoreExtensions()
{
int i;
PFNGLGETSTRINGIPROC getfunc;
getfunc = (PFNGLGETSTRINGIPROC)glfwGetProcAddress((const GLubyte*)"glGetStringi"); //此函数opengl 3.0才有
glGetIntegerv(GL_NUM_EXTENSIONS, &opengl_core_ext_number);
opengl_core_ext_string = malloc(opengl_core_ext_number*sizeof(char *));
for (i = 0; i < opengl_core_ext_number; i++)
opengl_core_ext_string[i] = (char *)getfunc(GL_EXTENSIONS, i);
}
void ClearOpenGLCoreExtension()
{
if (opengl_core_ext_string)
{
free(opengl_core_ext_string);
opengl_core_ext_string = 0;
}
opengl_core_ext_number = 0;
}

View File

@ -8,7 +8,6 @@ namespace hgl
void SetCurStatus(const RenderStatus &rs) override
{
if(rs.color
}
void ClearColorBuffer() override

28569
src/RenderDriver/GLCore/glew.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
#include<hgl/render/Shader.h>
#include<hgl/LogInfo.h>
//#include<hgl/LogInfo.h>
#include<hgl/type/Smart.h>
#include<malloc.h>
#include<GL/glext.h>
namespace hgl
{
@ -62,7 +63,7 @@ namespace hgl
glGetShaderInfoLog(shader,log_length,&char_writen,log);
LOG_HINT(UTF8String(name)+U8_TEXT(" shader compile error\n\n")+ UTF8String(log));
// LOG_HINT(UTF8String(name)+U8_TEXT(" shader compile error\n\n")+ UTF8String(log));
delete[] log;
@ -145,7 +146,7 @@ namespace hgl
glGetProgramInfoLog(program,log_length,&char_written,log);
LOG_ERROR(u8"Shader program link error\n\n"+UTF8String(log));
// LOG_ERROR(u8"Shader program link error\n\n"+UTF8String(log));
delete[] log;
@ -172,7 +173,7 @@ namespace hgl
{
if(!program)
{
LOG_ERROR(u8"GetAttribLocation("+UTF8String(name)+u8"),program=0");
// LOG_ERROR(u8"GetAttribLocation("+UTF8String(name)+u8"),program=0");
return(-1);
}
@ -209,7 +210,7 @@ namespace hgl
{
if(!program)
{
LOG_ERROR(u8"GetUniformLocation("+UTF8String(name)+u8"),program=0");
// LOG_ERROR(u8"GetUniformLocation("+UTF8String(name)+u8"),program=0");
return(-1);
}
@ -219,7 +220,7 @@ namespace hgl
{
const int gl_error=glGetError();
LOG_ERROR(u8"GetUniformLocation("+UTF8String(name)+u8"),program="+UTF8String(program)+u8",result=-1,gl_error="+UTF8String(gl_error));
// LOG_ERROR(u8"GetUniformLocation("+UTF8String(name)+u8"),program="+UTF8String(program)+u8",result=-1,gl_error="+UTF8String(gl_error));
}
return(result);
@ -227,13 +228,13 @@ namespace hgl
#define HGL_GLSL_CHECK_PROGRAM_AND_LOCATION(func) if(!program) \
{ \
LOG_ERROR(u8"Shader::SetUniform" #func ",program=0"); \
/*LOG_ERROR(u8"Shader::SetUniform" #func ",program=0"); */\
return(false); \
} \
\
if(location<0) \
{ \
LOG_ERROR(u8"Shader::SetUniform" #func ",location="+UTF8String(location)); \
/*LOG_ERROR(u8"Shader::SetUniform" #func ",location="+UTF8String(location));*/ \
return(false); \
}
@ -278,19 +279,19 @@ namespace hgl
{ \
if(!program) \
{ \
LOG_ERROR(u8"Shader::SetUniform" #func ",program=0"); \
/*LOG_ERROR(u8"Shader::SetUniform" #func ",program=0");*/ \
return(false); \
} \
\
if(location<0) \
{ \
LOG_ERROR(u8"Shader::SetUniform" #func ",location="+UTF8String(location)); \
/*LOG_ERROR(u8"Shader::SetUniform" #func ",location="+UTF8String(location));*/ \
return(false); \
} \
\
if(!value) \
{ \
LOG_ERROR(u8"Shader::SetUniform" #func ",value=nullptr"); \
/*LOG_ERROR(u8"Shader::SetUniform" #func ",value=nullptr");*/ \
return(false); \
} \
\
@ -319,19 +320,19 @@ namespace hgl
{ \
if(!program) \
{ \
LOG_ERROR(u8"Shader::SetUniformMatrix" #func ",program=0"); \
/*LOG_ERROR(u8"Shader::SetUniformMatrix" #func ",program=0"); */ \
return(false); \
} \
\
if(location<0) \
{ \
LOG_ERROR(u8"Shader::SetUniformMatrix" #func ",location="+UTF8String(location)); \
/*LOG_ERROR(u8"Shader::SetUniformMatrix" #func ",location="+UTF8String(location)); */ \
return(false); \
} \
\
if(!mat) \
{ \
LOG_ERROR(u8"Shader::SetUniformMatrix" #func ",mat=nullptr"); \
/*LOG_ERROR(u8"Shader::SetUniformMatrix" #func ",mat=nullptr"); */ \
return(false); \
} \
\
@ -352,41 +353,41 @@ namespace hgl
#undef HGL_GLSL_SetUniformMatrixPointer
int Shader::_GetUniformBlockIndex(const char *uniform_block_name)
{
if(!program)
{
LOG_ERROR(u8"Shader::_GetUniformBlockIndex("+UTF8String(uniform_block_name)+") program=0");
return(-1);
}
const int index=glGetUniformBlockIndex(program,uniform_block_name);
if(index<0)
{
LOG_ERROR(u8"Shader::_GetUniformBlockIndex("+UTF8String(uniform_block_name)+") block_index error");
return(-1);
}
return index;
}
int Shader::_GetShaderStorageIndex(const char *ssbo_name)
{
if(!program)
{
LOG_ERROR(u8"Shader::_GetShaderStorageIndex("+UTF8String(ssbo_name)+") program=0");
return(-1);
}
const int index=glGetProgramResourceIndex(program,GL_SHADER_STORAGE_BLOCK,ssbo_name);
if(index<0)
{
LOG_ERROR(u8"Shader::_GetShaderStorageIndex("+UTF8String(ssbo_name)+") block_index error");
return(-1);
}
return index;
}
// int Shader::_GetUniformBlockIndex(const char *uniform_block_name)
// {
// if(!program)
// {
// // LOG_ERROR(u8"Shader::_GetUniformBlockIndex("+UTF8String(uniform_block_name)+") program=0");
// return(-1);
// }
//
// const int index=glGetUniformBlockIndex(program,uniform_block_name);
//
// if(index<0)
// {
// // LOG_ERROR(u8"Shader::_GetUniformBlockIndex("+UTF8String(uniform_block_name)+") block_index error");
// return(-1);
// }
//
// return index;
// }
//
// int Shader::_GetShaderStorageIndex(const char *ssbo_name)
// {
// if(!program)
// {
// // LOG_ERROR(u8"Shader::_GetShaderStorageIndex("+UTF8String(ssbo_name)+") program=0");
// return(-1);
// }
//
// const int index=glGetProgramResourceIndex(program,GL_SHADER_STORAGE_BLOCK,ssbo_name);
//
// if(index<0)
// {
// // LOG_ERROR(u8"Shader::_GetShaderStorageIndex("+UTF8String(ssbo_name)+") block_index error");
// return(-1);
// }
//
// return index;
// }
}//namespace hgl

View File

@ -47,49 +47,49 @@ namespace hgl
return result;
}
/**
* Shader只读数据区索引
* @param name
* @return
* @return -1
*/
int Shader::GetUniformBlockIndex(const char *name)
{
if(!name||!(*name))return(-1);
int result;
if(!uniform_block_index.Get(name,result))
{
result=_GetUniformBlockIndex(name);
uniform_block_index.Add(name,result);
}
return result;
}
/**
* Shader数据存储区索引
* @param name
* @return
* @return -1
*/
int Shader::GetShaderStorageIndex(const char *name)
{
if(!name||!(*name))return(-1);
int result;
if(!ssbo_index.Get(name,result))
{
result=_GetShaderStorageIndex(name);
ssbo_index.Add(name,result);
}
return result;
}
// /**
// * 取得一个Shader只读数据区索引
// * @param name 数据区名称
// * @return 数据区索引
// * @return -1 出错
// */
// int Shader::GetUniformBlockIndex(const char *name)
// {
// if(!name||!(*name))return(-1);
//
// int result;
//
// if(!uniform_block_index.Get(name,result))
// {
// result=_GetUniformBlockIndex(name);
//
// uniform_block_index.Add(name,result);
// }
//
// return result;
// }
//
// /**
// * 取得一个Shader数据存储区索引
// * @param name 数据存储区名称
// * @return 数据存储区索引
// * @return -1 出错
// */
// int Shader::GetShaderStorageIndex(const char *name)
// {
// if(!name||!(*name))return(-1);
//
// int result;
//
// if(!ssbo_index.Get(name,result))
// {
// result=_GetShaderStorageIndex(name);
//
// ssbo_index.Add(name,result);
// }
//
// return result;
// }
#define HGL_GLSL_SetUniform1234(func,type) bool Shader::SetUniform1##func(const char *uniform_name,type v0) \
{ \