static void CreateShaders() { static const char *fragShaderText = "#ifdef GL_ES\n" "precision highp float;\n" "#endif\n" "varying vec2 TexCoordOut;\n" "uniform sampler2D Texture;\n" "void main() {\n" " gl_FragColor = texture2D(Texture, TexCoordOut);\n" "}\n"; static const char *vertShaderText = "#ifdef GL_ES\n" "precision highp float;\n" "#endif\n" "attribute vec4 pos;\n" "attribute vec2 TexCoordIn;\n " "varying vec2 TexCoordOut;\n " "void main() {\n" " gl_Position = pos;\n" " TexCoordOut = TexCoordIn;\n" "}\n"; program = OpenGL_CompileProgram(vertShaderText, fragShaderText); glUseProgram(program); uni_tex = glGetUniformLocation(program, "Texture"); attr_pos = glGetAttribLocation(program, "pos"); attr_tex = glGetAttribLocation(program, "TexCoordIn"); }
SoftGPU::SoftGPU() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment glGenTextures(1, &temp_texture); // TODO: Use highp for GLES static const char *fragShaderText = #ifdef USING_GLES2 "#version 100\n" #endif "varying vec2 TexCoordOut;\n" "uniform sampler2D Texture;\n" "void main() {\n" " vec4 tmpcolor;\n" " tmpcolor = texture2D(Texture, TexCoordOut);\n" " gl_FragColor = tmpcolor;\n" "}\n"; static const char *vertShaderText = #ifdef USING_GLES2 "#version 100\n" #endif "attribute vec4 pos;\n" "attribute vec2 TexCoordIn;\n " "varying vec2 TexCoordOut;\n " "void main() {\n" " gl_Position = pos;\n" " TexCoordOut = TexCoordIn;\n" "}\n"; program = OpenGL_CompileProgram(vertShaderText, fragShaderText); glUseProgram(program); uni_tex = glGetUniformLocation(program, "Texture"); attr_pos = glGetAttribLocation(program, "pos"); attr_tex = glGetAttribLocation(program, "TexCoordIn"); if (gl_extensions.ARB_vertex_array_object) { glGenVertexArrays(1, &vao); glGenBuffers(1, &vbuf); } fb.data = Memory::GetPointer(0x44000000); // TODO: correct default address? depthbuf.data = Memory::GetPointer(0x44000000); // TODO: correct default address? framebufferDirty_ = true; // TODO: Is there a default? displayFramebuf_ = 0; displayStride_ = 512; displayFormat_ = GE_FORMAT_8888; }
void SWOGLWindow::Prepare() { if (m_init) return; m_init = true; // Init extension support. if (!GLExtensions::Init()) { ERROR_LOG(VIDEO, "GLExtensions::Init failed!Does your video card support OpenGL 2.0?"); return; } else if (GLExtensions::Version() < 310) { ERROR_LOG(VIDEO, "OpenGL Version %d detected, but at least 3.1 is required.", GLExtensions::Version()); return; } std::string frag_shader = "in vec2 TexCoord;\n" "out vec4 ColorOut;\n" "uniform sampler2D Texture;\n" "void main() {\n" " ColorOut = texture2D(Texture, TexCoord);\n" "}\n"; std::string vertex_shader = "out vec2 TexCoord;\n" "void main() {\n" " vec2 rawpos = vec2(gl_VertexID & 1, (gl_VertexID & 2) >> 1);\n" " gl_Position = vec4(rawpos * 2.0 - 1.0, 0.0, 1.0);\n" " TexCoord = vec2(rawpos.x, -rawpos.y);\n" "}\n"; std::string header = GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL ? "#version 140\n" : "#version 300 es\n" "precision highp float;\n"; m_image_program = OpenGL_CompileProgram(header + vertex_shader, header + frag_shader); glUseProgram(m_image_program); glUniform1i(glGetUniformLocation(m_image_program, "Texture"), 0); glGenTextures(1, &m_image_texture); glBindTexture(GL_TEXTURE_2D, m_image_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glGenVertexArrays(1, &m_image_vao); }
SoftGPU::SoftGPU() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment glGenTextures(1, &temp_texture); // TODO: Use highp for GLES static const char *fragShaderText = "varying vec2 TexCoordOut;\n" "uniform sampler2D Texture;\n" "void main() {\n" " vec4 tmpcolor;\n" " tmpcolor = texture2D(Texture, TexCoordOut);\n" " gl_FragColor = tmpcolor;\n" "}\n"; static const char *vertShaderText = "attribute vec4 pos;\n" "attribute vec2 TexCoordIn;\n " "varying vec2 TexCoordOut;\n " "void main() {\n" " gl_Position = pos;\n" " TexCoordOut = TexCoordIn;\n" "}\n"; program = OpenGL_CompileProgram(vertShaderText, fragShaderText); glUseProgram(program); uni_tex = glGetUniformLocation(program, "Texture"); attr_pos = glGetAttribLocation(program, "pos"); attr_tex = glGetAttribLocation(program, "TexCoordIn"); fb = Memory::GetPointer(0x44000000); // TODO: correct default address? depthbuf = Memory::GetPointer(0x44000000); // TODO: correct default address? }